Ejemplo n.º 1
0
    public void actionPerformed(ActionEvent arg0) {
      DefaultMutableTreeNode curTreeNode =
          (DefaultMutableTreeNode) treWhere.getLastSelectedPathComponent();

      if (curTreeNode == null) {
        new MessageBox(calcColumnDialog, "请选择树节点!", MessageBox.MESSAGE, MessageBox.BUTTON_OK)
            .show();
        return;
      }
      if (!curTreeNode.isLeaf()) return;

      int row = treWhere.getSelectionRows()[0];
      DefaultMutableTreeNode nextTreeNode = curTreeNode.getNextNode();
      if (!nextTreeNode.isLeaf()) return;

      DefaultTreeModel model = (DefaultTreeModel) treWhere.getModel();
      DefaultMutableTreeNode parTreeNode = (DefaultMutableTreeNode) curTreeNode.getParent();
      int index = parTreeNode.getIndex(curTreeNode);

      model.removeNodeFromParent(curTreeNode);
      model.insertNodeInto(curTreeNode, parTreeNode, index + 1);
      // 刷新节点中文名称
      if (curTreeNode != null) refreshNodeChName(curTreeNode);
      if (curTreeNode.getPreviousSibling() != null)
        refreshNodeChName(curTreeNode.getPreviousSibling());
      model.nodeChanged(curTreeNode);
      model.nodeChanged(curTreeNode.getPreviousSibling());

      treWhere.repaint();
      treWhere.setSelectionRow(row + 1);
    }
Ejemplo n.º 2
0
  private void jTree1ValueChanged(
      javax.swing.event.TreeSelectionEvent evt) { // GEN-FIRST:event_jTree1ValueChanged
    // TODO add your handling code here:

    selectedObject = null;

    if (jTree1.getLastSelectedPathComponent() != null) {
      DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent();
      Object obj = dmtn.getUserObject();
      if (!dmtn.isLeaf()) {
        return;
      }

      if (obj instanceof CustomExpression) {
        // jRTextExpressionAreaDefaultExpression.setText( obj+"");
        jRTextExpressionAreaDefaultExpression.setEditable(true);
        jRTextExpressionAreaDefaultExpression.setBackground(java.awt.Color.WHITE);
        jRTextExpressionAreaDefaultExpression.setOpaque(true);
      } else {
        if (obj instanceof JRParameter)
          jRTextExpressionAreaDefaultExpression.setText("$P{" + obj + "}");
        if (obj instanceof JRVariable)
          jRTextExpressionAreaDefaultExpression.setText("$V{" + obj + "}");
        if (obj instanceof JRField)
          jRTextExpressionAreaDefaultExpression.setText("$F{" + obj + "}");
        jRTextExpressionAreaDefaultExpression.setEditable(false);

        jRTextExpressionAreaDefaultExpression.setBackground(java.awt.Color.GRAY);
        jRTextExpressionAreaDefaultExpression.setOpaque(true);
      }
      selectedObject = obj;
    }
  } // GEN-LAST:event_jTree1ValueChanged
Ejemplo n.º 3
0
    public void actionPerformed(ActionEvent arg0) {
      DefaultMutableTreeNode curTreeNode =
          (DefaultMutableTreeNode) treWhere.getLastSelectedPathComponent();
      if (curTreeNode == null || !curTreeNode.isLeaf()) return;

      Caliber cal = (Caliber) curTreeNode.getUserObject();
      IStatisticCaliber myCaliber = cal.getACal();
      if (!(myCaliber instanceof ICustomStatisticCaliber)) {
        ICustomStatisticCaliber caliberTmp = new MySummaryStatisticCaliberImpl();
        caliberTmp.setAddSQL(myCaliber.getAddSQL());
        caliberTmp.setCompareType(myCaliber.getCompareType());
        caliberTmp.setJoinBefore(myCaliber.getJoinBefore());
        caliberTmp.setSourceColID(myCaliber.getSourceColID());
        caliberTmp.setSourceID(myCaliber.getSourceID());
        caliberTmp.setValue(myCaliber.getValue());
        caliberTmp.setCaliberID(DefinePub.getRandomUUID());
        cal.setACal(caliberTmp);
      }

      myCaliber = cal.getACal();
      if (((ICustomStatisticCaliber) myCaliber).getRParenthesis() != null) {
        ((ICustomStatisticCaliber) myCaliber)
            .setRParenthesis(((ICustomStatisticCaliber) cal.getACal()).getRParenthesis() + ")");
      } else {
        ((ICustomStatisticCaliber) myCaliber).setRParenthesis(")");
      }
      curTreeNode.setUserObject(cal);
      // 刷新节点中文名称
      refreshNodeChName(curTreeNode);
      // 刷新节点
      ((DefaultTreeModel) treWhere.getModel()).nodeChanged(curTreeNode);
    }
  /*
   * Adds a field to the format being composed
   */
  public void addField() {
    DefaultMutableTreeNode node =
        (DefaultMutableTreeNode) availableFieldsComp.getTree().getLastSelectedPathComponent();
    if (node == null
        || !node.isLeaf()
        || !(node.getUserObject() instanceof DataObjDataFieldWrapper)) {
      return; // not really a field that can be added, just empty or a string
    }

    Object obj = node.getUserObject();
    if (obj instanceof DataObjDataFieldWrapper) {
      DataObjDataFieldWrapper wrapper = (DataObjDataFieldWrapper) obj;
      String sep = sepText.getText();
      if (StringUtils.isNotEmpty(sep)) {
        try {
          DefaultStyledDocument doc = (DefaultStyledDocument) formatEditor.getStyledDocument();
          if (doc.getLength() > 0) {
            doc.insertString(doc.getLength(), sep, null);
          }
        } catch (BadLocationException ble) {
        }
      }
      insertFieldIntoTextEditor(wrapper);
      setHasChanged(true);
    }
  }
Ejemplo n.º 5
0
  /**
   * We assume database files are stored on disk as given: - database | |- class0 |- image0 |-
   * image01 ... |- class1 |- image10 ... |- classN |- imageN0 ... |- |- imageNOTClASSIFIED-0 ... |-
   * imageNOTClASSIFIED-M
   *
   * <p>Other directories or files that are not images are ignored.
   */
  public ImagesModel(JFileChooser chooser) {
    this.saxRepresentation = new HashMap<String, SAXEnhanced>();
    this.currentClassification = new ArrayList<Pair<SAXEnhanced, String>>();
    File database = chooser.getSelectedFile();
    String[] childrenFiles = database.list();
    root = new DefaultMutableTreeNode(database.getName());

    for (String main : childrenFiles) {
      String imagePath = database + "/" + main;
      File imageFile = new File(imagePath);
      if (!imageFile.isDirectory()) {
        getSAXFromImageFile(imageFile, null, root);
      } else {
        childrenFiles = new File(imagePath).list();
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(database.getName() + "/" + main);
        for (String subMain : childrenFiles) {
          String subMainImagePath = imagePath + "/" + subMain;
          File subMainImageFile = new File(subMainImagePath);
          if (!subMainImageFile.isDirectory()) {
            getSAXFromImageFile(subMainImageFile, main, node);
          }
        }
        if (!node.isLeaf()) // images are in this directory
        root.add(node);
      }
    }
  }
 /** Expand the current node and return the list of leaves (MaterialVO objects). */
 private ArrayList getComponents(DefaultMutableTreeNode node) {
   ArrayList list = new ArrayList();
   for (int i = 0; i < node.getChildCount(); i++)
     list.addAll(getComponents((DefaultMutableTreeNode) node.getChildAt(i)));
   if (node.isLeaf()) list.add(node.getUserObject());
   return list;
 }
Ejemplo n.º 7
0
  public int createTreeFromMenuBar(
      javax.swing.MenuElement subElements[],
      javax.swing.tree.DefaultMutableTreeNode treeNodes,
      javax.swing.tree.DefaultMutableTreeNode topReports,
      java.lang.String reportNodeTitle,
      java.lang.String utilitiesNodeTitle) {

    for (int i = 0; i < subElements.length; i++) {

      if (subElements[i].getClass().getName() != "javax.swing.JPopupMenu") {

        javax.swing.JMenuItem abstractButton = (javax.swing.JMenuItem) subElements[i];

        if (abstractButton.isEnabled()) {

          siblingNode = new javax.swing.tree.DefaultMutableTreeNode(abstractButton.getText());

          treeNodes.add(siblingNode);

          if (treeNodes.getUserObject() == "Reports") {

            treeNodes.setUserObject(reportNodeTitle);

            topReports.add(treeNodes);
          }

          if (treeNodes.getUserObject() == "Utility") {

            treeNodes.setUserObject(utilitiesNodeTitle);

            topReports.add(treeNodes);
          }
        }
      }

      if (subElements[i].getSubElements().length > 0) {

        createTreeFromMenuBar(
            subElements[i].getSubElements(),
            siblingNode,
            topReports,
            reportNodeTitle,
            utilitiesNodeTitle);

        if (treeNodes.isLeaf()) {

          javax.swing.tree.DefaultMutableTreeNode parentNode =
              (javax.swing.tree.DefaultMutableTreeNode) siblingNode.getParent();

          siblingNode.removeFromParent();
        }
      }

      treeCount++;
    }

    return treeCount;
  }
  private void update() {
    DefaultMutableTreeNode node = getSelectedNode();
    getOKAction().setEnabled(node != null && node.isLeaf());

    PatternDescriptor descriptor = getSelectedDescriptor();
    if (descriptor != null) {
      updateDetails(descriptor);
    }
  }
Ejemplo n.º 9
0
 public static Icon getMenuItemIcon(String menuItemKey) {
   final DefaultMutableTreeNode treeNode = getMenuBuilder().get(menuItemKey);
   if (treeNode == null
       || !treeNode.isLeaf()
       || !(treeNode.getUserObject() instanceof JMenuItem)) {
     return null;
   }
   final JMenuItem menuItem = (JMenuItem) treeNode.getUserObject();
   return menuItem.getIcon();
 }
Ejemplo n.º 10
0
  private void remove(Object obj, DefaultMutableTreeNode parent) {
    for (int i = 0; i < parent.getChildCount(); i++) {
      if (!(parent.getChildAt(i) instanceof DefaultMutableTreeNode)) continue;
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent.getChildAt(i);

      if (!node.isLeaf()) remove(obj, node);
      else if (node.isLeaf()) {
        if (node.getUserObject().equals(obj)) {
          parent.remove(node);
          if (parent.getChildCount() == 0 && parent.getParent() instanceof DefaultMutableTreeNode) {
            ((DefaultMutableTreeNode) parent.getParent()).remove(parent);
          }

          treeModel.nodeStructureChanged(root);
          expandAllTree();
          return;
        }
      }
    }
  }
Ejemplo n.º 11
0
 @SuppressWarnings("rawtypes")
 public static void insertAsNodeModelRecursively(
     final NodeModel nodeModel, final Enumeration children, final MapController mapController) {
   while (children.hasMoreElements()) {
     final DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
     final NodeModel newNodeModel = MenuUtils.insertAsNodeModel(nodeModel, child, mapController);
     if (!child.isLeaf()) {
       MenuUtils.insertAsNodeModelRecursively(newNodeModel, child.children(), mapController);
     }
   }
 }
  private static void printImpl(
      JTree tree,
      Object root,
      Collection<String> strings,
      int level,
      boolean withSelection,
      @Nullable Condition<String> nodePrintCondition) {
    DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) root;

    final Object userObject = defaultMutableTreeNode.getUserObject();
    String nodeText;
    if (userObject != null) {
      nodeText = toString(userObject, null);
    } else {
      nodeText = "null";
    }

    if (nodePrintCondition != null && !nodePrintCondition.value(nodeText)) return;

    final StringBuilder buff = new StringBuilder();
    StringUtil.repeatSymbol(buff, ' ', level);

    final boolean expanded = tree.isExpanded(new TreePath(defaultMutableTreeNode.getPath()));
    if (!defaultMutableTreeNode.isLeaf()) {
      buff.append(expanded ? "-" : "+");
    }

    final boolean selected =
        tree.getSelectionModel().isPathSelected(new TreePath(defaultMutableTreeNode.getPath()));
    if (withSelection && selected) {
      buff.append("[");
    }

    buff.append(nodeText);

    if (withSelection && selected) {
      buff.append("]");
    }

    strings.add(buff.toString());

    int childCount = tree.getModel().getChildCount(root);
    if (expanded) {
      for (int i = 0; i < childCount; i++) {
        printImpl(
            tree,
            tree.getModel().getChild(root, i),
            strings,
            level + 1,
            withSelection,
            nodePrintCondition);
      }
    }
  }
Ejemplo n.º 13
0
 // filters out non-acceleratable menu entries
 @SuppressWarnings("rawtypes")
 private static void addAcceleratableChildrenRecursively(
     final DefaultMutableTreeNode target, final Enumeration sourceChildren) {
   while (sourceChildren.hasMoreElements()) {
     final DefaultMutableTreeNode sourceChild =
         (DefaultMutableTreeNode) sourceChildren.nextElement();
     final MenuEntry menuEntry = (MenuEntry) sourceChild.getUserObject();
     if (sourceChild.isLeaf()) {
       if (menuEntry.getKeyStroke() != null) {
         target.add(new DefaultMutableTreeNode(menuEntry));
       }
     } else {
       final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(menuEntry);
       target.add(newNode);
       MenuUtils.addAcceleratableChildrenRecursively(newNode, sourceChild.children());
       if (newNode.isLeaf()) {
         target.remove(newNode);
       }
     }
   }
 }
 // ===============================================================
 // ===============================================================
 private void expandChildren(DefaultMutableTreeNode node) {
   boolean level_done = false;
   for (int i = 0; i < node.getChildCount(); i++) {
     DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i);
     if (child.isLeaf()) {
       if (!level_done) {
         expandNode(child);
         level_done = true;
       }
     } else expandChildren(child);
   }
 }
Ejemplo n.º 15
0
  @Override
  public void drop(DropTargetDropEvent dtde) {
    Point pt = dtde.getLocation();
    DropTargetContext dtc = dtde.getDropTargetContext();
    JTree tree = (JTree) dtc.getComponent();
    TreePath parentpath = tree.getClosestPathForLocation(pt.x, pt.y);
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) parentpath.getLastPathComponent();
    if (!parent.isLeaf()) {
      dtde.rejectDrop();
      return;
    }

    try {
      Transferable tr = dtde.getTransferable();
      DataFlavor[] flavors = tr.getTransferDataFlavors();
      for (int i = 0; i < flavors.length; i++) {
        if (tr.isDataFlavorSupported(flavors[i])) {
          dtde.acceptDrop(dtde.getDropAction());
          EMedium eMedium = (EMedium) tr.getTransferData(flavors[i]);
          TreeNodeUserData userData = (TreeNodeUserData) parent.getUserObject();
          String shelfName = userData.getCaption();
          if (isLibrarySelected(dtde)
              && shelfName.equals(AppProperties.INSTANCE.RENTALS_SHELF_NAME)) {
            if (!uiDelegate.addRentalEMedium(eMedium))
              JOptionPane.showMessageDialog(
                  frame, "Cannot rent e-medium!", "Add document error", JOptionPane.ERROR_MESSAGE);
          } else if (!isLibrarySelected(dtde)
              && !shelfName.equals(AppProperties.INSTANCE.RENTALS_SHELF_NAME)) {
            if (!uiDelegate.addEMediumShelf(shelfName, eMedium))
              JOptionPane.showMessageDialog(
                  frame, "Duplicated e-medium!", "Add document error", JOptionPane.ERROR_MESSAGE);
          } else
            JOptionPane.showMessageDialog(
                frame,
                "Need to rent the e-medium first!",
                "Add document error",
                JOptionPane.ERROR_MESSAGE);
          dtde.dropComplete(true);
          return;
        }
      }
      // dtde.rejectDrop();
    } catch (OperationNotSupportedException e) {
      JOptionPane.showMessageDialog(
          frame,
          "Cannot add a document to this shelf",
          "Add document error",
          JOptionPane.ERROR_MESSAGE);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 16
0
 private void _storePaths(DefaultMutableTreeNode root) {
   ArrayList<TreeNode> childNodes = childrenToArray(root);
   for (final Object childNode1 : childNodes) {
     DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) childNode1;
     TreePath path = new TreePath(childNode.getPath());
     if (myTree.isPathSelected(path)) {
       addPathToList(childNode, mySelectionPaths);
     }
     if ((myTree.isExpanded(path) || childNode.getChildCount() == 0) && !childNode.isLeaf()) {
       addPathToList(childNode, myPathsToExpand);
       _storePaths(childNode);
     }
   }
 }
Ejemplo n.º 17
0
  /**
   * 得到树的所有叶节点
   *
   * @param jTree树
   * @return
   */
  public List getIsLeafNode() {
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.getModel().getRoot();
    if (root == null) return null;

    List cache = new ArrayList();
    for (Enumeration enumeration = root.breadthFirstEnumeration();
        enumeration.hasMoreElements(); ) {
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) enumeration.nextElement();
      if (node == root) continue;
      if (node.isLeaf()) {
        cache.add(node.getUserObject());
      }
    }
    return cache;
  }
Ejemplo n.º 18
0
 @Override
 public void valueChanged(TreeSelectionEvent event) {
   TreePath path = event.getPath();
   DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
   if (!node.isLeaf()) {
     return;
   }
   Cursor cursor = hydc3View.getCursor();
   hydc3View.setCursor(new Cursor(Cursor.WAIT_CURSOR));
   String s = (String) node.getUserObject();
   //		int partsStrokes = Integer.parseInt(s.split(" ")[0]);
   String sCharacters = s.split(" ")[2];
   searchWithRadical(sCharacters);
   hydc3View.setCursor(cursor);
 }
Ejemplo n.º 19
0
 public void QuestionSelected() {
   // TODO questionSelected
   DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree2.getLastSelectedPathComponent();
   if (node == null) {
     return;
   }
   if (node.isLeaf()) {
     String title = (String) node.getUserObject();
     System.out.println("你选择了:" + title.toString());
     Long num = questionList.get(title);
     selectQuestionId = num;
     Question q = questionMap.get(num);
     jTextField1.setText(q.getTitle());
     jEditorPane1.setText(q.getContent().toString());
   }
 }
Ejemplo n.º 20
0
    public void actionPerformed(ActionEvent arg0) {
      DefaultMutableTreeNode curTreeNode =
          (DefaultMutableTreeNode) treWhere.getLastSelectedPathComponent();
      if (curTreeNode == null || !curTreeNode.isLeaf()) return;

      // 检查信息是否填写完整
      if (!checkInputInfo()) return;

      String objDs = (String) dataSourceCbx.getValue();
      String objField = (String) cbxFieldName.getValue();
      String objValue = (String) cbxWhereValue.getValue();
      String objCompare = (String) cbxCompare.getValue();

      String[] arrField = objField.split(":");
      String fieldType = arrField[1];
      fieldType = DefinePub.getFieldTypeWithCh(fieldType);
      if (DefinePub.checkCharVal(fieldType)) {
        objValue = "'" + objValue + "'";
      } else {
        // 检查一下是不是数字
        try {
          Double.parseDouble(objValue);
        } catch (Exception e) {
          new MessageBox(calcColumnDialog, "值不是合法的数字!", MessageBox.MESSAGE, MessageBox.BUTTON_OK)
              .show();
          return;
        }
      }

      DefaultMutableTreeNode defaultMutableTreeNode =
          (DefaultMutableTreeNode) treWhere.getLastSelectedPathComponent();
      if (defaultMutableTreeNode == null) return;
      IStatisticCaliber asCal = ((Caliber) defaultMutableTreeNode.getUserObject()).getACal();

      asCal.setSourceID(objDs.toString());
      asCal.setSourceColID(arrField[0]);
      asCal.setCompareType(objCompare.toString());
      asCal.setValue(objValue.toString());
      asCal.setJoinBefore(frdoType.getValue().toString());

      defaultMutableTreeNode.setUserObject(new Caliber(asCal));
      // 刷新节点中文名称
      refreshNodeChName(defaultMutableTreeNode);
      // 刷新节点
      ((DefaultTreeModel) treWhere.getModel()).nodeChanged(defaultMutableTreeNode);
    }
Ejemplo n.º 21
0
    public void actionPerformed(ActionEvent arg0) {
      DefaultMutableTreeNode curTreeNode =
          (DefaultMutableTreeNode) treWhere.getLastSelectedPathComponent();
      if (!curTreeNode.isLeaf()) return;

      // 得到父对象节点
      DefaultMutableTreeNode parNode = (DefaultMutableTreeNode) curTreeNode.getParent();
      // 得到父对象的子节点数
      int iChildCount = parNode.getChildCount();

      DefaultTreeModel model = (DefaultTreeModel) treWhere.getModel();
      model.removeNodeFromParent(curTreeNode);
      // 点有一个子节点,子节点删除时,删除父节点
      if (iChildCount == 1) {
        model.removeNodeFromParent(parNode);
      }
    }
Ejemplo n.º 22
0
    public void actionPerformed(ActionEvent arg0) {

      DefaultMutableTreeNode curTreeNode =
          (DefaultMutableTreeNode) treWhere.getLastSelectedPathComponent();
      if (curTreeNode == null || !curTreeNode.isLeaf()) return;
      Caliber cal = (Caliber) curTreeNode.getUserObject();
      if (cal.getACal() instanceof ICustomStatisticCaliber) {
        ICustomStatisticCaliber myCal = (ICustomStatisticCaliber) cal.getACal();
        myCal.setLParenthesis("");
        myCal.setRParenthesis("");
        curTreeNode.setUserObject(cal);
        // 刷新节点中文名称
        refreshNodeChName(curTreeNode);
        // 刷新节点
        ((DefaultTreeModel) treWhere.getModel()).nodeChanged(curTreeNode);
      }
    }
Ejemplo n.º 23
0
 public static void executeMenuItems(final List<String> menuItemKeys) {
   LogUtils.info("menu items to execute: " + menuItemKeys);
   final MenuBuilder menuBuilder = getMenuBuilder();
   for (String menuItemKey : menuItemKeys) {
     final DefaultMutableTreeNode treeNode = menuBuilder.get(menuItemKey);
     if (treeNode == null
         || !treeNode.isLeaf()
         || !(treeNode.getUserObject() instanceof JMenuItem)) {
       UITools.errorMessage(TextUtils.format("MenuUtils.invalid_menuitem", menuItemKey));
       return;
     }
     final JMenuItem menuItem = (JMenuItem) treeNode.getUserObject();
     final Action action = menuItem.getAction();
     LogUtils.info("executing " + menuItem.getText() + "(" + menuItemKey + ")");
     ActionEvent e = new ActionEvent(menuItem, 0, null);
     action.actionPerformed(e);
   }
 }
  /**
   * Launches factorio with the current mods selected.
   *
   * @param lastSelected The last selected TreeNode.
   */
  public boolean launchFactorio(DefaultMutableTreeNode lastSelected) {
    if (this.model.getFactorioExecutablePath().isEmpty()) {
      System.out.println("Couldn't launch factorio, invalid executable path.");
      return false;
    }

    if (lastSelected == null) return false;

    // Get the file for the mod directory.
    File modDir = new File(this.model.getFactorioModPath());
    FileUtils.deleteAllFiles(modDir);

    // We get the dir of the profile of mods and get the list of files inside the dir.
    // We get the selected node. If it's a leaf, try to get the parent (which is most likely the
    // profile)
    if (lastSelected.isLeaf() && !((DefaultMutableTreeNode) lastSelected.getParent()).isRoot())
      lastSelected = (DefaultMutableTreeNode) lastSelected.getParent();

    File profileDir = null;
    if (!lastSelected.isRoot()) {
      profileDir = new File(this.model.getFactorioModManagerPath() + lastSelected);
      copyAllEnabledMods(profileDir, modDir, lastSelected);

      // Run the factorio executable.
      try {
        Process p = Runtime.getRuntime().exec(this.model.getFactorioExecutablePath());
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    // TODO Deal with not having the right thing selected.
    if (profileDir == null) {
      System.out.println("Invalid profile selected, can't execute.");
      return false;
    }

    // writeModsToJson(FileUtils.findFileWithPartName(profileDir, "mod-list.json"),
    // modListMap.get(profileDir.getName()));
    Profile selectedProfile = this.model.getModProfileMap().get(profileDir.getName());
    selectedProfile.writeModListToJson(lastSelected.children());

    return true;
  }
Ejemplo n.º 25
0
  /** Required by TreeSelectionListener interface. */
  public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

    if (node == null) return;

    Object nodeInfo = node.getUserObject();
    if (node.isLeaf()) {
      BookInfo book = (BookInfo) nodeInfo;
      displayURL(book.bookURL);
      if (DEBUG) {
        System.out.print(book.bookURL + ":  \n    ");
      }
    } else {
      displayURL(helpURL);
    }
    if (DEBUG) {
      System.out.println(nodeInfo.toString());
    }
  }
Ejemplo n.º 26
0
 private static NodeModel insertAsNodeModel(
     final NodeModel nodeModel,
     final DefaultMutableTreeNode treeNode,
     final MapController mapController) {
   final MenuEntry menuEntry = (MenuEntry) treeNode.getUserObject();
   final String text =
       menuEntry.getKeyStroke() == null
           ? menuEntry.getLabel()
           : menuEntry.getLabel() + ": " + MenuUtils.formatKeyStroke(menuEntry.getKeyStroke());
   final NodeModel newNodeModel = mapController.newNode(text, nodeModel.getMap());
   if (!treeNode.isLeaf()) {
     newNodeModel.setFolded(true);
   }
   if (menuEntry.getIconKey() != null) {
     final MindIcon mindIcon = menuEntry.createMindIcon();
     if (mindIcon != null) newNodeModel.addIcon(mindIcon);
   }
   nodeModel.insert(newNodeModel);
   return newNodeModel;
 }
Ejemplo n.º 27
0
 /**
  * Called whenever the value of the selection changes.
  *
  * @param e the event that characterizes the change.
  */
 public void valueChanged(TreeSelectionEvent e) {
   TreePath path = e.getPath();
   if (path != null) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
     if (node.isLeaf()) {
       if (getInformation(path) != null) {
         // When selecting an image information.
         XmlInformation info = getInformation(path);
         for (int i = 0; i < listener_list.size(); i++) {
           InformationTreeSelectionListener listener =
               (InformationTreeSelectionListener) listener_list.elementAt(i);
           listener.select(info);
         }
       } else {
         // When expanding a folder.
         expandNode(node);
       }
     }
   }
 }
  private void displayTreeValueChanged(
      javax.swing.event.TreeSelectionEvent evt) { // GEN-FIRST:event_displayTreeValueChanged
    // TODO add your handling code here:
    DefaultMutableTreeNode node =
        (DefaultMutableTreeNode) displayTree.getLastSelectedPathComponent();

    if (node == null) {
      return;
    }
    String nodeText = node.toString();
    if (node.isLeaf()) {
      displayPNL.removeAll();

      switch (nodeText) {
        case "PUBLISH":
          displayPNL.add(publishPanel);
          break;
        case "AUTHOR":
          displayPNL.add(authorPanel);
          break;
        case "MEMBER":
          displayPNL.add(memberPanel);
          break;
        case "BOOKS":
          displayPNL.add(booksPanel);
          break;
        case "BORROWED BY":
          displayPNL.add(borrowedPanel);
          break;
      }

      displayPNL.revalidate();
      displayPNL.repaint();

    } else {
      displayPNL.add(featurePanel);
      displayPNL.revalidate();
      displayPNL.repaint();
    }
  } // GEN-LAST:event_displayTreeValueChanged
  private void doSaveAll() {
    ObjectOutputStream objectStream = getObjectOutputStream();

    if (objectStream != null) {
      try {
        System.out.println("Saving All " + generations.getLeafCount() + " Generations...");

        for (Enumeration e = generations.depthFirstEnumeration(); e.hasMoreElements(); ) {
          DefaultMutableTreeNode tmpNode = (DefaultMutableTreeNode) e.nextElement();

          if (tmpNode.isLeaf()) objectStream.writeObject(tmpNode.getUserObject());
        }

        objectStream.close();
        System.out.println("Save completed successfully.");
      } catch (IOException e) {
        System.err.println(e);
      }
    } else {
      System.out.println("Save All Files has been aborted!");
    }
  }
Ejemplo n.º 30
0
  // required by TreeSelectionListener interface
  public void valueChanged(TreeSelectionEvent e) {

    // get selected node
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();

    if (node == null) return;

    // get node data object
    TermNode nodeInfo = (TermNode) node.getUserObject();
    // load children only for leaf nodes and those that have
    // not been marked as processed.
    if (node.isLeaf() && node.getAllowsChildren()) {
      System.out.println("will load children for: " + nodeInfo);
      // load children. if no children, set allowsChildren to false
      if (!parent.loadChildren(node, nodeInfo.getTermId())) {
        node.setAllowsChildren(false);
      }
    }
    // loadmetadata
    System.out.println("will load metadata for: " + nodeInfo.getTermId());
    // call method on parent container
    parent.loadMetaData(nodeInfo.getTermId());
  }