root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / StyleSelector.java @ 10959
History | View | Annotate | Download (3.67 KB)
1 | 10959 | jaume | package com.iver.cit.gvsig.gui.styling; |
---|---|---|---|
2 | |||
3 | import java.awt.Color; |
||
4 | import java.awt.Component; |
||
5 | import java.awt.Dimension; |
||
6 | import java.io.File; |
||
7 | import java.util.prefs.Preferences; |
||
8 | |||
9 | import javax.swing.BoxLayout; |
||
10 | import javax.swing.JLabel; |
||
11 | import javax.swing.JList; |
||
12 | import javax.swing.JPanel; |
||
13 | import javax.swing.ListCellRenderer; |
||
14 | import javax.swing.event.ListSelectionEvent; |
||
15 | import javax.swing.event.ListSelectionListener; |
||
16 | |||
17 | import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
||
18 | |||
19 | import com.iver.andami.PluginServices; |
||
20 | import com.iver.cit.gvsig.fmap.core.styles.IStyle; |
||
21 | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
||
22 | |||
23 | /**
|
||
24 | *
|
||
25 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
26 | *
|
||
27 | */
|
||
28 | public class StyleSelector extends SymbolSelector { |
||
29 | |||
30 | public StyleSelector(IStyle style, int shapeType) { |
||
31 | this(style, shapeType, new SelectorFilter() { |
||
32 | public boolean accepts(Object obj) { |
||
33 | return obj instanceof IStyle; |
||
34 | } |
||
35 | }); |
||
36 | } |
||
37 | |||
38 | public StyleSelector(IStyle style, int shapeType, SelectorFilter filter) { |
||
39 | super(null, shapeType, filter); |
||
40 | selectedElement = style; |
||
41 | Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" ); |
||
42 | rootDir = new File(prefs.get("SymbolStylesFolder", System.getProperty("user.home")+"/gvSIG/Styles")); |
||
43 | if (!rootDir.exists())
|
||
44 | rootDir.mkdir(); |
||
45 | lblTitle.setText(PluginServices.getText(this, "label_styles")); |
||
46 | treeRootName = PluginServices.getText(this, "style_library"); |
||
47 | |||
48 | } |
||
49 | |||
50 | protected SelectorListModel newListModel() {
|
||
51 | SelectorListModel listModel = new SelectorListModel(
|
||
52 | dir, |
||
53 | selectedElement, |
||
54 | sFilter, |
||
55 | SelectorListModel.STYLE_FILE_EXTENSION); |
||
56 | return listModel;
|
||
57 | |||
58 | } |
||
59 | |||
60 | protected JPanel getJPanelOptions() { |
||
61 | if (jPanelOptions == null) { |
||
62 | jPanelOptions = new GridBagLayoutPanel();
|
||
63 | // nothing in the panel
|
||
64 | |||
65 | } |
||
66 | return jPanelOptions;
|
||
67 | } |
||
68 | |||
69 | /**
|
||
70 | * This method initializes jList
|
||
71 | *
|
||
72 | * @return javax.swing.JList
|
||
73 | */
|
||
74 | protected JList getJListSymbols() { |
||
75 | if (jListSymbols == null) { |
||
76 | jListSymbols = new JList(); |
||
77 | jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
||
78 | jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
|
||
79 | jListSymbols.setVisibleRowCount(-1);
|
||
80 | jListSymbols.addListSelectionListener(new ListSelectionListener() { |
||
81 | public void valueChanged(ListSelectionEvent e) { |
||
82 | setStyle(jListSymbols.getSelectedValue()); |
||
83 | updateOptionsPanel(); |
||
84 | } |
||
85 | }); |
||
86 | ListCellRenderer renderer = new ListCellRenderer() { |
||
87 | private Color mySelectedBGColor = new Color(255,145,100,255); |
||
88 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
||
89 | IStyle sym = (IStyle) value; |
||
90 | JPanel pnl = new JPanel(); |
||
91 | BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS); |
||
92 | pnl.setLayout(layout); |
||
93 | Color bgColor = (isSelected) ? mySelectedBGColor
|
||
94 | : getJListSymbols().getBackground(); |
||
95 | |||
96 | pnl.setBackground(bgColor); |
||
97 | StylePreviewer sp = new StylePreviewer();
|
||
98 | sp.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||
99 | sp.setPreferredSize(new Dimension(50, 50)); |
||
100 | sp.setStyle(sym); |
||
101 | sp.setBackground(bgColor); |
||
102 | pnl.add(sp); |
||
103 | JLabel lbl = new JLabel(sym.getDescription()); |
||
104 | lbl.setBackground(bgColor); |
||
105 | lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||
106 | pnl.add(lbl); |
||
107 | |||
108 | return pnl;
|
||
109 | } |
||
110 | |||
111 | }; |
||
112 | jListSymbols.setCellRenderer(renderer); |
||
113 | } |
||
114 | return jListSymbols;
|
||
115 | } |
||
116 | |||
117 | protected void setStyle(Object selectedValue) { |
||
118 | // TODO missing change SymbolPreviewer by a StylePrevier and apply it
|
||
119 | // the new style
|
||
120 | } |
||
121 | |||
122 | } |