|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.refactoring.ui; import java.awt.BorderLayout; import java.awt.event.MouseEvent; import javax.swing.JPanel; import org.openide.awt.MouseUtils; import org.openide.explorer.ExplorerPanel; import org.openide.util.HelpCtx; import org.openide.windows.Mode; import org.openide.windows.WindowManager; import org.openide.windows.Workspace; import java.awt.Component; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JTabbedPane; import org.openide.awt.JPopupMenuPlus; import org.openide.util.NbBundle; /** * * @author Jan Becicka */ public class RefactoringPanelContainer extends ExplorerPanel { private static RefactoringPanelContainer usages = null; private static RefactoringPanelContainer refactorings = null; private String name; private transient boolean isVisible = false; private JPopupMenuPlus pop; /** Popup menu listener */ private PopupListener listener; /** Creates new form RefactoringPanelContainer */ private RefactoringPanelContainer(String name) { putClientProperty("PersistenceType", "Never"); // NOI18N this.name = name; setLayout(new java.awt.BorderLayout()); pop = new JPopupMenuPlus(); pop.add(new Close()); pop.add(new CloseAll()); pop.add(new CloseAllButCurrent()); listener = new PopupListener(); } void addPanel(JPanel panel) { if (getComponentCount() == 0) { add(panel, BorderLayout.CENTER); } else { Component comp = getComponent(0); if (comp instanceof JTabbedPane) { ((JTabbedPane) comp).add(panel); ((JTabbedPane) comp).setSelectedComponent(panel); } else { remove(comp); JTabbedPane pane = new JTabbedPane(); pane.addMouseListener(listener); add(pane, BorderLayout.CENTER); pane.add(comp); pane.add(panel); pane.setSelectedComponent(panel); } } if (!isVisible) { isVisible = true; Workspace workspace = WindowManager.getDefault().getCurrentWorkspace(); Mode mode = workspace.findMode("output"); // NOI18N if (mode != null) { // output windows is opened mode.dockInto(this); // TODO: put view here } open(workspace); requestActive(); } } public boolean requestFocusInWindow() { boolean result = super.requestFocusInWindow(); if (getComponentCount()>0) { Component comp = getComponent(0); return comp.requestFocusInWindow(); } else { return result; } } void removePanel(JPanel panel) { Component comp = getComponent(0); if (comp instanceof JTabbedPane) { JTabbedPane tabs = (JTabbedPane) comp; if (panel == null) { panel = (JPanel) tabs.getSelectedComponent(); } tabs.remove(panel); if (tabs.getComponentCount() == 1) { Component c = tabs.getComponent(0); tabs.removeMouseListener(listener); remove(tabs); add(c, BorderLayout.CENTER); } } else { remove(comp); isVisible = false; close(); } } void closeAllButCurrent() { Component comp = getComponent(0); if (comp instanceof JTabbedPane) { JTabbedPane tabs = (JTabbedPane) comp; Component current = tabs.getSelectedComponent(); Component[] c = tabs.getComponents(); for (int i = 0; i< c.length; i++) { if (c[i]!=current) { ((RefactoringPanel) c[i]).close(); } } } } public static synchronized RefactoringPanelContainer getUsagesComponent() { if (usages == null) { usages = new RefactoringPanelContainer(org.openide.util.NbBundle.getMessage(RefactoringPanelContainer.class, "LBL_Usages")); } return usages; } public static synchronized RefactoringPanelContainer getRefactoringComponent() { if (refactorings == null) { refactorings = new RefactoringPanelContainer(org.openide.util.NbBundle.getMessage(RefactoringPanelContainer.class, "LBL_Refactoring")); } return refactorings; } public String getName() { return name; } protected void closeNotify() { isVisible = false; if (getComponentCount() == 0) { return ; } Component comp = getComponent(0); if (comp instanceof JTabbedPane) { JTabbedPane pane = (JTabbedPane) comp; Component[] c = pane.getComponents(); for (int i = 0; i< c.length; i++) { ((RefactoringPanel) c[i]).close(); } } else { ((RefactoringPanel) comp).close(); } } protected String preferredID() { return "RefactoringPanel"; // NOI18N } public int getPersistenceType() { return PERSISTENCE_NEVER; } /** * Class to showing popup menu */ private class PopupListener extends MouseUtils.PopupMouseAdapter { /** * Called when the sequence of mouse events should lead to actual showing popup menu */ protected void showPopup (MouseEvent e) { pop.show(RefactoringPanelContainer.this, e.getX(), e.getY()); } } // end of PopupListener private class Close extends AbstractAction { public Close() { super(NbBundle.getMessage(RefactoringPanelContainer.class, "LBL_CloseWindow")); } public void actionPerformed(ActionEvent e) { removePanel(null); } } private final class CloseAll extends AbstractAction { public CloseAll() { super(NbBundle.getMessage(RefactoringPanelContainer.class, "LBL_CloseAll")); } public void actionPerformed(ActionEvent e) { close(); } } private class CloseAllButCurrent extends AbstractAction { public CloseAllButCurrent() { super(NbBundle.getMessage(RefactoringPanelContainer.class, "LBL_CloseAllButCurrent")); } public void actionPerformed(ActionEvent e) { closeAllButCurrent(); } } public HelpCtx getHelpCtx() { return new HelpCtx(RefactoringPanelContainer.class); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.