Revision 39765

View differences:

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
41 41
package org.gvsig.app.gui.styling;
42 42

  
43 43
import java.awt.BorderLayout;
44
import java.awt.Component;
45
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionListener;
44 47

  
48
import javax.swing.BorderFactory;
49
import javax.swing.JButton;
45 50
import javax.swing.JPanel;
46 51
import javax.swing.JTabbedPane;
52
import javax.swing.border.Border;
47 53

  
54
import org.slf4j.Logger;
55
import org.slf4j.LoggerFactory;
56

  
57
import org.gvsig.andami.PluginServices;
48 58
import org.gvsig.andami.ui.mdiManager.WindowInfo;
49 59
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector;
50 60
import org.gvsig.fmap.geom.Geometry;
61
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
62
import org.gvsig.fmap.geom.GeometryLocator;
63
import org.gvsig.fmap.geom.GeometryManager;
64
import org.gvsig.fmap.geom.type.GeometryType;
51 65
import org.gvsig.i18n.Messages;
52 66
import org.gvsig.symbology.SymbologyLocator;
53 67
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.IMultiShapeSymbol;
54 68
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
55
//import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.MultiShapeSymbol;
56 69
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
57 70
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
71
import org.gvsig.tools.exception.BaseException;
58 72

  
59 73

  
60
public class MultiShapeSymbolSelector extends JPanel implements ISymbolSelector {
61
	/**
62
	 * 
63
	 */
74
public class MultiShapeSymbolSelector extends JPanel implements
75
    ISymbolSelector, ActionListener {
76
    
77
    private static Logger logger = LoggerFactory.getLogger(
78
        MultiShapeSymbolSelector.class);
79

  
64 80
	private static final long serialVersionUID = 3967550608736418084L;
65 81
	private SymbolSelector markerSelector;
66 82
	private SymbolSelector lineSelector;
67 83
	private SymbolSelector fillSelector;
68 84
	private WindowInfo wi;
69 85
	private JTabbedPane tabbedPane;
86
	
87
	private GeometryManager gManager = null;
88
	private JButton closeButton = null;
89
	private JPanel closeButtonPanel = null;
70 90

  
71 91
	public static ISymbolSelector createSymbolBrowser() {
72 92
		WindowInfo winfo = new WindowInfo(WindowInfo.RESIZABLE|WindowInfo.MAXIMIZABLE|WindowInfo.ICONIFIABLE);
73 93
		winfo.setWidth(706);
74 94
		winfo.setHeight(500);
75 95
		winfo.setTitle(Messages.getText("symbols_browser"));
76
		return new MultiShapeSymbolSelector(winfo); 
96
		MultiShapeSymbolSelector resp = null;
97
		
98
		try {
99
		    /*
100
		     * This instantiates a symbol browser
101
		     * (a selector without accept/cancel panel)
102
		     */
103
            resp = new MultiShapeSymbolSelector();
104
            resp.wi = winfo;
105
        } catch (BaseException e) {
106
            logger.info("Unable to create symbol browser, will use selector.", e);
107
            resp = new MultiShapeSymbolSelector(winfo);
108
        }
109
        return resp;
77 110
	}
78 111
	
112
	/*
113
	 * This instantiates a symbol browser 
114
	 */
115
    private MultiShapeSymbolSelector() throws BaseException {
116

  
117
        GeometryType
118
        gt = getGeomManager().getGeometryType(Geometry.TYPES.POINT,
119
            SUBTYPES.GEOM2D);
120
        markerSelector = new SymbolSelectorBrowser(gt, true);
121
        gt = getGeomManager().getGeometryType(Geometry.TYPES.CURVE,
122
            SUBTYPES.GEOM2D);
123
        lineSelector = new SymbolSelectorBrowser(gt, true);
124
        gt = getGeomManager().getGeometryType(Geometry.TYPES.SURFACE,
125
            SUBTYPES.GEOM2D);
126
        fillSelector = new SymbolSelectorBrowser(gt, true);
127

  
128
        initialize(true);
129
    }
130
	
79 131
	private MultiShapeSymbolSelector(WindowInfo wi) {
80 132
		this((Object)null);
81 133
		this.wi = wi;
......
101 153
					.createSymbolSelector(sym.getFillSymbol(),
102 154
							Geometry.TYPES.SURFACE);
103 155
		}
104
		initialize();
156
		initialize(false);
105 157
	}
106 158

  
107 159

  
108
	private void initialize() {
160
	private void initialize(boolean add_close_button) {
109 161
		setLayout(new BorderLayout());
110 162
		add(getJTabbedPane(), BorderLayout.CENTER);
163
		if (add_close_button) {
164
		    add(getCloseButtonPanel(), BorderLayout.SOUTH);
165
		}
111 166
	}
112 167

  
113

  
114
	private JTabbedPane getJTabbedPane() {
168
    private JTabbedPane getJTabbedPane() {
115 169
		if (tabbedPane == null) {
116 170
			tabbedPane = new JTabbedPane();
117 171
			tabbedPane.addTab(Messages.getText("marker"), markerSelector);
......
173 227
		}
174 228
		return WindowInfo.EDITOR_PROFILE;
175 229
	}
230
	
231
	private GeometryManager getGeomManager() {
232
	    
233
	    if (gManager == null) {
234
	        gManager = GeometryLocator.getGeometryManager();
235
	    }
236
	    return gManager;
237
	}
238

  
239
	private JButton getCloseButton() {
240
	    if (closeButton == null) {
241
	        String txt = Messages.getText("close");
242
	        closeButton = new JButton(txt);
243
	        closeButton.addActionListener(this);
244
	    }
245
	    return closeButton;
246
	}
247
	
248
    private Component getCloseButtonPanel() {
249
        
250
        if (closeButtonPanel == null) {
251
            closeButtonPanel = new JPanel();
252
            Border brd = BorderFactory.createEmptyBorder(10, 10, 10, 10);
253
            closeButtonPanel.setBorder(brd);
254
            closeButtonPanel.setLayout(new BorderLayout());
255
            closeButtonPanel.add(getCloseButton(), BorderLayout.EAST);
256
        }
257
        return closeButtonPanel;
258
    }
259

  
260
    public void actionPerformed(ActionEvent e) {
261
        
262
        if (e.getSource() == this.getCloseButton()) {
263
            PluginServices.getMDIManager().closeWindow(this);
264
        }
265
        
266
    }
267

  
176 268
}
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/SymbolSelectorBrowser.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2013 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.app.gui.styling;
24

  
25
import java.awt.BorderLayout;
26
import org.gvsig.fmap.geom.type.GeometryType;
27

  
28

  
29
/**
30
 * Same as symbol selector but does not
31
 * ass Accept/Cancel button
32
 * 
33
 * Containing wizard will have a 'Close' button
34
 * or similar 
35
 * @author jldominguez
36
 *
37
 */
38
public class SymbolSelectorBrowser extends SymbolSelector {
39
    
40
    public SymbolSelectorBrowser(GeometryType shpt, boolean init) {
41
        
42
        super(null, shpt, init);
43
    }
44
    
45
    /**
46
     * Same as the symbol selector but without the accept/cancel
47
     * panel
48
     *
49
     */
50
    protected void initialize(Object currentElement) throws ClassNotFoundException {
51
        library = new SymbolLibrary(rootDir);
52

  
53
        this.setLayout(new BorderLayout());
54
        this.setSize(400, 221);
55

  
56
        this.add(getJNorthPanel(), BorderLayout.NORTH);
57
        this.add(getJSplitPane(), BorderLayout.CENTER);
58
        this.add(getJEastPanel(), BorderLayout.EAST);
59

  
60
        libraryBrowser.setSelectionRow(0);
61

  
62
        SillyDragNDropAction dndAction = new SillyDragNDropAction();
63
        libraryBrowser.addMouseListener(dndAction);
64
        libraryBrowser.addMouseMotionListener(dndAction);
65
        getJListSymbols().addMouseListener(dndAction);
66
        getJListSymbols().addMouseMotionListener(dndAction);
67
        setSymbol(currentElement);
68
    }
69

  
70

  
71
}

Also available in: Unified diff