Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / MultiShapeSymbolSelector.java @ 39087

History | View | Annotate | Download (5.47 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.app.gui.styling;
42

    
43
import java.awt.BorderLayout;
44

    
45
import javax.swing.JPanel;
46
import javax.swing.JTabbedPane;
47

    
48
import org.gvsig.andami.ui.mdiManager.WindowInfo;
49
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector;
50
import org.gvsig.fmap.geom.Geometry;
51
import org.gvsig.i18n.Messages;
52
import org.gvsig.symbology.SymbologyLocator;
53
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.IMultiShapeSymbol;
54
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
55
//import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.MultiShapeSymbol;
56
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
57
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
58

    
59

    
60
public class MultiShapeSymbolSelector extends JPanel implements ISymbolSelector {
61
        /**
62
         * 
63
         */
64
        private static final long serialVersionUID = 3967550608736418084L;
65
        private SymbolSelector markerSelector;
66
        private SymbolSelector lineSelector;
67
        private SymbolSelector fillSelector;
68
        private WindowInfo wi;
69
        private JTabbedPane tabbedPane;
70

    
71
        public static ISymbolSelector createSymbolBrowser() {
72
                WindowInfo winfo = new WindowInfo(WindowInfo.RESIZABLE|WindowInfo.MAXIMIZABLE|WindowInfo.ICONIFIABLE);
73
                winfo.setWidth(706);
74
                winfo.setHeight(500);
75
                winfo.setTitle(Messages.getText("symbols_browser"));
76
                return new MultiShapeSymbolSelector(winfo); 
77
        }
78
        
79
        private MultiShapeSymbolSelector(WindowInfo wi) {
80
                this((Object)null);
81
                this.wi = wi;
82
        }
83
        
84
        MultiShapeSymbolSelector(Object currSymbol) {
85
                IMultiShapeSymbol sym = (IMultiShapeSymbol) currSymbol;
86
                if (sym == null) {
87
                        markerSelector = (SymbolSelector) SymbolSelector
88
                                        .createSymbolSelector(null, Geometry.TYPES.POINT);
89
                        lineSelector = (SymbolSelector) SymbolSelector
90
                                        .createSymbolSelector(null, Geometry.TYPES.CURVE);
91
                        fillSelector = (SymbolSelector) SymbolSelector
92
                                        .createSymbolSelector(null, Geometry.TYPES.SURFACE);
93
                } else {
94
                        markerSelector = (SymbolSelector) SymbolSelector
95
                                        .createSymbolSelector(sym.getMarkerSymbol(),
96
                                                        Geometry.TYPES.POINT);
97
                        lineSelector = (SymbolSelector) SymbolSelector
98
                                        .createSymbolSelector(sym.getLineSymbol(),
99
                                                        Geometry.TYPES.CURVE);
100
                        fillSelector = (SymbolSelector) SymbolSelector
101
                                        .createSymbolSelector(sym.getFillSymbol(),
102
                                                        Geometry.TYPES.SURFACE);
103
                }
104
                initialize();
105
        }
106

    
107

    
108
        private void initialize() {
109
                setLayout(new BorderLayout());
110
                add(getJTabbedPane(), BorderLayout.CENTER);
111
        }
112

    
113

    
114
        private JTabbedPane getJTabbedPane() {
115
                if (tabbedPane == null) {
116
                        tabbedPane = new JTabbedPane();
117
                        tabbedPane.addTab(Messages.getText("marker"), markerSelector);
118
                        tabbedPane.addTab(Messages.getText("line"), lineSelector);
119
                        tabbedPane.addTab(Messages.getText("fill"), fillSelector);
120
                        tabbedPane.setPreferredSize(getWindowInfo().getMinimumSize());
121
                }
122

    
123
                return tabbedPane;
124
        }
125

    
126

    
127
        public Object getSelectedObject() {
128
            
129
                IMultiShapeSymbol sym = SymbologyLocator.getSymbologyManager().createMultiShapeSymbol();
130
                
131
                IMarkerSymbol ims = (IMarkerSymbol) markerSelector.getSelectedObject();
132
                ILineSymbol ils = (ILineSymbol) lineSelector.getSelectedObject();
133
                IFillSymbol ifs = (IFillSymbol) fillSelector.getSelectedObject();
134
                
135
                if (ims == null || ils == null || ifs == null) {
136
            /*
137
             * If one of the symbols is null, it's because the user
138
             * has cancelled so those who have called this method must
139
             * deal with null (many of them where already checking before
140
             * this change)
141
             */
142
            return null;
143
                } else {
144
            sym.setMarkerSymbol(ims);
145
            sym.setLineSymbol(ils);
146
            sym.setFillSymbol(ifs);
147
            return sym;
148
                }
149
                
150
                
151
        }
152

    
153
        public void setSymbol(Object symbol) {
154
                IMultiShapeSymbol sym = (IMultiShapeSymbol) symbol;
155
                markerSelector.setSymbol(sym.getMarkerSymbol());
156
                lineSelector.setSymbol(sym.getLineSymbol());
157
                fillSelector.setSymbol(sym.getFillSymbol());
158
        }
159

    
160
        public WindowInfo getWindowInfo() {
161
                if (wi == null) {
162
                        wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
163
                        wi.setWidth(706);
164
                        wi.setHeight(500);
165
                        wi.setTitle(Messages.getText("symbol_selector"));
166
                }
167
                return wi;
168
        }
169

    
170
        public Object getWindowProfile() {
171
                if( wi.isModal() ) {
172
                        return WindowInfo.DIALOG_PROFILE;
173
                }
174
                return WindowInfo.EDITOR_PROFILE;
175
        }
176
}