Java Code Examples for org.openide.explorer.ExplorerManager#setRootContext()

The following examples show how to use org.openide.explorer.ExplorerManager#setRootContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResultPanelTree.java    From netbeans with Apache License 2.0 6 votes vote down vote up
ResultPanelTree(ResultDisplayHandler displayHandler, StatisticsPanel statPanel) {
        super(new BorderLayout());
        treeView = new ResultTreeView();
        treeView.getAccessibleContext().setAccessibleName(Bundle.ACSN_TestResults());
        treeView.getAccessibleContext().setAccessibleDescription(Bundle.ACSD_TestResults());
        treeView.setBorder(BorderFactory.createEtchedBorder());
//        resultBar.setPassedPercentage(0.0f);
        JToolBar toolBar = new JToolBar();
        toolBar.setFloatable(false);
        toolBar.add(resultBar);
        toolBar.setBorder(BorderFactory.createEtchedBorder());

        add(toolBar, BorderLayout.NORTH);
        add(treeView, BorderLayout.CENTER);

        explorerManager = new ExplorerManager();
        explorerManager.setRootContext(rootNode = new RootNode(displayHandler.getSession(), filterMask));
        explorerManager.addPropertyChangeListener(this);

        initAccessibility();

        this.displayHandler = displayHandler;
        this.statPanel = statPanel;
        displayHandler.setLookup(ExplorerUtils.createLookup(explorerManager, new ActionMap()));
    }
 
Example 2
Source File: BytecodeViewTopComponent.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private BytecodeViewTopComponent() {
    initComponents();
    setName(NbBundle.getMessage(BytecodeViewTopComponent.class, "CTL_BytecodeViewTopComponent"));
    setToolTipText(NbBundle.getMessage(BytecodeViewTopComponent.class, "HINT_BytecodeViewTopComponent"));

    manager = new ExplorerManager();
    rootNode = new MethodNode(null, null, "");
    manager.setRootContext(rootNode);

    setLayout(new BorderLayout());

    treeView = new BeanTreeView();
    treeView.setRootVisible(false);
    this.add(BorderLayout.CENTER, treeView);
    associateLookup(ExplorerUtils.createLookup(manager, getActionMap()));
}
 
Example 3
Source File: BrowseFolders.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates new form BrowseFolders */
public BrowseFolders( SourceGroup[] folders) {
    initComponents();
    this.folders = folders;
    manager = new ExplorerManager();        
    AbstractNode rootNode = new AbstractNode( new SourceGroupsChildren( folders ) );
    manager.setRootContext( rootNode );
    
    // Create the templates view
    BeanTreeView btv = new BeanTreeView();
    btv.setRootVisible( false );
    btv.setSelectionMode( javax.swing.tree.TreeSelectionModel.SINGLE_TREE_SELECTION );
    btv.setBorder( SAMPLE_SCROLL_PANE.getBorder() );
    btv.getAccessibleContext().setAccessibleDescription(
            NbBundle.getMessage(BrowseFolders.class, "ACSD_SelectFile"));
    folderPanel.add( btv, java.awt.BorderLayout.CENTER );
}
 
Example 4
Source File: BytecodeViewTopComponent.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private BytecodeViewTopComponent() {
    initComponents();
    setName(NbBundle.getMessage(BytecodeViewTopComponent.class, "CTL_BytecodeViewTopComponent"));
    setToolTipText(NbBundle.getMessage(BytecodeViewTopComponent.class, "HINT_BytecodeViewTopComponent"));

    manager = new ExplorerManager();
    rootNode = new MethodNode(null, null, "");
    manager.setRootContext(rootNode);

    setLayout(new BorderLayout());

    treeView = new BeanTreeView();
    treeView.setRootVisible(false);
    this.add(BorderLayout.CENTER, treeView);
    associateLookup(ExplorerUtils.createLookup(manager, getActionMap()));
}
 
