gvsig-tools / 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 @ 1947
History | View | Annotate | Download (20.5 KB)
1 | 1251 | jjdelcerro | |
---|---|---|---|
2 | package org.gvsig.tools.swing.impl; |
||
3 | |||
4 | 1758 | jjdelcerro | import java.awt.BorderLayout; |
5 | 1628 | jjdelcerro | import java.awt.Color; |
6 | 1808 | jjdelcerro | import java.awt.Cursor; |
7 | 1530 | fdiaz | import java.awt.Dimension; |
8 | 1698 | jjdelcerro | import java.awt.event.ActionEvent; |
9 | 1758 | jjdelcerro | import java.awt.event.ActionListener; |
10 | 1530 | fdiaz | import java.awt.image.BufferedImage; |
11 | import java.awt.image.WritableRaster; |
||
12 | 1772 | jjdelcerro | import java.beans.PropertyChangeEvent; |
13 | import java.beans.PropertyChangeListener; |
||
14 | 1746 | jjdelcerro | import java.io.File; |
15 | import java.lang.reflect.InvocationTargetException; |
||
16 | import java.lang.reflect.Method; |
||
17 | 1698 | jjdelcerro | import javax.swing.AbstractAction; |
18 | 1640 | jjdelcerro | import javax.swing.AbstractButton; |
19 | 1698 | jjdelcerro | import javax.swing.Action; |
20 | 1424 | jjdelcerro | import javax.swing.ComboBoxModel; |
21 | 1947 | jjdelcerro | import javax.swing.Icon; |
22 | 1758 | jjdelcerro | import javax.swing.ImageIcon; |
23 | 1610 | jjdelcerro | import javax.swing.JButton; |
24 | 1377 | jjdelcerro | import javax.swing.JComboBox; |
25 | 1746 | jjdelcerro | import javax.swing.JComponent; |
26 | 1640 | jjdelcerro | import javax.swing.JLabel; |
27 | 1377 | jjdelcerro | import javax.swing.JList; |
28 | 1772 | jjdelcerro | import javax.swing.JMenuItem; |
29 | 1698 | jjdelcerro | import javax.swing.JPopupMenu; |
30 | 1750 | jjdelcerro | import javax.swing.JScrollPane; |
31 | 1610 | jjdelcerro | import javax.swing.JSlider; |
32 | 1683 | jjdelcerro | import javax.swing.JTabbedPane; |
33 | 1610 | jjdelcerro | import javax.swing.JTextField; |
34 | 1750 | jjdelcerro | import javax.swing.JViewport; |
35 | 1947 | jjdelcerro | import javax.swing.SwingConstants; |
36 | 1698 | jjdelcerro | import javax.swing.text.DefaultEditorKit; |
37 | import javax.swing.text.JTextComponent; |
||
38 | 1377 | jjdelcerro | import javax.swing.tree.TreeModel; |
39 | 1644 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
40 | 1640 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
41 | import org.gvsig.tools.i18n.I18nManager; |
||
42 | 1251 | jjdelcerro | import org.gvsig.tools.swing.api.ActionListenerSupport; |
43 | 1746 | jjdelcerro | import org.gvsig.tools.swing.api.ChangeListenerHelper; |
44 | 1610 | jjdelcerro | import org.gvsig.tools.swing.api.ColorChooserController; |
45 | 1947 | jjdelcerro | import org.gvsig.tools.swing.api.CompoundIcon; |
46 | 1884 | jjdelcerro | import org.gvsig.tools.swing.api.DropDown; |
47 | 1377 | jjdelcerro | import org.gvsig.tools.swing.api.JListWithCheckbox; |
48 | 1840 | jjdelcerro | import org.gvsig.tools.swing.api.SimpleImage; |
49 | 1758 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
50 | 1251 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingManager; |
51 | 1746 | jjdelcerro | import org.gvsig.tools.swing.api.pickercontroller.ColorPickerController; |
52 | import org.gvsig.tools.swing.api.pickercontroller.DatePickerController; |
||
53 | import org.gvsig.tools.swing.api.pickercontroller.FilePickerController; |
||
54 | import org.gvsig.tools.swing.api.pickercontroller.FolderPickerController; |
||
55 | 1894 | jjdelcerro | import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
56 | 1758 | jjdelcerro | import org.gvsig.tools.swing.icontheme.IconTheme; |
57 | import org.gvsig.tools.swing.icontheme.IconThemeManager; |
||
58 | 1538 | fdiaz | import org.gvsig.tools.swing.impl.bufferedImage.VirtualBufferedImageHelper; |
59 | import org.gvsig.tools.swing.impl.bufferedImage.VirtualBufferedImageHelper.VirtualDataBuffer; |
||
60 | 1894 | jjdelcerro | import org.gvsig.tools.swing.impl.pickercontroller.BytearrayPickerControllerImpl; |
61 | 1746 | jjdelcerro | import org.gvsig.tools.swing.impl.pickercontroller.ColorPickerControllerImpl; |
62 | import org.gvsig.tools.swing.impl.pickercontroller.DatePickerControllerImpl; |
||
63 | import org.gvsig.tools.swing.impl.pickercontroller.FilePickerControllerImpl; |
||
64 | import org.gvsig.tools.swing.impl.pickercontroller.FolderPickerControllerImpl; |
||
65 | 1251 | jjdelcerro | |
66 | |||
67 | public class DefaultToolsSwingManager implements ToolsSwingManager { |
||
68 | |||
69 | 1530 | fdiaz | private Dimension maxPhysicalSizeOfBufferedImage; |
70 | |||
71 | 1377 | jjdelcerro | @Override
|
72 | 1251 | jjdelcerro | public ActionListenerSupport createActionListenerSupport() {
|
73 | return new DefaultActionListenerSupport(); |
||
74 | } |
||
75 | 1377 | jjdelcerro | |
76 | @Override
|
||
77 | public JListWithCheckbox createJListWithCheckbox(JList wrappedList) { |
||
78 | return new DefaultJListWithCheckbox(wrappedList); |
||
79 | } |
||
80 | |||
81 | @Override
|
||
82 | public void setTreeModel(JComboBox comboBox, TreeModel aTreeModel) { |
||
83 | TreeComboUtils.setTreeModel(comboBox, aTreeModel); |
||
84 | } |
||
85 | 1530 | fdiaz | |
86 | 1538 | fdiaz | @Override
|
87 | 1424 | jjdelcerro | public ComboBoxModel createComboBoxModel(TreeModel treeModel) { |
88 | return TreeComboUtils.createComboBoxModel(treeModel);
|
||
89 | 1530 | fdiaz | } |
90 | |||
91 | |||
92 | 1538 | fdiaz | @Override
|
93 | 1530 | fdiaz | public BufferedImage createBufferedImage(int w, int h, int type) { |
94 | if(getMaxPhysicalSizeOfBufferedImage().getWidth() < w || getMaxPhysicalSizeOfBufferedImage().getHeight() < h){
|
||
95 | return createVirtualBufferedImage(w,h,type);
|
||
96 | } |
||
97 | return new BufferedImage(w,h,type); |
||
98 | } |
||
99 | |||
100 | 1538 | fdiaz | @Override
|
101 | 1530 | fdiaz | public BufferedImage createVirtualBufferedImage(int w, int h, int type) { |
102 | 1538 | fdiaz | return VirtualBufferedImageHelper.createVirtualBufferedImage(w, h, type);
|
103 | 1530 | fdiaz | } |
104 | |||
105 | 1538 | fdiaz | @Override
|
106 | 1530 | fdiaz | public BufferedImage copyBufferedImage(BufferedImage img) { |
107 | WritableRaster sourceRaster = img.getRaster();
|
||
108 | |||
109 | BufferedImage newImage;
|
||
110 | 1538 | fdiaz | if(sourceRaster.getDataBuffer() instanceof VirtualDataBuffer ){ |
111 | newImage = VirtualBufferedImageHelper.createVirtualBufferedImage( |
||
112 | 1692 | fdiaz | img.getWidth(), |
113 | img.getHeight(), |
||
114 | img.getSampleModel(), |
||
115 | 1538 | fdiaz | img.getColorModel() |
116 | ); |
||
117 | 1530 | fdiaz | } else {
|
118 | newImage = createBufferedImage(img.getWidth(), img.getHeight(), img.getType()); |
||
119 | } |
||
120 | |||
121 | WritableRaster raster = newImage.getRaster();
|
||
122 | img.copyData(raster); |
||
123 | return newImage;
|
||
124 | } |
||
125 | |||
126 | @Override
|
||
127 | public void setMaxPhysicalSizeOfBufferedImage(Dimension dimension) { |
||
128 | this.maxPhysicalSizeOfBufferedImage = dimension;
|
||
129 | } |
||
130 | |||
131 | @Override
|
||
132 | public Dimension getMaxPhysicalSizeOfBufferedImage() { |
||
133 | if(this.maxPhysicalSizeOfBufferedImage == null){ |
||
134 | this.maxPhysicalSizeOfBufferedImage = new Dimension(2000, 2000); |
||
135 | } |
||
136 | return this.maxPhysicalSizeOfBufferedImage; |
||
137 | } |
||
138 | |||
139 | 1610 | jjdelcerro | @Override
|
140 | public ColorChooserController createColorChooserController(JTextField txtLabel, JButton btnShowDialog, JSlider sldAlpha, boolean allowNull) { |
||
141 | return new DefaultColorChooserController(txtLabel, btnShowDialog, sldAlpha, allowNull); |
||
142 | } |
||
143 | 1530 | fdiaz | |
144 | 1610 | jjdelcerro | @Override
|
145 | public ColorChooserController createColorChooserController(JTextField txtLabel, JButton btnShowDialog) { |
||
146 | return new DefaultColorChooserController(txtLabel, btnShowDialog); |
||
147 | } |
||
148 | |||
149 | @Override
|
||
150 | public ColorChooserController createColorChooserController(JTextField txtLabel, JButton btnShowDialog, JSlider sldAlpha) { |
||
151 | return new DefaultColorChooserController(txtLabel, btnShowDialog, sldAlpha); |
||
152 | } |
||
153 | |||
154 | 1628 | jjdelcerro | @Override
|
155 | public Color alphaBlendingWithOpaqueBackground(Color bgColor, Color fgColor) { |
||
156 | 1632 | jjdelcerro | // https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
|
157 | 1628 | jjdelcerro | Color src = fgColor;
|
158 | Color dst = bgColor;
|
||
159 | |||
160 | // double outa = 1;
|
||
161 | double srca = src.getAlpha() / 255.0; |
||
162 | double srca_1 = (1 - srca); |
||
163 | |||
164 | Color color = new Color( |
||
165 | (int)(src.getRed() * srca + dst.getRed() * srca_1) & 0xff, |
||
166 | (int)(src.getGreen()* srca + dst.getGreen()* srca_1) & 0xff, |
||
167 | (int)(src.getBlue() * srca + dst.getBlue() * srca_1) & 0xff |
||
168 | ); |
||
169 | 1692 | fdiaz | return color;
|
170 | 1628 | jjdelcerro | } |
171 | 1692 | fdiaz | |
172 | 1632 | jjdelcerro | @Override
|
173 | public Color opaqueColor(Color src) { |
||
174 | // https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
|
||
175 | double srca = src.getAlpha() / 255.0; |
||
176 | double srca_1 = (1 - srca); |
||
177 | |||
178 | Color color = new Color( |
||
179 | (int)(src.getRed() * srca + 255 * srca_1) & 0xff, |
||
180 | (int)(src.getGreen()* srca + 255 * srca_1) & 0xff, |
||
181 | (int)(src.getBlue() * srca + 255 * srca_1) & 0xff |
||
182 | ); |
||
183 | return color;
|
||
184 | } |
||
185 | 1640 | jjdelcerro | |
186 | 1746 | jjdelcerro | private Object call(Object obj, String name, Object... params) { |
187 | Class[] types = null; |
||
188 | if( params != null ) { |
||
189 | types = new Class[params.length]; |
||
190 | for (int i = 0; i < params.length; i++) { |
||
191 | types[i] = params[i].getClass(); |
||
192 | } |
||
193 | } |
||
194 | Method method;
|
||
195 | try {
|
||
196 | method = obj.getClass().getMethod(name, types); |
||
197 | Object r = method.invoke(obj, params);
|
||
198 | return r;
|
||
199 | } catch (NoSuchMethodException | |
||
200 | SecurityException |
|
||
201 | IllegalAccessException |
|
||
202 | IllegalArgumentException |
|
||
203 | InvocationTargetException ex) {
|
||
204 | } |
||
205 | return null; |
||
206 | } |
||
207 | |||
208 | 1640 | jjdelcerro | @Override
|
209 | 1746 | jjdelcerro | public void translate(JComponent component) { |
210 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
211 | String s = (String) call(component, "getText", (Object[]) null); |
||
212 | if( !StringUtils.isEmpty(s) ) {
|
||
213 | call(component,"setText",i18n.getTranslation(s));
|
||
214 | } |
||
215 | s = (String) call(component, "getToolTipText", (Object[]) null); |
||
216 | if( !StringUtils.isEmpty(s) ) {
|
||
217 | call(component,"setToolTipText",i18n.getTranslation(s));
|
||
218 | } |
||
219 | } |
||
220 | |||
221 | @Override
|
||
222 | 1640 | jjdelcerro | public void translate(AbstractButton component) { |
223 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
224 | 1644 | jjdelcerro | String s = component.getText();
|
225 | if( !StringUtils.isEmpty(s) ) {
|
||
226 | component.setText(i18n.getTranslation(s)); |
||
227 | } |
||
228 | s = component.getToolTipText(); |
||
229 | if( !StringUtils.isEmpty(s) ) {
|
||
230 | 1683 | jjdelcerro | component.setToolTipText(i18n.getTranslation(s)); |
231 | 1644 | jjdelcerro | } |
232 | 1640 | jjdelcerro | } |
233 | |||
234 | @Override
|
||
235 | public void translate(JLabel component) { |
||
236 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
237 | 1644 | jjdelcerro | String s = component.getText();
|
238 | if( !StringUtils.isEmpty(s) ) {
|
||
239 | component.setText(i18n.getTranslation(s)); |
||
240 | } |
||
241 | s = component.getToolTipText(); |
||
242 | if( !StringUtils.isEmpty(s) ) {
|
||
243 | 1683 | jjdelcerro | component.setToolTipText(i18n.getTranslation(s)); |
244 | 1644 | jjdelcerro | } |
245 | 1640 | jjdelcerro | } |
246 | 1692 | fdiaz | |
247 | 1746 | jjdelcerro | @Override
|
248 | 1683 | jjdelcerro | public void translate(JTabbedPane component) { |
249 | I18nManager i18n = ToolsLocator.getI18nManager(); |
||
250 | 1692 | fdiaz | |
251 | 1683 | jjdelcerro | for( int i=0; i<component.getTabCount(); i++) { |
252 | String text = component.getTitleAt(i);
|
||
253 | if( !StringUtils.isEmpty(text) ) {
|
||
254 | component.setTitleAt(i, i18n.getTranslation(text)); |
||
255 | } |
||
256 | text = component.getToolTipTextAt(i); |
||
257 | if( !StringUtils.isEmpty(text) ) {
|
||
258 | component.setToolTipTextAt(i, i18n.getTranslation(text)); |
||
259 | } |
||
260 | } |
||
261 | 1692 | fdiaz | } |
262 | 1698 | jjdelcerro | |
263 | @Override
|
||
264 | public void setDefaultPopupMenu(final JTextComponent component) { |
||
265 | this.setDefaultPopupMenu(component, null); |
||
266 | } |
||
267 | |||
268 | @Override
|
||
269 | public void setDefaultPopupMenu(final JTextComponent component, String title) { |
||
270 | JPopupMenu popupMenu = new JPopupMenu(); |
||
271 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
272 | |||
273 | Action copyAction = component.getActionMap().get(DefaultEditorKit.copyAction); |
||
274 | Action cutAction = component.getActionMap().get(DefaultEditorKit.cutAction); |
||
275 | Action pasteAction = component.getActionMap().get(DefaultEditorKit.pasteAction); |
||
276 | Action selectAllAction = component.getActionMap().get(DefaultEditorKit.selectAllAction); |
||
277 | |||
278 | if (copyAction == null |
||
279 | && cutAction == null
|
||
280 | && pasteAction == null
|
||
281 | && selectAllAction == null) {
|
||
282 | copyAction = component.getActionMap().get(i18nManager.getTranslation("copy"));
|
||
283 | cutAction = component.getActionMap().get(i18nManager.getTranslation("cut"));
|
||
284 | pasteAction = component.getActionMap().get(i18nManager.getTranslation("paste"));
|
||
285 | selectAllAction = component.getActionMap().get(i18nManager.getTranslation("SelectAll"));
|
||
286 | } else {
|
||
287 | copyAction.putValue(Action.NAME, i18nManager.getTranslation("copy")); |
||
288 | cutAction.putValue(Action.NAME, i18nManager.getTranslation("cut")); |
||
289 | pasteAction.putValue(Action.NAME, i18nManager.getTranslation("paste")); |
||
290 | selectAllAction.putValue(Action.NAME, i18nManager.getTranslation("SelectAll")); |
||
291 | } |
||
292 | |||
293 | final String title2; |
||
294 | if( title == null ) { |
||
295 | title2 = i18nManager.getTranslation("text_editor");
|
||
296 | } else {
|
||
297 | title2 = title; |
||
298 | } |
||
299 | Action textEditorAction = new AbstractAction(i18nManager.getTranslation("text_editor")) { |
||
300 | @Override
|
||
301 | public void actionPerformed(ActionEvent e) { |
||
302 | 1867 | jjdelcerro | DefaultZoomDialog dialog = new DefaultZoomDialog(component, title2, component.getText());
|
303 | 1698 | jjdelcerro | dialog.setEditable(component.isEditable()); |
304 | dialog.setAlwaysOnTop(true);
|
||
305 | dialog.setVisible(true);
|
||
306 | if (component.isEditable() && component.isEnabled()) {
|
||
307 | component.setText(dialog.getText()); |
||
308 | } |
||
309 | } |
||
310 | }; |
||
311 | 1772 | jjdelcerro | final JMenuItem menuCut = new JMenuItem(cutAction); |
312 | final JMenuItem menuPaste = new JMenuItem(pasteAction); |
||
313 | |||
314 | 1698 | jjdelcerro | popupMenu.add(textEditorAction); |
315 | popupMenu.addSeparator(); |
||
316 | |||
317 | 1772 | jjdelcerro | popupMenu.add(menuCut); |
318 | 1698 | jjdelcerro | popupMenu.add(copyAction); |
319 | 1772 | jjdelcerro | popupMenu.add(menuPaste); |
320 | 1698 | jjdelcerro | popupMenu.add(selectAllAction); |
321 | 1772 | jjdelcerro | |
322 | if( component.isEnabled() && component.isEditable() ) {
|
||
323 | menuCut.setEnabled(true);
|
||
324 | menuPaste.setEnabled(true);
|
||
325 | } else {
|
||
326 | menuCut.setEnabled(false);
|
||
327 | menuPaste.setEnabled(false);
|
||
328 | } |
||
329 | component.addPropertyChangeListener(new PropertyChangeListener() { |
||
330 | @Override
|
||
331 | public void propertyChange(PropertyChangeEvent evt) { |
||
332 | if( evt==null ) { |
||
333 | return;
|
||
334 | } |
||
335 | if( evt.getPropertyName().equalsIgnoreCase("enabled") ) { |
||
336 | boolean enabled = component.isEnabled();
|
||
337 | menuCut.setEnabled(enabled); |
||
338 | menuPaste.setEnabled(enabled); |
||
339 | } else if( evt.getPropertyName().equalsIgnoreCase("editable") ) { |
||
340 | boolean editable = component.isEditable();
|
||
341 | menuCut.setEnabled(editable); |
||
342 | menuPaste.setEnabled(editable); |
||
343 | } |
||
344 | } |
||
345 | }); |
||
346 | 1698 | jjdelcerro | component.setComponentPopupMenu(popupMenu); |
347 | } |
||
348 | |||
349 | @Override
|
||
350 | public void setDefaultPopupMenu(JComboBox component) { |
||
351 | this.setDefaultPopupMenu((JTextComponent) component.getEditor().getEditorComponent(), null); |
||
352 | } |
||
353 | |||
354 | |||
355 | @Override
|
||
356 | public void setDefaultPopupMenu(JComboBox component, String title) { |
||
357 | this.setDefaultPopupMenu((JTextComponent) component.getEditor().getEditorComponent(), title); |
||
358 | } |
||
359 | 1746 | jjdelcerro | |
360 | @Override
|
||
361 | public ChangeListenerHelper createChangeListenerHelper() {
|
||
362 | DefaultChangeListenerHelper x = new DefaultChangeListenerHelper();
|
||
363 | return x;
|
||
364 | } |
||
365 | |||
366 | @Override
|
||
367 | public ColorPickerController createColorPickerController(JTextField txtLabel, JButton btnShowDialog, JSlider sldAlpha, boolean allowNull) { |
||
368 | return new ColorPickerControllerImpl(txtLabel, btnShowDialog, sldAlpha, allowNull); |
||
369 | } |
||
370 | |||
371 | @Override
|
||
372 | public ColorPickerController createColorPickerController(JTextField txtLabel, JButton btnShowDialog) { |
||
373 | return new ColorPickerControllerImpl(txtLabel, btnShowDialog); |
||
374 | } |
||
375 | |||
376 | @Override
|
||
377 | public ColorPickerController createColorPickerController(JTextField txtLabel, JButton btnShowDialog, JSlider sldAlpha) { |
||
378 | return new ColorPickerControllerImpl(txtLabel, btnShowDialog, sldAlpha); |
||
379 | } |
||
380 | |||
381 | @Override
|
||
382 | public DatePickerController createDatePickerController(JTextField txtDate, JButton btnDate) { |
||
383 | return new DatePickerControllerImpl(txtDate, btnDate); |
||
384 | } |
||
385 | |||
386 | @Override
|
||
387 | public FilePickerController createFilePickerController(JTextField txtFile, JButton btnFile, String dialogTitle, String fileChooserID, File initialPath, boolean seticon) { |
||
388 | return new FilePickerControllerImpl(txtFile, btnFile, dialogTitle, fileChooserID, initialPath, seticon); |
||
389 | } |
||
390 | |||
391 | @Override
|
||
392 | public FilePickerController createFilePickerController(JTextField txtFile, JButton btnFile) { |
||
393 | return new FilePickerControllerImpl(txtFile, btnFile); |
||
394 | } |
||
395 | |||
396 | @Override
|
||
397 | 1894 | jjdelcerro | public PickerController<byte[]> createByteArrayPickerController(JTextField txtText, JButton btnUpload, JButton btnDownload, String fileChooserID, File initialPath) { |
398 | return new BytearrayPickerControllerImpl(txtText, btnUpload, btnDownload,fileChooserID, initialPath); |
||
399 | } |
||
400 | |||
401 | @Override
|
||
402 | public PickerController<byte[]> createByteArrayPickerController(JTextField txtText, JButton btnUpload, JButton btnDownload) { |
||
403 | return new BytearrayPickerControllerImpl(txtText, btnUpload, btnDownload, null, null); |
||
404 | } |
||
405 | |||
406 | @Override
|
||
407 | 1746 | jjdelcerro | public FilePickerController createFilePickerController(JTextField txtFile, JButton btnFile, String dialogTitle) { |
408 | return new FilePickerControllerImpl(txtFile, btnFile, dialogTitle); |
||
409 | } |
||
410 | |||
411 | @Override
|
||
412 | public FolderPickerController createFolderPickerController(JTextField txtFile, JButton btnFile, String dialogTitle, String fileChooserID, File initialPath, boolean seticon) { |
||
413 | return new FolderPickerControllerImpl(txtFile, btnFile, dialogTitle, fileChooserID, initialPath, seticon); |
||
414 | } |
||
415 | |||
416 | @Override
|
||
417 | public FolderPickerController createFolderPickerController(JTextField txtFile, JButton btnFile) { |
||
418 | return new FolderPickerControllerImpl(txtFile, btnFile); |
||
419 | } |
||
420 | |||
421 | @Override
|
||
422 | public FolderPickerController createFolderPickerController(JTextField txtFile, JButton btnFile, String dialogTitle) { |
||
423 | return new FolderPickerControllerImpl(txtFile, btnFile,dialogTitle); |
||
424 | } |
||
425 | 1750 | jjdelcerro | |
426 | @Override
|
||
427 | public void removeBorder(JComponent component) { |
||
428 | try {
|
||
429 | component.setBorder(null);
|
||
430 | JComponent p1 = (JComponent) component.getParent(); |
||
431 | if( p1 instanceof JViewport ) { |
||
432 | p1 = (JComponent) component.getParent();
|
||
433 | } |
||
434 | if( p1 instanceof JScrollPane ) { |
||
435 | JScrollPane scrollPanel = (JScrollPane) component.getParent(); |
||
436 | scrollPanel.setBorder(null);
|
||
437 | } |
||
438 | } catch(Exception ex) { |
||
439 | |||
440 | } |
||
441 | } |
||
442 | 1758 | jjdelcerro | |
443 | protected ImageIcon getIcon(String name) { |
||
444 | IconThemeManager iconThemeManager = ToolsSwingLocator.getIconThemeManager(); |
||
445 | IconTheme theme = iconThemeManager.getCurrent(); |
||
446 | ImageIcon icon = theme.get(name);
|
||
447 | return icon;
|
||
448 | } |
||
449 | |||
450 | @Override
|
||
451 | 1796 | jjdelcerro | public void addClearButton(JTextComponent text) { |
452 | 1758 | jjdelcerro | this.addClearButton(text, null); |
453 | } |
||
454 | |||
455 | @Override
|
||
456 | 1862 | jjdelcerro | public void addClearButton(JComboBox combo) { |
457 | try {
|
||
458 | JTextComponent text = (JTextComponent) combo.getEditor().getEditorComponent(); |
||
459 | this.addClearButton(text, null); |
||
460 | } catch(Throwable th) { |
||
461 | // Si no puede a?adir el boton no hace nada.
|
||
462 | } |
||
463 | } |
||
464 | |||
465 | @Override
|
||
466 | 1796 | jjdelcerro | public void addClearButton(final JTextComponent text, final ActionListener action) { |
467 | 1772 | jjdelcerro | final JButton btnClear = new JButton(getIcon("picker-cleartext")); |
468 | 1758 | jjdelcerro | btnClear.setBorderPainted( false );
|
469 | btnClear.setFocusPainted( false );
|
||
470 | btnClear.setContentAreaFilled( false );
|
||
471 | btnClear.setOpaque(false);
|
||
472 | 1808 | jjdelcerro | btnClear.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
473 | 1758 | jjdelcerro | if( action == null ) { |
474 | btnClear.addActionListener(new ActionListener() { |
||
475 | @Override
|
||
476 | public void actionPerformed(ActionEvent e) { |
||
477 | text.setText("");
|
||
478 | } |
||
479 | }); |
||
480 | } else {
|
||
481 | btnClear.addActionListener(action); |
||
482 | } |
||
483 | text.setLayout(new BorderLayout()); |
||
484 | text.add(btnClear, BorderLayout.EAST);
|
||
485 | 1772 | jjdelcerro | text.addPropertyChangeListener(new PropertyChangeListener() { |
486 | @Override
|
||
487 | public void propertyChange(PropertyChangeEvent evt) { |
||
488 | 1862 | jjdelcerro | if( evt==null ) { |
489 | return;
|
||
490 | } |
||
491 | if( evt.getPropertyName().equalsIgnoreCase("enabled") ) { |
||
492 | 1772 | jjdelcerro | boolean enabled = text.isEnabled();
|
493 | btnClear.setEnabled(enabled); |
||
494 | 1862 | jjdelcerro | } else if( evt.getPropertyName().equalsIgnoreCase("editable") ) { |
495 | boolean editable = text.isEditable();
|
||
496 | btnClear.setEnabled(editable); |
||
497 | 1772 | jjdelcerro | } |
498 | } |
||
499 | }); |
||
500 | 1758 | jjdelcerro | } |
501 | 1840 | jjdelcerro | |
502 | @Override
|
||
503 | public SimpleImage createSimpleImage() {
|
||
504 | SimpleImage x = new DefaultSimpleImage();
|
||
505 | return x;
|
||
506 | } |
||
507 | |||
508 | @Override
|
||
509 | public SimpleImage createSimpleImage(Object source) { |
||
510 | SimpleImage x = new DefaultSimpleImage(source);
|
||
511 | return x;
|
||
512 | } |
||
513 | 1884 | jjdelcerro | |
514 | @Override
|
||
515 | public DropDown createDropDown(JComboBox combo) { |
||
516 | DropDown c = new DropDownComboBox(combo);
|
||
517 | return c;
|
||
518 | } |
||
519 | |||
520 | @Override
|
||
521 | public DropDown createDropDown(JLabel label) { |
||
522 | DropDown c = new DropDownLabel(label);
|
||
523 | return c;
|
||
524 | } |
||
525 | 1947 | jjdelcerro | |
526 | @Override
|
||
527 | public CompoundIcon createCompoundIcon(Icon... icons) { |
||
528 | DefaultCompoundIcon i = new DefaultCompoundIcon(icons);
|
||
529 | return i;
|
||
530 | } |
||
531 | |||
532 | @Override
|
||
533 | public CompoundIcon createCompoundIcon(int orientation, Icon... icons) { |
||
534 | DefaultCompoundIcon i = new DefaultCompoundIcon(orientation, icons);
|
||
535 | return i;
|
||
536 | } |
||
537 | |||
538 | @Override
|
||
539 | public CompoundIcon createCompoundIcon(int orientation, int gap, Icon... icons) { |
||
540 | DefaultCompoundIcon i = new DefaultCompoundIcon(orientation, gap, icons);
|
||
541 | return i;
|
||
542 | } |
||
543 | |||
544 | @Override
|
||
545 | public CompoundIcon createCompoundIcon(int orientation, int gap, int alignmentX, int alignmentY, Icon... icons) { |
||
546 | DefaultCompoundIcon i = new DefaultCompoundIcon(orientation, gap, alignmentX, alignmentY, icons);
|
||
547 | return i;
|
||
548 | } |
||
549 | 1840 | jjdelcerro | |
550 | 1251 | jjdelcerro | } |