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

View differences:

StyleSelector.java
4 4
import java.awt.Component;
5 5
import java.awt.Dimension;
6 6
import java.io.File;
7
import java.io.FileFilter;
7 8
import java.util.prefs.Preferences;
8 9

  
9 10
import javax.swing.BoxLayout;
......
13 14
import javax.swing.ListCellRenderer;
14 15
import javax.swing.event.ListSelectionEvent;
15 16
import javax.swing.event.ListSelectionListener;
17
import javax.swing.event.TreeModelListener;
18
import javax.swing.tree.TreeModel;
19
import javax.swing.tree.TreePath;
16 20

  
17 21
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
18 22

  
......
44 48
			rootDir.mkdir();
45 49
		lblTitle.setText(PluginServices.getText(this, "label_styles"));
46 50
		treeRootName = PluginServices.getText(this, "style_library");
51
		treeModel = new TreeModel() {
52
    		final class MyFile extends File {
53
    			public MyFile(String pathname) {
54
    				super(pathname);
55
    			}
47 56

  
57
    			public String toString() {
58
    				if (this.equals(root))
59
    					return treeRootName;
60
    				String path = getAbsolutePath();
61
    				String prefixToRemove = rootDir.getAbsolutePath();
62
    				path = path.substring(prefixToRemove.length()+1, path.length());
63
    				return path;
64
    			}
65
    		};
66
    		MyFile root = new MyFile(rootDir.getAbsolutePath());
67

  
68
    		private FileFilter ff = new FileFilter() {
69
    			public boolean accept(File pathname) {
70
    				return pathname.isDirectory();
71
    			}
72
    		};
73

  
74
    		public Object getRoot() {
75
    			return root;
76
    		}
77

  
78
    		public int getChildCount(Object parent) {
79
    			return ((File) parent).listFiles(ff).length;
80
    		}
81

  
82
    		public boolean isLeaf(Object node) {
83
    			return getChildCount(node)==0;
84
    		}
85

  
86
    		public void addTreeModelListener(TreeModelListener l) {
87
    			// TODO Necessite?
88

  
89
    		}
90

  
91
    		public void removeTreeModelListener(TreeModelListener l) {
92
    			// TODO Necessite?
93
    		}
94

  
95
    		public Object getChild(Object parent, int index) {
96
    			return new MyFile(((File) parent).listFiles(ff)[index].getAbsolutePath());
97
    		}
98

  
99
    		public int getIndexOfChild(Object parent, Object child) {
100
    			if (parent == null)
101
    				return -1;
102
    			File[] files = ((File) parent).listFiles(ff);
103
    			for (int i = 0; i < files.length; i++) {
104
    				if (files[i].equals((File) child))
105
    					return i;
106
    			}
107
    			return -1;
108
    		}
109

  
110
    		public void valueForPathChanged(TreePath path, Object newValue) {
111
    			// TODO Auto-generated method stub
112
    		}
113

  
114
    	};
115
		getTreeFav().setModel(treeModel);
48 116
	}
49 117

  
50
	protected SelectorListModel newListModel() {
51
		SelectorListModel listModel = new SelectorListModel(
118
	protected SymbolSelectorListModel newListModel() {
119
		StyleSelectorListModel listModel = new StyleSelectorListModel(
52 120
				dir,
53 121
				selectedElement,
54 122
				sFilter,
55
				SelectorListModel.STYLE_FILE_EXTENSION);
123
				StyleSelectorListModel.STYLE_FILE_EXTENSION);
56 124
		return listModel;
57 125

  
58 126
	}
......
86 154
            ListCellRenderer renderer = new ListCellRenderer() {
87 155
        		private Color mySelectedBGColor = new Color(255,145,100,255);
88 156
    			public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
89
    				IStyle sym = (IStyle) value;
157
    				IStyle sty = (IStyle) value;
90 158
    				JPanel pnl = new JPanel();
91 159
    				BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS);
92 160
    				pnl.setLayout(layout);
......
97 165
    				StylePreviewer sp = new StylePreviewer();
98 166
    				sp.setAlignmentX(Component.CENTER_ALIGNMENT);
99 167
    				sp.setPreferredSize(new Dimension(50, 50));
100
    				sp.setStyle(sym);
168
    				sp.setStyle(sty);
101 169
    				sp.setBackground(bgColor);
102 170
    				pnl.add(sp);
103
    				JLabel lbl = new JLabel(sym.getDescription());
171
    				JLabel lbl = new JLabel(sty.getDescription());
104 172
    				lbl.setBackground(bgColor);
105 173
    				lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
106 174
    				pnl.add(lbl);

Also available in: Unified diff