use of pcgen.gui2.dialog.DataInstaller in project pcgen by PCGen.
the class SourceSelectionDialog method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals(SAVE_COMMAND)) {
final JList sourcesList = new JList();
final JTextField nameField = new JTextField();
ListFacade<SourceSelectionFacade> sources = new SortedListFacade<>(Comparators.toStringIgnoreCaseCollator(), FacadeFactory.getCustomSourceSelections());
sourcesList.setModel(new FacadeListModel(sources));
sourcesList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent lse) {
nameField.setText(sourcesList.getSelectedValue().toString());
}
});
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JScrollPane(sourcesList), BorderLayout.CENTER);
panel.add(nameField, BorderLayout.SOUTH);
int ret = JOptionPane.showOptionDialog(this, panel, "Save the source selection as...", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null);
if (ret == JOptionPane.OK_OPTION) {
String name = nameField.getText();
List<CampaignFacade> selectedCampaigns = advancedPanel.getSelectedCampaigns();
GameModeFacade selectedGameMode = advancedPanel.getSelectedGameMode();
SourceSelectionFacade selection = null;
for (SourceSelectionFacade sourceSelectionFacade : sources) {
if (sourceSelectionFacade.toString().equals(name)) {
selection = sourceSelectionFacade;
break;
}
}
if (selection == null) {
selection = FacadeFactory.createCustomSourceSelection(name);
}
selection.setCampaigns(selectedCampaigns);
selection.setGameMode(selectedGameMode);
basicPanel.setSourceSelection(selection);
}
} else if (command.equals(DELETE_COMMAND)) {
FacadeFactory.deleteCustomSourceSelection(basicPanel.getSourceSelection());
} else if (command.equals(LOAD_COMMAND)) {
fireSourceLoad();
} else if (command.equals(INSTALLDATA_COMMAND)) {
// Swap to the install data dialog.
setVisible(false);
DataInstaller di = new DataInstaller();
di.setVisible(true);
} else if (command.equals(HIDEUNHIDE_COMMAND)) {
SourcesTableModel model = new SourcesTableModel();
JTableEx table = new JTableEx(model);
JTable rowTable = TableUtils.createDefaultTable();
JScrollPane pane = TableUtils.createCheckBoxSelectionPane(table, rowTable);
table.setShowGrid(false);
table.setFocusable(false);
table.setRowSelectionAllowed(false);
rowTable.setRowSelectionAllowed(false);
pane.setPreferredSize(new Dimension(300, 200));
int ret = JOptionPane.showOptionDialog(this, pane, "Select Sources to be visible", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null);
if (ret == JOptionPane.OK_OPTION) {
FacadeFactory.setDisplayedSources(model.getDisplayedSources());
}
model.dispose();
} else {
//must be the cancel command
setVisible(false);
}
}
Aggregations