Revision 10995 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/styling/SymbolSelector.java

View differences:

SymbolSelector.java
143 143
    protected GridBagLayoutPanel jPanelOptions = null;
144 144
    protected JList jListSymbols = null;
145 145
    protected String treeRootName;
146
    protected TreeModel treeModel;
146 147
    private JDecimalField txtWidth;
147 148

  
148 149
	protected SelectorFilter sFilter = new SelectorFilter() {
......
203 204
     *
204 205
     */
205 206
    private void initialize() {
207
    	treeModel = new TreeModel() {
208
    		final class MyFile extends File {
209
    			public MyFile(String pathname) {
210
    				super(pathname);
211
    			}
206 212

  
207
        this.setLayout(new BorderLayout());
208
        this.setSize(400, 221);
213
    			public String toString() {
214
    				if (this.equals(root))
215
    					return treeRootName;
216
    				String path = getAbsolutePath();
217
    				String prefixToRemove = rootDir.getAbsolutePath();
218
    				path = path.substring(prefixToRemove.length()+1, path.length());
219
    				return path;
220
    			}
221
    		};
222
    		MyFile root = new MyFile(rootDir.getAbsolutePath());
209 223

  
210
        this.add(getJNorthPanel(), BorderLayout.NORTH);
211
        this.add(getJSplitPane(), BorderLayout.CENTER);
212
        this.add(getJEastPanel(), BorderLayout.EAST);
213
        ActionListener okAction = new ActionListener() {
224
    		private FileFilter ff = new FileFilter() {
225
    			public boolean accept(File pathname) {
226
    				return pathname.isDirectory();
227
    			}
228
    		};
229

  
230
    		public Object getRoot() {
231
    			return root;
232
    		}
233

  
234
    		public int getChildCount(Object parent) {
235
    			return ((File) parent).listFiles(ff).length;
236
    		}
237

  
238
    		public boolean isLeaf(Object node) {
239
    			return getChildCount(node)==0;
240
    		}
241

  
242
    		public void addTreeModelListener(TreeModelListener l) {
243
    			// TODO Necessite?
244

  
245
    		}
246

  
247
    		public void removeTreeModelListener(TreeModelListener l) {
248
    			// TODO Necessite?
249
    		}
250

  
251
    		public Object getChild(Object parent, int index) {
252
    			return new MyFile(((File) parent).listFiles(ff)[index].getAbsolutePath());
253
    		}
254

  
255
    		public int getIndexOfChild(Object parent, Object child) {
256
    			if (parent == null)
257
    				return -1;
258
    			File[] files = ((File) parent).listFiles(ff);
259
    			for (int i = 0; i < files.length; i++) {
260
    				if (files[i].equals((File) child))
261
    					return i;
262
    			}
263
    			return -1;
264
    		}
265

  
266
    		public void valueForPathChanged(TreePath path, Object newValue) {
267
    			// TODO Auto-generated method stub
268
    		}
269

  
270
    	};
271

  
272
    	this.setLayout(new BorderLayout());
273
    	this.setSize(400, 221);
274

  
275
    	this.add(getJNorthPanel(), BorderLayout.NORTH);
276
    	this.add(getJSplitPane(), BorderLayout.CENTER);
277
    	this.add(getJEastPanel(), BorderLayout.EAST);
278
    	ActionListener okAction = new ActionListener() {
214 279
    		public void actionPerformed(ActionEvent e) {
215 280
    			PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
216 281
    		}
......
221 286
    		}
222 287
    	};
223 288

  
224
        okCancelPanel = new AcceptCancelPanel(okAction, cancelAction);
289
    	okCancelPanel = new AcceptCancelPanel(okAction, cancelAction);
225 290

  
226 291

  
227
        this.add(okCancelPanel, BorderLayout.SOUTH);
292
    	this.add(okCancelPanel, BorderLayout.SOUTH);
228 293
    }
229 294

  
230
    protected SelectorListModel newListModel() {
231
    	SelectorListModel listModel = new SelectorListModel(
295
    protected SymbolSelectorListModel newListModel() {
296
    	SymbolSelectorListModel listModel = new SymbolSelectorListModel(
232 297
    			dir,
233 298
    			(ISymbol) selectedElement,
234 299
    			sFilter,
235
    			SelectorListModel.SYMBOL_FILE_EXTENSION);
300
    			SymbolSelectorListModel.SYMBOL_FILE_EXTENSION);
236 301
    	return listModel;
237 302
    }
238 303

  
......
263 328
		return northPanel;
264 329
	}
265 330

  
266
	/**
267
     * This method initializes jList
268
     *
269
     * @return javax.swing.JList
270
     */
271
    private JTree getJListFav() {
331

  
332
    protected JTree getTreeFav() {
272 333
    	if (treeFamilies == null) {
273 334
    		treeFamilies = new JTree();
274 335
    		treeFamilies.setPreferredSize(new java.awt.Dimension(70,100));
275 336
    		try {
276
    			treeFamilies.setModel(new TreeModel() {
277
    				final class MyFile extends File {
278
    					public MyFile(String pathname) {
279
    						super(pathname);
280
    					}
281

  
282
    					public String toString() {
283
    						if (this.equals(root))
284
    							return treeRootName;
285
    						String path = getAbsolutePath();
286
    						String prefixToRemove = rootDir.getAbsolutePath();
287
    						path = path.substring(prefixToRemove.length()+1, path.length());
288
    						return path;
289
    					}
290
    				};
291
    				MyFile root = new MyFile(rootDir.getAbsolutePath());
292

  
293
    				private FileFilter ff = new FileFilter() {
294
    					public boolean accept(File pathname) {
295
    						return pathname.isDirectory();
296
    					}
297
    				};
298

  
299
    				public Object getRoot() {
300
    					return root;
301
    				}
302

  
303
    				public int getChildCount(Object parent) {
304
    					return ((File) parent).listFiles(ff).length;
305
    				}
306

  
307
    				public boolean isLeaf(Object node) {
308
    					return getChildCount(node)==0;
309
    				}
310

  
311
    				public void addTreeModelListener(TreeModelListener l) {
312
    					// TODO Necessite?
313

  
314
    				}
315

  
316
    				public void removeTreeModelListener(TreeModelListener l) {
317
    					// TODO Necessite?
318
    				}
319

  
320
    				public Object getChild(Object parent, int index) {
321
    					return new MyFile(((File) parent).listFiles(ff)[index].getAbsolutePath());
322
    				}
323

  
324
    				public int getIndexOfChild(Object parent, Object child) {
325
    					if (parent == null)
326
    						return -1;
327
    					File[] files = ((File) parent).listFiles(ff);
328
    					for (int i = 0; i < files.length; i++) {
329
    						if (files[i].equals((File) child))
330
    							return i;
331
    					}
332
    					return -1;
333
    				}
334

  
335
    				public void valueForPathChanged(TreePath path, Object newValue) {
336
    					// TODO Auto-generated method stub
337
    				}
338

  
339
    			});
337
    			treeFamilies.setModel(treeModel);
340 338
    			treeFamilies.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
341 339
					public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
342 340
						dir = (File)
......
519 517
    		jScrollPane = new JScrollPane();
520 518
    		jScrollPane.setPreferredSize(new java.awt.Dimension(80,130));
521 519
    		jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
522
    		jScrollPane.setViewportView(getJListFav());
520
    		jScrollPane.setViewportView(getTreeFav());
523 521
    	}
524 522
    	return jScrollPane;
525 523
    }
......
724 722
			public boolean accept(File f) {
725 723
				return f.getAbsolutePath().
726 724
				toLowerCase().
727
				endsWith(SelectorListModel.SYMBOL_FILE_EXTENSION);
725
				endsWith(SymbolSelectorListModel.SYMBOL_FILE_EXTENSION);
728 726
			}
729 727

  
730 728
			public String getDescription() {
......
741 739
		if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
742 740
			File targetFile = jfc.getSelectedFile();
743 741

  
744
			String fExtension = SelectorListModel.SYMBOL_FILE_EXTENSION;
742
			String fExtension = SymbolSelectorListModel.SYMBOL_FILE_EXTENSION;
745 743

  
746 744
			// apply description
747 745
			String desc;

Also available in: Unified diff