Statistics
| Revision:

root / trunk / libraries / libCorePlugin / src / com / iver / core / preferences / general / BrowserControlPage.java @ 13881

History | View | Annotate | Download (6.08 KB)

1
/* 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: BrowserControlPage.java 13881 2007-09-19 16:22:04Z jaume $
45
* $Log$
46
* 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
* *** empty log message ***
51
*
52
* Revision 1.1  2007/01/10 16:55:04  jaume
53
* default browser now configurable in linux
54
*
55
*
56
*/
57
package com.iver.core.preferences.general;
58

    
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
import javax.swing.SwingConstants;
70

    
71
import com.iver.andami.PluginServices;
72
import com.iver.andami.preferences.AbstractPreferencePage;
73
import com.iver.andami.preferences.StoreException;
74
import com.iver.utiles.BrowserControl;
75
import com.iver.utiles.XMLEntity;
76
import com.iver.utiles.swing.JComboBox;
77
/**
78
 * <p><b>Preference page</b> for system browser's properties.<br></p>
79
 *
80
 * <p>At the moment, this page will allow the <b>linux</b> users to select
81
 * a web browser and how to open it when the app needs to do such thing.<br>
82
 * For instance when following a link to a web page.<br></p>
83
 *
84
 * <p>This is the merely purpose of it, and it makes that this page has no
85
 * sense for windows users. That is why it does not appear in windows platforms.</p>
86
 *
87
 * <p>If you decide to extend this purpose, then you should enable it for those platforms
88
 * (or any) you want.</p>
89
 * TODO to know what about Mac platforms.
90
 * @author jaume dominguez faus - jaume.dominguez@iver.es
91
 *
92
 */
93
public class BrowserControlPage extends AbstractPreferencePage implements ActionListener{
94

    
95
        private static final String DEFAULT_BROWSER_KEY_NAME = "DefaultBrowser";
96
        private String id;
97
        private ImageIcon icon;
98
        private JRadioButton rdBtnSelectBrowser;
99
        private JRadioButton rdBtnSpecifyCommand;
100
        private JComboBox cmbBrowsers;
101
        private JTextField txtCustomCommand;
102
        private ArrayList supportedBrowsers = BrowserControl.getSupportedBrowsers();
103

    
104
        public BrowserControlPage() {
105
                super();
106
                id = this.getClass().getName();
107
                icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/browser.png"));
108
                setParentID(GeneralPage.id);
109

    
110
                JPanel aux;
111

    
112
                ButtonGroup group = new ButtonGroup();
113
                rdBtnSelectBrowser = new JRadioButton(PluginServices.getText(this, "options.general.browser.select_a_known_browser"));
114
                rdBtnSelectBrowser.addActionListener(this);
115

    
116
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING));
117
                cmbBrowsers = new JComboBox(
118
                                (String[]) supportedBrowsers.toArray(new String[0]));
119
                aux.add(cmbBrowsers);
120

    
121
                addComponent(rdBtnSelectBrowser, aux);
122

    
123
                rdBtnSpecifyCommand = new JRadioButton(PluginServices.getText(this, "options.general.browser.specify_a_command"));
124
                rdBtnSpecifyCommand.setVerticalAlignment(SwingConstants.BOTTOM);
125
                rdBtnSpecifyCommand.addActionListener(this);
126
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING));
127
                aux.add(txtCustomCommand = new JTextField(25));
128
                addComponent(rdBtnSpecifyCommand, aux);
129
                group.add(rdBtnSelectBrowser);
130
                group.add(rdBtnSpecifyCommand);
131

    
132
                actionPerformed(null);
133
        }
134

    
135
        public void storeValues() throws StoreException {
136
                String cmd =
137
                        rdBtnSelectBrowser.isSelected()
138
                        ? (String) cmbBrowsers.getSelectedItem()
139
                        : txtCustomCommand.getText();
140
                BrowserControl.setBrowserCommand(cmd);
141

    
142
                PluginServices ps = PluginServices.getPluginServices(this);
143
                XMLEntity xml = ps.getPersistentXML();
144
                xml.putProperty(DEFAULT_BROWSER_KEY_NAME, cmd);
145
        }
146

    
147
        public void setChangesApplied() {
148
                setChanged(false);
149
        }
150

    
151
        public String getID() {
152
                return id;
153
        }
154

    
155
        public String getTitle() {
156
                return PluginServices.getText(this, "browser");
157
        }
158

    
159
        public JPanel getPanel() {
160
                return this;
161
        }
162

    
163
        public void initializeValues() {
164
                PluginServices ps = PluginServices.getPluginServices(this);
165
                XMLEntity xml = ps.getPersistentXML();
166
                // Default Projection
167
                if (xml.contains(DEFAULT_BROWSER_KEY_NAME)) {
168
                        String cmd = xml.getStringProperty(DEFAULT_BROWSER_KEY_NAME);
169
                        boolean b = supportedBrowsers.contains(cmd);
170
                        if (b) {
171
                                cmbBrowsers.setSelectedItem(cmd);
172
                                cmbBrowsers.setEnabled(true);
173
                                txtCustomCommand.setEnabled(false);
174
                        } else {
175
                                txtCustomCommand.setText(cmd);
176
                                txtCustomCommand.setEnabled(true);
177
                                cmbBrowsers.setEnabled(false);
178
                        }
179
                        rdBtnSelectBrowser.setSelected(b);
180
                        rdBtnSpecifyCommand.setSelected(!b);
181
                } else {
182
                        initializeDefaults();
183
                }
184
        }
185

    
186
        public void initializeDefaults() {
187
                rdBtnSelectBrowser.setSelected(true);
188
                actionPerformed(null);
189
                cmbBrowsers.setSelectedItem(BrowserControl.FIREFOX);
190
        }
191

    
192
        public ImageIcon getIcon() {
193
                return icon;
194
        }
195

    
196
        public boolean isValueChanged() {
197
                return super.hasChanged();
198
        }
199

    
200
        public void actionPerformed(ActionEvent e) {
201

    
202
                if (rdBtnSelectBrowser.isSelected()) {
203
                        cmbBrowsers.setEnabled(true);
204
                        txtCustomCommand.setEnabled(false);
205

    
206
                } else if (rdBtnSpecifyCommand.isSelected()) {
207
                        txtCustomCommand.setEnabled(true);
208
                        cmbBrowsers.setEnabled(false);
209
                }
210
        }
211

    
212
}