Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / actions / MyPasteListener.java @ 37945

History | View | Annotate | Download (2.81 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2011 Software Colaborativo (www.scolab.es)   development
26
*/
27
 
28
package com.iver.cit.gvsig.project.documents.view.toc.actions;
29

    
30
import java.awt.event.ActionEvent;
31

    
32
import javax.swing.AbstractAction;
33
import javax.swing.JOptionPane;
34
import javax.swing.JPopupMenu;
35

    
36
import com.iver.andami.PluginServices;
37
import com.iver.cit.gvsig.fmap.MapContext;
38
import com.iver.cit.gvsig.fmap.layers.FLayer;
39
import com.iver.cit.gvsig.fmap.layers.FLayers;
40
import com.iver.cit.gvsig.fmap.layers.FLyrDefault;
41
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
42
import com.iver.cit.gvsig.project.documents.view.toc.gui.ChangeName;
43
import com.iver.utiles.Utils;
44
import com.iver.utiles.XMLEntity;
45

    
46
public class MyPasteListener extends AbstractAction {
47

    
48
        private XMLEntity xml;
49
        private ITocItem item;
50
        private FLayer root;
51
        private MapContext mapContext;
52
        private JPopupMenu pop;
53

    
54
        public MyPasteListener(JPopupMenu pop, ITocItem item, XMLEntity xml, FLayer root,
55
                        MapContext mapContext) {
56
                this.item = item;
57
                this.xml = xml;
58
                this.root = root;
59
                this.mapContext = mapContext;
60
                this.pop = pop;
61
        }
62

    
63
        public void actionPerformed(ActionEvent e) {
64
                // JOptionPane.showMessageDialog(null, e.getActionCommand());
65
                
66
                mapContext.beginAtomicEvent();
67
                try {
68
                        
69
                        FLayers all = mapContext.getLayers();
70
                        CopyPasteLayersUtiles.getInstance().loadLayersFromXML(xml, all);
71
                                // ponemos las capas en posici?n
72
                                int pos = -1;
73
                                for (int j=0; j < all.getLayersCount(); j++) {
74
                                        if (all.getLayer(j).getName().equalsIgnoreCase(root.getName())) {
75
                                                pos = j;
76
                                                break;
77
                                        }
78
                                }
79
                                int corrected = 1;
80
                                if (e.getActionCommand().equalsIgnoreCase("UP"))
81
                                        corrected = 2;
82
                                all.moveTo(0, all.getLayersCount()-corrected-pos);
83
                } catch (Exception ex) {
84
                        ex.printStackTrace();
85
                }
86
                                
87
                mapContext.endAtomicEvent();
88
                mapContext.invalidate();
89

    
90
        }
91
        
92

    
93
}
94