diff --git a/src/main/java/GUI/Agenda.java b/src/main/java/GUI/Agenda.java new file mode 100644 index 0000000..31091e6 --- /dev/null +++ b/src/main/java/GUI/Agenda.java @@ -0,0 +1,110 @@ +package GUI; + +import javax.swing.*; +import javax.swing.event.MouseInputAdapter; +import javax.swing.table.TableColumnModel; +import java.awt.*; +import java.awt.event.MouseEvent; +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(); + 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); + } + 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]; + } + }; + TableModel dm = new TableModel(day, currentPage, headers.length); + JTable table = new JTable(dm) { + @Override + public boolean getScrollableTracksViewportHeight() { + return true; + } + }; + 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); + + rowHeader.setCellRenderer(new RowHeaderRenderer(table)); + + JScrollPane scroll = new JScrollPane(table); + 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 819c572..0ddae9d 100644 --- a/src/main/java/GUI/GUI.form +++ b/src/main/java/GUI/GUI.form @@ -1,45 +1,150 @@