📄 integerspinner.java
字号:
/*====================================================================*\IntegerSpinner.javaInteger 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 java.awt.Font;import textfield.IntegerValueField;import textfield.TextFieldConstants;//----------------------------------------------------------------------// INTEGER SPINNER CLASSpublic class IntegerSpinner extends AbstractIntegerSpinner{////////////////////////////////////////////////////////////////////////// Member classes : non-inner classes//////////////////////////////////////////////////////////////////////// // EDITOR CLASS private static class Editor extends IntegerValueField { //////////////////////////////////////////////////////////////////// // Constants //////////////////////////////////////////////////////////////////// private static final String VALID_CHARS = "-0123456789"; //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private Editor( int maxLength, boolean signed ) { super( maxLength ); this.signed = signed; } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : overriding methods //////////////////////////////////////////////////////////////////// public int getValue( ) throws NumberFormatException { try { if ( signed ) return Integer.parseInt( getText( ) ); long value = Long.parseLong( getText( ) ); if ( value > 0xFFFFFFFFL ) throw new NumberFormatException( ); return (int)value; } catch ( NumberFormatException e ) { setInvalid( true ); throw e; } } //-------------------------------------------------------------- public void setValue( int value ) { setText( signed ? Integer.toString( value ) : Long.toString( value & 0xFFFFFFFFL ) ); } //-------------------------------------------------------------- protected char validateCharacter( char ch, int index ) { int i = VALID_CHARS.indexOf( ch ); return ( ((i < 0) || (!signed && (i == 0))) ? TextFieldConstants.INVALID_CHAR : ch ); } //-------------------------------------------------------------- protected int getColumnWidth( ) { return ( GuiUtilities.getCharWidth( '0', getFontMetrics( getFont( ) ) ) + 1 ); } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods //////////////////////////////////////////////////////////////////// public void setSigned( boolean signed ) { this.signed = signed; } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance variables //////////////////////////////////////////////////////////////////// private boolean signed; } //==================================================================////////////////////////////////////////////////////////////////////////// Constructors//////////////////////////////////////////////////////////////////////// public IntegerSpinner( int value, int minValue, int maxValue, int maxLength ) { this( value, minValue, maxValue, maxLength, false ); } //------------------------------------------------------------------ public IntegerSpinner( int value, int minValue, int maxValue, int maxLength, boolean signed ) { super( value, minValue, maxValue, new Editor( maxLength, signed ) ); } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods : overriding methods//////////////////////////////////////////////////////////////////////// public void setFont( Font font ) { super.setFont( font ); if ( editor != null ) editor.setFont( font ); } //------------------------------------------------------------------ protected boolean isEditorInvalid( ) { return ((Editor)editor).isInvalid( ); } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods//////////////////////////////////////////////////////////////////////// public void setSigned( boolean signed ) { ((Editor)editor).setSigned( signed ); } //------------------------------------------------------------------}//----------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -