📄 operationdialog.java
字号:
/*====================================================================*\OperationDialog.javaOperation dialog box 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.ProgressView;import java.awt.Color;import java.awt.Dialog;import java.awt.Dimension;import java.awt.Event;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Insets;import java.awt.Point;import java.awt.Window;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.io.File;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JPanel;import javax.swing.JProgressBar;import javax.swing.KeyStroke;import javax.swing.SwingUtilities;import util.KeyAction;import util.TextFile;import util.TextUtilities;//----------------------------------------------------------------------// OPERATION DIALOG BOX CLASSclass OperationDialog extends JDialog implements ActionListener, ProgressView, TextFile.ProgressListener{////////////////////////////////////////////////////////////////////////// Constants//////////////////////////////////////////////////////////////////////// private static final int INFO_FIELD_WIDTH = 480; private static final int PROGRESS_BAR_WIDTH = INFO_FIELD_WIDTH; private static final int PROGRESS_BAR_HEIGHT = 14; private static final int PROGRESS_BAR_MAX_VALUE = 10000; // Commands private interface Command { String CLOSE = "close"; }////////////////////////////////////////////////////////////////////////// Member classes : non-inner classes//////////////////////////////////////////////////////////////////////// // INFO FIELD CLASS private static class InfoField extends JComponent { //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private InfoField( ) { AppFont.MAIN.setFont( this ); setPreferredSize( new Dimension( INFO_FIELD_WIDTH, getFontMetrics( getFont( ) ).getHeight( ) ) ); setOpaque( true ); } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : overriding methods //////////////////////////////////////////////////////////////////// protected void paintComponent( Graphics gr ) { // Draw background gr.setColor( getBackground( ) ); gr.fillRect( 0, 0, getWidth( ), getHeight( ) ); // Draw text if ( text != null ) { FontMetrics fontMetrics = gr.getFontMetrics( ); int x = getComponentOrientation( ).isLeftToRight( ) ? 0 : getWidth( ) - fontMetrics.stringWidth( text ); gr.setColor( Color.BLACK ); gr.drawString( text, x, fontMetrics.getAscent( ) ); } } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods //////////////////////////////////////////////////////////////////// public void setText( String text ) { if ( ((this.text == null) && (text != null)) || ((this.text != null) && !this.text.equals( text )) ) { this.text = text; repaint( ); } } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance variables //////////////////////////////////////////////////////////////////// private String text; } //==================================================================////////////////////////////////////////////////////////////////////////// Member classes : inner classes//////////////////////////////////////////////////////////////////////// // SET INFO CLASS private class DoSetInfo implements Runnable { //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private DoSetInfo( String str, File file ) { this.str = str; this.file = file; } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : Runnable interface //////////////////////////////////////////////////////////////////// public void run( ) { if ( file == null ) infoField.setText( str ); else { FontMetrics fontMetrics = infoField.getFontMetrics( infoField.getFont( ) ); int maxWidth = infoField.getWidth( ) - fontMetrics.stringWidth( str + " " ); String pathname = TextUtilities.getWidthLimitedPathname( App.getPathname( file ), fontMetrics, maxWidth, App.getFileSeparatorChar( ) ); infoField.setText( str + " " + pathname ); } } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance variables //////////////////////////////////////////////////////////////////// private String str; private File file; } //================================================================== // SET PROGRESS CLASS private class DoSetProgress implements Runnable { //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private DoSetProgress( double value ) { this.value = value; } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods : Runnable interface //////////////////////////////////////////////////////////////////// public void run( ) { if ( value < 0.0 ) progressBar.setIndeterminate( true ); else { if ( progressBar.isIndeterminate( ) ) progressBar.setIndeterminate( false ); progressBar.setValue( (int)Math.round( value * (double)PROGRESS_BAR_MAX_VALUE ) ); } } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance variables //////////////////////////////////////////////////////////////////// private double value; } //================================================================== // WINDOW EVENT HANDLER CLASS private class WindowEventHandler extends WindowAdapter { //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private WindowEventHandler( ) { } //-------------------------------------------------------------- //////////////////////////////////////////////////////////////////// // Instance methods ////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -