⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabbedpanel.java

📁 FuncPlotter is a combined Java application and applet for displaying two-dimensional plots of explic
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        private int getPreferredWidth( )        {            return preferredWidth;        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance variables    ////////////////////////////////////////////////////////////////////        private String      title;        private Action      closeAction;        private int         preferredWidth;        private int         height;        private boolean     selected;        private boolean     closeButtonPressed;        private ButtonState closeButtonState;    }    //==================================================================    // KEY-SELECTION LIST WINDOW CLASS    private class KeySelectionListWindow        extends JWindow    {    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        private KeySelectionListWindow( Window  owner,                                        boolean decrement )        {            // Call base-class constructor            super( owner );            // Make window non-focusable            setFocusableWindowState( false );            // Create list            list = new SelectionList<Element>( recentElements, -1 );            list.setSelectedIndex( decrement ? recentElements.size( ) - 1 : 1 );            // Set list as content pane            setContentPane( list );            // Apply orientation to components            applyComponentOrientation( owner.getComponentOrientation( ) );            // Resize window to its preferred size            pack( );            // Set location of window            setLocation( GuiUtilities.getComponentLocation( list, owner ) );            // Show window            setVisible( true );        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods    ////////////////////////////////////////////////////////////////////        private void decrementSelection( )        {            int numItems = list.getNumItems( );            int index = list.getSelectedIndex( );            if ( index < 0 )                index = 0;            index = (index == 0) ? numItems - 1 : index - 1;            list.setSelectedIndex( index );        }        //--------------------------------------------------------------        private void incrementSelection( )        {            int numItems = list.getNumItems( );            int index = list.getSelectedIndex( );            if ( index < 0 )                index = 0;            index = (index == numItems - 1) ? 0 : index + 1;            list.setSelectedIndex( index );        }        //--------------------------------------------------------------        private void doSelection( )        {            destroyKeySelectionList( );            selectTab( list.getSelectedItem( ) );        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance variables    ////////////////////////////////////////////////////////////////////        private SelectionList<Element>  list;    }    //==================================================================    // MOUSE-SELECTION LIST WINDOW CLASS    private class MouseSelectionListWindow        extends JWindow        implements AWTEventListener, MouseListener, MouseMotionListener    {    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        private MouseSelectionListWindow( Window owner )        {            // Call base-class constructor            super( owner );            // Make window non-focusable            setFocusableWindowState( false );            // Create list            List<Element> orderedElements = new ArrayList<Element>( elements );            Collections.sort( orderedElements, elementComparator );            list = new SelectionList<Element>( orderedElements,                                               (selectedIndex < 0) ? null : elements.get( selectedIndex ) );            // Add listeners            getToolkit( ).addAWTEventListener( this, AWTEvent.MOUSE_EVENT_MASK );            list.addMouseListener( this );            list.addMouseMotionListener( this );            // Set list as content pane            setContentPane( list );            // Apply orientation to components            applyComponentOrientation( owner.getComponentOrientation( ) );            // Resize window to its preferred size            pack( );            // Set location of window            int x = getComponentOrientation( ).isLeftToRight( )                                                ? listButton.getWidth( ) - list.getPreferredSize( ).width                                                : 0;            Point location = new Point( x, listButton.getHeight( ) );            SwingUtilities.convertPointToScreen( location, listButton );            setLocation( GuiUtilities.getComponentLocation( list, location ) );            // Show window            setVisible( true );        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods : AWTEventListener interface    ////////////////////////////////////////////////////////////////////        public void eventDispatched( AWTEvent event )        {            if ( event.getID( ) == MouseEvent.MOUSE_PRESSED )            {                MouseEvent mouseEvent = (MouseEvent)event;                if ( mouseEvent.getComponent( ) != list )                    destroyMouseSelectionList( );                if ( mouseEvent.getComponent( ) == listButton )                    mouseEvent.consume( );            }        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods : MouseListener interface    ////////////////////////////////////////////////////////////////////        public void mouseClicked( MouseEvent event )        {            // do nothing        }        //--------------------------------------------------------------        public void mouseEntered( MouseEvent event )        {            updateSelection( event );        }        //--------------------------------------------------------------        public void mouseExited( MouseEvent event )        {            updateSelection( event );        }        //--------------------------------------------------------------        public void mousePressed( MouseEvent event )        {            updateSelection( event );            doSelection( );        }        //--------------------------------------------------------------        public void mouseReleased( MouseEvent event )        {            updateSelection( event );        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods : MouseMotionListener interface    ////////////////////////////////////////////////////////////////////        public void mouseDragged( MouseEvent event )        {            updateSelection( event );        }        //--------------------------------------------------------------        public void mouseMoved( MouseEvent event )        {            updateSelection( event );        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods    ////////////////////////////////////////////////////////////////////        private void updateSelection( MouseEvent event )        {            Point point = SwingUtilities.convertPoint( event.getComponent( ), event.getPoint( ), list );            list.setSelectedIndex( list.pointToIndex( point ) );        }        //--------------------------------------------------------------        private void doSelection( )        {            destroyMouseSelectionList( );            selectTab( list.getSelectedItem( ) );        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance variables    ////////////////////////////////////////////////////////////////////        private SelectionList<Element>  list;    }    //==================================================================    // ELEMENT COMPARATOR CLASS    private class ElementComparator        implements Comparator<Element>    {    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        private ElementComparator( )        {        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods : Comparator interface    ////////////////////////////////////////////////////////////////////        public int compare( Element element1,                            Element element2 )        {            return ( ignoreCase ? element1.toString( ).compareToIgnoreCase( element2.toString( ) )                                : element1.toString( ).compareTo( element2.toString( ) ) );        }        //--------------------------------------------------------------    }    //==================================================================//////////////////////////////////////////////////////////////////////////  Constructors////////////////////////////////////////////////////////////////////////    public TabbedPanel( )    {        // Initialise instance variables        elements = new ArrayList<Element>( );        recentElements = new ArrayList<Element>( );        selectedIndex = -1;        elementComparator = new ElementComparator( );        scrollTimer = new Timer( SCROLL_INTERVAL, this );        scrollTimer.setActionCommand( Command.SCROLL );        changeListeners = new ArrayList<ChangeListener>( );        headerHeight = HEADER_TOP_MARGIN +                            Math.max( HEADER_BUTTON_TOP_MARGIN + HEADER_BUTTON_HEIGHT +                                                                                HEADER_BUTTON_BOTTOM_MARGIN,                                      createTab( new String( ), null ).getPreferredSize( ).height );        // Set attributes        setLayout( null );        setOpaque( true );        setFocusable( false );        // Create header buttons        leftScrollButton = new ScrollButton( ArrowButton.Direction.LEFT );        rightScrollButton = new ScrollButton( ArrowButton.Direction.RIGHT );        listButton = new ListButton( );        updateButtons( );        // Remove Ctrl+Tab and Ctrl+Shift+Tab from focus traversal keys        setFocusTraversalKeys( KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,                               Collections.singleton( AWTKeyStroke.                                                            getAWTKeyStroke( KeyEvent.VK_TAB, 0 ) ) );        setFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,                               Collections.singleton( AWTKeyStroke.                                                            getAWTKeyStroke( KeyEvent.VK_TAB,                                                                             KeyEvent.SHIFT_DOWN_MASK) ) );        // Track changes in size        addComponentListener( this );        // Track focus owner        KeyboardFocusManager.getCurrentKeyboardFocusManager( ).                                                            addPropertyChangeListener( "focusOwner", this );        // Add commands to action map        KeyAction.create( this, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, KEY_COMMANDS, this );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods : ActionListener interface////////////////////////////////////////////////////////////////////////    public void actionPerformed( ActionEvent event )    {        try        {            String command = event.getActionCommand( );            String methodName = Constants.COMMAND_METHOD_PREFIX +                                        command.substring( 0, 1 ).toUpperCase( ) + command.substring( 1 );            Util.getDeclaredMethod( getClass( ), methodName, false ).invoke( this );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -