?? mainwindow.java
字號:
/*====================================================================*\MainWindow.javaMain window 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 gui.GuiUtilities;import gui.TabbedPanel;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.Transferable;import java.awt.datatransfer.UnsupportedFlavorException;import java.awt.event.ActionEvent;import java.awt.event.KeyEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.event.WindowFocusListener;import java.io.File;import java.io.IOException;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.BorderFactory;import javax.swing.JCheckBoxMenuItem;import javax.swing.JComponent;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.TransferHandler;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.swing.event.MenuEvent;import javax.swing.event.MenuListener;import util.DataImporter;//----------------------------------------------------------------------// MAIN WINDOW CLASSclass MainWindow extends JFrame implements ChangeListener, MenuListener, WindowFocusListener{////////////////////////////////////////////////////////////////////////// Constants//////////////////////////////////////////////////////////////////////// private static final String FILE_STR = "File"; private static final String EDIT_STR = "Edit"; private static final String OPTIONS_STR = "Options";////////////////////////////////////////////////////////////////////////// Enumeration types//////////////////////////////////////////////////////////////////////// // ERROR IDENTIFIERS private enum ErrorId implements AppException.Id { //////////////////////////////////////////////////////////////////// // Constants //////////////////////////////////////////////////////////////////// FILE_TRANSFER_NOT_SUPPORTED ( "The file transfer operation is not supported." ), ERROR_TRANSFERRING_DATA ( "An error occurred while transferring data." ); //////////////////////////////////////////////////////////////////// // 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//////////////////////////////////////////////////////////////////////// // CLOSE ACTION CLASS private static class CloseAction extends AbstractAction { //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private CloseAction( ) { putValue( Action.ACTION_COMMAND_KEY, new String( ) ); } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : ActionListener interface //////////////////////////////////////////////////////////////////// public void actionPerformed( ActionEvent event ) { App.getInstance( ).closeDocument( Integer.parseInt( event.getActionCommand( ) ) ); } //-------------------------------------------------------------- } //================================================================== // WINDOW EVENT HANDLER CLASS private static class WindowEventHandler extends WindowAdapter { //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private WindowEventHandler( ) { } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : overriding methods //////////////////////////////////////////////////////////////////// public void windowClosing( WindowEvent event ) { AppCommand.EXIT.execute( ); } //-------------------------------------------------------------- } //==================================================================////////////////////////////////////////////////////////////////////////// Member classes : inner classes//////////////////////////////////////////////////////////////////////// // FILE TRANSFER HANDLER CLASS private class FileTransferHandler extends TransferHandler { //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// public FileTransferHandler( ) { } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : overriding methods //////////////////////////////////////////////////////////////////// public boolean canImport( JComponent component, DataFlavor[] flavours ) { return DataImporter.isFileList( flavours ); } //-------------------------------------------------------------- public boolean importData( JComponent component, Transferable transferable ) { if ( canImport( component, transferable.getTransferDataFlavors( ) ) ) { try { try { File[] files = DataImporter.getFiles( transferable ); if ( files != null ) { toFront( ); AppCommand.TRANSFER_FILES.putValue( AppCommand.Property.FILES, files ); AppCommand.TRANSFER_FILES.execute( ); return true; } } catch ( UnsupportedFlavorException e ) { throw new AppException( ErrorId.FILE_TRANSFER_NOT_SUPPORTED ); } catch ( IOException e ) { throw new AppException( ErrorId.ERROR_TRANSFERRING_DATA ); } } catch ( AppException e ) { App.getInstance( ).showErrorMessage( App.SHORT_NAME, e ); } } return false; } //-------------------------------------------------------------- } //==================================================================////////////////////////////////////////////////////////////////////////// Constructors//////////////////////////////////////////////////////////////////////// public MainWindow( ) { // Set icons setIconImages( AppIcon.getAppIconImages( ) ); //---- Menu bar JMenuBar menuBar = new JMenuBar( ); menuBar.setBorder( BorderFactory.createEmptyBorder( ) ); // File menu fileMenu = new JMenu( FILE_STR ); fileMenu.setMnemonic( KeyEvent.VK_F ); fileMenu.addMenuListener( this ); JMenuItem menuItem = fileMenu.add( AppCommand.NEW_FILE ); menuItem.setMnemonic( KeyEvent.VK_N ); menuItem = fileMenu.add( AppCommand.OPEN_FILE ); menuItem.setMnemonic( KeyEvent.VK_O ); menuItem = fileMenu.add( AppCommand.REOPEN_FILE ); menuItem.setMnemonic( KeyEvent.VK_R ); menuItem = fileMenu.add( AppCommand.CLOSE_FILE ); menuItem.setMnemonic( KeyEvent.VK_C ); menuItem = fileMenu.add( AppCommand.CLOSE_ALL_FILES ); menuItem.setMnemonic( KeyEvent.VK_L ); fileMenu.addSeparator( ); menuItem = fileMenu.add( AppCommand.SAVE_FILE ); menuItem.setMnemonic( KeyEvent.VK_S ); menuItem = fileMenu.add( AppCommand.SAVE_FILE_AS ); menuItem.setMnemonic( KeyEvent.VK_A ); fileMenu.addSeparator( ); menuItem = fileMenu.add( AppCommand.EXPORT_IMAGE ); menuItem.setMnemonic( KeyEvent.VK_E ); fileMenu.addSeparator( ); menuItem = fileMenu.add( AppCommand.EXIT ); menuItem.setMnemonic( KeyEvent.VK_X ); menuBar.add( fileMenu ); // Edit menu editMenu = new JMenu( EDIT_STR ); editMenu.setMnemonic( KeyEvent.VK_E ); editMenu.addMenuListener( this );
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -