瀏覽代碼

added new version of agenda;

jancoow 11 年之前
父節點
當前提交
207e356dd5
共有 4 個文件被更改,包括 129 次插入40 次删除
  1. 14 6
      src/agenda/ActTime.java
  2. 28 4
      src/gui/panels/AgendaItemShape.java
  3. 74 28
      src/gui/panels/AgendaPane.java
  4. 13 2
      src/gui/panels/MainPanel.java

+ 14 - 6
src/agenda/ActTime.java

@@ -25,7 +25,7 @@ public class ActTime {
     	endTime.set(y,m-1,d,hh,mm);
     }
     
-    public String getBeginTime(){
+    public String getBeginTimeString(){
     	return 	beginTime.get(Calendar.YEAR) + "-" + 
     			beginTime.get(Calendar.MONTH) + "-" + 
     			(beginTime.get(Calendar.DATE)+1) + " " + 
@@ -33,20 +33,28 @@ public class ActTime {
     			beginTime.get(Calendar.MINUTE);
     }
     
-    public String getEndTime(){
+    public String getEndTimeString(){
     	return 	endTime.get(Calendar.YEAR) + "-" + 
     			endTime.get(Calendar.MONTH) + "-" + 
     			(endTime.get(Calendar.DATE)+1) + " " + 
     			endTime.get(Calendar.HOUR_OF_DAY) + ":" +
     			endTime.get(Calendar.MINUTE);
     }
-   
-    public long getLength(){
-    	return (endTime.getTimeInMillis()/60000)-(beginTime.getTimeInMillis()/60000);
+    
+    public GregorianCalendar getBeginTime() {
+		return beginTime;
+	}
+
+	public GregorianCalendar getEndTime() {
+		return endTime;
+	}
+  
+    public int getLength(){
+    	return (int) ((endTime.getTimeInMillis()/60000)-(beginTime.getTimeInMillis()/60000));
     }
   
     @Override
     public String toString(){
-        return "start time: " + this.getBeginTime() + "\nend time: " + this.getEndTime() + "\nlength: " + getLength() + " Minuts";
+        return "start time: " + this.getBeginTimeString() + "\nend time: " + this.getEndTimeString() + "\nlength: " + getLength() + " Minuts";
     }
 }

+ 28 - 4
src/gui/panels/AgendaItemShape.java

@@ -2,12 +2,19 @@ package gui.panels;
 
 import java.awt.Color;
 import java.awt.Rectangle;
+import java.util.Calendar;
+
+import agenda.Act;
+import agenda.ActTime;
+import agenda.Stage;
 
 public class AgendaItemShape extends Rectangle{
 	private int row;
 	private Color color;
-	public AgendaItemShape(int r, int h, Color color) {
-		super.setSize(0, h);
+	private Act act;
+	
+	public AgendaItemShape(Act act, int r, Color color){
+		this.act=act;
 		setRow(r);
 		setColor(color);
 	}
@@ -17,13 +24,30 @@ public class AgendaItemShape extends Rectangle{
 	public void setRow(int row) {
 		this.row = row;
 	}
+	public void setStage(Stage stage, int row){
+		setRow(row);
+		act.setStage(stage);
+	}
+	public Act getAct(){
+		return act;
+	}
 	public Color getColor() {
 		return color;
 	}
 	public void setColor(Color color) {
 		this.color = color;
 	}
-	
-
+	public ActTime getTime() {
+		return act.getActTime();
+	}
+	public String getName() {
+		return act.getStage().getName();
+	}
+	public int getBeginTime(){
+		return getTime().getBeginTime().get(Calendar.MINUTE) + getTime().getBeginTime().get(Calendar.HOUR_OF_DAY)*60;
+	}
+	public int getLength(){
+		return getTime().getLength();
+	}
 	
 }

+ 74 - 28
src/gui/panels/AgendaPane.java

@@ -1,33 +1,41 @@
 package gui.panels;
 
-import java.awt.BorderLayout;
+import java.awt.BasicStroke;
 import java.awt.Color;
 import java.awt.Cursor;
+import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.Rectangle;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
-import java.awt.event.MouseMotionListener;
 import java.util.ArrayList;
-
+import java.util.Calendar;
+import java.util.GregorianCalendar;
 import javax.swing.JPanel;
 
+import agenda.Act;
+import agenda.Agenda;
+import agenda.Stage;
+
 @SuppressWarnings("serial")
 public class AgendaPane extends JPanel {
 	ArrayList<AgendaItemShape> agendaItems;
 	private int clickedItem[];
 	private int xdifference, ydifference;
-	int vakjes = 5;
+	private final int yspacing = 45;
+	private final int itempadding = 10;
+	private final int heightoffset = 100;
+	Agenda agenda;
 	
-	public AgendaPane(){
+	public AgendaPane(Agenda agenda){
+		this.agenda = agenda;
 		agendaItems = new ArrayList<AgendaItemShape>();
-		agendaItems.add(new AgendaItemShape(0, 100, Color.BLUE));
-		agendaItems.add(new AgendaItemShape(2,100, Color.BLACK));
-		
-		this.setLayout(new BorderLayout());
+		for(Act act: agenda.getActs()){
+			agendaItems.add(new AgendaItemShape(act, stageToInt(act.getStage()), Color.red));
+		}		
+		this.setPreferredSize(new Dimension(agenda.getStages().size()*100, yspacing*48+heightoffset));
 		clickedItem = new int[]{-1};
-		
 		this.addMouseListener(new MouseAdapter() {
 			@Override
 			public void mouseReleased(MouseEvent e) {
@@ -39,7 +47,7 @@ public class AgendaPane extends JPanel {
 				clickedItem = getClickedItem(e);
 				if(clickedItem[0] != -1){
 					xdifference = -1*((int)agendaItems.get(clickedItem[0]).getX() - e.getX());
-					ydifference = -1*((int)agendaItems.get(clickedItem[0]).getY() - e.getY());	
+					ydifference = -1*((int)agendaItems.get(clickedItem[0]).getY() - e.getY())+heightoffset;	
 				}				
 			}
 		});
@@ -76,26 +84,53 @@ public class AgendaPane extends JPanel {
 		return new int[]{-1}; //Clicked outside all the agenda-items so return a -1
 	}
 	
+	public int stageToInt(Stage stage){
+		return agenda.getStages().indexOf(stage);
+	}
+	public Stage intToStage(int i){
+		return agenda.getStages().get(i);
+	}
+	
 	public void paintComponent(Graphics g){
 		super.paintComponent(g);
 		Graphics2D g2 = (Graphics2D)g;		
-		int xspacing = getWidth()/vakjes;	
-		
-		for(int i = 0; i <= vakjes; i++){
+		int xspacing = getWidth()/agenda.getStages().size()+20;
+		for(int i = 0; i < agenda.getStages().size(); i++){
+			g2.setColor(Color.black);
+			g2.drawString(agenda.getStages().get(i).getName(), i*xspacing+itempadding, heightoffset/2);
+			g2.setColor(new Color (100,100,100, 70));
 			g2.drawLine(i*xspacing, getHeight(), i*xspacing, 0); //draws the vertical separation lines
 		}
+		for(int i = 0; i <= 48; i++){
+			if(i%2==0){
+				g2.setStroke(new BasicStroke(1)); //full at normal hours
+				g2.setColor(Color.BLACK);
+				g2.drawString(i/2+":00", 0, i*yspacing+heightoffset);
+				g2.setColor(new Color (100,100,100, 50));
+			}else{
+				g2.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{9}, 0)); //dashed at half hours
+			}
+			g2.drawLine(0, i*yspacing+heightoffset, getWidth(), i*yspacing+heightoffset); //draws the horizontal time lines
+		}
+		
 		for(AgendaItemShape agendaItem: agendaItems){				
-			if(clickedItem[0] == -1){ //Window is resized, only resize the items
-				agendaItem.setSize(xspacing, (int) agendaItem.getHeight());
-				agendaItem.setLocation(agendaItem.getRow()*xspacing, (int) agendaItem.getY());
+			if(clickedItem[0] == -1){ //Window is resized, only resize & place the items 
+				agendaItem.setSize(xspacing-itempadding*2, (int) (agendaItem.getLength()* (yspacing/30.0)));
+				agendaItem.setLocation(agendaItem.getRow()*xspacing+itempadding, (int) (agendaItem.getBeginTime() * (yspacing/30.0)+heightoffset));
 			}else if(agendaItems.get(clickedItem[0]) == agendaItem){ // The element is moved
-				if(agendaItem.getX() / xspacing > vakjes-1){ // outside the field on the right
-					agendaItem.setLocation((int)xspacing*(vakjes-1), (int)agendaItem.getY());
-				}else if(agendaItem.getX() / xspacing < 0){ // outside the field on the left
-					agendaItem.setLocation((int)0, (int)agendaItem.getY());
-				}else{ //inside the field, stick it to a row
-					agendaItem.setRow((int) Math.round(agendaItem.getX() / xspacing));
-					agendaItem.setLocation((int) Math.round(agendaItem.getX() / xspacing)*xspacing, (int)agendaItem.getY());
+				if(clickedItem[1] == 0){ //if the item is moved, not resized
+					if(agendaItem.getX() / xspacing > agenda.getStages().size()-1){ // outside the window on the right
+						agendaItem.setLocation((int)xspacing*(agenda.getStages().size()-1)+itempadding, (int)agendaItem.getY()+heightoffset);
+					}else if(agendaItem.getX() / xspacing < 0){ // outside the window on the left
+						agendaItem.setLocation((int)itempadding, (int)agendaItem.getY()+heightoffset);
+					}else{ //inside the window, stick it to a row
+						agendaItem.setLocation((int) Math.round(agendaItem.getX() / xspacing)*xspacing+itempadding, (int)agendaItem.getY()+heightoffset);
+					}
+					if(agendaItem.getY() < heightoffset){ // outside the window on the top
+						agendaItem.setLocation((int)agendaItem.getX(), heightoffset);
+					}else if(agendaItem.getHeight() > 48*yspacing+heightoffset){ // outside the window on the bottom
+						agendaItem.setLocation((int)agendaItem.getX(),48*yspacing+heightoffset);
+					}	
 				}
 				
 				if(agendaItem.getHeight() < 30){ //check the height of the item
@@ -107,7 +142,7 @@ public class AgendaPane extends JPanel {
 						if(agendaItem.intersects(agendaItem2)){	//intersection found
 							if( agendaItem.getHeight()+agendaItem.getY() > agendaItem2.getY() && agendaItem.getY() > agendaItem2.getY()){
 								agendaItem.setLocation((int)agendaItem.getX(), (int)(agendaItem2.getY()+agendaItem2.getHeight()));
-							}else if(agendaItem.getY() < agendaItem2.getY()){
+							}else if(agendaItem.getY() <= agendaItem2.getY()){
 								if(clickedItem[1] == 0){
 									agendaItem.setLocation((int)agendaItem.getX(), (int)(agendaItem2.getY()-agendaItem.getHeight()));
 								}else if(clickedItem[1] == 2){
@@ -116,11 +151,22 @@ public class AgendaPane extends JPanel {
 							}
 						}
 					}
-				}	
+				}	 
+				//update the new data to the Act
+				agendaItem.setStage(intToStage((int) Math.round(agendaItem.getX() / xspacing)), (int) Math.round(agendaItem.getX() / xspacing));
+				agendaItem.getTime().getBeginTime().set((GregorianCalendar.MINUTE), (int) Math.round((agendaItem.getY()-heightoffset)/45*30)%60);
+				agendaItem.getTime().getBeginTime().set((GregorianCalendar.HOUR_OF_DAY), (int) Math.round((agendaItem.getY()-heightoffset)/45*30)/60);
+				agendaItem.getTime().getEndTime().set(GregorianCalendar.MINUTE, (int) Math.round((agendaItem.getY()+agendaItem.getHeight()-heightoffset)/45*30)%60);
+				agendaItem.getTime().getEndTime().set(GregorianCalendar.HOUR_OF_DAY, (int) Math.round((agendaItem.getY()+agendaItem.getHeight()-heightoffset)/45*30)/60);
+
 			}
-			//Fills the item with a color 
-			g2.setColor(agendaItem.getColor());
+			
+			g2.setColor(agendaItem.getColor());			//Fills the item with a color 
 			g2.fill(agendaItem);
+			g2.setColor(Color.WHITE);
+			g2.drawString(agendaItem.getName(), (int)agendaItem.getX() +5, (int)agendaItem.getY() +15);
+			g2.drawString(agendaItem.getTime().getBeginTimeString(), (int)agendaItem.getX() +5, (int)agendaItem.getY() +30);
+			g2.drawString(agendaItem.getTime().getEndTimeString(), (int)agendaItem.getX() +5, (int)agendaItem.getY() +45);		
 		}
 	}	
 }

+ 13 - 2
src/gui/panels/MainPanel.java

@@ -3,14 +3,25 @@ package gui.panels;
 import java.awt.BorderLayout;
 
 import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+import agenda.Agenda;
 
 @SuppressWarnings("serial")
 public class MainPanel extends JPanel{
 	public MainPanel(){
 		this.setLayout(new BorderLayout());
 		this.add(new InfoPane(), BorderLayout.WEST);
-		this.add(new AgendaPane(), BorderLayout.CENTER);;
-		this.add(new DaySelectorPane(), BorderLayout.SOUTH);
+		
+		Agenda agenda = new Agenda();
+		AgendaPane agendapanel = new AgendaPane(agenda);
+		
+		JScrollPane scroll = new JScrollPane(agendapanel);
+		scroll.getVerticalScrollBar().setUnitIncrement(20);
+		
+		
+		this.add(scroll, BorderLayout.CENTER);
+		
 		
 	}
 }