Remove edit from GUI menu bar and add exception to ProjectionHandler
This commit is contained in:
parent
ebfc03efdf
commit
c6a7f697b9
4 changed files with 24 additions and 29 deletions
7
src/main/java/Exceptions/ProjectionNotSpecified.java
Normal file
7
src/main/java/Exceptions/ProjectionNotSpecified.java
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package Exceptions;
|
||||||
|
|
||||||
|
public class ProjectionNotSpecified extends Exception {
|
||||||
|
public ProjectionNotSpecified() {
|
||||||
|
super("Can't edit without a specified projection !");
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package GUI.Agenda;
|
||||||
|
|
||||||
import DB.Competition;
|
import DB.Competition;
|
||||||
import DB.Projection;
|
import DB.Projection;
|
||||||
|
import Exceptions.ProjectionNotSpecified;
|
||||||
import GUI.ProjectionHandler;
|
import GUI.ProjectionHandler;
|
||||||
import GUI.Types.CompetType;
|
import GUI.Types.CompetType;
|
||||||
import GUI.Types.ProjectionType;
|
import GUI.Types.ProjectionType;
|
||||||
|
@ -159,13 +160,16 @@ public class Agenda extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void openDialog(ProjectionType projectionType) {
|
public void openDialog(ProjectionType projectionType) {
|
||||||
ProjectionHandler dialog = new ProjectionHandler(projectionType, this);
|
try {
|
||||||
dialog.pack();
|
ProjectionHandler dialog = new ProjectionHandler(projectionType, this);
|
||||||
dialog.setVisible(true);
|
dialog.pack();
|
||||||
|
dialog.setVisible(true);
|
||||||
|
} catch (ProjectionNotSpecified ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void openDialog(ProjectionType projectionType, Projection projection) {
|
public void openDialog(ProjectionType projectionType, Projection projection) {
|
||||||
ProjectionHandler dialog = new ProjectionHandler(projectionType, this, projection);
|
ProjectionHandler dialog = new ProjectionHandler(projectionType, this, projection);
|
||||||
dialog.pack();
|
dialog.pack();
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
|
|
|
@ -20,17 +20,12 @@ public class GUI extends JFrame implements ActionListener {
|
||||||
private JMenuBar menuBar = new JMenuBar();
|
private JMenuBar menuBar = new JMenuBar();
|
||||||
private JMenu menuFichier = new JMenu("File");
|
private JMenu menuFichier = new JMenu("File");
|
||||||
private JMenuItem menuItemAddProj = new JMenuItem("Add projection");
|
private JMenuItem menuItemAddProj = new JMenuItem("Add projection");
|
||||||
private JMenuItem menuItemEditProj = new JMenuItem("Edit projection");
|
|
||||||
private JMenuItem menuItemRemoveProj = new JMenuItem("Remove projection");
|
private JMenuItem menuItemRemoveProj = new JMenuItem("Remove projection");
|
||||||
private int currentPage;
|
private int currentPage;
|
||||||
private Agenda agenda;
|
private Agenda agenda;
|
||||||
String headers[] = {"Matin", "Midi", "<html>Milieu<br/>Après-midi</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
String headers[] = {"Matin", "Midi", "<html>Milieu<br/>Après-midi</html>", "<html>Fin<br/>Après-midi</html>", "Soirée"};
|
||||||
private CompetType currentCompetition = CompetType.LM;
|
private CompetType currentCompetition = CompetType.LM;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
new GUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GUI() {
|
public GUI() {
|
||||||
super();
|
super();
|
||||||
construct();
|
construct();
|
||||||
|
@ -39,7 +34,6 @@ public class GUI extends JFrame implements ActionListener {
|
||||||
private void renderMenu() {
|
private void renderMenu() {
|
||||||
menuBar.add(menuFichier);
|
menuBar.add(menuFichier);
|
||||||
menuFichier.add(menuItemAddProj);
|
menuFichier.add(menuItemAddProj);
|
||||||
menuFichier.add(menuItemEditProj);
|
|
||||||
menuFichier.add(menuItemRemoveProj);
|
menuFichier.add(menuItemRemoveProj);
|
||||||
setJMenuBar(menuBar);
|
setJMenuBar(menuBar);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +57,6 @@ public class GUI extends JFrame implements ActionListener {
|
||||||
LMButton.addActionListener(this);
|
LMButton.addActionListener(this);
|
||||||
UCRButton.addActionListener(this);
|
UCRButton.addActionListener(this);
|
||||||
menuItemAddProj.addActionListener(this);
|
menuItemAddProj.addActionListener(this);
|
||||||
menuItemEditProj.addActionListener(this);
|
|
||||||
menuItemRemoveProj.addActionListener(this);
|
menuItemRemoveProj.addActionListener(this);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
@ -77,8 +70,7 @@ public class GUI extends JFrame implements ActionListener {
|
||||||
this.currentPage = agenda.getCurrentPage();
|
this.currentPage = agenda.getCurrentPage();
|
||||||
this.repaint();
|
this.repaint();
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
}
|
} else if (source == nextButton) {
|
||||||
else if (source == nextButton) {
|
|
||||||
this.currentPage++;
|
this.currentPage++;
|
||||||
Agenda agenda = new Agenda(agendaPanel, this.currentPage, this.currentCompetition);
|
Agenda agenda = new Agenda(agendaPanel, this.currentPage, this.currentCompetition);
|
||||||
this.currentPage = agenda.getCurrentPage();
|
this.currentPage = agenda.getCurrentPage();
|
||||||
|
@ -104,17 +96,9 @@ public class GUI extends JFrame implements ActionListener {
|
||||||
this.repaint();
|
this.repaint();
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
} else if (source == this.menuItemAddProj) {
|
} else if (source == this.menuItemAddProj) {
|
||||||
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.ADD, agenda);
|
agenda.openDialog(ProjectionType.ADD);
|
||||||
dialog.pack();
|
|
||||||
dialog.setVisible(true);
|
|
||||||
} else if (source == this.menuItemEditProj) {
|
|
||||||
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.EDIT, agenda);
|
|
||||||
dialog.pack();
|
|
||||||
dialog.setVisible(true);
|
|
||||||
} else if (source == this.menuItemRemoveProj) {
|
} else if (source == this.menuItemRemoveProj) {
|
||||||
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.REMOVE, agenda);
|
agenda.openDialog(ProjectionType.REMOVE);
|
||||||
dialog.pack();
|
|
||||||
dialog.setVisible(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package GUI;
|
package GUI;
|
||||||
|
|
||||||
import DB.*;
|
import DB.*;
|
||||||
|
import Exceptions.ProjectionNotSpecified;
|
||||||
import GUI.Agenda.Agenda;
|
import GUI.Agenda.Agenda;
|
||||||
import GUI.Types.ProjectionType;
|
import GUI.Types.ProjectionType;
|
||||||
|
|
||||||
|
@ -38,7 +39,9 @@ public class ProjectionHandler extends JDialog {
|
||||||
private Agenda agenda;
|
private Agenda agenda;
|
||||||
private Projection projection = null;
|
private Projection projection = null;
|
||||||
|
|
||||||
public ProjectionHandler(ProjectionType projectionType, Agenda agenda) {
|
public ProjectionHandler(ProjectionType projectionType, Agenda agenda) throws ProjectionNotSpecified {
|
||||||
|
if (projectionType == ProjectionType.EDIT)
|
||||||
|
throw new ProjectionNotSpecified();
|
||||||
this.projectionType = projectionType;
|
this.projectionType = projectionType;
|
||||||
this.agenda = agenda;
|
this.agenda = agenda;
|
||||||
createUIComponents();
|
createUIComponents();
|
||||||
|
@ -167,10 +170,7 @@ public class ProjectionHandler extends JDialog {
|
||||||
new Projection(date, competition, room, movie, slot);
|
new Projection(date, competition, room, movie, slot);
|
||||||
break;
|
break;
|
||||||
case EDIT:
|
case EDIT:
|
||||||
if (projection != null)
|
projection.delete();
|
||||||
projection.delete();
|
|
||||||
else
|
|
||||||
(Projection.find(date, competition, room, movie, slot)).delete();
|
|
||||||
new Projection(date, competition, room, movie, slot);
|
new Projection(date, competition, room, movie, slot);
|
||||||
break;
|
break;
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
|
|
Reference in a new issue