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

📄 app.java

📁 FuncPlotter is a combined Java application and applet for displaying two-dimensional plots of explic
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*====================================================================*\App.javaApplication 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.ExceptionUtilities;import exception.TerminatedException;import java.awt.Component;import java.awt.ComponentOrientation;import java.awt.Dimension;import java.io.File;import java.lang.reflect.InvocationTargetException;import java.util.ArrayList;import java.util.List;import java.util.Vector;import javax.swing.JApplet;import javax.swing.JDialog;import javax.swing.JFileChooser;import javax.swing.JOptionPane;import javax.swing.Timer;import javax.swing.UIManager;import util.FilenameSuffixFilter;import util.PropertiesPathname;//----------------------------------------------------------------------// APPLICATION CLASSclass App{//////////////////////////////////////////////////////////////////////////  Constants////////////////////////////////////////////////////////////////////////    public static final     String  SHORT_NAME  = "FuncPlotter";    public static final     String  LONG_NAME   = "Function Plotter";    public static final     String  NAME_KEY    = "funcPlotter";    public static final     int     VERSION_MAJOR   = 2;    public static final     int     VERSION_MINOR   = 0;    public static final     String  VERSION_BUILD   = "0";    public static final     int     MAX_NUM_DOCUMENTS   = 64;    private static final    int FILE_CHECK_TIMER_INTERVAL   = 500;    private static final    String  DEBUG_PROPERTY_KEY  = "app.debug";    private static final    String  STARTUP_PARAM_KEY   = "app.startup";    private static final    String  DIMENSIONS_ERROR_STR    = "The applet dimensions are too small.";    private static final    String  CONFIG_ERROR_STR        = " : Configuration error";    private static final    String  LAF_ERROR_STR1          = "Look-and-feel: ";    private static final    String  LAF_ERROR_STR2          = "\nThe look-and-feel is not installed.";    private static final    String  APPLET_STR              = "Applet: ";    private static final    String  MINIMUM_DIMENSIONS_STR  = "The minimum dimensions of the applet are ";    private static final    String  WIDTH_STR               = "(width)";    private static final    String  HEIGHT_STR              = "(height)";    private static final    String  OPEN_FILE_STR           = "Open File";    private static final    String  REOPEN_FILE_STR         = "Reopen File";    private static final    String  SAVE_FILE_STR           = "Save File";    private static final    String  SAVE_FILE_AS_STR        = "Save File As";    private static final    String  SAVE_CLOSE_FILE_STR     = "Save File Before Closing";    private static final    String  EXPORT_IMAGE_STR        = "Export Image";    private static final    String  MODIFIED_FILE_STR       = "Modified File";    private static final    String  OPEN_FUNCTION_FILE_STR  = "Open Function File";    private static final    String  SAVE_FUNCTION_FILE_STR  = "Save Function File";    private static final    String  EXPORT_IMAGE_FILE_STR   = "Export Image File";    private static final    String  COPY_INTERVALS_STR      = "Copy Intervals to Other Documents";    private static final    String  DOCUMENTS_STR           = "Documents:";    private static final    String  ERRORS_STR              = "Errors in File";    private static final    String  WRITE_IMAGE_STR         = "Write Image";    private static final    String  READ_DOCUMENT_STR       = "Read Document";    private static final    String  WRITE_DOCUMENT_STR      = "Write Document";    private static final    String  UNNAMED_FILE_STR        = "The unnamed file";    private static final    String  FILE_STR                = "\nThe file";    private static final    String  MODIFIED_MESSAGE_STR    = "\nThe file has been modified externally.\n" +                                                                "Do you want to open the modified file?";    private static final    String  REOPEN_MESSAGE_STR      = "\nDo you want discard the changes to the " +                                                                "current document and reopen the " +                                                                "original file?";    private static final    String  CHANGED_MESSAGE_STR     = " has changed.\nDo you want to save the " +                                                                "changed file?";    private static final    String  SAVE_COLOURS_STR        = "Do you want to save the colours of the " +                                                                "functions?";    private static final    String  HAS_COMMENTS_STR        = "The document contains comments that will " +                                                                "be lost if the document is saved.";    private static final    String[]    CC_OPTION_STRS  = { "Continue", "Cancel" };    private static final    String[]    OC_OPTION_STRS  = { "Reopen", "Cancel" };    private static final    String[]    SDC_OPTION_STRS = { "Save", "Discard", "Cancel" };    private enum IncludeColours    {        NO,        YES    }//////////////////////////////////////////////////////////////////////////  Enumeration types////////////////////////////////////////////////////////////////////////    // ERROR IDENTIFIERS    private enum ErrorId        implements AppException.Id    {    ////////////////////////////////////////////////////////////////////    //  Constants    ////////////////////////////////////////////////////////////////////        NO_FILE_CHOOSER        ( "Security restrictions prevented a file selection dialog box from being displayed." );    ////////////////////////////////////////////////////////////////////    //  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////////////////////////////////////////////////////////////////////////    // DOCUMENT-VIEW CLASS    private static class DocumentView    {    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        private DocumentView( FunctionDocument document )        {            this.document = document;            view = new FunctionView( document );        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance variables    ////////////////////////////////////////////////////////////////////        FunctionDocument    document;        FunctionView        view;    }    //==================================================================//////////////////////////////////////////////////////////////////////////  Constructors////////////////////////////////////////////////////////////////////////    private App( JApplet applet )    {        this.applet = applet;        documentsViews = new ArrayList<DocumentView>( );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Class methods////////////////////////////////////////////////////////////////////////    public static App getInstance( )    {        if ( instance == null )            instance = new App( null );        return instance;    }    //------------------------------------------------------------------    public static App getInstance( JApplet applet )    {        instance = new App( applet );        return instance;    }    //------------------------------------------------------------------    public static boolean isDebug( )    {        return debug;    }    //------------------------------------------------------------------    public static String getPropertiesPathname( )    {        String pathname = PropertiesPathname.getPathname( );        if ( pathname != null )            pathname += NAME_KEY.toLowerCase( );        return pathname;    }    //------------------------------------------------------------------    public static void applyOrientationByLocale( Component component )    {        if ( AppConfig.getInstance( ).isOrientationByLocale( ) )            component.applyComponentOrientation( ComponentOrientation.                                                                getOrientation( component.getLocale( ) ) );    }    //------------------------------------------------------------------    public static String getPathname( File file )    {        return Util.getPathname( file, AppConfig.getInstance( ).isShowUnixPathnames( ) );    }    //------------------------------------------------------------------    public static char getFileSeparatorChar( )    {        return ( AppConfig.getInstance( ).isShowUnixPathnames( ) ? '/' : File.separatorChar );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods////////////////////////////////////////////////////////////////////////    public boolean isApplet( )    {        return ( applet != null );    }    //------------------------------------------------------------------    public MainWindow getMainWindow( )    {        return mainWindow;    }    //------------------------------------------------------------------    public int getNumDocuments( )    {        return documentsViews.size( );    }    //------------------------------------------------------------------    public boolean hasDocuments( )    {        return !documentsViews.isEmpty( );    }    //------------------------------------------------------------------    public boolean isDocumentsFull( )    {        return ( documentsViews.size( ) >= MAX_NUM_DOCUMENTS );    }    //------------------------------------------------------------------    public FunctionDocument getDocument( )    {        return ( (applet == null) ? hasDocuments( ) ? getDocument( mainWindow.getTabIndex( ) ) : null                                  : getDocument( 0 ) );    }    //------------------------------------------------------------------    public FunctionDocument getDocument( int index )    {        return ( hasDocuments( ) ? documentsViews.get( index ).document : null );    }    //------------------------------------------------------------------    public FunctionView getView( )    {        return ( (applet == null) ? hasDocuments( ) ? getView( mainWindow.getTabIndex( ) ) : null                                  : getView( 0 ) );    }    //------------------------------------------------------------------    public FunctionView getView( int index )    {        return ( hasDocuments( ) ? documentsViews.get( index ).view : null );    }    //------------------------------------------------------------------    public FunctionView getView( FunctionDocument document )    {        for ( DocumentView documentView : documentsViews )        {            if ( documentView.document == document )                return documentView.view;        }        return null;    }    //------------------------------------------------------------------    public void clearDocuments( )    {        documentsViews.clear( );    }    //------------------------------------------------------------------    public void showWarningMessage( String titleStr,                                    Object message )    {        JDialog dialog = new JOptionPane( message, JOptionPane.WARNING_MESSAGE ).createDialog( mainWindow,                                                                                               titleStr );        applyOrientationByLocale( dialog );        dialog.setVisible( true );    }    //------------------------------------------------------------------    public void showErrorMessage( String titleStr,                                  Object message )    {        JDialog dialog = new JOptionPane( message, JOptionPane.ERROR_MESSAGE ).createDialog( mainWindow,                                                                                             titleStr );        applyOrientationByLocale( dialog );        dialog.setVisible( true );    }    //------------------------------------------------------------------    public void init( String[] args )    {        // Set runtime debug flag        debug = (applet == null) ? (System.getProperty( DEBUG_PROPERTY_KEY ) != null)                                 : (applet.getParameter( DEBUG_PROPERTY_KEY ) != null);        // Get clipboard access permission        AppConfig config = AppConfig.getInstance( );        config.getPermissions( );        // Read configuration        config.read( applet );        // Set UNIX style for pathnames in file exceptions        ExceptionUtilities.setUnix( config.isShowUnixPathnames( ) );        // Set look-and-feel        String lookAndFeelName = config.getLookAndFeel( );        for ( UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels( ) )        {

⌨️ 快捷键说明

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