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

📄 abstractintegerspinner.java

📁 FuncPlotter is a combined Java application and applet for displaying two-dimensional plots of explic
💻 JAVA
字号:
/*====================================================================*\AbstractIntegerSpinner.javaAbstract integer spinner 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 javax.swing.BorderFactory;import javax.swing.SpinnerNumberModel;import textfield.IntegerValueField;//----------------------------------------------------------------------// ABSTRACT INTEGER SPINNER CLASSpublic abstract class AbstractIntegerSpinner    extends AbstractSpinner{//////////////////////////////////////////////////////////////////////////  Constants////////////////////////////////////////////////////////////////////////    private static final    int STEP_SIZE   = 1;//////////////////////////////////////////////////////////////////////////  Constructors////////////////////////////////////////////////////////////////////////    public AbstractIntegerSpinner( int value,                                   int minValue,                                   int maxValue )    {        this( value, minValue, maxValue, false );    }    //------------------------------------------------------------------    public AbstractIntegerSpinner( int     value,                                   int     minValue,                                   int     maxValue,                                   boolean alwaysUpdate )    {        super( new SpinnerNumberModel( value, minValue, maxValue, STEP_SIZE ), alwaysUpdate );    }    //------------------------------------------------------------------    public AbstractIntegerSpinner( int               value,                                   int               minValue,                                   int               maxValue,                                   IntegerValueField editor )    {        this( value, minValue, maxValue, editor, false );    }    //------------------------------------------------------------------    public AbstractIntegerSpinner( int               value,                                   int               minValue,                                   int               maxValue,                                   IntegerValueField editor,                                   boolean           alwaysUpdate )    {        this( value, minValue, maxValue, alwaysUpdate );        initEditor( editor );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods : overriding methods////////////////////////////////////////////////////////////////////////    public boolean requestFocusInWindow( )    {        return ( (editor == null) ? super.requestFocusInWindow( ) : editor.requestFocusInWindow( ) );    }    //------------------------------------------------------------------    public void updateValue( )    {        try        {            int value = getEditorValue( );            int boundedValue = getBoundedValue( value );            setIntValue( boundedValue );            if ( alwaysUpdate || (value != boundedValue) || isEditorInvalid( ) )                setEditorValue( boundedValue );        }        catch ( IllegalArgumentException e )        {            // ignore        }    }    //------------------------------------------------------------------    protected void updateEditorValue( )    {        setEditorValue( getIntValue( ) );    }    //------------------------------------------------------------------    protected void incrementValue( int increment )    {        long value = Math.min( Math.max( (long)Integer.MIN_VALUE, (long)getIntValue( ) + (long)increment ),                               (long)Integer.MAX_VALUE );        setIntValue( getBoundedValue( (int)value ) );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods////////////////////////////////////////////////////////////////////////    public int getIntValue( )    {        return ((Integer)getValue( )).intValue( );    }    //------------------------------------------------------------------    public void setIntValue( int value )    {        setValue( new Integer( value ) );    }    //------------------------------------------------------------------    public void setMinimum( int minValue )    {        ((SpinnerNumberModel)getModel( )).setMinimum( new Integer( minValue ) );        setIntValue( getBoundedValue( getIntValue( ) ) );    }    //------------------------------------------------------------------    public void setMaximum( int maxValue )    {        ((SpinnerNumberModel)getModel( )).setMaximum( new Integer( maxValue ) );        setIntValue( getBoundedValue( getIntValue( ) ) );    }    //------------------------------------------------------------------    protected void initEditor( IntegerValueField editor )    {        // Set editor        this.editor = editor;        editor.setBorder( BorderFactory.createEmptyBorder( SpinnerConstants.VERTICAL_MARGIN,                                                           SpinnerConstants.HORIZONTAL_MARGIN,                                                           SpinnerConstants.VERTICAL_MARGIN,                                                           SpinnerConstants.HORIZONTAL_MARGIN ) );        setEditor( editor );        updateEditorValue( );        // Add actions to editor        addEditorActions( );        // Add listeners        editor.setActionCommand( Command.COMMIT_EDIT );        editor.addActionListener( this );        editor.addFocusListener( this );    }    //------------------------------------------------------------------    protected int getEditorValue( )        throws IllegalArgumentException    {        return editor.getValue( );    }    //------------------------------------------------------------------    protected void setEditorValue( int value )    {        editor.setValue( value );    }    //------------------------------------------------------------------    protected boolean isEditorInvalid( )    {        return false;    }    //------------------------------------------------------------------    protected int getBoundedValue( int value )    {        SpinnerNumberModel model = (SpinnerNumberModel)getModel( );        int minValue = ((Integer)model.getMinimum( )).intValue( );        int maxValue = ((Integer)model.getMaximum( )).intValue( );        return Math.min( Math.max( minValue, value ), maxValue );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance variables////////////////////////////////////////////////////////////////////////    protected   IntegerValueField   editor;}//----------------------------------------------------------------------

⌨️ 快捷键说明

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