Revision 1219

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/TableOperations.java
40 40
 */
41 41
package com.iver.cit.gvsig;
42 42

  
43
import java.io.IOException;
43
import com.hardcode.driverManager.DriverLoadException;
44 44

  
45
import com.hardcode.driverManager.DriverLoadException;
46 45
import com.hardcode.gdbms.engine.data.DataSource;
47 46
import com.hardcode.gdbms.engine.data.DataSourceFactory;
48 47
import com.hardcode.gdbms.engine.instruction.SemanticException;
49 48
import com.hardcode.gdbms.parser.ParseException;
49

  
50 50
import com.iver.andami.PluginServices;
51 51
import com.iver.andami.messages.NotificationManager;
52 52
import com.iver.andami.plugins.Extension;
53 53
import com.iver.andami.ui.mdiManager.View;
54

  
54 55
import com.iver.cit.gvsig.fmap.DriverException;
55 56
import com.iver.cit.gvsig.fmap.layers.FBitSet;
56 57
import com.iver.cit.gvsig.fmap.layers.FLayer;
......
61 62
import com.iver.cit.gvsig.gui.filter.ExpressionListener;
62 63
import com.iver.cit.gvsig.gui.filter.FilterDialog;
63 64
import com.iver.cit.gvsig.project.castor.ProjectView;
65

  
64 66
import com.iver.utiles.exceptionHandling.ExceptionListener;
65 67

  
68
import java.io.IOException;
66 69

  
70

  
67 71
/**
68
 * DOCUMENT ME!
72
 * Extensi?n que controla las operaciones realizadas sobre las tablas.
69 73
 *
70 74
 * @author Fernando Gonz?lez Cort?s
71 75
 */
72 76
public class TableOperations implements Extension, ExpressionListener {
73 77
	private SelectableDataSource dataSource = null;
74
    private Table vista;
78
	private Table vista;
75 79

  
76
    /**
77
     * @see com.iver.mdiApp.plugins.Extension#updateUI(java.lang.String)
78
     */
79
    public void execute(String actionCommand) {
80
        View v = PluginServices.getMDIManager().getActiveView();
81
        if (v instanceof Table){
82
           	vista = (Table) v;
83
    		dataSource = vista.getModel().getModelo();
84
        }else if (v instanceof com.iver.cit.gvsig.gui.View){
85
        	ProjectView pv = ((com.iver.cit.gvsig.gui.View) v).getModel();
86
        	try {
87
				dataSource = ((AlphanumericData)pv.getMapContext().getLayers().getActives()[0]).getRecordset();
80
	/**
81
	 * @see com.iver.mdiApp.plugins.Extension#updateUI(java.lang.String)
82
	 */
83
	public void execute(String actionCommand) {
84
		View v = PluginServices.getMDIManager().getActiveView();
85

  
86
		if (v instanceof Table) {
87
			vista = (Table) v;
88
			dataSource = vista.getModel().getModelo();
89
		} else if (v instanceof com.iver.cit.gvsig.gui.View) {
90
			ProjectView pv = ((com.iver.cit.gvsig.gui.View) v).getModel();
91

  
92
			try {
93
				dataSource = ((AlphanumericData) pv.getMapContext().getLayers()
94
												   .getActives()[0]).getRecordset();
88 95
			} catch (DriverException e) {
89 96
				NotificationManager.addError(e.getMessage(), e);
90 97
			}
91
        	
92
        }
98
		}
93 99

  
94 100
		DefaultExpressionDataSource ds = new DefaultExpressionDataSource();
95
        ds.setTable(dataSource);
101
		ds.setTable(dataSource);
96 102

  
97
        FilterDialog dlg = new FilterDialog();
98
        dlg.addExpressionListener(this);
99
        dlg.addExceptionListener(new ExceptionListener() {
100
			public void exceptionThrown(Throwable t) {
101
				NotificationManager.addError(t.getMessage(), t);
102
			}
103
		});
103
		FilterDialog dlg = new FilterDialog();
104
		dlg.addExpressionListener(this);
105
		dlg.addExceptionListener(new ExceptionListener() {
106
				public void exceptionThrown(Throwable t) {
107
					NotificationManager.addError(t.getMessage(), t);
108
				}
109
			});
104 110

  
105
        dlg.setModel(ds);
106
        PluginServices.getMDIManager().addView(dlg);
107
    }
111
		dlg.setModel(ds);
112
		PluginServices.getMDIManager().addView(dlg);
113
	}
108 114

  
109
    /**
115
	/**
110 116
	 * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#newSet(java.lang.String)
111 117
	 */
112 118
	public void newSet(String expression) {
113 119
		long[] sel = doSet(expression);
114
		if (sel == null) throw new RuntimeException("Not a 'where' clause?");
115
		
120

  
121
		if (sel == null) {
122
			throw new RuntimeException("Not a 'where' clause?");
123
		}
124

  
116 125
		FBitSet selection = new FBitSet();
126

  
117 127
		for (int i = 0; i < sel.length; i++) {
118 128
			selection.set((int) sel[i]);
119 129
		}
120
		
130

  
121 131
		dataSource.clearSelection();
122 132
		dataSource.setSelection(selection);
123 133
	}
124
	
134

  
125 135
	/**
126 136
	 * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#newSet(java.lang.String)
127 137
	 */
128 138
	private long[] doSet(String expression) {
129 139
		try {
130 140
			DataSource ds = DataSourceFactory.executeSQL(expression);
141

  
131 142
			return ds.getWhereFilter();
132 143
		} catch (DriverLoadException e) {
133 144
			NotificationManager.addError("Error cargando el driver", e);
......
140 151
		} catch (IOException e) {
141 152
			NotificationManager.addError("GDBMS internal error", e);
142 153
		}
143
		
154

  
144 155
		return null;
145 156
	}
146 157

  
147
    /**
148
     * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#addToSet(java.lang.String)
149
     */
150
    public void addToSet(String expression) {
158
	/**
159
	 * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#addToSet(java.lang.String)
160
	 */
161
	public void addToSet(String expression) {
151 162
		long[] sel = doSet(expression);
152
		if (sel == null) throw new RuntimeException("Not a 'where' clause?");
153
		
163

  
164
		if (sel == null) {
165
			throw new RuntimeException("Not a 'where' clause?");
166
		}
167

  
154 168
		FBitSet selection = new FBitSet();
169

  
155 170
		for (int i = 0; i < sel.length; i++) {
156 171
			selection.set((int) sel[i]);
157 172
		}
158
		
173

  
159 174
		FBitSet fbs = dataSource.getSelection();
160 175
		fbs.or(selection);
161 176
		dataSource.setSelection(fbs);
162
    }
177
	}
163 178

  
164
    /**
165
     * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#fromSet(java.lang.String)
166
     */
167
    public void fromSet(String expression) {
179
	/**
180
	 * @see com.iver.cit.gvsig.gui.filter.ExpressionListener#fromSet(java.lang.String)
181
	 */
182
	public void fromSet(String expression) {
168 183
		long[] sel = doSet(expression);
169
		if (sel == null) throw new RuntimeException("Not a 'where' clause?");
170
		
184

  
185
		if (sel == null) {
186
			throw new RuntimeException("Not a 'where' clause?");
187
		}
188

  
171 189
		FBitSet selection = new FBitSet();
190

  
172 191
		for (int i = 0; i < sel.length; i++) {
173 192
			selection.set((int) sel[i]);
174 193
		}
175
		
194

  
176 195
		FBitSet fbs = dataSource.getSelection();
177 196
		fbs.and(selection);
178 197
		dataSource.setSelection(fbs);
179
    }
198
	}
180 199

  
181 200
	/**
182 201
	 * @see com.iver.mdiApp.plugins.Extension#isVisible()
......
187 206
		if (v == null) {
188 207
			return false;
189 208
		}
190
		
209

  
191 210
		if (v.getClass() == Table.class) {
192 211
			return true;
193
		}else{
194
			if (v instanceof com.iver.cit.gvsig.gui.View){
212
		} else {
213
			if (v instanceof com.iver.cit.gvsig.gui.View) {
195 214
				com.iver.cit.gvsig.gui.View view = (com.iver.cit.gvsig.gui.View) v;
196 215
				ProjectView pv = view.getModel();
197
				FLayer[] seleccionadas = pv.getMapContext().getLayers().getActives();
198
				if (seleccionadas.length == 1){
199
					if (seleccionadas[0] instanceof AlphanumericData){
216
				FLayer[] seleccionadas = pv.getMapContext().getLayers()
217
										   .getActives();
218

  
219
				if (seleccionadas.length == 1) {
220
					if (seleccionadas[0] instanceof AlphanumericData) {
200 221
						return true;
201 222
					}
202 223
				}
203 224
			}
225

  
204 226
			return false;
205 227
		}
206 228
	}
......
217 239
	public boolean isEnabled() {
218 240
		return true;
219 241
	}
220

  
221 242
}
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/Print.java
46 46
 */
47 47
package com.iver.cit.gvsig;
48 48

  
49
import com.iver.andami.PluginServices;
50
import com.iver.andami.plugins.Extension;
51
import com.iver.andami.ui.mdiManager.View;
52

  
53
import com.iver.cit.gvsig.gui.layout.Attributes;
54
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
55
import com.iver.cit.gvsig.gui.layout.Layout;
56

  
49 57
import java.awt.Graphics;
50 58
import java.awt.Graphics2D;
51 59
import java.awt.geom.AffineTransform;
......
69 77
import javax.print.event.PrintJobEvent;
70 78
import javax.print.event.PrintJobListener;
71 79

  
72
import com.iver.andami.PluginServices;
73
import com.iver.andami.plugins.Extension;
74
import com.iver.andami.ui.mdiManager.View;
75
import com.iver.cit.gvsig.gui.layout.Attributes;
76
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
77
import com.iver.cit.gvsig.gui.layout.Layout;
78 80

  
79

  
80 81
/**
81 82
 * Extensi?n desde la que se imprime.
82 83
 *
83 84
 * @author Vicente Caballero Navarro
84 85
 */
85 86
public class Print implements Extension, Printable {
86
    /** DOCUMENT ME! */
87
    public static PrinterJob printerJob = PrinterJob.getPrinterJob();
88
    private static Layout l=null;
89
    private Paper paper;
90
    Rectangle2D.Double aux = null;
91
    private int veces = 0;
92
    private PrintService[] m_cachePrintServices = null;
93
    private PrintService m_cachePrintService = null;
87
	public static PrinterJob printerJob = PrinterJob.getPrinterJob();
88
	private static Layout l = null;
89
	private Paper paper;
90
	Rectangle2D.Double aux = null;
91
	private int veces = 0;
92
	private PrintService[] m_cachePrintServices = null;
93
	private PrintService m_cachePrintService = null;
94 94

  
95
    /**
96
     * DOCUMENT ME!
97
     *
98
     * @param status DOCUMENT ME!
99
     * @param s DOCUMENT ME!
100
     */
101
    public void execute(String s) {
102
        l = (Layout) PluginServices.getMDIManager().getActiveView();
95
	/**
96
	 * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
97
	 */
98
	public void execute(String s) {
99
		l = (Layout) PluginServices.getMDIManager().getActiveView();
103 100

  
104
        PageFormat format = printerJob.defaultPage(); //new PageFormat();
105
        paper = format.getPaper();
101
		PageFormat format = printerJob.defaultPage(); //new PageFormat();
102
		paper = format.getPaper();
106 103

  
107
        //double margin = 72.0 / 25.4 * 5.0;
108
        try {
109
            PluginServices.backgroundExecution(new Runnable() {
110
                public void run() {
111
                    if (l.getAtributes().getType() == Attributes.CUSTOM) {
112
                        l.showPrintDialog(printerJob);
113
                    } else {
114
                        l.showPrintDialog(null);
115
                    }
116
                }
117
            });
104
		//double margin = 72.0 / 25.4 * 5.0;
105
		try {
106
			PluginServices.backgroundExecution(new Runnable() {
107
					public void run() {
108
						if (l.getAtributes().getType() == Attributes.CUSTOM) {
109
							l.showPrintDialog(printerJob);
110
						} else {
111
							l.showPrintDialog(null);
112
						}
113
					}
114
				});
118 115

  
119
            //Thread.sleep(10000);
120
        } catch (Exception e) {
121
            System.out.println("Excepci?n al abrir el di?logo de impresi?n: " +
122
                e);
123
        }
124
    }
116
			//Thread.sleep(10000);
117
		} catch (Exception e) {
118
			System.out.println("Excepci?n al abrir el di?logo de impresi?n: " +
119
				e);
120
		}
121
	}
125 122

  
126
    /**
127
     * Se dibuja sobre el graphics el Layout.
128
     *
129
     * @param g2 graphics sobre el que se dibuja.
130
     */
131
    public void drawShapes(Graphics2D g2) {
132
        ///double w = paper.getWidth();
123
	/**
124
	 * Se dibuja sobre el graphics el Layout.
125
	 *
126
	 * @param g2 graphics sobre el que se dibuja.
127
	 */
128
	public void drawShapes(Graphics2D g2) {
129
		///double w = paper.getWidth();
130
		//System.out.println("w " + w);
131
		///double h = paper.getHeight();
132
		//System.out.println("h " + h);
133
		//g2.translate(-l.getRect().x, -l.getRect().y);
134
		l.drawLayoutPrint(g2);
133 135

  
134
        //System.out.println("w " + w);
135
        ///double h = paper.getHeight();
136
		// System.out.println("drawShapes = "+g2.getTransform().getScaleX());
137
		//g2.translate(l.getRect().x, l.getRect().y);
138
	}
136 139

  
137
			//System.out.println("h " + h);
138
			//g2.translate(-l.getRect().x, -l.getRect().y);
139
			l.drawLayoutPrint(g2);
140
	/**
141
	 * @see com.iver.andami.plugins.Extension#isVisible()
142
	 */
143
	public boolean isVisible() {
144
		View f = PluginServices.getMDIManager().getActiveView();
140 145

  
141
        // System.out.println("drawShapes = "+g2.getTransform().getScaleX());
142
        //g2.translate(l.getRect().x, l.getRect().y);
143
    }
146
		if (f == null) {
147
			return false;
148
		}
144 149

  
145
    /**
146
     * DOCUMENT ME!
147
     *
148
     * @return DOCUMENT ME!
149
     */
150
    public boolean isVisible() {
151
        View f = PluginServices.getMDIManager().getActiveView();
150
		return (f.getClass() == Layout.class);
151
	}
152 152

  
153
        if (f == null) {
154
            return false;
155
        }
153
	/**
154
	 * @see com.iver.mdiApp.plugins.Extension#isEnabled()
155
	 */
156
	public boolean isEnabled() {
157
		Layout f = (Layout) PluginServices.getMDIManager().getActiveView();
156 158

  
157
        return (f.getClass() == Layout.class);
158
    }
159
		if (f == null) {
160
			return false;
161
		}
159 162

  
160
    /**
161
     * @see com.iver.mdiApp.plugins.Extension#isEnabled()
162
     */
163
    public boolean isEnabled() {
164
        Layout f = (Layout) PluginServices.getMDIManager().getActiveView();
163
		return true;
164
	}
165 165

  
166
        if (f == null) {
167
            return false;
168
        }
166
	/* (non-Javadoc)
167
	 * @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int)
168
	 */
169
	public int print(Graphics g, PageFormat format, int pi)
170
		throws PrinterException {
171
		if (pi >= 1) {
172
			return Printable.NO_SUCH_PAGE;
173
		}
169 174

  
170
        return true;
171
    }
175
		System.err.println("Clip 0 = " + g.getClip());
172 176

  
173
    /* (non-Javadoc)
174
     * @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int)
175
     */
176
    public int print(Graphics g, PageFormat format, int pi)
177
        throws PrinterException {
178
        if (pi >= 1) {
179
            return Printable.NO_SUCH_PAGE;
180
        }
177
		Graphics2D g2d = (Graphics2D) g;
181 178

  
182
        System.err.println("Clip 0 = " + g.getClip());
179
		double x = format.getImageableX();
180
		double y = format.getImageableY();
181
		double w = format.getImageableWidth();
182
		double h = format.getImageableHeight();
183 183

  
184
        Graphics2D g2d = (Graphics2D) g;
184
		//System.err.println("Orientaci?n en Print: " + format.getOrientation());
185
		System.out.println("print:(" + x + "," + y + "," + w + "," + h + ")");
186
		System.err.println("Clip 1 = " + g2d.getClip());
185 187

  
186
        double x = format.getImageableX();
187
        double y = format.getImageableY();
188
        double w = format.getImageableWidth();
189
        double h = format.getImageableHeight();
188
		AffineTransform at = g2d.getTransform();
189
		g2d.translate(0, 0);
190
		l.obtainRect(true);
190 191

  
191
        //System.err.println("Orientaci?n en Print: " + format.getOrientation());
192
        System.out.println("print:(" + x + "," + y + "," + w + "," + h + ")");
193
        System.err.println("Clip 1 = " + g2d.getClip());
192
		//LWSAffineTransform at = g2d.getTransform();
193
		g2d.scale((double) 72 / (double) (Attributes.DPI),
194
			(double) 72 / (double) (Attributes.DPI));
195
		System.err.println("Clip 2 =" + g2d.getClip());
194 196

  
195
        AffineTransform at = g2d.getTransform();
196
        g2d.translate(0, 0);
197
        l.obtainRect(true);
197
		if (l.getAtributes().isMargin()) {
198
			g2d.setClip((int) (l.getRect().getMinX() +
199
				FLayoutUtilities.fromSheetDistance(l.getAtributes().m_area[2],
200
					l.getAT())),
201
				(int) (l.getRect().getMinY() +
202
				FLayoutUtilities.fromSheetDistance(l.getAtributes().m_area[0],
203
					l.getAT())),
204
				(int) (l.getRect().getWidth() -
205
				FLayoutUtilities.fromSheetDistance(l.getAtributes().m_area[2] +
206
					l.getAtributes().m_area[3], l.getAT())),
207
				(int) (l.getRect().getHeight() -
208
				FLayoutUtilities.fromSheetDistance(l.getAtributes().m_area[0] +
209
					l.getAtributes().m_area[1], l.getAT())));
210
		} else {
211
			/*
212
			   Rectangle rec=(Rectangle)g2d.getClipBounds();
213
			   Rectangle2D.Double rec2d=new Rectangle2D.Double();
214
			   rec2d.setRect(rec.x,rec.y,l.getRect().width,rec.getHeight());
215
			   g2d.setClip((int)rec2d.x,(int)rec2d.y,(int)rec2d.width,(int)rec2d.height);
216
			 */
217
			/* g2d.setClip((int) l.getRect().getMinX(),
218
			   (int) l.getRect().getMinY(), (int) l.getRect().getWidth(),
219
			   (int) l.getRect().getHeight()); */
220
		}
198 221

  
199
        //LWSAffineTransform at = g2d.getTransform();
200
        g2d.scale((double) 72 / (double) (Attributes.DPI),
201
            (double) 72 / (double) (Attributes.DPI));
202
        System.err.println("Clip 2 =" + g2d.getClip());
222
		veces++;
223
		System.out.println("veces = " + veces);
203 224

  
204
        if (l.getAtributes().isMargin()) {
205
            g2d.setClip((int) (l.getRect().getMinX() +
206
                FLayoutUtilities.fromSheetDistance(l.getAtributes().m_area[2],
207
                    l.getAT())),
208
                (int) (l.getRect().getMinY() +
209
                FLayoutUtilities.fromSheetDistance(l.getAtributes().m_area[0],
210
                    l.getAT())),
211
                (int) (l.getRect().getWidth() -
212
                FLayoutUtilities.fromSheetDistance(l.getAtributes().m_area[2] +
213
                    l.getAtributes().m_area[3], l.getAT())),
214
                (int) (l.getRect().getHeight() -
215
                FLayoutUtilities.fromSheetDistance(l.getAtributes().m_area[0] +
216
                    l.getAtributes().m_area[1], l.getAT())));
217
        } else {
218
            /*
219
               Rectangle rec=(Rectangle)g2d.getClipBounds();
220
               Rectangle2D.Double rec2d=new Rectangle2D.Double();
221
               rec2d.setRect(rec.x,rec.y,l.getRect().width,rec.getHeight());
222
               g2d.setClip((int)rec2d.x,(int)rec2d.y,(int)rec2d.width,(int)rec2d.height);
223
             */
224
            /* g2d.setClip((int) l.getRect().getMinX(),
225
               (int) l.getRect().getMinY(), (int) l.getRect().getWidth(),
226
               (int) l.getRect().getHeight()); */
227
        }
225
		drawShapes(g2d);
226
		g2d.setTransform(at);
228 227

  
229
        veces++;
230
        System.out.println("veces = " + veces);
228
		return Printable.PAGE_EXISTS;
229
	}
231 230

  
232
        drawShapes(g2d);
233
        g2d.setTransform(at);
234

  
235
        return Printable.PAGE_EXISTS;
236
    }
237

  
238 231
	/**
239 232
	 * @see com.iver.andami.plugins.Extension#inicializar()
240 233
	 */
241 234
	public void inicializar() {
242 235
	}
236

  
237
	/**
238
	 * Abre un di?logo para imprimir.
239
	 *
240
	 * @param layout Layout a imprimir.
241
	 */
243 242
	public void OpenDialogToPrint(Layout layout) {
244
    	l = layout;
245
        PageFormat format = printerJob.defaultPage(); //new PageFormat();
246
        paper = format.getPaper();
247
        try {
248
            if (layout.getAtributes().getType() == Attributes.CUSTOM) {
249
                layout.showPrintDialog(printerJob);
250
            } else {
251
                layout.showPrintDialog(null);
252
            }
253
         } catch (Exception e) {
254
            System.out.println("Excepci?n al abrir el di?logo de impresi?n: " +
255
                e);
256
            e.printStackTrace();
257
        }
258
    }
259
	 public void printLayout(Layout layout){
260
    	l=layout;
261
    	try {
262
			printerJob.setPrintable((Printable) PluginServices.getExtension(com.iver.cit.gvsig.Print.class));
263
		    //Actualizar attributes
264
			PrintRequestAttributeSet att = layout.getAtributes().toPrintAttributes();
265
	        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
266
	        if (m_cachePrintServices == null)
267
	        	m_cachePrintServices = PrintServiceLookup.lookupPrintServices(flavor, null);
268
	        PrintService defaultService = null;
269
	        if (m_cachePrintService == null)
270
	        	defaultService = PrintServiceLookup.lookupDefaultPrintService();
271
	        if (m_cachePrintService == null)
272
	        {
273
	        	m_cachePrintService = ServiceUI.printDialog(null, 200, 200, 
274
	        		m_cachePrintServices, defaultService, flavor, att);
275
	        }
276
	        	
277
	        if (m_cachePrintService != null)
278
	        {
279
		        DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
280
		        PrintJobListener pjlistener = new PrintJobAdapter() {
281
		                public void printDataTransferCompleted(PrintJobEvent e) {
282
		                    System.out.println("Fin de impresi?n");
283
		                }
284
		            };
285
		        jobNuevo.addPrintJobListener(pjlistener);
286
		        Doc doc =new SimpleDoc((Printable) PluginServices.getExtension(com.iver.cit.gvsig.Print.class), flavor, null);
287
		        	jobNuevo.print(doc, att);
288
	        }
243
		l = layout;
289 244

  
290
    	} catch (PrintException pe) {
291
            pe.printStackTrace();
292
        }
245
		PageFormat format = printerJob.defaultPage(); //new PageFormat();
246
		paper = format.getPaper();
247

  
248
		try {
249
			if (layout.getAtributes().getType() == Attributes.CUSTOM) {
250
				layout.showPrintDialog(printerJob);
251
			} else {
252
				layout.showPrintDialog(null);
253
			}
254
		} catch (Exception e) {
255
			System.out.println("Excepci?n al abrir el di?logo de impresi?n: " +
256
				e);
257
			e.printStackTrace();
258
		}
293 259
	}
260

  
261
	/**
262
	 * Imprime el Layout que se pasa como par?metro.
263
	 *
264
	 * @param layout Layout a imprimir.
265
	 */
266
	public void printLayout(Layout layout) {
267
		l = layout;
268

  
269
		try {
270
			printerJob.setPrintable((Printable) PluginServices.getExtension(
271
					com.iver.cit.gvsig.Print.class));
272

  
273
			//Actualizar attributes
274
			PrintRequestAttributeSet att = layout.getAtributes()
275
												 .toPrintAttributes();
276
			DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
277

  
278
			if (m_cachePrintServices == null) {
279
				m_cachePrintServices = PrintServiceLookup.lookupPrintServices(flavor,
280
						null);
281
			}
282

  
283
			PrintService defaultService = null;
284

  
285
			if (m_cachePrintService == null) {
286
				defaultService = PrintServiceLookup.lookupDefaultPrintService();
287
			}
288

  
289
			if (m_cachePrintService == null) {
290
				m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
291
						m_cachePrintServices, defaultService, flavor, att);
292
			}
293

  
294
			if (m_cachePrintService != null) {
295
				DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
296
				PrintJobListener pjlistener = new PrintJobAdapter() {
297
						public void printDataTransferCompleted(PrintJobEvent e) {
298
							System.out.println("Fin de impresi?n");
299
						}
300
					};
301

  
302
				jobNuevo.addPrintJobListener(pjlistener);
303

  
304
				Doc doc = new SimpleDoc((Printable) PluginServices.getExtension(
305
							com.iver.cit.gvsig.Print.class), flavor, null);
306
				jobNuevo.print(doc, att);
307
			}
308
		} catch (PrintException pe) {
309
			pe.printStackTrace();
310
		}
311
	}
294 312
}
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/ViewControls.java
49 49
import com.iver.andami.PluginServices;
50 50
import com.iver.andami.messages.NotificationManager;
51 51
import com.iver.andami.plugins.Extension;
52
import com.iver.andami.ui.mdiManager.MDIManager;
53 52

  
54 53
import com.iver.cit.gvsig.fmap.DriverException;
55 54
import com.iver.cit.gvsig.fmap.FMap;
56 55
import com.iver.cit.gvsig.fmap.NewMapControl;
57
import com.iver.cit.gvsig.fmap.drivers.shp.SHP;
58 56
import com.iver.cit.gvsig.fmap.layers.FLayer;
59
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
60 57
import com.iver.cit.gvsig.gui.Encuadrator;
61 58
import com.iver.cit.gvsig.gui.ExtentListSelectorModel;
62 59
import com.iver.cit.gvsig.gui.FPanelExtentSelector;
......
69 66
import com.iver.cit.gvsig.project.castor.Project;
70 67
import com.iver.cit.gvsig.project.castor.ProjectExtent;
71 68
import com.iver.cit.gvsig.project.castor.ProjectView;
72
import com.iver.utiles.GenericFileFilter;
73 69

  
74

  
75 70
import org.apache.log4j.Logger;
76
import org.geotools.map.MapContext;
77 71

  
78
import java.awt.Component;
79
import java.awt.geom.Rectangle2D;
80
import java.io.File;
81
import java.util.BitSet;
82 72

  
83
import javax.swing.JFileChooser;
84

  
85

  
86 73
//import com.iver.utiles.FPanelExtentSelector;
87 74

  
88 75
/**
89
 * DOCUMENT ME!
76
 * Extensi?n que controla las operaciones basicas realizadas sobre la vista.
90 77
 *
91 78
 * @author vcn
92 79
 */
......
94 81
	private static Logger logger = Logger.getLogger(ViewControls.class.getName());
95 82

  
96 83
	/**
97
	 * DOCUMENT ME!
98
	 *
99
	 * @param s DOCUMENT ME!
84
	 * @see com.iver.mdiApp.plugins.Extension#updateUI(java.lang.String)
100 85
	 */
101 86
	public void execute(String s) {
102 87
		View vista = (View) PluginServices.getMDIManager().getActiveView();
......
143 128
			mapCtrl.setTool("zoomIn");
144 129
		} else if (s.compareTo("ZOOM_OUT") == 0) {
145 130
			mapCtrl.setTool("zoomOut");
146
		}  else if (s.compareTo("MEDICION") == 0) {
131
		} else if (s.compareTo("MEDICION") == 0) {
147 132
			mapCtrl.setTool("medicion");
148 133
		} else if (s.compareTo("AREA") == 0) {
149 134
			mapCtrl.setTool("area");
......
154 139
		} else if (s.compareTo("PROPERTIES") == 0) {
155 140
			ViewProperties viewProperties = new ViewProperties(model);
156 141
			PluginServices.getMDIManager().addView(viewProperties);
157
		} else if (s.compareTo("TEMAS_VISIBLES") == 0){
158
			setVisibles(true,mapa);
159
		} else if (s.compareTo("TEMAS_NOVISIBLES") == 0){
160
			setVisibles(false,mapa);
161
		} else if (s.compareTo("TEMAS_ACTIVOS") == 0){
162
			setActives(true,mapa);
163
		} else if (s.compareTo("TEMAS_NOACTIVOS") == 0){
164
			setActives(false,mapa);
142
		} else if (s.compareTo("TEMAS_VISIBLES") == 0) {
143
			setVisibles(true, mapa);
144
		} else if (s.compareTo("TEMAS_NOVISIBLES") == 0) {
145
			setVisibles(false, mapa);
146
		} else if (s.compareTo("TEMAS_ACTIVOS") == 0) {
147
			setActives(true, mapa);
148
		} else if (s.compareTo("TEMAS_NOACTIVOS") == 0) {
149
			setActives(false, mapa);
165 150
		}
166 151
	}
167
	private void setVisibles(boolean visible,FMap mapa){
168
		for (int i=0;i<mapa.getLayers().getLayersCount();i++){
169
			FLayer layer=mapa.getLayers().getLayer(i);
152

  
153
	/**
154
	 * Pone todas las capas visibles o no visibles.
155
	 *
156
	 * @param visible true si que quieren poner a visibles.
157
	 * @param mapa FMap sobre el que actuar.
158
	 */
159
	private void setVisibles(boolean visible, FMap mapa) {
160
		for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) {
161
			FLayer layer = mapa.getLayers().getLayer(i);
170 162
			layer.setVisible(visible);
171 163
		}
172 164
	}
173
	private void setActives(boolean active,FMap mapa){
174
		for (int i=0;i<mapa.getLayers().getLayersCount();i++){
175
			FLayer layer=mapa.getLayers().getLayer(i);
165

  
166
	/**
167
	 * Pone todas las capas activas o no activas.
168
	 *
169
	 * @param active true si que quieren poner a activas.
170
	 * @param mapa FMap sobre el que actuar.
171
	 */
172
	private void setActives(boolean active, FMap mapa) {
173
		for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) {
174
			FLayer layer = mapa.getLayers().getLayer(i);
176 175
			layer.setActive(active);
177 176
		}
178 177
	}
178

  
179 179
	/**
180 180
	 * @see com.iver.mdiApp.plugins.Extension#isVisible()
181 181
	 */
......
191 191
			View vista = (View) f;
192 192
			ProjectView model = vista.getModel();
193 193
			FMap mapa = model.getMapContext();
194

  
194 195
			return mapa.getLayers().getLayersCount() > 0;
195 196
		} else {
196 197
			return false;
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/Abrir.java
40 40
 */
41 41
package com.iver.cit.gvsig;
42 42

  
43
import java.awt.geom.Rectangle2D;
44
import java.io.File;
45

  
46
import javax.swing.JOptionPane;
47

  
48
import org.cresques.cts.ICoordTrans;
49
import org.cresques.cts.IProjection;
50
import org.cresques.cts.gt2.CoordSys;
51
import org.cresques.cts.gt2.CoordTrans;
52

  
53 43
import com.iver.andami.PluginServices;
54 44
import com.iver.andami.messages.NotificationManager;
55 45
import com.iver.andami.plugins.Extension;
46

  
56 47
import com.iver.cit.gvsig.fmap.DriverException;
57
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
58 48
import com.iver.cit.gvsig.fmap.drivers.RasterDriver;
59 49
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
60 50
import com.iver.cit.gvsig.fmap.layers.FLayer;
61 51
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
62
import com.iver.cit.gvsig.fmap.layers.XMLException;
63 52
import com.iver.cit.gvsig.gui.FOpenDialog;
64 53
import com.iver.cit.gvsig.gui.FileOpenDialog;
65 54
import com.iver.cit.gvsig.gui.View;
66 55
import com.iver.cit.gvsig.gui.WMSDataSourceAdapter;
67 56
import com.iver.cit.gvsig.gui.wms.WMSWizard;
68 57

  
58
import org.cresques.cts.ICoordTrans;
59
import org.cresques.cts.IProjection;
60
import org.cresques.cts.gt2.CoordSys;
61
import org.cresques.cts.gt2.CoordTrans;
69 62

  
63
import java.awt.geom.Rectangle2D;
64

  
65
import java.io.File;
66

  
67
import javax.swing.JOptionPane;
68

  
69

  
70 70
/**
71
 * DOCUMENT ME!
71
 * Extensi?n que abre un di?logo para seleccionar la capa o capas que se
72
 * quieren a?adir a la vista.
72 73
 *
73 74
 * @author Fernando Gonz?lez Cort?s
74 75
 */
......
146 147
							if (theView.getMapControl().getMapContext().getViewPort().getExtent()==null){
147 148
								first=true;
148 149
							}
150

  
149 151
							// Comprobar que la projecci?n es la misma que la vista
150
							if (proj != theView.getProjection())
151
							{
152
					        	int option = JOptionPane.showConfirmDialog(null, 
153
					        			"La proyecci?n de la capa no es igual que la de la vista", "?Desea reproyectar?", JOptionPane.YES_NO_OPTION);
152
							if (proj != theView.getProjection()) {
153
								int option = JOptionPane.showConfirmDialog(null,
154
										"La proyecci?n de la capa no es igual que la de la vista",
155
										"?Desea reproyectar?",
156
										JOptionPane.YES_NO_OPTION);
154 157

  
155
					        	if (option == JOptionPane.NO_OPTION)
156
					        	{
158
								if (option == JOptionPane.NO_OPTION) {
157 159
									continue;
158
					        	}
159
					        	else
160
					        	{
161
					        		ICoordTrans ct = new CoordTrans((CoordSys) proj, (CoordSys) theView.getProjection());
162
					        		lyr.setCoordTrans(ct);
163
					        		System.err.println("coordTrans = " + 
164
					        				proj.getAbrev() + " " + theView.getProjection().getAbrev());
165
					        	}
166
				
167
							
160
								} else {
161
									ICoordTrans ct = new CoordTrans((CoordSys) proj,
162
											(CoordSys) theView.getProjection());
163
									lyr.setCoordTrans(ct);
164
									System.err.println("coordTrans = " +
165
										proj.getAbrev() + " " +
166
										theView.getProjection().getAbrev());
167
								}
168 168
							}
169

  
169 170
							theView.getMapControl().getMapContext().getLayers()
170 171
								   .addLayer(lyr);
171 172
							rects[iFile]=lyr.getFullExtent();
......
174 175
							// todas las capas hayan sido cargadas.
175 176
							// TODO Se deber? de redibujar mediante la captura de los eventos, por
176 177
							//eso se comenta la parte anterior
177
//							theView.getMapControl().drawMap();
178
//							theView.getTOC().refresh();
178
							//							theView.getMapControl().drawMap();
179
							//							theView.getTOC().refresh();
179 180
						}
180 181

  
181 182
					} catch (DriverException e) {
182 183
						NotificationManager.addError("Error al crear la capa", e);
183
    				}
184
					}
184 185
				}
186

  
185 187
				//Esto permite que cuando se cargan varias capas de golpe y la vista est? vacia,se ponga como extent la suma de todos sus extents.
186
				if (rects.length>1){
187
					Rectangle2D rect=new Rectangle2D.Double();
188
				if (rects.length > 1) {
189
					Rectangle2D rect = new Rectangle2D.Double();
188 190
					rect.setRect(rects[0]);
189
					if (first){
190
						for (int i=0;i<rects.length;i++){
191

  
192
					if (first) {
193
						for (int i = 0; i < rects.length; i++) {
191 194
							rect.add(rects[i]);
192 195
						}
193
						theView.getMapControl().getMapContext().getViewPort().setExtent(rect);
196

  
197
						theView.getMapControl().getMapContext().getViewPort()
198
							   .setExtent(rect);
194 199
					}
195 200
				}
196 201
				theView.getMapControl().getMapContext()
......
210 215
					theView.getMapControl().getMapContext().getLayers()
211 216
						   .addLayer(lyr);
212 217
					theView.getMapControl().getMapContext().endAtomicEvent();
213

  
214 218
				}
215 219
			} // for
216 220
		}
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/GraphicControls.java
46 46
 */
47 47
package com.iver.cit.gvsig;
48 48

  
49
import org.apache.log4j.Logger;
50

  
51 49
import com.iver.andami.PluginServices;
52 50
import com.iver.andami.plugins.Extension;
53 51
import com.iver.andami.ui.mdiManager.View;
52

  
54 53
import com.iver.cit.gvsig.gui.layout.FLayoutGraphics;
55 54
import com.iver.cit.gvsig.gui.layout.Layout;
56 55

  
56
import org.apache.log4j.Logger;
57 57

  
58

  
58 59
/**
60
 * Extensi?n que actua sobre el Layout para controlas las diferentes
61
 * operaciones sobre los gr?ficos.
62
 *
59 63
 * @author Vicente Caballero Navarro
60 64
 */
