📄 preferencesdialog.java
字号:
private void validatePreferences( ) throws AppException { validatePreferencesGeneral( ); validatePreferencesAppearance( ); validatePreferencesPlot( ); validatePreferencesFunction( ); validatePreferencesFonts( ); } //------------------------------------------------------------------ private void setPreferences( ) { setPreferencesGeneral( ); setPreferencesAppearance( ); setPreferencesPlot( ); setPreferencesFunction( ); setPreferencesFonts( ); } //------------------------------------------------------------------ private void doEnableBackgroundColour( ) { backgroundColourButton.setEnabled( backgroundColourCheckBox.isSelected( ) ); } //------------------------------------------------------------------ private void doChooseBackgroundColour( ) { Color colour = JColorChooser.showDialog( this, BACKGROUND_COLOUR_TITLE_STR, backgroundColourButton.getForeground( ) ); if ( colour != null ) backgroundColourButton.setForeground( colour ); } //------------------------------------------------------------------ private void doChoosePlotFocusedBorderColour( ) { Color colour = JColorChooser.showDialog( this, PLOT_FOCUSED_BORDER_COLOUR_TITLE_STR, plotFocusedBorderColourButton.getForeground( ) ); if ( colour != null ) plotFocusedBorderColourButton.setForeground( colour ); } //------------------------------------------------------------------ private void doChoosePlotImageMarginColour( ) { Color colour = JColorChooser.showDialog( this, PLOT_IMAGE_MARGIN_COLOUR_TITLE_STR, plotImageMarginColourButton.getForeground( ) ); if ( colour != null ) plotImageMarginColourButton.setForeground( colour ); } //------------------------------------------------------------------ private void doChoosePlotBackgroundColour( ) { Color colour = JColorChooser.showDialog( this, PLOT_BACKGROUND_COLOUR_TITLE_STR, plotBackgroundColourButton.getForeground( ) ); if ( colour != null ) plotBackgroundColourButton.setForeground( colour ); } //------------------------------------------------------------------ private void doChoosePlotGridColour( ) { Color colour = JColorChooser.showDialog( this, PLOT_GRID_COLOUR_TITLE_STR, plotGridColourButton.getForeground( ) ); if ( colour != null ) plotGridColourButton.setForeground( colour ); } //------------------------------------------------------------------ private void doChoosePlotAxisColour( ) { Color colour = JColorChooser.showDialog( this, PLOT_AXIS_COLOUR_TITLE_STR, plotAxisColourButton.getForeground( ) ); if ( colour != null ) plotAxisColourButton.setForeground( colour ); } //------------------------------------------------------------------ private void doChoosePlotScaleColour( ) { Color colour = JColorChooser.showDialog( this, PLOT_SCALE_MARKINGS_COLOUR_TITLE_STR, plotScaleMarkingsColourButton.getForeground( ) ); if ( colour != null ) plotScaleMarkingsColourButton.setForeground( colour ); } //------------------------------------------------------------------ private void doChooseFunctionDirectory( ) { if ( directoryFileChooser == null ) { directoryFileChooser = new JFileChooser( ); directoryFileChooser.setDialogTitle( SELECT_DIR_STR1 ); directoryFileChooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY ); directoryFileChooser.setApproveButtonMnemonic( KeyEvent.VK_S ); directoryFileChooser.setApproveButtonToolTipText( SELECT_DIR_STR2 ); App.applyOrientationByLocale( directoryFileChooser ); } directoryFileChooser.setCurrentDirectory( directoryField.getCanonicalFile( ) ); directoryFileChooser.rescanCurrentDirectory( ); if ( directoryFileChooser.showDialog( this, SELECT_STR ) == JFileChooser.APPROVE_OPTION ) directoryField.setFile( directoryFileChooser.getSelectedFile( ), AppConfig.getInstance( ).isShowUnixPathnames( ) ); } //------------------------------------------------------------------ private void doChooseFunctionColour( String str ) { int index = Integer.parseInt( str ); Color colour = JColorChooser.showDialog( this, FUNCTION_COLOUR_TITLE_STR + (index + 1), functionColourButtons[index].getForeground( ) ); if ( colour != null ) functionColourButtons[index].setForeground( colour ); } //------------------------------------------------------------------ private void doSaveConfiguration( ) { try { validatePreferences( ); File file = AppConfig.getInstance( ).chooseFile( ); if ( file != null ) { if ( !file.exists( ) || (JOptionPane.showOptionDialog( this, App.getPathname( file ) + AppConstants.ALREADY_EXISTS_STR, SAVE_CONFIG_FILE_STR, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, AppConstants.RC_OPTION_STRS, AppConstants.RC_OPTION_STRS[1] ) == JOptionPane.OK_OPTION) ) { setPreferences( ); accepted = true; OperationDialog.showDialog( this, WRITE_CONFIG_FILE_STR, new Operation.WriteConfig( file ) ); } } } catch ( AppException e ) { JOptionPane.showMessageDialog( this, e, App.SHORT_NAME, JOptionPane.ERROR_MESSAGE ); } if ( accepted ) doClose( ); } //------------------------------------------------------------------ private void doAccept( ) { try { validatePreferences( ); setPreferences( ); accepted = true; doClose( ); } catch ( AppException e ) { JOptionPane.showMessageDialog( this, e, App.SHORT_NAME, JOptionPane.ERROR_MESSAGE ); } } //------------------------------------------------------------------ private void doClose( ) { location = getLocation( ); setVisible( false ); dispose( ); } //------------------------------------------------------------------ private JPanel getPanelGeneral( ) { //---- Control panel GridBagLayout gridBag = new GridBagLayout( ); GridBagConstraints gbc = new GridBagConstraints( ); JPanel controlPanel = new JPanel( gridBag ); GuiUtilities.setPaddedLineBorder( controlPanel ); int gridY = 0; AppConfig config = AppConfig.getInstance( ); // Label: default file type JLabel defaultFileTypeLabel = new FLabel( DEFAULT_FILE_TYPE_STR ); gbc.gridx = 0; gbc.gridy = gridY; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.LINE_END; gbc.fill = GridBagConstraints.NONE; gbc.insets = AppConstants.COMPONENT_INSETS; gridBag.setConstraints( defaultFileTypeLabel, gbc ); controlPanel.add( defaultFileTypeLabel ); // Combo box: default file type defaultFileTypeComboBox = new FComboBox( FileType.values( ) ); defaultFileTypeComboBox.setSelectedItem( config.getDefaultFileType( ) ); gbc.gridx = 1; gbc.gridy = gridY++; 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 = AppConstants.COMPONENT_INSETS; gridBag.setConstraints( defaultFileTypeComboBox, gbc ); controlPanel.add( defaultFileTypeComboBox ); // Label: new document on startup JLabel newDocOnStartupLabel = new FLabel( NEW_DOC_ON_STARTUP_STR ); gbc.gridx = 0; gbc.gridy = gridY; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.LINE_END; gbc.fill = GridBagConstraints.NONE; gbc.insets = AppConstants.COMPONENT_INSETS; gridBag.setConstraints( newDocOnStartupLabel, gbc ); controlPanel.add( newDocOnStartupLabel ); // Combo box: new document on startup newDocOnStartupComboBox = new BooleanComboBox( config.isNewDocumentOnStartup( ) ); gbc.gridx = 1; gbc.gridy = gridY++; 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 = AppConstants.COMPONENT_INSETS; gridBag.setConstraints( newDocOnStartupComboBox, gbc ); controlPanel.add( newDocOnStartupComboBox ); // Label: save function colours JLabel saveFunctionColoursLabel = new FLabel( SAVE_FUNCTION_COLOURS_STR ); gbc.gridx = 0; gbc.gridy = gridY; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.LINE_END; gbc.fill = GridBagConstraints.NONE; gbc.insets = AppConstants.COMPONENT_INSETS; gridBag.setConstraints( saveFunctionColoursLabel, gbc ); controlPanel.add( saveFunctionColoursLabel ); // Combo box: save function colours saveFunctionColoursComboBox = new FComboBox( AppConfig.NoYesAsk.values( ) ); saveFunctionColoursComboBox.setSelectedItem( config.getSaveFunctionColours( ) ); gbc.gridx = 1; gbc.gridy = gridY++; 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 = AppConstants.COMPONENT_INSETS; gridBag.setConstraints( saveFunctionColoursComboBox, gbc ); controlPanel.add( saveFunctionColoursComboBox ); // Label: show UNIX pathnames JLabel showUnixPathnamesLabel = new FLabel( SHOW_UNIX_PATHNAMES_STR ); gbc.gridx = 0; gbc.gridy = gridY; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.LINE_END; gbc.fill = GridBagConstraints.NONE; gbc.insets = AppConstants.COMPONENT_INSETS; gridBag.setConstraints( showUnixPathnamesLabel, gbc ); controlPanel.add( showUnixPathnamesLabel ); // Combo box: show UNIX pathnames showUnixPathnamesComboBox = new BooleanComboBox( config.isShowUnixPathnames( ) ); gbc.gridx = 1; gbc.gridy = gridY++; 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 = AppConstants.COMPONENT_INSETS; gridBag.setConstraints( showUnixPathnamesComboBox, gbc ); controlPanel.add( showUnixPathnamesComboBox ); //---- Outer panel JPanel outerPanel = new JPanel( gridBag ); outerPanel.setBorder( BorderFactory.createEmptyBorder( 2, 2, 2, 2 ) ); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets( 0, 0, 0, 0 ); gridBag.setConstraints( controlPanel, gbc ); outerPanel.add( controlPanel ); return outerPanel; } //------------------------------------------------------------------ private JPanel getPanelAppearance( ) { //---- Control panel GridBagLayout gridBag = new GridBagLayout( ); GridBagConstraints gbc = new GridBagConstraints( ); JPanel controlPanel = new JPanel( gridBag ); GuiUtilities.setPaddedLineBorder( controlPanel );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -