Revision 11073 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/styling/StyleEditor.java
StyleEditor.java | ||
---|---|---|
42 | 42 |
package com.iver.cit.gvsig.gui.styling; |
43 | 43 |
|
44 | 44 |
import java.awt.BorderLayout; |
45 |
import java.awt.Color; |
|
45 | 46 |
import java.awt.Component; |
46 |
import java.awt.Dimension;
|
|
47 |
import java.awt.Cursor;
|
|
47 | 48 |
import java.awt.FlowLayout; |
49 |
import java.awt.Graphics2D; |
|
50 |
import java.awt.Point; |
|
51 |
import java.awt.Rectangle; |
|
52 |
import java.awt.event.ActionEvent; |
|
53 |
import java.awt.event.ActionListener; |
|
54 |
import java.awt.event.MouseEvent; |
|
55 |
import java.awt.geom.Point2D; |
|
56 |
import java.awt.geom.Rectangle2D; |
|
48 | 57 |
|
49 | 58 |
import javax.swing.BorderFactory; |
50 | 59 |
import javax.swing.BoxLayout; |
51 | 60 |
import javax.swing.ButtonGroup; |
61 |
import javax.swing.ImageIcon; |
|
52 | 62 |
import javax.swing.JLabel; |
53 | 63 |
import javax.swing.JPanel; |
54 | 64 |
import javax.swing.JSeparator; |
... | ... | |
58 | 68 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
59 | 69 |
import org.gvsig.gui.beans.swing.JButton; |
60 | 70 |
|
71 |
import sun.awt.windows.WCustomCursor; |
|
72 |
|
|
61 | 73 |
import com.iver.andami.PluginServices; |
62 | 74 |
import com.iver.andami.ui.mdiManager.IWindow; |
63 | 75 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
76 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
|
77 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
78 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
|
64 | 79 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
65 |
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle; |
|
66 | 80 |
import com.iver.cit.gvsig.fmap.core.styles.IStyle; |
81 |
import com.iver.cit.gvsig.fmap.core.styles.SimpleLabelStyle; |
|
82 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol; |
|
83 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol; |
|
67 | 84 |
|
68 | 85 |
/** |
69 |
* |
|
70 | 86 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
71 |
* |
|
72 | 87 |
*/ |
73 |
/** |
|
74 |
* |
|
75 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
76 |
* |
|
77 |
*/ |
|
78 |
public class StyleEditor extends JPanel implements IWindow { |
|
88 |
public class StyleEditor extends JPanel implements IWindow, ActionListener { |
|
79 | 89 |
|
80 | 90 |
private JPanel pnlNorth = null; |
81 | 91 |
private JPanel jPanel = null; |
... | ... | |
84 | 94 |
private JLabel lblTitle; |
85 | 95 |
private StylePreviewer preview; |
86 | 96 |
private JPanel pnlTools; |
87 |
private JToggleButton btnPan; |
|
88 |
private JToggleButton btnNewTextArea; |
|
89 | 97 |
private JTextField txtDesc; |
90 |
private JButton btnBackground; |
|
98 |
private ActionListener okAction = new ActionListener() { |
|
99 |
public void actionPerformed(ActionEvent e) { |
|
100 |
PluginServices.getMDIManager().closeWindow(StyleEditor.this); |
|
101 |
} |
|
102 |
}; |
|
103 |
private ActionListener cancelAction = new ActionListener() { |
|
104 |
public void actionPerformed(ActionEvent e) { |
|
105 |
getStylePreviewer().setStyle(null); |
|
106 |
PluginServices.getMDIManager().closeWindow(StyleEditor.this); |
|
107 |
}; |
|
108 |
}; |
|
91 | 109 |
|
92 |
|
|
93 | 110 |
public StyleEditor(IStyle style) { |
94 | 111 |
if (style!=null) { |
95 | 112 |
IStyle sty = SymbologyFactory.createStyleFromXML(style.getXMLEntity(), style.getDescription()); |
... | ... | |
156 | 173 |
return pnlCenter; |
157 | 174 |
} |
158 | 175 |
|
176 |
private StylePreviewer getStylePreviewer() { |
|
177 |
if (preview == null) { |
|
178 |
preview = new StylePreviewer(); |
|
179 |
preview.setShowOutline(true); |
|
180 |
} |
|
181 |
|
|
182 |
return preview; |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* This method initializes pnlButtons |
|
187 |
* |
|
188 |
* @return javax.swing.JPanel |
|
189 |
*/ |
|
190 |
private JPanel getPnlButtons() { |
|
191 |
if (pnlButtons == null) { |
|
192 |
pnlButtons = new AcceptCancelPanel(okAction, cancelAction); |
|
193 |
} |
|
194 |
return pnlButtons; |
|
195 |
} |
|
196 |
|
|
197 |
public WindowInfo getWindowInfo() { |
|
198 |
WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE); |
|
199 |
wi.setTitle(PluginServices.getText(this, "edit_style")); |
|
200 |
wi.setWidth(getWidth()+10); |
|
201 |
wi.setHeight(getHeight()); |
|
202 |
return wi; |
|
203 |
} |
|
204 |
|
|
205 |
public IStyle getStyle() { |
|
206 |
return getStylePreviewer().getStyle(); |
|
207 |
} |
|
208 |
|
|
209 |
public void actionPerformed(ActionEvent e) { |
|
210 |
Component c = (Component) e.getSource(); |
|
211 |
if (c.equals(getBtnPan())) { |
|
212 |
getStylePreviewer().setEditorTool(panTool); |
|
213 |
} else if (c.equals(getBtnNewTextArea())) { |
|
214 |
getStylePreviewer().setEditorTool(newTextTool); |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
|
|
219 |
// to be extracted to a specific toolkit class |
|
220 |
private JToggleButton btnPan; |
|
221 |
private JToggleButton btnNewTextArea; |
|
222 |
private JButton btnBackground; |
|
223 |
private EditorTool panTool = new EditorTool(StyleEditor.this) { |
|
224 |
private Cursor cursor; |
|
225 |
private Point pIni, pEnd; |
|
226 |
public Cursor getCursor() { |
|
227 |
if (cursor == null) { |
|
228 |
ImageIcon cursorImage = new ImageIcon(getClass().getClassLoader().getResource("images/Hand.gif")); |
|
229 |
Point p = new Point(cursorImage.getIconWidth()/2, cursorImage.getIconHeight()/2); |
|
230 |
cursor = new WCustomCursor(cursorImage.getImage(), p, "as?dlfk"); |
|
231 |
|
|
232 |
} |
|
233 |
return cursor; |
|
234 |
} |
|
235 |
|
|
236 |
public void mousePressed(MouseEvent e) { |
|
237 |
Rectangle bounds = getStylePreviewer().getBounds(); |
|
238 |
SimpleLabelStyle sty = (SimpleLabelStyle) getStylePreviewer().getStyle(); |
|
239 |
Point2D marker = sty.getMarkerPoint(); |
|
240 |
pIni = new Point((int) (marker.getX()*bounds.width), bounds.height - (int) (marker.getY()*bounds.height)); |
|
241 |
pEnd = e.getPoint(); |
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
public void mouseReleased(MouseEvent e) { |
|
246 |
|
|
247 |
} |
|
248 |
|
|
249 |
public void mouseDragged(MouseEvent e) { |
|
250 |
pEnd = e.getPoint(); |
|
251 |
Rectangle bounds = getStylePreviewer().getBounds(); |
|
252 |
double xOffset = (pEnd.getX() - pIni.getX())/bounds.getWidth(); |
|
253 |
double yOffset = (pEnd.getY() - pIni.getY())/bounds.getHeight(); |
|
254 |
SimpleLabelStyle sty = (SimpleLabelStyle) getStylePreviewer().getStyle(); |
|
255 |
Point2D marker = sty.getMarkerPoint(); |
|
256 |
marker.setLocation(xOffset, -yOffset); |
|
257 |
|
|
258 |
repaint(); |
|
259 |
} |
|
260 |
|
|
261 |
}; |
|
262 |
private EditorTool newTextTool = new EditorTool(StyleEditor.this) { |
|
263 |
private /*static*/ final Cursor cursor = Cursor.getDefaultCursor(); |
|
264 |
private Point pIni, pEnd; |
|
265 |
public Cursor getCursor() { |
|
266 |
return cursor; |
|
267 |
} |
|
268 |
|
|
269 |
public void mousePressed(MouseEvent e) { |
|
270 |
pIni = e.getPoint(); |
|
271 |
pEnd = e.getPoint(); |
|
272 |
|
|
273 |
} |
|
274 |
public void mouseReleased(MouseEvent e) { |
|
275 |
|
|
276 |
} |
|
277 |
|
|
278 |
public void mouseDragged(MouseEvent e) { |
|
279 |
pEnd = e.getPoint(); |
|
280 |
|
|
281 |
int minx = pIni.x; |
|
282 |
int miny = pIni.y; |
|
283 |
int width = pEnd.x-pIni.x; |
|
284 |
int height = pEnd.y - pIni.y; |
|
285 |
if (width < 0) { |
|
286 |
minx += width; |
|
287 |
width = -width; |
|
288 |
} |
|
289 |
if (height <0) { |
|
290 |
miny += height; |
|
291 |
height = -height; |
|
292 |
} |
|
293 |
|
|
294 |
|
|
295 |
SimpleLabelStyle sty = (SimpleLabelStyle) getStylePreviewer().getStyle(); |
|
296 |
Rectangle bounds = getStylePreviewer().getBounds(); |
|
297 |
Rectangle2D rect = new Rectangle2D.Double( |
|
298 |
minx/bounds.getWidth(), |
|
299 |
miny/bounds.getHeight(), |
|
300 |
width/bounds.getWidth(), |
|
301 |
height/bounds.getHeight() |
|
302 |
); |
|
303 |
sty.setTextFieldArea(0, rect); |
|
304 |
repaint(); |
|
305 |
} |
|
306 |
}; |
|
307 |
|
|
159 | 308 |
private JPanel getPnlTools() { |
160 | 309 |
if (pnlTools == null) { |
161 | 310 |
pnlTools = new JPanel(); |
... | ... | |
186 | 335 |
private JToggleButton getBtnNewTextArea() { |
187 | 336 |
if (btnNewTextArea == null) { |
188 | 337 |
btnNewTextArea = new JToggleButton("new_text"); |
338 |
btnNewTextArea.addActionListener(this); |
|
189 | 339 |
} |
190 | 340 |
return btnNewTextArea; |
191 | 341 |
} |
... | ... | |
193 | 343 |
private JToggleButton getBtnPan() { |
194 | 344 |
if (btnPan == null) { |
195 | 345 |
btnPan = new JToggleButton("pan"); |
196 |
|
|
346 |
btnPan.addActionListener(this); |
|
197 | 347 |
} |
198 | 348 |
|
199 | 349 |
return btnPan; |
200 | 350 |
} |
201 | 351 |
|
202 |
private StylePreviewer getStylePreviewer() { |
|
203 |
if (preview == null) { |
|
204 |
preview = new StylePreviewer(); |
|
205 |
preview.setShowOutline(true); |
|
206 |
} |
|
207 |
|
|
208 |
return preview; |
|
209 |
} |
|
210 |
|
|
211 |
/** |
|
212 |
* This method initializes pnlButtons |
|
213 |
* |
|
214 |
* @return javax.swing.JPanel |
|
215 |
*/ |
|
216 |
private JPanel getPnlButtons() { |
|
217 |
if (pnlButtons == null) { |
|
218 |
pnlButtons = new AcceptCancelPanel(); |
|
219 |
} |
|
220 |
return pnlButtons; |
|
221 |
} |
|
222 |
|
|
223 |
public WindowInfo getWindowInfo() { |
|
224 |
WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE); |
|
225 |
wi.setTitle(PluginServices.getText(this, "edit_style")); |
|
226 |
wi.setWidth(getWidth()+10); |
|
227 |
wi.setHeight(getHeight()); |
|
228 |
return wi; |
|
229 |
} |
|
230 | 352 |
} // @jve:decl-index=0:visual-constraint="10,10" |
Also available in: Unified diff