Пример #1
0
 @Override
 public void actionPerformed(ActionEvent e) {
   CompanionSupportFacade support = character.getCompanionSupport();
   if (REMOVE_COMMAND.equals(e.getActionCommand())) {
     CompanionFacade companion = (CompanionFacade) selectedElement;
     int ret =
         JOptionPane.showConfirmDialog(
             button,
             LanguageBundle.getFormattedString(
                 "in_companionConfirmRemovalMsg",
                 companion //$NON-NLS-1$
                     .getNameRef()
                     .getReference()),
             LanguageBundle.getString("in_companionConfirmRemoval"), // $NON-NLS-1$
             JOptionPane.YES_NO_OPTION);
     if (ret == JOptionPane.YES_OPTION) {
       support.removeCompanion(companion);
     }
   }
   if (CREATE_COMMAND.equals(e.getActionCommand())) {
     initDialog();
     String type = (String) selectedElement;
     companionDialog.setCharacter(character);
     companionDialog.setCompanionType(type);
     Utility.setDialogRelativeLocation(CompanionInfoTab.this, companionDialog);
     companionDialog.setVisible(true);
     CharacterFacade comp = companionDialog.getNewCompanion();
     if (comp != null) {
       selectCompanion(comp);
     }
   }
   cancelCellEditing();
 }
Пример #2
0
 void showCompanion(boolean switchTabs) {
   CompanionFacade companion = getSelectedCompanion();
   if (companion == null) {
     if (!switchTabs) {
       infoPane.setText(""); // $NON-NLS-1$
     }
     return;
   }
   if (isCompanionOpen(companion)) {
     CharacterFacade character = CharacterManager.getCharacterMatching(companion);
     if (character != null) {
       if (switchTabs) {
         frame.setSelectedCharacter(character);
         return;
       } else {
         sheetSupport.setCharacter(character);
         sheetSupport.refresh();
       }
     }
     // the companion was not found
     // TODO: show error, complain?
   } else if (switchTabs) {
     frame.loadCharacterFromFile(companion.getFileRef().getReference());
   } else {
     // Display a message telling the user to open the companion.
     infoPane.setText(
         LanguageBundle.getString("in_companionLoadCompanionMessage")); // $NON-NLS-1$
   }
 }
Пример #3
0
  private void selectCompanion(CompanionFacade compFacade) {
    TreeTableModel treeTableModel = companionsTable.getTreeTableModel();
    treeTableModel.getRoot();
    TreePath path = null;

    JTree tree = companionsTable.getTree();
    String companionType = compFacade.getCompanionType();
    for (int i = 0; i < tree.getRowCount(); i++) {
      TreePath pathForRow = tree.getPathForRow(i);
      Object lastPathComponent = pathForRow.getLastPathComponent();
      if (lastPathComponent.toString().startsWith(companionType)) {
        tree.expandRow(i);
      } else if (lastPathComponent
          instanceof pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode) {
        CompanionFacade rowComp =
            (CompanionFacade)
                ((pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode) lastPathComponent)
                    .getValueAt(0);

        if (rowComp != null
            && rowComp.getFileRef().getReference() == compFacade.getFileRef().getReference()
            && rowComp.getNameRef().getReference() == compFacade.getNameRef().getReference()
            && rowComp.getRaceRef().getReference() == compFacade.getRaceRef().getReference()) {
          path = pathForRow;
        }
      }
    }
    if (path != null) {
      companionsTable.getTree().setSelectionPath(path);
      companionsTable.getTree().scrollPathToVisible(path);
    }
  }
Пример #4
0
 private void addCompanion(CompanionFacade companion, boolean silently) {
   companion.getNameRef().addReferenceListener(this);
   CompanionNode child = new CompanionNode(companion);
   if (children == null) {
     children = new Vector();
   }
   @SuppressWarnings("unchecked")
   int insertIndex =
       Collections.binarySearch(children, child, Comparators.toStringIgnoreCaseCollator());
   if (insertIndex < 0) {
     if (silently) {
       insert(child, -(insertIndex + 1));
     } else {
       insertNodeInto(child, this, -(insertIndex + 1));
     }
   } else {
     if (silently) {
       insert(child, insertIndex);
     } else {
       insertNodeInto(child, this, insertIndex);
     }
   }
   if (!silently) {
     nodeChanged(this);
   }
 }
Пример #5
0
 private void removeCompanion(CompanionFacade companion) {
   companion.getNameRef().removeReferenceListener(this);
   // we create a dummy child for comparison
   CompanionNode child = new CompanionNode(companion);
   @SuppressWarnings("unchecked")
   int index =
       Collections.binarySearch(children, child, Comparators.toStringIgnoreCaseCollator());
   removeNodeFromParent((CompanionNode) getChildAt(index));
   nodeChanged(this);
 }
Пример #6
0
 private boolean isCompanionOpen(CompanionFacade companion) {
   File compFile = companion.getFileRef().getReference();
   if (compFile == null) {
     return true;
   }
   for (CharacterFacade character : CharacterManager.getCharacters()) {
     File charFile = character.getFileRef().getReference();
     if (compFile.equals(charFile)) {
       return true;
     }
   }
   return false;
 }
Пример #7
0
 private void addCompanion(CompanionFacade companion, boolean silently) {
   String type = companion.getCompanionType();
   int index = Collections.binarySearch(types, type, Comparators.toStringIgnoreCaseCollator());
   if (index < 0) {
     Logging.errorPrint(
         "Unable to add companion "
             + companion
             + " as the type "
             + type
             + " could not be found.");
     return;
   }
   CompanionTypeNode child = (CompanionTypeNode) getChildAt(index);
   child.addCompanion(companion, silently);
 }
Пример #8
0
 @Override
 public String toString() {
   return companion.getNameRef().getReference();
 }