Java Code Examples for javax.swing.event.TreeSelectionListener

The following are top voted examples for showing how to use javax.swing.event.TreeSelectionListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: incubator-netbeans   File: HintsPanel.java   View source code 6 votes vote down vote up
public HintsPanel(HintMetadata preselected, @NullAllowed final CustomizerContext<?, ?> cc, ClassPathBasedHintWrapper cpBased) {
    this.cpBased = cpBased;
    this.queryStatus = cc == null ? QueryStatus.NEVER : QueryStatus.SHOW_QUERIES;
    this.showHeavyInspections = true;
    init(null, true, false, false, false, cc == null, false, cc != null);
    select(preselected);
    configurationsPanel.setVisible(false);
    
    if (cc != null) {
        errorTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
            @Override public void valueChanged(TreeSelectionEvent e) {
                HintMetadata hm = getSelectedHint();

                if (hm != null) {
                    cc.setSelectedId(AnalyzerImpl.ID_JAVA_HINTS_PREFIX + hm.id);
                }
            }
        });
    }
}
 
Example 2
Project: jmt   File: TemplateAddingPanel.java   View source code 6 votes vote down vote up
public AvailableTreeTable() {
	super();
	setTreeTableModel(new AvailableTreeTableModel(data.getRoot()));
	sizeColumns();
	setRowHeight(CELL_HEIGHT);
	setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	getTableHeader().setReorderingAllowed(false);

	addTreeSelectionListener(new TreeSelectionListener() {
		@Override
		public void valueChanged(TreeSelectionEvent e) {
			TreePath path = e.getPath();
			TreeTableNode node = (TreeTableNode) path.getLastPathComponent();
			if ("template".equals(node.getType())) {
				tempDownload.setEnabled(true);
			} else {
				tempDownload.setEnabled(false);
			}
		}
	});
}
 
Example 3
Project: org.alloytools.alloy   File: OurTree.java   View source code 6 votes vote down vote up
/** Construct a Tree object with the given font size. */
public OurTree(int fontSize) {
	Font font = OurUtil.getVizFont().deriveFont((float) fontSize);
	OurTreeRenderer renderer = new OurTreeRenderer(fontSize);
	renderer.setFont(font);
	renderer.invalidate();
	renderer.validate();
	setRowHeight(0); // To allow variable row height on Mac OS X
	setCellRenderer(renderer);
	setFont(font);
	setBorder(new EmptyBorder(8, 8, 2, 2));
	getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	putClientProperty("JTree.lineStyle", "Angled");
	setRootVisible(true);
	setForeground(Color.BLACK);
	setBackground(Color.WHITE);
	setOpaque(true);
	addTreeSelectionListener(new TreeSelectionListener() {
		public void valueChanged(TreeSelectionEvent e) {
			TreePath path = OurTree.this.getSelectionPath();
			if (path != null)
				OurTree.this.listeners.fire(OurTree.this, Listener.Event.CLICK, path.getLastPathComponent());
		}
	});
}
 
Example 4
Project: ramus   File: AbstractTableView.java   View source code 6 votes vote down vote up
protected void createInnerComponent() {
    panel.removeAll();
    Attribute[] attributes = getAttributes();
    RootCreater rootCreater = getRootCreater();

    component = new RowTreeTableComponent(engine, qualifier, accessRules,
            rootCreater, attributes, framework);

    rowSet = component.getRowSet();
    table = component.getTable();

    table.getTreeSelectionModel().addTreeSelectionListener(
            new TreeSelectionListener() {
                @Override
                public void valueChanged(TreeSelectionEvent e) {
                    refreshActions();
                }
            });
    refreshActions();
    panel.add(component, BorderLayout.CENTER);
    panel.revalidate();
    panel.repaint();
}
 
Example 5
Project: Tarski   File: OurTree.java   View source code 6 votes vote down vote up
/** Construct a Tree object with the given font size. */
public OurTree(int fontSize) {
   Font font = OurUtil.getVizFont().deriveFont((float)fontSize);
   OurTreeRenderer renderer = new OurTreeRenderer(fontSize);
   renderer.setFont(font);
   renderer.invalidate();
   renderer.validate();
   setRowHeight(0); // To allow variable row height on Mac OS X
   setCellRenderer(renderer);
   setFont(font);
   setBorder(new EmptyBorder(8, 8, 2, 2));
   getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
   putClientProperty("JTree.lineStyle", "Angled");
   setRootVisible(true);
   setForeground(Color.BLACK);
   setBackground(Color.WHITE);
   setOpaque(true);
   addTreeSelectionListener(new TreeSelectionListener() {
      public void valueChanged(TreeSelectionEvent e) {
         TreePath path = OurTree.this.getSelectionPath();
         if (path!=null) OurTree.this.listeners.fire(OurTree.this, Listener.Event.CLICK, path.getLastPathComponent());
      }
   });
}
 
