Revision 1219 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/ThemeControls.java

View differences:

ThemeControls.java
46 46
 */
47 47
package com.iver.cit.gvsig;
48 48

  
49
import java.awt.Component;
50
import java.awt.geom.Rectangle2D;
51
import java.util.BitSet;
52

  
53
import javax.swing.JFileChooser;
54

  
55
import org.apache.log4j.Logger;
56

  
57 49
import com.iver.andami.PluginServices;
58 50
import com.iver.andami.plugins.Extension;
51

  
59 52
import com.iver.cit.gvsig.fmap.FMap;
60 53
import com.iver.cit.gvsig.fmap.NewMapControl;
61 54
import com.iver.cit.gvsig.fmap.drivers.shp.SHP;
......
63 56
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
64 57
import com.iver.cit.gvsig.gui.View;
65 58
import com.iver.cit.gvsig.project.castor.ProjectView;
59

  
66 60
import com.iver.utiles.GenericFileFilter;
67 61

  
62
import org.apache.log4j.Logger;
68 63

  
64
import java.awt.Component;
65
import java.awt.geom.Rectangle2D;
66
import java.io.File;
67

  
68
import java.util.BitSet;
69

  
70
import javax.swing.JFileChooser;
71

  
72

  
69 73
/**
70
 * Propiedades del tema.
74
 * Extensi?n de operaciones sobre el tema.
71 75
 *
72 76
 * @author Vicente Caballero Navarro
73 77
 */
74 78
public class ThemeControls implements Extension {
75
    private static Logger logger = Logger.getLogger(ViewControls.class.getName());
79
	private static Logger logger = Logger.getLogger(ThemeControls.class.getName());
76 80

  
77
    /**
78
     * DOCUMENT ME!
79
     *
80
     * @param status DOCUMENT ME!
81
     * @param s DOCUMENT ME!
82
     */
83
    public void execute(String s) {
84
        View vista = (View) PluginServices.getMDIManager().getActiveView();
85
       	ProjectView model = vista.getModel();
81
	/**
82
	 * @see com.iver.mdiApp.plugins.Extension#updateUI(java.lang.String)
83
	 */
84
	public void execute(String s) {
85
		View vista = (View) PluginServices.getMDIManager().getActiveView();
86
		ProjectView model = vista.getModel();
86 87
		FMap mapa = model.getMapContext();
87 88
		NewMapControl mapCtrl = vista.getMapControl();
88 89
		logger.debug("Comand : " + s);
89
        if (s.compareTo("PROPERTIES") == 0){
90
        	vista.openThemeProperties();
91
        }else if (s.compareTo("SHAPE_SELECTED") == 0) {
90

  
91
		if (s.compareTo("PROPERTIES") == 0) {
92
			vista.openThemeProperties();
93
		} else if (s.compareTo("SHAPE_SELECTED") == 0) {
92 94
			createShape(mapa);
93
		}else if (s.compareTo("DEL_SELECTION") == 0) {
94
			boolean refresh=false;
95
			for (int i=0; i<mapa.getLayers().getLayersCount();i++){
96
			if (mapa.getLayers().getLayer(i) instanceof Selectable){
97
				if (mapa.getLayers().getLayer(i).isActive()){
98
				BitSet bitset=((Selectable)mapa.getLayers().getLayer(i)).getSelection();
99
				if (bitset.cardinality()!=0){
100
					refresh=true;
95
		} else if (s.compareTo("DEL_SELECTION") == 0) {
96
			boolean refresh = false;
97

  
98
			for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) {
99
				if (mapa.getLayers().getLayer(i) instanceof Selectable) {
100
					if (mapa.getLayers().getLayer(i).isActive()) {
101
						BitSet bitset = ((Selectable) mapa.getLayers().getLayer(i)).getSelection();
102

  
103
						if (bitset.cardinality() != 0) {
104
							refresh = true;
105
						}
106

  
107
						bitset.clear();
108
					}
101 109
				}
102
				bitset.clear();
103
				}
104 110
			}
111

  
112
			if (refresh) {
113
				mapCtrl.drawMap(false);
105 114
			}
106
			if (refresh) mapCtrl.drawMap(false);
107
			
108
		}else if (s.compareTo("ZOOM_SELECT") == 0) {
115
		} else if (s.compareTo("ZOOM_SELECT") == 0) {
109 116
			Rectangle2D selectedExtent = mapa.getSelectionBounds();
110 117

  
111 118
			if (selectedExtent != null) {
112 119
				mapa.getViewPort().setExtent(selectedExtent);
113 120
			}
114 121
		}
115
    }
116
    private void createShape(FMap map){
122
	}
123

  
124
	/**
125
	 * Crea un nuevo shape.
126
	 *
127
	 * @param map FMap de donde coger las capas a copiar.
128
	 */
129
	private void createShape(FMap map) {
117 130
		if (map.getSelectionBounds() != null) {
118 131
			JFileChooser jfc = new JFileChooser();
119
			jfc.addChoosableFileFilter(new GenericFileFilter("shp", PluginServices.getText(this,"ShapeFile")));
120
			if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION){
121
				SHP.SHPFileFromSelected(map,jfc.getSelectedFile());
132
			jfc.addChoosableFileFilter(new GenericFileFilter("shp",
133
					PluginServices.getText(this, "ShapeFile")));
134

  
135
			if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
136
				File file=jfc.getSelectedFile();
137
				if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){
138
					file=new File(file.getPath()+".shp");
139
				}
140
				SHP.SHPFileFromSelected(map, file);
122 141
			}
123
		}// else {
142
		} // else {
143

  
124 144
		//}
145
	}
146

  
147
	/**
148
	 * @see com.iver.mdiApp.plugins.Extension#isVisible()
149
	 */
150
	public boolean isVisible() {
151
		com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
152
															 .getActiveView();
153

  
154
		if (f == null) {
155
			return false;
125 156
		}
126
    /**
127
     * @see com.iver.mdiApp.plugins.Extension#isVisible()
128
     */
129
    public boolean isVisible() {
130
        com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
131
                                                           .getActiveView();
132
        
133
        if (f == null) {
134
            return false;
135
        }
136 157

  
137
        if (f.getClass() == View.class) {
138
            FMap mapa = ((View) f).getModel().getMapContext();
158
		if (f.getClass() == View.class) {
159
			FMap mapa = ((View) f).getModel().getMapContext();
139 160

  
140
            View v = (View) f;
161
			View v = (View) f;
141 162

  
142
            return mapa.getLayers().getLayersCount() > 0;
143
        } else {
144
            return false;
145
        }
146
    }
163
			return mapa.getLayers().getLayersCount() > 0;
164
		} else {
165
			return false;
166
		}
167
	}
147 168

  
148
    /**
149
     * DOCUMENT ME!
150
     *
151
     * @return DOCUMENT ME!
152
     */
153
    public boolean isEnabled() {
154
        View f = (View) PluginServices.getMDIManager().getActiveView();
169
	/**
170
	 * @see com.iver.andami.plugins.Extension#isEnabled()
171
	 */
172
	public boolean isEnabled() {
173
		View f = (View) PluginServices.getMDIManager().getActiveView();
155 174

  
156
        if (f == null) {
157
            return false;
158
        }
175
		if (f == null) {
176
			return false;
177
		}
159 178

  
160
        FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
179
		FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
161 180

  
162
        return selected.length > 0;
163
    }
181
		return selected.length > 0;
182
	}
164 183

  
165 184
	/**
166 185
	 * @see com.iver.andami.plugins.Extension#inicializar()

Also available in: Unified diff