001: // Copyright (c) 2000, 2005, 2007 BlueJ Group, Deakin University
002: //
003: // This software is made available under the terms of the "MIT License"
004: // A copy of this license is included with this source distribution
005: // in "license.txt" and is also available at:
006: // http://www.opensource.org/licenses/mit-license.html
007: // Any queries should be directed to Michael Kolling mik@bluej.org
008:
009: package bluej.editor.moe;
010:
011: import java.awt.FlowLayout;
012: import java.awt.GridLayout;
013:
014: import javax.swing.*;
015:
016: import bluej.BlueJTheme;
017: import bluej.Config;
018: import bluej.prefmgr.PrefMgr;
019: import bluej.prefmgr.PrefPanelListener;
020:
021: /**
022: * A PrefPanel subclass to allow the user to interactively edit
023: * editor settings
024: *
025: * @author Michael Kolling
026: * @version $Id: EditorPrefPanel.java 5306 2007-10-05 05:34:10Z davmac $
027: */
028: public class EditorPrefPanel extends JPanel implements
029: PrefPanelListener {
030: private JTextField editorFontField;
031: private JCheckBox hilightingBox;
032: private JCheckBox autoIndentBox;
033: private JCheckBox lineNumbersBox;
034: private JCheckBox makeBackupBox;
035: private JCheckBox matchBracketsBox;
036:
037: /**
038: * Setup the UI for the dialog and event handlers for the buttons.
039: */
040: public EditorPrefPanel() {
041: setLayout(new BoxLayout(this , BoxLayout.Y_AXIS));
042: setBorder(BlueJTheme.generalBorder);
043:
044: // add(Box.createVerticalGlue());
045:
046: JPanel editorPanel = new JPanel(new GridLayout(4, 2, 0, 0));
047: {
048: String editorTitle = Config
049: .getString("prefmgr.edit.editor.title");
050: editorPanel.setBorder(BorderFactory.createCompoundBorder(
051: BorderFactory.createTitledBorder(editorTitle),
052: BlueJTheme.generalBorder));
053: editorPanel.setAlignmentX(LEFT_ALIGNMENT);
054:
055: JPanel fontPanel = new JPanel(new FlowLayout(
056: FlowLayout.LEFT, 5, 0));
057: {
058: fontPanel.add(new JLabel(Config
059: .getString("prefmgr.edit.editorfontsize")));
060: editorFontField = new JTextField(4);
061: fontPanel.add(editorFontField);
062: }
063: editorPanel.add(fontPanel);
064: editorPanel.add(new JLabel(" "));
065: autoIndentBox = new JCheckBox(Config
066: .getString("prefmgr.edit.autoindent"));
067: editorPanel.add(autoIndentBox);
068: lineNumbersBox = new JCheckBox(Config
069: .getString("prefmgr.edit.displaylinenumbers"));
070: editorPanel.add(lineNumbersBox);
071: hilightingBox = new JCheckBox(Config
072: .getString("prefmgr.edit.usesyntaxhilighting"));
073: editorPanel.add(hilightingBox);
074: makeBackupBox = new JCheckBox(Config
075: .getString("prefmgr.edit.makeBackup"));
076: editorPanel.add(makeBackupBox);
077: matchBracketsBox = new JCheckBox(Config
078: .getString("prefmgr.edit.matchBrackets"));
079: editorPanel.add(matchBracketsBox);
080: }
081: add(editorPanel);
082:
083: add(Box.createVerticalStrut(BlueJTheme.generalSpacingWidth));
084:
085: add(Box.createVerticalGlue());
086: add(Box.createVerticalGlue());
087: add(Box.createVerticalGlue());
088: }
089:
090: public void beginEditing() {
091: editorFontField.setText(String.valueOf(PrefMgr
092: .getEditorFontSize()));
093: hilightingBox.setSelected(PrefMgr.getFlag(PrefMgr.HILIGHTING));
094: autoIndentBox.setSelected(PrefMgr.getFlag(PrefMgr.AUTO_INDENT));
095: lineNumbersBox
096: .setSelected(PrefMgr.getFlag(PrefMgr.LINENUMBERS));
097: makeBackupBox.setSelected(PrefMgr.getFlag(PrefMgr.MAKE_BACKUP));
098: matchBracketsBox.setSelected(PrefMgr
099: .getFlag(PrefMgr.MATCH_BRACKETS));
100: }
101:
102: public void revertEditing() {
103: }
104:
105: public void commitEditing() {
106: int newFontSize = 0;
107:
108: try {
109: newFontSize = Integer.parseInt(editorFontField.getText());
110: PrefMgr.setEditorFontSize(newFontSize);
111: } catch (NumberFormatException nfe) {
112: }
113:
114: PrefMgr.setFlag(PrefMgr.HILIGHTING, hilightingBox.isSelected());
115: PrefMgr
116: .setFlag(PrefMgr.AUTO_INDENT, autoIndentBox
117: .isSelected());
118: PrefMgr.setFlag(PrefMgr.LINENUMBERS, lineNumbersBox
119: .isSelected());
120: PrefMgr
121: .setFlag(PrefMgr.MAKE_BACKUP, makeBackupBox
122: .isSelected());
123: PrefMgr.setFlag(PrefMgr.MATCH_BRACKETS, matchBracketsBox
124: .isSelected());
125: }
126: }
|