Search in sources :

Example 11 with CampaignFacade

use of pcgen.facade.core.CampaignFacade in project pcgen by PCGen.

the class AdvancedSourceSelectionPanel method setSourceSelection.

public void setSourceSelection(SourceSelectionFacade sources) {
    if (sources == null || sources.getGameMode() == null) {
        Logging.errorPrint("Invalid source selection " + sources + "- ignoring.");
        return;
    }
    GameModeFacade selectedGame = sources.getGameMode().get();
    for (int i = 0; i < gameModeList.getModel().getSize(); i++) {
        GameModeDisplayFacade gmdf = (GameModeDisplayFacade) gameModeList.getModel().getElementAt(i);
        if (gmdf.getGameMode() == selectedGame) {
            gameModeList.setSelectedItem(gmdf);
        }
    }
    List<CampaignFacade> wrap = new ArrayList<>(ListFacades.wrap(sources.getCampaigns()));
    wrap.sort(Comparators.toStringIgnoreCaseCollator());
    selectedCampaigns.setContents(wrap);
}
Also used : GameModeFacade(pcgen.facade.core.GameModeFacade) ArrayList(java.util.ArrayList) CampaignFacade(pcgen.facade.core.CampaignFacade) GameModeDisplayFacade(pcgen.facade.core.GameModeDisplayFacade)

Example 12 with CampaignFacade

use of pcgen.facade.core.CampaignFacade in project pcgen by PCGen.

the class AdvancedSourceSelectionPanel method selectDefaultSources.

/**
	 * Add the user's previously selected sources for this gamemode 
	 * to the selected list.  
	 * @param mode The game mode being selected
	 */
private void selectDefaultSources(GameModeFacade mode) {
    if (mode != null) {
        List<String> sourceNames;
        String defaultSelectedSources = context.initProperty(PROP_SELECTED_SOURCES + mode.toString(), //$NON-NLS-1$
        "");
        if (defaultSelectedSources == null || "".equals(defaultSelectedSources)) {
            sourceNames = mode.getDefaultDataSetList();
        } else {
            //$NON-NLS-1$
            sourceNames = Arrays.asList(defaultSelectedSources.split("\\|"));
        }
        for (String name : sourceNames) {
            for (CampaignFacade camp : FacadeFactory.getSupportedCampaigns(mode)) {
                if (name.equals(camp.toString())) {
                    selectedCampaigns.addElement(camp);
                    break;
                }
            }
        }
    }
}
Also used : CampaignFacade(pcgen.facade.core.CampaignFacade)

Example 13 with CampaignFacade

use of pcgen.facade.core.CampaignFacade in project pcgen by PCGen.

the class AdvancedSourceSelectionPanel method initComponents.

private void initComponents() {
    FlippingSplitPane mainPane = new FlippingSplitPane(JSplitPane.VERTICAL_SPLIT, "advSrcMain");
    FlippingSplitPane topPane = new FlippingSplitPane("advSrcTop");
    topPane.setResizeWeight(0.6);
    JPanel panel = new JPanel(new BorderLayout());
    //$NON-NLS-1$
    panel.add(new JLabel(LanguageBundle.getString("in_src_gameLabel")), BorderLayout.WEST);
    FacadeComboBoxModel<GameModeDisplayFacade> gameModes = new FacadeComboBoxModel<>();
    gameModes.setListFacade(FacadeFactory.getGameModeDisplays());
    gameModeList.setModel(gameModes);
    gameModeList.addActionListener(this);
    panel.add(gameModeList, BorderLayout.CENTER);
    FilterBar<Object, CampaignFacade> bar = new FilterBar<>(false);
    bar.add(panel, BorderLayout.WEST);
    bar.addDisplayableFilter(new SearchFilterPanel());
    panel = new JPanel(new BorderLayout());
    panel.add(bar, BorderLayout.NORTH);
    availableTable.setDisplayableFilter(bar);
    availableTable.setTreeViewModel(availTreeViewModel);
    availableTable.getSelectionModel().addListSelectionListener(this);
    availableTable.setTreeCellRenderer(new CampaignRenderer());
    ((DynamicTableColumnModel) availableTable.getColumnModel()).getAvailableColumns().get(2).setCellRenderer(new TableCellUtilities.AlignRenderer(SwingConstants.CENTER));
    JScrollPane pane = new JScrollPane(availableTable);
    pane.setPreferredSize(new Dimension(600, 310));
    panel.add(pane, BorderLayout.CENTER);
    Box box = Box.createHorizontalBox();
    unloadAllButton.setAction(new UnloadAllAction());
    box.add(unloadAllButton);
    box.add(Box.createHorizontalGlue());
    addButton.setHorizontalTextPosition(SwingConstants.LEADING);
    addButton.setAction(new AddAction());
    box.add(addButton);
    box.add(Box.createHorizontalStrut(5));
    box.setBorder(new EmptyBorder(0, 0, 5, 0));
    panel.add(box, BorderLayout.SOUTH);
    topPane.setLeftComponent(panel);
    JPanel selPanel = new JPanel(new BorderLayout());
    FilterBar<Object, CampaignFacade> filterBar = new FilterBar<>();
    filterBar.addDisplayableFilter(new SearchFilterPanel());
    selectedTable.setDisplayableFilter(filterBar);
    selectedTable.setTreeViewModel(selTreeViewModel);
    selectedTable.getSelectionModel().addListSelectionListener(this);
    selectedTable.setTreeCellRenderer(new CampaignRenderer());
    ((DynamicTableColumnModel) selectedTable.getColumnModel()).getAvailableColumns().get(2).setCellRenderer(new TableCellUtilities.AlignRenderer(SwingConstants.CENTER));
    JScrollPane scrollPane = new JScrollPane(selectedTable);
    scrollPane.setPreferredSize(new Dimension(300, 350));
    selPanel.add(scrollPane, BorderLayout.CENTER);
    box = Box.createHorizontalBox();
    box.add(Box.createHorizontalStrut(5));
    removeButton.setAction(new RemoveAction());
    box.add(removeButton);
    box.add(Box.createHorizontalGlue());
    box.setBorder(new EmptyBorder(0, 0, 5, 0));
    selPanel.add(box, BorderLayout.SOUTH);
    topPane.setRightComponent(selPanel);
    mainPane.setTopComponent(topPane);
    linkAction.install();
    infoPane.setPreferredSize(new Dimension(800, 150));
    mainPane.setBottomComponent(infoPane);
    mainPane.setResizeWeight(0.7);
    setLayout(new BorderLayout());
    add(mainPane, BorderLayout.CENTER);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) DynamicTableColumnModel(pcgen.gui2.util.table.DynamicTableColumnModel) JLabel(javax.swing.JLabel) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) Dimension(java.awt.Dimension) FlippingSplitPane(pcgen.gui2.tools.FlippingSplitPane) CampaignFacade(pcgen.facade.core.CampaignFacade) FacadeComboBoxModel(pcgen.gui2.util.FacadeComboBoxModel) TableCellUtilities(pcgen.gui2.util.table.TableCellUtilities) GameModeDisplayFacade(pcgen.facade.core.GameModeDisplayFacade) FilterBar(pcgen.gui2.filter.FilterBar) BorderLayout(java.awt.BorderLayout) SearchFilterPanel(pcgen.gui2.filter.SearchFilterPanel) EmptyBorder(javax.swing.border.EmptyBorder)

