199.patch

Jose Antonio Canalejo Alonso, 06/11/2012 10:22 AM

Download (19.5 KB)

View differences:

src/org/gvsig/gui/beans/swing/JFileChooser.java (working copy)
78 78
	 *        means the user's home directory. 
79 79
	 */
80 80
	public JFileChooser(String fileChooserID, File defaultDirectory) {
81
		super();
82
		setDragEnabled(true);
83
		if (fileChooserID == null) 
84
			throw new IllegalArgumentException("JFileChooser's ID cannot be null");
85
		
86
		this.fileChooserID = fileChooserID;
87

  
88
		setCurrentDirectory(getLastPath(fileChooserID, defaultDirectory));
89

  
90
//		if (defaultDirectory == null)
91
//			defaultDirectory = new File(System.getProperty("user.home"));
92
//		File currentDirectory;
93
//		if (jfcLastPaths.get(fileChooserID) != null)
94
//			currentDirectory = new File(jfcLastPaths.get(fileChooserID));
95
//		else
96
//			currentDirectory = defaultDirectory;
97
//		setCurrentDirectory(currentDirectory);
98
//		if (defaultDirectory != null)
99
//			jfcLastPaths.put(fileChooserID, currentDirectory.getAbsolutePath());
81
		this(fileChooserID, defaultDirectory, null);
100 82
	}
101 83

  
102 84
	/**
......
107 89
	 * @return
108 90
	 */
109 91
	static public File getLastPath(String fileChooserID, File defaultDirectory) {
92
		return getLastPath(fileChooserID, defaultDirectory,
93
				FileSystemView.getFileSystemView());
94
	}
95

  
96
	private static File getLastPath(String fileChooserID,
97
			File defaultDirectory, FileSystemView fsv) {
110 98
		File path = jfcLastPaths.get(fileChooserID);
111 99

  
112 100
		if (path != null)
......
115 103
		if (defaultDirectory != null)
116 104
			return defaultDirectory;
117 105

  
118
		return FileSystemView.getFileSystemView().getHomeDirectory();
106
		if (fsv != null) {
107
			return fsv.getDefaultDirectory();
108
		} else {
109
			return FileSystemView.getFileSystemView().getDefaultDirectory();
110
		}
119 111
	}
120 112

  
121 113
	/**
......
125 117
	 * @return
126 118
	 */
127 119
	public File getLastPath(File defaultDirectory) {
128
		return getLastPath(fileChooserID, defaultDirectory);
120
		return getLastPath(fileChooserID, defaultDirectory, getFileSystemView());
129 121
	}
130 122

  
131 123
	/**
......
133 125
	 * @return
134 126
	 */
135 127
	public File getLastPath() {
136
		return getLastPath(fileChooserID, null);
128
		return getLastPath(fileChooserID, null, getFileSystemView());
137 129
	}
138 130

  
139 131
	/**
......
177 169
     * and <code>FileSystemView</code>.
178 170
     */
179 171
    public JFileChooser(String fileChooserID, File defaultDirectory, FileSystemView fsv) {
180
    	this(fileChooserID, defaultDirectory);
181
		setup(fsv);
172
		super(fsv);
173
		setDragEnabled(true);
174
		if (fileChooserID == null)
175
			throw new IllegalArgumentException(
176
					"JFileChooser's ID cannot be null");
177

  
178
		this.fileChooserID = fileChooserID;
179

  
180
		setCurrentDirectory(getLastPath(fileChooserID, defaultDirectory, fsv));
182 181
    }
183 182

  
184 183
    /**
......
186 185
     * path and <code>FileSystemView</code>.
187 186
     */
188 187
    public JFileChooser(String fileChooserID, String defaultDirectoryPath, FileSystemView fsv) {
189
	this(fileChooserID, new File(defaultDirectoryPath), fsv);
190
		}
188
		this(fileChooserID, defaultDirectoryPath == null ? null : new File(
189
				defaultDirectoryPath), fsv);
190
	}
191 191

  
192 192
	@Override
