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

📄 functiondocument.java

📁 FuncPlotter is a combined Java application and applet for displaying two-dimensional plots of explic
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*====================================================================*\FunctionDocument.javaFunction document 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 exception.TempFileException;import gui.ProgressView;import gui.SingleSelectionList;import java.awt.Color;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.datatransfer.StringSelection;import java.awt.event.ActionEvent;import java.awt.event.KeyEvent;import java.awt.image.BufferedImage;import java.beans.PropertyChangeListener;import java.io.BufferedOutputStream;import java.io.CharArrayWriter;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.lang.reflect.InvocationTargetException;import java.math.BigDecimal;import java.nio.channels.FileChannel;import java.util.ArrayList;import java.util.Collections;import java.util.LinkedList;import java.util.List;import javax.imageio.ImageIO;import javax.swing.Action;import javax.swing.ImageIcon;import javax.swing.JOptionPane;import javax.swing.KeyStroke;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import util.ColourUtilities;import util.TextFile;import xml.Comment;import xml.XmlConstants;import xml.XmlParseException;import xml.XmlUtilities;import xml.XmlWriter;//----------------------------------------------------------------------// FUNCTION DOCUMENT CLASSclass FunctionDocument    implements SingleSelectionList.Model<Function>{//////////////////////////////////////////////////////////////////////////  Constants////////////////////////////////////////////////////////////////////////    public static final     int MAX_NUM_FUNCTIONS   = 20;    public static final     String  X_INTERVAL_KEY  = "xInterval";    public static final     String  Y_INTERVAL_KEY  = "yInterval";    public static final     String  FUNCTION_KEY    = "function";    private static final    int VERSION                 = 0;    private static final    int MAX_SUPPORTED_VERSION   = 0;    private static final    int MERGE_INTERVAL_EDITS_INTERVAL   = 500;    private static final    char    INTERVAL_PREFIX_CHAR    = '@';    private static final    char    COMMENT_PREFIX_CHAR     = '#';    private static final    String  XML_PREFIX          = "<?xm";    private static final    String  XML_VERSION_STR     = "1.0";    private static final    String  XML_NAMESPACE_STR   =                                                "data:text/plain;charset=utf-8,FuncPlotter/functionList";    private static final    String  UNTITLED_STR                = "Untitled";    private static final    String  LINE_STR                    = "Line ";    private static final    String  PNG_STR                     = "png";    private static final    String  READING_STR                 = "Reading";    private static final    String  WRITING_STR                 = "Writing";    private static final    String  COMMENT_STR                 = "Comment";    private static final    String  ADD_FUNCTION_STR            = "Add Function";    private static final    String  EDIT_FUNCTION_STR           = "Edit Function";    private static final    String  DELETE_FUNCTION_STR         = "Delete Function";    private static final    String  DELETE_ALL_FUNCTIONS_STR    = "Delete All Functions";    private static final    String  CLEAR_EDIT_LIST_STR         = "Do you want to clear all the " +                                                                    "undo/redo actions?";    private static final    String  DELETE_MESSAGE_STR          = "Do you want to delete the selected " +                                                                    "function?";    private static final    String  DELETE_ALL_MESSAGE_STR      = "Do you want to delete all the " +                                                                    "functions?";    private static final    String[]    CC_OPTION_STRS  = { "Clear", "Cancel" };    private static final    String[]    DC_OPTION_STRS  = { "Delete", "Cancel" };    private enum ViewComponent    {        PLOT,        BUTTONS,        X_INTERVAL,        Y_INTERVAL,        INTERVALS    }    private enum TextState    {        COMMENT_FIRST_LINE,        COMMENT,        STATEMENT,        INTERVAL,        FUNCTION,        DONE    }    private interface ElementName    {        String  FUNCTION        = "function";        String  FUNCTION_LIST   = "functionList";    }    private interface AttrName    {        String  COLOUR      = "colour";        String  EXPRESSION  = "expression";        String  VERSION     = "version";        String  XMLNS       = "xmlns";        String  X_INTERVAL  = "xInterval";        String  Y_INTERVAL  = "yInterval";    }//////////////////////////////////////////////////////////////////////////  Enumeration types////////////////////////////////////////////////////////////////////////    // COMMANDS    enum Command        implements Action    {    ////////////////////////////////////////////////////////////////////    //  Constants    ////////////////////////////////////////////////////////////////////        // Commands        UNDO        (            "undo",            "Undo",            KeyStroke.getKeyStroke( KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK )        ),        REDO        (            "redo",            "Redo",            KeyStroke.getKeyStroke( KeyEvent.VK_Y, KeyEvent.CTRL_DOWN_MASK )        ),        CLEAR_EDIT_LIST        (            "clearEditList",            "Clear Undo/Redo Actions"        ),        EDIT_COMMENT        (            "editComment",            "Comment" + AppConstants.ELLIPSIS_STR,            KeyStroke.getKeyStroke( KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK )        ),        ADD_FUNCTION        (            "addFunction",            "Add" + AppConstants.ELLIPSIS_STR,            "Add a function"        ),        EDIT_FUNCTION        (            "editFunction",            "Edit" + AppConstants.ELLIPSIS_STR,            "Edit the selected function"        ),        COPY_FUNCTION        (            "copyFunction",            "Copy",            "Copy the selected function to the clipboard"        ),        HIDE_SHOW_FUNCTION        (            "hideShowFunction",            "Hide"        ),        DELETE_FUNCTION        (            "deleteFunction",            "Delete",            "Delete the selected function"        ),        CONFIRM_DELETE_FUNCTION        (            "confirmDeleteFunction"        ),        CLEAR_FUNCTIONS        (            "clearFunctions",            "Clear",            "Delete all functions"        ),        MOVE_FUNCTION        (            "moveFunction"        ),        REVERSE_FUNCTIONS        (            "reverseFunctions",            "Reverse Order of Functions"        ),        SCROLL_LEFT        (            "scrollLeft",            AppIcon.ARROW_LEFT,            "Scroll left"        ),        SCROLL_RIGHT        (            "scrollRight",            AppIcon.ARROW_RIGHT,            "Scroll right"        ),        SCROLL_DOWN        (            "scrollDown",            AppIcon.ARROW_DOWN,            "Scroll down"        ),        SCROLL_UP        (            "scrollUp",            AppIcon.ARROW_UP,            "Scroll up"        ),        CENTRE_ON_ORIGIN        (            "centreOnOrigin",            AppIcon.ORIGIN,            "Centre on origin"        ),        X_ZOOM_OUT        (            "xZoomOut",            AppIcon.ZOOM_OUT,            "x zoom out"        ),        X_ZOOM_IN        (            "xZoomIn",            AppIcon.ZOOM_IN,            "x zoom in"        ),        Y_ZOOM_OUT        (            "yZoomOut",            AppIcon.ZOOM_OUT,            "y zoom out"        ),        Y_ZOOM_IN        (            "yZoomIn",            AppIcon.ZOOM_IN,            "y zoom in"        ),        SET_X_INTERVAL        (            "setXInterval"        ),        SET_Y_INTERVAL        (            "setYInterval"        ),        SET_INTERVALS        (            "setIntervals"        );        //--------------------------------------------------------------        // Property keys        interface Property        {            String  END         = "end";            String  INDEX       = "index";            String  X_INTERVAL  = "xInterval";            String  Y_INTERVAL  = "yInterval";        }        // Other constants        public static final String  UNDO_STR            = "Undo the previous edit";        public static final String  REDO_STR            = "Redo the next edit";        public static final String  HIDE_STR            = "Hide";        public static final String  SHOW_STR            = "Show";        public static final String  HIDE_FUNCTION_STR   = "Hide the selected function";        public static final String  SHOW_FUNCTION_STR   = "Show the selected function";    ////////////////////////////////////////////////////////////////////    //  Static initialiser    ////////////////////////////////////////////////////////////////////        static        {            if ( App.getInstance( ).isApplet( ) )            {                UNDO.putValue( Action.SHORT_DESCRIPTION, UNDO_STR );                REDO.putValue( Action.SHORT_DESCRIPTION, REDO_STR );            }        }    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        private Command( String key )        {            command = new util.Command( this );            putValue( Action.ACTION_COMMAND_KEY, key );        }        //--------------------------------------------------------------        private Command( String key,                         String name )        {            this( key );            putValue( Action.NAME, name );        }        //--------------------------------------------------------------        private Command( String key,                         String name,                         String text )        {            this( key, name );            putValue( Action.SHORT_DESCRIPTION, text );        }        //--------------------------------------------------------------        private Command( String    key,                         ImageIcon icon,                         String    text )        {            this( key );

⌨️ 快捷键说明

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