Example #1
0
 /**
  * Identify the current spell book, being the spell book that spells should be added to. If no
  * books exist then return an empty string.
  *
  * @param character The character we are checking for.
  * @return The name of the 'current' spell book, or empty string if none exist.
  */
 String getCurrentSpellBookName(CharacterFacade character) {
   String spellList = "";
   Object selectedObject = selectedTable.getSelectedObject();
   if (selectedObject != null) {
     if (selectedObject instanceof SpellNode) {
       spellList = ((SpellNode) selectedObject).getRootNode().getName();
     } else if (selectedObject instanceof RootNode) {
       spellList = ((RootNode) selectedObject).getName();
     } else {
       JTree tree = selectedTable.getTree();
       TreePath path = tree.getSelectionPath();
       while (path.getParentPath() != null && (path.getParentPath().getParentPath() != null)) {
         path = path.getParentPath();
       }
       spellList = path.getLastPathComponent().toString();
     }
   }
   if (StringUtils.isEmpty(spellList)) {
     ListFacade<?> data = selectedTable.getTreeViewModel().getDataModel();
     if (!data.isEmpty()) {
       Object firstElem = data.getElementAt(0);
       if (firstElem instanceof SpellNode) {
         spellList = ((SpellNode) firstElem).getRootNode().getName();
       }
     }
   }
   return spellList;
 }
Example #2
0
 @Override
 public void valueChanged(ListSelectionEvent e) {
   if (availTable != null && !e.getValueIsAdjusting()) {
     if (e.getSource() == availTable.getSelectionModel()
         && availTable.getSelectedObject() instanceof InfoFacade) {
       InfoFacade target = (InfoFacade) availTable.getSelectedObject();
       InfoFactory factory = chooser.getInfoFactory();
       if (factory != null && target != null) {
         infoPane.setText(factory.getHTMLInfo(target));
       }
     }
   }
 }
Example #3
0
 public void restoreModels(Hashtable<?, ?> state) {
   ((TreeViewModelHandler) state.get(TreeViewModelHandler.class)).install();
   ((SpellInfoHandler) state.get(SpellInfoHandler.class)).install();
   ((ClassInfoHandler) state.get(ClassInfoHandler.class)).install();
   ((AddSpellAction) state.get(AddSpellAction.class)).install();
   ((RemoveSpellAction) state.get(RemoveSpellAction.class)).install();
   addButton.setAction((AddSpellAction) state.get(AddSpellAction.class));
   removeButton.setAction((RemoveSpellAction) state.get(RemoveSpellAction.class));
   defaultBookCombo.setModel((ComboBoxModel) state.get(Models.DefaultSpellBookModel));
   availableTable.setTreeCellRenderer(
       (QualifiedSpellTreeCellRenderer) state.get(QualifiedSpellTreeCellRenderer.class));
   selectedTable.setTreeCellRenderer(
       (QualifiedSpellTreeCellRenderer) state.get(QualifiedSpellTreeCellRenderer.class));
 }
Example #4
0
  @Override
  public void actionPerformed(ActionEvent e) {
    if (availTable != null && (e.getActionCommand().equals("ADD") || e.getSource() == availTable)) {
      List<Object> data = availTable.getSelectedData();
      if (!data.isEmpty()) {
        for (Object object : data) {
          if (object instanceof InfoFacade) {
            chooser.addSelected((InfoFacade) object);
          }
        }
      }
      return;
    }
    if (availInput != null && (e.getActionCommand().equals("ADD") || e.getSource() == availInput)) {
      String data = availInput.getText();
      if (StringUtils.isNotBlank(data)) {
        chooser.addSelected(new InfoWrapper(data));
      }
      availInput.setText("");
      return;
    }

    if (e.getActionCommand().equals("REMOVE") || e.getSource() == list) {
      Object value = list.getSelectedValue();
      if (value != null && value instanceof InfoFacade) {
        chooser.removeSelected((InfoFacade) value);
        if (availInput != null) {
          availInput.setText(value.toString());
        }
      }
      return;
    }
    if (e.getActionCommand().equals("OK")) {
      if (chooser.isRequireCompleteSelection() && chooser.getRemainingSelections().get() > 0) {
        JOptionPane.showMessageDialog(
            this,
            LanguageBundle.getFormattedString(
                "in_chooserRequireComplete", //$NON-NLS-1$
                chooser.getRemainingSelections().get()),
            chooser.getName(),
            JOptionPane.INFORMATION_MESSAGE);
        return;
      } else {
        chooser.commit();
      }
    } else {
      chooser.rollback();
    }
    committed = e.getActionCommand().equals("OK");
    dispose();
  }
Example #5
0
  private void initComponents() {
    setTitle(chooser.getName());
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosed(WindowEvent e) {
            // detach listeners from the chooser
            treeViewModel.setDelegate(null);
            listModel.setListFacade(null);
            chooser.getRemainingSelections().removeReferenceListener(ChooserDialog.this);
          }
        });
    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());

    JSplitPane split = new JSplitPane();
    JPanel leftPane = new JPanel(new BorderLayout());
    if (availTable != null) {
      availTable.setAutoCreateRowSorter(true);
      availTable.setTreeViewModel(treeViewModel);
      availTable.getRowSorter().toggleSortOrder(0);
      availTable.addActionListener(this);
      leftPane.add(new JScrollPane(availTable), BorderLayout.CENTER);
    } else {
      availInput.addActionListener(this);
      Dimension maxDim = new Dimension(Integer.MAX_VALUE, availInput.getPreferredSize().height);
      availInput.setMaximumSize(maxDim);
      JPanel availPanel = new JPanel();
      availPanel.setLayout(new BoxLayout(availPanel, BoxLayout.PAGE_AXIS));
      availPanel.add(Box.createRigidArea(new Dimension(10, 30)));
      availPanel.add(Box.createVerticalGlue());
      availPanel.add(new JLabel(LanguageBundle.getString("in_uichooser_value")));
      availPanel.add(availInput);
      availPanel.add(Box.createVerticalGlue());
      leftPane.add(availPanel, BorderLayout.WEST);
    }

    JPanel buttonPane1 = new JPanel(new FlowLayout());
    JButton addButton = new JButton(chooser.getAddButtonName());
    addButton.setActionCommand("ADD");
    addButton.addActionListener(this);
    buttonPane1.add(addButton);
    buttonPane1.add(new JLabel(Icons.Forward16.getImageIcon()));
    leftPane.add(buttonPane1, BorderLayout.SOUTH);

    split.setLeftComponent(leftPane);

    JPanel rightPane = new JPanel(new BorderLayout());
    JPanel labelPane = new JPanel(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    labelPane.add(new JLabel(chooser.getSelectionCountName()), new GridBagConstraints());
    remainingLabel.setText(chooser.getRemainingSelections().get().toString());
    labelPane.add(remainingLabel, gbc);
    labelPane.add(new JLabel(chooser.getSelectedTableTitle()), gbc);
    rightPane.add(labelPane, BorderLayout.NORTH);

    list.setModel(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.addActionListener(this);
    rightPane.add(new JScrollPane(list), BorderLayout.CENTER);

    JPanel buttonPane2 = new JPanel(new FlowLayout());
    buttonPane2.add(new JLabel(Icons.Back16.getImageIcon()));
    JButton removeButton = new JButton(chooser.getRemoveButtonName());
    removeButton.setActionCommand("REMOVE");
    removeButton.addActionListener(this);
    buttonPane2.add(removeButton);
    rightPane.add(buttonPane2, BorderLayout.SOUTH);

    split.setRightComponent(rightPane);

    if (chooser.isInfoAvailable()) {
      JSplitPane infoSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
      infoSplit.setTopComponent(split);
      infoSplit.setBottomComponent(infoPane);
      infoSplit.setResizeWeight(.8);
      pane.add(infoSplit, BorderLayout.CENTER);
      if (availTable != null) {
        availTable.getSelectionModel().addListSelectionListener(this);
      }
    } else {
      pane.add(split, BorderLayout.CENTER);
    }
    JPanel bottomPane = new JPanel(new FlowLayout());
    JButton button = new JButton(LanguageBundle.getString("in_ok")); // $NON-NLS-1$
    button.setMnemonic(LanguageBundle.getMnemonic("in_mn_ok")); // $NON-NLS-1$
    button.setActionCommand("OK");
    button.addActionListener(this);
    bottomPane.add(button);
    button = new JButton(LanguageBundle.getString("in_cancel")); // $NON-NLS-1$
    button.setMnemonic(LanguageBundle.getMnemonic("in_mn_cancel")); // $NON-NLS-1$
    button.setActionCommand("CANCEL");
    button.addActionListener(this);
    bottomPane.add(button);
    pane.add(bottomPane, BorderLayout.SOUTH);
  }