Example 5
Source File: BrowseFolders.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates new form BrowseFolders */
public BrowseFolders( SourceGroup[] folders, Project project, String preselectedFileName ) {
    initComponents();
    this.folders = folders;
    this.project = project;
    
    manager = new ExplorerManager();        
    AbstractNode rootNode = new AbstractNode( new SourceGroupsChildren( folders, project ) );
    manager.setRootContext( rootNode );
    
    // Create the templates view
    btv = new BeanTreeView();
    btv.setRootVisible( false );
    btv.setSelectionMode( javax.swing.tree.TreeSelectionModel.SINGLE_TREE_SELECTION );
    btv.setBorder( SAMPLE_SCROLL_PANE.getBorder() );        
    btv.setPopupAllowed( false );
    btv.getAccessibleContext ().setAccessibleName (NbBundle.getMessage(BrowseFolders.class, "ACSN_BrowseFolders_folderPanel"));
    btv.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage(BrowseFolders.class, "ACSD_BrowseFolders_folderPanel"));
    expandSelection( preselectedFileName );
    //expandAllNodes( btv, manager.getRootContext() );
    folderPanel.add( btv, java.awt.BorderLayout.CENTER );      
    jLabel1.setLabelFor(btv.getViewport().getView());
}
 
Example 6
Source File: ResourceBundleBrandingPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ResourceBundleBrandingPanel(BrandingModel model) {
    super(getMessage("LBL_ResourceBundleTab"), model); //NOI18N
    
    initComponents();

    searchField.getDocument().addDocumentListener(searchListener);
    searchField.addFocusListener(searchListener);

    manager = new ExplorerManager();
    rootNode = null;
    waitRoot = getWaitRoot();
    waitRoot.setName(getMessage("LBL_ResourceBundlesList")); // NOI18N
    waitRoot.setDisplayName(getMessage("LBL_ResourceBundlesList")); // NOI18N
    manager.setRootContext(waitRoot);

    branding = getBranding();
    prj = branding.getProject();
}
 
Example 7
Source File: BrowseFolders.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates new form BrowseFolders */
public BrowseFolders( SourceGroup[] folders, Class target, String preselectedFileName  ) {
    initComponents();
    getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(BrowseFolders.class, (target == DataFolder.class?"ACSD_BrowseFolders":"ACSD_BrowseFiles")));

    this.folders = folders;
    this.target = target;
    manager = new ExplorerManager();        
    AbstractNode rootNode = new AbstractNode( new SourceGroupsChildren( folders ) );
    manager.setRootContext( rootNode );
    
    // Create the templates view
    btv = new BeanTreeView();
    btv.setRootVisible( false );
    btv.setSelectionMode( javax.swing.tree.TreeSelectionModel.SINGLE_TREE_SELECTION );
    btv.setBorder( SAMPLE_SCROLL_PANE.getBorder() );
    expandSelection( preselectedFileName );
    folderPanel.add( btv, java.awt.BorderLayout.CENTER );
}
 
Example 8
Source File: BrowseFolders.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates new form BrowseFolders */
public BrowseFolders( SourceGroup[] folders) {
    initComponents();
    this.folders = folders;
    manager = new ExplorerManager();        
    AbstractNode rootNode = new AbstractNode( new SourceGroupsChildren( folders ) );
    manager.setRootContext( rootNode );
    
    // Create the templates view
    BeanTreeView btv = new BeanTreeView();
    btv.setRootVisible( false );
    btv.setSelectionMode( javax.swing.tree.TreeSelectionModel.SINGLE_TREE_SELECTION );
    btv.setBorder( SAMPLE_SCROLL_PANE.getBorder() );
    folderPanel.add( btv, java.awt.BorderLayout.CENTER );
}
 
