Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extAnnotations / src / com / iver / cit / gvsig / project / documents / view / tool / Annotation_ModifyToolListenerImpl.java @ 28607

History | View | Annotate | Download (5.65 KB)

1

    
2
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib��ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42

    
43
package com.iver.cit.gvsig.project.documents.view.tool;
44

    
45
import java.awt.Cursor;
46
import java.awt.Image;
47
import java.awt.Point;
48
import java.awt.Toolkit;
49
import java.util.BitSet;
50

    
51
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
52
import com.hardcode.gdbms.engine.values.Value;
53
import com.iver.andami.PluginServices;
54
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
55
import com.iver.cit.gvsig.exceptions.validate.ValidateRowException;
56
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
57
import com.iver.cit.gvsig.fmap.MapControl;
58
import com.iver.cit.gvsig.fmap.core.IRow;
59
import com.iver.cit.gvsig.fmap.edition.Annotation_EditableAdapter;
60
import com.iver.cit.gvsig.fmap.edition.EditionEvent;
61
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer;
62
import com.iver.cit.gvsig.fmap.layers.Annotation_Mapping;
63
import com.iver.cit.gvsig.fmap.layers.FLayer;
64
import com.iver.cit.gvsig.fmap.operation.strategies.Annotation_Strategy;
65
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
66
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
67
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
68
import com.iver.cit.gvsig.project.documents.view.tool.gui.Annotation_ModifyWindow;
69

    
70

    
71
/**
72
 * Implementation of the interface PointListener as tool
73
 * of modify annotation.
74
 *
75
 * @author Vicente Caballero Navarro
76
 */
77
public class Annotation_ModifyToolListenerImpl implements PointListener {
78
        private static final int tolerance=10;
79
        private static final Image imodifytool=PluginServices.getIconTheme().get("annotation-modify").getImage();
80
        private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(imodifytool,
81
            new Point(16, 16), "");
82
    private MapControl mapControl;
83
    /**
84
     * Create a new Annotation_ModifyToolListenerImpl.
85
     *
86
     * @param mapControl MapControl.
87
     */
88
    public Annotation_ModifyToolListenerImpl(MapControl mapControl) {
89
        this.mapControl = mapControl;
90
    }
91

    
92
    /* (non-Javadoc)
93
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
94
     */
95
    public void point(PointEvent event) throws BehaviorException {
96
             FLayer[] layers=mapControl.getMapContext().getLayers().getActives();
97
         if (layers[0] instanceof Annotation_Layer){
98
                 if (layers[0].isEditing())
99
                 try {
100
                                Annotation_Mapping am=((Annotation_Layer)layers[0]).getAnnotatonMapping();
101
                         Annotation_Strategy as=(Annotation_Strategy)((Annotation_Layer)layers[0]).getStrategy();
102
                         BitSet bs=as.queryByPoint(mapControl.getViewPort().toMapPoint(event.getPoint()),mapControl.getViewPort().toMapDistance(tolerance));
103
                         Annotation_EditableAdapter aea=(Annotation_EditableAdapter)((Annotation_Layer)layers[0]).getSource();
104
                                if (bs.cardinality()>0)
105
                                        aea.startComplexRow();
106
                         for(int i=bs.nextSetBit(0); i>=0; i=bs.nextSetBit(i+1)) {
107
                                 IRow row=aea.getRow(i).getLinkedRow().cloneRow();
108
                                 Value[] values=row.getAttributes();
109
                                        Annotation_ModifyWindow maw=new Annotation_ModifyWindow();
110
                                        maw.setValues(values,am);
111
                                        PluginServices.getMDIManager().addWindow(maw);
112
                                        if (maw.isAccepted()){
113
                                                Value[] newValues=maw.getValues();
114
                                                if (!(values.equals(newValues))){
115
                                                        row.setAttributes(newValues);
116
                                                        aea.modifyRow(i,row,PluginServices.getText(this,"modify_annotation"),EditionEvent.ALPHANUMERIC);
117
                                                }
118
                                        }
119
                                }
120
                         if (bs.cardinality()>0){
121
                                 aea.endComplexRow(PluginServices.getText(this,"modify_annotation"));
122
                                 mapControl.drawMap(false);
123
                         }
124
                        } catch (ExpansionFileReadException e) {
125
                                throw new BehaviorException(e.getMessage());
126
                        } catch (ReadDriverException e) {
127
                                throw new BehaviorException(e.getMessage());
128
                        } catch (ValidateRowException e) {
129
                                throw new BehaviorException(e.getMessage());
130
                        } catch (VisitorException e) {
131
                                throw new BehaviorException(e.getMessage());
132
                        }
133

    
134
              }
135
    }
136

    
137
    /* (non-Javadoc)
138
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
139
     */
140
    public Cursor getCursor() {
141
        return cur;
142
    }
143

    
144
    /* (non-Javadoc)
145
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
146
     */
147
    public boolean cancelDrawing() {
148
        return true;
149
    }
150

    
151
    /* (non-Javadoc)
152
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
153
     */
154
    public void pointDoubleClick(PointEvent event) {
155
    }
156
}