Sfoglia il codice sorgente

Time editing and popularity added.

Gilian Joosen 10 anni fa
parent
commit
d769a2155f
3 ha cambiato i file con 130 aggiunte e 23 eliminazioni
  1. 16 2
      src/agenda/Act.java
  2. 30 0
      src/agenda/ActTime.java
  3. 84 21
      src/gui/panels/edit/dialogs/ActDialogPanel.java

+ 16 - 2
src/agenda/Act.java

@@ -13,12 +13,14 @@ public class Act implements Serializable  {
     private Stage stage;
     private String genre, name;
     private ActTime actTime;
-
-    public Act(String name, Stage stage, String genre, ActTime actTime, Artist... artists){
+    private int popularity;
+    
+    public Act(String name, Stage stage, String genre, ActTime actTime, int popularity, Artist... artists){
         this.name = name;
         this.stage = stage; 
         this.genre = genre;
         this.actTime = actTime;
+        this.popularity = popularity;
 
         this.artists = new ArrayList<Artist>();
         for(Artist artist: artists) {
@@ -101,4 +103,16 @@ public class Act implements Serializable  {
             this.artists.add(artist);
         }
     }
+
+    public int getPopularity() {
+        return popularity;
+    }
+
+    public void setPopularity(int popularity) {
+        this.popularity = popularity;
+    }
+
+    public void setActTime(ActTime actTime) {
+        this.actTime = actTime;
+    }
 }

+ 30 - 0
src/agenda/ActTime.java

@@ -61,6 +61,21 @@ public class ActTime implements Serializable {
     			beginTime.get(Calendar.HOUR_OF_DAY) + ":" +
     			minutes;
     }
+
+    public String getBeginTimeStringField(){
+        String minutes = "";
+        if(beginTime.get(Calendar.MINUTE)>=0 && beginTime.get(Calendar.MINUTE)<10){
+            minutes = "0"+beginTime.get(Calendar.MINUTE);
+        } else {
+            minutes = ""+beginTime.get(Calendar.MINUTE);
+        }
+
+        return 	beginTime.get(Calendar.YEAR) + "-" +
+                (beginTime.get(Calendar.MONTH)+1) + "-" +
+                beginTime.get(Calendar.DATE) + "-" +
+                beginTime.get(Calendar.HOUR_OF_DAY) + "-" +
+                minutes;
+    }
     
     public String getEndTimeString(){
     	String minutes = "";
@@ -75,6 +90,21 @@ public class ActTime implements Serializable {
     			endTime.get(Calendar.HOUR_OF_DAY) + ":" +
     			minutes;
     }
+
+    public String getEndTimeStringField(){
+        String minutes = "";
+        if(endTime.get(Calendar.MINUTE)>=0 && endTime.get(Calendar.MINUTE)<10){
+            minutes = "0"+endTime.get(Calendar.MINUTE);
+        } else {
+            minutes = ""+endTime.get(Calendar.MINUTE);
+        }
+        return 	endTime.get(Calendar.YEAR) + "-" +
+                (endTime.get(Calendar.MONTH)+1) + "-" +
+                endTime.get(Calendar.DATE) + "-" +
+                endTime.get(Calendar.HOUR_OF_DAY) + "-" +
+                minutes;
+    }
+    
     public GregorianCalendar getBeginTime() {
 		return beginTime;
 	}

+ 84 - 21
src/gui/panels/edit/dialogs/ActDialogPanel.java

@@ -9,27 +9,17 @@ import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
 
-import javax.swing.BorderFactory;
-import javax.swing.BoxLayout;
-import javax.swing.DefaultListModel;
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-import javax.swing.JComboBox;
-import javax.swing.JDialog;
-import javax.swing.JLabel;
-import javax.swing.JList;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTextField;
-import javax.swing.ListCellRenderer;
+import javax.swing.*;
 
 import agenda.Act;
 import agenda.ActTime;
 import agenda.Agenda;
 import agenda.Artist;
 import agenda.Stage;
+import javafx.scene.control.RadioButton;
 
 /**
  * Created by gjoosen on 20/02/15.
@@ -39,7 +29,9 @@ public class ActDialogPanel extends JDialog{
     private Agenda agenda;
     private JTextField name, genre, beginTime, endTime;
     private JComboBox stageComboBox;
-
+    private JRadioButton radio1, radio2, radio3, radio4, radio5;
+    private ButtonGroup radioButtons;
+    
     private DefaultListModel model;
     private final DefaultListModel  artistModel = new DefaultListModel();
     private Act act;
@@ -63,6 +55,7 @@ public class ActDialogPanel extends JDialog{
         main.add(this.genreChooser());
         //todo dates
         main.add(this.dates());
+        main.add(this.popularity());
         main.add(this.artistsChooser());
         
         main.add(this.buttons());
@@ -95,9 +88,13 @@ public class ActDialogPanel extends JDialog{
         for(Artist artist: this.act.getArtists()){
             this.artistModel.addElement(artist);
         }
-        
+        main.add(this.popularity(act.getPopularity()));
         main.add(this.artistsChooser());
         main.add(this.buttons());
+        
+        //set time
+        this.beginTime.setText(this.act.getActTime().getBeginTimeStringField());
+        this.endTime.setText(this.act.getActTime().getEndTimeStringField());
         super.add(main);
     }
     
@@ -211,6 +208,59 @@ public class ActDialogPanel extends JDialog{
         return panel;
     }
     
+    private JPanel popularity(){
+        return this.popularity(3);
+    }
+
+    private JPanel popularity(int number){
+        JPanel panel = new JPanel();
+        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+        panel.add(new JLabel("popularity"));
+
+        JPanel buttons = new JPanel();
+        buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
+
+        this.radio1 = new JRadioButton("1");
+        this.radio2 = new JRadioButton("2");
+        this.radio3 = new JRadioButton("3");
+        this.radio4 = new JRadioButton("4");
+        this.radio5 = new JRadioButton("5");
+        
+        switch(number){
+            case 1:
+                this.radio1.setSelected(true);
+                break;
+            case 2:       
+                this.radio2.setSelected(true);
+                break;
+            case 3:
+                this.radio3.setSelected(true);
+                break;
+            case 4:
+                this.radio4.setSelected(true);
+                break;
+            case 5:
+                this.radio5.setSelected(true);
+                break;
+        }
+
+        buttons.add(this.radio1);
+        buttons.add(this.radio2);
+        buttons.add(this.radio3);
+        buttons.add(this.radio4);
+        buttons.add(this.radio5);
+
+        this.radioButtons = new ButtonGroup();
+        this.radioButtons.add(this.radio1);
+        this.radioButtons.add(this.radio2);
+        this.radioButtons.add(this.radio3);
+        this.radioButtons.add(this.radio4);
+        this.radioButtons.add(this.radio5);
+
+        panel.add(buttons);
+        return panel;
+    }
+    
     private JPanel artistsChooser(){
         JPanel artists = new JPanel();
         artists.setOpaque(false);
@@ -230,7 +280,7 @@ public class ActDialogPanel extends JDialog{
         buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
         
         JLabel addArtists = new JLabel();
-        addArtists.setIcon(new ImageIcon("E:\\Bibliotheek\\Documenten\\Workspaces\\FestivalPlanner\\res\\add.png"));
+        addArtists.setIcon(new ImageIcon(getClass().getResource("/add.png")));
         addArtists.setForeground(new Color(51,51,51));
         addArtists.addMouseListener(new MouseListener() {
 			@Override
@@ -298,7 +348,7 @@ public class ActDialogPanel extends JDialog{
 		});
         
         JLabel removeButton = new JLabel();
-        removeButton.setIcon(new ImageIcon("E:\\Bibliotheek\\Documenten\\Workspaces\\FestivalPlanner\\res\\remove.png"));
+        removeButton.setIcon(new ImageIcon(getClass().getResource("/remove.png")));
         removeButton.addMouseListener(new MouseListener() {
 			@Override
 			public void mouseClicked(MouseEvent e) {
@@ -379,7 +429,7 @@ public class ActDialogPanel extends JDialog{
         
         
         if(this.act == null){
-            Act act = new Act(this.name.getText(), (Stage) this.stageComboBox.getSelectedItem(), this.genre.getText(), new ActTime(this.beginTime.getText(), this.endTime.getText()), artists);
+            Act act = new Act(this.name.getText(), (Stage) this.stageComboBox.getSelectedItem(), this.genre.getText(), new ActTime(this.beginTime.getText(), this.endTime.getText()), this.getSelectedButtonNumber() ,artists);
             this.model.addElement(act);
             this.agenda.addAct(act);
         }else{
@@ -388,18 +438,31 @@ public class ActDialogPanel extends JDialog{
             this.act.setStage((Stage) this.stageComboBox.getSelectedItem());
             this.act.setArtists(artists);
             this.act.setTime(new ActTime(this.beginTime.getText(), this.endTime.getText()));
+            this.act.setPopularity(this.getSelectedButtonNumber());
+            this.act.setActTime(new ActTime(this.beginTime.getText(), this.endTime.getText()));
             this.model.removeElement(this.act);
             this.model.addElement(act);
         }
-        
         System.out.println(act);
         dispose();
-
     }
 
     private void cancel(){
         dispose();
     }
+    
+    private int getSelectedButtonNumber(){
+
+        Enumeration<AbstractButton> buttons = this.radioButtons.getElements();
+        
+        while(buttons.hasMoreElements()){
+            AbstractButton button = buttons.nextElement();
+            if(button.isSelected()){
+                return Integer.valueOf(button.getText());
+            }
+        }
+        return -1;
+    }
 }
 
 class ArtistCellRenderer extends JLabel implements ListCellRenderer {