appconfig.java
来自「FuncPlotter is a combined Java applicati」· Java 代码 · 共 1,932 行 · 第 1/5 页
JAVA
1,932 行
lookAndFeel = lookAndFeelInfo.getName( ); break; } } plotSize = new Dimension( DEFAULT_PLOT_WIDTH, DEFAULT_PLOT_HEIGHT ); plotShowGrid = true; plotNumFractionDigits = DEFAULT_PLOT_NUM_FRACTION_DIGITS; plotFixedPointExponentRange = new IntegerRange( DEFAULT_PLOT_FIXED_POINT_LOWER_LIMIT, DEFAULT_PLOT_FIXED_POINT_UPPER_LIMIT ); plotNormaliseScientificNotation = true; plotFocusedBorderColour = DEFAULT_PLOT_FOCUSED_BORDER_COLOUR; plotImageMarginColour = DEFAULT_PLOT_IMAGE_MARGIN_COLOUR; plotBackgroundColour = DEFAULT_PLOT_BACKGROUND_COLOUR; plotGridColour = DEFAULT_PLOT_GRID_COLOUR; plotAxisColour = DEFAULT_PLOT_AXIS_COLOUR; plotScaleColour = DEFAULT_PLOT_SCALE_COLOUR; functionPathname = DEFAULT_PATHNAME; functionListSize = new Dimension( DEFAULT_FUNCTION_LIST_NUM_COLUMNS, DEFAULT_FUNCTION_LIST_NUM_ROWS ); functionColours = new Color[FunctionDocument.MAX_NUM_FUNCTIONS]; for ( int i = 0; i < functionColours.length; ++i ) functionColours[i] = DEFAULT_COLOURS[i % DEFAULT_COLOURS.length]; FontEx.init( AppFont.getNumFonts( ) ); AppFont.PLOT.getFontEx( ).setSize( DEFAULT_PLOT_FONT_SIZE ); } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Class methods//////////////////////////////////////////////////////////////////////// public static AppConfig getInstance( ) { if ( instance == null ) instance = new AppConfig( ); return instance; } //------------------------------------------------------------------ private static Boolean parseParamBoolean( Parameter param ) { Boolean value = null; try { value = Parameter.parseParamBoolean( param ); } catch ( AppException e ) { showWarningMessage( e ); } return value; } //------------------------------------------------------------------ private static Integer parseParamInteger( Parameter param, IntegerRange range ) { Integer value = null; try { value = Parameter.parseParamInteger( param, range ); } catch ( AppException e ) { showWarningMessage( e ); } return value; } //------------------------------------------------------------------ private static int[] parseParamIntegers( Parameter param, int length, IntegerRange[] ranges ) { return parseParamIntegers( param, length, ranges, null ); } //------------------------------------------------------------------ private static int[] parseParamIntegers( Parameter param, int length, IntegerRange[] ranges, Parameter.Order order ) { int[] values = null; try { values = Parameter.parseParamIntegers( param, length, ranges, order ); } catch ( AppException e ) { showWarningMessage( e ); } return values; } //------------------------------------------------------------------ private static Color parseParamColour( Parameter param ) { Color colour = null; try { colour = Parameter.parseParamColour( param ); } catch ( AppException e ) { showWarningMessage( e ); } return colour; } //------------------------------------------------------------------ public static void showWarningMessage( AppException exception ) { App.getInstance( ).showWarningMessage( App.SHORT_NAME + " : " + CONFIG_ERROR_STR, exception ); } //------------------------------------------------------------------ public static void showErrorMessage( AppException exception ) { App.getInstance( ).showErrorMessage( App.SHORT_NAME + " : " + CONFIG_ERROR_STR, exception ); } //------------------------------------------------------------------ private static File getFile( ) throws AppException { File file = null; String pathname = System.getProperty( Parameter.APP_PREFIX + CONFIG_PATH_STR ); if ( pathname == null ) { file = new File( CONFIG_FILENAME ); if ( !file.isFile( ) ) { file = null; pathname = App.getPropertiesPathname( ); if ( pathname != null ) { file = new File( pathname, CONFIG_FILENAME ); if ( !file.isFile( ) ) file = null; } } } else { if ( pathname.length( ) > 0 ) { file = new File( PropertyString.parsePathname( pathname ), CONFIG_FILENAME ); if ( !file.isFile( ) ) throw new FileException( ErrorId.FILE_DOES_NOT_EXIST, file ); } } return file; } //------------------------------------------------------------------ private static URL getURL( JApplet applet ) throws AppException { URL url = null; String pathname = applet.getParameter( Parameter.APP_PREFIX + CONFIG_PATH_STR ); if ( pathname != null ) { int length = pathname.length( ); if ( (length > 0) && (pathname.charAt( length - 1 ) != '/') ) pathname += '/'; try { url = new URL( applet.getCodeBase( ), pathname + CONFIG_FILENAME ); if ( url.getProtocol( ).equals( "file" ) ) { String urlPath = url.getPath( ); if ( urlPath.equals( "/" + PropertyString.USER_HOME_PREFIX ) || urlPath.startsWith( "/" + PropertyString.USER_HOME_PREFIX + "/" ) ) urlPath = urlPath.substring( 1 ); url = new URL( url.getProtocol( ), url.getHost( ), PropertyString.parsePathname( urlPath ) ); } } catch ( MalformedURLException e ) { throw new AppException( ErrorId.MALFORMED_URL ); } } return url; } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods//////////////////////////////////////////////////////////////////////// public File chooseFile( ) throws AppException { if ( fileChooser == null ) { try { fileChooser = new JFileChooser( ); fileChooser.setDialogTitle( SAVE_CONFIGURATION_FILE_STR ); fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY ); fileChooser. addChoosableFileFilter( new FilenameSuffixFilter( AppConstants.CONFIG_FILE_SUFFIX, AppConstants.CONFIG_FILES_STR ) ); App.applyOrientationByLocale( fileChooser ); selectedFile = file; } catch ( SecurityException e ) { throw new AppException( ErrorId.NO_FILE_CHOOSER ); } } fileChooser.setSelectedFile( (selectedFile == null) ? new File( CONFIG_FILENAME ).getAbsoluteFile( ) : selectedFile.getAbsoluteFile( ) ); fileChooser.rescanCurrentDirectory( ); if ( fileChooser.showSaveDialog( App.getInstance( ).getMainWindow( ) ) == JFileChooser.APPROVE_OPTION ) { selectedFile = Util.appendSuffix( fileChooser.getSelectedFile( ), AppConstants.CONFIG_FILE_SUFFIX ); return selectedFile; } return null; } //------------------------------------------------------------------ public void read( JApplet applet ) { // Read configuration file ConfigFile configFile = null; try { if ( applet == null ) { file = getFile( ); if ( file != null ) { configFile = new ConfigFile( ); configFile.read( file, ElementName.CONFIGURATION ); } } else { URL url = getURL( applet ); if ( url != null ) { configFile = new ConfigFile( ); configFile.read( url, ElementName.CONFIGURATION ); } } if ( configFile != null ) { String versionStr = configFile.getVersionString( ); if ( versionStr == null ) throw new FileException( ErrorId.NO_VERSION_NUMBER, file ); try { int version = Integer.parseInt( versionStr ); if ( version < 0 ) throw new NumberFormatException( ); if ( version > MAX_SUPPORTED_VERSION ) { String[] substStrs = { versionStr }; throw new FileException( ErrorId.INCOMPATIBLE_CONFIG_FILE, file, substStrs ); } } catch ( NumberFormatException e ) { throw new FileException( ErrorId.INVALID_VERSION_NUMBER, file ); } } } catch ( AppException e ) { file = null; configFile = null; showErrorMessage( e ); } // Get parameters getParameters( applet, configFile ); // Reset changed flag changed = false; } //------------------------------------------------------------------ public void write( ) { if ( changed ) { try { if ( file == null ) { String pathname = App.getPropertiesPathname( ); if ( pathname != null ) { File directory = new File( pathname ); if ( !directory.exists( ) ) directory.mkdirs( ); if ( !directory.isDirectory( ) ) throw new FileException( ErrorId.FAILED_TO_CREATE_DIRECTORY, directory ); file = new File( directory, CONFIG_FILENAME ); } } if ( file != null ) { write( file ); changed = false; } } catch ( AppException e ) { showErrorMessage( e ); } } } //------------------------------------------------------------------ public void write( File file ) throws AppException { // Initialise progress view OperationDialog progressView = (OperationDialog)Operation.getProgressView( ); if ( progressView != null ) { progressView.setInfo( WRITING_STR, file ); progressView.setProgress( -1.0 ); } // Create new DOM document ConfigFile configFile = new ConfigFile( Integer.toString( VERSION ) ); // Set configuration parameters in document setParameters( configFile ); // Write file configFile.write( file ); } //------------------------------------------------------------------ public void getPermissions( ) { // Assume permissions permissionAccessClipboard = true; // Get security manager SecurityManager securityManager = System.getSecurityManager( );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?