61 65
public class GraphicControls implements Extension {
62
	private static Logger logger = Logger.getLogger(LayoutControls.class.getName());
66
	private static Logger logger = Logger.getLogger(GraphicControls.class.getName());
63 67

  
64 68
	/**
65
	 * DOCUMENT ME!
66
	 *
67
	 * @param s DOCUMENT ME!
69
	 * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
68 70
	 */
69 71
	public void execute(String s) {
70 72
		Layout layout = (Layout) PluginServices.getMDIManager().getActiveView();
71
		FLayoutGraphics lg= new FLayoutGraphics(layout);
73
		FLayoutGraphics lg = new FLayoutGraphics(layout);
72 74
		logger.debug("Comand : " + s);
73 75

  
74 76
		if (s.compareTo("SIMPLIFICAR") == 0) {
......
89 91
			lg.border();
90 92
		} else if (s.compareTo("POSICIONAR") == 0) {
91 93
			lg.position();
92
		} 
94
		}
93 95
	}
94 96

  
95 97
	/**
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/LayoutControls.java
46 46
 */
47 47
package com.iver.cit.gvsig;
48 48

  
49
import org.apache.log4j.Logger;
50

  
51 49
import com.iver.andami.PluginServices;
52 50
import com.iver.andami.plugins.Extension;
53 51
import com.iver.andami.ui.mdiManager.View;
52

  
54 53
import com.iver.cit.gvsig.fmap.DriverException;
55
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
56 54
import com.iver.cit.gvsig.gui.layout.FLayoutZooms;
57 55
import com.iver.cit.gvsig.gui.layout.Layout;
58 56

  
57
import org.apache.log4j.Logger;
59 58

  
59

  
60 60
/**
61
 * DOCUMENT ME!
61
 * Extensi?n para controlar las operaciones basicas sobre el Layout.
62 62
 *
63 63
 * @author Vicente Caballero Navarro
64 64
 */
65 65
public class LayoutControls implements Extension {
66
    private static Logger logger = Logger.getLogger(LayoutControls.class.getName());
67
    private Layout layout=null;
68
    /**
69
     * DOCUMENT ME!
70
     *
71
     * @param status DOCUMENT ME!
72
     * @param s DOCUMENT ME!
73
     */
74
    public void execute(String s) {
75
        layout = (Layout) PluginServices.getMDIManager().getActiveView();
76
        FLayoutZooms zooms = new FLayoutZooms(layout);
77
        logger.debug("Comand : " + s);
78
        
79
        
80
        if (s.compareTo("PAN") == 0) {
81
            layout.setTool(Layout.PAN);
82
        } else if (s.compareTo("ZOOM_IN") == 0) {
83
            layout.setTool(Layout.ZOOM_MAS);
84
        } else if (s.compareTo("ZOOM_OUT") == 0) {
85
            layout.setTool(Layout.ZOOM_MENOS);
86
        } else if (s.compareTo("RECTANGLEVIEW") == 0) {
87
            layout.setTool(Layout.RECTANGLEVIEW);
88
        } else if (s.compareTo("RECTANGLEPICTURE") == 0) {
89
            layout.setTool(Layout.RECTANGLEPICTURE);
90
        } else if (s.compareTo("RECTANGLESCALEBAR") == 0) {
91
            layout.setTool(Layout.RECTANGLESCALEBAR);
92
        } else if (s.compareTo("RECTANGLELEGEND") == 0) {
93
            layout.setTool(Layout.RECTANGLELEGEND);
94
        } else if (s.compareTo("RECTANGLETEXT") == 0) {
95
            layout.setTool(Layout.RECTANGLETEXT);
96
        } else if (s.compareTo("SELECT") == 0) {
97
            layout.setTool(Layout.SELECT);
98
        } else if (s.compareTo("POINT") == 0) {
99
            layout.setTool(Layout.POINT);
100
        } else if (s.compareTo("LINE") == 0) {
101
            layout.setTool(Layout.LINE);
102
        } else if (s.compareTo("POLYLINE") == 0) {
103
            layout.setTool(Layout.POLYLINE);
104
        } else if (s.compareTo("CIRCLE") == 0) {
105
            layout.setTool(Layout.CIRCLE);
106
        } else if (s.compareTo("RECTANGLESIMPLE") == 0) {
107
            layout.setTool(Layout.RECTANGLESIMPLE);
108
        } else if (s.compareTo("POLYGON") == 0) {
109
            layout.setTool(Layout.POLYGON);
110
        } else if (s.compareTo("CONFIG") == 0) {
111
            layout.showFConfig();
112
        } else if (s.compareTo("PROPERTIES") == 0) {
113
            layout.showFProperties();
114
        } else if (s.compareTo("FULL") == 0) {
115
            layout.fullRect();
116
        } else if (s.compareTo("REALZOOM") == 0) {
117
            zooms.realZoom();
118
        } else if (s.compareTo("ZOOMOUT") == 0) {
119
            zooms.zoomOut();
120
        } else if (s.compareTo("ZOOMIN") == 0) {
121
            zooms.zoomIn();
122
        } else if (s.compareTo("ZOOMSELECT") == 0) {
123
            zooms.zoomSelect();
124
        } else if (s.compareTo("VIEW_ZOOMIN") == 0) {
125
            layout.setTool(Layout.VIEW_ZOOMIN);
126
        } else if (s.compareTo("VIEW_ZOOMOUT") == 0) {
127
            layout.setTool(Layout.VIEW_ZOOMOUT);
128
        } else if (s.compareTo("VIEW_FULL") == 0) {
129
            try {
66
	private static Logger logger = Logger.getLogger(LayoutControls.class.getName());
67
	private Layout layout = null;
68

  
69
	/**
70
	 * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
71
	 */
72
	public void execute(String s) {
73
		layout = (Layout) PluginServices.getMDIManager().getActiveView();
74

  
75
		FLayoutZooms zooms = new FLayoutZooms(layout);
76
		logger.debug("Comand : " + s);
77

  
78
		if (s.compareTo("PAN") == 0) {
79
			layout.setTool(Layout.PAN);
80
		} else if (s.compareTo("ZOOM_IN") == 0) {
81
			layout.setTool(Layout.ZOOM_MAS);
82
		} else if (s.compareTo("ZOOM_OUT") == 0) {
83
			layout.setTool(Layout.ZOOM_MENOS);
84
		} else if (s.compareTo("RECTANGLEVIEW") == 0) {
85
			layout.setTool(Layout.RECTANGLEVIEW);
86
		} else if (s.compareTo("RECTANGLEPICTURE") == 0) {
87
			layout.setTool(Layout.RECTANGLEPICTURE);
88
		} else if (s.compareTo("RECTANGLESCALEBAR") == 0) {
89
			layout.setTool(Layout.RECTANGLESCALEBAR);
90
		} else if (s.compareTo("RECTANGLELEGEND") == 0) {
91
			layout.setTool(Layout.RECTANGLELEGEND);
92
		} else if (s.compareTo("RECTANGLETEXT") == 0) {
93
			layout.setTool(Layout.RECTANGLETEXT);
94
		} else if (s.compareTo("SELECT") == 0) {
95
			layout.setTool(Layout.SELECT);
96
		} else if (s.compareTo("POINT") == 0) {
97
			layout.setTool(Layout.POINT);
98
		} else if (s.compareTo("LINE") == 0) {
99
			layout.setTool(Layout.LINE);
100
		} else if (s.compareTo("POLYLINE") == 0) {
101
			layout.setTool(Layout.POLYLINE);
102
		} else if (s.compareTo("CIRCLE") == 0) {
103
			layout.setTool(Layout.CIRCLE);
104
		} else if (s.compareTo("RECTANGLESIMPLE") == 0) {
105
			layout.setTool(Layout.RECTANGLESIMPLE);
106
		} else if (s.compareTo("POLYGON") == 0) {
107
			layout.setTool(Layout.POLYGON);
108
		} else if (s.compareTo("CONFIG") == 0) {
109
			layout.showFConfig();
110
		} else if (s.compareTo("PROPERTIES") == 0) {
111
			layout.showFProperties();
112
		} else if (s.compareTo("FULL") == 0) {
113
			layout.fullRect();
114
		} else if (s.compareTo("REALZOOM") == 0) {
115
			zooms.realZoom();
116
		} else if (s.compareTo("ZOOMOUT") == 0) {
117
			zooms.zoomOut();
118
		} else if (s.compareTo("ZOOMIN") == 0) {
119
			zooms.zoomIn();
120
		} else if (s.compareTo("ZOOMSELECT") == 0) {
121
			zooms.zoomSelect();
122
		} else if (s.compareTo("VIEW_ZOOMIN") == 0) {
123
			layout.setTool(Layout.VIEW_ZOOMIN);
124
		} else if (s.compareTo("VIEW_ZOOMOUT") == 0) {
125
			layout.setTool(Layout.VIEW_ZOOMOUT);
126
		} else if (s.compareTo("VIEW_FULL") == 0) {
127
			try {
130 128
				layout.viewFull();
131 129
			} catch (DriverException e) {
132 130
				//TODO Enviar a Andami
133 131
				e.printStackTrace();
134 132
			}
135
        } else if (s.compareTo("VIEW_PAN") == 0) {
136
            layout.setTool(Layout.VIEW_PAN);
137
        }else if (s.compareTo("SET_TAG") == 0) {
138
            layout.setTool(Layout.SET_TAG);
139
        }
140
    }
133
		} else if (s.compareTo("VIEW_PAN") == 0) {
134
			layout.setTool(Layout.VIEW_PAN);
135
		} else if (s.compareTo("SET_TAG") == 0) {
136
			layout.setTool(Layout.SET_TAG);
137
		}
138
	}
141 139

  
142
    /**
143
     * @see com.iver.mdiApp.plugins.Extension#isVisible()
144
     */
145
    public boolean isVisible() {
146
        View f = PluginServices.getMDIManager().getActiveView();
140
	/**
141
	 * @see com.iver.mdiApp.plugins.Extension#isVisible()
142
	 */
143
	public boolean isVisible() {
144
		View f = PluginServices.getMDIManager().getActiveView();
147 145

  
148
        if (f == null) {
149
            return false;
150
        }
146
		if (f == null) {
147
			return false;
148
		}
151 149

  
152
        if (f.getClass() == Layout.class) {
153
            Layout layout = (Layout) f;
150
		if (f.getClass() == Layout.class) {
151
			Layout layout = (Layout) f;
154 152

  
155
            return true; //layout.m_Display.getMapControl().getMapContext().getLayers().layerCount() > 0;
156
        } else {
157
            return false;
158
        }
159
    }
153
			return true; //layout.m_Display.getMapControl().getMapContext().getLayers().layerCount() > 0;
154
		} else {
155
			return false;
156
		}
157
	}
160 158

  
161 159
	/**
162 160
	 * @see com.iver.andami.plugins.Extension#inicializar()
......
170 168
	public boolean isEnabled() {
171 169
		return true;
172 170
	}
173
	public Layout getLayout(){
171

  
172
	/**
173
	 * Devuelve el Layout sobre el que se opera.
174
	 *
175
	 * @return Layout.
176
	 */
177
	public Layout getLayout() {
174 178
		return layout;
175
		
176 179
	}
177 180
}
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/ProjectExtension.java
40 40
 */
41 41
package com.iver.cit.gvsig;
42 42

  
43
import java.awt.Component;
44
import java.io.File;
45
import java.io.FileNotFoundException;
46
import java.io.FileReader;
47
import java.io.FileWriter;
48
import java.text.DateFormat;
49
import java.util.ArrayList;
50
import java.util.Date;
51

  
52
import javax.swing.JFileChooser;
53
import javax.swing.JOptionPane;
54

  
55
import org.exolab.castor.xml.MarshalException;
56
import org.exolab.castor.xml.Marshaller;
57
import org.exolab.castor.xml.ValidationException;
58

  
59 43
import com.iver.andami.PluginServices;
60 44
import com.iver.andami.messages.NotificationManager;
61 45
import com.iver.andami.plugins.Extension;
46

  
62 47
import com.iver.cit.gvsig.fmap.DriverException;
63 48
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
64 49
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
......
66 51
import com.iver.cit.gvsig.project.ProjectFactory;
67 52
import com.iver.cit.gvsig.project.ProjectWindow;
68 53
import com.iver.cit.gvsig.project.castor.Project;
54

  
69 55
import com.iver.utiles.GenericFileFilter;
70 56
import com.iver.utiles.XMLEntity;
71 57
import com.iver.utiles.xmlEntity.generate.XmlTag;
72 58

  
59
import org.exolab.castor.xml.MarshalException;
60
import org.exolab.castor.xml.Marshaller;
61
import org.exolab.castor.xml.ValidationException;
62

  
63
import java.awt.Component;
64

  
65
import java.io.File;
66
import java.io.FileNotFoundException;
67
import java.io.FileReader;
68
import java.io.FileWriter;
69

  
70
import java.text.DateFormat;
71

  
72
import java.util.ArrayList;
73
import java.util.Date;
74

  
75
import javax.swing.JFileChooser;
76
import javax.swing.JOptionPane;
77

  
78

  
73 79
/**
74 80
 * Extension que proporciona controles para crear proyectos nuevos, abrirlos y
75 81
 * guardarlos. Adem?s los tipos de tabla que soporta el proyecto son a?adidos
......
78 84
 * @author Fernando Gonz?lez Cort?s
79 85
 */
80 86
public class ProjectExtension implements Extension {
81
    private ArrayList tableExtensions = new ArrayList();
82
    private ProjectWindow projectFrame;
83
    private Project p;
87
	private ArrayList tableExtensions = new ArrayList();
88
	private ProjectWindow projectFrame;
89
	private Project p;
84 90
	private boolean modified = false;
85 91

  
86
    /**
87
     * @see com.iver.mdiApp.plugins.Extension#inicializar()
88
     */
89
    public void inicializar() {
90
        p = ProjectFactory.createProject();
91
        p.setName(PluginServices.getText(this, "untitled"));
92
        p.setModified(false);
93
        projectFrame = new ProjectWindow(this);
94
        projectFrame.setProject(p);
95
        showProjectWindow();
96
        PluginServices.getMainFrame().setTitle("gvSIG: " + PluginServices.getText(this,
97
									 "sin_titulo"));
98
        
99
        LayerFactory.setDriversPath(PluginServices.getPluginServices(this).getPluginDirectory().getAbsolutePath() + File.separator + "drivers");
100
    }
92
	/**
93
	 * @see com.iver.mdiApp.plugins.Extension#inicializar()
94
	 */
95
	public void inicializar() {
96
		p = ProjectFactory.createProject();
97
		p.setName(PluginServices.getText(this, "untitled"));
98
		p.setModified(false);
99
		projectFrame = new ProjectWindow(this);
100
		projectFrame.setProject(p);
101
		showProjectWindow();
102
		PluginServices.getMainFrame().setTitle("gvSIG: " +
103
			PluginServices.getText(this, "sin_titulo"));
101 104

  
102
	public void showProjectWindow(){
105
		LayerFactory.setDriversPath(PluginServices.getPluginServices(this)
106
												  .getPluginDirectory()
107
												  .getAbsolutePath() +
108
			File.separator + "drivers");
109
	}
110

  
111
	/**
112
	 * Muestra la ventana con el gestor de proyectos.
113
	 */
114
	public void showProjectWindow() {
103 115
		PluginServices.getMDIManager().addView(projectFrame);
104 116
	}
105 117

  
106
	private void guardar(){
118
	/**
119
	 * Guarda el proyecto actual en disco.
120
	 */
121
	private void guardar() {
107 122
		if (p.getPath() == null) {
108 123
			JFileChooser jfc = new JFileChooser();
109
			jfc.addChoosableFileFilter(new GenericFileFilter("xml", PluginServices.getText(this,"tipo_fichero_proyecto")));
110
			if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION){
124
			jfc.addChoosableFileFilter(new GenericFileFilter("xml",
125
					PluginServices.getText(this, "tipo_fichero_proyecto")));
126

  
127
			if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
111 128
				escribirProyecto(jfc.getSelectedFile(), p);
112 129
			}
113 130
		} else {
114 131
			escribirProyecto(new File(p.getPath()), p);
115 132
		}
116 133
	}
117
	
118
	private boolean modificado(){
134

  
135
	/**
136
	 * Guarda si el proyecto ha sido modificado.
137
	 *
138
	 * @return True si se ha guardado correctamente.
139
	 */
140
	private boolean modificado() {
119 141
		if (p.isModified()) {
120 142
			int res = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(),
121 143
					PluginServices.getText(this, "guardar_cambios"),
......
129 151
				return false;
130 152
			}
131 153
		}
132
		
154

  
133 155
		return true;
134 156
	}
135 157

  
136
    /**
137
     * @see com.iver.mdiApp.plugins.Extension#updateUI(java.lang.String)
138
     */
139
    public void execute(String actionCommand) {
140
            if (actionCommand.equals("NUEVO")) {
141
            	//Si est? modificado se pregunta si se quiere guardar el anterior
142
				if (!modificado()) return;
158
	/**
159
	 * @see com.iver.mdiApp.plugins.Extension#updateUI(java.lang.String)
160
	 */
161
	public void execute(String actionCommand) {
162
		if (actionCommand.equals("NUEVO")) {
163
			//Si est? modificado se pregunta si se quiere guardar el anterior
164
			if (!modificado()) {
165
				return;
166
			}
143 167

  
168
			PluginServices.getMDIManager().closeAllViews();
169
			p = ProjectFactory.createProject();
170
			p.setName(PluginServices.getText(this, "untitled"));
171
			p.setModified(false);
172
			projectFrame.setProject(p);
173
			showProjectWindow();
174
			PluginServices.getMainFrame().setTitle("gvSIG: " +
175
				PluginServices.getText(this, "sin_titulo"));
176
		} else if (actionCommand.equals("ABRIR")) {
177
			//Si est? modificado se pregunta si se quiere guardar el anterior
178
			if (!modificado()) {
179
				return;
180
			}
181

  
182
			JFileChooser jfc = new JFileChooser();
183
			jfc.addChoosableFileFilter(new GenericFileFilter("xml",
184
					PluginServices.getText(this, "tipo_fichero_proyecto")));
185

  
186
			if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
144 187
				PluginServices.getMDIManager().closeAllViews();
145
                p = ProjectFactory.createProject();
146
                p.setName(PluginServices.getText(this, "untitled"));
147
                p.setModified(false);
148
                projectFrame.setProject(p);
149
                showProjectWindow();
150
                PluginServices.getMainFrame().setTitle("gvSIG: " + PluginServices.getText(this,
151
				 "sin_titulo"));
152 188

  
153
            } else if (actionCommand.equals("ABRIR")) {
154
				//Si est? modificado se pregunta si se quiere guardar el anterior
155
				if (!modificado()) return;
189
				Project o = leerProyecto(jfc.getSelectedFile());
156 190

  
157
				JFileChooser jfc = new JFileChooser();
158
				jfc.addChoosableFileFilter(new GenericFileFilter("xml", PluginServices.getText(this,"tipo_fichero_proyecto")));
159
				if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION){
160
					PluginServices.getMDIManager().closeAllViews();
161
                	Project o = leerProyecto(jfc.getSelectedFile());
162
                	if (o != null){
163
						p = o; 
164
                	}
165
                	projectFrame.setProject(p);
166
                	projectFrame.refreshControls();
167
                	showProjectWindow();
191
				if (o != null) {
192
					p = o;
168 193
				}
169
            } else if (actionCommand.equals("GUARDAR")) {
170
            	guardar();
171
            }
172
    }
173 194

  
174
    private void escribirProyecto(File file, Project p){
175
            // write it out as XML
176
            try {
177
            	FileWriter writer = new FileWriter(file.getAbsolutePath());
178
            	Marshaller m = new Marshaller(writer);
179
            	m.setEncoding("ISO-8859-1");
180
            	m.marshal(p.getXMLEntity().getXmlTag());
181
                p.setPath(file.toString());
182
                p.setModificationDate(DateFormat.getDateInstance().format(new Date()));
183
                p.setModified(false);
184
                PluginServices.getMainFrame().setTitle("gvSIG: " + file.getName());
185
            } catch (Exception e) {
186
                NotificationManager.addError("Error guardando el proyecto", e);
187
            }
188
            projectFrame.refreshControls();
189
    }
195
				projectFrame.setProject(p);
196
				projectFrame.refreshControls();
197
				showProjectWindow();
198
			}
199
		} else if (actionCommand.equals("GUARDAR")) {
200
			guardar();
201
		}
202
	}
190 203

  
191
    /**
192
     * @see com.iver.mdiApp.FileExtension#writeFile(java.io.File)
193
     */
194
    public Project leerProyecto(File file) {
195
    	Project proj = null;
204
	/**
205
	 * Escribe el proyecto en XML.
206
	 *
207
	 * @param file Fichero.
208
	 * @param p Proyecto.
209
	 */
210
	private void escribirProyecto(File file, Project p) {
211
		// write it out as XML
196 212
		try {
197
        	 File xmlFile = new File(file.getAbsolutePath());
198
        	 FileReader reader;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff