瀏覽代碼

Bugfixes and optimalisation

jancoow 10 年之前
父節點
當前提交
2b3045b4cb

+ 1 - 0
src/gui/panels/agenda/AgendaItemShape.java

@@ -9,6 +9,7 @@ import agenda.ActTime;
 import agenda.Artist;
 import agenda.Stage;
 
+@SuppressWarnings("serial")
 public class AgendaItemShape extends Rectangle{
 	private int row;
 	private Color color;

+ 15 - 4
src/gui/panels/agenda/AgendaPane.java

@@ -15,20 +15,31 @@ import agenda.Agenda;
 public class AgendaPane extends JPanel {
 	private GregorianCalendar currentdate;
 	private	DaySelectorPane dayselector;
+	private InfoPane infopanel;
 	private final AgendaScrollPane agendapanel;
 	
 	public AgendaPane(Agenda agenda){
 		setLayout(new BorderLayout());
-		currentdate = new GregorianCalendar(2015, 1, 11);
-		
-		agendapanel = new AgendaScrollPane(agenda, currentdate);
+
+		agendapanel = new AgendaScrollPane(agenda);
 		dayselector = new DaySelectorPane();
+		infopanel = new InfoPane();
+		
 		JScrollPane scroll = new JScrollPane(agendapanel);
 		scroll.getVerticalScrollBar().setUnitIncrement(20);
 		
 		this.add(scroll, BorderLayout.CENTER);
 		this.add(dayselector, BorderLayout.SOUTH);
-		dayselector.setDate(currentdate);
+		this.add(infopanel, BorderLayout.WEST);
+		
+		if(agenda.getActs().size()==0){
+			setCurrentdate(new GregorianCalendar());
+		}else{
+			GregorianCalendar date = agenda.getActs().get(0).getActTime().getBeginTime();
+			setCurrentdate(new GregorianCalendar(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH)));
+		}
+
+
 		dayselector.getButtonLeft().addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {

+ 65 - 51
src/gui/panels/agenda/AgendaScrollPane.java

@@ -29,18 +29,17 @@ public class AgendaScrollPane extends JPanel {
 	GregorianCalendar currentdate;
 	Agenda agenda;
 	
-	public AgendaScrollPane(final Agenda agenda, GregorianCalendar date){
+	public AgendaScrollPane(final Agenda agenda){
 		this.agenda = agenda;
 		this.setPreferredSize(new Dimension(600, yspacing*48+heightoffset));
 		agendaItems = new ArrayList<AgendaItemShape>();
 		clickedItem = new int[]{-1};
-		setDate(date);
 
 		this.addMouseListener(new MouseAdapter() {
 			@Override
 			public void mouseReleased(MouseEvent e) {
-				clickedItem = new int[]{-1};			
-				setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+				clickedItem = new int[]{-1};
+				getClickedItem(e);
 			}
 			@Override
 			public void mousePressed(MouseEvent e) {
@@ -48,10 +47,15 @@ public class AgendaScrollPane extends JPanel {
 				if(clickedItem[0] != -1){
 					xdifference = -1*((int)agendaItems.get(clickedItem[0]).getX() - e.getX());
 					ydifference = -1*((int)agendaItems.get(clickedItem[0]).getY() - e.getY())+heightoffset;	
-				}				
+				}		
+				repaint();
 			}
 		});
 		this.addMouseMotionListener(new MouseAdapter() {	
+			@Override
+			public void mouseMoved(MouseEvent e){
+				getClickedItem(e);
+			}
 			@Override
 			public void mouseDragged(MouseEvent e) {
 				if(clickedItem[0] != -1){
@@ -61,7 +65,6 @@ public class AgendaScrollPane extends JPanel {
 					}else{
 						item.setLocation(e.getX()-xdifference, e.getY()-ydifference);
 					}
-					
 					for(AgendaItemShape agendaItem: agendaItems){	
 						if(clickedItem[0] == -1){ //Window is resized, only resize & place the items 
 							agendaItem.setSize(xspacing-itempadding*2, (int) (agendaItem.getHeight()));
@@ -75,11 +78,6 @@ public class AgendaScrollPane extends JPanel {
 								}else{ //inside the window, stick it to a stage
 									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()+agendaItem.getY() > 48*yspacing+heightoffset){ // outside the window on the bottom
-////									agendaItem.setLocation((int)agendaItem.getX(),(48*yspacing+heightoffset)-(int)agendaItem.getHeight()-1);
-////								}	
 							}else if(clickedItem[1] == 2){ //agenda item is resized
 								if(agendaItem.getHeight() < 30){ //check the height of the item
 									agendaItem.setSize((int) agendaItem.getWidth(), 30);
@@ -87,24 +85,7 @@ public class AgendaScrollPane extends JPanel {
 									agendaItem.setSize((int)agendaItem.getWidth(),(int) ((48*yspacing+heightoffset)-agendaItem.getY()-1));
 								}		
 							}
-							for(AgendaItemShape agendaItem2: agendaItems){ //check if there are any collisions with other items
-								if(agendaItem2 != agendaItem){
-									if(agendaItem.intersects(agendaItem2)){	//intersection found
-										if( agendaItem.getHeight()+agendaItem.getY() > agendaItem2.getY() && agendaItem.getY() > agendaItem2.getY()){//collision on the bottom of another item
-											agendaItem.setLocation((int)agendaItem.getX(), (int)(agendaItem2.getY()+agendaItem2.getHeight()));
-										}else if(agendaItem.getY() <= agendaItem2.getY()){//collision on the top of another item
-											if(clickedItem[1] == 0){//item was moved, only change location
-												agendaItem.setLocation((int)agendaItem.getX(), (int)(agendaItem2.getY()-agendaItem.getHeight()));
-												if(agendaItem.getY() < heightoffset){
-													agendaItem.y = (int) (agendaItem2.getY() + agendaItem2.getHeight());
-												}
-											}else if(clickedItem[1] == 2){//item was resized, only change the size
-												agendaItem.setSize((int)agendaItem.getWidth(), (int)(agendaItem2.getY()-agendaItem.getY()));
-											}
-										}
-									}
-								}
-							}	 
+							checkCollision(agendaItem);
 							//update the new data to the Act
 							agendaItem.setStage(agenda.getStages().get((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);
@@ -120,30 +101,55 @@ public class AgendaScrollPane extends JPanel {
 			}
 		});
 	}
-	
+	public void checkCollision(AgendaItemShape agendaItem){
+		for(int i = 0; i < agendaItems.size(); i++){ //check if there are any collisions with other items
+			AgendaItemShape agendaItem2 = agendaItems.get(i);
+			if(agendaItem2 != agendaItem){
+				if(agendaItem.intersects(agendaItem2)){	//intersection found
+					if( agendaItem.getHeight()+agendaItem.getY() > agendaItem2.getY() && agendaItem.getY() > agendaItem2.getY()){//collision on the bottom of another item
+						agendaItem.setLocation((int)agendaItem.getX(), (int)(agendaItem2.getY()+agendaItem2.getHeight()));
+					}else if(agendaItem.getY() <= agendaItem2.getY()){//collision on the top of another item
+						if(clickedItem[1] == 0){//item was moved, only change location
+							agendaItem.setLocation((int)agendaItem.getX(), (int)(agendaItem2.getY()-agendaItem.getHeight()));
+							if(agendaItem.getY() < heightoffset){
+								agendaItem.y = (int) (agendaItem2.getY() + agendaItem2.getHeight());
+							}
+						}else if(clickedItem[1] == 2){//item was resized, only change the size
+							agendaItem.setSize((int)agendaItem.getWidth(), (int)(agendaItem2.getY()-agendaItem.getY()));
+						}
+					}	
+				}
+			}
+		}
+	}
 	public int[] getClickedItem(MouseEvent e){
-		if(e.getButton() == 1){
-			for(int i = 0; i < agendaItems.size(); i++){
-				if(agendaItems.get(i).intersects(e.getX(), e.getY(), 1, 1)){
-					if(	agendaItems.get(i).getY()+agendaItems.get(i).getHeight()+10 > e.getY() &&
-						agendaItems.get(i).getY()+agendaItems.get(i).getHeight()-10 < e.getY()){
-						setCursor(new Cursor(Cursor.S_RESIZE_CURSOR));
+		for(int i = 0; i < agendaItems.size(); i++){
+			if(agendaItems.get(i).intersects(e.getX(), e.getY()-10, 1, 10)){
+				if(	agendaItems.get(i).getY()+agendaItems.get(i).getHeight()+10 > e.getY() &&
+					agendaItems.get(i).getY()+agendaItems.get(i).getHeight()-10 < e.getY()){
+					setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
+					if(e.getButton() == 1){
 						return new int[]{i, 2}; //Clicked on the bottom border of the item
 					}
-					setCursor(new Cursor(Cursor.MOVE_CURSOR));
+					return new int[]{-1};
+				}
+				if(e.getButton() == 1){
+					setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
 					return new int[]{i, 0}; // Clicked inside the item
+				}else{
+					setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+					return new int[]{-1};
 				}
 			}
 		}
+		setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
 		return new int[]{-1}; //Clicked outside all the agenda-items so return a -1
 	}	
 	public void setDate(GregorianCalendar date){
 		agendaItems.clear();
 		currentdate = date;
-		for(Act act: agenda.getActs()){
-			GregorianCalendar begintime = act.getActTime().getBeginTime();
-			GregorianCalendar endtime = act.getActTime().getEndTime();
-			if(currentdate.compareTo(begintime) <= 1 && currentdate.compareTo(endtime) >= -1){
+		for(Act act : agenda.getActs()){
+			if(currentdate.compareTo(act.getActTime().getBeginTime()) <= 1 && currentdate.compareTo(act.getActTime().getEndTime()) >= -1){
 				agendaItems.add(new AgendaItemShape(act, agenda.getStages().indexOf(act.getStage()), new Color(250,209,101)));
 			}
 		}
@@ -155,18 +161,12 @@ public class AgendaScrollPane extends JPanel {
 	}
 	public void paintComponent(Graphics g){
 		super.paintComponent(g);
-		Graphics2D g2 = (Graphics2D)g;		
+		Graphics2D g2 = (Graphics2D)g;	
         if(agenda.getStages().size() == 0){
             xspacing = 0;
         }else{
             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
@@ -183,10 +183,14 @@ public class AgendaScrollPane extends JPanel {
 			if(clickedItem[0] == -1){ //Window is resized, only resize & place the items 
 				agendaItem.setSize(xspacing-itempadding*2, (int) (agendaItem.getHeight()));
 				agendaItem.setLocation(agendaItem.getRow()*xspacing+itempadding, (int) agendaItem.getY());
-			}			
-			g2.setColor(agendaItem.getColor());			//Fills the item with a given 
+			}
+			g2.setColor(agendaItem.getColor());			//Fills the item with a given color
 			g2.fill(agendaItem);
-			g2.setColor(agendaItem.getColor().darker());
+			if(clickedItem[0] != -1 && agendaItems.get(clickedItem[0]) == agendaItem){
+				g2.setColor(Color.black);	
+			}else{
+				g2.setColor(agendaItem.getColor().darker());
+			}
 			g2.draw(agendaItem);
 			g2.setColor(Color.BLACK);
 			
@@ -196,7 +200,17 @@ public class AgendaScrollPane extends JPanel {
 				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);
+				g2.setColor(Color.GRAY);
+				g2.drawString(".....", (int)(agendaItem.getX() + agendaItem.getWidth()/2), (int)(agendaItem.getY()+agendaItem.getHeight()-10));
 			}
 		}
+		g2.setColor(Color.LIGHT_GRAY);
+		g2.fillRect(0, 0, getWidth(), heightoffset);
+		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
+		}
 	}	
 }

+ 1 - 0
src/gui/panels/agenda/DaySelectorPane.java

@@ -8,6 +8,7 @@ import javax.swing.JButton;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 
+@SuppressWarnings("serial")
 public class DaySelectorPane extends JPanel{
 	private JButton buttonLeft, buttonRight;
 	private JLabel dateLabel;