protected Tree createTree() { final Tree tree = new Tree(new DefaultTreeModel(new DefaultMutableTreeNode())); tree.setCellRenderer(getTreeCellRenderer()); UIUtil.setLineStyleAngled(tree); tree.setRootVisible(false); tree.setShowsRootHandles(true); tree.addKeyListener(new TreeKeyListener()); tree.addTreeSelectionListener(new MyTreeSelectionListener()); if (!myAllowMultiSelection) { tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); } new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { if (tree.getPathForLocation(e.getX(), e.getY()) != null) { doOKAction(); return true; } return false; } }.installOn(tree); TreeUtil.installActions(tree); return tree; }
protected void initTree() { ((DefaultTreeModel) myTree.getModel()).setRoot(myRoot); myTree.setRootVisible(false); myTree.setShowsRootHandles(true); UIUtil.setLineStyleAngled(myTree); TreeUtil.installActions(myTree); myTree.setCellRenderer( new ColoredTreeCellRenderer() { public void customizeCellRenderer( JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value instanceof MyNode) { final MyNode node = ((MyNode) value); setIcon(node.getIcon(expanded)); final Font font = UIUtil.getTreeFont(); if (node.isDisplayInBold()) { setFont(font.deriveFont(Font.BOLD)); } else { setFont(font.deriveFont(Font.PLAIN)); } append( node.getDisplayName(), node.isDisplayInBold() ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES); } } }); initToolbar(); ArrayList<AnAction> actions = createActions(true); if (actions != null) { final DefaultActionGroup group = new DefaultActionGroup(); for (AnAction action : actions) { group.add(action); } actions = getAdditionalActions(); if (actions != null) { group.addSeparator(); for (AnAction action : actions) { group.add(action); } } PopupHandler.installPopupHandler( myTree, group, ActionPlaces.UNKNOWN, ActionManager.getInstance()); // popup should follow the selection } }
private void createTree() { SmartExpander.installOn(myTree); SelectionSaver.installOn(myTree); refreshTree(); myTree.addTreeSelectionListener( new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { AbstractTreeNode treeNode = (AbstractTreeNode) e.getPath().getLastPathComponent(); if (treeNode instanceof FileTreeNode) { final VirtualFilePointer pointer = ((FileTreeNode) treeNode).getFilePointer(); mySelectedUrl = pointer.getUrl(); mySelectedFile = pointer.getFile(); } else { mySelectedUrl = null; mySelectedFile = null; } } }); myTree.setCellRenderer(new UpdateTreeCellRenderer()); TreeUtil.installActions(myTree); new TreeSpeedSearch( myTree, new Convertor<TreePath, String>() { public String convert(TreePath path) { Object last = path.getLastPathComponent(); if (last instanceof AbstractTreeNode) { return ((AbstractTreeNode) last).getName(); } return TreeSpeedSearch.NODE_DESCRIPTOR_TOSTRING.convert(path); } }); myTree.addMouseListener( new PopupHandler() { public void invokePopup(Component comp, int x, int y) { final DefaultActionGroup group = (DefaultActionGroup) ActionManager.getInstance().getAction("UpdateActionGroup"); if (group != null) { // if no UpdateActionGroup was configured ActionPopupMenu popupMenu = ActionManager.getInstance() .createActionPopupMenu(ActionPlaces.UPDATE_POPUP, group); popupMenu.getComponent().show(comp, x, y); } } }); EditSourceOnDoubleClickHandler.install(myTree); EditSourceOnEnterKeyHandler.install(myTree); myTree.setSelectionRow(0); }
public ServersToolWindowContent(@NotNull Project project) { super(new BorderLayout()); myProject = project; myTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode()); myTree = new Tree(myTreeModel); myTree.setRootVisible(false); myTree.setShowsRootHandles(true); myTree.setCellRenderer(new NodeRenderer()); myTree.setLineStyleAngled(); getMainPanel().add(createToolbar(), BorderLayout.WEST); Splitter splitter = new Splitter(false, 0.3f); splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myTree, SideBorder.LEFT)); myPropertiesPanelLayout = new CardLayout(); myPropertiesPanel = new JPanel(myPropertiesPanelLayout); myMessageLabel = new JLabel(EMPTY_SELECTION_MESSAGE, SwingConstants.CENTER); myPropertiesPanel.add(MESSAGE_CARD, new Wrapper(myMessageLabel)); splitter.setSecondComponent(myPropertiesPanel); getMainPanel().add(splitter, BorderLayout.CENTER); setupBuilder(project); for (RemoteServersViewContributor contributor : RemoteServersViewContributor.EP_NAME.getExtensions()) { contributor.setupTree(myProject, myTree, myBuilder); } myTree.addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { onSelectionChanged(); } }); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent event) { Set<ServersTreeStructure.RemoteServerNode> nodes = getSelectedRemoteServerNodes(); if (nodes.size() == 1) { RemoteServer<?> server = nodes.iterator().next().getValue(); ServerConnectionManager.getInstance().getOrCreateConnection(server); return true; } return false; } }.installOn(myTree); }
public void setCellRenderer(final TreeCellRenderer x) { super.setCellRenderer( new TreeCellRenderer() { public Component getTreeCellRendererComponent( JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { return x.getTreeCellRendererComponent( tree, value, selected, expanded, leaf, row, myCellFocused); } }); }
private void initTree(Tree tree) { tree.setCellRenderer(new MyTreeCellRenderer()); tree.setRootVisible(false); tree.setShowsRootHandles(true); tree.setLineStyleAngled(); TreeUtil.installActions(tree); SmartExpander.installOn(tree); new TreeSpeedSearch(tree); tree.addTreeWillExpandListener( new TreeWillExpandListener() { @Override public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { ((PackageDependenciesNode) event.getPath().getLastPathComponent()).sortChildren(); } @Override public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {} }); PopupHandler.installUnknownPopupHandler( tree, createTreePopupActions(), ActionManager.getInstance()); }
@Override protected JComponent createCenterPanel() { final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode()); myTree = new Tree(model); ProjectAbstractTreeStructureBase treeStructure = new AbstractProjectTreeStructure(myProject) { @Override public boolean isFlattenPackages() { return false; } @Override public boolean isShowMembers() { return myIsShowMembers; } @Override public boolean isHideEmptyMiddlePackages() { return true; } @Override public boolean isAbbreviatePackageNames() { return false; } @Override public boolean isShowLibraryContents() { return myIsShowLibraryContents; } @Override public boolean isShowModules() { return false; } }; myBuilder = new ProjectTreeBuilder(myProject, myTree, model, AlphaComparator.INSTANCE, treeStructure); myTree.setRootVisible(false); myTree.setShowsRootHandles(true); myTree.expandRow(0); myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); myTree.setCellRenderer(new NodeRenderer()); UIUtil.setLineStyleAngled(myTree); JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree); scrollPane.setPreferredSize(new Dimension(500, 300)); myTree.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (KeyEvent.VK_ENTER == e.getKeyCode()) { doOKAction(); } } }); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent event) { TreePath path = myTree.getPathForLocation(event.getX(), event.getY()); if (path != null && myTree.isPathSelected(path)) { doOKAction(); return true; } return false; } }.installOn(myTree); myTree.addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { handleSelectionChanged(); } }); new TreeSpeedSearch(myTree); myTabbedPane = new TabbedPaneWrapper(getDisposable()); final JPanel dummyPanel = new JPanel(new BorderLayout()); String name = null; /* if (myInitialClass != null) { name = myInitialClass.getName(); } */ myGotoByNamePanel = new ChooseByNamePanel( myProject, createChooseByNameModel(), name, myScope.isSearchInLibraries(), getContext()) { @Override protected void showTextFieldPanel() {} @Override protected void close(boolean isOk) { super.close(isOk); if (isOk) { doOKAction(); } else { doCancelAction(); } } @NotNull @Override protected Set<Object> filter(@NotNull Set<Object> elements) { return doFilter(elements); } @Override protected void initUI( ChooseByNamePopupComponent.Callback callback, ModalityState modalityState, boolean allowMultipleSelection) { super.initUI(callback, modalityState, allowMultipleSelection); dummyPanel.add(myGotoByNamePanel.getPanel(), BorderLayout.CENTER); IdeFocusTraversalPolicy.getPreferredFocusedComponent(myGotoByNamePanel.getPanel()) .requestFocus(); } @Override protected void showList() { super.showList(); if (myInitialClass != null && myList.getModel().getSize() > 0) { myList.setSelectedValue(myInitialClass, true); myInitialClass = null; } } @Override protected void chosenElementMightChange() { handleSelectionChanged(); } }; Disposer.register(myDisposable, myGotoByNamePanel); myTabbedPane.addTab(IdeBundle.message("tab.chooser.search.by.name"), dummyPanel); myTabbedPane.addTab(IdeBundle.message("tab.chooser.project"), scrollPane); myGotoByNamePanel.invoke(new MyCallback(), getModalityState(), false); myTabbedPane.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { handleSelectionChanged(); } }); return myTabbedPane.getComponent(); }
public MavenArchetypesStep(MavenModuleBuilder builder, @Nullable StepAdapter step) { myBuilder = builder; myStep = step; Disposer.register(this, myLoadingIcon); myArchetypesTree = new Tree(); myArchetypesTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); JScrollPane archetypesScrollPane = ScrollPaneFactory.createScrollPane(myArchetypesTree); myArchetypesPanel.add(archetypesScrollPane, "archetypes"); JPanel loadingPanel = new JPanel(new GridBagLayout()); JPanel bp = new JPanel(new BorderLayout(10, 10)); bp.add(new JLabel("Loading archetype list..."), BorderLayout.NORTH); bp.add(myLoadingIcon, BorderLayout.CENTER); loadingPanel.add(bp, new GridBagConstraints()); myArchetypesPanel.add(ScrollPaneFactory.createScrollPane(loadingPanel), "loading"); ((CardLayout) myArchetypesPanel.getLayout()).show(myArchetypesPanel, "archetypes"); myUseArchetypeCheckBox.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { updateComponents(); archetypeMayBeChanged(); } }); myAddArchetypeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doAddArchetype(); } }); myArchetypesTree.setRootVisible(false); myArchetypesTree.setShowsRootHandles(true); myArchetypesTree.setCellRenderer(new MyRenderer()); myArchetypesTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); myArchetypesTree .getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { updateArchetypeDescription(); archetypeMayBeChanged(); } }); new TreeSpeedSearch( myArchetypesTree, new Convertor<TreePath, String>() { public String convert(TreePath path) { MavenArchetype info = getArchetypeInfoFromPathComponent(path.getLastPathComponent()); return info.groupId + ":" + info.artifactId + ":" + info.version; } }) .setComparator(new SpeedSearchComparator(false)); myArchetypeDescriptionField.setEditable(false); myArchetypeDescriptionField.setBackground(UIUtil.getPanelBackground()); requestUpdate(); updateComponents(); }
@NotNull private JTree createTree() { DefaultMutableTreeNode root = new DefaultMutableTreeNode(); final Tree tree = new Tree(new DefaultTreeModel(root)) /* { @Override protected void paintComponent(Graphics g) { DuplicateNodeRenderer.paintDuplicateNodesBackground(g, this); super.paintComponent(g); } }*/; tree.setOpaque(false); tree.setToggleClickCount(-1); SliceUsageCellRenderer renderer = new SliceUsageCellRenderer(); renderer.setOpaque(false); tree.setCellRenderer(renderer); UIUtil.setLineStyleAngled(tree); tree.setRootVisible(false); tree.setShowsRootHandles(true); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setSelectionPath(new TreePath(root.getPath())); // ActionGroup group = // (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_METHOD_HIERARCHY_POPUP); // PopupHandler.installPopupHandler(tree, group, ActionPlaces.METHOD_HIERARCHY_VIEW_POPUP, // ActionManager.getInstance()); EditSourceOnDoubleClickHandler.install(tree); new TreeSpeedSearch(tree); TreeUtil.installActions(tree); ToolTipManager.sharedInstance().registerComponent(tree); myAutoScrollToSourceHandler.install(tree); tree.getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(final TreeSelectionEvent e) { treeSelectionChanged(); } }); tree.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (KeyEvent.VK_ENTER == e.getKeyCode()) { List<Navigatable> navigatables = getNavigatables(); if (navigatables.isEmpty()) return; for (Navigatable navigatable : navigatables) { if (navigatable instanceof AbstractTreeNode && ((AbstractTreeNode) navigatable).getValue() instanceof Usage) { navigatable = (Usage) ((AbstractTreeNode) navigatable).getValue(); } if (navigatable.canNavigateToSource()) { navigatable.navigate(false); if (navigatable instanceof Usage) { ((Usage) navigatable).highlightInEditor(); } } } e.consume(); } } }); tree.addTreeWillExpandListener( new TreeWillExpandListener() { @Override public void treeWillCollapse(TreeExpansionEvent event) {} @Override public void treeWillExpand(TreeExpansionEvent event) { TreePath path = event.getPath(); SliceNode node = fromPath(path); node.calculateDupNode(); } }); return tree; }
protected JComponent createCenterPanel() { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); myModel = new DefaultTreeModel(new DefaultMutableTreeNode()); createTreeModel(); myTree = new Tree(myModel); UIUtil.setLineStyleAngled(myTree); myTree.setCellRenderer( new DefaultTreeCellRenderer() { public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); setIcon(expanded ? Icons.PACKAGE_OPEN_ICON : Icons.PACKAGE_ICON); if (value instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object object = node.getUserObject(); if (object instanceof PsiPackage) { String name = ((PsiPackage) object).getName(); if (name != null && name.length() > 0) { setText(name); } else { setText(IdeBundle.message("node.default")); } } } return this; } }); myTree.setBorder(BorderFactory.createEtchedBorder()); JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree); scrollPane.setPreferredSize(new Dimension(500, 300)); new TreeSpeedSearch( myTree, new Convertor<TreePath, String>() { public String convert(TreePath path) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object object = node.getUserObject(); if (object instanceof PsiPackage) return ((PsiPackage) object).getName(); else return ""; } }); myTree .getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { PsiPackage selection = getTreeSelection(); if (selection != null) { String name = selection.getQualifiedName(); setTitle( myTitle + " - " + ("".equals(name) ? IdeBundle.message("node.default.package") : name)); } else { setTitle(myTitle); } } }); panel.add(scrollPane, BorderLayout.CENTER); DefaultActionGroup group = createActionGroup(myTree); ActionToolbar toolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true); panel.add(toolBar.getComponent(), BorderLayout.NORTH); toolBar.getComponent().setAlignmentX(JComponent.LEFT_ALIGNMENT); return panel; }
public ResourcePanel(AndroidFacet facet, ResourceType[] types, boolean system) { myTree = new Tree(); myTree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); myTree.setScrollsOnExpand(true); myTree.setRootVisible(false); myTree.setShowsRootHandles(true); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { if (!myTreeBuilder.getSelectedElements(ResourceItem.class).isEmpty()) { close(OK_EXIT_CODE); return true; } return false; } }.installOn(myTree); ToolTipManager.sharedInstance().registerComponent(myTree); TreeUtil.installActions(myTree); myManager = facet.getResourceManager(system ? AndroidUtils.SYSTEM_RESOURCE_PACKAGE : null); myGroups = new ResourceGroup[types.length]; for (int i = 0; i < types.length; i++) { myGroups[i] = new ResourceGroup(types[i], myManager); } myTreeBuilder = new AbstractTreeBuilder( myTree, (DefaultTreeModel) myTree.getModel(), new TreeContentProvider(myGroups), null); myTreeBuilder.initRootNode(); TreeSelectionModel selectionModel = myTree.getSelectionModel(); selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); selectionModel.addTreeSelectionListener(ChooseResourceDialog.this); myTree.setCellRenderer(new NodeRenderer()); new TreeSpeedSearch(myTree, TreeSpeedSearch.NODE_DESCRIPTOR_TOSTRING, true); myComponent = new JBSplitter(true, 0.8f); myComponent.setSplitterProportionKey("android.resource_dialog_splitter"); myComponent.setFirstComponent(ScrollPaneFactory.createScrollPane(myTree)); myPreviewPanel = new JPanel(new CardLayout()); myComponent.setSecondComponent(myPreviewPanel); myTextArea = new JTextArea(5, 20); myTextArea.setEditable(false); myPreviewPanel.add(ScrollPaneFactory.createScrollPane(myTextArea), TEXT); myComboTextArea = new JTextArea(5, 20); myComboTextArea.setEditable(false); myComboBox = new JComboBox(); myComboBox.setMaximumRowCount(15); myComboBox.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { java.util.List<ResourceElement> resources = (java.util.List<ResourceElement>) myComboBox.getClientProperty(COMBO); myComboTextArea.setText( getResourceElementValue(resources.get(myComboBox.getSelectedIndex()))); } }); JPanel comboPanel = new JPanel( new BorderLayout(0, 1) { @Override public void layoutContainer(Container target) { super.layoutContainer(target); Rectangle bounds = myComboBox.getBounds(); Dimension size = myComboBox.getPreferredSize(); size.width += 20; myComboBox.setBounds( (int) bounds.getMaxX() - size.width, bounds.y, size.width, size.height); } }); comboPanel.add(ScrollPaneFactory.createScrollPane(myComboTextArea), BorderLayout.CENTER); comboPanel.add(myComboBox, BorderLayout.SOUTH); myPreviewPanel.add(comboPanel, COMBO); myImageComponent = new JLabel(); myImageComponent.setHorizontalAlignment(SwingConstants.CENTER); myImageComponent.setVerticalAlignment(SwingConstants.CENTER); myPreviewPanel.add(myImageComponent, IMAGE); myNoPreviewComponent = new JLabel("No Preview"); myNoPreviewComponent.setHorizontalAlignment(SwingConstants.CENTER); myNoPreviewComponent.setVerticalAlignment(SwingConstants.CENTER); myPreviewPanel.add(myNoPreviewComponent, NONE); }
public GenerateByPatternDialog(Project project, PatternDescriptor[] descriptors) { super(project); myProject = project; setTitle("Generate by Pattern"); setOKButtonText("Generate"); myMap = new MultiMap<>(); for (PatternDescriptor descriptor : descriptors) { myMap.putValue(descriptor.getParentId(), descriptor); } DefaultMutableTreeNode root = createNode(null); myTree = new SimpleTree() {}; myTree.setRootVisible(false); myTree.setCellRenderer( new DefaultTreeCellRenderer() { @NotNull @Override public Component getTreeCellRendererComponent( @NotNull JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { Component component = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); Object object = ((DefaultMutableTreeNode) value).getUserObject(); if (object instanceof PatternDescriptor) { setText(((PatternDescriptor) object).getName()); setIcon(((PatternDescriptor) object).getIcon()); } return component; } }); myTree.setModel(new DefaultTreeModel(root)); myTree .getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(@NotNull TreeSelectionEvent e) { update(); } }); myEditor = TemplateEditorUtil.createEditor(true, ""); mySplitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myTree)); JPanel details = new JPanel(new BorderLayout()); details.add(myEditor.getComponent(), BorderLayout.CENTER); mySplitter.setSecondComponent(details); mySplitter.setHonorComponentsMinimumSize(true); mySplitter.setShowDividerControls(true); myTree.setSelectionRow(0); init(); }