root / trunk / extensions / extSymbology / src / org / gvsig / symbology / gui / styling / editortools / LabelStylePanTool.java @ 20768
History | View | Annotate | Download (3.6 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.Toolkit; |
47 |
import java.awt.event.MouseEvent; |
48 |
import java.awt.geom.Point2D; |
49 |
|
50 |
import javax.swing.AbstractButton; |
51 |
import javax.swing.ImageIcon; |
52 |
import javax.swing.JComponent; |
53 |
import javax.swing.JToggleButton; |
54 |
|
55 |
import com.iver.andami.PluginServices; |
56 |
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle; |
57 |
import com.iver.cit.gvsig.gui.styling.EditorTool; |
58 |
/**
|
59 |
*
|
60 |
* SimpleLabelStylePanTool.java
|
61 |
*
|
62 |
*
|
63 |
* @author jaume dominguez faus - jaume.dominguez@iver.es Jan 7, 2008
|
64 |
*
|
65 |
*/
|
66 |
public class LabelStylePanTool extends EditorTool { |
67 |
private JToggleButton btnPan; |
68 |
private Cursor cursor; |
69 |
private Point pIni, pEnd; |
70 |
private ILabelStyle style;
|
71 |
|
72 |
public LabelStylePanTool(JComponent owner) { |
73 |
super(owner);
|
74 |
} |
75 |
|
76 |
public Cursor getCursor() { |
77 |
if (cursor == null) { |
78 |
ImageIcon cursorImage = new ImageIcon(PluginServices.getIconTheme().get("hand-icon").getImage()); |
79 |
cursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage.getImage(),
|
80 |
new Point(16, 16), ""); |
81 |
|
82 |
} |
83 |
return cursor;
|
84 |
} |
85 |
|
86 |
public void mousePressed(MouseEvent e) { |
87 |
Rectangle bounds = owner.getBounds();
|
88 |
Point2D marker = style.getMarkerPoint();
|
89 |
pIni = new Point((int) (marker.getX()*bounds.width), bounds.height - (int) (marker.getY()*bounds.height)); |
90 |
pEnd = e.getPoint(); |
91 |
} |
92 |
|
93 |
public void mouseReleased(MouseEvent e) { |
94 |
|
95 |
} |
96 |
|
97 |
public void mouseDragged(MouseEvent e) { |
98 |
pEnd = e.getPoint(); |
99 |
Rectangle bounds = owner.getBounds();
|
100 |
double xOffset = (pEnd.getX() - pIni.getX())/bounds.getWidth();
|
101 |
double yOffset = (pEnd.getY() - pIni.getY())/bounds.getHeight();
|
102 |
Point2D marker = style.getMarkerPoint();
|
103 |
marker.setLocation(xOffset, -yOffset); |
104 |
|
105 |
owner.repaint(); |
106 |
} |
107 |
|
108 |
@Override
|
109 |
public AbstractButton getButton() { |
110 |
return getBtnPan();
|
111 |
} |
112 |
|
113 |
private JToggleButton getBtnPan() { |
114 |
if (btnPan == null) { |
115 |
btnPan = new JToggleButton(PluginServices.getIconTheme().get("hand-icon")); |
116 |
btnPan.setToolTipText(PluginServices.getText(this, "offset_label")); |
117 |
btnPan.setPreferredSize(EditorTool.SMALL_BTN_SIZE); |
118 |
btnPan.setSize(EditorTool.SMALL_BTN_SIZE); |
119 |
} |
120 |
|
121 |
return btnPan;
|
122 |
} |
123 |
|
124 |
@Override
|
125 |
public String getID() { |
126 |
return "1"; |
127 |
} |
128 |
|
129 |
@Override
|
130 |
public boolean isSuitableFor(Object obj) { |
131 |
return obj instanceof ILabelStyle; |
132 |
} |
133 |
|
134 |
@Override
|
135 |
public void setModel(Object objectToBeEdited) { |
136 |
style = (ILabelStyle) objectToBeEdited; |
137 |
} |
138 |
} |