Example 9
Source File: FilterTopComponent.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private FilterTopComponent() {
    filterSettingsChangedEvent = new ChangedEvent<FilterTopComponent>(this);
    initComponents();
    setName(NbBundle.getMessage(FilterTopComponent.class, "CTL_FilterTopComponent"));
    setToolTipText(NbBundle.getMessage(FilterTopComponent.class, "HINT_FilterTopComponent"));
    //        setIcon(Utilities.loadImage(ICON_PATH, true));

    sequence = new FilterChain();
    filterChain = new FilterChain();
    initFilters();
    manager = new ExplorerManager();
    manager.setRootContext(new AbstractNode(new FilterChildren()));
    associateLookup(ExplorerUtils.createLookup(manager, getActionMap()));
    view = new CheckListView();

    ToolbarPool.getDefault().setPreferredIconSize(16);
    Toolbar toolBar = new Toolbar();
    Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N
    toolBar.setBorder(b);
    comboBox = new JComboBox();
    toolBar.add(comboBox);
    this.add(toolBar, BorderLayout.NORTH);
    toolBar.add(SaveFilterSettingsAction.get(SaveFilterSettingsAction.class));
    toolBar.add(RemoveFilterSettingsAction.get(RemoveFilterSettingsAction.class));
    toolBar.addSeparator();
    toolBar.add(MoveFilterUpAction.get(MoveFilterUpAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(MoveFilterDownAction.get(MoveFilterDownAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(RemoveFilterAction.get(RemoveFilterAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(NewFilterAction.get(NewFilterAction.class));
    this.add(view, BorderLayout.CENTER);

    filterSettings = new ArrayList<FilterSetting>();
    updateComboBox();

    comboBox.addActionListener(comboBoxActionListener);
    setChain(filterChain);
}
 
Example 10
Source File: TTVTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void setupTTV (Node rootNode, Node.Property[] props) {
    ttv.setProperties(props);
    ttv.setRootVisible(false);
    
    ExplorerManager em = new ExplorerManager();
    em.setRootContext(rootNode);
    ep = new TreeTableViewPanel (em);
    ep.add(ttv, BorderLayout.CENTER);
}
 
Example 11
Source File: FilterTopComponent.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private FilterTopComponent() {
    filterSettingsChangedEvent = new ChangedEvent<FilterTopComponent>(this);
    initComponents();
    setName(NbBundle.getMessage(FilterTopComponent.class, "CTL_FilterTopComponent"));
    setToolTipText(NbBundle.getMessage(FilterTopComponent.class, "HINT_FilterTopComponent"));
    //        setIcon(Utilities.loadImage(ICON_PATH, true));

    sequence = new FilterChain();
    filterChain = new FilterChain();
    initFilters();
    manager = new ExplorerManager();
    manager.setRootContext(new AbstractNode(new FilterChildren()));
    associateLookup(ExplorerUtils.createLookup(manager, getActionMap()));
    view = new CheckListView();

    ToolbarPool.getDefault().setPreferredIconSize(16);
    Toolbar toolBar = new Toolbar();
    Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N
    toolBar.setBorder(b);
    comboBox = new JComboBox();
    toolBar.add(comboBox);
    this.add(toolBar, BorderLayout.NORTH);
    toolBar.add(SaveFilterSettingsAction.get(SaveFilterSettingsAction.class));
    toolBar.add(RemoveFilterSettingsAction.get(RemoveFilterSettingsAction.class));
    toolBar.addSeparator();
    toolBar.add(MoveFilterUpAction.get(MoveFilterUpAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(MoveFilterDownAction.get(MoveFilterDownAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(RemoveFilterAction.get(RemoveFilterAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(NewFilterAction.get(NewFilterAction.class));
    this.add(view, BorderLayout.CENTER);

    filterSettings = new ArrayList<FilterSetting>();
    updateComboBox();

    comboBox.addActionListener(comboBoxActionListener);
    setChain(filterChain);
}
 
Example 12
Source File: CategoryView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public CategoryView( CategoryModel categoryModel ) {

        this.categoryModel = categoryModel;

        // See #36315
        manager = new ExplorerManager();

        setLayout( new BorderLayout() );

        Dimension size = new Dimension( 220, 4 );
        btv = new BeanTreeView();    // Add the BeanTreeView
        btv.setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION );
        btv.setPopupAllowed( false );
        btv.setRootVisible( false );
        btv.setDefaultActionAllowed( false );
        btv.setMinimumSize( size );
        btv.setPreferredSize( size );
        btv.setMaximumSize( size );
        btv.setDragSource (false);
        this.add( btv, BorderLayout.CENTER );
        manager.setRootContext( createRootNode( categoryModel ) );
        manager.addPropertyChangeListener( this );
        categoryModel.addPropertyChangeListener( this );
        btv.expandAll();
        selectNode( categoryModel.getCurrentCategory() );

        btv.getAccessibleContext().setAccessibleName(NbBundle.getMessage(CategoryView.class,"AN_CatgoryView"));
        btv.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CategoryView.class,"AD_CategoryView"));

    }
 
Example 13
Source File: FilterTopComponent.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private FilterTopComponent() {
    filterSettingsChangedEvent = new ChangedEvent<>(this);
    initComponents();
    setName(NbBundle.getMessage(FilterTopComponent.class, "CTL_FilterTopComponent"));
    setToolTipText(NbBundle.getMessage(FilterTopComponent.class, "HINT_FilterTopComponent"));
    //        setIcon(Utilities.loadImage(ICON_PATH, true));

    sequence = new FilterChain();
    filterChain = new FilterChain();
    initFilters();
    manager = new ExplorerManager();
    manager.setRootContext(new AbstractNode(new FilterChildren()));
    associateLookup(ExplorerUtils.createLookup(manager, getActionMap()));
    view = new CheckListView();

    ToolbarPool.getDefault().setPreferredIconSize(16);
    Toolbar toolBar = new Toolbar();
    Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N
    toolBar.setBorder(b);
    comboBox = new JComboBox();
    toolBar.add(comboBox);
    this.add(toolBar, BorderLayout.NORTH);
    toolBar.add(SaveFilterSettingsAction.get(SaveFilterSettingsAction.class));
    toolBar.add(RemoveFilterSettingsAction.get(RemoveFilterSettingsAction.class));
    toolBar.addSeparator();
    toolBar.add(NewFilterAction.get(NewFilterAction.class));
    toolBar.add(RemoveFilterAction.get(RemoveFilterAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(MoveFilterUpAction.get(MoveFilterUpAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(MoveFilterDownAction.get(MoveFilterDownAction.class).createContextAwareInstance(this.getLookup()));
    this.add(view, BorderLayout.CENTER);

    filterSettings = new ArrayList<>();
    updateComboBox();

    comboBox.addActionListener(comboBoxActionListener);
    setChain(filterChain);
}
 
Example 14
Source File: MoveMembersPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new form MoveMembersPanel
 */
public MoveMembersPanel(TreePathHandle[] selectedElements, final ChangeListener parent) {
    manager = new ExplorerManager();
    this.parent = parent;
    this.naturalSort = NbPreferences.forModule(MoveMembersPanel.class).getBoolean("naturalSort", false); //NOI18N
    this.selectedElements = selectedElements;
    this.fileObject = selectedElements[0].getFileObject();
    initComponents();

    rootComboBox.setRenderer(GROUP_CELL_RENDERER);
    packageComboBox.setRenderer(PackageView.listRenderer());
    projectsComboBox.setRenderer(PROJECT_CELL_RENDERER);
    classComboBox.setRenderer(CLASS_CELL_RENDERER);
    Project fileOwner = this.fileObject != null ? FileOwnerQuery.getOwner(this.fileObject) : null;
    project = fileOwner != null ? fileOwner : OpenProjects.getDefault().getOpenProjects()[0];

    manager.setRootContext(ElementNode.getWaitNode());
    outlineView1.getOutline().setRootVisible(true);
    outlineView1.getOutline().setTableHeader(null);
    initFiltersPanel();
    actions = new Action[]{
        new SortByNameAction(this),
        new SortBySourceAction(this)
    };
    ItemListener parentListener = new ItemListener() {
                                    @Override
                                    public void itemStateChanged(ItemEvent e) {
                                        parent.stateChanged(null);
                                    }
                                };
    btnAsIs.addItemListener(parentListener);
    btnDefault.addItemListener(parentListener);
    btnEscalate.addItemListener(parentListener);
    btnJavadocAsIs.addItemListener(parentListener);
    btnJavadocUpdate.addItemListener(parentListener);
    btnPrivate.addItemListener(parentListener);
    btnProtected.addItemListener(parentListener);
    btnPublic.addItemListener(parentListener);
}
 
Example 15
Source File: NewPluginPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates new form FindResultsPanel */
private QueryPanel(NewPluginPanel plugPanel) {
    this.pluginPanel = plugPanel;
    btv = new BeanTreeView();
    btv.setRootVisible(false);
    btv.setDefaultActionAllowed(false);
    manager = new ExplorerManager();
    manager.setRootContext(getNoResultsRoot());
    setLayout(new BorderLayout());
    add(btv, BorderLayout.CENTER);
    manager.addPropertyChangeListener(this);
    pluginPanel.lblPlugins.setLabelFor(btv);
}
 
Example 16
Source File: OutlineTopComponent.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void initListView() {
    manager = new ExplorerManager();
    root = new FolderNode(document);
    manager.setRootContext(root);
    ((BeanTreeView) this.treeView).setRootVisible(false);

    associateLookup(ExplorerUtils.createLookup(manager, getActionMap()));
}
 
Example 17
Source File: FilterTopComponent.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private FilterTopComponent() {
    filterSettingsChangedEvent = new ChangedEvent<FilterTopComponent>(this);
    initComponents();
    setName(NbBundle.getMessage(FilterTopComponent.class, "CTL_FilterTopComponent"));
    setToolTipText(NbBundle.getMessage(FilterTopComponent.class, "HINT_FilterTopComponent"));
    //        setIcon(Utilities.loadImage(ICON_PATH, true));

    sequence = new FilterChain();
    filterChain = new FilterChain();
    initFilters();
    manager = new ExplorerManager();
    manager.setRootContext(new AbstractNode(new FilterChildren()));
    associateLookup(ExplorerUtils.createLookup(manager, getActionMap()));
    view = new CheckListView();

    ToolbarPool.getDefault().setPreferredIconSize(16);
    Toolbar toolBar = new Toolbar();
    Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N
    toolBar.setBorder(b);
    comboBox = new JComboBox();
    toolBar.add(comboBox);
    this.add(toolBar, BorderLayout.NORTH);
    toolBar.add(SaveFilterSettingsAction.get(SaveFilterSettingsAction.class));
    toolBar.add(RemoveFilterSettingsAction.get(RemoveFilterSettingsAction.class));
    toolBar.addSeparator();
    toolBar.add(MoveFilterUpAction.get(MoveFilterUpAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(MoveFilterDownAction.get(MoveFilterDownAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(RemoveFilterAction.get(RemoveFilterAction.class).createContextAwareInstance(this.getLookup()));
    toolBar.add(NewFilterAction.get(NewFilterAction.class));
    this.add(view, BorderLayout.CENTER);

    filterSettings = new ArrayList<FilterSetting>();
    updateComboBox();

    comboBox.addActionListener(comboBoxActionListener);
    setChain(filterChain);
}
 
Example 18
Source File: StatefulView.java    From Llunatic with GNU General Public License v3.0 4 votes vote down vote up
public void setRootNode(ExplorerManager em, Node newRoot, List<String[]> expandedPaths) {
    this.root = newRoot;
    em.setRootContext(newRoot);
    expandNodes(expandedPaths);
}
 
Example 19
Source File: ClassPathFileChooser.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new ClassPathFileChooser. Can be used directly as a panel,
 * or getDialog can be called to get it wrapped in a Dialog.
 * @param fileInProject a source file from project sources (determines the
 *        project's classpath)
 * @param filter a filter for files to be displayed
 * @param choosingFolder if true, the chooser only allows to select a folder,
 *        and only source classpath is shown (i.e. not JARs on execution CP)
 * @param okCancelButtons defines whether the controls buttons should be shown
 *        (typically true if using as a dialog and false if using as a panel)
 */
public ClassPathFileChooser(FileObject fileInProject, Filter filter, boolean choosingFolder, boolean okCancelButtons) {
    this.choosingFolder = choosingFolder;

    Listener listener = new Listener();

    Node root = getRootNode(fileInProject, filter);
    explorerManager = new ExplorerManager();
    explorerManager.setRootContext(root);
    try {
        explorerManager.setSelectedNodes (new Node[] { root });
    }
    catch(PropertyVetoException ex) {
        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
    }
    explorerManager.addPropertyChangeListener(listener);

    if (choosingFolder) { // add a button allowing to create a new folder
        newButton = new JButton();
        Mnemonics.setLocalizedText(newButton, NbBundle.getMessage(ClassPathFileChooser.class, "CTL_CreateNewButton")); // NOI18N
        newButton.addActionListener(listener);
        newButton.setEnabled(false);
        newButton.setToolTipText(NbBundle.getMessage(ClassPathFileChooser.class, "CTL_CreateNewButtonHint")); // NOI18N
    }
    if (okCancelButtons) {
        okButton = new JButton(NbBundle.getMessage(ClassPathFileChooser.class, "CTL_OKButton")); // NOI18N
        okButton.addActionListener(listener);
        okButton.setEnabled(false);
        cancelButton = new JButton(NbBundle.getMessage(ClassPathFileChooser.class, "CTL_CancelButton")); // NOI18N
    }

    treeView = new BeanTreeView();
    treeView.setPopupAllowed(false);
    treeView.setDefaultActionAllowed(true);
    treeView.setBorder((Border)UIManager.get("Nb.ScrollPane.border")); // NOI18N
    treeView.getAccessibleContext().setAccessibleName(NbBundle.getMessage(ClassPathFileChooser.class, "ACSN_FileSelectorTreeView")); // NOI18N
    treeView.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ClassPathFileChooser.class, "ACSD_FileSelectorTreeView")); // NOI18N
    this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ClassPathFileChooser.class, "ACSD_FileSelectorPanel")); // NOI18N

    // label and text field with mnemonic
    JLabel label = new JLabel();
    Mnemonics.setLocalizedText(label, NbBundle.getMessage(ClassPathFileChooser.class,
            choosingFolder ? "LBL_FolderName": "LBL_FileName")); // NOI18N
    fileNameTextField = new JTextField();
    fileNameTextField.getDocument().addDocumentListener(listener);
    fileNameTextField.addActionListener(listener);
    label.setLabelFor(fileNameTextField);

    GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    layout.setAutoCreateGaps(true);

    GroupLayout.SequentialGroup sq = layout.createSequentialGroup()
                                        .addComponent(label).addComponent(fileNameTextField);
    if (!okCancelButtons && newButton != null) // add newButton next to the text field
        sq.addComponent(newButton);
    layout.setHorizontalGroup(layout.createParallelGroup()
        .addComponent(treeView, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addGroup(sq));

    GroupLayout.ParallelGroup pq = layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(label).addComponent(fileNameTextField);
    if (!okCancelButtons && newButton != null) // add newButton next to the text field
        pq.addComponent(newButton);
    layout.setVerticalGroup(layout.createSequentialGroup()
        .addComponent(treeView, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addGroup(pq));
}
 
Example 20
Source File: BreadCrumbComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void expand(int startX, final Node what) {
    if (what.getChildren().getNodesCount() == 0) return ;
    
    final ExplorerManager expandManager = new ExplorerManager();
    class Expanded extends JPanel implements ExplorerManager.Provider {
        public Expanded(LayoutManager layout) {
            super(layout);
        }
        @Override public ExplorerManager getExplorerManager() {
            return expandManager;
        }
    }
    final JPanel expanded = new Expanded(new BorderLayout());
    expanded.setBorder(new LineBorder(Color.BLACK, 1));
    
    final ListView listView = new ListView() {
        {
            int nodesCount = what.getChildren().getNodesCount();
            
            if (nodesCount >= MAX_ROWS_IN_POP_UP) {
                list.setVisibleRowCount(MAX_ROWS_IN_POP_UP);
            } else {
                list.setVisibleRowCount(nodesCount);
                
                NodeRenderer nr = new NodeRenderer();
                int i = 0;
                int width = getPreferredSize().width;
                
                for (Node n : what.getChildren().getNodes()) {
                    if (nr.getListCellRendererComponent(list, n, i, false, false).getPreferredSize().width > width) {
                        Dimension pref = getPreferredSize();
                        pref.height += getHorizontalScrollBar().getPreferredSize().height;
                        setPreferredSize(pref);
                        break;
                    }
                }
            }
        }
    };
    listView.setPopupAllowed(false);
    expanded.add(listView, BorderLayout.CENTER);
    expandManager.setRootContext(what);
    
    Point place = new Point(startX, 0);
    
    SwingUtilities.convertPointToScreen(place, this);
    
    expanded.validate();
    
    final Popup popup = PopupFactory.getSharedInstance().getPopup(this, expanded, place.x, place.y - expanded.getPreferredSize().height);
    final AWTEventListener multicastListener = new AWTEventListener() {
        @Override public void eventDispatched(AWTEvent event) {
                if (event instanceof MouseEvent && ((MouseEvent) event).getClickCount() > 0) {
                    Object source = event.getSource();
                    
                    while (source instanceof Component) {
                        if (source == expanded) return ; //accept
                        source = ((Component) source).getParent();
                    }
                    
                    popup.hide();
                    Toolkit.getDefaultToolkit().removeAWTEventListener(this);
                }
        }
    };
    
    Toolkit.getDefaultToolkit().addAWTEventListener(multicastListener, AWTEvent.MOUSE_EVENT_MASK);
    
    expandManager.addPropertyChangeListener(new PropertyChangeListener() {
        @Override public void propertyChange(PropertyChangeEvent evt) {
            if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
                Node[] selected = expandManager.getSelectedNodes();
                if (selected.length == 1) {
                    open(selected[0]);
                    popup.hide();
                    Toolkit.getDefaultToolkit().removeAWTEventListener(multicastListener);
                }
            }
        }
    });
    
    popup.show();
}