root / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / preferences / general / BrowserControlPage.java @ 38608
History | View | Annotate | Download (6.07 KB)
1 | 9644 | jaume | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
||
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 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | |||
42 | /* CVS MESSAGES:
|
||
43 | *
|
||
44 | * $Id$
|
||
45 | * $Log$
|
||
46 | 13881 | jaume | * Revision 1.3 2007-09-19 16:16:52 jaume
|
47 | * removed unnecessary imports
|
||
48 | *
|
||
49 | * Revision 1.2 2007/01/10 18:28:58 jaume
|
||
50 | 9653 | jaume | * *** empty log message ***
|
51 | *
|
||
52 | * Revision 1.1 2007/01/10 16:55:04 jaume
|
||
53 | 9644 | jaume | * default browser now configurable in linux
|
54 | *
|
||
55 | *
|
||
56 | */
|
||
57 | 29630 | jpiera | package org.gvsig.coreplugin.preferences.general; |
58 | 9644 | jaume | |
59 | import java.awt.FlowLayout; |
||
60 | import java.awt.event.ActionEvent; |
||
61 | import java.awt.event.ActionListener; |
||
62 | import java.util.ArrayList; |
||
63 | |||
64 | import javax.swing.ButtonGroup; |
||
65 | import javax.swing.ImageIcon; |
||
66 | import javax.swing.JPanel; |
||
67 | import javax.swing.JRadioButton; |
||
68 | import javax.swing.JTextField; |
||
69 | 9653 | jaume | import javax.swing.SwingConstants; |
70 | 9644 | jaume | |
71 | 29630 | jpiera | import org.gvsig.andami.PluginServices; |
72 | import org.gvsig.andami.preferences.AbstractPreferencePage; |
||
73 | import org.gvsig.andami.preferences.StoreException; |
||
74 | import org.gvsig.utils.BrowserControl; |
||
75 | import org.gvsig.utils.XMLEntity; |
||
76 | import org.gvsig.utils.swing.JComboBox; |
||
77 | |||
78 | 9644 | jaume | /**
|
79 | * <p><b>Preference page</b> for system browser's properties.<br></p>
|
||
80 | *
|
||
81 | * <p>At the moment, this page will allow the <b>linux</b> users to select
|
||
82 | * a web browser and how to open it when the app needs to do such thing.<br>
|
||
83 | * For instance when following a link to a web page.<br></p>
|
||
84 | *
|
||
85 | * <p>This is the merely purpose of it, and it makes that this page has no
|
||
86 | * sense for windows users. That is why it does not appear in windows platforms.</p>
|
||
87 | *
|
||
88 | * <p>If you decide to extend this purpose, then you should enable it for those platforms
|
||
89 | * (or any) you want.</p>
|
||
90 | * TODO to know what about Mac platforms.
|
||
91 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
92 | *
|
||
93 | */
|
||
94 | public class BrowserControlPage extends AbstractPreferencePage implements ActionListener{ |
||
95 | |||
96 | private static final String DEFAULT_BROWSER_KEY_NAME = "DefaultBrowser"; |
||
97 | private String id; |
||
98 | private ImageIcon icon; |
||
99 | private JRadioButton rdBtnSelectBrowser; |
||
100 | private JRadioButton rdBtnSpecifyCommand; |
||
101 | private JComboBox cmbBrowsers; |
||
102 | private JTextField txtCustomCommand; |
||
103 | private ArrayList supportedBrowsers = BrowserControl.getSupportedBrowsers(); |
||
104 | |||
105 | public BrowserControlPage() {
|
||
106 | super();
|
||
107 | id = this.getClass().getName();
|
||
108 | 38564 | jjdelcerro | icon = PluginServices.getIconTheme().get("edit-setup-browsercontrol");
|
109 | 9644 | jaume | setParentID(GeneralPage.id); |
110 | |||
111 | JPanel aux;
|
||
112 | |||
113 | ButtonGroup group = new ButtonGroup(); |
||
114 | 9653 | jaume | rdBtnSelectBrowser = new JRadioButton(PluginServices.getText(this, "options.general.browser.select_a_known_browser")); |
115 | 9644 | jaume | rdBtnSelectBrowser.addActionListener(this);
|
116 | |||
117 | aux = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
||
118 | cmbBrowsers = new JComboBox( |
||
119 | (String[]) supportedBrowsers.toArray(new String[0])); |
||
120 | aux.add(cmbBrowsers); |
||
121 | |||
122 | addComponent(rdBtnSelectBrowser, aux); |
||
123 | |||
124 | 9653 | jaume | rdBtnSpecifyCommand = new JRadioButton(PluginServices.getText(this, "options.general.browser.specify_a_command")); |
125 | rdBtnSpecifyCommand.setVerticalAlignment(SwingConstants.BOTTOM);
|
||
126 | 9644 | jaume | rdBtnSpecifyCommand.addActionListener(this);
|
127 | 9653 | jaume | aux = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
128 | aux.add(txtCustomCommand = new JTextField(25)); |
||
129 | addComponent(rdBtnSpecifyCommand, aux); |
||
130 | 9644 | jaume | group.add(rdBtnSelectBrowser); |
131 | group.add(rdBtnSpecifyCommand); |
||
132 | |||
133 | actionPerformed(null);
|
||
134 | } |
||
135 | |||
136 | public void storeValues() throws StoreException { |
||
137 | String cmd =
|
||
138 | rdBtnSelectBrowser.isSelected() |
||
139 | ? (String) cmbBrowsers.getSelectedItem()
|
||
140 | : txtCustomCommand.getText(); |
||
141 | BrowserControl.setBrowserCommand(cmd); |
||
142 | |||
143 | PluginServices ps = PluginServices.getPluginServices(this);
|
||
144 | XMLEntity xml = ps.getPersistentXML(); |
||
145 | xml.putProperty(DEFAULT_BROWSER_KEY_NAME, cmd); |
||
146 | } |
||
147 | |||
148 | public void setChangesApplied() { |
||
149 | setChanged(false);
|
||
150 | } |
||
151 | |||
152 | public String getID() { |
||
153 | return id;
|
||
154 | } |
||
155 | |||
156 | public String getTitle() { |
||
157 | return PluginServices.getText(this, "browser"); |
||
158 | } |
||
159 | |||
160 | public JPanel getPanel() { |
||
161 | return this; |
||
162 | } |
||
163 | |||
164 | public void initializeValues() { |
||
165 | PluginServices ps = PluginServices.getPluginServices(this);
|
||
166 | XMLEntity xml = ps.getPersistentXML(); |
||
167 | // Default Projection
|
||
168 | if (xml.contains(DEFAULT_BROWSER_KEY_NAME)) {
|
||
169 | String cmd = xml.getStringProperty(DEFAULT_BROWSER_KEY_NAME);
|
||
170 | 9653 | jaume | boolean b = supportedBrowsers.contains(cmd);
|
171 | if (b) {
|
||
172 | cmbBrowsers.setSelectedItem(cmd); |
||
173 | cmbBrowsers.setEnabled(true);
|
||
174 | txtCustomCommand.setEnabled(false);
|
||
175 | } else {
|
||
176 | txtCustomCommand.setText(cmd); |
||
177 | txtCustomCommand.setEnabled(true);
|
||
178 | cmbBrowsers.setEnabled(false);
|
||
179 | } |
||
180 | rdBtnSelectBrowser.setSelected(b); |
||
181 | rdBtnSpecifyCommand.setSelected(!b); |
||
182 | 9644 | jaume | } else {
|
183 | initializeDefaults(); |
||
184 | } |
||
185 | } |
||
186 | |||
187 | public void initializeDefaults() { |
||
188 | rdBtnSelectBrowser.setSelected(true);
|
||
189 | actionPerformed(null);
|
||
190 | cmbBrowsers.setSelectedItem(BrowserControl.FIREFOX); |
||
191 | } |
||
192 | |||
193 | public ImageIcon getIcon() { |
||
194 | return icon;
|
||
195 | } |
||
196 | |||
197 | public boolean isValueChanged() { |
||
198 | return super.hasChanged(); |
||
199 | } |
||
200 | |||
201 | public void actionPerformed(ActionEvent e) { |
||
202 | |||
203 | if (rdBtnSelectBrowser.isSelected()) {
|
||
204 | cmbBrowsers.setEnabled(true);
|
||
205 | txtCustomCommand.setEnabled(false);
|
||
206 | |||
207 | } else if (rdBtnSpecifyCommand.isSelected()) { |
||
208 | txtCustomCommand.setEnabled(true);
|
||
209 | cmbBrowsers.setEnabled(false);
|
||
210 | } |
||
211 | } |
||
212 | |||
213 | } |