Main gui prototype
This commit is contained in:
parent
d9fbf7cdd9
commit
33e181a667
5 changed files with 217 additions and 110 deletions
79
src/main/java/GUI/Agenda.java
Normal file
79
src/main/java/GUI/Agenda.java
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +1,76 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="GUI.GUI">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridBagLayout">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="695"/>
|
||||
<xy x="50" y="20" width="1325" height="348"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="7954c" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<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>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="empty">
|
||||
<size top="0" left="50" bottom="0" right="0"/>
|
||||
</border>
|
||||
<children/>
|
||||
</grid>
|
||||
<hspacer id="82bd">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="5ab4e" binding="arrowPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" 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="1" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<gridbag weightx="1.0" weighty="0.0"/>
|
||||
<grid row="2" column="4" 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>
|
||||
<vspacer id="668e3">
|
||||
<component id="ea5a" class="javax.swing.JButton" binding="previousButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="←"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ddc41" class="javax.swing.JButton" binding="nextButton">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="→"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<vspacer id="b0c71">
|
||||
<constraints>
|
||||
<grid row="3" column="4" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="41fdc" layout-manager="GridLayoutManager" row-count="1" column-count="2" 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="3" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<vspacer id="fbe38">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<grid id="7f894" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="f1379" layout-manager="GridLayoutManager" row-count="2" column-count="2" 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="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
|
@ -29,7 +78,7 @@
|
|||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="fc703" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="b1c37" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="25" left="50" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false">
|
||||
|
@ -39,7 +88,7 @@
|
|||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="a4e5" class="javax.swing.JButton" binding="LMButton" default-binding="true">
|
||||
<component id="2dfdc" class="javax.swing.JButton" binding="LMButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="75" height="-1"/>
|
||||
|
@ -49,7 +98,7 @@
|
|||
<text value="LM"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b3aec" class="javax.swing.JButton" binding="HCButton" default-binding="true">
|
||||
<component id="9869d" class="javax.swing.JButton" binding="HCButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="75" height="-1"/>
|
||||
|
@ -59,7 +108,7 @@
|
|||
<text value="HC"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e290e" class="javax.swing.JButton" binding="UCRButton" default-binding="true">
|
||||
<component id="bc004" class="javax.swing.JButton" binding="UCRButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="75" height="-1"/>
|
||||
|
@ -71,14 +120,14 @@
|
|||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<hspacer id="4ab95">
|
||||
<hspacer id="975cc">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="14" height="61"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="4fa1" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="edbdc" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="50" 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"/>
|
||||
|
@ -86,13 +135,12 @@
|
|||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="8afcf" class="javax.swing.JLabel">
|
||||
<component id="f0690" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font size="22"/>
|
||||
<labelFor value="c1d0a"/>
|
||||
<text value="Agenda"/>
|
||||
</properties>
|
||||
</component>
|
||||
|
@ -102,67 +150,6 @@
|
|||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="8ead9" layout-manager="GridBagLayout">
|
||||
<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">
|
||||
<maximum-size width="-1" height="750"/>
|
||||
</grid>
|
||||
<gridbag weightx="1.0" weighty="1.0"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<scrollpane id="c1d0a" binding="scrollPane">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="7" anchor="0" fill="3" indent="1" use-parent-layout="false"/>
|
||||
<gridbag weightx="1.0" weighty="1.0"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e6114" class="javax.swing.JTable" binding="table1" default-binding="true">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<cellSelectionEnabled value="true"/>
|
||||
<gridColor color="-13105660"/>
|
||||
<intercellSpacing width="1" height="1"/>
|
||||
<rowHeight value="100"/>
|
||||
<rowMargin value="1"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="7e556" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<gridbag weightx="0.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="37e85" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Label"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="6580f">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="2dd31">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
|
|
@ -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", "<html>Milieu<br/>Après-midi</html>", "<html>Fin<br/>Après-midi</html>", "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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
24
src/main/java/GUI/RowHeaderRenderer.java
Normal file
24
src/main/java/GUI/RowHeaderRenderer.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
Reference in a new issue