📄 functiondocument.java
字号:
putValue( Action.LARGE_ICON_KEY, icon ); putValue( Action.SHORT_DESCRIPTION, text ); } //-------------------------------------------------------------- private Command( String key, String name, KeyStroke acceleratorKey ) { this( key, name ); putValue( Action.ACCELERATOR_KEY, acceleratorKey ); } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Class methods //////////////////////////////////////////////////////////////////// public static void setAllEnabled( boolean enabled ) { for ( Command command : values( ) ) command.setEnabled( enabled ); } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : Action interface //////////////////////////////////////////////////////////////////// public void addPropertyChangeListener( PropertyChangeListener listener ) { command.addPropertyChangeListener( listener ); } //-------------------------------------------------------------- public Object getValue( String key ) { return command.getValue( key ); } //-------------------------------------------------------------- public boolean isEnabled( ) { return command.isEnabled( ); } //-------------------------------------------------------------- public void putValue( String key, Object value ) { command.putValue( key, value ); } //-------------------------------------------------------------- public void removePropertyChangeListener( PropertyChangeListener listener ) { command.removePropertyChangeListener( listener ); } //-------------------------------------------------------------- public void setEnabled( boolean enabled ) { command.setEnabled( enabled ); } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : ActionListener interface //////////////////////////////////////////////////////////////////// public void actionPerformed( ActionEvent event ) { FunctionDocument document = App.getInstance( ).getDocument( ); if ( document != null ) document.executeCommand( this ); } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods //////////////////////////////////////////////////////////////////// public String getMethodName( ) { return command.getMethodName( ); } //-------------------------------------------------------------- public void execute( ) { actionPerformed( null ); } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance variables //////////////////////////////////////////////////////////////////// private util.Command command; } //================================================================== // ERROR IDENTIFIERS private enum ErrorId implements AppException.Id { //////////////////////////////////////////////////////////////////// // Constants //////////////////////////////////////////////////////////////////// FILE_DOES_NOT_EXIST ( "The file does not exist." ), NOT_A_FILE ( "The pathname does not specify a file." ), FAILED_TO_OPEN_FILE ( "Failed to open the file." ), FAILED_TO_CLOSE_FILE ( "Failed to close the file." ), FAILED_TO_LOCK_FILE ( "Failed to lock the file." ), ERROR_WRITING_FILE ( "An error occurred when writing the file." ), FILE_ACCESS_NOT_PERMITTED ( "Access to the file was not permitted." ), FAILED_TO_CREATE_TEMPORARY_FILE ( "Failed to create a temporary file." ), FAILED_TO_DELETE_FILE ( "Failed to delete the existing file." ), FAILED_TO_RENAME_FILE ( "Failed to rename the temporary file to the specified filename." ), INCORRECT_DOCUMENT_FORMAT ( "The document is not in the correct format." ), UNSUPPORTED_DOCUMENT_VERSION ( "The version of the document (%1) is not supported by this version of " + App.SHORT_NAME + "." ), NO_ATTRIBUTE ( "The element does not have such an attribute." ), INVALID_ATTRIBUTE ( "The attribute is invalid." ), ATTRIBUTE_OUT_OF_BOUNDS ( "The attribute value is out of bounds." ), MULTIPLE_COMMENT_ELEMENTS ( "The file contains more than one comment element." ), INVALID_INTERVAL_IDENTIFIER ( "The interval identifier is invalid." ), INVALID_INTERVAL ( "The interval is invalid." ), INVALID_INTERVAL_LOWER_ENDPOINT ( "The lower endpoint of the interval is invalid." ), INTERVAL_LOWER_ENDPOINT_OUT_OF_BOUNDS ( "The lower endpoint of the interval must be between " + PlotInterval.MIN_VALUE + " and " + PlotInterval.MAX_VALUE + "." ), INTERVAL_LOWER_ENDPOINT_HAS_TOO_MANY_SIGNIFICANT_DIGITS ( "The lower endpoint of the interval must not have more than " + PlotInterval.MAX_NUM_SIGNIFICANT_DIGITS + " significant digits." ), INVALID_INTERVAL_UPPER_ENDPOINT ( "The upper endpoint of the interval is invalid." ), INTERVAL_UPPER_ENDPOINT_OUT_OF_BOUNDS ( "The upper endpoint of the interval must be between " + PlotInterval.MIN_VALUE + " and " + PlotInterval.MAX_VALUE + "." ), INTERVAL_UPPER_ENDPOINT_HAS_TOO_MANY_SIGNIFICANT_DIGITS ( "The upper endpoint of the interval must not have more than " + PlotInterval.MAX_NUM_SIGNIFICANT_DIGITS + " significant digits." ), INTERVAL_ENDPOINTS_OUT_OF_ORDER ( "The upper endpoint of the interval is less than or equal to the lower endpoint." ), TOO_MANY_FUNCTIONS ( "The document contains too many functions." ), INVALID_COLOUR ( "The colour is invalid." ), COLOUR_COMPONENT_OUT_OF_BOUNDS ( "Colour component values must be between 0 and 255." ), PNG_NOT_SUPPORTED ( "This implementation of Java does not support the writing of PNG files." ), CLIPBOARD_UNAVAILABLE ( "The clipboard is currently unavailable." ), NOT_ENOUGH_MEMORY_TO_PERFORM_COMMAND ( "There was not enough memory to perform the command.\n" + "Clearing the list of undo/redo actions may make more memory available." ); //////////////////////////////////////////////////////////////////// // 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//////////////////////////////////////////////////////////////////////// // EXTENDED FILE CLASS public static class FileEx { //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// public FileEx( File file, FileType fileType ) { this.file = file; this.fileType = fileType; } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance variables //////////////////////////////////////////////////////////////////// File file; FileType fileType; } //================================================================== // EDIT CLASS public static abstract class Edit { //////////////////////////////////////////////////////////////////// // Member classes : non-inner classes //////////////////////////////////////////////////////////////////// // ADD FUNCTION EDIT CLASS private static class Add extends Edit { //////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////// private Add( int index, Function function ) { this.index = index; this.function = (Function)function.clone( ); } //---------------------------------------------------------- //////////////////////////////////////////////////////////////// // Instance methods : overriding methods //////////////////////////////////////////////////////////////// public void undo( FunctionDocument document ) { document.getFunctionList( ).removeElement( index ); } //---------------------------------------------------------- public void redo( FunctionDocument document ) { document.getFunctionList( ).addElement( index, function ); } //---------------------------------------------------------- //////////////////////////////////////////////////////////////// // Instance variables //////////////////////////////////////////////////////////////// private int index; private Function function; } //============================================================== // REMOVE FUNCTION EDIT CLASS private static class Remove extends Edit { //////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////// private Remove( int index, Function function ) { this.index = index; this.function = (Function)function.clone( ); } //---------------------------------------------------------- //////////////////////////////////////////////////////////////// // Instance methods : overriding methods //////////////////////////////////////////////////////////////// public void undo( FunctionDocument document ) { document.getFunctionList( ).addElement( index, function ); } //---------------------------------------------------------- public void redo( FunctionDocument document ) { document.getFunctionList( ).removeElement( index ); } //---------------------------------------------------------- //////////////////////////////////////////////////////////////// // Instance variables //////////////////////////////////////////////////////////////// private int index; private Function function; } //============================================================== // X INTERVAL EDIT CLASS private static class XInterval extends Edit { //////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////// private XInterval( PlotInterval oldInterval, PlotInterval newInterval ) { this.oldInterval = new PlotInterval( oldInterval ); this.newInterval = new PlotInterval( newInterval ); timestamp = System.currentTimeMillis( ); } //---------------------------------------------------------- //////////////////////////////////////////////////////////////// // Instance methods : overriding methods //////////////////////////////////////////////////////////////// public void undo( FunctionDocument document ) { document.setXInterval( oldInterval ); } //---------------------------------------------------------- public void redo( FunctionDocument document ) { document.setXInterval( newInterval ); } //---------------------------------------------------------- //////////////////////////////////////////////////////////////// // Instance variables //////////////////////////////////////////////////////////////// private PlotInterval oldInterval; private PlotInterval newInterval; private long timestamp; } //============================================================== // Y INTERVAL EDIT CLASS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -