From 86ef72e38881b5f0c482d0b375f8063d20eed2f2 Mon Sep 17 00:00:00 2001 From: Tergel TSAGAAN Date: Fri, 18 Dec 2020 11:51:44 +0100 Subject: [PATCH 1/5] test --- src/main/java/GUI/GUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/GUI/GUI.java b/src/main/java/GUI/GUI.java index e3fca02..77773b8 100644 --- a/src/main/java/GUI/GUI.java +++ b/src/main/java/GUI/GUI.java @@ -13,7 +13,7 @@ public class GUI extends JFrame { private void construct() { setTitle("Projection Planning"); setContentPane(mainPanel); - setSize(200,200); + setSize(1280,800); setLocationRelativeTo(null); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); From 54d76581f33935bd3a264725016b95d9f6e6055e Mon Sep 17 00:00:00 2001 From: Tergel TSAGAAN Date: Thu, 24 Dec 2020 21:02:10 +0100 Subject: [PATCH 2/5] backup --- config.json | 1 + src/main/java/GUI/GUI.form | 169 ++++++++++++++++++++++++---- src/main/java/GUI/GUI.java | 51 ++++++++- src/main/java/GUI/MyTableModel.java | 27 +++++ 4 files changed, 223 insertions(+), 25 deletions(-) create mode 100644 config.json create mode 100644 src/main/java/GUI/MyTableModel.java diff --git a/config.json b/config.json new file mode 100644 index 0000000..16cb637 --- /dev/null +++ b/config.json @@ -0,0 +1 @@ +{"host":"vps.flifloo.fr","password":"cannes","database":"cannes","user":"root"} \ No newline at end of file diff --git a/src/main/java/GUI/GUI.form b/src/main/java/GUI/GUI.form index 819c572..3cdfae1 100644 --- a/src/main/java/GUI/GUI.form +++ b/src/main/java/GUI/GUI.form @@ -1,45 +1,166 @@
- - + - + - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - diff --git a/src/main/java/GUI/GUI.java b/src/main/java/GUI/GUI.java index 77773b8..d14cff5 100644 --- a/src/main/java/GUI/GUI.java +++ b/src/main/java/GUI/GUI.java @@ -1,15 +1,62 @@ package GUI; import javax.swing.*; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableModel; +import java.awt.*; public class GUI extends JFrame { private JPanel mainPanel; - + 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"); public GUI() { super(); construct(); } + private void renderMenu() { + menuBar.add(menuFichier); + menuFichier.add(menuItemAddProj); + menuFichier.add(menuItemEditProj); + 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() { setTitle("Projection Planning"); setContentPane(mainPanel); @@ -17,6 +64,8 @@ public class GUI extends JFrame { setLocationRelativeTo(null); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.renderMenu(); + this.renderTable(); setVisible(true); } } diff --git a/src/main/java/GUI/MyTableModel.java b/src/main/java/GUI/MyTableModel.java new file mode 100644 index 0000000..a501427 --- /dev/null +++ b/src/main/java/GUI/MyTableModel.java @@ -0,0 +1,27 @@ +package GUI; + +import javax.swing.table.AbstractTableModel; + +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","","",""}, {"","","","",""}, {"","","","",""}, {"","","","",""}}; + @Override + public int getRowCount() { + return data.length; + } + + @Override + public int getColumnCount() { + return columnNames.length; + } + + @Override + public String getColumnName(int column) { + return columnNames[column]; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + return data[rowIndex][columnIndex]; + } +} From cb1ba75d4abe753a3df90831da06a26e0127741c Mon Sep 17 00:00:00 2001 From: Tergel TSAGAAN Date: Sun, 3 Jan 2021 17:32:05 +0100 Subject: [PATCH 3/5] Main gui prototype --- src/main/java/GUI/Agenda.java | 79 +++++++++++++ src/main/java/GUI/GUI.form | 139 ++++++++++------------- src/main/java/GUI/GUI.java | 66 +++++------ src/main/java/GUI/MyTableModel.java | 19 +++- src/main/java/GUI/RowHeaderRenderer.java | 24 ++++ 5 files changed, 217 insertions(+), 110 deletions(-) create mode 100644 src/main/java/GUI/Agenda.java create mode 100644 src/main/java/GUI/RowHeaderRenderer.java 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 @@ - + + - + - + + + + + + + + + + + + + + + + + + + - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -29,7 +78,7 @@ - + @@ -39,7 +88,7 @@ - + @@ -49,7 +98,7 @@ - + @@ -59,7 +108,7 @@ - + @@ -71,14 +120,14 @@ - + - + @@ -86,13 +135,12 @@ - + - @@ -102,67 +150,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 From 44482bae780a272182f7ca22082d26f8ef04d5c2 Mon Sep 17 00:00:00 2001 From: Tergel TSAGAAN Date: Mon, 4 Jan 2021 21:50:04 +0100 Subject: [PATCH 4/5] Added add/edit/remove projection dialog, agenda adaptation --- src/main/java/GUI/Agenda.java | 48 +++++-- src/main/java/GUI/CompetType.java | 5 + src/main/java/GUI/GUI.form | 5 +- src/main/java/GUI/GUI.java | 53 ++++++-- src/main/java/GUI/ProjectionHandler.form | 125 ++++++++++++++++++ src/main/java/GUI/ProjectionHandler.java | 61 +++++++++ src/main/java/GUI/ProjectionType.java | 5 + .../{MyTableModel.java => TableModel.java} | 15 ++- 8 files changed, 292 insertions(+), 25 deletions(-) create mode 100644 src/main/java/GUI/CompetType.java create mode 100644 src/main/java/GUI/ProjectionHandler.form create mode 100644 src/main/java/GUI/ProjectionHandler.java create mode 100644 src/main/java/GUI/ProjectionType.java rename src/main/java/GUI/{MyTableModel.java => TableModel.java} (66%) diff --git a/src/main/java/GUI/Agenda.java b/src/main/java/GUI/Agenda.java index 230b1df..6dc86ff 100644 --- a/src/main/java/GUI/Agenda.java +++ b/src/main/java/GUI/Agenda.java @@ -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; + } } diff --git a/src/main/java/GUI/CompetType.java b/src/main/java/GUI/CompetType.java new file mode 100644 index 0000000..9b0e1a5 --- /dev/null +++ b/src/main/java/GUI/CompetType.java @@ -0,0 +1,5 @@ +package GUI; + +public enum CompetType { + LM, UCR, HC +} \ No newline at end of file diff --git a/src/main/java/GUI/GUI.form b/src/main/java/GUI/GUI.form index 97b6bb9..0ddae9d 100644 --- a/src/main/java/GUI/GUI.form +++ b/src/main/java/GUI/GUI.form @@ -10,10 +10,7 @@ - - - - + diff --git a/src/main/java/GUI/GUI.java b/src/main/java/GUI/GUI.java index 2634b71..2640c7d 100644 --- a/src/main/java/GUI/GUI.java +++ b/src/main/java/GUI/GUI.java @@ -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", "Milieu
Après-midi", "Fin
Après-midi", "Soirée"}; + private CompetType currentCompetition = CompetType.LM; + public GUI() { super(); construct(); } + private void renderMenu() { menuBar.add(menuFichier); menuFichier.add(menuItemAddProj); @@ -41,7 +39,7 @@ public class GUI extends JFrame implements ActionListener { this.currentPage = 1; setTitle("Projection Planning"); setContentPane(mainPanel); - setSize(1280,800); + setSize(1280, 800); setLocationRelativeTo(null); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -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", "Milieu
Après-midi", "Fin
Après-midi", "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[]{"Fin
Matinée", "Fin
Après-midi", "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", "Milieu
Après-midi", "Fin
Après-midi", "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); } } } diff --git a/src/main/java/GUI/ProjectionHandler.form b/src/main/java/GUI/ProjectionHandler.form new file mode 100644 index 0000000..8f19d6a --- /dev/null +++ b/src/main/java/GUI/ProjectionHandler.form @@ -0,0 +1,125 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/main/java/GUI/ProjectionHandler.java b/src/main/java/GUI/ProjectionHandler.java new file mode 100644 index 0000000..8d83116 --- /dev/null +++ b/src/main/java/GUI/ProjectionHandler.java @@ -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; + } + } +} diff --git a/src/main/java/GUI/ProjectionType.java b/src/main/java/GUI/ProjectionType.java new file mode 100644 index 0000000..ceccf0f --- /dev/null +++ b/src/main/java/GUI/ProjectionType.java @@ -0,0 +1,5 @@ +package GUI; + +public enum ProjectionType { + ADD, EDIT, REMOVE +} \ No newline at end of file diff --git a/src/main/java/GUI/MyTableModel.java b/src/main/java/GUI/TableModel.java similarity index 66% rename from src/main/java/GUI/MyTableModel.java rename to src/main/java/GUI/TableModel.java index f5a81d9..eda7239 100644 --- a/src/main/java/GUI/MyTableModel.java +++ b/src/main/java/GUI/TableModel.java @@ -3,21 +3,22 @@ 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]; for (int i = 0; i < this.day; i++) { - this.columnNames[i] = "Jour " + ((i+1)+(5*(currentPage))); + this.columnNames[i] = "Jour " + ((i + 1) + (5 * (currentPage))); } - for (int i = 0; i < 5 ; i++) { + 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; + } } From 1b25c747b1e87cdb31e9455c5f2d0ad76c37f614 Mon Sep 17 00:00:00 2001 From: Tergel TSAGAAN Date: Mon, 4 Jan 2021 21:58:22 +0100 Subject: [PATCH 5/5] removed sout --- src/main/java/GUI/Agenda.java | 1 - src/main/java/GUI/GUI.java | 1 - src/main/java/GUI/ProjectionHandler.java | 1 + 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/GUI/Agenda.java b/src/main/java/GUI/Agenda.java index 6dc86ff..31091e6 100644 --- a/src/main/java/GUI/Agenda.java +++ b/src/main/java/GUI/Agenda.java @@ -58,7 +58,6 @@ public class Agenda extends JPanel { return true; } }; - System.out.println(table.getRowHeight()); table.setCellSelectionEnabled(true); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); diff --git a/src/main/java/GUI/GUI.java b/src/main/java/GUI/GUI.java index 2640c7d..b8b0877 100644 --- a/src/main/java/GUI/GUI.java +++ b/src/main/java/GUI/GUI.java @@ -46,7 +46,6 @@ public class GUI extends JFrame implements ActionListener { this.renderMenu(); new Agenda(agendaPanel, headers, 8, this.currentPage); - System.out.println("agenda"); previousButton.addActionListener(this); nextButton.addActionListener(this); HCButton.addActionListener(this); diff --git a/src/main/java/GUI/ProjectionHandler.java b/src/main/java/GUI/ProjectionHandler.java index 8d83116..3d23f5a 100644 --- a/src/main/java/GUI/ProjectionHandler.java +++ b/src/main/java/GUI/ProjectionHandler.java @@ -35,6 +35,7 @@ public class ProjectionHandler extends JDialog { dispose(); } }); + setLocationRelativeTo(null); } private void handleDialogName() {