Example 6
Project: Tarski   File: OurTree.java   View source code 6 votes vote down vote up
/** Construct a Tree object with the given font size. */
public OurTree(int fontSize) {
   Font font = OurUtil.getVizFont().deriveFont((float)fontSize);
   OurTreeRenderer renderer = new OurTreeRenderer(fontSize);
   renderer.setFont(font);
   renderer.invalidate();
   renderer.validate();
   setRowHeight(0); // To allow variable row height on Mac OS X
   setCellRenderer(renderer);
   setFont(font);
   setBorder(new EmptyBorder(8, 8, 2, 2));
   getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
   putClientProperty("JTree.lineStyle", "Angled");
   setRootVisible(true);
   setForeground(Color.BLACK);
   setBackground(Color.WHITE);
   setOpaque(true);
   addTreeSelectionListener(new TreeSelectionListener() {
      public void valueChanged(TreeSelectionEvent e) {
         TreePath path = OurTree.this.getSelectionPath();
         if (path!=null) OurTree.this.listeners.fire(OurTree.this, Listener.Event.CLICK, path.getLastPathComponent());
      }
   });
}
 
Example 7
Project: Mujeed-Arabic-Prolog   File: FileTree.java   View source code 6 votes vote down vote up
/** Construct a FileTree */
 public FileTree(File dir) {
   setLayout(new BorderLayout());
   applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
   setBorder(null);

   // Make a tree list with all the nodes, and make it a JTree
   JTree tree = new JTree(addNodes(null, dir));
   tree.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

   // Add a listener
   tree.addTreeSelectionListener(new TreeSelectionListener() {
     public void valueChanged(TreeSelectionEvent e) {
       DefaultMutableTreeNode node = (DefaultMutableTreeNode) e
           .getPath().getLastPathComponent();
     }
   });

   add(BorderLayout.CENTER, tree);
   
   JScrollPane scrollBarExplorer = new JScrollPane();
   scrollBarExplorer.getViewport().add(tree);
   scrollBarExplorer.setBorder(null);
add(scrollBarExplorer, BorderLayout.CENTER);

 }
 
Example 8
Project: Mona-Secure-Multi-Owner-Data-Sharing-for-Dynamic-Group-in-the-Cloud   File: ViewTreeGroups.java   View source code 6 votes vote down vote up
public ViewTreeGroups(String directory) {
	//super("JTree FileSystem Viewer - JavaProgrammingForums.com");
	setTitle("GroupsTree Structure");
	fileDetailsTextArea.setEditable(false);
	fileSystemModel = new FileSystemModel(new File(directory));
	fileTree = new JTree(fileSystemModel);
	fileTree.setEditable(true);
	fileTree.addTreeSelectionListener(new TreeSelectionListener() {
		public void valueChanged(TreeSelectionEvent event) {
			File file = (File) fileTree.getLastSelectedPathComponent();
			fileDetailsTextArea.setText(getFileDetails(file));
		}
	});
	JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
			true, new JScrollPane(fileTree), new JScrollPane(
					fileDetailsTextArea));
	getContentPane().add(splitPane);
	setDefaultCloseOperation(EXIT_ON_CLOSE);
	setSize(640, 480);
	setVisible(true);
}
 
Example 9
Project: Analyst   File: NavigatorTopComponent.java   View source code 6 votes vote down vote up
public NavigatorTopComponent() {
    initComponents();

    tsl = new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            TreePath path = e.getPath();
            if(path != null) processSelection(path);
        }
    };
    tree = new ProjectTree("root");
    jTree1.addTreeSelectionListener(tsl);
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(tree.getRoot().getName());
    jTree1.setModel(new DefaultTreeModel(processNodes(root, tree.getRoot())));
    jTree1.setRootVisible(false);
    jTree1.revalidate();

    setName(Bundle.CTL_ProjectsTopComponent());
    setToolTipText(Bundle.HINT_ProjectsTopComponent());
    putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE);
    putClientProperty(TopComponent.PROP_DRAGGING_DISABLED, Boolean.TRUE);
    putClientProperty(TopComponent.PROP_MAXIMIZATION_DISABLED, Boolean.TRUE);
    putClientProperty(TopComponent.PROP_SLIDING_DISABLED, Boolean.TRUE);
    putClientProperty(TopComponent.PROP_UNDOCKING_DISABLED, Boolean.TRUE);
    putClientProperty(TopComponent.PROP_KEEP_PREFERRED_SIZE_WHEN_SLIDED_IN, Boolean.TRUE);
}
 
Example 10
Project: semtool   File: SemanticExplorerPanel.java   View source code 6 votes vote down vote up
private TreeSelectionListener getTreeSelectionListener() {
	return new TreeSelectionListener() {
		@Override
		public void valueChanged( TreeSelectionEvent e ) {
			TreePath path = e.getPath();

			switch ( path.getPathCount() ) {
				case 1:
					//This shouldn't be possible because the root node is invisible.
					break;
				case 2:
					tablemodel.clear();
					break;
				case 3:
					DefaultMutableTreeNode dmtn = DefaultMutableTreeNode.class.cast( e.getPath().getLastPathComponent() );
					URI instance = URI.class.cast( dmtn.getUserObject() );
					ModelQueryAdapter mqa = ModelQueryAdapter.describe( instance );
					mqa.useInferred( false );
					tablemodel.setModel( engine.constructNoEx( mqa ) );
					break;
				default:
					break;
			}
		}
	};
}
 
Example 11
Project: mtg-desktop-okhttp   File: ViewChecklist.java   View source code 6 votes vote down vote up
private void createView() {

		tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
		tree.addTreeSelectionListener(new TreeSelectionListener() {

			@Override
			public void valueChanged(TreeSelectionEvent e) {
				DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
				if (node == null) {
					return;
				}
				Object nodeInfo = node.getUserObject();
				if (node.isLeaf()) {
					switchView(nodeInfo.toString());
				}
			}
		});

		windowPane = new JPanel();
		windowPane.add(new TaskScreenPanel());
		JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tree, windowPane);
		getContentPane().add(pane);
	}
 
Example 12
Project: j2se_for_android   File: JTree.java   View source code 6 votes vote down vote up
public void setSelectionModel(TreeSelectionModel selectionModel) {
		if (selectionModel == null)
			return;

		TreeSelectionModel oldValue = this.selectionModel;

		if (accessibleContext != null) {
			this.selectionModel
					.removeTreeSelectionListener((TreeSelectionListener) accessibleContext);
			selectionModel
					.addTreeSelectionListener((TreeSelectionListener) accessibleContext);
		}

		this.selectionModel = selectionModel;
//		firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue, this.selectionModel);
	}
 
Example 13
Project: CVForge   File: CVForgeFrame.java   View source code 6 votes vote down vote up
/**
 * Initialize tree properties and add listener.
 */
public void setupTreeListener(){
    libTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    libTree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode)
                    libTree.getLastSelectedPathComponent();
            if (node == null)
                return;

            if (!node.children().hasMoreElements()) {
                Method m = methodCache.get(node.getUserObject());
                if (m != null){
                    callFrame.createParameterList(m);
                    callFrame.setVisible(true);
                }
            }
        }
    });
}
 
Example 14
Project: iBioSim   File: Graph.java   View source code 6 votes vote down vote up
private void addTreeListener() {
	for (int i = 1; i < tree.getRowCount(); i++) {
		tree.setSelectionRow(i);
		if (selected.equals(lastSelected)) {
			break;
		}
	}
	tree.addTreeSelectionListener(new TreeSelectionListener() {
		@Override
		public void valueChanged(TreeSelectionEvent e) {
			node = (IconNode) e.getPath().getLastPathComponent();
			updateVariableChoices(node,null);
		}
	});
	tree.setSelectionRow(0);
}
 
Example 15
Project: tda   File: TreeCategory.java   View source code 6 votes vote down vote up
/**
 * return category tree with filtered child nodes
 */
public JComponent getCatComponent(EventListener listener) {
    if(isFilterEnabled() && ((filteredCatTree == null) || (getLastUpdated() < PrefManager.get().getFiltersLastChanged()))) {
        // first refresh filter checker with current filters
        setFilterChecker(FilterChecker.getFilterChecker());
        
        // apply new filter settings.
        filteredCatTree = new JTree(filterNodes(getRootNode()));
        if(getName().startsWith("Monitors") || getName().startsWith("Threads blocked by Monitors")) {
            filteredCatTree.setShowsRootHandles(true);
        }
        filteredCatTree.setCellRenderer(new TreeRenderer());
        filteredCatTree.setRootVisible(false);
        filteredCatTree.addTreeSelectionListener((TreeSelectionListener) listener);
        setLastUpdated();
    } else if (!isFilterEnabled() && (filteredCatTree == null) || (getLastUpdated() < PrefManager.get().getFiltersLastChanged())) {
        filteredCatTree = new JTree(getRootNode());
        if(getName().startsWith("Monitors") || getName().startsWith("Threads blocked by Monitors")) {
            filteredCatTree.setShowsRootHandles(true);
        }
        filteredCatTree.setCellRenderer(new TreeRenderer());
        filteredCatTree.setRootVisible(false);
        filteredCatTree.addTreeSelectionListener((TreeSelectionListener) listener);
    }
    return(filteredCatTree);
}
 
