Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / gui / styling / editortools / PointLabelHighPrecedenceTool.java @ 40911

History | View | Annotate | Download (4.61 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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.labeling.gui.styling.editortools;
42

    
43
import java.awt.Cursor;
44
import java.awt.Dimension;
45
import java.awt.Point;
46
import java.awt.event.MouseEvent;
47

    
48
import javax.swing.AbstractButton;
49
import javax.swing.ImageIcon;
50
import javax.swing.JComponent;
51
import javax.swing.JToggleButton;
52

    
53
import org.gvsig.andami.IconThemeHelper;
54
import org.gvsig.app.gui.styling.EditorTool;
55
import org.gvsig.app.gui.styling.StyleEditor;
56
import org.gvsig.i18n.Messages;
57
import org.gvsig.labeling.placements.PointLabelPositioner;
58

    
59
/**
60
 * Implements an editor tool which can be used to select the position for the
61
 * label when the user is performing a layer of points. There will be 4 different
62
 * precedence levels for the 8 different places where the text for the specified point
63
 * will be placed (see PointLabelPositioneer.java). This class implements the highest one,
64
 * but the user can select a normal, a low or a forbidden one.
65
 *
66
 *
67
 * @author Pepe Vidal Salvador - jose.vidal.salvador@iver.es
68
 *
69
 */
70
public class PointLabelHighPrecedenceTool extends EditorTool {
71
        
72
        protected String buttonIcon = "set-high-precedence";
73
        protected byte precedenceValue = PointLabelPositioner.PREFERENCE_HIGH;
74
        private final Cursor cursor = Cursor.getDefaultCursor();
75

    
76
        private JToggleButton btnNewPrecedence;
77

    
78
        private PointLabelPositioner positioneer;
79

    
80
        /**
81
         * Constructor
82
         *
83
         * @param targetEditor
84
         */
85
        public PointLabelHighPrecedenceTool(JComponent targetEditor) {
86
                super(targetEditor);
87
        }
88
        /**
89
         * Implements the button for the tool
90
         *
91
         * @return
92
         */
93
        private JToggleButton getBtnNewPrecedence() {
94
                if (btnNewPrecedence == null) {
95
                        btnNewPrecedence = new JToggleButton();
96
                        btnNewPrecedence.setSize(EditorTool.SMALL_BTN_SIZE);
97
                        btnNewPrecedence.setIcon(getIconButton());
98
                        btnNewPrecedence.setToolTipText(
99
                                        Messages.getText("set_high_precedence"));
100

    
101
                }
102
                return btnNewPrecedence;
103
        }
104
        /**
105
         * Obtains the image for the button of the tool
106
         *
107
         * @return
108
         */
109
        protected ImageIcon getIconButton() {
110
                return IconThemeHelper.getImageIcon(buttonIcon);
111
        }
112
        @Override
113
        public AbstractButton getButton() {
114
                return getBtnNewPrecedence();
115
        }
116

    
117
        @Override
118
        public Cursor getCursor() {
119
                return cursor;
120
        }
121

    
122
        @Override
123
        public String getID() {
124
                return "1";
125
        }
126

    
127
        @Override
128
        public boolean isSuitableFor(Object obj) {
129
                return obj instanceof PointLabelPositioner;
130
        }
131

    
132
        @Override
133
        public void setModel(Object objectToBeEdited) {
134
                positioneer = (PointLabelPositioner) objectToBeEdited;
135
        }
136
        /**
137
         * Obtains the position
138
         * @param p
139
         * @return
140
         */
141
        private int getPositionerCellIndex(Point p) {
142
                Dimension dim = ((StyleEditor) owner).getStylePreviewer().getSize();
143
                int size = Math.min(dim.width, dim.height);
144
                if(p.getX() > size || p.getY()>size)
145
                        return -1;
146
                int cellSize = size/3;
147
                int row = (int) p.getY() / cellSize;
148
                int col = (int) p.getX() / cellSize;
149
                int arrayPosition = (3 * row) + col;
150
                if (arrayPosition==4) return -1;
151
                if (arrayPosition>4) return arrayPosition-1;
152
                return arrayPosition;
153

    
154
        }
155
        public void mousePressed(MouseEvent e) {
156
                int[] pv = positioneer.getPreferenceVector();
157
                int cellIndex = getPositionerCellIndex(e.getPoint());
158
                if (cellIndex!=-1) {
159
                        pv[cellIndex] = precedenceValue;
160
                }
161
                owner.repaint();
162
        }
163

    
164
        public void mouseReleased(MouseEvent e) {
165
        }
166

    
167
        public void mouseDragged(MouseEvent e) {
168
        }
169
}