193 193
	public int showDialog(Component parent, String approveButtonText) throws HeadlessException {
src/org/gvsig/symbology/fmap/symbols/PictureMarkerSymbol.java (working copy)
118 118

  
119 119
import org.apache.log4j.Logger;
120 120
import org.gvsig.symbology.fmap.styles.BackgroundFileStyle;
121
import org.gvsig.tools.file.PathGenerator;
122 121

  
123 122
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
124 123
import com.iver.cit.gvsig.fmap.Messages;
......
148 147

  
149 148
	private BackgroundFileStyle bgImage;
150 149
	private BackgroundFileStyle bgSelImage;
151
	private PathGenerator pathGenerator=PathGenerator.getInstance();
152 150

  
153 151
	/**
154 152
	 * Constructor method
......
239 237
		xml.putProperty("className", getClassName());
240 238
		xml.putProperty("isShapeVisible", isShapeVisible());
241 239
		xml.putProperty("desc", getDescription());
242
		xml.putProperty("imagePath", pathGenerator.getURLPath(imagePath));
243
		xml.putProperty("selImagePath", pathGenerator.getURLPath(selImagePath));
240
		xml.putProperty("imagePath",
241
				PicturePathGeneratorUtils.getURLPath(imagePath));
242
		xml.putProperty("selImagePath",
243
				PicturePathGeneratorUtils.getURLPath(selImagePath));
244 244
		xml.putProperty("size", getSize());
245 245
		xml.putProperty("offsetX", getOffset().getX());
246 246
		xml.putProperty("offsetY", getOffset().getY());
......
262 262
	public void setXMLEntity(XMLEntity xml) {
263 263
		setDescription(xml.getStringProperty("desc"));
264 264
		setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
265
		imagePath = pathGenerator.getAbsoluteURLPath(xml.getStringProperty("imagePath"));
266
		selImagePath = pathGenerator.getAbsoluteURLPath(xml.getStringProperty("selImagePath"));
265
		imagePath = PicturePathGeneratorUtils.getAbsoluteURLPath(xml
266
				.getStringProperty("imagePath"));
267
		selImagePath = PicturePathGeneratorUtils.getAbsoluteURLPath(xml
268
				.getStringProperty("selImagePath"));
267 269
		setSize(xml.getDoubleProperty("size"));
268 270
		double offsetX = 0.0;
269 271
		double offsetY = 0.0;
......
284 286
				setImage(new URL(imagePath));
285 287
			} catch (MalformedURLException e) {
286 288
				try{
287
					setImage(new URL(pathGenerator.getAbsoluteURLPath(imagePath)));
289
					setImage(new URL(
290
							PicturePathGeneratorUtils
291
									.getAbsoluteURLPath(imagePath)));
288 292
				} catch (MalformedURLException e1) {
289 293
					setImage(new URL("file://"+ rootDir.getAbsolutePath() + File.separator +imagePath));
290 294
				}
......
299 303
				setSelImage(new URL(selImagePath));
300 304
			} catch (MalformedURLException e) {
301 305
				try{
302
					setSelImage(new URL(pathGenerator.getAbsoluteURLPath(selImagePath)));
306
					setSelImage(new URL(
307
							PicturePathGeneratorUtils
308
									.getAbsoluteURLPath(selImagePath)));
303 309
				} catch (MalformedURLException e1) {
304 310
					setSelImage(new URL("file://"+ rootDir.getAbsolutePath() + File.separator +selImagePath));
305 311
				}
src/org/gvsig/symbology/fmap/symbols/PictureLineSymbol.java (working copy)
57 57
import org.apache.batik.ext.awt.geom.PathLength;
58 58
import org.apache.log4j.Logger;
59 59
import org.gvsig.symbology.fmap.styles.BackgroundFileStyle;
60
import org.gvsig.tools.file.PathGenerator;
61 60

  
62 61
import com.iver.cit.gvsig.fmap.Messages;
63 62
import com.iver.cit.gvsig.fmap.ViewPort;
......
92 91
	private BackgroundFileStyle bgImage;
93 92
	private BackgroundFileStyle bgSelImage;
94 93
	private PrintRequestAttributeSet properties;
95
	private PathGenerator pathGenerator=PathGenerator.getInstance();
96 94

  
97 95
	/**
98 96
	 * Constructor method
......
260 258
		xml.putProperty("className", getClassName());
261 259
		xml.putProperty("isShapeVisible", isShapeVisible());
262 260
		xml.putProperty("desc", getDescription());
263
		xml.putProperty("imagePath", pathGenerator.getURLPath(imagePath));
264
		xml.putProperty("selImagePath", pathGenerator.getURLPath(selImagePath));
261
		xml.putProperty("imagePath",
262
				PicturePathGeneratorUtils.getURLPath(imagePath));
263
		xml.putProperty("selImagePath",
264
				PicturePathGeneratorUtils.getURLPath(selImagePath));
265 265
		xml.putProperty("lineWidth", getLineWidth());
266 266
		xml.putProperty("xScale", getXScale());
267 267
		xml.putProperty("yScale", getYScale());
......
280 280
		System.out.println(this.getClass().getClassLoader());
281 281
		setDescription(xml.getStringProperty("desc"));
282 282
		setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
283
		imagePath = pathGenerator.getAbsoluteURLPath(xml.getStringProperty("imagePath"));
284
		selImagePath = pathGenerator.getAbsoluteURLPath(xml.getStringProperty("selImagePath"));
283
		imagePath = PicturePathGeneratorUtils.getAbsoluteURLPath(xml
284
				.getStringProperty("imagePath"));
285
		selImagePath = PicturePathGeneratorUtils.getAbsoluteURLPath(xml
286
				.getStringProperty("selImagePath"));
285 287
		setLineWidth(xml.getDoubleProperty("lineWidth"));
286 288
		setXScale(xml.getDoubleProperty("xScale"));
287 289
		setYScale(xml.getDoubleProperty("yScale"));
......
294 296
				setImage(new URL(imagePath));
295 297
			} catch (MalformedURLException e) {
296 298
				try{
297
					setImage(new URL(pathGenerator.getAbsoluteURLPath(imagePath)));
299
					setImage(new URL(
300
							PicturePathGeneratorUtils
301
									.getAbsoluteURLPath(imagePath)));
298 302
				} catch (MalformedURLException e1) {
299 303
					setImage(new URL("file://"+ rootDir.getAbsolutePath() + File.separator +imagePath));
300 304
				}
......
303 307
				setSelImage(new URL(selImagePath));
304 308
			} catch (MalformedURLException e) {
305 309
				try{
306
					setSelImage(new URL(pathGenerator.getAbsoluteURLPath(selImagePath)));
310
					setSelImage(new URL(
311
							PicturePathGeneratorUtils
312
									.getAbsoluteURLPath(selImagePath)));
307 313
				} catch (MalformedURLException e1) {
308 314
					setSelImage(new URL("file://"+ rootDir.getAbsolutePath() + File.separator +selImagePath));
309 315
				}
src/org/gvsig/symbology/fmap/symbols/PictureFillSymbol.java (working copy)
59 59
import org.apache.log4j.Logger;
60 60
import org.gvsig.symbology.fmap.styles.BackgroundFileStyle;
61 61
import org.gvsig.symbology.fmap.styles.SimpleMarkerFillPropertiesStyle;
62
import org.gvsig.tools.file.PathGenerator;
63 62

  
64 63
import com.iver.cit.gvsig.fmap.Messages;
65 64
import com.iver.cit.gvsig.fmap.ViewPort;
......
93 92
	private BackgroundFileStyle bgImage;
94 93
	private BackgroundFileStyle bgSelImage;
95 94
	private PrintRequestAttributeSet properties;
96
	private PathGenerator pathGenerator=PathGenerator.getInstance();
97 95

  
98 96
	public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) {
99 97
 		Color fillColor = getFillColor();
......
240 238
		xml.putProperty("angle", angle);
241 239
		xml.putProperty("scaleX", xScale);
242 240
		xml.putProperty("scaleY", yScale);
243
		xml.putProperty("imagePath", pathGenerator.getURLPath(imagePath));
244
		xml.putProperty("selImagePath", pathGenerator.getURLPath(selImagePath));
241
		xml.putProperty("imagePath",
242
				PicturePathGeneratorUtils.getURLPath(imagePath));
243
		xml.putProperty("selImagePath",
244
				PicturePathGeneratorUtils.getURLPath(selImagePath));
245 245
		if (getFillColor()!=null)
246 246
			xml.putProperty("fillColor", StringUtilities.color2String(getFillColor()));
247 247

  
......
260 260

  
261 261
	public void setXMLEntity(XMLEntity xml) {
262 262

  
263
		imagePath = pathGenerator.getAbsoluteURLPath(xml.getStringProperty("imagePath"));
264
		selImagePath = pathGenerator.getAbsoluteURLPath(xml.getStringProperty("selImagePath"));
263
		imagePath = PicturePathGeneratorUtils.getAbsoluteURLPath(xml
264
				.getStringProperty("imagePath"));
265
		selImagePath = PicturePathGeneratorUtils.getAbsoluteURLPath(xml
266
				.getStringProperty("selImagePath"));
265 267
		setDescription(xml.getStringProperty("desc"));
266 268
		setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
267 269
		setAngle(xml.getDoubleProperty("angle"));
......
280 282
				setImage(new URL(imagePath));
281 283
			} catch (MalformedURLException e) {
282 284
				try{
283
					setImage(new URL(pathGenerator.getAbsoluteURLPath(imagePath)));
285
					setImage(new URL(
286
							PicturePathGeneratorUtils
287
									.getAbsoluteURLPath(imagePath)));
284 288
				} catch (MalformedURLException e1) {
285 289
					setImage(new URL("file://"+ rootDir.getAbsolutePath() + File.separator +imagePath));
286 290
				}
......
289 293
				setSelImage(new URL(selImagePath));
290 294
			} catch (MalformedURLException e) {
291 295
				try{
292
					setSelImage(new URL(pathGenerator.getAbsoluteURLPath(selImagePath)));
296
					setSelImage(new URL(
297
							PicturePathGeneratorUtils
298
									.getAbsoluteURLPath(selImagePath)));
293 299
				} catch (MalformedURLException e1) {
294 300
					setSelImage(new URL("file://"+ rootDir.getAbsolutePath() + File.separator +selImagePath));
295 301
				}
src/org/gvsig/symbology/fmap/symbols/PicturePathGeneratorUtils.java (revision 0)
1
package org.gvsig.symbology.fmap.symbols;
2

  
3
import java.io.File;
4
import java.io.UnsupportedEncodingException;
5
import java.net.MalformedURLException;
6
import java.net.URI;
7
import java.net.URL;
8
import java.net.URLDecoder;
9

  
10
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
11

  
12
public class PicturePathGeneratorUtils {
13

  
14
	public static String getAbsoluteURLPath(String path) {
15
		try {
16
			return new URL(path).toExternalForm();
17
		} catch (MalformedURLException e) {
18
			File file = new File(path);
19
			if (!file.isAbsolute()) {
20
				file = new File(SymbologyFactory.SymbolLibraryPath, path);
21
			}
22
			try {
23
				return new URL("file", null, file.getAbsolutePath())
24
						.toExternalForm();
25
			} catch (MalformedURLException e1) {
26
				// Should never fail
27
				return path;
28
			}
29
		}
30
	}
31

  
32
	public static String getURLPath(String imagePath) {
33
		URL url;
34
		try {
35
			url = new URL(imagePath);
36
			if (url.getProtocol().equals("file")) {
37
				File file = new File(url.getFile());
38
				assert file.isAbsolute(); // Internally all paths are still
39
											// absolute
40
				URI relativeURI = new File(SymbologyFactory.SymbolLibraryPath)
41
						.toURI().relativize(file.toURI());
42
				try {
43
					return URLDecoder.decode(relativeURI.getPath(), "UTF-8");
44
				} catch (UnsupportedEncodingException e) {
45
					// UTF-8 not supported?
46
					throw new AssertionError();
47
				}
48
			} else {
49
				return imagePath;
50
			}
51
		} catch (MalformedURLException e) {
52
			// PictureXXXSymbol.xxxImagePath is always created with
53
			// url.toExternalForm
54
			throw new AssertionError();
55
		}
56
	}
57
}
src/org/gvsig/symbology/gui/styling/PictureMarker.java (working copy)
68 68
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException;
69 69
import com.iver.cit.gvsig.gui.styling.AbstractTypeSymbolEditor;
70 70
import com.iver.cit.gvsig.gui.styling.EditorTool;
71
import com.iver.cit.gvsig.gui.styling.Mask;
72 71
import com.iver.cit.gvsig.gui.styling.SymbolEditor;
73 72

  
74 73
/**
......
136 135
					return PluginServices.getText(this, "bitmap_and_svg_image_files");
137 136
				}
138 137
			};
139
			JUrlFileChooser jfc = new JUrlFileChooser(getName(), null);
138
			JUrlFileChooser jfc = new JUrlFileChooser(getName());
140 139
			jfc.setFileFilter(ff);
141 140
			jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
142 141
			jfc.setSelectedFile(picFile);
......
144 143
			int returnVal = jfc.showOpenDialog(PictureMarker.this.owner);
145 144
			if(returnVal == JFileChooser.APPROVE_OPTION) {
146 145

  
147
				URL url = jfc.getSelectedURL();
146
				String url = jfc.getSelectedURLPath();
148 147
				if (url == null) return;
149
				targetLbl.setText(url.toString());
148
				targetLbl.setText(url);
150 149
				fireSymbolChangedEvent();
151 150
			}
152 151
//			if(returnVal == JFileChooser.APPROVE_OPTION) {
src/org/gvsig/symbology/gui/styling/JUrlFileChooser.java (working copy)
45 45
import java.net.URL;
46 46

  
47 47
import javax.swing.filechooser.FileFilter;
48
import javax.swing.filechooser.FileSystemView;
48 49

  
49 50
import org.gvsig.gui.beans.swing.JFileChooser;
50 51

  
51 52
import com.iver.andami.PluginServices;
53
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
52 54

  
53 55
public class JUrlFileChooser extends JFileChooser {
54 56

  
55 57
	private static final long serialVersionUID = 1844355534608274984L;
56 58

  
57
	public JUrlFileChooser(String fileChooserID, String defaultDirectory) {
58
		super(fileChooserID, defaultDirectory);
59
	public JUrlFileChooser(String fileChooserID) {
60
		super(fileChooserID, new SymbolFileSystemView());
59 61
		this.setFileFilter(ff);
60 62
		this.setFileSelectionMode(JFileChooser.FILES_ONLY);
61 63
		this.setMultiSelectionEnabled(false);
......
83 85
		}
84 86
	};
85 87

  
86
	public URL getSelectedURL() {
87
		String path;
88
		File f = getSelectedFile();  
89

  
88
	public String getSelectedURLPath() {
90 89
		try {
91
			if(f.canRead()) {
92
				return f.toURL();
93
			}
94
			else {
95
				path = f.toString();
96

  
97
				if (!path.startsWith("http"))
98
					if(path.contains("http") && 
99
							(path.endsWith(".png")
100
									|| path.endsWith(".gif")
101
									|| path.endsWith(".jpg")
102
									|| path.endsWith(".jpeg")
103
									|| path.endsWith(".bmp")
104
									|| path.endsWith(".svg"))) {
105

  
106
						path = path.substring(path.indexOf("http"), path.length());
107
						path = path.replace('\\', '/');
108
						path = path.replaceFirst("/", "//");
109

  
110
						return new URL(path);
111
					}
112
			}
90
			return new URL("file", null, getSelectedFile().getAbsolutePath())
91
					.toExternalForm();
113 92
		} catch (MalformedURLException e) {
114 93
			return null;
115 94
		}
116
		return null;
117 95
	}
118 96

  
97
	private static class SymbolFileSystemView extends FileSystemView {
98
		private File root = new File(SymbologyFactory.SymbolLibraryPath);
99
		private File[] roots = new File[] { root };
100

  
101
		@Override
102
		public File createNewFolder(File containingDir) {
103
			File folder = new File(containingDir, "New Folder");
104
			folder.mkdir();
105
			return folder;
106
		}
119 107

  
108
		@Override
109
		public File getDefaultDirectory() {
110
			return root;
111
		}
112

  
113
		@Override
114
		public File getHomeDirectory() {
115
			return root;
116
		}
117

  
118

  
119
		@Override
120
		public File[] getRoots() {
121
			return roots;
122
		}
123
	}
120 124
}
src/org/gvsig/symbology/gui/styling/PictureFill.java (working copy)
41 41
package org.gvsig.symbology.gui.styling;
42 42

  
43 43
import java.awt.Color;
44
import java.awt.Component;
45
import java.awt.Container;
46 44
import java.awt.FlowLayout;
47 45
import java.awt.Font;
48 46
import java.awt.GridLayout;
......
66 64
import org.gvsig.symbology.fmap.symbols.PictureFillSymbol;
67 65

  
68 66
import com.iver.andami.PluginServices;
69
import com.iver.andami.messages.NotificationManager;
70 67
import com.iver.cit.gvsig.fmap.core.FShape;
71 68
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
72 69
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
......
153 150
					return PluginServices.getText(this, "bitmap_and_svg_image_files");
154 151
				}
155 152
			};
156
			JUrlFileChooser jfc = new JUrlFileChooser(getName(), null);
153
			JUrlFileChooser jfc = new JUrlFileChooser(getName());
157 154
			jfc.setFileFilter(ff);
158 155
			jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
159 156
			jfc.setSelectedFile(picFile);
......
179 176
//			}
180 177
			if(returnVal == JFileChooser.APPROVE_OPTION) {
181 178

  
182
				URL url = jfc.getSelectedURL();
179
				String url = jfc.getSelectedURLPath();
183 180
				if (url == null) return;
184
				targetLbl.setText(url.toString());
181
				targetLbl.setText(url);
185 182
				fireSymbolChangedEvent();
186 183
			}
187 184
			boolean enabled = (lblFileName.getText()!="");
......
394 391
	public void refreshControls(ISymbol layer) {
395 392
		PictureFillSymbol sym = (PictureFillSymbol) layer;
396 393

  
397
		File imageFile = new File(sym.getImagePath());
398
		File selImageFile =  new File (sym.getSelImagePath());
399

  
400 394
//		boolean enabled = imageFile.exists();
401 395
//		setControlsEnabled(enabled);
402 396