Example 16
Project: SweetHome3D   File: FurnitureCatalogTree.java   View source code 6 votes vote down vote up
/** 
 * Adds the listeners that manage selection synchronization in this tree. 
 */
private void addSelectionListeners(final FurnitureCatalog catalog, final FurnitureCatalogController controller)
{
	final SelectionListener modelSelectionListener = new SelectionListener()
	{
		public void selectionChanged(SelectionEvent selectionEvent)
		{
			updateTreeSelectedFurniture(catalog, controller);
		}
	};
	this.treeSelectionListener = new TreeSelectionListener()
	{
		public void valueChanged(TreeSelectionEvent ev)
		{
			// Updates selected furniture in catalog from selected nodes in tree. 
			controller.removeSelectionListener(modelSelectionListener);
			controller.setSelectedFurniture(getSelectedFurniture());
			controller.addSelectionListener(modelSelectionListener);
		}
	};
	
	controller.addSelectionListener(modelSelectionListener);
	getSelectionModel().addTreeSelectionListener(this.treeSelectionListener);
}
 
Example 17
Project: intellij-ce-playground   File: HintUpdateSupply.java   View source code 6 votes vote down vote up
protected void installTreeListener(@NotNull final JTree tree) {
  tree.addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(final TreeSelectionEvent e) {
      if (!isHintVisible(HintUpdateSupply.this.myHint) || isSelectedByMouse(tree)) return;

      TreePath path = tree.getSelectionPath();
      if (path != null) {
        final PsiElement psiElement = getPsiElementForHint(path.getLastPathComponent());
        if (psiElement != null && psiElement.isValid()) {
          updateHint(psiElement);
        }
      }
    }
  });
}
 
Example 18
Project: intellij-ce-playground   File: TreeToolbarDecorator.java   View source code 6 votes vote down vote up
TreeToolbarDecorator(JTree tree, @Nullable final ElementProducer<?> producer) {
  myTree = tree;
  myProducer = producer;
  myAddActionEnabled = myRemoveActionEnabled = myUpActionEnabled = myDownActionEnabled = myTree.getModel() instanceof EditableTreeModel;
  if (myTree.getModel() instanceof EditableTreeModel) {
    createDefaultTreeActions();
  }
  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      updateButtons();
    }
  });
  myTree.addPropertyChangeListener("enabled", new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      updateButtons();
    }
  });
}
 
Example 19
Project: intellij-ce-playground   File: StructureFilteringStrategy.java   View source code 6 votes vote down vote up
public MyUI() {
  myStructureTree = new Tree();
  myStructureTree.setRootVisible(false);
  myStructureTree.setShowsRootHandles(true);
  myStructureTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    public void valueChanged(final TreeSelectionEvent e) {
      final List<FilePath> filePaths = new ArrayList<FilePath>(mySelection);

      mySelection.clear();
      final TreePath[] selectionPaths = myStructureTree.getSelectionPaths();
      if (selectionPaths != null) {
        for (TreePath selectionPath : selectionPaths) {
          Collections.addAll(mySelection, ((ChangesBrowserNode)selectionPath.getLastPathComponent()).getFilePathsUnder());
        }
      }

      if (Comparing.haveEqualElements(filePaths, mySelection)) return;

      for (ChangeListener listener : myListeners) {
        listener.stateChanged(new ChangeEvent(this));
      }
    }
  });
  myScrollPane = ScrollPaneFactory.createScrollPane(myStructureTree);
  myBuilder = new TreeModelBuilder(myProject, false);
}
 
Example 20
Project: intellij-ce-playground   File: ToolSelectDialog.java   View source code 6 votes vote down vote up
protected ToolSelectDialog(@Nullable Project project, @Nullable String actionIdToSelect, BaseToolsPanel toolsPanel) {
  super(project);
  myToolsPanel = toolsPanel;
  myToolsPanel.reset();
  setOKActionEnabled(myToolsPanel.getSingleSelectedTool() != null);
  myToolsPanel.addSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      setOKActionEnabled(myToolsPanel.getSingleSelectedTool() != null);
    }
  });
  init();
  pack();
  if (actionIdToSelect != null) {
    myToolsPanel.selectTool(actionIdToSelect);
  }
  setTitle(ToolsBundle.message("tools.dialog.title"));
}
 
Example 21
Project: intellij-ce-playground   File: FileTemplateTabAsTree.java   View source code 6 votes vote down vote up
protected FileTemplateTabAsTree(String title) {
  super(title);
  myRoot = initModel();
  MyTreeModel treeModel = new MyTreeModel(myRoot);
  myTree = new Tree(treeModel);
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);
  UIUtil.setLineStyleAngled(myTree);

  myTree.expandPath(TreeUtil.getPathFromRoot(myRoot));
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  myTree.setCellRenderer(new MyTreeCellRenderer());
  myTree.expandRow(0);

  myTree.addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      onTemplateSelected();
    }
  });
  new TreeSpeedSearch(myTree);
}
 
Example 22
Project: intellij-ce-playground   File: ScopeChooserConfigurable.java   View source code 6 votes vote down vote up
@Override
protected void initTree() {
  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      final TreePath path = e.getOldLeadSelectionPath();
      if (path != null) {
        final MyNode node = (MyNode)path.getLastPathComponent();
        final NamedConfigurable namedConfigurable = node.getConfigurable();
        if (namedConfigurable instanceof ScopeConfigurable) {
          ((ScopeConfigurable)namedConfigurable).cancelCurrentProgress();
        }
      }
    }
  });
  super.initTree();
  myTree.setShowsRootHandles(false);
  new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
    @Override
    public String convert(final TreePath treePath) {
      return ((MyNode)treePath.getLastPathComponent()).getDisplayName();
    }
  }, true);

  myTree.getEmptyText().setText(IdeBundle.message("scopes.no.scoped"));
}
 
Example 23
Project: intellij-ce-playground   File: SelectLocationDialog.java   View source code 6 votes vote down vote up
protected void init() {
  super.init();
  final String urlString = myURL.toString();
  if (myAllowActions) {
    // initialize repo browser this way - to make actions work correctly
    myRepositoryBrowser.setRepositoryURLs(new SVNURL[]{myURL}, myIsShowFiles, new UrlOpeningExpander.Factory(urlString, urlString), true);
  }
  else {
    myRepositoryBrowser.setRepositoryURL(myURL, myIsShowFiles, new UrlOpeningExpander.Factory(urlString, urlString));
  }
  myRepositoryBrowser.addChangeListener(new TreeSelectionListener() {
    public void valueChanged(TreeSelectionEvent e) {
      getOKAction().setEnabled(isOKActionEnabled());
    }
  });
}
 
Example 24
Project: intellij-ce-playground   File: SelectCreateExternalTargetDialog.java   View source code 6 votes vote down vote up
@Override
protected void init() {
  super.init();
  myFollowRemoteTarget = true;
  setTitle("Select Target For External");
  setOKButtonText("Select");
  getRepositoryBrowser().addChangeListener(new TreeSelectionListener() {
    public void valueChanged(TreeSelectionEvent e) {
      if (getOKAction() != null) {
        final String selectedURL = getRepositoryBrowser().getSelectedURL();
        if (myFollowRemoteTarget && selectedURL != null) {
          myFolderName.setText(SVNPathUtil.tail(selectedURL));
        }
        checkEnabled();
      }
    }
  });
  getOKAction().setEnabled(getRepositoryBrowser().getSelectedURL() != null);
}
 
Example 25
Project: thread-dump-analysis   File: TreeCategory.java   View source code 6 votes vote down vote up
/**
 * return category tree with filtered child nodes
 */
public JComponent getCatComponent(EventListener listener) {
    if(isFilterEnabled() && ((filteredCatTree == null) || (getLastUpdated() < PrefManager.get().getFiltersLastChanged()))) {
        // first refresh filter checker with current filters
        setFilterChecker(FilterChecker.getFilterChecker());
        
        // apply new filter settings.
        filteredCatTree = new JTree(filterNodes(getRootNode()));
        if(getName().startsWith("Monitors") || getName().startsWith("Threads blocked by Monitors")) {
            filteredCatTree.setShowsRootHandles(true);
        }
        filteredCatTree.setCellRenderer(new TreeRenderer());
        filteredCatTree.setRootVisible(false);
        filteredCatTree.addTreeSelectionListener((TreeSelectionListener) listener);
        setLastUpdated();
    } else if (!isFilterEnabled() && (filteredCatTree == null) || (getLastUpdated() < PrefManager.get().getFiltersLastChanged())) {
        filteredCatTree = new JTree(getRootNode());
        if(getName().startsWith("Monitors") || getName().startsWith("Threads blocked by Monitors")) {
            filteredCatTree.setShowsRootHandles(true);
        }
        filteredCatTree.setCellRenderer(new TreeRenderer());
        filteredCatTree.setRootVisible(false);
        filteredCatTree.addTreeSelectionListener((TreeSelectionListener) listener);
    }
    return(filteredCatTree);
}
 
Example 26
Project: mobac   File: MapAreaHighlightingLayer.java   View source code 6 votes vote down vote up
public MapAreaHighlightingLayer(JAtlasTree tree) {
	this.tree = tree;
	object = (AtlasObject) tree.getSelectionPath().getLastPathComponent();
	MainGUI.getMainGUI().previewMap.repaint();
	treeListener = new TreeSelectionListener() {

		public void valueChanged(TreeSelectionEvent event) {
			try {
				object = (AtlasObject) event.getNewLeadSelectionPath().getLastPathComponent();
			} catch (Exception e) {
				object = null;
			}
			MainGUI.getMainGUI().previewMap.repaint();
		}
	};
	tree.addTreeSelectionListener(treeListener);
	tree.getModel().addTreeModelListener(this);
}
 
Example 27
Project: WP3   File: OurTree.java   View source code 6 votes vote down vote up
/** Construct a Tree object with the given font size. */
public OurTree(int fontSize) {
   Font font = OurUtil.getVizFont().deriveFont((float)fontSize);
   OurTreeRenderer renderer = new OurTreeRenderer(fontSize);
   renderer.setFont(font);
   renderer.invalidate();
   renderer.validate();
   setRowHeight(0); // To allow variable row height on Mac OS X
   setCellRenderer(renderer);
   setFont(font);
   setBorder(new EmptyBorder(8, 8, 2, 2));
   getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
   putClientProperty("JTree.lineStyle", "Angled");
   setRootVisible(true);
   setForeground(Color.BLACK);
   setBackground(Color.WHITE);
   setOpaque(true);
   addTreeSelectionListener(new TreeSelectionListener() {
      public void valueChanged(TreeSelectionEvent e) {
         TreePath path = OurTree.this.getSelectionPath();
         if (path!=null) OurTree.this.listeners.fire(OurTree.this, Listener.Event.CLICK, path.getLastPathComponent());
      }
   });
}
 
Example 28
Project: WP3   File: OurTree.java   View source code 6 votes vote down vote up
/** Construct a Tree object with the given font size. */
public OurTree(int fontSize) {
   Font font = OurUtil.getVizFont().deriveFont((float)fontSize);
   OurTreeRenderer renderer = new OurTreeRenderer(fontSize);
   renderer.setFont(font);
   renderer.invalidate();
   renderer.validate();
   setRowHeight(0); // To allow variable row height on Mac OS X
   setCellRenderer(renderer);
   setFont(font);
   setBorder(new EmptyBorder(8, 8, 2, 2));
   getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
   putClientProperty("JTree.lineStyle", "Angled");
   setRootVisible(true);
   setForeground(Color.BLACK);
   setBackground(Color.WHITE);
   setOpaque(true);
   addTreeSelectionListener(new TreeSelectionListener() {
      public void valueChanged(TreeSelectionEvent e) {
         TreePath path = OurTree.this.getSelectionPath();
         if (path!=null) OurTree.this.listeners.fire(OurTree.this, Listener.Event.CLICK, path.getLastPathComponent());
      }
   });
}
 
Example 29
Project: cn1   File: DefaultTreeSelectionModelTest.java   View source code 6 votes vote down vote up
public void testAddTreeSelectionListener() {
    ConcreteTreeSelectionListener listener1 = new ConcreteTreeSelectionListener();
    ConcreteTreeSelectionListener listener2 = new ConcreteTreeSelectionListener();
    TreeSelectionListener[] listenersArray = null;
    model.addTreeSelectionListener(listener1);
    listenersArray = model.getTreeSelectionListeners();
    assertTrue(listenersArray.length == 1);
    assertEquals(1, model.listenerList.getListeners(TreeSelectionListener.class).length);
    assertEquals(1, model.getListeners(TreeSelectionListener.class).length);
    assertTrue(listener1.findMe(listenersArray) > 0);
    model.addTreeSelectionListener(listener2);
    listenersArray = model.getTreeSelectionListeners();
    assertEquals(2, listenersArray.length);
    assertTrue(listener1.findMe(listenersArray) > 0);
    assertTrue(listener2.findMe(listenersArray) > 0);
    model.addTreeSelectionListener(listener2);
    listenersArray = model.getTreeSelectionListeners();
    assertEquals(3, listenersArray.length);
}
 
Example 30
Project: cn1   File: DefaultTreeSelectionModelTest.java   View source code 6 votes vote down vote up
public void testGetTreeSelectionListeners() {
    ConcreteTreeSelectionListener changeListener1 = new ConcreteTreeSelectionListener();
    ConcreteTreeSelectionListener changeListener2 = new ConcreteTreeSelectionListener();
    ConcreteTreeSelectionListener changeListener3 = new ConcreteTreeSelectionListener();
    TreeSelectionListener[] listenersArray = null;
    listenersArray = model.getTreeSelectionListeners();
    assertTrue(listenersArray != null && listenersArray.length == 0);
    model.addTreeSelectionListener(changeListener1);
    model.addTreeSelectionListener(changeListener2);
    model.addTreeSelectionListener(changeListener3);
    model.addTreeSelectionListener(changeListener2);
    listenersArray = model.getTreeSelectionListeners();
    assertTrue(listenersArray.length == 4);
    assertTrue(changeListener1.findMe(listenersArray) == 1);
    assertTrue(changeListener2.findMe(listenersArray) == 2);
    assertTrue(changeListener3.findMe(listenersArray) == 1);
}
 
Example 31
Project: cn1   File: DefaultTreeSelectionModelTest.java   View source code 6 votes vote down vote up
public void testFireValueChange() {
    ConcreteTreeSelectionListener listener = new ConcreteTreeSelectionListener();
    TreeSelectionListener[] listenersArray = null;
    listenersArray = model.getTreeSelectionListeners();
    assertTrue(listenersArray != null && listenersArray.length == 0);
    model.addTreeSelectionListener(listener);
    TreePath path = new TreePath("asd");
    TreePath oldSelection = new TreePath("old");
    TreePath newSelection = new TreePath("new");
    Object source = new Object();
    boolean isNew = true;
    TreeSelectionEvent event = new TreeSelectionEvent(source, path, isNew, oldSelection,
            newSelection);
    model.fireValueChanged(event);
    assertSame(event, listener.event);
    listener.reset();
    model.fireValueChanged(null);
    assertTrue(listener.fired);
    assertNull(listener.event);
}
 
Example 32
Project: cn1   File: DefaultTreeSelectionModelTest.java   View source code 6 votes vote down vote up
public void testGetListenersClass() {
    PropertyChangeController changeListener1 = new PropertyChangeController();
    PropertyChangeController changeListener2 = new PropertyChangeController();
    TreeSelectionListener treeSelectionListener = new ConcreteTreeSelectionListener();
    EventListener[] listenersArray = null;
    listenersArray = model.getListeners(TreeSelectionListener.class);
    assertEquals(0, listenersArray.length);
    listenersArray = model.getListeners(PropertyChangeListener.class);
    assertEquals(0, listenersArray.length);
    model.addPropertyChangeListener(changeListener1);
    model.addTreeSelectionListener(treeSelectionListener);
    model.addPropertyChangeListener(changeListener2);
    model.addPropertyChangeListener(changeListener2);
    listenersArray = model.getListeners(PropertyChangeListener.class);
    assertEquals(0, listenersArray.length);
    listenersArray = model.getListeners(TreeSelectionListener.class);
    assertEquals(1, listenersArray.length);
    model.removeTreeSelectionListener(treeSelectionListener);
    listenersArray = model.getListeners(TreeSelectionListener.class);
    assertEquals(0, listenersArray.length);
}
 
Example 33
Project: cn1   File: JTreeTest.java   View source code 6 votes vote down vote up
public void testFireValueChanged() {
    final Marker changeMarker = new Marker();
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(final TreeSelectionEvent e) {
            changeMarker.setOccurred();
            changeMarker.setAuxiliary(e);
        }
    });
    TreePath eventPath = new TreePath(new DefaultMutableTreeNode("anyRoot"))
            .pathByAddingChild(new DefaultMutableTreeNode("anyNode"));
    tree.getSelectionModel().addSelectionPath(eventPath);
    assertTrue(changeMarker.isOccurred());
    assertSame(eventPath, ((TreeSelectionEvent) changeMarker.getAuxiliary()).getPath());
    changeMarker.reset();
    tree.fireValueChanged(null);
    assertTrue(changeMarker.isOccurred());
    assertNull(changeMarker.getAuxiliary());
}
 
Example 34
Project: CSSBox   File: BoxBrowser.java   View source code 6 votes vote down vote up
/**
 * This method initializes domTree	
 * 	
 * @return javax.swing.JTree	
 */
private JTree getDomTree()
{
    if (domTree == null)
    {
        domTree = new JTree();
        domTree.addTreeSelectionListener(new TreeSelectionListener() 
        {
            public void valueChanged(TreeSelectionEvent e) 
            {
                //DefaultMutableTreeNode node = (DefaultMutableTreeNode) domTree.getLastSelectedPathComponent();
                /*if (node != null)
                {
                    Box box = (Box) node.getUserObject();
                    if (box != null)
                    {
                        box.drawExtent(((BrowserCanvas) contentCanvas).getImageGraphics());
                        contentCanvas.repaint();
                        displayBoxInfo(box);
                    }
                }*/
            }
        });
    }
    return domTree;
}
 
Example 35
Project: tools-idea   File: TreeToolbarDecorator.java   View source code 6 votes vote down vote up
TreeToolbarDecorator(JTree tree, @Nullable final ElementProducer<?> producer) {
  myTree = tree;
  myProducer = producer;
  myAddActionEnabled = myRemoveActionEnabled = myUpActionEnabled = myDownActionEnabled = myTree.getModel() instanceof EditableTreeModel;
  if (myTree.getModel() instanceof EditableTreeModel) {
    createDefaultTreeActions();
  }
  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      updateButtons();
    }
  });
  myTree.addPropertyChangeListener("enabled", new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      updateButtons();
    }
  });
}
 
Example 36
Project: tools-idea   File: StructureFilteringStrategy.java   View source code 6 votes vote down vote up
public MyUI() {
  myStructureTree = new Tree();
  myStructureTree.setRootVisible(false);
  myStructureTree.setShowsRootHandles(true);
  myStructureTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    public void valueChanged(final TreeSelectionEvent e) {
      final List<FilePath> filePaths = new ArrayList<FilePath>(mySelection);

      mySelection.clear();
      final TreePath[] selectionPaths = myStructureTree.getSelectionPaths();
      if (selectionPaths != null) {
        for (TreePath selectionPath : selectionPaths) {
          Collections.addAll(mySelection, ((ChangesBrowserNode)selectionPath.getLastPathComponent()).getFilePathsUnder());
        }
      }

      if (Comparing.haveEqualElements(filePaths, mySelection)) return;

      for (ChangeListener listener : myListeners) {
        listener.stateChanged(new ChangeEvent(this));
      }
    }
  });
  myScrollPane = ScrollPaneFactory.createScrollPane(myStructureTree);
  myBuilder = new TreeModelBuilder(myProject, false);
}
 
Example 37
Project: tools-idea   File: JBTreeWithHintProvider.java   View source code 6 votes vote down vote up
private void addSelectionListener() {
  addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(final TreeSelectionEvent e) {
      if (isHintBeingShown() && getClientProperty(PopupChooserBuilder.SELECTED_BY_MOUSE_EVENT) != Boolean.TRUE) {
        final TreePath path = getSelectionPath();
        if (path != null) {
          final PsiElement psiElement = getPsiElementForHint(path.getLastPathComponent());
          if (psiElement != null && psiElement.isValid()) {
            updateHint(psiElement);
          }
        }
      }
    }
  });
}
 
Example 38
Project: tools-idea   File: ToolSelectDialog.java   View source code 6 votes vote down vote up
protected ToolSelectDialog(@Nullable Project project, @Nullable String actionIdToSelect, BaseToolsPanel toolsPanel) {
  super(project);
  myToolsPanel = toolsPanel;
  myToolsPanel.reset();
  setOKActionEnabled(myToolsPanel.getSingleSelectedTool() != null);
  myToolsPanel.addSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      setOKActionEnabled(myToolsPanel.getSingleSelectedTool() != null);
    }
  });
  init();
  pack();
  if (actionIdToSelect != null) {
    myToolsPanel.selectTool(actionIdToSelect);
  }
  setTitle(ToolsBundle.message("tools.dialog.title"));
}
 
Example 39
Project: tools-idea   File: FileTemplateTabAsTree.java   View source code 6 votes vote down vote up
protected FileTemplateTabAsTree(String title) {
  super(title);
  myRoot = initModel();
  MyTreeModel treeModel = new MyTreeModel(myRoot);
  myTree = new Tree(treeModel);
  myTree.setRootVisible(false);
  myTree.setShowsRootHandles(true);
  UIUtil.setLineStyleAngled(myTree);

  myTree.expandPath(TreeUtil.getPathFromRoot(myRoot));
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  myTree.setCellRenderer(new MyTreeCellRenderer());
  myTree.expandRow(0);

  myTree.addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      onTemplateSelected();
    }
  });
  new TreeSpeedSearch(myTree);
}
 
Example 40
Project: tools-idea   File: ScopeChooserConfigurable.java   View source code 6 votes vote down vote up
@Override
protected void initTree() {
  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      final TreePath path = e.getOldLeadSelectionPath();
      if (path != null) {
        final MyNode node = (MyNode)path.getLastPathComponent();
        final NamedConfigurable namedConfigurable = node.getConfigurable();
        if (namedConfigurable instanceof ScopeConfigurable) {
          ((ScopeConfigurable)namedConfigurable).cancelCurrentProgress();
        }
      }
    }
  });
  super.initTree();
  myTree.setShowsRootHandles(false);
  new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
    @Override
    public String convert(final TreePath treePath) {
      return ((MyNode)treePath.getLastPathComponent()).getDisplayName();
    }
  }, true);

  myTree.getEmptyText().setText(IdeBundle.message("scopes.no.scoped"));
}