root / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / SingleLabelingConfigPanel.java @ 20768
History | View | Annotate | Download (5.91 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.symbology.gui; |
42 |
|
43 |
import java.awt.BasicStroke; |
44 |
import java.awt.BorderLayout; |
45 |
import java.awt.Color; |
46 |
import java.awt.Dimension; |
47 |
import java.awt.Graphics; |
48 |
import java.awt.Graphics2D; |
49 |
import java.awt.Rectangle; |
50 |
import java.awt.event.ActionEvent; |
51 |
import java.awt.event.ActionListener; |
52 |
import java.util.Date; |
53 |
|
54 |
import javax.swing.JPanel; |
55 |
|
56 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
57 |
import org.gvsig.symbology.fmap.labeling.GeneralLabelingStrategy; |
58 |
import org.gvsig.symbology.fmap.labeling.OnSelectionLabeled; |
59 |
import org.gvsig.symbology.fmap.labeling.PlacementManager; |
60 |
import org.gvsig.symbology.gui.styling.LabelClassRenderingProperties; |
61 |
|
62 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
63 |
import com.hardcode.gdbms.engine.data.DataSource; |
64 |
import com.iver.andami.PluginServices; |
65 |
import com.iver.andami.messages.NotificationManager; |
66 |
import com.iver.andami.ui.mdiManager.IWindow; |
67 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
68 |
import com.iver.cit.gvsig.fmap.core.ILabelable; |
69 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
70 |
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException; |
71 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
72 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
73 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass; |
74 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelingFactory; |
75 |
|
76 |
public class SingleLabelingConfigPanel extends JPanel implements IWindow, ActionListener { |
77 |
private static final long serialVersionUID = 211912532798765584L; |
78 |
private static LabelClass TheLabelToBeUsed; |
79 |
private LabelClass clonedClass;
|
80 |
private LabelClassRenderingProperties properties;
|
81 |
private JPanel preview; |
82 |
private WindowInfo wii;
|
83 |
private ILabelable labelableElement;
|
84 |
|
85 |
public SingleLabelingConfigPanel(ILabelable labelableElement) throws ReadDriverException { |
86 |
this.labelableElement = labelableElement;
|
87 |
setLayout(new BorderLayout(5, 15)); |
88 |
String[] fieldNames = new String[] {}; |
89 |
|
90 |
clonedClass = LabelingFactory.createLabelClassFromXML(getLabelClass().getXMLEntity()); |
91 |
if (labelableElement instanceof FLyrVect) { |
92 |
DataSource sds = ((FLyrVect) labelableElement).getRecordset();
|
93 |
fieldNames = sds.getFieldNames(); |
94 |
|
95 |
} |
96 |
add(properties = new LabelClassRenderingProperties(), BorderLayout.CENTER); |
97 |
JPanel aux = new JPanel(); |
98 |
aux.add(preview = new JPanel() { |
99 |
private static final long serialVersionUID = 3788548343944220354L; |
100 |
|
101 |
@Override
|
102 |
protected void paintComponent(Graphics g) { |
103 |
Rectangle r = getBounds();
|
104 |
r.setLocation(0, 0); |
105 |
g.setColor(Color.white);
|
106 |
((Graphics2D) g).fill(r);
|
107 |
((Graphics2D) g).setStroke(new BasicStroke(2)); |
108 |
g.setColor(Color.black);
|
109 |
((Graphics2D) g).draw(r);
|
110 |
|
111 |
try {
|
112 |
getLabelClass().drawInsideRectangle((Graphics2D) g, r);
|
113 |
} catch (SymbolDrawingException e) {
|
114 |
SymbologyFactory.getWarningSymbol( |
115 |
PluginServices.getText(this, "cant_draw_preview"), |
116 |
SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS, |
117 |
SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS); |
118 |
} |
119 |
} |
120 |
|
121 |
}); |
122 |
add(aux, BorderLayout.NORTH);
|
123 |
preview.setPreferredSize(new Dimension(300, 200)); |
124 |
|
125 |
properties.setFieldNames(fieldNames); |
126 |
properties.setModel(clonedClass); |
127 |
|
128 |
add(new AcceptCancelPanel(this, this), BorderLayout.SOUTH); |
129 |
} |
130 |
|
131 |
public LabelClass getLabelClass() {
|
132 |
if (TheLabelToBeUsed == null) { |
133 |
TheLabelToBeUsed = new LabelClass();
|
134 |
TheLabelToBeUsed.setTextSymbol(SymbologyFactory.createDefaultTextSymbol()); |
135 |
TheLabelToBeUsed.getTextSymbol().setFontSize(14);
|
136 |
TheLabelToBeUsed.setTexts(new String[] {"Text"}); |
137 |
|
138 |
} |
139 |
return TheLabelToBeUsed;
|
140 |
} |
141 |
|
142 |
public WindowInfo getWindowInfo() {
|
143 |
if (wii == null) { |
144 |
wii = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
|
145 |
wii.setTitle(PluginServices.getText(this, "simple_labeling")); |
146 |
wii.setWidth(630);
|
147 |
wii.setHeight(400);
|
148 |
} |
149 |
return wii;
|
150 |
} |
151 |
|
152 |
public void actionPerformed(ActionEvent e) { |
153 |
if ("OK".equals(e.getActionCommand())) { |
154 |
TheLabelToBeUsed = clonedClass; |
155 |
GeneralLabelingStrategy gls = new GeneralLabelingStrategy();
|
156 |
OnSelectionLabeled osl = new OnSelectionLabeled();
|
157 |
osl.setDefaultLabelClass(TheLabelToBeUsed); |
158 |
gls.setLabelingMethod(osl); |
159 |
labelableElement.setLabelingStrategy(gls); |
160 |
try {
|
161 |
gls.setPlacementConstraints(PlacementManager.createPlacementConstraints(((FLyrVect) labelableElement).getShapeType())); |
162 |
gls.setLayer((FLayer) labelableElement); |
163 |
} catch (ReadDriverException e1) {
|
164 |
NotificationManager.addError(PluginServices.getText(this, "could_not_set_labeling_to_labelable_element")+" "+ |
165 |
labelableElement.getClass()+" "+ new Date(System.currentTimeMillis()).toString(), e1); |
166 |
} |
167 |
} else if ("CANCEL".equals(e.getActionCommand())) { |
168 |
|
169 |
} |
170 |
|
171 |
PluginServices.getMDIManager().closeWindow(this);
|
172 |
} |
173 |
} |