Statistics
| Revision:

gvsig-projects-pool / org.gvsig.winmgr / trunk / org.gvsig.winmgr.app / org.gvsig.winmgr.app.mainplugin / src / main / java / org / gvsig / coreplugin / preferences / general / BrowserControlPage.java @ 682

History | View | Annotate | Download (5.88 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* CVS MESSAGES:
25
*
26
* $Id: BrowserControlPage.java 38564 2012-07-16 11:19:13Z jjdelcerro $
27
* $Log$
28
* Revision 1.3  2007-09-19 16:16:52  jaume
29
* removed unnecessary imports
30
*
31
* Revision 1.2  2007/01/10 18:28:58  jaume
32
* *** empty log message ***
33
*
34
* Revision 1.1  2007/01/10 16:55:04  jaume
35
* default browser now configurable in linux
36
*
37
*
38
*/
39
package org.gvsig.coreplugin.preferences.general;
40

    
41
import java.awt.FlowLayout;
42
import java.awt.event.ActionEvent;
43
import java.awt.event.ActionListener;
44
import java.util.ArrayList;
45

    
46
import javax.swing.ButtonGroup;
47
import javax.swing.ImageIcon;
48
import javax.swing.JPanel;
49
import javax.swing.JRadioButton;
50
import javax.swing.JTextField;
51
import javax.swing.SwingConstants;
52

    
53
import org.gvsig.andami.PluginServices;
54
import org.gvsig.andami.preferences.AbstractPreferencePage;
55
import org.gvsig.andami.preferences.StoreException;
56
import org.gvsig.utils.BrowserControl;
57
import org.gvsig.utils.XMLEntity;
58
import org.gvsig.utils.swing.JComboBox;
59

    
60
/**
61
 * <p><b>Preference page</b> for system browser's properties.<br></p>
62
 *
63
 * <p>At the moment, this page will allow the <b>linux</b> users to select
64
 * a web browser and how to open it when the app needs to do such thing.<br>
65
 * For instance when following a link to a web page.<br></p>
66
 *
67
 * <p>This is the merely purpose of it, and it makes that this page has no
68
 * sense for windows users. That is why it does not appear in windows platforms.</p>
69
 *
70
 * <p>If you decide to extend this purpose, then you should enable it for those platforms
71
 * (or any) you want.</p>
72
 * TODO to know what about Mac platforms.
73
 * @author jaume dominguez faus - jaume.dominguez@iver.es
74
 *
75
 */
76
public class BrowserControlPage extends AbstractPreferencePage implements ActionListener{
77

    
78
        private static final String DEFAULT_BROWSER_KEY_NAME = "DefaultBrowser";
79
        private String id;
80
        private ImageIcon icon;
81
        private JRadioButton rdBtnSelectBrowser;
82
        private JRadioButton rdBtnSpecifyCommand;
83
        private JComboBox cmbBrowsers;
84
        private JTextField txtCustomCommand;
85
        private ArrayList supportedBrowsers = BrowserControl.getSupportedBrowsers();
86

    
87
        public BrowserControlPage() {
88
                super();
89
                id = this.getClass().getName();
90
                icon = PluginServices.getIconTheme().get("edit-setup-browsercontrol");
91
                setParentID(GeneralPage.id);
92

    
93
                JPanel aux;
94

    
95
                ButtonGroup group = new ButtonGroup();
96
                rdBtnSelectBrowser = new JRadioButton(PluginServices.getText(this, "options.general.browser.select_a_known_browser"));
97
                rdBtnSelectBrowser.addActionListener(this);
98

    
99
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING));
100
                cmbBrowsers = new JComboBox(
101
                                (String[]) supportedBrowsers.toArray(new String[0]));
102
                aux.add(cmbBrowsers);
103

    
104
                addComponent(rdBtnSelectBrowser, aux);
105

    
106
                rdBtnSpecifyCommand = new JRadioButton(PluginServices.getText(this, "options.general.browser.specify_a_command"));
107
                rdBtnSpecifyCommand.setVerticalAlignment(SwingConstants.BOTTOM);
108
                rdBtnSpecifyCommand.addActionListener(this);
109
                aux = new JPanel(new FlowLayout(FlowLayout.LEADING));
110
                aux.add(txtCustomCommand = new JTextField(25));
111
                addComponent(rdBtnSpecifyCommand, aux);
112
                group.add(rdBtnSelectBrowser);
113
                group.add(rdBtnSpecifyCommand);
114

    
115
                actionPerformed(null);
116
        }
117

    
118
        public void storeValues() throws StoreException {
119
                String cmd =
120
                        rdBtnSelectBrowser.isSelected()
121
                        ? (String) cmbBrowsers.getSelectedItem()
122
                        : txtCustomCommand.getText();
123
                BrowserControl.setBrowserCommand(cmd);
124

    
125
                PluginServices ps = PluginServices.getPluginServices(this);
126
                XMLEntity xml = ps.getPersistentXML();
127
                xml.putProperty(DEFAULT_BROWSER_KEY_NAME, cmd);
128
        }
129

    
130
        public void setChangesApplied() {
131
                setChanged(false);
132
        }
133

    
134
        public String getID() {
135
                return id;
136
        }
137

    
138
        public String getTitle() {
139
                return PluginServices.getText(this, "browser");
140
        }
141

    
142
        public JPanel getPanel() {
143
                return this;
144
        }
145

    
146
        public void initializeValues() {
147
                PluginServices ps = PluginServices.getPluginServices(this);
148
                XMLEntity xml = ps.getPersistentXML();
149
                // Default Projection
150
                if (xml.contains(DEFAULT_BROWSER_KEY_NAME)) {
151
                        String cmd = xml.getStringProperty(DEFAULT_BROWSER_KEY_NAME);
152
                        boolean b = supportedBrowsers.contains(cmd);
153
                        if (b) {
154
                                cmbBrowsers.setSelectedItem(cmd);
155
                                cmbBrowsers.setEnabled(true);
156
                                txtCustomCommand.setEnabled(false);
157
                        } else {
158
                                txtCustomCommand.setText(cmd);
159
                                txtCustomCommand.setEnabled(true);
160
                                cmbBrowsers.setEnabled(false);
161
                        }
162
                        rdBtnSelectBrowser.setSelected(b);
163
                        rdBtnSpecifyCommand.setSelected(!b);
164
                } else {
165
                        initializeDefaults();
166
                }
167
        }
168

    
169
        public void initializeDefaults() {
170
                rdBtnSelectBrowser.setSelected(true);
171
                actionPerformed(null);
172
                cmbBrowsers.setSelectedItem(BrowserControl.FIREFOX);
173
        }
174

    
175
        public ImageIcon getIcon() {
176
                return icon;
177
        }
178

    
179
        public boolean isValueChanged() {
180
                return super.hasChanged();
181
        }
182

    
183
        public void actionPerformed(ActionEvent e) {
184

    
185
                if (rdBtnSelectBrowser.isSelected()) {
186
                        cmbBrowsers.setEnabled(true);
187
                        txtCustomCommand.setEnabled(false);
188

    
189
                } else if (rdBtnSpecifyCommand.isSelected()) {
190
                        txtCustomCommand.setEnabled(true);
191
                        cmbBrowsers.setEnabled(false);
192
                }
193
        }
194

    
195
}