1
0
Fork 0

Refactor GUI, ProjectionHandler and ProjectionSelecter

This commit is contained in:
Ethanell 2021-01-14 09:25:26 +01:00
parent b3d18e78b2
commit dd8a94a492
3 changed files with 24 additions and 53 deletions

View file

@ -12,7 +12,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
public class GUI extends JFrame implements ActionListener {
public class GUI extends JFrame {
private JPanel mainPanel;
private JPanel agendaPanel;
private JPanel arrowPanel;
@ -56,10 +56,10 @@ public class GUI extends JFrame implements ActionListener {
this.renderMenu();
agenda = new Agenda(agendaPanel, this.currentPage, this.currentCompetition);
previousButton.addActionListener(this);
nextButton.addActionListener(this);
menuItemAddProj.addActionListener(this);
menuItemRemoveProj.addActionListener(this);
previousButton.addActionListener(e -> nextPreviousPage(false));
nextButton.addActionListener(e -> nextPreviousPage(true));
menuItemAddProj.addActionListener(e -> agenda.openDialog(ProjectionType.ADD));
menuItemRemoveProj.addActionListener(e -> agenda.openDialog(ProjectionType.REMOVE));
setVisible(true);
}
@ -73,34 +73,22 @@ public class GUI extends JFrame implements ActionListener {
}
}
@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == previousButton) {
this.currentPage--;
Agenda agenda = new Agenda(agendaPanel, this.currentPage, this.currentCompetition);
this.currentPage = agenda.getCurrentPage();
this.repaint();
this.revalidate();
} else if (source == nextButton) {
this.currentPage++;
Agenda agenda = new Agenda(agendaPanel, this.currentPage, this.currentCompetition);
this.currentPage = agenda.getCurrentPage();
this.repaint();
this.revalidate();
} else if (source == this.menuItemAddProj) {
agenda.openDialog(ProjectionType.ADD);
} else if (source == this.menuItemRemoveProj) {
agenda.openDialog(ProjectionType.REMOVE);
}
private void nextPreviousPage(boolean next) {
if (next)
currentPage++;
else
currentPage--;
agenda = new Agenda(agendaPanel, currentPage, currentCompetition);
currentPage = agenda.getCurrentPage();
repaint();
revalidate();
}
private void switchAgenda(Competition competition) {
this.currentCompetition = competition;
this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition);
this.repaint();
this.revalidate();
currentCompetition = competition;
agenda = new Agenda(agendaPanel, 0, currentCompetition);
repaint();
revalidate();
}
private void createUIComponents() {

View file

@ -96,11 +96,7 @@ 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);
contentPane.registerKeyboardAction(e -> dispose(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}
private void onCancel() {

View file

@ -29,17 +29,9 @@ public class ProjectionSelecter extends JDialog {
getRootPane().setDefaultButton(buttonOK);
ProjectionTableModel pTM = new ProjectionTableModel(projections);
table1.setModel(pTM);
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
buttonOK.addActionListener(e -> onOK());
buttonCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
});
buttonCancel.addActionListener(e -> onCancel());
table1.addMouseListener(
new MouseAdapter() {
@Override
@ -55,7 +47,7 @@ public class ProjectionSelecter extends JDialog {
}
}
);
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
@ -63,20 +55,15 @@ public class ProjectionSelecter extends JDialog {
}
});
// 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);
contentPane.registerKeyboardAction(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();
}