Search in sources :

Example 1 with JTableEx

use of pcgen.gui2.util.JTableEx 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);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) DataInstaller(pcgen.gui2.dialog.DataInstaller) SourceSelectionFacade(pcgen.facade.core.SourceSelectionFacade) GameModeFacade(pcgen.facade.core.GameModeFacade) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) CampaignFacade(pcgen.facade.core.CampaignFacade) Point(java.awt.Point) ListSelectionListener(javax.swing.event.ListSelectionListener) BorderLayout(java.awt.BorderLayout) JTableEx(pcgen.gui2.util.JTableEx) JTable(javax.swing.JTable) SortedListFacade(pcgen.facade.util.SortedListFacade) JList(javax.swing.JList) FacadeListModel(pcgen.gui2.util.FacadeListModel)

Aggregations

BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 JList (javax.swing.JList)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTable (javax.swing.JTable)1 JTextField (javax.swing.JTextField)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 CampaignFacade (pcgen.facade.core.CampaignFacade)1 GameModeFacade (pcgen.facade.core.GameModeFacade)1 SourceSelectionFacade (pcgen.facade.core.SourceSelectionFacade)1 SortedListFacade (pcgen.facade.util.SortedListFacade)1 DataInstaller (pcgen.gui2.dialog.DataInstaller)1 FacadeListModel (pcgen.gui2.util.FacadeListModel)1 JTableEx (pcgen.gui2.util.JTableEx)1