|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
PrefsDialog.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
* SimplyHTML, a word processor based on Java, HTML and CSS
|
|
3 |
* Copyright (C) 2002 Ulrich Hilger
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or
|
|
6 |
* modify it under the terms of the GNU General Public License
|
|
7 |
* as published by the Free Software Foundation; either version 2
|
|
8 |
* of the License, or (at your option) any later version.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
18 |
*/
|
|
19 |
|
|
20 |
import javax.swing.*;
|
|
21 |
import java.awt.*;
|
|
22 |
import javax.swing.border.*;
|
|
23 |
import java.awt.event.*;
|
|
24 |
import java.util.prefs.*;
|
|
25 |
|
|
26 |
/**
|
|
27 |
* Dialog to set user preferences for application SimplyHTML.
|
|
28 |
*
|
|
29 |
* @author Ulrich Hilger
|
|
30 |
* @author Light Development
|
|
31 |
* @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
|
|
32 |
* @author <a href="mailto:info@lightdev.com">info@lightdev.com</a>
|
|
33 |
* @author published under the terms and conditions of the
|
|
34 |
* GNU General Public License,
|
|
35 |
* for details see file gpl.txt in the distribution
|
|
36 |
* package of this software
|
|
37 |
*
|
|
38 |
* @version stage 11, April 27, 2003
|
|
39 |
*/
|
|
40 |
|
|
41 |
public class PrefsDialog extends DialogShell implements ActionListener { |
|
42 |
|
|
43 |
/** the look and feels avaliable in the system */
|
|
44 |
private UIManager.LookAndFeelInfo[] lfinfo;
|
|
45 |
|
|
46 |
/** reference for user preferences for this class */
|
|
47 |
protected Preferences prefs = Preferences.userNodeForPackage( getClass() );
|
|
48 |
|
|
49 |
/** constant for dock location setting in preferences file */
|
|
50 |
public static final String PREFSID_LOOK_AND_FEEL = "Laf"; |
|
51 |
public static final String PREFSID_WRITE_MODE = "writeMode"; |
|
52 |
|
|
53 |
public static final String PREFS_WRITE_MODE_HTML32 = "html32"; |
|
54 |
public static final String PREFS_WRITE_MODE_HTML4 = "html4"; |
|
55 |
public static final String PREFS_USE_STD_STYLE_SHEET = "useStdStyles"; |
|
56 |
|
|
57 |
|
|
58 |
private String lafName = UIManager.getLookAndFeel().getName();
|
|
59 |
|
|
60 |
private JComboBox lafCombo;
|
|
61 |
JRadioButton saveHTML32; |
|
62 |
JRadioButton saveHTML4; |
|
63 |
JCheckBox useStdStyleSheet; |
|
64 |
|
|
65 |
/** the help id for this dialog */
|
|
66 |
private static final String helpTopicId = "item167"; |
|
67 |
|
|
68 | 0 |
public PrefsDialog(Frame parent, String title) {
|
69 | 0 |
super(parent, title, helpTopicId);
|
70 |
|
|
71 |
// have a grid bag layout ready to use
|
|
72 | 0 |
GridBagLayout g = new GridBagLayout();
|
73 | 0 |
GridBagConstraints c = new GridBagConstraints();
|
74 |
|
|
75 | 0 |
JPanel layoutPanel = new JPanel(g);
|
76 |
|
|
77 |
// build a panel for preferences related to the application
|
|
78 | 0 |
JPanel appPrefsPanel = new JPanel(g);
|
79 | 0 |
Util.addGridBagComponent( |
80 |
appPrefsPanel, |
|
81 |
new JLabel(
|
|
82 |
FrmMain.dynRes.getResourceString( |
|
83 |
FrmMain.resources, "prfLafLabel")),
|
|
84 |
g, c, 0, 0, GridBagConstraints.EAST); |
|
85 | 0 |
lafCombo = new JComboBox();
|
86 | 0 |
initLfComboBox(); |
87 | 0 |
Util.addGridBagComponent( |
88 |
appPrefsPanel, |
|
89 |
lafCombo, |
|
90 |
g, c, 1, 0, GridBagConstraints.EAST); |
|
91 |
|
|
92 |
// build a panel for preferences related to documents
|
|
93 |
/*
|
|
94 |
JPanel docPrefsPanel = new JPanel(g);
|
|
95 |
Util.addGridBagComponent(docPrefsPanel,
|
|
96 |
new JCheckBox(
|
|
97 |
FrmMain.dynRes.getResourceString(
|
|
98 |
FrmMain.resources, "prfShareDocResourcesLabel")),
|
|
99 |
g, c, 0, 1,
|
|
100 |
GridBagConstraints.EAST);
|
|
101 |
*/
|
|
102 |
|
|
103 |
// build panel for writing mode
|
|
104 | 0 |
JPanel writeModePnl = new JPanel(g);
|
105 | 0 |
writeModePnl.setBorder(new TitledBorder(new EtchedBorder( |
106 |
EtchedBorder.LOWERED), |
|
107 |
FrmMain.dynRes.getResourceString( |
|
108 |
FrmMain.resources, "prfWriteModeLabel")));
|
|
109 | 0 |
saveHTML32 = new JRadioButton(FrmMain.dynRes.getResourceString(
|
110 |
FrmMain.resources, "prfWriteModeHTML32Label"));
|
|
111 | 0 |
saveHTML4 = new JRadioButton(FrmMain.dynRes.getResourceString(
|
112 |
FrmMain.resources, "prfWriteModeHTML4Label"));
|
|
113 | 0 |
ButtonGroup bg = new ButtonGroup();
|
114 | 0 |
bg.add(saveHTML32); |
115 | 0 |
bg.add(saveHTML4); |
116 | 0 |
Util.addGridBagComponent(writeModePnl, saveHTML32, g, c, 0, 0, GridBagConstraints.WEST); |
117 | 0 |
Util.addGridBagComponent(writeModePnl, saveHTML4, g, c, 0, 1, GridBagConstraints.WEST); |
118 | 0 |
String writeMode = prefs.get(PrefsDialog.PREFSID_WRITE_MODE, PrefsDialog.PREFS_WRITE_MODE_HTML32); |
119 | 0 |
if(writeMode.equalsIgnoreCase(PrefsDialog.PREFS_WRITE_MODE_HTML32)) {
|
120 | 0 |
saveHTML32.setSelected(true);
|
121 |
} |
|
122 |
else {
|
|
123 | 0 |
saveHTML4.setSelected(true);
|
124 |
} |
|
125 |
|
|
126 | 0 |
Util.addGridBagComponent(layoutPanel, appPrefsPanel, g, c, 0, 0, GridBagConstraints.WEST); |
127 |
//Util.addGridBagComponent(layoutPanel, docPrefsPanel, g, c, 0, 1, GridBagConstraints.WEST);
|
|
128 | 0 |
Util.addGridBagComponent(layoutPanel, writeModePnl, g, c, 0, 1, GridBagConstraints.WEST); |
129 |
|
|
130 |
// add option for standard stlye sheet
|
|
131 | 0 |
useStdStyleSheet = new JCheckBox(FrmMain.dynRes.getResourceString(
|
132 |
FrmMain.resources, "linkDefaultStyleSheetLabel"));
|
|
133 | 0 |
boolean useStyle = prefs.getBoolean(PrefsDialog.PREFS_USE_STD_STYLE_SHEET, false); |
134 | 0 |
useStdStyleSheet.setSelected(useStyle); |
135 | 0 |
Util.addGridBagComponent(layoutPanel, useStdStyleSheet, g, c, 0, 2, GridBagConstraints.WEST); |
136 |
|
|
137 |
// add to content pane of DialogShell
|
|
138 | 0 |
Container contentPane = super.getContentPane();
|
139 | 0 |
contentPane.add(layoutPanel, BorderLayout.CENTER); |
140 |
//contentPane.add(appPrefsPanel, BorderLayout.NORTH);
|
|
141 |
//contentPane.add(docPrefsPanel, BorderLayout.CENTER);
|
|
142 |
|
|
143 |
// cause optimal placement of all elements
|
|
144 | 0 |
pack(); |
145 |
} |
|
146 |
|
|
147 | 0 |
private void initLfComboBox() { |
148 | 0 |
lfinfo = UIManager.getInstalledLookAndFeels(); |
149 | 0 |
int count = lfinfo.length;
|
150 | 0 |
String[] lfNames = new String[count];
|
151 | 0 |
for(int i=0; i<count; i++) { |
152 | 0 |
lfNames[i] = lfinfo[i].getName(); |
153 |
} |
|
154 | 0 |
lafCombo.setModel(new DefaultComboBoxModel(lfNames));
|
155 | 0 |
lafCombo.setSelectedItem(lafName); |
156 |
} |
|
157 |
|
|
158 |
/**
|
|
159 |
* implements the ActionListener interface to be notified of
|
|
160 |
* clicks onto the ok and cancel button.
|
|
161 |
*/
|
|
162 | 0 |
public void actionPerformed(ActionEvent e) { |
163 | 0 |
Object src = e.getSource(); |
164 | 0 |
if(src == okButton) {
|
165 | 0 |
savePrefs(); |
166 |
} |
|
167 | 0 |
super.actionPerformed(e);
|
168 |
} |
|
169 |
|
|
170 | 0 |
private void savePrefs() { |
171 | 0 |
try {
|
172 | 0 |
String newLaf = lfinfo[lafCombo.getSelectedIndex()].getClassName(); |
173 | 0 |
if(!lafName.equalsIgnoreCase(newLaf)) {
|
174 | 0 |
prefs.put(PREFSID_LOOK_AND_FEEL, newLaf); |
175 | 0 |
UIManager.setLookAndFeel(newLaf); |
176 | 0 |
SwingUtilities.updateComponentTreeUI(FrmMain.mainFrame); |
177 |
} |
|
178 | 0 |
if(saveHTML32.isSelected()) {
|
179 | 0 |
prefs.put(PREFSID_WRITE_MODE, PREFS_WRITE_MODE_HTML32); |
180 |
} |
|
181 |
else {
|
|
182 | 0 |
prefs.put(PREFSID_WRITE_MODE, PREFS_WRITE_MODE_HTML4); |
183 |
} |
|
184 | 0 |
prefs.putBoolean(PREFS_USE_STD_STYLE_SHEET, useStdStyleSheet.isSelected()); |
185 |
} |
|
186 |
catch(Exception ex) {
|
|
187 | 0 |
Util.errMsg(this, ex.getMessage(), ex);
|
188 |
} |
|
189 |
} |
|
190 |
} |
|