📄 preferencesdialog.java
字号:
/*====================================================================*\PreferencesDialog.javaPreferences 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 exception.FileException;import gui.BooleanComboBox;import gui.ColourSampleIcon;import gui.FontEx;import gui.GuiUtilities;import gui.IntegerSpinner;import gui.PathnamePanel;import gui.TitledBorder;import java.awt.Color;import java.awt.Dialog;import java.awt.Dimension;import java.awt.GraphicsEnvironment;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.JCheckBox;import javax.swing.JColorChooser;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JFileChooser;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTabbedPane;import javax.swing.KeyStroke;import javax.swing.UIManager;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import textfield.IntegerValueField;import util.IntegerRange;import util.KeyAction;//----------------------------------------------------------------------// PREFERENCES DIALOG BOX CLASSclass PreferencesDialog extends JDialog implements ActionListener, ChangeListener{////////////////////////////////////////////////////////////////////////// Constants//////////////////////////////////////////////////////////////////////// private enum Tab { GENERAL, APPEARANCE, PLOT, FUNCTION, FONTS } // Main panel private static final String TITLE_STR = "Preferences"; private static final String SAVE_CONFIGURATION_STR = "Save Configuration"; private static final String SAVE_CONFIG_FILE_STR = "Save Configuration File"; private static final String WRITE_CONFIG_FILE_STR = "Write Configuration File"; // General panel private static final String GENERAL_STR = "General"; private static final String DEFAULT_FILE_TYPE_STR = "Default file type:"; private static final String NEW_DOC_ON_STARTUP_STR = "New document on startup:"; private static final String SAVE_FUNCTION_COLOURS_STR = "Save function colours in document:"; private static final String SHOW_UNIX_PATHNAMES_STR = "Display UNIX-style pathnames:"; // Appearance panel private static final String APPEARANCE_STR = "Appearance"; private static final String LOOK_AND_FEEL_STR = "Look-and-feel:"; private static final String ORIENTATION_BY_LOCALE_STR = "Orientation by locale:"; private static final String BACKGROUND_COLOUR_STR = "Background colour:"; private static final String NO_LOOK_AND_FEELS_STR = "<no look-and-feels>"; // Plot panel private static final int PLOT_SIZE_FIELD_LENGTH = 4; private static final int NUM_FRACTION_DIGITS_FIELD_LENGTH = 2; private static final int FIXED_POINT_RANGE_FIELD_LENGTH = 3; private static final String PLOT_STR = "Plot"; private static final String PLOT_SIZE_STR = "Plot size:"; private static final String TIMES_STR = "\u00D7"; private static final String SHOW_GRID_STR = "Show grid:"; private static final String NUM_FRACTION_DIGITS_STR = "Maximum number of fraction digits:"; private static final String FIXED_POINT_EXPONENT_RANGE_STR = "Fixed-point exponent range:"; private static final String TO_STR = "to"; private static final String NORMALISE_SCI_NOTATION_STR = "Normalise scientific notation:"; private static final String PLOT_COLOURS_STR = "Plot colours"; private static final String FOCUSED_BORDER_STR = "Focused border:"; private static final String IMAGE_MARGIN_STR = "Image margin:"; private static final String BACKGROUND_STR = "Background:"; private static final String GRID_STR = "Grid:"; private static final String AXIS_STR = "Axis:"; private static final String SCALE_MARKINGS_STR = "Scale markings:"; private static final String BACKGROUND_COLOUR_TITLE_STR = "Select Background Colour"; private static final String PLOT_FOCUSED_BORDER_COLOUR_TITLE_STR = "Select Plot Focused Border Colour"; private static final String PLOT_IMAGE_MARGIN_COLOUR_TITLE_STR = "Select Plot Image Margin Colour"; private static final String PLOT_BACKGROUND_COLOUR_TITLE_STR = "Select Plot Background Colour"; private static final String PLOT_GRID_COLOUR_TITLE_STR = "Select Plot Grid Colour"; private static final String PLOT_AXIS_COLOUR_TITLE_STR = "Select Plot Axis Colour"; private static final String PLOT_SCALE_MARKINGS_COLOUR_TITLE_STR = "Select Plot Scale Markings Colour"; // Function panel private static final int LIST_WIDTH_FIELD_LENGTH = 2; private static final int LIST_HEIGHT_FIELD_LENGTH = 2; private static final int FUNCTION_COLOUR_ROWS = 2; private static final int FUNCTION_COLOUR_BUTTON_ICON_WIDTH = 20; private static final int FUNCTION_COLOUR_BUTTON_ICON_HEIGHT = 12; private static final Insets FUNCTION_COLOUR_BUTTON_MARGINS = new Insets( 1, 1, 1, 1 ); private static final String FUNCTION_STR = "Function"; private static final String DIRECTORY_STR = "Directory:"; private static final String LIST_SIZE_STR = "Function list size:"; private static final String COLUMNS_BY_ROWS_STR = "(columns " + TIMES_STR + " rows)"; private static final String FUNCTION_COLOURS_STR = "Default function colours"; private static final String FUNCTION_COLOUR_TITLE_STR = "Select Default Function Colour "; private static final String SELECT_STR = "Select"; private static final String SELECT_DIR_STR1 = "Select Directory"; private static final String SELECT_DIR_STR2 = "Select directory"; // Fonts panel private static final String FONTS_STR = "Fonts"; private static final String PT_STR = "pt"; private static final String FONT_LABEL_SUFFIX = " font:"; // Commands private interface Command { String ENABLE_BACKGROUND_COLOUR = "enableBackgroundColour"; String CHOOSE_BACKGROUND_COLOUR = "chooseBackgroundColour"; String CHOOSE_PLOT_FOCUSED_BORDER_COLOUR = "choosePlotFocusedBorderColour"; String CHOOSE_PLOT_IMAGE_MARGIN_COLOUR = "choosePlotImageMarginColour"; String CHOOSE_PLOT_BACKGROUND_COLOUR = "choosePlotBackgroundColour"; String CHOOSE_PLOT_GRID_COLOUR = "choosePlotGridColour"; String CHOOSE_PLOT_AXIS_COLOUR = "choosePlotAxisColour"; String CHOOSE_PLOT_SCALE_COLOUR = "choosePlotScaleColour"; String CHOOSE_FUNCTION_DIRECTORY = "chooseFunctionDirectory"; String CHOOSE_FUNCTION_COLOUR = "chooseFunctionColour."; String SAVE_CONFIGURATION = "saveConfiguration"; String ACCEPT = "accept"; String CLOSE = "close"; }////////////////////////////////////////////////////////////////////////// Enumeration types//////////////////////////////////////////////////////////////////////// // ERROR IDENTIFIERS private enum ErrorId implements AppException.Id { //////////////////////////////////////////////////////////////////// // Constants //////////////////////////////////////////////////////////////////// DIRECTORY_DOES_NOT_EXIST ( "The specified directory does not exist." ), NOT_A_DIRECTORY ( "The pathname does not specify a directory." ), DIRECTORY_ACCESS_NOT_PERMITTED ( "Access to the directory was not permitted." ), FIXED_POINT_LIMITS_OUT_OF_ORDER ( "The upper limit of the fixed-point exponent range is less than the lower limit." ); //////////////////////////////////////////////////////////////////// // 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//////////////////////////////////////////////////////////////////////// // PLOT COLOUR BUTTON CLASS private static class PlotColourButton extends JButton { //////////////////////////////////////////////////////////////////// // Constants //////////////////////////////////////////////////////////////////// private static final int ICON_WIDTH = 40; private static final int ICON_HEIGHT = 16; private static final Insets MARGINS = new Insets( 2, 2, 2, 2 ); //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private PlotColourButton( Color colour ) { super( new ColourSampleIcon( ICON_WIDTH, ICON_HEIGHT ) ); setMargin( MARGINS ); setForeground( colour ); } //-------------------------------------------------------------- } //================================================================== // COLOUR BUTTON PANEL CLASS private static class ColourButtonPanel extends JPanel { //////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////// private ColourButtonPanel( int index, JButton button ) { GridBagLayout gridBag = new GridBagLayout( ); GridBagConstraints gbc = new GridBagConstraints( ); setLayout( gridBag ); JLabel label = new FLabel( Integer.toString( index ) ); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.LINE_END; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets( 0, 0, 0, 4 ); gridBag.setConstraints( label, gbc ); add( label ); gbc.gridx = 1; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.LINE_START; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets( 0, 0, 0, 0 ); gridBag.setConstraints( button, gbc ); add( button ); } //-------------------------------------------------------------- } //================================================================== // FONT PANEL CLASS private static class FontPanel { //////////////////////////////////////////////////////////////////// // Constants //////////////////////////////////////////////////////////////////// private static final int MIN_SIZE = 0; private static final int MAX_SIZE = 99; private static final int SIZE_FIELD_LENGTH = 2; private static final String DEFAULT_FONT_STR = "<default font>";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -