📄 appconfig.java
字号:
/*====================================================================*\AppConfig.javaApplication configuration 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/>.\*====================================================================*/// IMPORTSimport exception.AppException;import exception.FileException;import gui.FontEx;import java.awt.AWTPermission;import java.awt.Color;import java.awt.Dimension;import java.awt.Point;import java.io.File;import java.net.MalformedURLException;import java.net.URL;import javax.swing.JApplet;import javax.swing.JFileChooser;import javax.swing.UIManager;import util.ColourUtilities;import util.FilenameSuffixFilter;import util.IntegerRange;import util.NoYes;import util.Parameter;import util.PropertyString;import xml.PropertyFile;//----------------------------------------------------------------------// APPLICATION CONFIGURATION CLASSclass AppConfig{////////////////////////////////////////////////////////////////////////// Constants//////////////////////////////////////////////////////////////////////// public static final int MIN_NUM_FRACTION_DIGITS = 1; public static final int MAX_NUM_FRACTION_DIGITS = 12; public static final int MIN_FIXED_POINT_EXPONENT_LIMIT = -12; public static final int MAX_FIXED_POINT_EXPONENT_LIMIT = 12; private static final int VERSION = 2; private static final int MAX_SUPPORTED_VERSION = 2; private static final String CONFIG_ERROR_STR = "Configuration error"; private static final String CONFIG_PATH_STR = "configPath"; private static final String CONFIG_FILENAME = App.NAME_KEY + AppConstants.CONFIG_FILE_SUFFIX; private static final String SAVE_CONFIGURATION_FILE_STR = "Save Configuration File"; private static final String WRITING_STR = "Writing"; private interface ElementName { String APPEARANCE = "appearance"; String AXIS_COLOUR = "axisColour"; String BACKGROUND_COLOUR = "backgroundColour"; String COLOUR = "colour"; String CONFIGURATION = App.NAME_KEY + "Configuration"; String DEFAULT_FILE_TYPE = "defaultFileType"; String DIRECTORY = "directory"; String FIXED_POINT_EXPONENT_RANGE = "fixedPointExponentRange"; String FOCUSED_BORDER_COLOUR = "focusedBorderColour"; String FONT = "font"; String FUNCTION = "function"; String GENERAL = "general"; String GRID_COLOUR = "gridColour"; String IMAGE_MARGIN_COLOUR = "imageMarginColour"; String LIST_SIZE = "listSize"; String LOOK_AND_FEEL = "lookAndFeel"; String MAIN_WINDOW_LOCATION = "mainWindowLocation"; String NEW_DOCUMENT_ON_STARTUP = "newDocumentOnStartup"; String NORMALISE_SCIENTIFIC_NOTATION = "normaliseScientificNotation"; String NUM_FRACTION_DIGITS = "numFractionDigits"; String ORIENTATION_BY_LOCALE = "orientationByLocale"; String PLOT = "plot"; String SAVE_FUNCTION_COLOURS = "saveFunctionColours"; String SCALE_COLOUR = "scaleColour"; String SHOW_FULL_PATHNAMES = "showFullPathnames"; String SHOW_GRID = "showGrid"; String SHOW_UNIX_PATHNAMES = "showUnixPathnames"; String SIZE = "size"; } private static final String PANEL_BACKGROUND_COLOUR_KEY = "Panel.background"; // Default values private static final String DEFAULT_PATHNAME = PropertyString.USER_HOME_PREFIX; private static final FileType DEFAULT_DEFAULT_FILE_TYPE = FileType.XML; private static final NoYesAsk DEFAULT_SAVE_FUNCTION_COLOURS = NoYesAsk.YES; private static final Color DEFAULT_BACKGROUND_COLOUR = new Color( 236, 236, 224 ); private static final int DEFAULT_PLOT_WIDTH = 480; private static final int DEFAULT_PLOT_HEIGHT = 480; private static final int DEFAULT_PLOT_NUM_FRACTION_DIGITS = 5; private static final int DEFAULT_PLOT_FIXED_POINT_LOWER_LIMIT = -3; private static final int DEFAULT_PLOT_FIXED_POINT_UPPER_LIMIT = 6; private static final Color DEFAULT_PLOT_FOCUSED_BORDER_COLOUR = new Color( 128, 64, 64 ); private static final Color DEFAULT_PLOT_IMAGE_MARGIN_COLOUR = new Color( 224, 224, 220 ); private static final Color DEFAULT_PLOT_BACKGROUND_COLOUR = new Color( 248, 248, 240 ); private static final Color DEFAULT_PLOT_GRID_COLOUR = new Color( 216, 216, 216 ); private static final Color DEFAULT_PLOT_AXIS_COLOUR = new Color( 144, 144, 144 ); private static final Color DEFAULT_PLOT_SCALE_COLOUR = Color.BLACK; private static final int DEFAULT_PLOT_FONT_SIZE = 10; private static final int DEFAULT_FUNCTION_LIST_NUM_COLUMNS = 32; private static final int DEFAULT_FUNCTION_LIST_NUM_ROWS = 12; private static final int LEVEL_A1 = 236; private static final int LEVEL_A2 = 255; private static final int LEVEL_B1 = 112; private static final int LEVEL_B2 = 184; private static final int LEVEL_B3 = 255; private static final Color DEFAULT_COLOURS[] = { new Color( LEVEL_A2, 0, 0 ), new Color( 0, LEVEL_A2, 0 ), new Color( 0, 0, LEVEL_A2 ), new Color( LEVEL_A1, LEVEL_A1, 0 ), new Color( LEVEL_A1, 0, LEVEL_A1 ), new Color( 0, LEVEL_A1, LEVEL_A1 ), new Color( 0, 0, 0 ), new Color( LEVEL_B3, LEVEL_B2, LEVEL_B1 ), new Color( LEVEL_B2, LEVEL_B3, LEVEL_B1 ), new Color( LEVEL_B3, LEVEL_B1, LEVEL_B2 ), new Color( LEVEL_B1, LEVEL_B3, LEVEL_B2 ), new Color( LEVEL_B2, LEVEL_B1, LEVEL_B3 ), new Color( LEVEL_B1, LEVEL_B2, LEVEL_B3 ), };////////////////////////////////////////////////////////////////////////// Enumeration types//////////////////////////////////////////////////////////////////////// // NO-YES-ASK OPTION enum NoYesAsk { //////////////////////////////////////////////////////////////////// // Constants //////////////////////////////////////////////////////////////////// NO ( "no", "No" ), YES ( "yes", "Yes" ), ASK ( "ask", "Ask" ); //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private NoYesAsk( String key, String text ) { this.key = key; this.text = text; } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Class methods //////////////////////////////////////////////////////////////////// public static NoYesAsk get( String key ) { for ( NoYesAsk value : values( ) ) { if ( value.key.equals( key ) ) return value; } return null; } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : overriding methods //////////////////////////////////////////////////////////////////// public String toString( ) { return text; } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods //////////////////////////////////////////////////////////////////// public String getKey( ) { return key; } //-------------------------------------------------------------- public String getText( ) { return text; } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance variables //////////////////////////////////////////////////////////////////// private String key; private String text; } //================================================================== // ERROR IDENTIFIERS private enum ErrorId implements AppException.Id { //////////////////////////////////////////////////////////////////// // Constants //////////////////////////////////////////////////////////////////// FILE_DOES_NOT_EXIST ( "The configuration file does not exist." ), MALFORMED_URL ( "The pathname of the configuration file is malformed." ), NO_VERSION_NUMBER ( "The configuration file does not have a version number." ), INVALID_VERSION_NUMBER ( "The version number of the configuration file is invalid." ), INCOMPATIBLE_CONFIG_FILE ( "The version of the configuration file (%1) is incompatible with this version of " + App.SHORT_NAME + "." ), NO_FILE_CHOOSER ( "Security restrictions prevented a file selection dialog box from being displayed." ), FAILED_TO_CREATE_DIRECTORY ( "Failed to create the directory for the configuration file." ); //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private ErrorId( String message ) { this.message = message; } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : AppException.Id interface //////////////////////////////////////////////////////////////////// public String getMessage( ) { return message; } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance variables //////////////////////////////////////////////////////////////////// private String message; } //==================================================================////////////////////////////////////////////////////////////////////////// Member classes : non-inner classes//////////////////////////////////////////////////////////////////////// // CONFIGURATION FILE CLASS private static class ConfigFile extends PropertyFile { //////////////////////////////////////////////////////////////////// // Constants //////////////////////////////////////////////////////////////////// private static final String FILE_TYPE_STR = "configuration file"; //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private ConfigFile( ) { } //-------------------------------------------------------------- private ConfigFile( String versionStr ) throws AppException { super( ElementName.CONFIGURATION, versionStr ); } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : overriding methods //////////////////////////////////////////////////////////////////// protected String getFileTypeString( ) { return FILE_TYPE_STR; } //-------------------------------------------------------------- } //==================================================================////////////////////////////////////////////////////////////////////////// Constructors//////////////////////////////////////////////////////////////////////// private AppConfig( ) { defaultFileType = DEFAULT_DEFAULT_FILE_TYPE; saveFunctionColours = DEFAULT_SAVE_FUNCTION_COLOURS; mainWindowLocation = new Point( ); lookAndFeel = new String( ); for ( UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels( ) ) { if ( lookAndFeelInfo.getClassName( ). equals( UIManager.getCrossPlatformLookAndFeelClassName( ) ) ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -