Working
This commit is contained in:
+27
-3
@@ -126,8 +126,19 @@ public class Event implements Serializable {
|
||||
// System.out.println(format.format(startDate.getTime()));
|
||||
|
||||
// System.out.println(date.get(Calendar.HOUR_OF_DAY));
|
||||
|
||||
return Integer.valueOf(format.format(startDate.getTime()));
|
||||
int time = Integer.valueOf(format.format(startDate.getTime()));
|
||||
int hours = time/100;
|
||||
int minutes = time%100;
|
||||
int finaltime;
|
||||
if(minutes != 0)
|
||||
{
|
||||
finaltime = hours*60 + minutes;
|
||||
}
|
||||
else
|
||||
{
|
||||
finaltime = hours*60;
|
||||
}
|
||||
return finaltime;
|
||||
}
|
||||
|
||||
public int getEndTime()
|
||||
@@ -135,7 +146,20 @@ public class Event implements Serializable {
|
||||
DateFormat format = new SimpleDateFormat("kkmm");
|
||||
format.setLenient(false);
|
||||
// System.out.println(format.format(endDate.getTime()));
|
||||
return Integer.valueOf(format.format(endDate.getTime()));
|
||||
int time = Integer.valueOf(format.format(endDate.getTime()));
|
||||
int hours = time/100;
|
||||
int minutes = time%100;
|
||||
int finaltime;
|
||||
if(minutes != 0)
|
||||
{
|
||||
finaltime = hours*60 + minutes;
|
||||
}
|
||||
else
|
||||
{
|
||||
finaltime = hours*60;
|
||||
}
|
||||
|
||||
return finaltime;
|
||||
}
|
||||
|
||||
public void setStartTime(int hours, int minutes)
|
||||
|
||||
+12
-7
@@ -13,13 +13,16 @@ public class StagePanel extends JPanel
|
||||
{
|
||||
private BufferedImage image;
|
||||
private int width, height, posX;
|
||||
private double widthD, posXD;
|
||||
private Event event;
|
||||
public StagePanel(int width, int height, int posX, Event event)
|
||||
public StagePanel(int width, int height, int posX, Event event, double widthD, double posXD)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.posX = posX;
|
||||
this.event = event;
|
||||
this.widthD = widthD;
|
||||
this.posXD = posXD;
|
||||
image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g2 = image.createGraphics();
|
||||
g2.setColor(Color.blue);
|
||||
@@ -44,9 +47,10 @@ public class StagePanel extends JPanel
|
||||
|
||||
}
|
||||
|
||||
public void update(int posx)
|
||||
public void update(int posx, double posXD)
|
||||
{
|
||||
this.posX = posx;
|
||||
this.posXD = posXD;
|
||||
repaint();
|
||||
}
|
||||
|
||||
@@ -57,14 +61,15 @@ public class StagePanel extends JPanel
|
||||
|
||||
}
|
||||
|
||||
public int getPosX()
|
||||
public double getPosX()
|
||||
{
|
||||
return this.posX;
|
||||
return this.posXD;
|
||||
}
|
||||
|
||||
public void setLength(int length)
|
||||
public void setLength(int length, double widthD)
|
||||
{
|
||||
this.width = length;
|
||||
this.widthD = widthD;
|
||||
}
|
||||
|
||||
public void setStageStartTime(int hours, int minutes)
|
||||
@@ -82,9 +87,9 @@ public class StagePanel extends JPanel
|
||||
return event.getStartTime();
|
||||
}
|
||||
|
||||
public int getImageWidth()
|
||||
public double getImageWidth()
|
||||
{
|
||||
return this.width;
|
||||
return this.widthD;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+92
-36
@@ -40,10 +40,6 @@ public class Timeline extends JPanel
|
||||
// });
|
||||
|
||||
|
||||
// DateTime dt1 = new DateTime(2000, 1, 1, 0, 0, 0, 0);
|
||||
// DateTime dt2 = new DateTime(2010, 1, 1, 0, 0, 0, 0);
|
||||
// int days = Days.daysBetween(dt1, dt2).getDays();
|
||||
|
||||
public Timeline(JPanel frame)
|
||||
{
|
||||
super();
|
||||
@@ -69,6 +65,7 @@ public class Timeline extends JPanel
|
||||
|
||||
public JPanel createMainPanel()
|
||||
{
|
||||
// this.setSize(frame.getWidth(), frame.getHeight());
|
||||
JPanel mainPanel = new JPanel();
|
||||
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
|
||||
Container topContainer = createTopPanel();
|
||||
@@ -76,7 +73,7 @@ public class Timeline extends JPanel
|
||||
topContainer.setMaximumSize(dim);
|
||||
mainPanel.add(topContainer);
|
||||
|
||||
Dimension centerDim = new Dimension(this.getWidth(), frame.getHeight());
|
||||
Dimension centerDim = new Dimension(this.getWidth(), this.getHeight());
|
||||
|
||||
// Container centerContainer = createCenterPanel();
|
||||
JPanel centerContainer = createCenterPanel();
|
||||
@@ -85,7 +82,7 @@ public class Timeline extends JPanel
|
||||
centerContainer.setMaximumSize(centerDim);
|
||||
// System.out.println(centerDim);
|
||||
mainPanel.add(centerContainer);
|
||||
// this.add(mainPanel, BorderLayout.CENTER);
|
||||
this.add(mainPanel, BorderLayout.CENTER);
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
@@ -99,7 +96,7 @@ public class Timeline extends JPanel
|
||||
|
||||
for(Event event : events)
|
||||
{
|
||||
StagePanel stagepanel = new StagePanel(calcLengthOfStage(event.getLength()), 30, calcPositionOfStage(event.getStartTime()), event);
|
||||
StagePanel stagepanel = new StagePanel((int)calcLengthOfStage(event.getLength()), 30, (int)calcPositionOfStage(event.getStartTime()), event,calcLengthOfStage(event.getLength()),calcPositionOfStage(event.getStartTime()));
|
||||
Container content = stagepanel;
|
||||
content.setMaximumSize(new Dimension(this.getWidth(),30));
|
||||
content.addMouseListener(new MouseListener() {
|
||||
@@ -138,7 +135,11 @@ public class Timeline extends JPanel
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
stagepanel.update(e.getX() - stagepanel.getImageWidth() / 2);
|
||||
int value = (int)(e.getX() - stagepanel.getImageWidth() / 2);
|
||||
double value2 = (e.getX() - stagepanel.getImageWidth() / 2);
|
||||
// System.out.println("Value1: " + value);
|
||||
// System.out.println("Value2: " + value2);
|
||||
stagepanel.update(value, value2);
|
||||
}
|
||||
});
|
||||
centerPanel.add(content);
|
||||
@@ -151,54 +152,67 @@ public class Timeline extends JPanel
|
||||
|
||||
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(calcStartTimeOfStagePanelHours(stagepanel.getPosX()),calcStartTimeOfStagePanelMinutes(stagepanel.getPosX()));
|
||||
stagepanel.setStageEndTime(calcEndTimeOfStagePanelHours(stagepanel.getPosX(), stagepanel.getImageWidth()),calcEndTimeOfStagePanelMinutes(stagepanel.getPosX(), stagepanel.getImageWidth()));
|
||||
// stagepanel.setLength(calcLengthOfStagePanel(stagepanel.getImageWidth()));
|
||||
// System.out.println(calcLengthOfStagePanel(stagepanel.getImageWidth()));
|
||||
// System.out.println("HOURS: " + calcEndTimeOfStagePanelHours(stagepanel.getPosX(), stagepanel.getImageWidth()));
|
||||
// System.out.println("MINUTES: " + calcEndTimeOfStagePanelMinutes(stagepanel.getPosX(), stagepanel.getImageWidth()) );
|
||||
// TimelinePanel tempPanel = (TimelinePanel) frame;
|
||||
// tempPanel.refresh();
|
||||
refresh();
|
||||
|
||||
|
||||
// System.out.println(stagepanel.getPosX());
|
||||
}
|
||||
|
||||
public int calcLengthOfStage(int length)
|
||||
public double calcLengthOfStage(double length)
|
||||
{
|
||||
double lengthOfStage = 0;
|
||||
int min = findMinMax(1);
|
||||
int max = findMinMax(2);
|
||||
|
||||
double frameWidth = this.getWidth();
|
||||
double pixelsPerLength = frameWidth / (max - min);
|
||||
double minmax = max-min;
|
||||
double pixelsPerLength = frameWidth / minmax;
|
||||
lengthOfStage = pixelsPerLength * (double)length;
|
||||
// System.out.println((int)lengthOfStage);
|
||||
return (int)lengthOfStage;
|
||||
// System.out.println("LengthOfStage: " + lengthOfStage);
|
||||
//
|
||||
// System.out.println("MAX: " + max);
|
||||
// System.out.println("MIN: " + min);
|
||||
// System.out.println("LENGTH: " + length);
|
||||
// System.out.println("FRAME: " + frameWidth);
|
||||
// System.out.println("PixelsPerLEngth: " + pixelsPerLength);
|
||||
|
||||
return lengthOfStage;
|
||||
}
|
||||
|
||||
public int calcLengthOfStagePanel(int length)
|
||||
public double calcLengthOfStagePanel(double length)
|
||||
{
|
||||
double lengthOfStagePanel = 0;
|
||||
int min = findMinMax(1);
|
||||
int max = findMinMax(2);
|
||||
// System.out.println(length);
|
||||
double frameWidth = this.getWidth();
|
||||
double pixelsPerLength = frameWidth / (max - min);
|
||||
double minmax = max-min;
|
||||
double pixelsPerLength = frameWidth / minmax;
|
||||
// System.out.println(pixelsPerLength);
|
||||
lengthOfStagePanel = (double)length / pixelsPerLength;
|
||||
// System.out.println(lengthOfStagePanel);
|
||||
|
||||
return (int)lengthOfStagePanel;
|
||||
|
||||
// System.out.println("LengthOfStagePane: " + (int)lengthOfStagePanel);
|
||||
|
||||
return lengthOfStagePanel;
|
||||
}
|
||||
|
||||
public int calcPositionOfStage(int startTime)
|
||||
public double calcPositionOfStage(int startTime)
|
||||
{
|
||||
int posx = 0;
|
||||
double posx;
|
||||
int min = findMinMax(1);
|
||||
int max = findMinMax(2);
|
||||
double minmax = max-min;
|
||||
posx = startTime - min;
|
||||
posx = posx * this.getWidth() / (max-min);
|
||||
posx = posx * this.getWidth() / minmax;
|
||||
// System.out.println("Frame: " + this.getWidth());
|
||||
// System.out.println("startTime: " + startTime);
|
||||
// System.out.println("Max: " + max + " min: " + min);
|
||||
@@ -206,20 +220,27 @@ public class Timeline extends JPanel
|
||||
return posx;
|
||||
}
|
||||
|
||||
public int calcStartTimeOfStagePanelHours(int posx)
|
||||
public int calcStartTimeOfStagePanelHours(double posx)
|
||||
{
|
||||
int min = findMinMax(1);
|
||||
int max = findMinMax(2);
|
||||
// System.out.println("MIN: " + min);
|
||||
// System.out.println("max: " + max);
|
||||
// double startTime = (posx / (this.getWidth() / (max - min )) ) + min;
|
||||
//Omdat het anders onnodig afgerond wordt, alles apart in doubles.
|
||||
double minmax = max-min;
|
||||
double bottom = this.getWidth() / minmax;
|
||||
double all = posx / bottom;
|
||||
double startTime = all + min;
|
||||
return (int)startTime / 100;
|
||||
// System.out.println("STPH: " + this.getWidth());
|
||||
|
||||
|
||||
|
||||
|
||||
return ((int)startTime / 60);
|
||||
}
|
||||
|
||||
public int calcStartTimeOfStagePanelMinutes(int posx)
|
||||
public int calcStartTimeOfStagePanelMinutes(double posx)
|
||||
{
|
||||
int min = findMinMax(1);
|
||||
int max = findMinMax(2);
|
||||
@@ -229,10 +250,12 @@ public class Timeline extends JPanel
|
||||
double bottom = this.getWidth() / minmax;
|
||||
double all = posx / bottom;
|
||||
double startTime = all + min;
|
||||
return (int)startTime % 100;
|
||||
// System.out.println("STPM: " + this.getWidth());
|
||||
|
||||
return ((int)startTime % 60);
|
||||
}
|
||||
|
||||
public int calcEndTimeOfStagePanelHours(int posx, int imageWidth)
|
||||
public int calcEndTimeOfStagePanelHours(double posx, double imageWidth)
|
||||
{
|
||||
int min = findMinMax(1);
|
||||
int max = findMinMax(2);
|
||||
@@ -241,10 +264,11 @@ public class Timeline extends JPanel
|
||||
double bottom = this.getWidth() / minmax;
|
||||
double all = posx / bottom;
|
||||
double endTime = all + min + calcLengthOfStagePanel(imageWidth);
|
||||
return (int)endTime / 100;
|
||||
// System.out.println("ETPH: " + this.getWidth());
|
||||
return (int)endTime / 60;
|
||||
}
|
||||
|
||||
public int calcEndTimeOfStagePanelMinutes(int posx, int imageWidth)
|
||||
public int calcEndTimeOfStagePanelMinutes(double posx, double imageWidth)
|
||||
{
|
||||
int min = findMinMax(1);
|
||||
int max = findMinMax(2);
|
||||
@@ -253,7 +277,13 @@ public class Timeline extends JPanel
|
||||
double bottom = this.getWidth() / minmax;
|
||||
double all = posx / bottom;
|
||||
double endTime = all + min + calcLengthOfStagePanel(imageWidth);
|
||||
return (int)endTime % 100;
|
||||
// System.out.println("ETPM: " + this.getWidth());
|
||||
return (int)endTime % 60;
|
||||
}
|
||||
|
||||
public int minutesToHours(int minutes)
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
public int intToTime(int time, String option)
|
||||
@@ -266,10 +296,21 @@ public class Timeline extends JPanel
|
||||
{
|
||||
time = time % 60;
|
||||
}
|
||||
System.out.println(time);
|
||||
// System.out.println(time);
|
||||
return time;
|
||||
}
|
||||
|
||||
public int toHours(int minutesTot)
|
||||
{
|
||||
int hours = minutesTot / 60;
|
||||
int minutes = minutesTot % 60;
|
||||
int finaltime;
|
||||
|
||||
finaltime = hours * 100 + minutes;
|
||||
|
||||
return finaltime;
|
||||
}
|
||||
|
||||
public int findMinMax(int i)
|
||||
{
|
||||
// Event oldevent = new Event(0, 0, null, "Base", 0);
|
||||
@@ -344,9 +385,9 @@ public class Timeline extends JPanel
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
||||
panel.add(Box.createRigidArea(new Dimension(50, 10)));
|
||||
panel.add(new JLabel(Integer.toString(findMinMax(1))));
|
||||
panel.add(new JLabel(Integer.toString(toHours(findMinMax(1)))));
|
||||
panel.add(Box.createHorizontalGlue());
|
||||
panel.add(new JLabel(Integer.toString(findMinMax(2))));
|
||||
panel.add(new JLabel(Integer.toString(toHours(findMinMax(2)))));
|
||||
panel.add(Box.createRigidArea(new Dimension(50, 10)));
|
||||
topPane.add(panel);
|
||||
topPane.add(topPanel);
|
||||
@@ -356,12 +397,20 @@ public class Timeline extends JPanel
|
||||
|
||||
public JPanel createWestPanel()
|
||||
{
|
||||
this.setSize(frame.getWidth(), frame.getHeight());
|
||||
JPanel westPanel = new JPanel();
|
||||
westPanel.setLayout(new BoxLayout(westPanel, BoxLayout.Y_AXIS));
|
||||
westPanel.add(Box.createRigidArea(new Dimension(0, 100)));
|
||||
for(int i = 0; i < events.size(); i++)
|
||||
// for(int i = 0; i < events.size(); i++)
|
||||
// {
|
||||
// JLabel stageText = new JLabel("Stage: " + (i+1) + " ");
|
||||
// westPanel.add(stageText);
|
||||
// westPanel.add(Box.createRigidArea(new Dimension(0, 30 )));
|
||||
// }
|
||||
for(Event event : events)
|
||||
{
|
||||
JLabel stageText = new JLabel("Stage: " + (i+1) + " ");
|
||||
JLabel stageText = new JLabel(event.getStage().getName() + ": " + " ");
|
||||
|
||||
westPanel.add(stageText);
|
||||
westPanel.add(Box.createRigidArea(new Dimension(0, 30 )));
|
||||
}
|
||||
@@ -390,6 +439,13 @@ public class Timeline extends JPanel
|
||||
|
||||
}
|
||||
|
||||
public void createNull()
|
||||
{
|
||||
this.removeAll();
|
||||
this.add(new JLabel("No events for this day"));
|
||||
this.revalidate();
|
||||
}
|
||||
|
||||
public JPanel getTimeline()
|
||||
{
|
||||
return this;
|
||||
|
||||
+32
-17
@@ -8,48 +8,63 @@ import javax.swing.JPanel;
|
||||
public class TimelinePanel extends JPanel implements Panel {
|
||||
|
||||
private Timeline timeline;
|
||||
// private WestPanel westPanel;
|
||||
|
||||
public TimelinePanel()
|
||||
{
|
||||
super(new BorderLayout());
|
||||
|
||||
this.setSize(1920, 1080);
|
||||
this.setSize(600, 600);
|
||||
this.setVisible(true);
|
||||
timeline = new Timeline(this);
|
||||
this.add(timeline,BorderLayout.CENTER);
|
||||
this.add(timeline.createWestPanel(), BorderLayout.WEST);
|
||||
// westPanel = new WestPanel();
|
||||
// this.add(timeline.createMainPanel(),BorderLayout.CENTER);
|
||||
// this.add(new JButton());
|
||||
// this.add(timeline.createWestPanel(), BorderLayout.WEST);
|
||||
}
|
||||
|
||||
public void refresh()
|
||||
{
|
||||
this.removeAll();
|
||||
this.add(timeline.createMainPanel(),BorderLayout.CENTER);
|
||||
timeline.refresh();
|
||||
// westPanel.refresh();
|
||||
this.add(timeline,BorderLayout.CENTER);
|
||||
this.add(timeline.createWestPanel(), BorderLayout.WEST);
|
||||
this.revalidate();
|
||||
// timeline.refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ArrayList<Event> events)
|
||||
{
|
||||
timeline.setEvents(events);
|
||||
System.out.println(events.size());
|
||||
// System.out.println(events.size());
|
||||
// westPanel.setEvents(events);
|
||||
// refresh();
|
||||
// this.add(timeline.createMainPanel(),BorderLayout.CENTER);
|
||||
// this.add(new JButton());
|
||||
// this.add(timeline.createWestPanel(), BorderLayout.WEST);
|
||||
|
||||
//dit fixt het half
|
||||
// if(events.size() == 0)
|
||||
// {
|
||||
// this.removeAll();
|
||||
// this.add(timeline.createWestPanel(),BorderLayout.WEST);
|
||||
// this.add(timeline, BorderLayout.CENTER);
|
||||
// this.revalidate();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// refresh();
|
||||
// }
|
||||
refresh();
|
||||
if(events.size() != 0)
|
||||
{
|
||||
this.removeAll();
|
||||
timeline.refresh();
|
||||
this.add(timeline.createWestPanel(),BorderLayout.WEST);
|
||||
this.add(timeline, BorderLayout.CENTER);
|
||||
this.revalidate();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.removeAll();
|
||||
timeline.createNull();
|
||||
this.add(timeline);
|
||||
this.revalidate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public TimelinePanel getTimelinePanel()
|
||||
{
|
||||
return this;
|
||||
|
||||
@@ -173,6 +173,7 @@ public class Window extends JFrame {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
TimelinePanel tempTimeLine = (TimelinePanel) timeline;
|
||||
tempTimeLine.refresh();
|
||||
// System.out.println("WINDOWS: " + tempframe.getWidth());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user