Revision 47375
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.api/src/main/java/org/gvsig/symbology/swing/SymbologySwingManager.java | ||
---|---|---|
26 | 26 |
import java.util.Collection; |
27 | 27 |
import java.util.List; |
28 | 28 |
import javax.swing.Action; |
29 |
import javax.swing.JButton; |
|
30 |
import javax.swing.text.JTextComponent; |
|
29 | 31 |
import org.gvsig.app.gui.labeling.LabelClassEditor; |
30 | 32 |
import org.gvsig.app.gui.labeling.LabelClassEditorFactory; |
31 | 33 |
import org.gvsig.app.gui.styling.TypeSymbolEditor; |
... | ... | |
35 | 37 |
import org.gvsig.fmap.geom.type.GeometryType; |
36 | 38 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 | 39 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
38 |
|
|
40 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
39 | 41 |
import org.gvsig.gui.ColorTablePainter; |
40 | 42 |
import org.gvsig.gui.ColorTablesFactory; |
41 | 43 |
import org.gvsig.symbology.SymbologyManager; |
44 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
|
42 | 45 |
|
43 | 46 |
/** |
44 | 47 |
* This class is responsible of the management of the library's swing user |
... | ... | |
121 | 124 |
public Iterable<Action> getOptionalActionOfLegendsPanel(); |
122 | 125 |
|
123 | 126 |
public void addOptionalActionToLegendsPanel(Action action); |
127 |
|
|
128 |
public PickerController<ISymbol> createSymbolPickerController(JButton btn, ISymbol symbol); |
|
129 |
|
|
130 |
public PickerController<ISymbol> createSymbolPickerController(JButton btnPreview, JTextComponent txtDescription, int geomType, ISymbol symbol); |
|
131 |
|
|
124 | 132 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.impl/src/main/java/org/gvsig/symbology/swing/impl/DefaultSymbologySwingManager.java | ||
---|---|---|
29 | 29 |
import java.util.Iterator; |
30 | 30 |
import java.util.List; |
31 | 31 |
import java.util.Map; |
32 |
|
|
33 | 32 |
import javax.swing.Action; |
34 |
|
|
35 |
import org.slf4j.Logger; |
|
36 |
import org.slf4j.LoggerFactory; |
|
37 |
|
|
33 |
import javax.swing.JButton; |
|
34 |
import javax.swing.text.JTextComponent; |
|
38 | 35 |
import org.gvsig.app.gui.labeling.LabelClassEditor; |
39 | 36 |
import org.gvsig.app.gui.labeling.LabelClassEditorFactory; |
40 | 37 |
import org.gvsig.app.gui.styling.TypeSymbolEditor; |
... | ... | |
44 | 41 |
import org.gvsig.fmap.geom.type.GeometryType; |
45 | 42 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
46 | 43 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
44 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
47 | 45 |
import org.gvsig.gui.ColorTablePainter; |
48 | 46 |
import org.gvsig.gui.ColorTablesFactory; |
49 | 47 |
import org.gvsig.gui.DefaultColorTablesFactory; |
... | ... | |
51 | 49 |
import org.gvsig.symbology.SymbologyManager; |
52 | 50 |
import org.gvsig.symbology.swing.SymbologySwingManager; |
53 | 51 |
import org.gvsig.symbology.swing.SymbologyWindowManager; |
52 |
import org.gvsig.symbology.swing.impl.pickercontroller.SymbolPickerController; |
|
54 | 53 |
import org.gvsig.tools.ToolsLocator; |
55 | 54 |
import org.gvsig.tools.i18n.I18nManager; |
55 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
|
56 |
import org.slf4j.Logger; |
|
57 |
import org.slf4j.LoggerFactory; |
|
56 | 58 |
|
57 | 59 |
/** |
58 | 60 |
* Default implementation of the {@link SymbologySwingManager}. |
... | ... | |
288 | 290 |
} |
289 | 291 |
this.optionalActionsOfLegendsPanel.add(action); |
290 | 292 |
} |
293 |
|
|
294 |
@Override |
|
295 |
public PickerController<ISymbol> createSymbolPickerController(JButton btn, ISymbol symbol) { |
|
296 |
return new SymbolPickerController(btn, null, -1, symbol); |
|
297 |
} |
|
291 | 298 |
|
299 |
@Override |
|
300 |
public PickerController<ISymbol> createSymbolPickerController(JButton btnPreview, JTextComponent txtDescription, int geomType, ISymbol symbol) { |
|
301 |
return new SymbolPickerController(btnPreview, txtDescription, geomType, symbol); |
|
302 |
} |
|
303 |
|
|
292 | 304 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.impl/src/main/java/org/gvsig/symbology/swing/impl/pickercontroller/SymbolPickerController.java | ||
---|---|---|
1 |
package org.gvsig.symbology.swing.impl.pickercontroller; |
|
2 |
|
|
3 |
import java.awt.Dimension; |
|
4 |
import java.awt.Graphics2D; |
|
5 |
import java.awt.Rectangle; |
|
6 |
import java.awt.event.ActionEvent; |
|
7 |
import java.awt.event.ComponentAdapter; |
|
8 |
import java.awt.event.ComponentEvent; |
|
9 |
import java.awt.geom.AffineTransform; |
|
10 |
import java.awt.image.BufferedImage; |
|
11 |
import javax.swing.BorderFactory; |
|
12 |
import javax.swing.ImageIcon; |
|
13 |
import javax.swing.JButton; |
|
14 |
import javax.swing.JPanel; |
|
15 |
import javax.swing.JTextField; |
|
16 |
import javax.swing.text.JTextComponent; |
|
17 |
import org.gvsig.app.gui.styling.SymbolSelector; |
|
18 |
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector; |
|
19 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
20 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
21 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
|
22 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
23 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
|
24 |
import org.gvsig.tools.swing.api.pickercontroller.AbstractPickerController; |
|
25 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
* @author gvSIG Team |
|
30 |
*/ |
|
31 |
@SuppressWarnings("UseSpecificCatch") |
|
32 |
public class SymbolPickerController extends AbstractPickerController<ISymbol> { |
|
33 |
|
|
34 |
private final JButton btnPreview; |
|
35 |
private final JTextComponent txtDescription; |
|
36 |
private int geomType; |
|
37 |
private ISymbol symbol; |
|
38 |
|
|
39 |
/* |
|
40 |
El tama?o m?nimo del bot?n ser? 22x22 |
|
41 |
Si se quiere otro tama?o, hay que asegurarse de que se fuerza ese tama?o en el gui, |
|
42 |
no delegando en el layout para calcularlo. |
|
43 |
En el Abeille se recomienda: |
|
44 |
- en la pesta?a Cell, fijar Alignment a Horizontal y Vertical a FILL |
|
45 |
- en la pesta?a Column, poner Constant en Column Size con un valor de 22 DLU |
|
46 |
- en la pesta?a Row, poner Constant en Row Size con un valor de 22 DLU |
|
47 |
El valor del Row/Col Constant depender? de los componentes que coexistan |
|
48 |
en la linea o columna del bot?n. |
|
49 |
*/ |
|
50 |
public SymbolPickerController(JButton btnPreview, JTextComponent txtDescription, int geomType, ISymbol symbol) { |
|
51 |
this.btnPreview = btnPreview; |
|
52 |
if( txtDescription==null ) { |
|
53 |
this.txtDescription = new JTextField(); |
|
54 |
} else { |
|
55 |
this.txtDescription = txtDescription; |
|
56 |
} |
|
57 |
|
|
58 |
this.symbol = symbol; |
|
59 |
if (this.symbol == null) { |
|
60 |
this.symbol = MapContextLocator.getSymbolManager().createSymbol(geomType); |
|
61 |
} |
|
62 |
this.btnPreview.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); |
|
63 |
this.btnPreview.setText(""); |
|
64 |
this.btnPreview.addActionListener((ActionEvent e) -> { |
|
65 |
doSelectSymbol(); |
|
66 |
}); |
|
67 |
this.btnPreview.addComponentListener(new ComponentAdapter() { |
|
68 |
@Override |
|
69 |
public void componentResized(ComponentEvent e) { |
|
70 |
updatePreview(); |
|
71 |
} |
|
72 |
}); |
|
73 |
this.set(this.symbol); |
|
74 |
} |
|
75 |
|
|
76 |
private void updatePreview() { |
|
77 |
|
|
78 |
Dimension previewSize = btnPreview.getSize(); |
|
79 |
if(previewSize.width < 22) { |
|
80 |
previewSize.width = 22; |
|
81 |
} |
|
82 |
if(previewSize.height < 22) { |
|
83 |
previewSize.height = 22; |
|
84 |
} |
|
85 |
Dimension size = new Dimension(previewSize.width-4,previewSize.height-4); |
|
86 |
this.btnPreview.setIcon( |
|
87 |
new ImageIcon(this.createPreview(size, this.symbol)) |
|
88 |
); |
|
89 |
} |
|
90 |
|
|
91 |
private BufferedImage createPreview(Dimension size, ISymbol symbol) { |
|
92 |
BufferedImage previewImage = new BufferedImage( |
|
93 |
size.width, |
|
94 |
size.height, |
|
95 |
BufferedImage.TYPE_INT_ARGB |
|
96 |
); |
|
97 |
|
|
98 |
Graphics2D g2 = (Graphics2D) previewImage.createGraphics(); |
|
99 |
if (g2 != null) { |
|
100 |
Rectangle bounds = new Rectangle(size.width, size.height); |
|
101 |
ISymbol prevSymbol = symbol; |
|
102 |
try { |
|
103 |
prevSymbol.drawInsideRectangle(g2, new AffineTransform(), bounds, null); |
|
104 |
} catch (Exception e) { |
|
105 |
try { |
|
106 |
prevSymbol = MapContextLocator.getSymbolManager().getWarningSymbol( |
|
107 |
SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS, |
|
108 |
symbol.getDescription(), |
|
109 |
SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS |
|
110 |
); |
|
111 |
prevSymbol.drawInsideRectangle(g2,g2.getTransform(),bounds,null); |
|
112 |
} catch (Exception e1) { |
|
113 |
LOG.debug("Can't create preview symbol",e1); |
|
114 |
} |
|
115 |
} |
|
116 |
} |
|
117 |
return previewImage; |
|
118 |
} |
|
119 |
|
|
120 |
private void doSelectSymbol() { |
|
121 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
|
122 |
ISymbolSelector sSelect = SymbolSelector.createSymbolSelector(this.symbol, this.geomType); |
|
123 |
|
|
124 |
Dimension desktopPanelSize = ToolsSwingUtils.getDesktopPanelSize(); |
|
125 |
ToolsSwingUtils.ensureHeightWitdh( |
|
126 |
(JPanel) sSelect, |
|
127 |
Math.max(3*(desktopPanelSize.height/4), ToolsSwingUtils.rows2px(80)), |
|
128 |
Math.max(2*(desktopPanelSize.width/4), ToolsSwingUtils.cols2px(35)), |
|
129 |
7*(desktopPanelSize.height/8), |
|
130 |
3*(desktopPanelSize.width/4) |
|
131 |
); |
|
132 |
|
|
133 |
|
|
134 |
wm.showWindow((JPanel) sSelect, sSelect.getWindowInfo().getTitle(), WindowManager.MODE.DIALOG); |
|
135 |
if (sSelect.getSelectedObject() != null) { |
|
136 |
this.symbol = (ISymbol) sSelect.getSelectedObject(); |
|
137 |
this.updatePreview(); |
|
138 |
this.fireChangeEvent(); |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 |
@Override |
|
143 |
public ISymbol get() { |
|
144 |
symbol.setDescription(this.txtDescription.getText()); |
|
145 |
return symbol; |
|
146 |
} |
|
147 |
|
|
148 |
@Override |
|
149 |
public final void set(ISymbol symbol) { |
|
150 |
this.symbol = symbol; |
|
151 |
this.geomType = symbol.getSymbolType(); |
|
152 |
this.txtDescription.setText(this.symbol.getDescription()); |
|
153 |
this.updatePreview(); |
|
154 |
} |
|
155 |
|
|
156 |
@Override |
|
157 |
public void coerceAndSet(Object o) { |
|
158 |
this.set((ISymbol) o); |
|
159 |
} |
|
160 |
|
|
161 |
@Override |
|
162 |
public void setEnabled(boolean enabled) { |
|
163 |
this.btnPreview.setEnabled(enabled); |
|
164 |
this.txtDescription.setEnabled(enabled); |
|
165 |
} |
|
166 |
|
|
167 |
@Override |
|
168 |
public boolean isEnabled() { |
|
169 |
return this.btnPreview.isEnabled(); |
|
170 |
} |
|
171 |
|
|
172 |
} |
Also available in: Unified diff