Dragging to change time in Stage possible
This commit is contained in:
+19
-5
@@ -13,19 +13,17 @@ public class StagePanel extends JPanel
|
|||||||
{
|
{
|
||||||
private BufferedImage image;
|
private BufferedImage image;
|
||||||
private int width, height, posX;
|
private int width, height, posX;
|
||||||
private boolean listening;
|
private Stage stage;
|
||||||
public StagePanel(int width, int height, int posX)
|
public StagePanel(int width, int height, int posX, Stage stage)
|
||||||
{
|
{
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.posX = posX;
|
this.posX = posX;
|
||||||
listening = false;
|
this.stage = stage;
|
||||||
image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB);
|
image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB);
|
||||||
Graphics2D g2 = image.createGraphics();
|
Graphics2D g2 = image.createGraphics();
|
||||||
g2.setColor(Color.blue);
|
g2.setColor(Color.blue);
|
||||||
g2.fillRect(0, 0, image.getWidth(), image.getHeight());
|
g2.fillRect(0, 0, image.getWidth(), image.getHeight());
|
||||||
// this.setSize(new Dimension(width, height));
|
|
||||||
// System.out.println(this.getSize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paint(Graphics g)
|
public void paint(Graphics g)
|
||||||
@@ -51,6 +49,7 @@ public class StagePanel extends JPanel
|
|||||||
this.posX = posx;
|
this.posX = posx;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public StagePanel(LayoutManager arg0, boolean arg1)
|
public StagePanel(LayoutManager arg0, boolean arg1)
|
||||||
{
|
{
|
||||||
@@ -58,6 +57,21 @@ public class StagePanel extends JPanel
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getPosX()
|
||||||
|
{
|
||||||
|
return this.posX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStageStartTime(int startTime)
|
||||||
|
{
|
||||||
|
stage.setStartTime(startTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStageStartTime()
|
||||||
|
{
|
||||||
|
return stage.getStartTime();
|
||||||
|
}
|
||||||
|
|
||||||
public int getImageWidth()
|
public int getImageWidth()
|
||||||
{
|
{
|
||||||
return this.width;
|
return this.width;
|
||||||
|
|||||||
+41
-16
@@ -65,14 +65,14 @@ public class Timeline extends JPanel
|
|||||||
|
|
||||||
for(Stage stage : stages)
|
for(Stage stage : stages)
|
||||||
{
|
{
|
||||||
StagePanel stagepanel = new StagePanel(calcLengthOfStage(stage.getLength()), 30, calcshit(stage.getStartTime()));
|
StagePanel stagepanel = new StagePanel(calcLengthOfStage(stage.getLength()), 30, calcPositionOfStage(stage.getStartTime()), stage);
|
||||||
Container content = stagepanel;
|
Container content = stagepanel;
|
||||||
content.setMaximumSize(new Dimension(frame.getWidth() - 70,30));
|
content.setMaximumSize(new Dimension(frame.getWidth() - 70,30));
|
||||||
content.addMouseListener(new MouseListener() {
|
content.addMouseListener(new MouseListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
resizeTimeline();
|
resizeTimeline(stagepanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -114,40 +114,65 @@ public class Timeline extends JPanel
|
|||||||
this.add(centerPanel, BorderLayout.CENTER);
|
this.add(centerPanel, BorderLayout.CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resizeTimeline()
|
public void resizeTimeline(StagePanel stagepanel)
|
||||||
{
|
{
|
||||||
|
int min = findMinMax(1);
|
||||||
|
int max = findMinMax(2);
|
||||||
|
System.out.println(stagepanel.getStageStartTime());
|
||||||
|
System.out.println(calcStartTimeOfStagePanel(stagepanel.getPosX()));
|
||||||
|
stagepanel.setStageStartTime(calcStartTimeOfStagePanel(stagepanel.getPosX()));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//testcode
|
|
||||||
public int calcLengthOfStage(int length)
|
public int calcLengthOfStage(int length)
|
||||||
{
|
{
|
||||||
double lengthOfStage = 0;
|
double lengthOfStage = 0;
|
||||||
int min = test(1);
|
int min = findMinMax(1);
|
||||||
int max = test(2);
|
int max = findMinMax(2);
|
||||||
|
|
||||||
double frameWidth = frame.getWidth();
|
double frameWidth = frame.getWidth();
|
||||||
double pixelsPerLength = frameWidth / (max - min);
|
double pixelsPerLength = frameWidth / (max - min);
|
||||||
// System.out.println(pixelsPerLength);
|
|
||||||
lengthOfStage = pixelsPerLength * (double)length;
|
lengthOfStage = pixelsPerLength * (double)length;
|
||||||
// System.out.println(length);
|
|
||||||
System.out.println(lengthOfStage);
|
|
||||||
|
|
||||||
return (int)lengthOfStage;
|
return (int)lengthOfStage;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Testcode
|
public int calcPositionOfStage(int startTime)
|
||||||
public int calcshit(int startTime)
|
|
||||||
{
|
{
|
||||||
int posx = 0;
|
int posx = 0;
|
||||||
int min = test(1);
|
int min = findMinMax(1);
|
||||||
int max = test(2);
|
int max = findMinMax(2);
|
||||||
posx = startTime - min;
|
posx = startTime - min;
|
||||||
|
posx = posx * frame.getWidth() / (max-min);
|
||||||
|
// System.out.println("Frame: " + frame.getWidth());
|
||||||
|
// System.out.println("startTime: " + startTime);
|
||||||
|
// System.out.println("Max: " + max + " min: " + min);
|
||||||
|
// System.out.println("Posx: " + posx);
|
||||||
return posx;
|
return posx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int calcStartTimeOfStagePanel(int posx)
|
||||||
|
{
|
||||||
|
int min = findMinMax(1);
|
||||||
|
int max = findMinMax(2);
|
||||||
|
// double startTime = (posx / (frame.getWidth() / (max - min )) ) + min;
|
||||||
|
//Omdat het anders onnodig afgerond wordt, alles apart in doubles.
|
||||||
|
double minmax = max-min;
|
||||||
|
double bottom = frame.getWidth() / minmax;
|
||||||
|
double all = posx / bottom;
|
||||||
|
double startTime = all + min;
|
||||||
|
|
||||||
|
|
||||||
|
// System.out.println("starttime----------------");
|
||||||
|
// System.out.println("Frame: " + frame.getWidth());
|
||||||
|
// System.out.println("startTime: " + startTime);
|
||||||
|
// System.out.println("Max: " + max + " min: " + min);
|
||||||
|
// System.out.println("Posx: " + posx);
|
||||||
|
return (int)startTime;
|
||||||
|
}
|
||||||
|
|
||||||
//testcode
|
public int findMinMax(int i)
|
||||||
public int test(int i)
|
|
||||||
{
|
{
|
||||||
// Event oldevent = new Event(0, 0, null, "Base", 0);
|
// Event oldevent = new Event(0, 0, null, "Base", 0);
|
||||||
// ArrayList<Event> oldevents = new ArrayList<Event>();
|
// ArrayList<Event> oldevents = new ArrayList<Event>();
|
||||||
|
|||||||
Reference in New Issue
Block a user