📄 tabbedpanel.java
字号:
/*====================================================================*\TabbedPanel.javaTabbed panel class.------------------------------------------------------------------------This file is part of FuncPlotter, a combined Java application and appletfor plotting explicit functions in one variable.Copyright 2005-2007 Andy Morgan-Richards.FuncPlotter is free software: you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation, either version 3 of the License, or (at youroption) any later version.This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith this program. If not, see <http://www.gnu.org/licenses/>.\*====================================================================*/// PACKAGEpackage gui;//----------------------------------------------------------------------// IMPORTSimport java.awt.AWTEvent;import java.awt.AWTKeyStroke;import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.KeyboardFocusManager;import java.awt.Point;import java.awt.Rectangle;import java.awt.Window;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.AWTEventListener;import java.awt.event.ComponentEvent;import java.awt.event.ComponentListener;import java.awt.event.KeyEvent;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.awt.event.WindowEvent;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.List;import javax.swing.Action;import javax.swing.ImageIcon;import javax.swing.JComponent;import javax.swing.JWindow;import javax.swing.KeyStroke;import javax.swing.SwingUtilities;import javax.swing.Timer;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import util.KeyAction;import util.TextUtilities;//----------------------------------------------------------------------// TABBED PANEL CLASSpublic class TabbedPanel extends JComponent implements ActionListener, ComponentListener, PropertyChangeListener{////////////////////////////////////////////////////////////////////////// Constants//////////////////////////////////////////////////////////////////////// private static final int SCROLL_INTERVAL = 400; private static final int BORDER_TOP = 1; private static final int BORDER_BOTTOM = 1; private static final int BORDER_LEFT = 1; private static final int BORDER_RIGHT = 1; private static final int HEADER_TOP_MARGIN = 1; private static final int HEADER_BUTTON_TOP_MARGIN = 2; private static final int HEADER_BUTTON_BOTTOM_MARGIN = 2; private static final int SCROLL_BUTTON_LEADING_MARGIN = 4; private static final int SCROLL_BUTTON_TRAILING_MARGIN = 2; private static final int LIST_BUTTON_TRAILING_MARGIN = 2; private static final int ARROW_SIZE = 5; private static final int SCROLL_BUTTON_WIDTH = 15; private static final int LIST_BUTTON_WIDTH = 17; private static final int HEADER_BUTTON_HEIGHT = 15; private static final int MIN_HEADER_WIDTH = SCROLL_BUTTON_LEADING_MARGIN + 2 * SCROLL_BUTTON_WIDTH + SCROLL_BUTTON_TRAILING_MARGIN + LIST_BUTTON_WIDTH + LIST_BUTTON_TRAILING_MARGIN; private static final Color HEADER_BACKGROUND_COLOUR = new Color( 120, 136, 136 ); private static final Color HEADER_BORDER_BOTTOM_COLOUR = new Color( 240, 240, 232 ); private static final Color DARK_SHADOW_COLOUR = new Color( 64, 64, 64 ); private static final Color LIGHT_SHADOW_COLOUR = new Color( 128, 128, 128 ); private static final Color DARK_HIGHLIGHT_COLOUR = new Color( 212, 212, 212 ); private static final Color LIGHT_HIGHLIGHT_COLOUR = new Color( 255, 255, 255 ); private static final Color BACKGROUND_COLOUR = new Color( 180, 180, 176 ); private static final Color SELECTED_BACKGROUND_COLOUR = new Color( 184, 208, 216 ); private static final Color TEXT_COLOUR = Color.BLACK; private static final Color BUTTON_SHADOW_COLOUR = new Color( 92, 92, 92 ); private static final Color BUTTON_HIGHLIGHT_COLOUR = new Color( 255, 255, 255 ); private static final Color BUTTON_BACKGROUND_COLOUR = new Color( 212, 208, 200 ); private enum ButtonState { NOT_OVER, OVER, PRESSED } private enum ScrollDirection { BACKWARD, FORWARD } private static final byte[] CROSS_ICON_DATA = { (byte)0x89, (byte)0x50, (byte)0x4E, (byte)0x47, (byte)0x0D, (byte)0x0A, (byte)0x1A, (byte)0x0A, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0D, (byte)0x49, (byte)0x48, (byte)0x44, (byte)0x52, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x08, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x07, (byte)0x08, (byte)0x06, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x35, (byte)0x59, (byte)0x0C, (byte)0x5E, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x2B, (byte)0x49, (byte)0x44, (byte)0x41, (byte)0x54, (byte)0x78, (byte)0xDA, (byte)0x63, (byte)0x60, (byte)0x60, (byte)0x60, (byte)0xF8, (byte)0x0F, (byte)0xC6, (byte)0x45, (byte)0xF9, (byte)0x0C, (byte)0x28, (byte)0x18, (byte)0x26, (byte)0x8E, (byte)0xC2, (byte)0x41, (byte)0x97, (byte)0x04, (byte)0xB3, (byte)0x31, (byte)0x74, (byte)0xA0, (byte)0x2B, (byte)0xC6, (byte)0x66, (byte)0x2C, (byte)0x8A, (byte)0x18, (byte)0x51, (byte)0x26, (byte)0xE0, (byte)0x75, (byte)0x03, (byte)0x01, (byte)0x5F, (byte)0x00, (byte)0x00, (byte)0x70, (byte)0x42, (byte)0x34, (byte)0x45, (byte)0xE9, (byte)0x0D, (byte)0x37, (byte)0xBE, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x49, (byte)0x45, (byte)0x4E, (byte)0x44, (byte)0xAE, (byte)0x42, (byte)0x60, (byte)0x82 }; private static final ImageIcon CROSS_ICON = new ImageIcon( CROSS_ICON_DATA ); private interface Command { String SCROLL = "scroll"; String SELECT_PREVIOUS_TAB = "selectPreviousTab"; String SELECT_NEXT_TAB = "selectNextTab"; } private static final KeyAction.CommandMap[] KEY_COMMANDS = { new KeyAction.CommandMap( KeyStroke.getKeyStroke( KeyEvent.VK_TAB, KeyEvent.CTRL_DOWN_MASK ), Command.SELECT_NEXT_TAB ), new KeyAction.CommandMap( KeyStroke.getKeyStroke( KeyEvent.VK_TAB, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK ), Command.SELECT_PREVIOUS_TAB ) };////////////////////////////////////////////////////////////////////////// Member classes : non-inner classes//////////////////////////////////////////////////////////////////////// // ELEMENT CLASS private static class Element { //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private Element( Tab tab, Component component ) { this.tab = tab; this.component = component; } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : overriding methods //////////////////////////////////////////////////////////////////// public String toString( ) { return tab.getTitle( ); } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance variables //////////////////////////////////////////////////////////////////// private Tab tab; private Component component; private Component focusOwner; } //==================================================================////////////////////////////////////////////////////////////////////////// Member classes : inner classes//////////////////////////////////////////////////////////////////////// // SCROLL BUTTON CLASS private class ScrollButton extends ArrowButton implements MouseListener { //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private ScrollButton( ArrowButton.Direction direction ) { super( SCROLL_BUTTON_WIDTH, HEADER_BUTTON_HEIGHT, ARROW_SIZE, direction ); addMouseListener( this ); } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : MouseListener interface //////////////////////////////////////////////////////////////////// public void mouseClicked( MouseEvent event ) { // do nothing } //-------------------------------------------------------------- public void mouseEntered( MouseEvent event ) { // do nothing } //-------------------------------------------------------------- public void mouseExited( MouseEvent event ) { // do nothing } //-------------------------------------------------------------- public void mousePressed( MouseEvent event ) { if ( isEnabled( ) ) { setPressed( true ); repaint( ); switch ( getDirection( ) ) { case LEFT: startScrollingLeft( ); break; case RIGHT: startScrollingRight( ); break; } } } //-------------------------------------------------------------- public void mouseReleased( MouseEvent event ) { setPressed( false ); if ( isEnabled( ) ) { switch ( getDirection( ) ) { case LEFT: case RIGHT: stopScrolling( ); break; } } } //-------------------------------------------------------------- } //================================================================== // LIST BUTTON CLASS private class ListButton extends ArrowButton implements MouseListener, MouseMotionListener { //////////////////////////////////////////////////////////////////// // Constants //////////////////////////////////////////////////////////////////// private static final int CLICK_INTERVAL = 500; //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private ListButton( ) { super( LIST_BUTTON_WIDTH, HEADER_BUTTON_HEIGHT, ARROW_SIZE, ArrowButton.Direction.DOWN ); addMouseListener( this ); addMouseMotionListener( this ); } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : MouseListener interface //////////////////////////////////////////////////////////////////// public void mouseClicked( MouseEvent event ) { // do nothing } //-------------------------------------------------------------- public void mouseEntered( MouseEvent event ) { // do nothing } //-------------------------------------------------------------- public void mouseExited( MouseEvent event ) { // do nothing } //-------------------------------------------------------------- public void mousePressed( MouseEvent event ) { if ( mouseSelectionListWindow == null ) { pressTime = event.getWhen( ); createMouseSelectionList( ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -