/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/gui/PanelWindowContainer.java
Java | 954 lines | 713 code | 114 blank | 127 comment | 113 complexity | f6f7dba1c1c96b57d1af980b8a940396 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- /*
- * PanelWindowContainer.java - holds dockable windows
- * :tabSize=8:indentSize=8:noTabs=false:
- * :folding=explicit:collapseFolds=1:
- *
- * Copyright (C) 2000, 2004 Slava Pestov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- package org.gjt.sp.jedit.gui;
- //{{{ Imports
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import java.awt.RenderingHints;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.font.FontRenderContext;
- import java.awt.font.GlyphVector;
- import java.awt.font.LineMetrics;
- import java.awt.geom.AffineTransform;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.List;
- import javax.swing.AbstractButton;
- import javax.swing.ButtonGroup;
- import javax.swing.Icon;
- import javax.swing.JButton;
- import javax.swing.JComponent;
- import javax.swing.JPanel;
- import javax.swing.JPopupMenu;
- import javax.swing.JToggleButton;
- import javax.swing.UIManager;
- import javax.swing.border.Border;
- import javax.swing.border.EmptyBorder;
- import javax.swing.plaf.metal.MetalLookAndFeel;
- import org.gjt.sp.jedit.EditBus;
- import org.gjt.sp.jedit.GUIUtilities;
- import org.gjt.sp.jedit.OperatingSystem;
- import org.gjt.sp.jedit.jEdit;
- import org.gjt.sp.jedit.gui.DockableWindowManager.DockingArea;
- import org.gjt.sp.jedit.msg.DockableWindowUpdate;
- import org.gjt.sp.util.StandardUtilities;
- //}}}
- /**
- * A container for dockable windows. This class should never be used
- * directly.
- * @author Slava Pestov
- * @version $Id: PanelWindowContainer.java 20108 2011-10-18 12:16:38Z evanpw $
- * @since jEdit 4.0pre1
- */
- public class PanelWindowContainer implements DockableWindowContainer, DockingArea
- {
- //{{{ PanelWindowContainer constructor
- public PanelWindowContainer(DockableWindowManagerImpl wm, String position,
- int dimension)
- {
- this.wm = wm;
- this.position = position;
- //{{{ Button box setup
- buttonPanel = new JPanel(new ButtonLayout());
- buttonPanel.setBorder(new EmptyBorder(1,1,1,1));
- closeBox = new JButton(GUIUtilities.loadIcon("closebox.gif"));
- closeBox.setRequestFocusEnabled(false);
- closeBox.setToolTipText(jEdit.getProperty("view.docking.close-tooltip"));
- if(OperatingSystem.isMacOSLF())
- closeBox.putClientProperty("JButton.buttonType","toolbar");
- closeBox.setMargin(new Insets(0,0,0,0));
- closeBox.addActionListener(new ActionHandler());
- menuBtn = new JButton(GUIUtilities.loadIcon(jEdit.getProperty("dropdown-arrow.icon")));
- menuBtn.setRequestFocusEnabled(false);
- menuBtn.setToolTipText(jEdit.getProperty("view.docking.menu-tooltip"));
- if(OperatingSystem.isMacOSLF())
- menuBtn.putClientProperty("JButton.buttonType","toolbar");
- menuBtn.setMargin(new Insets(0,0,0,0));
- menuBtn.addMouseListener(new MenuMouseHandler());
- buttonGroup = new ButtonGroup();
- // JDK 1.4 workaround
- buttonGroup.add(nullButton = new JToggleButton());
- //}}}
- dockables = new ArrayList<DockableWindowManagerImpl.Entry>();
- buttons = new ArrayList<AbstractButton>();
- dockablePanel = new DockablePanel(this);
- this.dimension = dimension;
- } //}}}
- //{{{ getDockableWindowManager() method
- /**
- * @since jEdit 4.3pre2
- */
- public DockableWindowManagerImpl getDockableWindowManager()
- {
- return wm;
- } //}}}
-
- //{{{ register() method
- public void register(DockableWindowManagerImpl.Entry entry)
- {
- dockables.add(entry);
- //{{{ Create button
- int rotation;
- if(position.equals(DockableWindowManagerImpl.TOP)
- || position.equals(DockableWindowManagerImpl.BOTTOM))
- rotation = RotatedTextIcon.NONE;
- else if(position.equals(DockableWindowManagerImpl.LEFT))
- rotation = RotatedTextIcon.CCW;
- else if(position.equals(DockableWindowManagerImpl.RIGHT))
- rotation = RotatedTextIcon.CW;
- else
- throw new InternalError("Invalid position: " + position);
- JToggleButton button = new JToggleButton();
- button.setMargin(new Insets(1,1,1,1));
- button.setRequestFocusEnabled(false);
- button.setIcon(new RotatedTextIcon(rotation,button.getFont(),
- entry.shortTitle()));
- button.setActionCommand(entry.factory.name);
- button.addActionListener(new ActionHandler());
- button.addMouseListener(new MenuMouseHandler());
- if(OperatingSystem.isMacOSLF())
- button.putClientProperty("JButton.buttonType","toolbar");
- //}}}
- buttonGroup.add(button);
- buttons.add(button);
- entry.btn = button;
- wm.revalidate();
- } //}}}
- //{{{ unregister() method
- public void unregister(DockableWindowManagerImpl.Entry entry)
- {
- if(entry.factory.name.equals(mostRecent))
- mostRecent = null;
- if(entry.btn != null)
- {
- buttonPanel.remove(entry.btn);
- buttons.remove(entry.btn);
- entry.btn = null;
- }
- dockables.remove(entry);
- if(entry.win != null)
- dockablePanel.remove(entry.win);
- if(current == entry)
- {
- current = null;
- show(current);
- }
- else
- {
- wm.revalidate();
- dockablePanel.repaint();
- buttonPanel.repaint();
- }
- } //}}}
- //{{{ remove() method
- public void remove(DockableWindowManagerImpl.Entry entry)
- {
- if(entry.factory.name.equals(mostRecent))
- mostRecent = null;
- if(entry.win != null)
- {
- dockablePanel.remove(entry.win);
- entry.win = null;
- }
- if(current == entry)
- {
- current = null;
- show(current);
- }
- else
- {
- wm.revalidate();
- dockablePanel.repaint();
- }
- } //}}}
- //{{{ showMostRecent() method
- public void showMostRecent()
- {
- if(dockables.isEmpty())
- {
- Toolkit.getDefaultToolkit().beep();
- return;
- }
- if(mostRecent == null)
- {
- mostRecent = dockables.get(0).factory.name;
- }
- wm.showDockableWindow(mostRecent);
- } //}}}
- //{{{ show() method
- public void show(DockableWindowManagerImpl.Entry entry)
- {
- if(current == entry)
- {
- if(entry != null)
- {
- if(entry.win instanceof DefaultFocusComponent)
-