|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
PluginManagerDialog.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 com.lightdev.app.shtm.DialogShell;
|
|
21 |
//import com.lightdev.app.shtm.FrmMain;
|
|
22 |
//import com.lightdev.app.shtm.Util;
|
|
23 |
import java.awt.Frame;
|
|
24 |
import javax.swing.JPanel;
|
|
25 |
import javax.swing.JList;
|
|
26 |
import javax.swing.JButton;
|
|
27 |
import javax.swing.JLabel;
|
|
28 |
import java.awt.BorderLayout;
|
|
29 |
import java.util.Enumeration;
|
|
30 |
import javax.swing.border.EtchedBorder;
|
|
31 |
import javax.swing.JComboBox;
|
|
32 |
import javax.swing.border.TitledBorder;
|
|
33 |
import java.awt.Container;
|
|
34 |
import java.awt.GridBagConstraints;
|
|
35 |
import java.awt.GridBagLayout;
|
|
36 |
import javax.swing.JCheckBox;
|
|
37 |
import java.awt.event.ActionListener;
|
|
38 |
import java.awt.event.ActionEvent;
|
|
39 |
import javax.swing.event.ListSelectionListener;
|
|
40 |
import javax.swing.event.ListSelectionEvent;
|
|
41 |
import javax.swing.JScrollPane;
|
|
42 |
import java.awt.Dimension;
|
|
43 |
|
|
44 |
/**
|
|
45 |
* User interface for changing plug-in settings.
|
|
46 |
*
|
|
47 |
* @author Ulrich Hilger
|
|
48 |
* @author Light Development
|
|
49 |
* @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
|
|
50 |
* @author <a href="mailto:info@lightdev.com">info@lightdev.com</a>
|
|
51 |
* @author published under the terms and conditions of the
|
|
52 |
* GNU General Public License,
|
|
53 |
* for details see file gpl.txt in the distribution
|
|
54 |
* package of this software
|
|
55 |
*
|
|
56 |
* @version stage 11, April 27, 2003
|
|
57 |
*/
|
|
58 |
|
|
59 |
public class PluginManagerDialog extends DialogShell implements |
|
60 |
ListSelectionListener, ActionListener |
|
61 |
{ |
|
62 |
/** combo box for selecting the dock location */
|
|
63 |
private JComboBox dockLocation;
|
|
64 |
|
|
65 |
/** indicates if we can ignore changes (when happenig programmatically */
|
|
66 |
private boolean ignoreChanges = false; |
|
67 |
|
|
68 |
/** the list with available plug-ins */
|
|
69 |
private JList pluginNames;
|
|
70 |
|
|
71 |
/** constant for activation button label */
|
|
72 |
private String activateName = FrmMain.dynRes.getResourceString(
|
|
73 |
FrmMain.resources, "activatePlugin");
|
|
74 |
|
|
75 |
/** constant for deactivation button label */
|
|
76 |
private String deactivateName = FrmMain.dynRes.getResourceString(
|
|
77 |
FrmMain.resources, "deactivatePlugin");
|
|
78 |
|
|
79 |
/** button to toggle plug-in activation state */
|
|
80 |
private JButton toggleActivationButton;
|
|
81 |
|
|
82 |
/** checkbox to toggle plug-in activation state */
|
|
83 |
private JCheckBox toggleActivationCheckbox;
|
|
84 |
|
|
85 |
/**
|
|
86 |
* construct a new <code>PluginManagerDialog</code>
|
|
87 |
*
|
|
88 |
* @param parent the parent frame
|
|
89 |
* @param title the title of the dialog
|
|
90 |
*/
|
|
91 | 0 |
public PluginManagerDialog(Frame parent, String title) {
|
92 | 0 |
super(parent, title);
|
93 | 0 |
Container contentPane = super.getContentPane();
|
94 |
|
|
95 | 0 |
okButton.setText(FrmMain.dynRes.getResourceString(FrmMain.resources, "close"));
|
96 | 0 |
cancelButton.setVisible(false);
|
97 |
|
|
98 | 0 |
GridBagLayout g; |
99 | 0 |
GridBagConstraints c = new GridBagConstraints();
|
100 |
|
|
101 |
/** create panel to show and select plug-ins */
|
|
102 | 0 |
JPanel pluginPanel = new JPanel(new BorderLayout()); |
103 | 0 |
pluginPanel.setBorder( |
104 |
new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), |
|
105 |
FrmMain.dynRes.getResourceString( |
|
106 |
FrmMain.resources, "pluginPanelTitle")));
|
|
107 |
//pluginPanel.setMinimumSize(new Dimension(400, 400));
|
|
108 |
|
|
109 |
/** load a list with plug-in names and add it to the plug-in panel */
|
|
110 | 0 |
Enumeration plugins = FrmMain.pluginManager.plugins(); |
111 | 0 |
pluginNames = new JList(FrmMain.pluginManager.getPluginNames());
|
112 | 0 |
pluginNames.addListSelectionListener(this);
|
113 | 0 |
pluginNames.setMinimumSize(new Dimension(250, 400));
|
114 | 0 |
pluginNames.setPreferredSize(new Dimension(250, 400));
|
115 | 0 |
pluginPanel.add(new JScrollPane(pluginNames), BorderLayout.CENTER);
|
116 |
|
|
117 |
/** create panel for actins on loaded plug-ins */
|
|
118 | 0 |
JPanel actionPanel = new JPanel();
|
119 | 0 |
toggleActivationButton = new JButton(activateName);
|
120 | 0 |
toggleActivationButton.setEnabled(false);
|
121 | 0 |
toggleActivationButton.addActionListener(this);
|
122 | 0 |
actionPanel.add(toggleActivationButton); |
123 | 0 |
pluginPanel.add(actionPanel, BorderLayout.SOUTH); |
124 |
|
|
125 |
/** create panel to edit settings for a plug-in */
|
|
126 | 0 |
g = new GridBagLayout();
|
127 | 0 |
JPanel pluginSettingsPanel = new JPanel(g);
|
128 | 0 |
toggleActivationCheckbox = new JCheckBox(FrmMain.dynRes.getResourceString(
|
129 |
FrmMain.resources, "togglePluginActivationCheckbox"));
|
|
130 | 0 |
toggleActivationCheckbox.setEnabled(false);
|
131 | 0 |
toggleActivationCheckbox.addActionListener(this);
|
132 | 0 |
Util.addGridBagComponent(pluginSettingsPanel, toggleActivationCheckbox, |
133 |
g, c, 0, 0, GridBagConstraints.WEST); |
|
134 |
|
|
135 | 0 |
Util.addGridBagComponent(pluginSettingsPanel, new JLabel(
|
136 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "dockLocationLabel")),
|
|
137 |
g, c, 0, 1, GridBagConstraints.EAST); |
|
138 | 0 |
String[] locations = { |
139 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "pluginDockLocationNone"),
|
|
140 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "pluginDockLocationTop"),
|
|
141 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "pluginDockLocationRight"),
|
|
142 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "pluginDockLocationBottom"),
|
|
143 |
FrmMain.dynRes.getResourceString(FrmMain.resources, "pluginDockLocationLeft"),
|
|
144 |
}; |
|
145 | 0 |
dockLocation = new JComboBox(locations);
|
146 | 0 |
dockLocation.setEnabled(false);
|
147 | 0 |
dockLocation.addActionListener(this);
|
148 | 0 |
Util.addGridBagComponent(pluginSettingsPanel, dockLocation, g, c, |
149 |
1, 1, GridBagConstraints.WEST); |
|
150 |
|
|
151 |
/** add components to dialog */
|
|
152 | 0 |
contentPane.add(pluginPanel, BorderLayout.WEST); |
153 | 0 |
JPanel centerPanel = new JPanel(new BorderLayout()); |
154 | 0 |
JPanel centerWestPanel = new JPanel(new BorderLayout()); |
155 | 0 |
centerWestPanel.add(pluginSettingsPanel, BorderLayout.NORTH); |
156 | 0 |
centerPanel.add(centerWestPanel, BorderLayout.WEST); |
157 | 0 |
centerPanel.setBorder( |
158 |
new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), |
|
159 |
FrmMain.dynRes.getResourceString( |
|
160 |
FrmMain.resources, "pluginSettingsPanelTitle")));
|
|
161 |
//centerPanel.setPreferredSize(new Dimension(200,400));
|
|
162 | 0 |
contentPane.add(centerPanel, BorderLayout.CENTER); |
163 |
|
|
164 | 0 |
pack(); |
165 |
} |
|
166 |
|
|
167 |
/**
|
|
168 |
* ListSelectionListener implementation
|
|
169 |
*/
|
|
170 | 0 |
public void valueChanged(ListSelectionEvent e) { |
171 | 0 |
ignoreChanges = true;
|
172 | 0 |
if(pluginNames.getSelectedIndex() > -1) {
|
173 | 0 |
SHTMLPlugin p = getSelectedPlugin(); |
174 | 0 |
boolean active = p.isActive();
|
175 | 0 |
updateActivationButtonText(active); |
176 | 0 |
toggleActivationButton.setEnabled(true);
|
177 | 0 |
toggleActivationCheckbox.setEnabled(true);
|
178 | 0 |
toggleActivationCheckbox.setSelected(active); |
179 | 0 |
dockLocation.setSelectedIndex(p.getDockLocation()); |
180 | 0 |
dockLocation.setEnabled(true);
|
181 |
} |
|
182 |
else {
|
|
183 | 0 |
toggleActivationButton.setEnabled(false);
|
184 | 0 |
toggleActivationCheckbox.setEnabled(false);
|
185 | 0 |
dockLocation.setEnabled(false);
|
186 |
} |
|
187 | 0 |
ignoreChanges = false;
|
188 |
} |
|
189 |
|
|
190 |
/**
|
|
191 |
* helper method for getting the currently selected
|
|
192 |
* line in the list of plug-ins
|
|
193 |
*/
|
|
194 | 0 |
private SHTMLPlugin getSelectedPlugin() {
|
195 | 0 |
String name = (String) pluginNames.getSelectedValue(); |
196 | 0 |
return FrmMain.pluginManager.pluginForName(name);
|
197 |
} |
|
198 |
|
|
199 |
/**
|
|
200 |
* helper method to toggle the button text between
|
|
201 |
* activate and deactivate
|
|
202 |
*/
|
|
203 | 0 |
private void updateActivationButtonText(boolean active) { |
204 | 0 |
if(active) {
|
205 | 0 |
toggleActivationButton.setText(deactivateName); |
206 |
} |
|
207 |
else {
|
|
208 | 0 |
toggleActivationButton.setText(activateName); |
209 |
} |
|
210 |
} |
|
211 |
|
|
212 |
/**
|
|
213 |
* ActionListener implementation
|
|
214 |
*/
|
|
215 | 0 |
public void actionPerformed(ActionEvent e) { |
216 | 0 |
Object source = e.getSource(); |
217 | 0 |
if((pluginNames.getSelectedIndex() > -1) && (!ignoreChanges)) {
|
218 | 0 |
ignoreChanges = true;
|
219 | 0 |
SHTMLPlugin p = getSelectedPlugin(); |
220 | 0 |
if(source.equals(toggleActivationButton)) {
|
221 | 0 |
p.setStatus(!p.isActive()); |
222 |
} |
|
223 | 0 |
else if(source.equals(toggleActivationCheckbox)) { |
224 | 0 |
p.setStatus(!p.isActive()); |
225 |
} |
|
226 | 0 |
else if(source.equals(dockLocation)) { |
227 | 0 |
p.setDockLocation(dockLocation.getSelectedIndex()); |
228 |
} |
|
229 |
else {
|
|
230 | 0 |
super.actionPerformed(e);
|
231 |
} |
|
232 | 0 |
boolean active = p.isActive();
|
233 | 0 |
toggleActivationCheckbox.setSelected(active); |
234 | 0 |
updateActivationButtonText(active); |
235 | 0 |
ignoreChanges = false;
|
236 |
} |
|
237 |
else {
|
|
238 | 0 |
super.actionPerformed(e);
|
239 |
} |
|
240 |
} |
|
241 |
|
|
242 |
} |
|