From: <sou...@us...> - 2006-03-25 05:25:55
|
Revision: 434 Author: soulcatcher Date: 2006-03-24 21:25:47 -0800 (Fri, 24 Mar 2006) ViewCVS: http://svn.sourceforge.net/pcgen/?rev=434&view=rev Log Message: ----------- finished template screen work. W00t! Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoRace.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoTemplates.java Modified: Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties 2006-03-25 05:25:20 UTC (rev 433) +++ Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties 2006-03-25 05:25:47 UTC (rev 434) @@ -939,8 +939,12 @@ in_irTemplRemoveTip=Click to remove selected Template -in_irSelectRace=Select a Race and desired Templates. +in_irSelectRace=Select a Race +in_irNoTemplate=No template selected. Try again. + +in_irSelectTemplate = Select desired Templates. + in_irHaveTemplate=Already have that template. in_irNotRemovable=That Template is not Removable @@ -961,11 +965,23 @@ in_irRemoveTemplateTip=Remove the template from the character +in_irIREr1=In InfoTemplates.resetModel the mode + +in_irIREr2=is not supported + +in_irIREr3=In InfoTemplates.getColumnName the column + +in_irIREr4=In InfoTemplates.getColumnClass the column + +in_irIREr6=In InfoTemplates.getValueAt the column + ##added 04/01/03 in_irTableStat=Stat Adjustments in_irTodoRace=Select a race. +in_irTodoTemplates= Select a template + in_various=Various in_Q=Q Modified: Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoRace.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoRace.java 2006-03-25 05:25:20 UTC (rev 433) +++ Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoRace.java 2006-03-25 05:25:47 UTC (rev 434) @@ -37,7 +37,6 @@ import pcgen.core.Constants; import pcgen.core.GameMode; -import pcgen.core.Globals; import pcgen.core.PlayerCharacter; import pcgen.core.SettingsHandler; import pcgen.gui.CharacterInfoTab; @@ -266,9 +265,8 @@ public List getToDos() { List toDoList = new ArrayList(); - if (Globals.s_EMPTYRACE.equals(pc.getRace()) || pc.getRace() == null) { - toDoList.add(PropertyFactory.getString("in_irTodoRace")); //$NON-NLS-1$ - } + toDoList.addAll(races.getToDos()); + toDoList.addAll(templates.getToDos()); return toDoList; } } \ No newline at end of file Modified: Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoTemplates.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoTemplates.java 2006-03-25 05:25:20 UTC (rev 433) +++ Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoTemplates.java 2006-03-25 05:25:47 UTC (rev 434) @@ -42,7 +42,6 @@ import java.awt.event.KeyListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -94,10 +93,12 @@ import pcgen.gui.filter.FilterFactory; import pcgen.gui.panes.FlippingSplitPane; import pcgen.gui.utils.AbstractTreeTableModel; +import pcgen.gui.utils.ClickHandler; import pcgen.gui.utils.IconUtilitities; import pcgen.gui.utils.JComboBoxEx; import pcgen.gui.utils.JLabelPane; import pcgen.gui.utils.JTreeTable; +import pcgen.gui.utils.JTreeTableMouseAdapter; import pcgen.gui.utils.JTreeTableSorter; import pcgen.gui.utils.LabelTreeCellRenderer; import pcgen.gui.utils.PObjectNode; @@ -139,10 +140,6 @@ private JLabel selSortLabel = new JLabel(PropertyFactory.getString("in_irSortTemplSel")); private JComboBoxEx viewSelComboBox = new JComboBoxEx(); private int viewSelMode = 0; - private final JLabel lblSelQFilter = new JLabel("Filter:"); - private JTextField textSelQFilter = new JTextField(); - private JButton clearSelQFilterButton = new JButton("Clear"); - private static Integer saveSelViewMode = null; private JButton removeButton; private TemplatesTableModel selectedModel; @@ -191,326 +188,35 @@ }); } - public void setPc(PlayerCharacter pc) - { - if(this.pc != pc || pc.getSerial() > serial) - { - this.pc = pc; - serial = pc.getSerial(); - forceRefresh(); - } - } - - public PlayerCharacter getPc() - { - return pc; - } - - public int getTabOrder() - { - return SettingsHandler.getPCGenOption(".Panel.Race.Order", Constants.TAB_TEMPLATES); - } - - public void setTabOrder(int order) - { - SettingsHandler.setPCGenOption(".Panel.Race.Order", order); - } - - public String getTabName() - { - GameMode game = SettingsHandler.getGame(); - return game.getTabName(Constants.TAB_TEMPLATES); - } - - public boolean isShown() - { - GameMode game = SettingsHandler.getGame(); - return game.getTabShown(Constants.TAB_TEMPLATES); - } - - /** - * Retrieve the list of tasks to be done on the tab. - * @return List of task descriptions as Strings. - */ - public List getToDos() - { - List toDoList = new ArrayList(); - if (Globals.s_EMPTYRACE.equals(pc.getRace()) || pc.getRace() == null) - { - toDoList.add(PropertyFactory.getString("in_irTodoRace")); //$NON-NLS-1$ - } - return toDoList; - } - - public void refresh() - { - if(pc.getSerial() > serial) - { - serial = pc.getSerial(); - forceRefresh(); - } - } - - public void forceRefresh() - { - if(readyForRefresh) - { - needsUpdate = true; - updateCharacterInfo(); - } - else - { - serial = 0; - } - } - - public JComponent getView() - { - return this; - } - - /** - * Set needs update flag for templates tab - * @param b - */ - public static void setNeedsUpdate(boolean b) - { - needsUpdate = b; - } - - /** - * specifies whether the "match any" option should be available - * @return true - **/ - public final boolean isMatchAnyEnabled() - { - return true; - } - - /** - * Push an update of the tabs in the GUI - */ - public void pushUpdate() - { - final PCGen_Frame1 rootFrame = PCGen_Frame1.getInst(); - rootFrame.featList_Changed(); - rootFrame.hpTotal_Changed(); - PCGen_Frame1.forceUpdate_PlayerTabs(); - CharacterInfo pane = PCGen_Frame1.getCharacterPane(); - pane.setPaneForUpdate(pane.infoSkills()); - pane.setPaneForUpdate(pane.infoSpells()); - pane.setPaneForUpdate(pane.infoDomain()); - pane.setPaneForUpdate(pane.infoInventory()); - pane.setPaneForUpdate(pane.infoSummary()); - pane.refresh(); - } - - /** - * specifies whether the "negate/reverse" option should be available - * @return true - **/ - public final boolean isNegateEnabled() - { - return true; - } - - /** - * specifies the filter selection mode - * @return FilterConstants.MULTI_MULTI_MODE = 2 - **/ - public final int getSelectionMode() - { - return FilterConstants.MULTI_MULTI_MODE; - } - - /** - * implementation of Filterable interface - **/ - public final void initializeFilters() - { - FilterFactory.registerAllSourceFilters(this); - FilterFactory.registerAllSizeFilters(this); - FilterFactory.registerAllRaceFilters(this); - FilterFactory.registerAllPrereqAlignmentFilters(this); - } - - /** - * implementation of Filterable interface - **/ - public final void refreshFiltering() - { - availableModel.resetModel(viewMode, true); - selectedModel.resetModel(viewSelMode, false); - } - - private void setInfoLabelText(PCTemplate temp, PObjectNode pn) - { - lastTemplate = temp; //even if that's null - - StringBuffer b = new StringBuffer(); - b.append("<html>"); - - if ((temp != null)) - { - b.append("<b>").append(temp.piSubString()).append("</b>"); - b.append("<br><b>RACE TYPE</b>: ").append(temp.getRaceType()); - if (temp.getType().length() > 0) - { - b.append(" <b>TYPE</b>:").append(temp.getType()); - } - String bString = temp.getSource(); - - if (bString.length() > 0) - { - b.append(" <b>SOURCE</b>:").append(bString); - } - } - - b.append("</html>"); - infoLabel.setText(b.toString()); - } - - /** - * <p>Handles the action from <code>rightButton</code>. Adds the currently selected template - * to the character if the character is qualified.</p> - * <p>Forces update of all tabs by calling <code>forceUpdate()</code>, and updates - * <code>allTemplatesDataModel</code> to refresh template or other dependancies.</p> - */ - private void addTemplate() - { - PCTemplate template = getSelectedTemplate(); - - if ((template == null) || !template.isQualified(pc)) - { - return; - } - - pc.setDirty(true); - - PCTemplate pcTemplate = pc.getTemplateNamed(template.getName()); - - if (pcTemplate == null) - { - pc.addTemplate(template); - pushUpdate(); - availableModel.resetModel(viewMode, true); - } - else - { - JOptionPane.showMessageDialog(null, PropertyFactory.getString("in_irHaveTemplate")); - } - - CharacterInfo pane = PCGen_Frame1.getCharacterPane(); - pane.setPaneForUpdate(pane.infoFeats()); - pane.setPaneForUpdate(pane.infoDomain()); - pane.setPaneForUpdate(pane.infoSkills()); - pane.setPaneForUpdate(pane.infoSpells()); - pane.setPaneForUpdate(pane.infoSpecialAbilities()); - pane.setPaneForUpdate(pane.infoSummary()); - pane.refresh(); - - forceRefresh(); - } - - private PCTemplate getSelectedTemplate() - { - if (lastTemplate == null) - { - ShowMessageDelegate.showMessageDialog(PropertyFactory.getString("in_clNoTemplate"), Constants.s_APPNAME, MessageType.ERROR); - } - - return lastTemplate; - } - - private int getSelectedIndex(ListSelectionEvent e) - { - final DefaultListSelectionModel model = (DefaultListSelectionModel) e.getSource(); - - if (model == null) - { - return -1; - } - - return model.getMinSelectionIndex(); - } - - /** - * This is called when the tab is shown - **/ - private void formComponentShown() - { - requestFocus(); - PCGen_Frame1.setMessageAreaTextWithoutSaving(PropertyFactory.getString("in_irSelectTemplate")); - refresh(); - - int width; - int t = bsplit.getDividerLocation(); - int u = split.getDividerLocation(); - - if (!hasBeenSized) - { - t = SettingsHandler.getPCGenOption("InfoTemplate.bsplit", (int) (InfoTemplates.this.getSize().getHeight() - 120)); - u = SettingsHandler.getPCGenOption("InfoTemplate.asplit", - (int) ((InfoTemplates.this.getSize().getWidth() * 75.0) / 100.0)); - - // set the prefered width on allTemplatesTable - for (int i = 0; i < availableTable.getColumnCount(); i++) - { - TableColumn sCol = availableTable.getColumnModel().getColumn(i); - width = Globals.getCustColumnWidth("Template", i); - - if (width != 0) - { - sCol.setPreferredWidth(width); - } - - sCol.addPropertyChangeListener(new ResizeColumnListener(availableTable, "Template", i)); - } - } - - if (t > 0) - { - bsplit.setDividerLocation(t); - SettingsHandler.setPCGenOption("InfoRace.bsplit", t); - } - - if (u > 0) - { - split.setDividerLocation(u); - SettingsHandler.setPCGenOption("InfoRace.asplit", u); - } - } - - private void hookupPopupMenu(JTreeTable treeTable) - { - treeTable.addMouseListener(new TemplatePopupListener(treeTable, new TemplatePopupMenu(treeTable))); - } - private void initActionListeners() { + addFocusListener(new FocusAdapter() + { + public void focusGained(FocusEvent evt) + { + refresh(); + } + }); addComponentListener(new ComponentAdapter() { public void componentShown(ComponentEvent evt) { formComponentShown(); } - }); - addComponentListener(new ComponentAdapter() - { public void componentResized(ComponentEvent e) { int s = split.getDividerLocation(); if (s > 0) { - SettingsHandler.setPCGenOption("InfoRace.asplit", s); + SettingsHandler.setPCGenOption("InfoTemplates.asplit", s); } s = bsplit.getDividerLocation(); if (s > 0) { - SettingsHandler.setPCGenOption("InfoRace.bsplit", s); + SettingsHandler.setPCGenOption("InfoTemplates.bsplit", s); } } }); @@ -557,21 +263,6 @@ setQFilter(); } }); - textSelQFilter.getDocument().addDocumentListener(new DocumentListener() - { - public void changedUpdate(DocumentEvent evt) - { - setSelQFilter(); - } - public void insertUpdate(DocumentEvent evt) - { - setSelQFilter(); - } - public void removeUpdate(DocumentEvent evt) - { - setSelQFilter(); - } - }); clearQFilterButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) @@ -579,23 +270,11 @@ clearQFilter(); } }); - clearSelQFilterButton.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - clearSelQFilter(); - } - }); - addFocusListener(new FocusAdapter() - { - public void focusGained(FocusEvent evt) - { - refresh(); - } - }); - availableTable.getSelectionModel().addListSelectionListener(new AvailableListSelectionListener()); selectedTable.getSelectionModel().addListSelectionListener(new SelectedListSelectionListener()); + availableTable.addMouseListener(new JTreeTableMouseAdapter(availableTable, new AvailableClickHandler(), false)); + selectedTable.addMouseListener(new JTreeTableMouseAdapter(selectedTable, new SelectedClickHandler(), false)); + FilterFactory.restoreFilterSettings(this); } /** @@ -713,7 +392,6 @@ private void createTreeTables() { availableTable = new JTreeTable(availableModel); availableTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - availableTable.setDoubleBuffered(false); availableTree = availableTable.getTree(); availableTree.setRootVisible(false); @@ -722,7 +400,6 @@ selectedTable = new JTreeTable(selectedModel); selectedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - selectedTable.setDoubleBuffered(false); selectedTree = selectedTable.getTree(); selectedTree.setRootVisible(false); @@ -775,19 +452,6 @@ // Data - All Available Templates Table availablePane = new JScrollPane(availableTable); - - MouseListener aml = new MouseAdapter() - { - public void mousePressed(MouseEvent e) - { - if (e.getClickCount() == 2) - { - addTemplate(); - } - } - }; - availableTable.addMouseListener(aml); - availablePane.setViewportView(availableTable); JButton columnButton = new JButton(); availablePane.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, columnButton); @@ -808,22 +472,10 @@ // - selected templates // Header - rightPane.add(createFilterPane(selSortLabel, viewSelComboBox, lblSelQFilter, textSelQFilter, clearSelQFilterButton), BorderLayout.NORTH); + rightPane.add(createFilterPane(selSortLabel, viewSelComboBox, null, null, null), BorderLayout.NORTH); // Data - Selected Templates table selectedPane = new JScrollPane(); - - aml = new MouseAdapter() - { - public void mousePressed(MouseEvent e) - { - if (e.getClickCount() == 2) - { - removeTemplate(); - } - } - }; - selectedTable.addMouseListener(aml); selectedPane.setViewportView(selectedTable); JButton columnButton2 = new JButton(); selectedPane.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, columnButton2); @@ -914,130 +566,231 @@ return filterPanel; } + public void setPc(PlayerCharacter pc) + { + if(this.pc != pc || pc.getSerial() > serial) + { + this.pc = pc; + serial = pc.getSerial(); + forceRefresh(); + } + } + + public PlayerCharacter getPc() + { + return pc; + } + + public int getTabOrder() + { + return SettingsHandler.getPCGenOption(".Panel.Race.Order", Constants.TAB_TEMPLATES); + } + + public void setTabOrder(int order) + { + SettingsHandler.setPCGenOption(".Panel.Race.Order", order); + } + + public String getTabName() + { + GameMode game = SettingsHandler.getGame(); + return game.getTabName(Constants.TAB_TEMPLATES); + } + + public boolean isShown() + { + GameMode game = SettingsHandler.getGame(); + return game.getTabShown(Constants.TAB_TEMPLATES); + } + /** - * <p>Handles the action from <code>leftButton</code>. Removes the currently selected template - * from the character if the template is removeable.</p> - * <p>Forces update of all tabs by calling <code>forceUpdate()</code>, and updates - * <code>allTemplatesDataModel</code> to refresh template or other dependancies.</p> + * Retrieve the list of tasks to be done on the tab. + * @return List of task descriptions as Strings. */ - private void removeTemplate() + public List getToDos() { - PCTemplate template = getSelectedTemplate(); + List toDoList = new ArrayList(); + return toDoList; + } - if ((template == null) || !template.isQualified(pc)) + public void refresh() + { + if(pc.getSerial() > serial) { - return; + serial = pc.getSerial(); + forceRefresh(); } + } - pc.setDirty(true); - - PCTemplate pcTemplate = pc.getTemplateNamed(template.getName()); - - if (pcTemplate == null) + public void forceRefresh() + { + if(readyForRefresh) { - pc.removeTemplate(template); - pushUpdate(); - availableModel.resetModel(viewMode, true); - selectedModel.resetModel(viewSelMode, false); + needsUpdate = true; + updateCharacterInfo(); } else { - JOptionPane.showMessageDialog(null, PropertyFactory.getString("in_irHaveTemplate")); + serial = 0; } + } + public JComponent getView() + { + return this; + } + + /** + * Set needs update flag for templates tab + * @param b + */ + public static void setNeedsUpdate(boolean b) + { + needsUpdate = b; + } + + /** + * specifies whether the "match any" option should be available + * @return true + **/ + public final boolean isMatchAnyEnabled() + { + return true; + } + + /** + * Push an update of the tabs in the GUI + */ + public void pushUpdate() + { + final PCGen_Frame1 rootFrame = PCGen_Frame1.getInst(); + rootFrame.featList_Changed(); + rootFrame.hpTotal_Changed(); + PCGen_Frame1.forceUpdate_PlayerTabs(); CharacterInfo pane = PCGen_Frame1.getCharacterPane(); - pane.setPaneForUpdate(pane.infoFeats()); - pane.setPaneForUpdate(pane.infoDomain()); pane.setPaneForUpdate(pane.infoSkills()); pane.setPaneForUpdate(pane.infoSpells()); - pane.setPaneForUpdate(pane.infoSpecialAbilities()); + pane.setPaneForUpdate(pane.infoDomain()); + pane.setPaneForUpdate(pane.infoInventory()); pane.setPaneForUpdate(pane.infoSummary()); pane.refresh(); + } - forceRefresh(); + /** + * specifies whether the "negate/reverse" option should be available + * @return true + **/ + public final boolean isNegateEnabled() + { + return true; } /** - * Updates the Available table + * specifies the filter selection mode + * @return FilterConstants.MULTI_MULTI_MODE = 2 **/ - private void updateAvailableModel() + public final int getSelectionMode() { - List pathList = availableTable.getExpandedPaths(); - createAvailableModel(); - availableTable.updateUI(); - availableTable.expandPathList(pathList); + return FilterConstants.MULTI_MULTI_MODE; } /** - * Updates the Selected table + * implementation of Filterable interface **/ - private void updateSelectedModel() + public final void initializeFilters() { - List pathList = selectedTable.getExpandedPaths(); - createSelectedModel(); - selectedTable.updateUI(); - selectedTable.expandPathList(pathList); + FilterFactory.registerAllSourceFilters(this); + FilterFactory.registerAllSizeFilters(this); + FilterFactory.registerAllRaceFilters(this); + FilterFactory.registerAllPrereqAlignmentFilters(this); } /** - * Creates the ClassModel that will be used. - */ - private void createModels() + * implementation of Filterable interface + **/ + public final void refreshFiltering() { - createSelectedModel(); - createAvailableModel(); + availableModel.resetModel(viewMode, true); + selectedModel.resetModel(viewSelMode, false); } - private void createAvailableModel() + private void setInfoLabelText(PCTemplate temp, PObjectNode pn) { - if (availableModel == null) - { - availableModel = new TemplatesTableModel(viewMode, true); - } - else - { - availableModel.resetModel(viewMode, true); - } + lastTemplate = temp; //even if that's null - if (availableSort != null) + StringBuffer b = new StringBuffer(); + b.append("<html>"); + + if ((temp != null)) { - availableSort.setRoot((PObjectNode) availableModel.getRoot()); - availableSort.sortNodeOnColumn(); + b.append("<b>").append(temp.piSubString()).append("</b>"); + b.append("<br><b>RACE TYPE</b>: ").append(temp.getRaceType()); + if (temp.getType().length() > 0) + { + b.append(" <b>TYPE</b>:").append(temp.getType()); + } + String bString = temp.getSource(); + + if (bString.length() > 0) + { + b.append(" <b>SOURCE</b>:").append(bString); + } } + + b.append("</html>"); + infoLabel.setText(b.toString()); } - private void createSelectedModel() + /** + * This is called when the tab is shown + **/ + private void formComponentShown() { - if (selectedModel == null) + requestFocus(); + PCGen_Frame1.setMessageAreaTextWithoutSaving(PropertyFactory.getString("in_irSelectTemplate")); + refresh(); + + int width; + int t = bsplit.getDividerLocation(); + int u = split.getDividerLocation(); + + if (!hasBeenSized) { - selectedModel = new TemplatesTableModel(viewSelMode, false); + t = SettingsHandler.getPCGenOption("InfoTemplate.bsplit", (int) (InfoTemplates.this.getSize().getHeight() - 120)); + u = SettingsHandler.getPCGenOption("InfoTemplate.asplit", + (int) ((InfoTemplates.this.getSize().getWidth() * 75.0) / 100.0)); + + // set the prefered width on allTemplatesTable + for (int i = 0; i < availableTable.getColumnCount(); i++) + { + TableColumn sCol = availableTable.getColumnModel().getColumn(i); + width = Globals.getCustColumnWidth("Template", i); + + if (width != 0) + { + sCol.setPreferredWidth(width); + } + + sCol.addPropertyChangeListener(new ResizeColumnListener(availableTable, "Template", i)); + } } - else + + if (t > 0) { - selectedModel.resetModel(viewSelMode, false); + bsplit.setDividerLocation(t); + SettingsHandler.setPCGenOption("InfoRace.bsplit", t); } - if (selectedSort != null) + if (u > 0) { - selectedSort.setRoot((PObjectNode) selectedModel.getRoot()); - selectedSort.sortNodeOnColumn(); + split.setDividerLocation(u); + SettingsHandler.setPCGenOption("InfoRace.asplit", u); } } - /** - * This recalculates the states of everything based - * upon the currently selected character - **/ - private final void updateCharacterInfo() + private void hookupPopupMenu(JTreeTable treeTable) { - if (!needsUpdate) - { - return; - } - - availableModel.resetModel(viewMode, true); - selectedModel.resetModel(viewSelMode, false); - needsUpdate = false; + treeTable.addMouseListener(new TemplatePopupListener(treeTable, new TemplatePopupMenu(treeTable))); } private void viewComboBoxActionPerformed() @@ -1093,50 +846,186 @@ { saveViewMode = new Integer(viewMode); } - viewMode = GuiConstants.INFORACE_VIEW_NAME; + viewMode = GuiConstants.INFOTEMPLATE_VIEW_NAME; availableModel.resetModel(viewMode, true); clearQFilterButton.setEnabled(true); viewComboBox.setEnabled(false); forceRefresh(); } - private void clearSelQFilter() + /** + * <p>Handles the action from <code>rightButton</code>. Adds the currently selected template + * to the character if the character is qualified.</p> + * <p>Forces update of all tabs by calling <code>forceUpdate()</code>, and updates + * <code>allTemplatesDataModel</code> to refresh template or other dependancies.</p> + */ + private void addTemplate() { - selectedModel.clearQFilter(); - if (saveSelViewMode != null) + PCTemplate template = getSelectedTemplate(); + + if ((template == null) || !template.isQualified(pc)) { - viewSelMode = saveSelViewMode.intValue(); - saveSelViewMode = null; + return; } - selectedModel.resetModel(viewSelMode, false); - clearSelQFilterButton.setEnabled(false); - viewSelComboBox.setEnabled(true); + + pc.setDirty(true); + + PCTemplate pcTemplate = pc.getTemplateNamed(template.getName()); + + if (pcTemplate == null) + { + pc.addTemplate(template); + pushUpdate(); + availableModel.resetModel(viewMode, true); + } + else + { + JOptionPane.showMessageDialog(null, PropertyFactory.getString("in_irHaveTemplate")); + } + forceRefresh(); } - - private void setSelQFilter() + + /** + * <p>Handles the action from <code>leftButton</code>. Removes the currently selected template + * from the character if the template is removeable.</p> + * <p>Forces update of all tabs by calling <code>forceUpdate()</code>, and updates + * <code>allTemplatesDataModel</code> to refresh template or other dependancies.</p> + */ + private void removeTemplate() { - String aString = textSelQFilter.getText(); + PCTemplate template = getSelectedTemplate(); - if (aString.length() == 0) + if ((template == null) || !template.isQualified(pc)) { - clearSelQFilter(); return; } - selectedModel.setQFilter(aString); - if (saveSelViewMode == null) + pc.setDirty(true); + + PCTemplate pcTemplate = pc.getTemplateNamed(template.getName()); + + if (pcTemplate == null) { - saveSelViewMode = new Integer(viewSelMode); + pc.removeTemplate(template); + pushUpdate(); + availableModel.resetModel(viewMode, true); + selectedModel.resetModel(viewSelMode, false); } - viewSelMode = GuiConstants.INFORACE_VIEW_NAME; - selectedModel.resetModel(viewSelMode, false); - clearSelQFilterButton.setEnabled(true); - viewSelComboBox.setEnabled(false); + else + { + JOptionPane.showMessageDialog(null, PropertyFactory.getString("in_irHaveTemplate")); + } + forceRefresh(); } + private PCTemplate getSelectedTemplate() + { + if (lastTemplate == null) + { + ShowMessageDelegate.showMessageDialog(PropertyFactory.getString("in_irNoTemplate"), Constants.s_APPNAME, MessageType.ERROR); + } + + return lastTemplate; + } + + private int getSelectedIndex(ListSelectionEvent e) + { + final DefaultListSelectionModel model = (DefaultListSelectionModel) e.getSource(); + + if (model == null) + { + return -1; + } + + return model.getMinSelectionIndex(); + } + /** + * Creates the ClassModel that will be used. + */ + private void createModels() + { + createSelectedModel(); + createAvailableModel(); + } + + private void createAvailableModel() + { + if (availableModel == null) + { + availableModel = new TemplatesTableModel(viewMode, true); + } + else + { + availableModel.resetModel(viewMode, true); + } + + if (availableSort != null) + { + availableSort.setRoot((PObjectNode) availableModel.getRoot()); + availableSort.sortNodeOnColumn(); + } + } + + private void createSelectedModel() + { + if (selectedModel == null) + { + selectedModel = new TemplatesTableModel(viewSelMode, false); + } + else + { + selectedModel.resetModel(viewSelMode, false); + } + + if (selectedSort != null) + { + selectedSort.setRoot((PObjectNode) selectedModel.getRoot()); + selectedSort.sortNodeOnColumn(); + } + } + + /** + * Updates the Available table + **/ + private void updateAvailableModel() + { + List pathList = availableTable.getExpandedPaths(); + createAvailableModel(); + availableTable.updateUI(); + availableTable.expandPathList(pathList); + } + + /** + * Updates the Selected table + **/ + private void updateSelectedModel() + { + List pathList = selectedTable.getExpandedPaths(); + createSelectedModel(); + selectedTable.updateUI(); + selectedTable.expandPathList(pathList); + } + + /** + * This recalculates the states of everything based + * upon the currently selected character + **/ + private final void updateCharacterInfo() + { + if (!needsUpdate) + { + return; + } + + updateAvailableModel(); + updateSelectedModel(); + needsUpdate = false; + } + + /** * * A TableModel to handle the full list of templates. * It pulls its data straight from Globals.getTemplateList() @@ -1177,9 +1066,15 @@ displayList = new ArrayList(); displayList.add(new Boolean(true)); displayList.add(new Boolean(getColumnViewOption(modelType + "." + COL_NAMES[1], true))); - displayList.add(new Boolean(getColumnViewOption(modelType + "." + COL_NAMES[1], true))); - displayList.add(new Boolean(getColumnViewOption(modelType + "." + COL_NAMES[1], true))); - displayList.add(new Boolean(getColumnViewOption(modelType + "." + COL_NAMES[1], true))); + if(available) { + displayList.add(new Boolean(getColumnViewOption(modelType + "." + COL_NAMES[2], true))); + displayList.add(new Boolean(getColumnViewOption(modelType + "." + COL_NAMES[3], true))); + } + else { + displayList.add(new Boolean(getColumnViewOption(modelType + "." + COL_NAMES[2], false))); + displayList.add(new Boolean(getColumnViewOption(modelType + "." + COL_NAMES[3], false))); + } + displayList.add(new Boolean(getColumnViewOption(modelType + "." + COL_NAMES[4], true))); } public boolean isCellEditable(Object node, int column) @@ -1208,8 +1103,8 @@ return String.class; default: - Logging.errorPrint(PropertyFactory.getString("in_clICEr4") + " " + column + " " - + PropertyFactory.getString("in_clICEr2")); + Logging.errorPrint(PropertyFactory.getString("in_irIREr4") + " " + column + " " + + PropertyFactory.getString("in_irIREr2")); break; } @@ -1307,140 +1202,150 @@ } /** - * This assumes the ClassModel exists + * This assumes the TemplateModel exists * but needs to be repopulated * @param mode * @param available **/ private void resetModel(int mode, boolean available) { - Iterator fI; + Iterator templItr; if (available) { - fI = Globals.getTemplateList().iterator(); + templItr = Globals.getTemplateList().iterator(); } else { - fI = pc.getTemplateList().iterator(); + templItr = pc.getTemplateList().iterator(); } switch (mode) { case GuiConstants.INFOTEMPLATE_VIEW_NAME: // Name - setRoot(new PObjectNode()); // just need a blank one - String qFilter = this.getQFilter(); + createNameViewModel(templItr); + break; - while (fI.hasNext()) - { - final PCTemplate template = (PCTemplate) fI.next(); + case GuiConstants.INFOTEMPLATE_VIEW_TYPE_NAME: // type/name + createTypeViewModel(templItr); + break; - // in the availableTable, if filtering out unqualified items - // ignore any class the PC doesn't qualify for - if (!shouldDisplayThis(template)) - { - continue; - } + case GuiConstants.INFOTEMPLATE_VIEW_SOURCE_NAME: // source/name + createSourceViewModel(templItr); + break; - if (qFilter == null || - ( template.getName().toLowerCase().indexOf(qFilter) >= 0 || - template.getType().toLowerCase().indexOf(qFilter) >= 0 )) - { - PObjectNode aFN = new PObjectNode(); - aFN.setParent((PObjectNode) super.getRoot()); - aFN.setItem(template); - PrereqHandler.passesAll( template.getPreReqList(), pc, template ); - ((PObjectNode) super.getRoot()).addChild(aFN); - } - } + default: + Logging.errorPrint(PropertyFactory.getString("in_irIREr1") + " " + mode + " " + + PropertyFactory.getString("in_irIREr2")); break; + } - case GuiConstants.INFOTEMPLATE_VIEW_TYPE_NAME: // type/name - setRoot((PObjectNode) typeRoot.clone()); + PObjectNode rootAsPObjectNode = (PObjectNode) super.getRoot(); - while (fI.hasNext()) - { - final PCTemplate template = (PCTemplate) fI.next(); + if (rootAsPObjectNode.getChildCount() > 0) + { + fireTreeNodesChanged(super.getRoot(), new TreePath(super.getRoot())); + } + } + + private void createNameViewModel(Iterator templItr) { + setRoot(new PObjectNode()); // just need a blank one + String qFilter = this.getQFilter(); - // in the availableTable, if filtering out unqualified items - // ignore any class the PC doesn't qualify for - if (!shouldDisplayThis(template)) - { - continue; - } + while (templItr.hasNext()) + { + final PCTemplate template = (PCTemplate) templItr.next(); - PObjectNode rootAsPObjectNode = (PObjectNode) super.getRoot(); - boolean added = false; + // in the availableTable, if filtering out unqualified items + // ignore any class the PC doesn't qualify for + if (!shouldDisplayThis(template)) + { + continue; + } - for (int i = 0; i < rootAsPObjectNode.getChildCount(); i++) - { - if ((!added && (i == (rootAsPObjectNode.getChildCount() - 1))) - || template.isType(((PObjectNode) rootAsPObjectNode.getChildren().get(i)).getItem() - .toString())) - { - PObjectNode aFN = new PObjectNode(); - aFN.setParent(rootAsPObjectNode.getChild(i)); - aFN.setItem(template); - PrereqHandler.passesAll(template.getPreReqList(), pc, template ) ; - rootAsPObjectNode.getChild(i).addChild(aFN); - added = true; - } - } - } + if (qFilter == null || + ( template.getName().toLowerCase().indexOf(qFilter) >= 0 || + template.getType().toLowerCase().indexOf(qFilter) >= 0 )) + { + PObjectNode aFN = new PObjectNode(); + aFN.setParent((PObjectNode) super.getRoot()); + aFN.setItem(template); + PrereqHandler.passesAll( template.getPreReqList(), pc, template ); + ((PObjectNode) super.getRoot()).addChild(aFN); + } + } + + } + + private void createTypeViewModel(Iterator templItr) { + setRoot((PObjectNode) typeRoot.clone()); - break; + while (templItr.hasNext()) + { + final PCTemplate template = (PCTemplate) templItr.next(); - case GuiConstants.INFOTEMPLATE_VIEW_SOURCE_NAME: // source/name - setRoot((PObjectNode) sourceRoot.clone()); + // in the availableTable, if filtering out unqualified items + // ignore any class the PC doesn't qualify for + if (!shouldDisplayThis(template)) + { + continue; + } - while (fI.hasNext()) - { - final PCTemplate template = (PCTemplate) fI.next(); + PObjectNode rootAsPObjectNode = (PObjectNode) super.getRoot(); + boolean added = false; - // in the availableTable, if filtering out unqualified items - // ignore any class the PC doesn't qualify for - if (!shouldDisplayThis(template)) - { - continue; - } - - PObjectNode rootAsPObjectNode = (PObjectNode) super.getRoot(); - boolean added = false; - - for (int i = 0; i < rootAsPObjectNode.getChildCount(); i++) - { - if ((!added && (i == (rootAsPObjectNode.getChildCount() - 1))) - || template.getSourceWithKey("LONG").equals(((PObjectNode) rootAsPObjectNode.getChildren().get(i)).getItem() - .toString())) - { - PObjectNode aFN = new PObjectNode(); - aFN.setParent(rootAsPObjectNode.getChild(i)); - aFN.setItem(template); - PrereqHandler.passesAll(template.getPreReqList(), pc, template ); - rootAsPObjectNode.getChild(i).addChild(aFN); - added = true; - } - } + for (int i = 0; i < rootAsPObjectNode.getChildCount(); i++) + { + if ((!added && (i == (rootAsPObjectNode.getChildCount() - 1))) + || template.isType(((PObjectNode) rootAsPObjectNode.getChildren().get(i)).getItem() + .toString())) + { + PObjectNode aFN = new PObjectNode(); + aFN.setParent(rootAsPObjectNode.getChild(i)); + aFN.setItem(template); + PrereqHandler.passesAll(template.getPreReqList(), pc, template ) ; + rootAsPObjectNode.getChild(i).addChild(aFN); + added = true; } + } + } + } - break; + private void createSourceViewModel(Iterator templItr) { + setRoot((PObjectNode) sourceRoot.clone()); - default: - Logging.errorPrint(PropertyFactory.getString("in_clICEr1") + " " + mode + " " - + PropertyFactory.getString("in_clICEr2")); + while (templItr.hasNext()) + { + final PCTemplate template = (PCTemplate) templItr.next(); - break; - } + // in the availableTable, if filtering out unqualified items + // ignore any class the PC doesn't qualify for + if (!shouldDisplayThis(template)) + { + continue; + } - PObjectNode rootAsPObjectNode = (PObjectNode) super.getRoot(); + PObjectNode rootAsPObjectNode = (PObjectNode) super.getRoot(); + boolean added = false; - if (rootAsPObjectNode.getChildCount() > 0) - { - fireTreeNodesChanged(super.getRoot(), new TreePath(super.getRoot())); + for (int i = 0; i < rootAsPObjectNode.getChildCount(); i++) + { + if ((!added && (i == (rootAsPObjectNode.getChildCount() - 1))) + || template.getSourceWithKey("LONG").equals(((PObjectNode) rootAsPObjectNode.getChildren().get(i)).getItem() + .toString())) + { + PObjectNode aFN = new PObjectNode(); + aFN.setParent(rootAsPObjectNode.getChild(i)); + aFN.setItem(template); + PrereqHandler.passesAll(template.getPreReqList(), pc, template ); + rootAsPObjectNode.getChild(i).addChild(aFN); + added = true; + } + } } } - + /** * return a boolean to indicate if the item should be included in the list. * Only Weapon, Armor and Shield type items should be checked for proficiency. @@ -1449,10 +1354,9 @@ */ private boolean shouldDisplayThis(final PCTemplate template) { - return ((modelType == 1) - || ((template.isVisible() == PCTemplate.VISIBILITY_DEFAULT + return ((template.isVisible() == PCTemplate.VISIBILITY_DEFAULT || template.isVisible() == PCTemplate.VISIBILITY_DISPLAY_ONLY) - && accept(pc, template))); + && accept(pc, template)); } public List getMColumnList() { @@ -1653,7 +1557,7 @@ if (temp == null) { lastTemplate = null; - ShowMessageDelegate.showMessageDialog(PropertyFactory.getString("in_clNoClass"), Constants.s_APPNAME, + ShowMessageDelegate.showMessageDialog(PropertyFactory.getString("in_irNoTemplate"), Constants.s_APPNAME, MessageType.ERROR); return; @@ -1728,4 +1632,53 @@ } } } + + private class AvailableClickHandler implements ClickHandler + { + public void singleClickEvent() { + // Do Nothing + } + + public void doubleClickEvent() + { + // We run this after the event has been processed so that + // we don't confuse the table when we change its contents + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + addTemplate(); + } + }); + } + public boolean isSelectable(Object obj) + { + return !(obj instanceof String); + } + } + + private class SelectedClickHandler implements ClickHandler + { + public void singleClickEvent() { + // Do nothing + } + + public void doubleClickEvent() + { + // We run this after the event has been processed so that + // we don't confuse the table when we change its contents + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + removeTemplate(); + } + }); + } + public boolean isSelectable(Object obj) + { + return !(obj instanceof String); + } + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |