Revision 1698
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/DefaultToolsSwingManager.java | ||
---|---|---|
3 | 3 |
|
4 | 4 |
import java.awt.Color; |
5 | 5 |
import java.awt.Dimension; |
6 |
import java.awt.event.ActionEvent; |
|
6 | 7 |
import java.awt.image.BufferedImage; |
7 | 8 |
import java.awt.image.WritableRaster; |
9 |
import javax.swing.AbstractAction; |
|
8 | 10 |
import javax.swing.AbstractButton; |
11 |
import javax.swing.Action; |
|
9 | 12 |
import javax.swing.ComboBoxModel; |
10 | 13 |
import javax.swing.JButton; |
11 | 14 |
import javax.swing.JComboBox; |
12 | 15 |
import javax.swing.JLabel; |
13 | 16 |
import javax.swing.JList; |
17 |
import javax.swing.JPopupMenu; |
|
14 | 18 |
import javax.swing.JSlider; |
15 | 19 |
import javax.swing.JTabbedPane; |
16 | 20 |
import javax.swing.JTextField; |
21 |
import javax.swing.text.DefaultEditorKit; |
|
22 |
import javax.swing.text.JTextComponent; |
|
17 | 23 |
import javax.swing.tree.TreeModel; |
18 | 24 |
import org.apache.commons.lang3.StringUtils; |
19 | 25 |
import org.gvsig.tools.ToolsLocator; |
... | ... | |
185 | 191 |
} |
186 | 192 |
} |
187 | 193 |
} |
194 |
|
|
195 |
@Override |
|
196 |
public void setDefaultPopupMenu(final JTextComponent component) { |
|
197 |
this.setDefaultPopupMenu(component, null); |
|
198 |
} |
|
199 |
|
|
200 |
@Override |
|
201 |
public void setDefaultPopupMenu(final JTextComponent component, String title) { |
|
202 |
JPopupMenu popupMenu = new JPopupMenu(); |
|
203 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
204 |
|
|
205 |
Action copyAction = component.getActionMap().get(DefaultEditorKit.copyAction); |
|
206 |
Action cutAction = component.getActionMap().get(DefaultEditorKit.cutAction); |
|
207 |
Action pasteAction = component.getActionMap().get(DefaultEditorKit.pasteAction); |
|
208 |
Action selectAllAction = component.getActionMap().get(DefaultEditorKit.selectAllAction); |
|
209 |
|
|
210 |
if (copyAction == null |
|
211 |
&& cutAction == null |
|
212 |
&& pasteAction == null |
|
213 |
&& selectAllAction == null) { |
|
214 |
copyAction = component.getActionMap().get(i18nManager.getTranslation("copy")); |
|
215 |
cutAction = component.getActionMap().get(i18nManager.getTranslation("cut")); |
|
216 |
pasteAction = component.getActionMap().get(i18nManager.getTranslation("paste")); |
|
217 |
selectAllAction = component.getActionMap().get(i18nManager.getTranslation("SelectAll")); |
|
218 |
} else { |
|
219 |
copyAction.putValue(Action.NAME, i18nManager.getTranslation("copy")); |
|
220 |
cutAction.putValue(Action.NAME, i18nManager.getTranslation("cut")); |
|
221 |
pasteAction.putValue(Action.NAME, i18nManager.getTranslation("paste")); |
|
222 |
selectAllAction.putValue(Action.NAME, i18nManager.getTranslation("SelectAll")); |
|
223 |
} |
|
224 |
|
|
225 |
final String title2; |
|
226 |
if( title == null ) { |
|
227 |
title2 = i18nManager.getTranslation("text_editor"); |
|
228 |
} else { |
|
229 |
title2 = title; |
|
230 |
} |
|
231 |
Action textEditorAction = new AbstractAction(i18nManager.getTranslation("text_editor")) { |
|
232 |
@Override |
|
233 |
public void actionPerformed(ActionEvent e) { |
|
234 |
DefaultZoomDialog dialog = new DefaultZoomDialog(title2, component.getText()); |
|
235 |
dialog.setEditable(component.isEditable()); |
|
236 |
dialog.setAlwaysOnTop(true); |
|
237 |
dialog.setVisible(true); |
|
238 |
if (component.isEditable() && component.isEnabled()) { |
|
239 |
component.setText(dialog.getText()); |
|
240 |
} |
|
241 |
} |
|
242 |
}; |
|
243 |
popupMenu.add(textEditorAction); |
|
244 |
popupMenu.addSeparator(); |
|
245 |
|
|
246 |
popupMenu.add(cutAction); |
|
247 |
popupMenu.add(copyAction); |
|
248 |
popupMenu.add(pasteAction); |
|
249 |
popupMenu.add(selectAllAction); |
|
250 |
|
|
251 |
component.setComponentPopupMenu(popupMenu); |
|
252 |
} |
|
253 |
|
|
254 |
@Override |
|
255 |
public void setDefaultPopupMenu(JComboBox component) { |
|
256 |
this.setDefaultPopupMenu((JTextComponent) component.getEditor().getEditorComponent(), null); |
|
257 |
} |
|
258 |
|
|
259 |
|
|
260 |
@Override |
|
261 |
public void setDefaultPopupMenu(JComboBox component, String title) { |
|
262 |
this.setDefaultPopupMenu((JTextComponent) component.getEditor().getEditorComponent(), title); |
|
263 |
} |
|
264 |
|
|
188 | 265 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/DefaultZoomDialog.java | ||
---|---|---|
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 |
package org.gvsig.tools.swing.impl; |
|
25 |
|
|
26 |
import java.awt.BorderLayout; |
|
27 |
import java.awt.Dialog; |
|
28 |
import java.awt.Dimension; |
|
29 |
import java.awt.Toolkit; |
|
30 |
import java.awt.event.ActionEvent; |
|
31 |
import java.awt.event.ActionListener; |
|
32 |
|
|
33 |
import javax.swing.BorderFactory; |
|
34 |
import javax.swing.JButton; |
|
35 |
import javax.swing.JDialog; |
|
36 |
import javax.swing.JPanel; |
|
37 |
import javax.swing.JScrollPane; |
|
38 |
import javax.swing.JTextArea; |
|
39 |
|
|
40 |
public class DefaultZoomDialog extends JDialog { |
|
41 |
|
|
42 |
/** |
|
43 |
* |
|
44 |
*/ |
|
45 |
private static final long serialVersionUID = 7913363575200612492L; |
|
46 |
|
|
47 |
private String value = null; |
|
48 |
private JTextArea text = null; |
|
49 |
|
|
50 |
public DefaultZoomDialog(String title) { |
|
51 |
super((Dialog) null, title, true); |
|
52 |
} |
|
53 |
|
|
54 |
public DefaultZoomDialog(String title, String value) { |
|
55 |
this(title); |
|
56 |
this.value = value; |
|
57 |
initComponents(); |
|
58 |
|
|
59 |
} |
|
60 |
|
|
61 |
public void setEditable(boolean editable) { |
|
62 |
this.text.setEditable(editable); |
|
63 |
} |
|
64 |
|
|
65 |
private void initComponents() { |
|
66 |
|
|
67 |
JPanel panel = new JPanel(); |
|
68 |
panel.setLayout(new BorderLayout()); |
|
69 |
|
|
70 |
text = new JTextArea(); |
|
71 |
text.setText(value); |
|
72 |
text.setLineWrap(true); |
|
73 |
JScrollPane scroll = new JScrollPane(text); |
|
74 |
panel.add(scroll, BorderLayout.CENTER); |
|
75 |
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
|
76 |
|
|
77 |
JPanel p = new JPanel(); |
|
78 |
|
|
79 |
JButton close = new JButton("Close"); |
|
80 |
close.addActionListener(new ActionListener() { |
|
81 |
@Override |
|
82 |
public void actionPerformed(ActionEvent arg0) { |
|
83 |
value = text.getText(); |
|
84 |
setVisible(false); |
|
85 |
} |
|
86 |
}); |
|
87 |
|
|
88 |
p.setLayout(new BorderLayout()); |
|
89 |
p.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
|
90 |
p.add(close, BorderLayout.LINE_END); |
|
91 |
|
|
92 |
panel.add(p, BorderLayout.PAGE_END); |
|
93 |
|
|
94 |
panel.setPreferredSize(new Dimension(600, 250)); |
|
95 |
|
|
96 |
this.setContentPane(panel); |
|
97 |
|
|
98 |
this.center(); |
|
99 |
this.pack(); |
|
100 |
} |
|
101 |
|
|
102 |
public void center() { |
|
103 |
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); |
|
104 |
Dimension size = this.getPreferredSize(); |
|
105 |
int x = (int) ((dimension.getWidth() - size.getWidth()) / 2); |
|
106 |
int y = (int) ((dimension.getHeight() - size.getHeight()) / 2); |
|
107 |
this.setLocation(x, y); |
|
108 |
} |
|
109 |
|
|
110 |
public String getText() { |
|
111 |
return this.value; |
|
112 |
} |
|
113 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/ToolsSwingManager.java | ||
---|---|---|
5 | 5 |
import java.awt.Dimension; |
6 | 6 |
import java.awt.Image; |
7 | 7 |
import java.awt.image.BufferedImage; |
8 |
import java.io.IOException; |
|
9 | 8 |
import javax.swing.AbstractButton; |
10 | 9 |
import javax.swing.ComboBoxModel; |
11 | 10 |
import javax.swing.JButton; |
... | ... | |
15 | 14 |
import javax.swing.JSlider; |
16 | 15 |
import javax.swing.JTabbedPane; |
17 | 16 |
import javax.swing.JTextField; |
17 |
import javax.swing.text.JTextComponent; |
|
18 | 18 |
import javax.swing.tree.TreeModel; |
19 |
import org.gvsig.tools.ToolsLocator; |
|
20 |
import org.gvsig.tools.i18n.I18nManager; |
|
21 | 19 |
|
22 | 20 |
|
23 | 21 |
public interface ToolsSwingManager { |
... | ... | |
59 | 57 |
* @param h height in pixels of the requested image |
60 | 58 |
* @param type image type (refers to bands, etc. see {@link Image} |
61 | 59 |
* @return a buffered (editable) image of the desired size and type |
62 |
* @throws IOException |
|
63 | 60 |
*/ |
64 | 61 |
public BufferedImage createVirtualBufferedImage(int w, int h, int type); |
65 | 62 |
|
... | ... | |
101 | 98 |
public void translate(JLabel component); |
102 | 99 |
|
103 | 100 |
public void translate(JTabbedPane component); |
101 |
|
|
102 |
public void setDefaultPopupMenu(final JTextComponent component); |
|
103 |
|
|
104 |
public void setDefaultPopupMenu(final JComboBox component); |
|
105 |
|
|
106 |
public void setDefaultPopupMenu(final JTextComponent component, String title); |
|
107 |
|
|
108 |
public void setDefaultPopupMenu(final JComboBox component, String title); |
|
104 | 109 |
} |
Also available in: Unified diff