1
0
Fork 0

Remove edit from GUI menu bar and add exception to ProjectionHandler

This commit is contained in:
Tergel TSAGAAN 2021-01-11 16:39:13 +01:00
parent ebfc03efdf
commit c6a7f697b9
4 changed files with 24 additions and 29 deletions

View file

@ -0,0 +1,7 @@
package Exceptions;
public class ProjectionNotSpecified extends Exception {
public ProjectionNotSpecified() {
super("Can't edit without a specified projection !");
}
}

View file

@ -2,6 +2,7 @@ package GUI.Agenda;
import DB.Competition;
import DB.Projection;
import Exceptions.ProjectionNotSpecified;
import GUI.ProjectionHandler;
import GUI.Types.CompetType;
import GUI.Types.ProjectionType;
@ -159,13 +160,16 @@ public class Agenda extends JPanel {
}
}
protected void openDialog(ProjectionType projectionType) {
ProjectionHandler dialog = new ProjectionHandler(projectionType, this);
dialog.pack();
dialog.setVisible(true);
public void openDialog(ProjectionType projectionType) {
try {
ProjectionHandler dialog = new ProjectionHandler(projectionType, this);
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);
dialog.pack();
dialog.setVisible(true);

View file

@ -20,17 +20,12 @@ public class GUI extends JFrame implements ActionListener {
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;
private Agenda agenda;
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;
public static void main(String[] args) {
new GUI();
}
public GUI() {
super();
construct();
@ -39,7 +34,6 @@ public class GUI extends JFrame implements ActionListener {
private void renderMenu() {
menuBar.add(menuFichier);
menuFichier.add(menuItemAddProj);
menuFichier.add(menuItemEditProj);
menuFichier.add(menuItemRemoveProj);
setJMenuBar(menuBar);
}
@ -63,7 +57,6 @@ public class GUI extends JFrame implements ActionListener {
LMButton.addActionListener(this);
UCRButton.addActionListener(this);
menuItemAddProj.addActionListener(this);
menuItemEditProj.addActionListener(this);
menuItemRemoveProj.addActionListener(this);
setVisible(true);
}
@ -77,8 +70,7 @@ public class GUI extends JFrame implements ActionListener {
this.currentPage = agenda.getCurrentPage();
this.repaint();
this.revalidate();
}
else if (source == nextButton) {
} else if (source == nextButton) {
this.currentPage++;
Agenda agenda = new Agenda(agendaPanel, this.currentPage, this.currentCompetition);
this.currentPage = agenda.getCurrentPage();
@ -104,17 +96,9 @@ public class GUI extends JFrame implements ActionListener {
this.repaint();
this.revalidate();
} else if (source == this.menuItemAddProj) {
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.ADD, agenda);
dialog.pack();
dialog.setVisible(true);
} else if (source == this.menuItemEditProj) {
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.EDIT, agenda);
dialog.pack();
dialog.setVisible(true);
agenda.openDialog(ProjectionType.ADD);
} else if (source == this.menuItemRemoveProj) {
ProjectionHandler dialog = new ProjectionHandler(ProjectionType.REMOVE, agenda);
dialog.pack();
dialog.setVisible(true);
agenda.openDialog(ProjectionType.REMOVE);
}
}
}

View file

@ -1,6 +1,7 @@
package GUI;
import DB.*;
import Exceptions.ProjectionNotSpecified;
import GUI.Agenda.Agenda;
import GUI.Types.ProjectionType;
@ -38,7 +39,9 @@ public class ProjectionHandler extends JDialog {
private Agenda agenda;
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.agenda = agenda;
createUIComponents();
@ -167,10 +170,7 @@ public class ProjectionHandler extends JDialog {
new Projection(date, competition, room, movie, slot);
break;
case EDIT:
if (projection != null)
projection.delete();
else
(Projection.find(date, competition, room, movie, slot)).delete();
projection.delete();
new Projection(date, competition, room, movie, slot);
break;
case REMOVE: