Package fr.soleil.gumtreeexplorer.core

Examples of fr.soleil.gumtreeexplorer.core.GumTreeNode


    // action to expand a node and all its children
    final InputMap treeInputMap = tree.getInputMap(JComponent.WHEN_FOCUSED);
    treeInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_MULTIPLY, 0), "MultPressed");
    tree.getActionMap().put("MultPressed", new ExpandTreeNodeAction(tree));

    GumTreeNode rootNode = new GumTreeNode("Root");
    treeModel = new DefaultTreeModel(rootNode, false);
    tree.setModel(treeModel);

    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    tree.setCellRenderer(new DefaultTreeCellRenderer() {
      @Override
      public Component getTreeCellRendererComponent(JTree tree, Object value,
          boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row,
            hasFocus);

        if (value instanceof GumTreeNode) {
          GumTreeNode gtn = (GumTreeNode) value;
          setText(getNodeName(gtn));

          Object userObject = gtn.getUserObject();
          if (userObject instanceof IDataItem) {
            IDataItem di = (IDataItem) userObject;
            NodeDataType nodeDataType = getNodeDataType(di);
            switch (nodeDataType) {
              case SCALAR:
                setIcon(ICONS.getIcon("NodeScalar"));
                break;
              case SPECTRUM:
                setIcon(ICONS.getIcon("NodeSpectrum"));
                break;
              case IMAGE:
                setIcon(ICONS.getIcon("NodeImage"));
                break;
              case IMAGE_STACK:
                setIcon(ICONS.getIcon("NodeImageStack"));
                break;
              default:
                setIcon(ICONS.getIcon("NodeUnknown"));
                break;
            }
          }

        }
        return this;
      }
    });
    tree.addTreeSelectionListener(new TreeSelectionListener() {
      public void valueChanged(TreeSelectionEvent e) {
        JTree source = (JTree) e.getSource();
        if (source.getSelectionCount() == 1) {// unnecessary with single selection mode
          GumTreeNode gtn = (GumTreeNode) source.getLastSelectedPathComponent();
          Object userObject = gtn.getUserObject();
          displayNodeInfos(userObject);
        }
      }
    });
    tree.addMouseListener(new MouseAdapter() {
      /* (non-Javadoc)
       * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
       */
      @Override
      public void mouseClicked(MouseEvent e) {
        JXTree sourceTree = (JXTree) e.getSource();
        if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
          TreePath path = sourceTree.getSelectionPath();
          // TODO récupérer la coordonnée dans le scrollpane -> conversion
          // TreePath path = sourceTree.getPathForLocation(e.getX(), e.getY());

          // we ensure we clicked on a node, not in the blank part or a handle
          if (path != null) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
            .getLastPathComponent();
            // TODO sysout SMA
            // System.out.println("Double-click on node \""
            // + getNodeName((GumTreeNode) node) + "\"");

            if (node instanceof GumTreeNode) {
              GumTreeNode gtn = (GumTreeNode) node;
              displayNodeValue(gtn);
            }
          }
        }
      }
View Full Code Here


    JScrollPane tabContent = new JScrollPane(content);
    CloseTabComponent tabComponent = new CloseTabComponent(tabbedPane, tabContent) {
      @Override
      protected void beforeRemoving(int index) {
        Component componentAt = tabbedPane.getComponentAt(index);
        GumTreeNode key = null;
        for (Entry<GumTreeNode, JComponent> entry : getDisplayedNodesTable().entrySet()) {
          if (entry.getValue().equals(componentAt)) {
            key = entry.getKey();
            break;
          }
View Full Code Here

        // TODO sysout SMA
        // System.out.println("filter key = " + selectedItem);
        filterModel.addElement(selectedItem);
      }
      // filter each opened file
      GumTreeNode root = (GumTreeNode) treeModel.getRoot();
      int childCount = root.getChildCount();
      for (int i = 0; i < childCount; i++) {
        GumTreeNode fileNode = (GumTreeNode) root.getChildAt(i);
        buildFilteredTree(selectedItem, fileNode);
      }
    }
    catch (Exception e) {
      e.printStackTrace();
View Full Code Here

      for (IGroup childGroup : fileGroup.getGroupList()) {
        addGroupNode(fileNode, childGroup);
      }

      // Get all data nodes (means NeXus dataset) sons of currently opened node
      GumTreeNode itemNode;
      for (IDataItem item : fileGroup.getDataItemList()) {
        itemNode = new GumTreeNode(item);
        fileNode.add(itemNode);
      }
    }
    else {
      IGroup fileGroup = (IGroup) fileNode.getUserObject();

      IDictionary dictionary = fileGroup.findDictionary();

      // TODO pas sûr, c'est pas encore implémenté
      String path;
      Object objectByPath;
      for (String key : dictionary.getAllKeys()) {
        if (key.contains(filterKey)) {
          path = dictionary.getPath(key);
          objectByPath = fileGroup.findObjectByPath(path);
          if (objectByPath instanceof IDataItem) {
            fileNode.add(new GumTreeNode(objectByPath));
          }
        }
      }

      // for (Entry<String, String> entry : dictionary.entrySet()) {
View Full Code Here

    }

    // Get the file root
    IGroup rootGroup = dataset.getRootGroup();

    GumTreeNode nodeRoot = (GumTreeNode) treeModel.getRoot();

    addGroupNode(nodeRoot, rootGroup);

    dataset.setTitle(file.getName());
View Full Code Here

    treeModel.reload();
  }

  private GumTreeNode addGroupNode(GumTreeNode parentNode, IGroup group) {
    GumTreeNode groupNode = new GumTreeNode(group);
    parentNode.add(groupNode);

    // Get all groups directly belonging to the current node
    for (IGroup childGroup : group.getGroupList()) {
      addGroupNode(groupNode, childGroup);
    }

    // Get all data nodes (means NeXus dataset) sons of currently opened node
    GumTreeNode itemNode;
    for (IDataItem item : group.getDataItemList()) {
      itemNode = new GumTreeNode(item);
      groupNode.add(itemNode);
    }

    return groupNode;
  }
View Full Code Here

TOP

Related Classes of fr.soleil.gumtreeexplorer.core.GumTreeNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.