diff --git a/src/main/java/GUI/Agenda.java b/src/main/java/GUI/Agenda.java
new file mode 100644
index 0000000..230b1df
--- /dev/null
+++ b/src/main/java/GUI/Agenda.java
@@ -0,0 +1,79 @@
+package GUI;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import javax.swing.table.DefaultTableModel;
+import javax.swing.table.TableColumn;
+import javax.swing.table.TableColumnModel;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class Agenda extends JPanel {
+ private JPanel agendaPanel;
+ private String headers[];
+ private int totalDay;
+ private int currentPage;
+ public Agenda(JPanel agendaPanel, String headers[], int totalDay, int currentPage) {
+ this.agendaPanel = agendaPanel;
+ this.headers = headers;
+ this.totalDay = totalDay;
+ this.currentPage = currentPage;
+ this.agendaPanel.removeAll();
+ System.out.println("lolilol");
+ int totalPages[] = dayToPage(9);
+ JScrollPane scroll = constructAgenda(totalPages[this.currentPage]);
+ agendaPanel.add(scroll);
+ }
+ private int[] dayToPage(int totalDay) {
+ int day = totalDay;
+ int count = 0;
+ while (day >= 5) {
+ day = day-5;
+ count++;
+ }
+ int rest = totalDay - 5*count;
+ int totalPages = rest < 5 ? count+1:count;
+ int pages[] = new int[totalPages];
+ Arrays.fill(pages, 5);
+ if (rest < 5) pages[totalPages-1] = rest;
+ return pages;
+ }
+ private JScrollPane constructAgenda(int day) {
+ ListModel lm = new AbstractListModel() {
+ public int getSize() {
+ return headers.length;
+ }
+ public Object getElementAt(int index) {
+ return headers[index];
+ }
+ };
+ MyTableModel dm = new MyTableModel(day, currentPage);
+ JTable table = new JTable(dm) {
+ @Override
+ public Dimension getPreferredScrollableViewportSize() {
+ return new Dimension(super.getPreferredSize().width, getRowHeight()*(getRowCount()-1)-20);
+ }
+ };
+ table.setCellSelectionEnabled(true);
+ table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
+ table.setRowHeight(100);
+ 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);
+
+ rowHeader.setCellRenderer(new RowHeaderRenderer(table));
+
+ JScrollPane scroll = new JScrollPane(table);
+ scroll.setRowHeaderView(rowHeader);
+ scroll.setBorder(BorderFactory.createEmptyBorder());
+ scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
+ return scroll;
+ }
+
+}
diff --git a/src/main/java/GUI/GUI.form b/src/main/java/GUI/GUI.form
index 3cdfae1..97b6bb9 100644
--- a/src/main/java/GUI/GUI.form
+++ b/src/main/java/GUI/GUI.form
@@ -1,27 +1,76 @@
diff --git a/src/main/java/GUI/GUI.java b/src/main/java/GUI/GUI.java
index d14cff5..2634b71 100644
--- a/src/main/java/GUI/GUI.java
+++ b/src/main/java/GUI/GUI.java
@@ -1,23 +1,30 @@
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;
-public class GUI extends JFrame {
+public class GUI extends JFrame implements ActionListener {
private JPanel mainPanel;
+ private JPanel agendaPanel;
+ private JPanel arrowPanel;
+ private JButton previousButton;
+ private JButton nextButton;
private JButton LMButton;
private JButton HCButton;
private JButton UCRButton;
- private JTable table1;
- private JScrollPane scrollPane;
- private JTable table2;
private JMenuBar menuBar = new JMenuBar();
private JMenu menuFichier = new JMenu("File");
private JMenuItem menuItemAddProj = new JMenuItem("Add projection");
private JMenuItem menuItemEditProj = new JMenuItem("Edit projection");
private JMenuItem menuItemRemoveProj = new JMenuItem("Remove projection");
+ private int currentPage;
+ String headers[] = {"Matin", "Midi", "Milieu
Après-midi", "Fin
Après-midi", "Soirée"};
public GUI() {
super();
construct();
@@ -29,35 +36,9 @@ public class GUI extends JFrame {
menuFichier.add(menuItemRemoveProj);
setJMenuBar(menuBar);
}
- private void renderTable() {
- DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
- centerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
- TableModel dataTest = new MyTableModel();
- table1.setModel(dataTest);
- for (int columnIndex = 0; columnIndex < dataTest.getColumnCount(); columnIndex++)
- {
- table1.getColumnModel().getColumn(columnIndex).setCellRenderer(centerRenderer);
- }
- scrollPane.setViewportView(table1);
- JList rowHeader = new JList(new AbstractListModel() {
- String headers[] = { "Matin", "Midi", "Milieu A", "Fin Aprem", "Soirée"};
-
- @Override
- public int getSize() {
- return headers.length;
- }
-
- @Override
- public Object getElementAt(int index) {
- return headers[index];
- }
- });
- rowHeader.setFixedCellHeight(100);
- rowHeader.setFixedCellWidth(60);
- scrollPane.setRowHeaderView(rowHeader);
- }
private void construct() {
+ this.currentPage = 1;
setTitle("Projection Planning");
setContentPane(mainPanel);
setSize(1280,800);
@@ -65,7 +46,28 @@ public class GUI extends JFrame {
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.renderMenu();
- this.renderTable();
+
+ new Agenda(agendaPanel, headers, 8, this.currentPage);
+ System.out.println("agenda");
+ previousButton.addActionListener(this);
+ nextButton.addActionListener(this);
setVisible(true);
}
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ Object source = e.getSource();
+ if (source == previousButton) {
+ this.currentPage--;
+ new Agenda(agendaPanel, headers, 8, this.currentPage);
+ this.repaint();
+ this.revalidate();
+ }
+ else if (source == nextButton) {
+ this.currentPage++;
+ new Agenda(agendaPanel, headers, 8, this.currentPage);
+ this.repaint();
+ this.revalidate();
+ }
+ }
}
diff --git a/src/main/java/GUI/MyTableModel.java b/src/main/java/GUI/MyTableModel.java
index a501427..f5a81d9 100644
--- a/src/main/java/GUI/MyTableModel.java
+++ b/src/main/java/GUI/MyTableModel.java
@@ -1,10 +1,24 @@
package GUI;
import javax.swing.table.AbstractTableModel;
+import java.util.Arrays;
public class MyTableModel extends AbstractTableModel {
- private String[] columnNames = {"Jour 1", "Jour 2", "Jour 3", "Jour 4", "Jour 5"};
- private Object[][] data = {{"","Film 1","Film 2","",""}, {"","Film 4","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}};
+ private String[] columnNames;
+ private Object[][] data;
+ private int day;
+ public MyTableModel(int day, int currentPage) {
+ this.day = day;
+ columnNames = new String[this.day];
+ data = new Object[5][this.day];
+ for (int i = 0; i < this.day; i++) {
+ this.columnNames[i] = "Jour " + ((i+1)+(5*(currentPage)));
+ }
+ for (int i = 0; i < 5 ; i++) {
+ Arrays.fill(data[i], "");
+ }
+ System.out.println(Arrays.toString(this.columnNames));
+ }
@Override
public int getRowCount() {
return data.length;
@@ -24,4 +38,5 @@ public class MyTableModel extends AbstractTableModel {
public Object getValueAt(int rowIndex, int columnIndex) {
return data[rowIndex][columnIndex];
}
+
}
diff --git a/src/main/java/GUI/RowHeaderRenderer.java b/src/main/java/GUI/RowHeaderRenderer.java
new file mode 100644
index 0000000..dd7a2c3
--- /dev/null
+++ b/src/main/java/GUI/RowHeaderRenderer.java
@@ -0,0 +1,24 @@
+package GUI;
+
+import javax.swing.*;
+import javax.swing.table.JTableHeader;
+import java.awt.*;
+
+class RowHeaderRenderer extends JLabel implements ListCellRenderer {
+
+ RowHeaderRenderer(JTable table) {
+ JTableHeader header = table.getTableHeader();
+ setOpaque(true);
+ setBorder(UIManager.getBorder("TableHeader.cellBorder"));
+ setHorizontalAlignment(CENTER);
+ setForeground(header.getForeground());
+ setBackground(header.getBackground());
+ setFont(header.getFont());
+ }
+
+ public Component getListCellRendererComponent(JList list, Object value,
+ int index, boolean isSelected, boolean cellHasFocus) {
+ setText((value == null) ? "" : value.toString());
+ return this;
+ }
+}
\ No newline at end of file