root / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / styling / editortools / LabelStyleNewTextFieldTool.java @ 20768
History | View | Annotate | Download (3.65 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.styling.editortools; |
42 |
|
43 |
import java.awt.Cursor; |
44 |
import java.awt.Point; |
45 |
import java.awt.Rectangle; |
46 |
import java.awt.event.MouseEvent; |
47 |
import java.awt.geom.Rectangle2D; |
48 |
|
49 |
import javax.swing.AbstractButton; |
50 |
import javax.swing.JComponent; |
51 |
import javax.swing.JToggleButton; |
52 |
|
53 |
import com.iver.andami.PluginServices; |
54 |
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle; |
55 |
import com.iver.cit.gvsig.gui.styling.EditorTool; |
56 |
|
57 |
public class LabelStyleNewTextFieldTool extends EditorTool { |
58 |
private Point pIni, pEnd; |
59 |
private final Cursor cursor = Cursor.getDefaultCursor(); |
60 |
private ILabelStyle style;
|
61 |
private JToggleButton btnNewTextArea; |
62 |
|
63 |
public LabelStyleNewTextFieldTool(JComponent targetEditor) { |
64 |
super(targetEditor);
|
65 |
// TODO Auto-generated constructor stub
|
66 |
} |
67 |
public Cursor getCursor() { |
68 |
return cursor;
|
69 |
} |
70 |
|
71 |
public void mousePressed(MouseEvent e) { |
72 |
pIni = e.getPoint(); |
73 |
pEnd = e.getPoint(); |
74 |
Rectangle2D rect = screenPointsToLabelRect(pIni, pEnd);
|
75 |
style.addTextFieldArea(rect); |
76 |
} |
77 |
|
78 |
public void mouseReleased(MouseEvent e) { |
79 |
|
80 |
} |
81 |
|
82 |
public void mouseDragged(MouseEvent e) { |
83 |
pEnd = e.getPoint(); |
84 |
Rectangle2D rect = screenPointsToLabelRect(pIni, pEnd);
|
85 |
style.setTextFieldArea(style.getFieldCount()-1, rect);
|
86 |
owner.repaint(); |
87 |
} |
88 |
|
89 |
private Rectangle2D screenPointsToLabelRect(Point pIni, Point pEnd) { |
90 |
int minx = pIni.x;
|
91 |
int miny = pIni.y;
|
92 |
int width = pEnd.x-pIni.x;
|
93 |
int height = pEnd.y - pIni.y;
|
94 |
if (width < 0) { |
95 |
minx += width; |
96 |
width = -width; |
97 |
} |
98 |
if (height <0) { |
99 |
miny += height; |
100 |
height = -height; |
101 |
} |
102 |
|
103 |
|
104 |
Rectangle bounds = owner.getBounds();
|
105 |
Rectangle2D rect = new Rectangle2D.Double( |
106 |
minx/bounds.getWidth(), |
107 |
miny/bounds.getHeight(), |
108 |
width/bounds.getWidth(), |
109 |
height/bounds.getHeight() |
110 |
); |
111 |
return rect;
|
112 |
} |
113 |
|
114 |
public AbstractButton getButton() { |
115 |
return getBtnNewTextArea();
|
116 |
} |
117 |
|
118 |
@Override
|
119 |
public String getID() { |
120 |
return "2"; |
121 |
} |
122 |
|
123 |
@Override
|
124 |
public boolean isSuitableFor(Object obj) { |
125 |
return obj instanceof ILabelStyle; |
126 |
} |
127 |
|
128 |
@Override
|
129 |
public void setModel(Object objectToBeEdited) { |
130 |
style = (ILabelStyle) objectToBeEdited; |
131 |
} |
132 |
|
133 |
private JToggleButton getBtnNewTextArea() { |
134 |
if (btnNewTextArea == null) { |
135 |
btnNewTextArea = new JToggleButton(PluginServices.getIconTheme().get("add-text-icon")); |
136 |
btnNewTextArea.setToolTipText(PluginServices.getText(this, "add_text_area")); |
137 |
btnNewTextArea.setSize(EditorTool.SMALL_BTN_SIZE); |
138 |
btnNewTextArea.setSize(EditorTool.SMALL_BTN_SIZE); |
139 |
} |
140 |
return btnNewTextArea;
|
141 |
} |
142 |
} |