Refactor GUI, ProjectionHandler and ProjectionSelecter
This commit is contained in:
parent
b3d18e78b2
commit
dd8a94a492
3 changed files with 24 additions and 53 deletions
|
@ -12,7 +12,7 @@ import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class GUI extends JFrame implements ActionListener {
|
public class GUI extends JFrame {
|
||||||
private JPanel mainPanel;
|
private JPanel mainPanel;
|
||||||
private JPanel agendaPanel;
|
private JPanel agendaPanel;
|
||||||
private JPanel arrowPanel;
|
private JPanel arrowPanel;
|
||||||
|
@ -56,10 +56,10 @@ public class GUI extends JFrame implements ActionListener {
|
||||||
this.renderMenu();
|
this.renderMenu();
|
||||||
|
|
||||||
agenda = new Agenda(agendaPanel, this.currentPage, this.currentCompetition);
|
agenda = new Agenda(agendaPanel, this.currentPage, this.currentCompetition);
|
||||||
previousButton.addActionListener(this);
|
previousButton.addActionListener(e -> nextPreviousPage(false));
|
||||||
nextButton.addActionListener(this);
|
nextButton.addActionListener(e -> nextPreviousPage(true));
|
||||||
menuItemAddProj.addActionListener(this);
|
menuItemAddProj.addActionListener(e -> agenda.openDialog(ProjectionType.ADD));
|
||||||
menuItemRemoveProj.addActionListener(this);
|
menuItemRemoveProj.addActionListener(e -> agenda.openDialog(ProjectionType.REMOVE));
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,34 +73,22 @@ public class GUI extends JFrame implements ActionListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void nextPreviousPage(boolean next) {
|
||||||
public void actionPerformed(ActionEvent e) {
|
if (next)
|
||||||
Object source = e.getSource();
|
currentPage++;
|
||||||
if (source == previousButton) {
|
else
|
||||||
this.currentPage--;
|
currentPage--;
|
||||||
Agenda agenda = new Agenda(agendaPanel, this.currentPage, this.currentCompetition);
|
agenda = new Agenda(agendaPanel, currentPage, currentCompetition);
|
||||||
this.currentPage = agenda.getCurrentPage();
|
currentPage = agenda.getCurrentPage();
|
||||||
this.repaint();
|
repaint();
|
||||||
this.revalidate();
|
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 switchAgenda(Competition competition) {
|
private void switchAgenda(Competition competition) {
|
||||||
this.currentCompetition = competition;
|
currentCompetition = competition;
|
||||||
this.agenda = new Agenda(agendaPanel, 0, this.currentCompetition);
|
agenda = new Agenda(agendaPanel, 0, currentCompetition);
|
||||||
this.repaint();
|
repaint();
|
||||||
this.revalidate();
|
revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createUIComponents() {
|
private void createUIComponents() {
|
||||||
|
|
|
@ -96,11 +96,7 @@ public class ProjectionHandler extends JDialog {
|
||||||
slotComboBox.addActionListener(actionEvent -> updateRooms());
|
slotComboBox.addActionListener(actionEvent -> updateRooms());
|
||||||
cancelButton.addActionListener(actionEvent -> dispose());
|
cancelButton.addActionListener(actionEvent -> dispose());
|
||||||
confirmButton.addActionListener(actionEvent -> confirm());
|
confirmButton.addActionListener(actionEvent -> confirm());
|
||||||
contentPane.registerKeyboardAction(new ActionListener() {
|
contentPane.registerKeyboardAction(e -> dispose(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
dispose();
|
|
||||||
}
|
|
||||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onCancel() {
|
private void onCancel() {
|
||||||
|
|
|
@ -29,17 +29,9 @@ public class ProjectionSelecter extends JDialog {
|
||||||
getRootPane().setDefaultButton(buttonOK);
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
ProjectionTableModel pTM = new ProjectionTableModel(projections);
|
ProjectionTableModel pTM = new ProjectionTableModel(projections);
|
||||||
table1.setModel(pTM);
|
table1.setModel(pTM);
|
||||||
buttonOK.addActionListener(new ActionListener() {
|
buttonOK.addActionListener(e -> onOK());
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
onOK();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
buttonCancel.addActionListener(new ActionListener() {
|
buttonCancel.addActionListener(e -> onCancel());
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
onCancel();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
table1.addMouseListener(
|
table1.addMouseListener(
|
||||||
new MouseAdapter() {
|
new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,7 +47,7 @@ public class ProjectionSelecter extends JDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// call onCancel() when cross is clicked
|
|
||||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||||
addWindowListener(new WindowAdapter() {
|
addWindowListener(new WindowAdapter() {
|
||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
|
@ -63,20 +55,15 @@ public class ProjectionSelecter extends JDialog {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// call onCancel() on ESCAPE
|
contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||||
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() {
|
private void onOK() {
|
||||||
agenda.openDialog(ProjectionType.EDIT, currentProjection);
|
agenda.openDialog(ProjectionType.EDIT, currentProjection);
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onCancel() {
|
private void onCancel() {
|
||||||
// add your code here if necessary
|
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue