svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.coreplugin.app / org.gvsig.coreplugin.app.mainplugin / src / main / java / org / gvsig / coreplugin / preferences / general / DirExtensionsPage.java @ 40558
History | View | Annotate | Download (5.23 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
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 | 40435 | jjdelcerro | package org.gvsig.coreplugin.preferences.general; |
25 | |||
26 | import java.awt.BorderLayout; |
||
27 | import java.awt.Component; |
||
28 | import java.awt.Dimension; |
||
29 | import java.awt.event.KeyEvent; |
||
30 | import java.awt.event.KeyListener; |
||
31 | |||
32 | import javax.swing.BorderFactory; |
||
33 | import javax.swing.ImageIcon; |
||
34 | import javax.swing.JButton; |
||
35 | import javax.swing.JFileChooser; |
||
36 | import javax.swing.JPanel; |
||
37 | import javax.swing.JTextField; |
||
38 | import javax.swing.border.TitledBorder; |
||
39 | |||
40 | import org.gvsig.andami.Launcher; |
||
41 | import org.gvsig.andami.PluginServices; |
||
42 | import org.gvsig.andami.preferences.AbstractPreferencePage; |
||
43 | import org.gvsig.utils.GenericFileFilter; |
||
44 | |||
45 | |||
46 | public class DirExtensionsPage extends AbstractPreferencePage { |
||
47 | private ImageIcon icon; |
||
48 | private String id; |
||
49 | private JPanel pN = null; |
||
50 | private JPanel pC = null; |
||
51 | private boolean changed = false; |
||
52 | private JPanel jPanel = null; |
||
53 | private JTextField jTextField = null; |
||
54 | private JButton jButton = null; |
||
55 | private String pluginDirectory; |
||
56 | |||
57 | public DirExtensionsPage() {
|
||
58 | super();
|
||
59 | initialize(); |
||
60 | id = this.getClass().getName();
|
||
61 | setParentID(GeneralPage.class.getName()); |
||
62 | } |
||
63 | |||
64 | private void initialize() { |
||
65 | icon = PluginServices.getIconTheme().get("edit-setup-dirextension");
|
||
66 | this.setLayout(new BorderLayout()); |
||
67 | this.setSize(new java.awt.Dimension(386,177)); |
||
68 | this.add(getPN(), java.awt.BorderLayout.NORTH);
|
||
69 | this.add(getPC(), java.awt.BorderLayout.CENTER);
|
||
70 | } |
||
71 | |||
72 | public String getID() { |
||
73 | return id;
|
||
74 | } |
||
75 | |||
76 | public String getTitle() { |
||
77 | return PluginServices.getText(this, "directorio_extensiones"); |
||
78 | } |
||
79 | |||
80 | public JPanel getPanel() { |
||
81 | return this; |
||
82 | } |
||
83 | |||
84 | |||
85 | |||
86 | public void initializeValues() { |
||
87 | pluginDirectory = Launcher.getAndamiConfig().getPluginsDirectory(); |
||
88 | getJTextField().setText(pluginDirectory); |
||
89 | } |
||
90 | |||
91 | public void storeValues() { |
||
92 | // Se escribe el directorio de los plugins
|
||
93 | pluginDirectory = getJTextField().getText(); |
||
94 | Launcher.getAndamiConfig().setPluginsDirectory(pluginDirectory); |
||
95 | } |
||
96 | |||
97 | public void initializeDefaults() { |
||
98 | |||
99 | } |
||
100 | |||
101 | public ImageIcon getIcon() { |
||
102 | return icon;
|
||
103 | } |
||
104 | |||
105 | /**
|
||
106 | * This method initializes pN
|
||
107 | *
|
||
108 | * @return javax.swing.JPanel
|
||
109 | */
|
||
110 | private JPanel getPN() { |
||
111 | if (pN == null) { |
||
112 | pN = new JPanel(); |
||
113 | } |
||
114 | return pN;
|
||
115 | } |
||
116 | |||
117 | /**
|
||
118 | * This method initializes pC
|
||
119 | *
|
||
120 | * @return javax.swing.JPanel
|
||
121 | */
|
||
122 | private JPanel getPC() { |
||
123 | if (pC == null) { |
||
124 | pC = new JPanel(); |
||
125 | pC.add(getJPanel(), null);
|
||
126 | } |
||
127 | return pC;
|
||
128 | } |
||
129 | |||
130 | /**
|
||
131 | * This method initializes jPanel
|
||
132 | *
|
||
133 | * @return javax.swing.JPanel
|
||
134 | */
|
||
135 | private JPanel getJPanel() { |
||
136 | if (jPanel == null) { |
||
137 | jPanel = new JPanel(); |
||
138 | jPanel.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "directorio"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null)); |
||
139 | jPanel.add(getJTextField(), null);
|
||
140 | jPanel.add(getJButton(), null);
|
||
141 | } |
||
142 | return jPanel;
|
||
143 | } |
||
144 | |||
145 | /**
|
||
146 | * This method initializes jTextField
|
||
147 | *
|
||
148 | * @return javax.swing.JTextField
|
||
149 | */
|
||
150 | private JTextField getJTextField() { |
||
151 | if (jTextField == null) { |
||
152 | jTextField = new JTextField(); |
||
153 | jTextField.setPreferredSize(new Dimension(200, 20)); |
||
154 | jTextField.setText(pluginDirectory); |
||
155 | jTextField.addKeyListener(new KeyListener() { |
||
156 | public void keyPressed(KeyEvent e) { changed = true; } |
||
157 | public void keyReleased(KeyEvent e) { changed = true; } |
||
158 | public void keyTyped(KeyEvent e){ changed = true; } |
||
159 | }); |
||
160 | } |
||
161 | return jTextField;
|
||
162 | } |
||
163 | |||
164 | /**
|
||
165 | * This method initializes jButton
|
||
166 | *
|
||
167 | * @return javax.swing.JButton
|
||
168 | */
|
||
169 | private JButton getJButton() { |
||
170 | if (jButton == null) { |
||
171 | jButton = new JButton(); |
||
172 | jButton.setText(PluginServices.getText(this, "examinar")); |
||
173 | jButton.addActionListener(new java.awt.event.ActionListener() {
|
||
174 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
175 | JFileChooser jfc = new JFileChooser(); |
||
176 | jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||
177 | jfc.addChoosableFileFilter(new GenericFileFilter("", |
||
178 | PluginServices.getText(this,
|
||
179 | "directorio_extensiones")));
|
||
180 | |||
181 | if (jfc.showOpenDialog(
|
||
182 | (Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
||
183 | getJTextField().setText(jfc.getSelectedFile() |
||
184 | .getAbsolutePath()); |
||
185 | changed = true;
|
||
186 | } |
||
187 | } |
||
188 | }); |
||
189 | |||
190 | } |
||
191 | return jButton;
|
||
192 | } |
||
193 | |||
194 | public boolean isValueChanged() { |
||
195 | return changed;
|
||
196 | } |
||
197 | |||
198 | public void setChangesApplied() { |
||
199 | changed = false;
|
||
200 | } |
||
201 | |||
202 | } // @jve:decl-index=0:visual-constraint="10,10"
|