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);
}
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;
}
}
}
}
}
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);
}
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);
}
}
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.");
}
}
Aggregations