dispose dialog when escape
handling multiple projection on same slot and room
This commit is contained in:
parent
34b1b1d55a
commit
a9e867237a
8 changed files with 340 additions and 68 deletions
|
@ -117,4 +117,8 @@ public class Projection extends Table {
|
|||
public String toString() {
|
||||
return getMovie().getName();
|
||||
}
|
||||
|
||||
public String[] toArray() {
|
||||
return new String[]{getMovie().toString(), getCompetition().toString(), getRoom().toString(), getStartDate().toString(), getSlot().toString()};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ import DB.Projection;
|
|||
import DB.Slot;
|
||||
import Exceptions.NotFoundInTable;
|
||||
import Exceptions.ProjectionNotSpecified;
|
||||
import GUI.Agenda.Model.AgendaTableModel;
|
||||
import GUI.ProjectionHandler;
|
||||
import GUI.ProjectionSelecter;
|
||||
import GUI.Types.CompetType;
|
||||
import GUI.Types.ProjectionType;
|
||||
|
||||
|
@ -83,11 +85,12 @@ public class Agenda extends JPanel {
|
|||
public int getSize() {
|
||||
return headers.length;
|
||||
}
|
||||
|
||||
public Object getElementAt(int index) {
|
||||
return headers[index];
|
||||
}
|
||||
};
|
||||
TableModel dm = new TableModel(day, currentPage);
|
||||
AgendaTableModel dm = new AgendaTableModel(day, currentPage);
|
||||
table = new JTable(dm) {
|
||||
@Override
|
||||
public boolean getScrollableTracksViewportHeight() {
|
||||
|
@ -98,7 +101,7 @@ public class Agenda extends JPanel {
|
|||
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||
table.setRowHeight(100);
|
||||
Agenda tmp = this;
|
||||
agenda = this;
|
||||
table.addMouseListener(new MouseInputAdapter() {
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent mouseEvent) {
|
||||
|
@ -110,7 +113,7 @@ public class Agenda extends JPanel {
|
|||
Projection projection = null;
|
||||
if (currentCellValue.getClass() == Projection.class)
|
||||
projection = (Projection) currentCellValue;
|
||||
PopUpProjection popUpProjection = new PopUpProjection(projection, tmp);
|
||||
PopUpProjection popUpProjection = new PopUpProjection(projection, agenda);
|
||||
popUpProjection.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
|
||||
}
|
||||
}
|
||||
|
@ -126,13 +129,15 @@ public class Agenda extends JPanel {
|
|||
if (currentCellValue.getClass() == Projection.class)
|
||||
projection = (Projection) currentCellValue;
|
||||
if (mouseEvent.getClickCount() == 2 && table.getSelectedRow() != -1) {
|
||||
if (projection == null) {
|
||||
if (projection == null && currentCellValue.getClass() != String.class) {
|
||||
ProjectionSelecter dialog = new ProjectionSelecter((ArrayList<Projection>) currentCellValue, agenda);
|
||||
dialog.pack();
|
||||
dialog.setVisible(true);
|
||||
} else if (projection == null)
|
||||
openDialog(ProjectionType.ADD);
|
||||
} else {
|
||||
openDialog(ProjectionType.EDIT, projection);
|
||||
}
|
||||
else openDialog(ProjectionType.EDIT, projection);
|
||||
} else if (mouseEvent.isPopupTrigger()) {
|
||||
PopUpProjection popUpProjection = new PopUpProjection(projection, tmp);
|
||||
PopUpProjection popUpProjection = new PopUpProjection(projection, agenda);
|
||||
popUpProjection.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
|
||||
}
|
||||
}
|
||||
|
@ -196,8 +201,16 @@ public class Agenda extends JPanel {
|
|||
break;
|
||||
}
|
||||
}
|
||||
Object tableValue = table.getValueAt(row, column);
|
||||
if (tableValue.getClass() == Projection.class) {
|
||||
Projection[] projections = {(Projection) tableValue, projection};
|
||||
table.setValueAt(projections, row, column);
|
||||
} else if (tableValue.getClass() != String.class) {
|
||||
((AgendaTableModel) table.getModel()).addValueAt(projection, row, column);
|
||||
} else {
|
||||
table.setValueAt(projection, row, column);
|
||||
}
|
||||
}
|
||||
|
||||
public int getCurrentPage() {
|
||||
return this.currentPage;
|
||||
|
|
93
src/main/java/GUI/Agenda/Model/AgendaTableModel.java
Normal file
93
src/main/java/GUI/Agenda/Model/AgendaTableModel.java
Normal file
|
@ -0,0 +1,93 @@
|
|||
package GUI.Agenda.Model;
|
||||
|
||||
import Config.Config;
|
||||
import DB.Projection;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class AgendaTableModel extends AbstractTableModel {
|
||||
private LocalDate[] columnNames;
|
||||
private Object[][] data;
|
||||
private int day;
|
||||
|
||||
public AgendaTableModel(int day, int currentPage) {
|
||||
this.day = day;
|
||||
columnNames = new LocalDate[this.day];
|
||||
data = new Object[5][this.day];
|
||||
|
||||
LocalDate startDate = Config.getStartDate();
|
||||
|
||||
for (int i = 0; i < this.day; i++) {
|
||||
this.columnNames[i] = startDate.plusDays(i + 5 * (currentPage));
|
||||
}
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Arrays.fill(data[i], "");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return columnNames.length;
|
||||
}
|
||||
|
||||
public LocalDate getColumn(int column) {
|
||||
return columnNames[column];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int column) {
|
||||
return columnNames[column].toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
Object dataObject = data[rowIndex][columnIndex];
|
||||
if (dataObject.getClass() == DB.Projection[].class) {
|
||||
ArrayList<Projection> projections = new ArrayList<Projection>() {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder("<html>");
|
||||
for (int i = 0; i < size(); i++) {
|
||||
builder.append(String.format("%s<br>", get(i)));
|
||||
}
|
||||
builder.append("</html>");
|
||||
return builder.toString();
|
||||
}
|
||||
};
|
||||
Projection[] dataArray = (Projection[]) dataObject;
|
||||
projections.addAll(Arrays.asList(dataArray));
|
||||
return projections;
|
||||
}
|
||||
return data[rowIndex][columnIndex];
|
||||
}
|
||||
|
||||
public void addValueAt(Projection projection, int rowIndex, int columnIndex) {
|
||||
Projection[] projections = (Projection[]) data[rowIndex][columnIndex];
|
||||
ArrayList<Projection> projectionsArrayList = new ArrayList<>(Arrays.asList(projections)) {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder("<html>");
|
||||
for (int i = 0; i < size(); i++) {
|
||||
builder.append(String.format("%s<br>", get(i)));
|
||||
}
|
||||
builder.append("</html>");
|
||||
return builder.toString();
|
||||
}
|
||||
};
|
||||
projectionsArrayList.add(projection);
|
||||
setValueAt(projectionsArrayList, rowIndex, columnIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
||||
data[rowIndex][columnIndex] = aValue;
|
||||
}
|
||||
}
|
47
src/main/java/GUI/Agenda/Model/ProjectionTableModel.java
Normal file
47
src/main/java/GUI/Agenda/Model/ProjectionTableModel.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
package GUI.Agenda.Model;
|
||||
|
||||
import DB.Projection;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ProjectionTableModel extends AbstractTableModel {
|
||||
private String[] columnNames = {"Movie", "Competition", "Room", "Start", "Slot"};
|
||||
private Projection[] data;
|
||||
|
||||
public ProjectionTableModel(ArrayList<Projection> projections) {
|
||||
data = new Projection[projections.size()];
|
||||
for (int i = 0; i < projections.size(); i++) {
|
||||
data[i] = projections.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return columnNames.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int column) {
|
||||
return columnNames[column];
|
||||
}
|
||||
|
||||
public Projection getRowAt(int row) {
|
||||
return (Projection) data[row];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
return data[rowIndex].toArray()[columnIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
||||
data[rowIndex] = (Projection) aValue;
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package GUI.Agenda;
|
||||
|
||||
import Config.Config;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TableModel extends AbstractTableModel {
|
||||
private LocalDate[] columnNames;
|
||||
private Object[][] data;
|
||||
private int day;
|
||||
|
||||
public TableModel(int day, int currentPage) {
|
||||
this.day = day;
|
||||
columnNames = new LocalDate[this.day];
|
||||
data = new Object[5][this.day];
|
||||
|
||||
LocalDate startDate = Config.getStartDate();
|
||||
|
||||
for (int i = 0; i < this.day; i++) {
|
||||
this.columnNames[i] = startDate.plusDays(i + 5 * (currentPage));
|
||||
}
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Arrays.fill(data[i], "");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return columnNames.length;
|
||||
}
|
||||
|
||||
public LocalDate getColumn(int column) {
|
||||
return columnNames[column];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int column) {
|
||||
return columnNames[column].toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
return data[rowIndex][columnIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
||||
data[rowIndex][columnIndex] = aValue;
|
||||
}
|
||||
}
|
|
@ -9,8 +9,7 @@ import GUI.Types.ProjectionType;
|
|||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.*;
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
|
@ -97,6 +96,15 @@ public class ProjectionHandler extends JDialog {
|
|||
slotComboBox.addActionListener(actionEvent -> updateRooms());
|
||||
cancelButton.addActionListener(actionEvent -> dispose());
|
||||
confirmButton.addActionListener(actionEvent -> confirm());
|
||||
contentPane.registerKeyboardAction(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
dispose();
|
||||
}
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
}
|
||||
|
||||
private void onCancel() {
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void updateCompetitions() {
|
||||
|
|
81
src/main/java/GUI/ProjectionSelecter.form
Normal file
81
src/main/java/GUI/ProjectionSelecter.form
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="GUI.ProjectionSelecter">
|
||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" 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="94766" 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="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<hspacer id="98af6">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" 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="e7465" class="javax.swing.JButton" binding="buttonOK">
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="OK"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Cancel"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="e3588" 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="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="200"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-14273992"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<scrollpane id="90da7" binding="scrollPane">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e297b" class="javax.swing.JTable" binding="table1" default-binding="true">
|
||||
<constraints/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
83
src/main/java/GUI/ProjectionSelecter.java
Normal file
83
src/main/java/GUI/ProjectionSelecter.java
Normal file
|
@ -0,0 +1,83 @@
|
|||
package GUI;
|
||||
|
||||
import DB.Projection;
|
||||
import GUI.Agenda.Agenda;
|
||||
import GUI.Agenda.Model.ProjectionTableModel;
|
||||
import GUI.Types.ProjectionType;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ProjectionSelecter extends JDialog {
|
||||
private JPanel contentPane;
|
||||
private JButton buttonOK;
|
||||
private JButton buttonCancel;
|
||||
private JTable table1;
|
||||
private JScrollPane scrollPane;
|
||||
private Projection currentProjection;
|
||||
private Agenda agenda;
|
||||
|
||||
public ProjectionSelecter(ArrayList<Projection> projections, Agenda agenda) {
|
||||
this.agenda = agenda;
|
||||
setContentPane(contentPane);
|
||||
setModal(true);
|
||||
setLocationRelativeTo(null);
|
||||
setTitle("Projection Selecter");
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
ProjectionTableModel pTM = new ProjectionTableModel(projections);
|
||||
table1.setModel(pTM);
|
||||
buttonOK.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onOK();
|
||||
}
|
||||
});
|
||||
|
||||
buttonCancel.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
table1.addMouseListener(
|
||||
new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
JTable table = (JTable) e.getSource();
|
||||
Point point = e.getPoint();
|
||||
int row = table.rowAtPoint(point);
|
||||
if (e.getClickCount() == 2 && table.getSelectedRow() != -1) {
|
||||
currentProjection = ((ProjectionTableModel) table.getModel()).getRowAt(row);
|
||||
agenda.openDialog(ProjectionType.EDIT, currentProjection);
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
// call onCancel() when cross is clicked
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
|
||||
// call onCancel() on ESCAPE
|
||||
contentPane.registerKeyboardAction(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCancel();
|
||||
}
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
}
|
||||
|
||||
private void onOK() {
|
||||
agenda.openDialog(ProjectionType.EDIT, currentProjection);
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void onCancel() {
|
||||
// add your code here if necessary
|
||||
dispose();
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue