KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bluej > editor > moe > EditorPrefPanel


1 // Copyright (c) 2000, 2005 BlueJ Group, Deakin University
2
//
3
// This software is made available under the terms of the "MIT License"
4
// A copy of this license is included with this source distribution
5
// in "license.txt" and is also available at:
6
// http://www.opensource.org/licenses/mit-license.html
7
// Any queries should be directed to Michael Kolling mik@bluej.org
8

9 package bluej.editor.moe;
10
11 import javax.swing.*;
12 import java.awt.*;
13
14 import bluej.Config;
15 import bluej.BlueJTheme;
16 import bluej.editor.EditorManager;
17 import bluej.prefmgr.*;
18
19 /**
20  * A PrefPanel subclass to allow the user to interactively edit
21  * editor settings
22  *
23  * @author Michael Kolling
24  * @version $Id: EditorPrefPanel.java,v 1.5 2005/05/02 03:23:32 davmac Exp $
25  */

26 public class EditorPrefPanel extends JPanel implements PrefPanelListener
27 {
28     private JTextField editorFontField;
29     private JCheckBox hilightingBox;
30     private JCheckBox autoIndentBox;
31     private JCheckBox lineNumbersBox;
32     private JCheckBox makeBackupBox;
33     private JCheckBox showTestBox;
34     private JCheckBox matchBracketsBox;
35
36     /**
37      * Setup the UI for the dialog and event handlers for the buttons.
38      */

39     public EditorPrefPanel()
40     {
41         setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
42         setBorder(BlueJTheme.generalBorder);
43
44 // add(Box.createVerticalGlue());
45

46         JPanel editorPanel = new JPanel(new GridLayout(4,2,0,0));
47         {
48             String JavaDoc editorTitle = Config.getString("prefmgr.edit.editor.title");
49             editorPanel.setBorder(BorderFactory.createCompoundBorder(
50                                         BorderFactory.createTitledBorder(editorTitle),
51                                         BlueJTheme.generalBorder));
52             editorPanel.setAlignmentX(LEFT_ALIGNMENT);
53
54             JPanel fontPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
55             {
56                 fontPanel.add(new JLabel(Config.getString("prefmgr.edit.editorfontsize")));
57                 editorFontField = new JTextField(4);
58                 fontPanel.add(editorFontField);
59             }
60             editorPanel.add(fontPanel);
61             editorPanel.add(new JLabel(" "));
62             autoIndentBox = new JCheckBox(Config.getString("prefmgr.edit.autoindent"));
63             editorPanel.add(autoIndentBox);
64             lineNumbersBox = new JCheckBox(Config.getString("prefmgr.edit.displaylinenumbers"));
65             editorPanel.add(lineNumbersBox);
66             hilightingBox = new JCheckBox(Config.getString("prefmgr.edit.usesyntaxhilighting"));
67             editorPanel.add(hilightingBox);
68             makeBackupBox = new JCheckBox(Config.getString("prefmgr.edit.makeBackup"));
69             editorPanel.add(makeBackupBox);
70             matchBracketsBox= new JCheckBox(Config.getString("prefmgr.edit.matchBrackets"));
71             editorPanel.add(matchBracketsBox);
72         }
73         add(editorPanel);
74
75         add(Box.createVerticalStrut(BlueJTheme.generalSpacingWidth));
76
77         add(Box.createVerticalGlue());
78         add(Box.createVerticalGlue());
79         add(Box.createVerticalGlue());
80     }
81
82     public void beginEditing()
83     {
84         editorFontField.setText(String.valueOf(PrefMgr.getEditorFontSize()));
85         hilightingBox.setSelected(PrefMgr.getFlag(PrefMgr.HILIGHTING));
86         autoIndentBox.setSelected(PrefMgr.getFlag(PrefMgr.AUTO_INDENT));
87         lineNumbersBox.setSelected(PrefMgr.getFlag(PrefMgr.LINENUMBERS));
88         makeBackupBox.setSelected(PrefMgr.getFlag(PrefMgr.MAKE_BACKUP));
89         matchBracketsBox.setSelected(PrefMgr.getFlag(PrefMgr.MATCH_BRACKETS));
90     }
91
92     public void revertEditing()
93     {
94     }
95
96     public void commitEditing()
97     {
98         int newFontSize = 0;
99
100         try {
101             newFontSize = Integer.parseInt(editorFontField.getText());
102             PrefMgr.setEditorFontSize(newFontSize);
103         }
104         catch (NumberFormatException JavaDoc nfe) { }
105
106         PrefMgr.setFlag(PrefMgr.HILIGHTING, hilightingBox.isSelected());
107         PrefMgr.setFlag(PrefMgr.AUTO_INDENT, autoIndentBox.isSelected());
108         PrefMgr.setFlag(PrefMgr.LINENUMBERS, lineNumbersBox.isSelected());
109         PrefMgr.setFlag(PrefMgr.MAKE_BACKUP, makeBackupBox.isSelected());
110         PrefMgr.setFlag(PrefMgr.MATCH_BRACKETS, matchBracketsBox.isSelected());
111
112         EditorManager.getEditorManager().refreshAll();
113     }
114 }
115
Popular Tags