Left to do: fix time in timeline

This commit is contained in:
Yorick
2015-02-26 19:29:28 +00:00
parent 7195152f7f
commit 18726278a5
4 changed files with 89 additions and 34 deletions
+12 -6
View File
@@ -123,7 +123,7 @@ public class Event implements Serializable {
{ {
DateFormat format = new SimpleDateFormat("kkmm"); DateFormat format = new SimpleDateFormat("kkmm");
format.setLenient(false); format.setLenient(false);
System.out.println(format.format(startDate.getTime())); // System.out.println(format.format(startDate.getTime()));
// System.out.println(date.get(Calendar.HOUR_OF_DAY)); // System.out.println(date.get(Calendar.HOUR_OF_DAY));
@@ -134,18 +134,24 @@ public class Event implements Serializable {
{ {
DateFormat format = new SimpleDateFormat("kkmm"); DateFormat format = new SimpleDateFormat("kkmm");
format.setLenient(false); format.setLenient(false);
System.out.println(format.format(endDate.getTime())); // System.out.println(format.format(endDate.getTime()));
return Integer.valueOf(format.format(endDate.getTime())); return Integer.valueOf(format.format(endDate.getTime()));
} }
public void setStartTime(int time) public void setStartTime(int hours, int minutes)
{ {
startDate.set(Calendar.HOUR, 6); // System.out.println("Start:" + hours + ":" + minutes);
startDate.set(Calendar.HOUR_OF_DAY, hours);
startDate.set(Calendar.MINUTE, minutes);
// System.out.println(startDate.getTime());
} }
public void setEndTime(int time) public void setEndTime(int hours, int minutes)
{ {
// System.out.println("End:" + hours + ":" + minutes);
endDate.set(Calendar.HOUR_OF_DAY, hours);
endDate.set(Calendar.MINUTE, minutes);
// System.out.println(endDate.getTime());
} }
public String toString() { public String toString() {
+4 -4
View File
@@ -67,14 +67,14 @@ public class StagePanel extends JPanel
this.width = length; this.width = length;
} }
public void setStageStartTime(int startTime) public void setStageStartTime(int hours, int minutes)
{ {
event.setStartTime(startTime); event.setStartTime(hours, minutes);
} }
public void setStageEndTime(int endTime) public void setStageEndTime(int hours, int minutes)
{ {
event.setEndTime(endTime); event.setEndTime(hours, minutes);
} }
public int getStageStartTime() public int getStageStartTime()
+50 -19
View File
@@ -63,12 +63,11 @@ public class Timeline extends JPanel
public void refresh() public void refresh()
{ {
this.removeAll(); this.removeAll();
// createWestPanel();
createMainPanel(); createMainPanel();
this.revalidate(); this.revalidate();
} }
private void createMainPanel() public JPanel createMainPanel()
{ {
JPanel mainPanel = new JPanel(); JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
@@ -86,7 +85,8 @@ public class Timeline extends JPanel
centerContainer.setMaximumSize(centerDim); centerContainer.setMaximumSize(centerDim);
// System.out.println(centerDim); // System.out.println(centerDim);
mainPanel.add(centerContainer); mainPanel.add(centerContainer);
this.add(mainPanel, BorderLayout.CENTER); // this.add(mainPanel, BorderLayout.CENTER);
return mainPanel;
} }
private JPanel createCenterPanel() private JPanel createCenterPanel()
@@ -155,8 +155,8 @@ public class Timeline extends JPanel
int max = findMinMax(2); int max = findMinMax(2);
// System.out.println(stagepanel.getStageStartTime()); // System.out.println(stagepanel.getStageStartTime());
// System.out.println(calcStartTimeOfStagePanel(stagepanel.getPosX())); // System.out.println(calcStartTimeOfStagePanel(stagepanel.getPosX()));
stagepanel.setStageStartTime(calcStartTimeOfStagePanel(stagepanel.getPosX())); stagepanel.setStageStartTime(calcStartTimeOfStagePanelHours(stagepanel.getPosX()),calcStartTimeOfStagePanelMinutes(stagepanel.getPosX()));
stagepanel.setStageEndTime(calcEndTimeOfStagePanel(stagepanel.getPosX(), stagepanel.getImageWidth())); stagepanel.setStageEndTime(calcEndTimeOfStagePanelHours(stagepanel.getPosX(), stagepanel.getImageWidth()),calcEndTimeOfStagePanelMinutes(stagepanel.getPosX(), stagepanel.getImageWidth()));
// stagepanel.setLength(calcLengthOfStagePanel(stagepanel.getImageWidth())); // stagepanel.setLength(calcLengthOfStagePanel(stagepanel.getImageWidth()));
// System.out.println(calcLengthOfStagePanel(stagepanel.getImageWidth())); // System.out.println(calcLengthOfStagePanel(stagepanel.getImageWidth()));
refresh(); refresh();
@@ -206,7 +206,7 @@ public class Timeline extends JPanel
return posx; return posx;
} }
public int calcStartTimeOfStagePanel(int posx) public int calcStartTimeOfStagePanelHours(int posx)
{ {
int min = findMinMax(1); int min = findMinMax(1);
int max = findMinMax(2); int max = findMinMax(2);
@@ -216,17 +216,23 @@ public class Timeline extends JPanel
double bottom = this.getWidth() / minmax; double bottom = this.getWidth() / minmax;
double all = posx / bottom; double all = posx / bottom;
double startTime = all + min; double startTime = all + min;
return (int)startTime / 100;
}
// System.out.println("starttime----------------");
// System.out.println("Frame: " + this.getWidth()); public int calcStartTimeOfStagePanelMinutes(int posx)
// System.out.println("startTime: " + startTime); {
// System.out.println("Max: " + max + " min: " + min); int min = findMinMax(1);
// System.out.println("Posx: " + posx); int max = findMinMax(2);
return (int)startTime; // 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;
} }
public int calcEndTimeOfStagePanel(int posx, int imageWidth) public int calcEndTimeOfStagePanelHours(int posx, int imageWidth)
{ {
int min = findMinMax(1); int min = findMinMax(1);
int max = findMinMax(2); int max = findMinMax(2);
@@ -235,9 +241,33 @@ public class Timeline extends JPanel
double bottom = this.getWidth() / minmax; double bottom = this.getWidth() / minmax;
double all = posx / bottom; double all = posx / bottom;
double endTime = all + min + calcLengthOfStagePanel(imageWidth); double endTime = all + min + calcLengthOfStagePanel(imageWidth);
// System.out.println(calcLengthOfStagePanel(imageWidth)); return (int)endTime / 100;
// System.out.println(endTime); }
return (int)endTime;
public int calcEndTimeOfStagePanelMinutes(int posx, int imageWidth)
{
int min = findMinMax(1);
int max = findMinMax(2);
//Omdat het anders onnodig afgerond wordt, alles apart in doubles.
double minmax = max-min;
double bottom = this.getWidth() / minmax;
double all = posx / bottom;
double endTime = all + min + calcLengthOfStagePanel(imageWidth);
return (int)endTime % 100;
}
public int intToTime(int time, String option)
{
if(option == "hours")
{
time = time % 24;
}
else if(option == "minutes")
{
time = time % 60;
}
System.out.println(time);
return time;
} }
public int findMinMax(int i) public int findMinMax(int i)
@@ -306,7 +336,7 @@ public class Timeline extends JPanel
JPanel topPanel = new JPanel(new FlowLayout()); JPanel topPanel = new JPanel(new FlowLayout());
for(int i = 0; i <= this.getWidth() / 10; i++) for(int i = 0; i <= this.getWidth() / 10; i++)
{ {
ImageIcon topImageIcon = new ImageIcon("src/test2.png"); ImageIcon topImageIcon = new ImageIcon("src/sprites/block.png");
JLabel topImage = new JLabel(topImageIcon); JLabel topImage = new JLabel(topImageIcon);
topPanel.add(topImage); topPanel.add(topImage);
} }
@@ -365,4 +395,5 @@ public class Timeline extends JPanel
return this; return this;
} }
} }
+23 -5
View File
@@ -1,6 +1,7 @@
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JPanel; import javax.swing.JPanel;
@@ -12,7 +13,7 @@ public class TimelinePanel extends JPanel implements Panel {
{ {
super(new BorderLayout()); super(new BorderLayout());
this.setSize(600, 600); this.setSize(1920, 1080);
this.setVisible(true); this.setVisible(true);
timeline = new Timeline(this); timeline = new Timeline(this);
this.add(timeline,BorderLayout.CENTER); this.add(timeline,BorderLayout.CENTER);
@@ -21,14 +22,31 @@ public class TimelinePanel extends JPanel implements Panel {
public void refresh() public void refresh()
{ {
timeline.refresh(); this.removeAll();
this.add(timeline.createMainPanel(),BorderLayout.CENTER);
this.add(timeline.createWestPanel(), BorderLayout.WEST);
this.revalidate();
} }
@Override @Override
public void update(ArrayList<Event> event) public void update(ArrayList<Event> events)
{ {
timeline.setEvents(event); timeline.setEvents(events);
timeline.refresh(); System.out.println(events.size());
//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();
} }