Example 14 with CampaignFacade

use of pcgen.facade.core.CampaignFacade 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)

Example 15 with CampaignFacade

use of pcgen.facade.core.CampaignFacade in project pcgen by PCGen.

the class SourceFileLoader method loadCampaigns.

private void loadCampaigns() throws PersistenceLayerException {
    // Unload the existing campaigns and load our selected campaign
    Globals.emptyLists();
    PersistenceManager pManager = PersistenceManager.getInstance();
    List<URI> uris = new ArrayList<>();
    for (CampaignFacade campaignFacade : selectedCampaigns) {
        uris.add(((Campaign) campaignFacade).getSourceURI());
    }
    pManager.setChosenCampaignSourcefiles(uris);
    sourcesSet.clear();
    licenseFiles.clear();
    if (selectedCampaigns.isEmpty()) {
        throw new PersistenceLayerException("You must select at least one campaign to load.");
    }
    // -- sage_sam
    try {
        LoadContext context = Globals.getContext();
        loadCampaigns(selectedGame, selectedCampaigns, context);
        // Load custom items
        loadCustomItems(context);
        finishLoad(selectedCampaigns, context);
        // Check for valid race types
        //			checkRaceTypes();
        // Verify weapons are melee or ranged
        verifyWeaponsMeleeOrRanged(context);
        //  Auto-gen additional equipment
        if (PCGenSettings.OPTIONS_CONTEXT.initBoolean(PCGenSettings.OPTION_AUTOCREATE_MW_MAGIC_EQUIP, false)) {
            EquipmentList.autoGenerateEquipment();
        }
        for (Campaign campaign : selectedCampaigns) {
            sourcesSet.add(SourceFormat.getFormattedString(campaign, SourceFormat.MEDIUM, true));
        }
        context.setLoaded(selectedCampaigns);
        /*
			 * This needs to happen after auto equipment generation and after
			 * context.setLoaded, not in finishLoad
			 */
        context.loadCampaignFacets();
        dataset = new DataSet(context, selectedGame, new DefaultListFacade<>(selectedCampaigns));
    //			//  Show the licenses
    //			showLicensesIfNeeded();
    //			showSponsorsIfNeeded();
    } catch (Throwable thr) {
        Logging.errorPrint("Exception loading files.", thr);
        uiDelegate.showErrorMessage(Constants.APPLICATION_NAME, "Failed to load campaigns, see log for details.");
    }
}
Also used : Campaign(pcgen.core.Campaign) DataSet(pcgen.core.DataSet) ArrayList(java.util.ArrayList) LoadContext(pcgen.rules.context.LoadContext) URI(java.net.URI) CampaignFacade(pcgen.facade.core.CampaignFacade) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

Aggregations

CampaignFacade (pcgen.facade.core.CampaignFacade)20 ArrayList (java.util.ArrayList)6 Campaign (pcgen.core.Campaign)5 GameMode (pcgen.core.GameMode)4 GameModeFacade (pcgen.facade.core.GameModeFacade)4 SourceSelectionFacade (pcgen.facade.core.SourceSelectionFacade)4 DefaultListFacade (pcgen.facade.util.DefaultListFacade)4 URI (java.net.URI)3 BorderLayout (java.awt.BorderLayout)2 Dimension (java.awt.Dimension)2 JPanel (javax.swing.JPanel)2 JScrollPane (javax.swing.JScrollPane)2 DataSet (pcgen.core.DataSet)2 GameModeDisplayFacade (pcgen.facade.core.GameModeDisplayFacade)2 HtmlInfoBuilder (pcgen.gui2.util.HtmlInfoBuilder)2 PCGIOHandler (pcgen.io.PCGIOHandler)2 Point (java.awt.Point)1 File (java.io.File)1 HashSet (java.util.HashSet)1 Box (javax.swing.Box)1