Added add/edit/remove projection dialog, agenda adaptation
This commit is contained in:
parent
cb1ba75d4a
commit
44482bae78
8 changed files with 292 additions and 25 deletions
|
@ -1,12 +1,10 @@
|
|||
package GUI;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.event.MouseInputAdapter;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Agenda extends JPanel {
|
||||
|
@ -20,8 +18,12 @@ public class Agenda extends JPanel {
|
|||
this.totalDay = totalDay;
|
||||
this.currentPage = currentPage;
|
||||
this.agendaPanel.removeAll();
|
||||
System.out.println("lolilol");
|
||||
int totalPages[] = dayToPage(9);
|
||||
if (this.currentPage >= totalPages.length) {
|
||||
this.currentPage = totalPages.length - 1;
|
||||
} else if (this.currentPage < 0) {
|
||||
this.currentPage = 0;
|
||||
}
|
||||
JScrollPane scroll = constructAgenda(totalPages[this.currentPage]);
|
||||
agendaPanel.add(scroll);
|
||||
}
|
||||
|
@ -44,25 +46,50 @@ public class Agenda extends JPanel {
|
|||
public int getSize() {
|
||||
return headers.length;
|
||||
}
|
||||
|
||||
public Object getElementAt(int index) {
|
||||
return headers[index];
|
||||
}
|
||||
};
|
||||
MyTableModel dm = new MyTableModel(day, currentPage);
|
||||
TableModel dm = new TableModel(day, currentPage, headers.length);
|
||||
JTable table = new JTable(dm) {
|
||||
@Override
|
||||
public Dimension getPreferredScrollableViewportSize() {
|
||||
return new Dimension(super.getPreferredSize().width, getRowHeight()*(getRowCount()-1)-20);
|
||||
public boolean getScrollableTracksViewportHeight() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
System.out.println(table.getRowHeight());
|
||||
table.setCellSelectionEnabled(true);
|
||||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
table.setRowHeight(100);
|
||||
table.addMouseListener(new MouseInputAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent mouseEvent) {
|
||||
JTable table = (JTable) mouseEvent.getSource();
|
||||
Point point = mouseEvent.getPoint();
|
||||
int row = table.getSelectedRow();
|
||||
int column = table.getSelectedColumn();
|
||||
if (mouseEvent.getClickCount() == 2 && table.getSelectedRow() != -1) {
|
||||
ProjectionHandler dialog;
|
||||
if (table.getValueAt(row, column) == "") {
|
||||
dialog = new ProjectionHandler(ProjectionType.ADD);
|
||||
} else {
|
||||
dialog = new ProjectionHandler(ProjectionType.EDIT);
|
||||
}
|
||||
dialog.pack();
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
TableColumnModel columnModel = table.getColumnModel();
|
||||
int columnCount = columnModel.getColumnCount();
|
||||
for (int i = 0; i < columnCount; i++) {
|
||||
table.getColumnModel().getColumn(i).setPreferredWidth(200);
|
||||
}
|
||||
|
||||
|
||||
JList rowHeader = new JList(lm);
|
||||
rowHeader.setFixedCellWidth(100);
|
||||
rowHeader.setFixedCellHeight(100);
|
||||
|
@ -73,7 +100,12 @@ public class Agenda extends JPanel {
|
|||
scroll.setRowHeaderView(rowHeader);
|
||||
scroll.setBorder(BorderFactory.createEmptyBorder());
|
||||
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
|
||||
this.agendaPanel.setPreferredSize(new Dimension(this.agendaPanel.getWidth(), headers.length * 100 + 20));
|
||||
|
||||
return scroll;
|
||||
}
|
||||
|
||||
public int getCurrentPage() {
|
||||
return this.currentPage;
|
||||
}
|
||||
}
|
||||
|
|
5
src/main/java/GUI/CompetType.java
Normal file
5
src/main/java/GUI/CompetType.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package GUI;
|
||||
|
||||
public enum CompetType {
|
||||
LM, UCR, HC
|
||||
}
|
|
@ -10,10 +10,7 @@
|
|||
<children>
|
||||
<grid id="6e52f" binding="agendaPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="5" vsize-policy="7" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="1000" height="-1"/>
|
||||
<preferred-size width="1000" height="-1"/>
|
||||
</grid>
|
||||
<grid row="1" column="0" row-span="1" col-span="5" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="empty">
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
package GUI;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.plaf.basic.BasicArrowButton;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.TableModel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
|
@ -25,10 +20,13 @@ public class GUI extends JFrame implements ActionListener {
|
|||
private JMenuItem menuItemRemoveProj = new JMenuItem("Remove projection");
|
||||
private int currentPage;
|
||||
String headers[] = {"Matin", "Midi", "<html>Milieu<br/>Après-midi</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
||||
private CompetType currentCompetition = CompetType.LM;
|
||||
|
||||
public GUI() {
|
||||
super();
|
||||
construct();
|
||||
}
|
||||
|
||||
private void renderMenu() {
|
||||
menuBar.add(menuFichier);
|
||||
menuFichier.add(menuItemAddProj);
|
||||
|
@ -51,6 +49,12 @@ public class GUI extends JFrame implements ActionListener {
|
|||
System.out.println("agenda");
|
||||
previousButton.addActionListener(this);
|
||||
nextButton.addActionListener(this);
|
||||
HCButton.addActionListener(this);
|
||||
LMButton.addActionListener(this);
|
||||
UCRButton.addActionListener(this);
|
||||
menuItemAddProj.addActionListener(this);
|
||||
menuItemEditProj.addActionListener(this);
|
||||
menuItemRemoveProj.addActionListener(this);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
|
@ -59,15 +63,48 @@ public class GUI extends JFrame implements ActionListener {
|
|||
Object source = e.getSource();
|
||||
if (source == previousButton) {
|
||||
this.currentPage--;
|
||||
new Agenda(agendaPanel, headers, 8, this.currentPage);
|
||||
Agenda agenda = new Agenda(agendaPanel, headers, 8, this.currentPage);
|
||||
this.currentPage = agenda.getCurrentPage();
|
||||
this.repaint();
|
||||
this.revalidate();
|
||||
}
|
||||
else if (source == nextButton) {
|
||||
this.currentPage++;
|
||||
new Agenda(agendaPanel, headers, 8, this.currentPage);
|
||||
Agenda agenda = new Agenda(agendaPanel, headers, 8, this.currentPage);
|
||||
this.currentPage = agenda.getCurrentPage();
|
||||
|
||||
this.repaint();
|
||||
this.revalidate();
|
||||
} else if (source == LMButton) {
|
||||
this.headers = new String[]{"Matin", "Midi", "<html>Milieu<br/>Après-midi</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
||||
Agenda agenda = new Agenda(agendaPanel, headers, 8, 0);
|
||||
currentCompetition = CompetType.LM;
|
||||
this.repaint();
|
||||
this.revalidate();
|
||||
} else if (source == HCButton) {
|
||||
this.headers = new String[]{"<html>Fin<br/>Matinée</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
||||
Agenda agenda = new Agenda(agendaPanel, headers, 8, 0);
|
||||
currentCompetition = CompetType.HC;
|
||||
this.repaint();
|
||||
this.revalidate();
|
||||
} else if (source == UCRButton) {
|
||||
this.headers = new String[]{"Matin", "Midi", "<html>Milieu<br/>Après-midi</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
||||
Agenda agenda = new Agenda(agendaPanel, headers, 8, 0);
|
||||
currentCompetition = CompetType.UCR;
|
||||
this.repaint();
|
||||
this.revalidate();
|
||||
} else if (source == this.menuItemAddProj) {
|
||||
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.ADD);
|
||||
dialog.pack();
|
||||
dialog.setVisible(true);
|
||||
} else if (source == this.menuItemEditProj) {
|
||||
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.EDIT);
|
||||
dialog.pack();
|
||||
dialog.setVisible(true);
|
||||
} else if (source == this.menuItemRemoveProj) {
|
||||
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.REMOVE);
|
||||
dialog.pack();
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
125
src/main/java/GUI/ProjectionHandler.form
Normal file
125
src/main/java/GUI/ProjectionHandler.form
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="GUI.ProjectionHandler">
|
||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="10" bottom="10" right="10"/>
|
||||
<constraints>
|
||||
<xy x="48" y="54" width="436" height="297"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="98ce1" binding="competitionPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="11335" class="javax.swing.JLabel" binding="competitionLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="10" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Competition"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9a08d" class="javax.swing.JComboBox" binding="competitionComboBox">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="9" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="66435" binding="slotPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="6aae7" class="javax.swing.JLabel" binding="slotLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="10" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Slot"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="cdf9a" class="javax.swing.JComboBox" binding="slotComboBox">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="9" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="38155" binding="dayPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="447af" class="javax.swing.JLabel" binding="dayLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="10" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Day"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f63b7" class="javax.swing.JComboBox" binding="dayComboBox">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="9" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="6eea5" class="javax.swing.JButton" binding="cancelButton">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Cancel"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9b61e" class="javax.swing.JButton" binding="confirmButton">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Button"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="37be2" binding="filmPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="febba" class="javax.swing.JLabel" binding="filmLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="10" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Film"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="80251" class="javax.swing.JComboBox" binding="filmComboBox">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="9" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
61
src/main/java/GUI/ProjectionHandler.java
Normal file
61
src/main/java/GUI/ProjectionHandler.java
Normal file
|
@ -0,0 +1,61 @@
|
|||
package GUI;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
public class ProjectionHandler extends JDialog {
|
||||
private JPanel contentPane;
|
||||
private JButton cancelButton;
|
||||
private JButton confirmButton;
|
||||
private JComboBox competitionComboBox;
|
||||
private JComboBox dayComboBox;
|
||||
private JComboBox slotComboBox;
|
||||
private JPanel competitionPanel;
|
||||
private JPanel slotPanel;
|
||||
private JPanel dayPanel;
|
||||
private JLabel competitionLabel;
|
||||
private JLabel slotLabel;
|
||||
private JLabel dayLabel;
|
||||
private JPanel filmPanel;
|
||||
private JLabel filmLabel;
|
||||
private JComboBox filmComboBox;
|
||||
private ProjectionType projectionType;
|
||||
|
||||
public ProjectionHandler(ProjectionType projectionType) {
|
||||
this.projectionType = projectionType;
|
||||
setContentPane(contentPane);
|
||||
setModal(true);
|
||||
setPreferredSize(new Dimension(500, 300));
|
||||
handleDialogName();
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleDialogName() {
|
||||
switch (this.projectionType) {
|
||||
case ADD: {
|
||||
setTitle("Add projection");
|
||||
confirmButton.setText("Add");
|
||||
break;
|
||||
}
|
||||
case EDIT: {
|
||||
setTitle("Edit projection");
|
||||
confirmButton.setText("Edit");
|
||||
break;
|
||||
}
|
||||
case REMOVE: {
|
||||
setTitle("Remove projection");
|
||||
confirmButton.setText("remove");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
5
src/main/java/GUI/ProjectionType.java
Normal file
5
src/main/java/GUI/ProjectionType.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package GUI;
|
||||
|
||||
public enum ProjectionType {
|
||||
ADD, EDIT, REMOVE
|
||||
}
|
|
@ -3,11 +3,13 @@ package GUI;
|
|||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MyTableModel extends AbstractTableModel {
|
||||
public class TableModel extends AbstractTableModel {
|
||||
private String[] columnNames;
|
||||
private Object[][] data;
|
||||
private int headerSize;
|
||||
private int day;
|
||||
public MyTableModel(int day, int currentPage) {
|
||||
|
||||
public TableModel(int day, int currentPage, int headerSize) {
|
||||
this.day = day;
|
||||
columnNames = new String[this.day];
|
||||
data = new Object[5][this.day];
|
||||
|
@ -17,7 +19,6 @@ public class MyTableModel extends AbstractTableModel {
|
|||
for (int i = 0; i < 5; i++) {
|
||||
Arrays.fill(data[i], "");
|
||||
}
|
||||
System.out.println(Arrays.toString(this.columnNames));
|
||||
}
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
|
@ -39,4 +40,8 @@ public class MyTableModel extends AbstractTableModel {
|
|||
return data[rowIndex][columnIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
||||
data[rowIndex][columnIndex] = aValue;
|
||||
}
|
||||
}
|
Reference in a new issue