Revision 39193

View differences:

tags/v2_0_0_Build_2057/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
4
		 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5

  
6
	<modelVersion>4.0.0</modelVersion>
7
	<artifactId>org.gvsig.symbology.swing</artifactId>
8
	<packaging>pom</packaging>
9
	<name>org.gvsig.symbology.swing</name>
10
	<parent>
11
		<groupId>org.gvsig</groupId>
12
		<artifactId>org.gvsig.symbology</artifactId>
13
		<version>2.0.0-SNAPSHOT</version>
14
	</parent>
15
	<dependencies>
16
		<dependency>
17
			<groupId>org.gvsig</groupId>
18
			<artifactId>org.gvsig.symbology.lib.api</artifactId>
19
			<version>2.0.0-SNAPSHOT</version>
20
		</dependency>
21
	</dependencies>
22

  
23
	<modules>
24
		<module>org.gvsig.symbology.swing.api</module>
25
		<module>org.gvsig.symbology.swing.impl</module>
26
	</modules>
27
</project>
28

  
0 29

  
tags/v2_0_0_Build_2057/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.impl/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
0 9

  
tags/v2_0_0_Build_2057/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.impl/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	org.gvsig.tools packages.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.symbology">
26
		<priority value="DEBUG" />
27
	</category>
28

  
29
	<!-- 
30
	By default, show only logging messages of INFO level or higher, 
31
	through the previously configured CONSOLE appender. 
32
	-->
33
	<root>
34
		<priority value="INFO" />
35
		<appender-ref ref="CONSOLE" />
36
	</root>
37
</log4j:configuration>
0 38

  
tags/v2_0_0_Build_2057/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.symbology.swing.impl.SymbologySwingDefaultImplLibrary
tags/v2_0_0_Build_2057/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.impl/src/main/java/org/gvsig/symbology/swing/impl/SymbologySwingDefaultImplLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.symbology.swing.impl;
23

  
24

  
25
import org.gvsig.symbology.swing.SymbologySwingLibrary;
26
import org.gvsig.symbology.swing.SymbologySwingLocator;
27
import org.gvsig.tools.library.AbstractLibrary;
28
import org.gvsig.tools.library.LibraryException;
29

  
30
/**
31
 * Library for default swing implementation initialization and configuration.
32
 * 
33
 * @author gvSIG team
34
 * @version $Id$
35
 */
36
public class SymbologySwingDefaultImplLibrary extends AbstractLibrary {
37

  
38
    @Override
39
    public void doRegistration() {
40
        registerAsImplementationOf(SymbologySwingLibrary.class);
41
    }
42

  
43
    @Override
44
    protected void doInitialize() throws LibraryException {
45
        SymbologySwingLocator
46
            .registerSwingManager(DefaultSymbologySwingManager.class);
47
        
48
        // LineProperties
49
        IconThemeHelper.registerIcon("line-properties", "line-properties-join-bevel", this);
50
        IconThemeHelper.registerIcon("line-properties", "line-properties-join-bevel-selected", this);
51
        IconThemeHelper.registerIcon("line-properties", "line-properties-join-miter", this);
52
        IconThemeHelper.registerIcon("line-properties", "line-properties-join-miter-selected", this);
53
        IconThemeHelper.registerIcon("line-properties", "line-properties-join-round", this);
54
        IconThemeHelper.registerIcon("line-properties", "line-properties-join-round-selected", this);
55
        IconThemeHelper.registerIcon("line-properties", "line-properties-cap-butt", this);
56
        IconThemeHelper.registerIcon("line-properties", "line-properties-cap-butt-selected", this);
57
        IconThemeHelper.registerIcon("line-properties", "line-properties-cap-round", this);
58
        IconThemeHelper.registerIcon("line-properties", "line-properties-cap-round-selected", this);
59
        IconThemeHelper.registerIcon("line-properties", "line-properties-cap-square", this);
60
        IconThemeHelper.registerIcon("line-properties", "line-properties-cap-square-selected", this);
61
        // SymbolLayerManager
62
        IconThemeHelper.registerIcon("symbol-editor", "symbol-editor-unlocked", this);
63
    }
64

  
65
    @Override
66
    protected void doPostInitialize() throws LibraryException {
67
        // Nothing to do
68
    }
69

  
70
}
0 71

  
tags/v2_0_0_Build_2057/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.impl/src/main/java/org/gvsig/symbology/swing/impl/IconThemeHelper.java
1
package org.gvsig.symbology.swing.impl;
2

  
3
import java.awt.Image;
4

  
5
import javax.swing.ImageIcon;
6

  
7
import org.gvsig.tools.swing.api.ToolsSwingLocator;
8
import org.gvsig.tools.swing.icontheme.IconTheme;
9
import org.gvsig.tools.swing.icontheme.IconThemeManager;
10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
12

  
13
public class IconThemeHelper {
14

  
15
	private static Logger logger = LoggerFactory.getLogger(IconThemeHelper.class);
16
	
17
	@SuppressWarnings("rawtypes")
18
	public static void registerIcon(String group, String name, Object obj) {
19
		String resourceName;
20
		ClassLoader loader;
21
		String provider; 
22
		IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getCurrent();
23
		if( group == null || group.trim().length()==0 ) {
24
			resourceName = "images/"+name+".png";
25
		} else {
26
			resourceName = "images/"+group+"/"+name+".png";
27
		}
28
		if( obj instanceof Class ) {
29
			loader = ((Class) obj).getClassLoader();
30
			provider = ((Class) obj).getName(); 
31
		} else {
32
			loader = obj.getClass().getClassLoader();
33
			provider = obj.getClass().getName();
34
		}
35
		try {
36
			iconTheme.registerDefault(provider, group, name, null, loader.getResource(resourceName));
37
		} catch( Throwable e) {
38
			logger.info(e.getMessage());
39
		}
40
	}
41

  
42
	public static ImageIcon getImageIcon(String iconName) {
43
		IconThemeManager manager = ToolsSwingLocator.getIconThemeManager();
44
		return manager.getCurrent().get(iconName);
45
	}
46
	
47
	public static Image getImage(String iconName) {
48
		IconThemeManager manager = ToolsSwingLocator.getIconThemeManager();
49
		return manager.getCurrent().get(iconName).getImage();
50
	}
51
}
0 52

  
tags/v2_0_0_Build_2057/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.impl/src/main/java/org/gvsig/symbology/swing/impl/DefaultSymbologySwingManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.symbology.swing.impl;
23

  
24
import java.util.List;
25

  
26
import org.gvsig.app.gui.styling.SymbolEditor;
27
import org.gvsig.gui.ColorTablePainter;
28
import org.gvsig.gui.ColorTablesFactory;
29
import org.gvsig.gui.DefaultColorTablesFactory;
30
import org.gvsig.symbology.SymbologyLocator;
31
import org.gvsig.symbology.SymbologyManager;
32
import org.gvsig.symbology.swing.SymbologySwingManager;
33
import org.gvsig.symbology.swing.SymbologyWindowManager;
34

  
35
/**
36
 * Default implementation of the {@link SymbologySwingManager}.
37
 * 
38
 * @author gvSIG Team
39
 * @version $Id$
40
 */
41
public class DefaultSymbologySwingManager implements
42
    SymbologySwingManager {
43

  
44
    private SymbologyManager manager;
45
    // private I18nManager i18nmanager = null;
46
    private SymbologyWindowManager windowManager;
47
    private ColorTablesFactory colorTablesFactory;
48

  
49
    public DefaultSymbologySwingManager() {
50
        this.manager = SymbologyLocator.getSymbologyManager();
51
        // this.i18nmanager = ToolsLocator.getI18nManager();
52
        this.windowManager = new DefaultSymbologyWindowManager();
53
        colorTablesFactory = new DefaultColorTablesFactory();
54
    }
55

  
56
    public SymbologyManager getManager() {
57
        return this.manager;
58
    }
59

  
60
    public String getTranslation(String key) {
61
        // TODO: add I18nManager usage when org.gvsig.tools.lib 2.1.0 becomes
62
        // available
63
        // return this.i18nmanager.getTranslation(key);
64
        return key;
65
    }
66

  
67
    public void registerWindowManager(SymbologyWindowManager manager) {
68
        this.windowManager = manager;
69
    }
70

  
71
    public SymbologyWindowManager getWindowManager() {
72
        return this.windowManager;
73
    }
74
    
75
	@SuppressWarnings("rawtypes")
76
	public void addSymbolEditorPanel(Class abstractTypeSymbolEditorPanelClass, int shapeType) {
77
		SymbolEditor.addSymbolEditorPanel(abstractTypeSymbolEditorPanelClass, shapeType);
78
	}
79

  
80
	public void setColorTablesFactory(ColorTablesFactory factory) {
81
		colorTablesFactory = factory;
82
	}
83

  
84
	public List<ColorTablePainter> createColorTables() {
85
		if (colorTablesFactory != null){
86
		    return colorTablesFactory.createColorTables();
87
		}
88
		return null;
89
	}
90
	
91
	public ColorTablesFactory getColorTablesFactory() {
92
		return this.colorTablesFactory;
93
	}
94
}
0 95

  
tags/v2_0_0_Build_2057/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.impl/src/main/java/org/gvsig/symbology/swing/impl/DefaultSymbologyWindowManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.symbology.swing.impl;
23

  
24
import java.awt.BorderLayout;
25
import java.awt.Dimension;
26
import java.awt.Toolkit;
27
import java.awt.event.ComponentEvent;
28
import java.awt.event.ComponentListener;
29

  
30
import javax.swing.JFrame;
31
import javax.swing.JPanel;
32

  
33
import org.gvsig.symbology.swing.SymbologyWindowManager;
34

  
35
/**
36
 * Default implementation for the {@link SymbologyWindowManager}.
37
 * 
38
 * @author gvSIG Team
39
 * @version $Id$
40
 */
41
public class DefaultSymbologyWindowManager implements
42
    SymbologyWindowManager, ComponentListener {
43

  
44
    public void showWindow(JPanel panel, String title, int mode) {
45
        JFrame frame = new JFrame();
46
        // frame.setAlwaysOnTop(true);
47

  
48
        final Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
49
        frame.setLocation(s.width / 4, s.height / 4);
50

  
51
        frame.setLayout(new BorderLayout());
52
        frame.setTitle(title);
53
        frame.add(panel, BorderLayout.CENTER);
54

  
55
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
56

  
57
        frame.setSize(400, 400);
58
        panel.addComponentListener(this);
59

  
60
        frame.pack();
61
        frame.setVisible(true);
62
    }
63

  
64
    public void componentHidden(ComponentEvent componentEvent) {
65
        JFrame frame =
66
            (JFrame) ((JPanel) componentEvent.getSource()).getRootPane()
67
                .getParent();
68
        frame.setVisible(false);
69
        frame.dispose();
70
    }
71

  
72
    public void componentMoved(ComponentEvent arg0) {
73
        // Do nothing
74
    }
75

  
76
    public void componentResized(ComponentEvent arg0) {
77
        // Do nothing
78
    }
79

  
80
    public void componentShown(ComponentEvent arg0) {
81
        // Do nothing
82
    }
83
}
0 84

  
tags/v2_0_0_Build_2057/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.impl/src/main/java/org/gvsig/symbology/swing/impl/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.symbology package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>Symbology swing library API default implementation.</p>
11

  
12
</body>
13
</html>
0 14

  
tags/v2_0_0_Build_2057/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.impl/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.symbology.swing.impl</artifactId>
6
	<packaging>jar</packaging>
7
	<name>org.gvsig.symbology.swing.impl</name>
8
	<parent>
9
		<groupId>org.gvsig</groupId>
10
		<artifactId>org.gvsig.symbology.swing</artifactId>
11
		<version>2.0.0-SNAPSHOT</version>
12
	</parent>
13
	<dependencies>
14
		<dependency>
15
			<groupId>org.gvsig</groupId>
16
			<artifactId>org.gvsig.tools.swing.api</artifactId>
17
			<scope>compile</scope>
18
		</dependency>
19
		<dependency>
20
			<groupId>org.gvsig</groupId>
21
			<artifactId>org.gvsig.symbology.lib.api</artifactId>
22
			<version>2.0.0-SNAPSHOT</version>
23
			<scope>compile</scope>
24
		</dependency>
25
		<dependency>
26
			<groupId>org.gvsig</groupId>
27
			<artifactId>org.gvsig.symbology.swing.api</artifactId>
28
			<version>2.0.0-SNAPSHOT</version>
29
			<scope>compile</scope>
30
		</dependency>
31
		<dependency>
32
			<groupId>org.gvsig</groupId>
33
			<artifactId>org.gvsig.symbology.swing.api</artifactId>
34
			<version>2.0.0-SNAPSHOT</version>
35
			<type>test-jar</type>
36
			<scope>test</scope>
37
		</dependency>
38
		<dependency>
39
			<groupId>org.gvsig</groupId>
40
			<artifactId>org.gvsig.symbology.lib.impl</artifactId>
41
			<version>2.0.0-SNAPSHOT</version>
42
			<scope>test</scope>
43
		</dependency>
44
		<dependency>
45
			<groupId>org.gvsig</groupId>
46
			<artifactId>org.gvsig.ui</artifactId>
47
			<scope>compile</scope>
48
		</dependency>
49
		<dependency>
50
			<groupId>org.gvsig</groupId>
51
			<artifactId>org.gvsig.fmap.dal</artifactId>
52
			<classifier>spi</classifier>
53
			<scope>test</scope>
54
		</dependency>
55
		<dependency>
56
			<groupId>org.gvsig</groupId>
57
			<artifactId>org.gvsig.fmap.geometry</artifactId>
58
			<classifier>impl</classifier>
59
			<scope>test</scope>
60
		</dependency>
61
		<dependency>
62
			<groupId>org.gvsig</groupId>
63
			<artifactId>org.gvsig.projection</artifactId>
64
			<scope>test</scope>
65
		</dependency>
66
		<dependency>
67
			<groupId>org.gvsig</groupId>
68
			<artifactId>org.gvsig.projection</artifactId>
69
			<classifier>cresques-impl</classifier>
70
			<scope>test</scope>
71
		</dependency>
72
		<dependency>
73
			<groupId>org.gvsig</groupId>
74
			<artifactId>org.gvsig.compat</artifactId>
75
			<classifier>se</classifier>
76
			<scope>test</scope>
77
		</dependency>
78
		<dependency>
79
			<groupId>org.gvsig</groupId>
80
			<artifactId>org.gvsig.fmap.mapcontext</artifactId>
81
			<scope>test</scope>
82
		</dependency>
83
		<dependency>
84
			<groupId>org.gvsig</groupId>
85
			<artifactId>org.gvsig.fmap.mapcontext</artifactId>
86
			<classifier>impl</classifier>
87
			<scope>test</scope>
88
		</dependency>
89
	</dependencies>
90
</project>
0 91

  
tags/v2_0_0_Build_2057/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.api/src/main/java/org/gvsig/app/gui/styling/SymbolLevelsWindow.java
1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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
import java.awt.Color;
45
import java.awt.Component;
46
import java.awt.FlowLayout;
47
import java.awt.Font;
48
import java.awt.Graphics;
49
import java.awt.Graphics2D;
50
import java.awt.Point;
51
import java.awt.Rectangle;
52
import java.awt.event.ActionEvent;
53
import java.awt.event.ActionListener;
54
import java.awt.event.MouseEvent;
55
import java.awt.event.MouseListener;
56
import java.awt.geom.GeneralPath;
57
import java.util.Hashtable;
58
import java.util.Iterator;
59

  
60
import javax.swing.BorderFactory;
61
import javax.swing.BoxLayout;
62
import javax.swing.Icon;
63
import javax.swing.JButton;
64
import javax.swing.JCheckBox;
65
import javax.swing.JComponent;
66
import javax.swing.JPanel;
67
import javax.swing.JScrollPane;
68
import javax.swing.JTable;
69
import javax.swing.border.EtchedBorder;
70
import javax.swing.event.ChangeEvent;
71
import javax.swing.table.DefaultTableModel;
72
import javax.swing.table.TableCellEditor;
73
import javax.swing.table.TableColumn;
74
import javax.swing.table.TableModel;
75

  
76
import org.gvsig.andami.PluginServices;
77
import org.gvsig.andami.ui.mdiManager.IWindow;
78
import org.gvsig.andami.ui.mdiManager.WindowInfo;
79
import org.gvsig.app.project.documents.gui.TableSymbolCellRenderer;
80
import org.gvsig.fmap.mapcontext.MapContextLocator;
81
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort;
82
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
83
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
84
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
85
import org.gvsig.gui.beans.AcceptCancelPanel;
86
import org.gvsig.gui.beans.swing.JBlank;
87
import org.gvsig.gui.beans.swing.celleditors.BooleanTableCellEditor;
88
import org.gvsig.gui.beans.swing.celleditors.IntegerTableCellEditor;
89
import org.gvsig.gui.beans.swing.cellrenderers.BooleanTableCellRenderer;
90
import org.gvsig.gui.beans.swing.cellrenderers.NumberTableCellRenderer;
91
import org.gvsig.i18n.Messages;
92

  
93

  
94
/**
95
 * Creates a panel to specify an order for the symbols of a map. This order
96
 * is important when the map is going to be painted because, apart from that
97
 * the waste of time can be less, the final representation of the map will
98
 * depend on this order.
99
 *
100
 *
101
 * @author jaume dominguez faus - jaume.dominguez@iver.es
102
 */
103
public class SymbolLevelsWindow extends JPanel implements IWindow, ActionListener {
104
	private static final long serialVersionUID = 3241898997869313055L;
105
	private static final int DESCRIPTION_COLUMN_INDEX = 1;
106
	private static final int SYMBOL_COLUMN_INDEX = 0;
107
	private static final int MERGE_COLUMN_INDEX = 3;
108
	private static final int JOIN_COLUMN_INDEX = 2;
109
	private static final int FIRST_LEVEL_COLUMN_INDEX = 2;
110
	private static final String[] defaultHeaders = new String[] {
111
		Messages.getText("symbol"),
112
		Messages.getText("description"),
113
		Messages.getText("join"),
114
		Messages.getText("merge"),
115
	};
116
	private static final int DEFAULT_VIEW = 0;
117
	private static final int ADVANCED_VIEW = 1;
118
	private static int viewMode = ADVANCED_VIEW;
119
	private JCheckBox chkSpecifyDrawOrder = null;
120
	private JPanel pnlCenter = null;
121
	private JScrollPane srclLevels = null;
122
	private JTable tblLevels = null;
123
	private JButton btnUp = null;
124
	private JButton btnDown;
125
	private JPanel pnlSouth = null;
126
	private String[] advancedHeaders;
127
	private JButton btnSwitchView;
128
	private ZSort zSort;
129
	private SymbolSummary summary = new SymbolSummary();
130

  
131
	private ActionListener action = new ActionListener() {
132
		public void actionPerformed(ActionEvent e) {
133
			String actionCommand = e.getActionCommand();
134
			if ("OK".equals(actionCommand)) {
135
				tblLevels.editingStopped(new ChangeEvent(tblLevels));
136
				applyValues();
137
			}
138

  
139
			PluginServices.getMDIManager().closeWindow(SymbolLevelsWindow.this);
140

  
141
		}
142
	};
143

  
144
	public WindowInfo getWindowInfo() {
145
		WindowInfo wi = new WindowInfo(WindowInfo.RESIZABLE | WindowInfo.MODALDIALOG);
146
		wi.setTitle(Messages.getText("symbol_levels"));
147
		wi.setWidth(getWidth()+10);
148
		wi.setHeight(getHeight());
149
		return wi;
150
	}
151
	/**
152
	 * Completes the main table of the panel with the symbols contained in the
153
	 * legend of the map.
154
	 *
155
	 */
156
	private void applyValues() {
157

  
158
		// update symbol order
159
		TableModel model = tblLevels.getModel();
160

  
161

  
162

  
163
		Hashtable<ISymbol, int[] > aTable = new Hashtable<ISymbol, int[]>();
164
		ISymbol[] symbols = new ISymbol[model.getRowCount()];
165
		for (int i = 0; i < symbols.length; i++) {
166
			symbols[i] = (ISymbol) model.getValueAt(i, SYMBOL_COLUMN_INDEX);
167
			int length = 1;
168
			if (symbols[i] instanceof IMultiLayerSymbol) {
169
				IMultiLayerSymbol mlSym = (IMultiLayerSymbol) symbols[i];
170
				length = mlSym.getLayerCount();
171
			}
172

  
173
			int[] symbolLevels = new int[length];
174
			if (viewMode == DEFAULT_VIEW) {
175
				// default view (JOIN and MERGE)
176
				if (symbols[i] instanceof IMultiLayerSymbol) {
177
					boolean join = ((Boolean) model.getValueAt(i, JOIN_COLUMN_INDEX)).booleanValue();
178
					boolean merge= ((Boolean) model.getValueAt(i, MERGE_COLUMN_INDEX)).booleanValue();
179
					boolean needToJoin = true;
180
					if (merge && i>0) {
181
						int j=0;
182
						try {
183
							int[] prevSymbolLevels = aTable.get(symbols[i-1]);
184
							for (j = 0; j < symbolLevels.length; j++) {
185
								symbolLevels[j] = prevSymbolLevels[j];
186
							}
187
						} catch (IndexOutOfBoundsException ex) {
188
							/* perfect, no problem
189
							 * the previous symbol has different amount of layers
190
							 * that is ok because we just have to replicate
191
							 * the values of each cell
192
							 */
193
							for (; j < symbolLevels.length; j++) {
194
								symbolLevels[j] = symbolLevels[j-1]+1;
195
							}
196
						}
197
						needToJoin = false;
198
					}
199
					if (join && needToJoin) {
200
						for (int j = 0; j < symbolLevels.length; j++) {
201
							symbolLevels[j] = zSort.getLevelCount()+j+1;
202
						}
203
					}
204
					if (!join && !merge) {
205
						for (int j = 0; j < symbolLevels.length; j++) {
206
							symbolLevels[j] = zSort.getLevelCount();
207
						}
208
					}
209
				} else {
210
					symbolLevels[0] = zSort.getLevelCount();
211
				}
212
			} else {
213
				// ADVANCED VIEW (user may set map levels manually)
214
				for (int j = 0; j < symbolLevels.length; j++) {
215
					symbolLevels[j] = ((Integer) model.getValueAt(i, j+FIRST_LEVEL_COLUMN_INDEX)).intValue();
216
				}
217
			}
218

  
219
			aTable.put(symbols[i], symbolLevels);
220
		}
221

  
222
		Iterator<ISymbol> it = aTable.keySet().iterator();
223
		while (it.hasNext()) {
224
			ISymbol sym = it.next();
225
			zSort.setLevels(sym, aTable.get(sym));
226
		}
227

  
228
		zSort.setUsingZSort(getChkSpecifyDrawOrder().isSelected());
229
	}
230

  
231
	public SymbolLevelsWindow(ZSort zSort) {
232
		super();
233
		initialize();
234
		setModel(zSort);
235
		quitaEsteMetodo();
236
		tblLevels.setRowHeight(23);
237
	}
238
	private void quitaEsteMetodo() {
239
		getBtnSwitchView().setEnabled(false);
240
		getBtnDown().setEnabled(false);
241
		getBtnUp().setEnabled(false);
242
	}
243
	/**
244
	 * Sets the model
245
	 * @param plan ZSort
246
	 */
247

  
248
	public void setModel(ZSort plan) {
249
		advancedHeaders = new String[FIRST_LEVEL_COLUMN_INDEX
250
		                             +plan.getTopLevelIndexAllowed() ];
251
		advancedHeaders[SYMBOL_COLUMN_INDEX] = defaultHeaders[SYMBOL_COLUMN_INDEX];
252
		advancedHeaders[DESCRIPTION_COLUMN_INDEX] = defaultHeaders[DESCRIPTION_COLUMN_INDEX];
253
		for (int i = 2; i < advancedHeaders.length; i++) {
254
			advancedHeaders[i] = String.valueOf(i-1);
255
		}
256
		this.zSort = plan;
257
		getChkSpecifyDrawOrder().setSelected(plan.isUsingZSort());
258
		initTableContents(getTblLevels(), plan, viewMode);
259
	}
260
	/**
261
	 * Initializes the table that it is showed in the panel where the user can
262
	 * see the different symbols of the legend and has options to specify the
263
	 * level for each one, merge and so on.
264
	 *
265
	 * @param table
266
	 * @param zSort
267
	 * @param mode
268
	 */
269
	private void initTableContents(JTable table, ZSort zSort, int mode) {
270
		DefaultTableModel model = new DefaultTableModel();
271
		Object[][] dataVector = null;
272
		ISymbol[] syms = zSort.getSymbols();
273
		String[] labels = zSort.getDescriptions();
274

  
275
		if (mode == DEFAULT_VIEW) {
276
			// default view (JOIN and MERGE)
277
			dataVector = new Object[syms.length][syms.length];
278
			for (int i = 0; i < syms.length; i++) {
279
				dataVector[i] = new Object[defaultHeaders.length];
280
				dataVector[i][SYMBOL_COLUMN_INDEX] = syms[i];
281
				dataVector[i][DESCRIPTION_COLUMN_INDEX] = labels[i];
282
				if (syms[i] instanceof IMultiLayerSymbol) {
283
					boolean joined = true;
284
					int[] levels = zSort.getLevels(syms[i]);
285
					if(levels != null){
286
						for (int j = 0; j < levels.length; j++) {
287
							if (joined) {
288
								joined = levels[j] != levels[j+1];
289
							}
290
						}
291
					}
292

  
293

  
294
					boolean merged = true;
295
					if (i<syms.length-1) {
296
						for (int j = 0; joined && j < levels.length; j++) {
297
							// must be joined to be merged
298
							ISymbol nextSymbol = syms[i+1];
299
							int[] nextLevels = zSort.getLevels(nextSymbol);
300
							if(nextLevels != null){
301
								if (nextSymbol instanceof IMultiLayerSymbol) {
302
									if (j<nextLevels.length) {
303
										merged = levels[j] == nextLevels[j];
304
									}
305
								} else {
306
									merged = levels[0] == nextLevels[0];
307
								}
308
							}
309
						}
310
						if (!merged) {
311
							break;
312
						}
313
					}
314
					if (!joined) {
315
						merged = false;
316
					}
317
					dataVector[i][JOIN_COLUMN_INDEX] = new Boolean(joined);
318
					dataVector[i][MERGE_COLUMN_INDEX] = new Boolean(merged);
319
				}
320
			}
321

  
322
			model.setDataVector(dataVector, defaultHeaders);
323
			table.setModel(model);
324
			TableColumn col = table.getColumnModel().getColumn(JOIN_COLUMN_INDEX);
325
			col.setCellRenderer(new BooleanTableCellRenderer(true));
326
			col.setCellEditor(new BooleanTableCellEditor(table));
327
			col = table.getColumnModel().getColumn(MERGE_COLUMN_INDEX);
328
			col.setCellRenderer(new BooleanTableCellRenderer(true));
329
			col.setCellEditor(new BooleanTableCellEditor(table));
330
		} else {
331
			// advanced view (user may input the map level manually)
332
			dataVector = new Object[syms.length][
333
			                                     FIRST_LEVEL_COLUMN_INDEX + /* this is the first column that
334
			                                      * contains a level for the symbol
335
			                                      */
336

  
337
			                                     zSort.getTopLevelIndexAllowed() + /* according to the set of
338
			                                      * symbols this will get the
339
			                                      * max level reachable
340
			                                      */
341
			                                     1 /* plus 1 to get a count instead of an index */];
342
			for (int i = 0; i < syms.length; i++) {
343
				dataVector[i][SYMBOL_COLUMN_INDEX] = syms[i];
344
				dataVector[i][DESCRIPTION_COLUMN_INDEX] = labels[i];
345
				if (syms[i] instanceof IMultiLayerSymbol) {
346
					int[] levels = zSort.getLevels(syms[i]);
347

  
348
					for (int j = 0; j < levels.length; j++) {
349
						dataVector[i][j+FIRST_LEVEL_COLUMN_INDEX] = levels[j];
350
					}
351
				} else {
352
					dataVector[i][FIRST_LEVEL_COLUMN_INDEX] = new Integer(zSort.getLevels(syms[i])[0]);
353
				}
354
			}
355

  
356
			model.setDataVector(dataVector, advancedHeaders);
357
			table.setModel(model);
358
			for (int j = FIRST_LEVEL_COLUMN_INDEX; j < model.getColumnCount(); j++) {
359

  
360
				table.getColumnModel().getColumn(j).setCellRenderer(new NumberTableCellRenderer(true, false));
361
				table.getColumnModel().getColumn(j).setCellEditor(new IntegerTableCellEditor());
362
			}
363
		}
364

  
365
		TableSymbolCellRenderer symbolCellRenderer = new TableSymbolCellRenderer(true) {
366
			private static final long serialVersionUID = 5603529641148869112L;
367

  
368
			{ // Object static initialize block
369

  
370
				preview = new SymbolPreviewer() {
371
					private static final long serialVersionUID = 7262380340075167043L;
372
					private Icon downIcon = new Icon(){
373
						public int getIconHeight() { return 7; }
374
						public int getIconWidth() { return 7; }
375
						public void paintIcon(Component c, Graphics g, int x, int y) {
376
							Graphics2D g2 = (Graphics2D) g;
377
							g2.setColor(Color.GRAY);
378
							g2.translate(x + c.getWidth()-getIconWidth()*2, y + c.getHeight()-getIconHeight()*2);
379
							GeneralPath gp = new GeneralPath();
380
							gp.moveTo(0, 0);
381
							gp.lineTo(getIconWidth()/2, getIconHeight()-1);
382
							gp.lineTo(getIconWidth()-1, 0);
383
							g2.fill(gp);
384
							g2.translate(-(x + c.getWidth()-getIconWidth()*2), -(y + c.getHeight()-getIconHeight()*2));
385
						}
386
					};
387
					@Override
388
					public void paint(Graphics g) {
389
						super.paint(g);
390
						if (getSymbol() instanceof IMultiLayerSymbol) {
391
							downIcon.paintIcon(this, g, 0, 0);
392
						}
393
					}
394
				};
395

  
396
			} // Object static initialize block
397
		};
398
		TableColumn col = table.getColumnModel().getColumn(SYMBOL_COLUMN_INDEX);
399
		col.setCellRenderer(symbolCellRenderer);
400
	}
401

  
402
	private void initialize() {
403
		this.setLayout(new BorderLayout(15, 15));
404
		this.setSize(564, 344);
405

  
406
		this.add(getChkSpecifyDrawOrder(), BorderLayout.NORTH);
407
		this.add(new JBlank(20, 20));
408
		this.add(getPnlCenter(), BorderLayout.CENTER);
409
		this.add(getPnlSouth(), BorderLayout.SOUTH);
410
		tblLevels.addMouseListener(new MouseListener() {
411
			public void mouseReleased(MouseEvent e) { }
412
			public void mouseClicked(MouseEvent e)  { }
413
			public void mouseEntered(MouseEvent e)  { }
414
			public void mouseExited(MouseEvent e)  {
415
				summary.sym = null;
416
				repaint();
417
	}
418

  
419
			public void mousePressed(MouseEvent e) {
420
				Point where = e.getPoint();
421
				int whereX = where.x;
422
				int whereY = where.y;
423
				Rectangle bounds = tblLevels.getBounds();
424
				/*
425
				 * calculate the right border x-position of the symbol
426
				 * column
427
	 			*/
428
				int rightEdge = 0;
429
				for (int i = 0; i <= SYMBOL_COLUMN_INDEX; i++) {
430
					rightEdge += tblLevels.getColumnModel().getColumn(i).getWidth();
431
				}
432
				if (whereX >= bounds.x &&
433
					whereX <= rightEdge + bounds.x &&
434
					whereY >= bounds.y &&
435
					whereY <= bounds.height + bounds.y) {
436
					int rowHeight = tblLevels.getRowHeight();
437
					int rowClicked = (whereY - bounds.y) / rowHeight;
438
					ISymbol sym = (ISymbol) tblLevels.
439
											getModel().
440
											getValueAt(
441
												rowClicked,
442
												SYMBOL_COLUMN_INDEX);
443
					if (sym instanceof IMultiLayerSymbol) {
444
						summary.sym = (IMultiLayerSymbol) sym;
445
						summary.rowIndex = rowClicked;
446
					} else {
447
						summary.sym = null;
448
					}
449
					repaint();
450
				}
451
			}
452

  
453
		});
454

  
455
	}
456

  
457
	private JCheckBox getChkSpecifyDrawOrder() {
458
		if (chkSpecifyDrawOrder == null) {
459
			chkSpecifyDrawOrder = new JCheckBox("<html><b>"+
460
					Messages.getText("draw_symbols_in_specified_order")
461
					+"</b></html>");
462
			chkSpecifyDrawOrder.addActionListener(this);
463
		}
464
		return chkSpecifyDrawOrder;
465
	}
466

  
467

  
468
	private JPanel getPnlCenter() {
469
		if (pnlCenter == null) {
470
			pnlCenter = new JPanel();
471
			pnlCenter.setLayout(new BorderLayout(0, 15));
472
			pnlCenter.add(getSrclLevels(), BorderLayout.CENTER);
473
			pnlCenter.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
474
			JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 15));
475
			JPanel pnlButtons = new JPanel();
476
			pnlButtons.setLayout(new BoxLayout(pnlButtons, BoxLayout.Y_AXIS));
477
			pnlButtons.add(new JBlank(1, 70));
478
			pnlButtons.add(getBtnUp());
479
			pnlButtons.add(new JBlank(1, 10));
480
			pnlButtons.add(getBtnDown());
481
			pnlButtons.setVisible(false);
482
			aux.add(pnlButtons);
483
			pnlCenter.add(aux, BorderLayout.EAST);
484

  
485
		}
486
		pnlCenter.setEnabled(getChkSpecifyDrawOrder().isSelected());
487
		return pnlCenter;
488
	}
489

  
490
	private JScrollPane getSrclLevels() {
491
		if (srclLevels == null) {
492
			srclLevels = new JScrollPane();
493
			srclLevels.setViewportView(getTblLevels());
494
		}
495
		srclLevels.setEnabled(getChkSpecifyDrawOrder().isSelected());
496
		return srclLevels;
497
	}
498

  
499

  
500
	private JTable getTblLevels() {
501
		if (tblLevels == null) {
502
			tblLevels = new JTable() {
503
				private static final long serialVersionUID = -1545710722048183232L;
504

  
505
				@Override
506
				protected void paintComponent(Graphics g) {
507
					super.paintComponent(g);
508
					summary.paint((Graphics2D) g);
509
		}
510
			};
511
			summary.rowHeight = tblLevels.getRowHeight();
512
		}
513
		tblLevels.setEnabled(getChkSpecifyDrawOrder().isSelected());
514
		return tblLevels;
515
	}
516

  
517

  
518
	private JButton getBtnUp() {
519
		if (btnUp == null) {
520
			btnUp = new JButton(PluginServices.getIconTheme().get("arrow-up-icono"));
521
			btnUp.setActionCommand("MOVE_UP");
522
		}
523
		return btnUp;
524
	}
525

  
526
	private JButton getBtnDown() {
527
		if (btnDown == null) {
528
			btnDown = new JButton(PluginServices.getIconTheme().get("arrow-down-icono"));
529
			btnDown.setActionCommand("MOVE_DOWN");
530
		}
531
		return btnDown;
532
	}
533

  
534

  
535
	private JPanel getPnlSouth() {
536
		if (pnlSouth == null) {
537
			pnlSouth = new JPanel(new BorderLayout());
538
			JPanel aux = new JPanel();
539
			aux.setLayout(new FlowLayout(FlowLayout.RIGHT));
540
			aux.add(getBtnSwitchView());
541
			pnlSouth.add(aux, BorderLayout.NORTH);
542

  
543
			aux = new JPanel();
544
			aux.setLayout(new FlowLayout(FlowLayout.RIGHT));
545
			pnlSouth.add(new AcceptCancelPanel(action, action), BorderLayout.SOUTH);
546

  
547
		}
548
		return pnlSouth;
549
	}
550

  
551
	private JButton getBtnSwitchView() {
552
		if (btnSwitchView == null) {
553
			btnSwitchView = new JButton(
554
					(viewMode != DEFAULT_VIEW) ?
555
					Messages.getText("default_view"):
556
					Messages.getText("advanced_view")
557
					);
558
			btnSwitchView.addActionListener(this);
559
			btnSwitchView.setVisible(false);
560
		}
561

  
562
		return btnSwitchView;
563
	}
564

  
565
	public void actionPerformed(ActionEvent e) {
566
		JComponent c = (JComponent) e.getSource();
567
		if (c.equals(getChkSpecifyDrawOrder())) {
568
			getPnlCenter().setEnabled(getChkSpecifyDrawOrder().isSelected());
569
			getSrclLevels().setEnabled(getChkSpecifyDrawOrder().isSelected());
570
			TableCellEditor tce = getTblLevels().getCellEditor();
571
			if (tce != null){
572
				tce.stopCellEditing();
573
			}
574
			getTblLevels().setEnabled(getChkSpecifyDrawOrder().isSelected());
575
		} else if (c.equals(getBtnSwitchView())) {
576
			viewMode = (viewMode == ADVANCED_VIEW) ? DEFAULT_VIEW : ADVANCED_VIEW;
577
			initTableContents(getTblLevels(), zSort, viewMode);
578
			btnSwitchView.setText((viewMode != DEFAULT_VIEW) ?
579
					Messages.getText("default_view"):
580
					Messages.getText("advanced_view"));
581
		}
582
	}
583
	/**
584
	 * Gets the ZSort value
585
	 *
586
	 * @return zSort ZSort
587
	 */
588
	public ZSort getZSort() {
589
		return zSort;
590
	}
591

  
592
	private class SymbolSummary {
593
		int witdh;
594
		int rowHeight = 10;
595

  
596
		int rowIndex;
597

  
598
		IMultiLayerSymbol sym;
599

  
600
		void paint(Graphics2D g){
601

  
602
			if (sym != null) {
603
				int whereY = (rowHeight*(rowIndex-1) + (int) (rowHeight/0.6));
604
				int whereX = 0;
605
				for (int i = 0; i <= SYMBOL_COLUMN_INDEX; i++) {
606
					whereX += tblLevels.getColumnModel().getColumn(i).getWidth();
607
				}
608
				whereX -= 40;
609
				int width = 150;
610
				int height = Math.max(rowHeight*sym.getLayerCount(), rowHeight);
611
				Rectangle bounds = new Rectangle(whereX, whereY, width, height);
612
				g.setColor(new Color(255, 255, 220));
613
				g.fill(bounds);
614

  
615
				g.setColor(new Color(255, 230, 20));
616
				g.draw(bounds);
617

  
618
				g.setFont(new Font("Arial", Font.BOLD, 10));
619

  
620
				for (int i = 0; i < sym.getLayerCount(); i++) {
621
					g.setColor(Color.black);
622
					g.drawString(i+1+":", whereX+5, height + whereY - ( (i*rowHeight) + 5 ));
623
					Rectangle rect = new Rectangle(whereX + 20,
624
							height + whereY - ((i+1)*rowHeight) + 3,
625
							width - 20,
626
							rowHeight - 6);
627
					try {
628
						sym.getLayer(i).drawInsideRectangle(g, null, rect,null);
629
					} catch (SymbolDrawingException e) {
630
						if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
631
							try {
632
								MapContextLocator.getSymbolManager()
633
										.getWarningSymbol(
634
												SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
635
												"",
636
												SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS)
637
										.drawInsideRectangle(g, null, rect,
638
												null);
639
							} catch (SymbolDrawingException e1) {
640
								// IMPOSSIBLE TO REACH THIS
641
							}
642
						} else {
643
							// should be unreachable code
644
							throw new Error(Messages.getText("symbol_shapetype_mismatch"));
645
						}
646
					}
647
				}
648

  
649
			}
650
		};
651
	}
652

  
653
	public Object getWindowProfile() {
654
		return WindowInfo.DIALOG_PROFILE;
655
	}
656

  
657
}
0 658

  
tags/v2_0_0_Build_2057/libraries/org.gvsig.symbology/org.gvsig.symbology.swing/org.gvsig.symbology.swing.api/src/main/java/org/gvsig/app/gui/styling/LibraryBrowser.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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
import java.awt.Point;
45
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionListener;
47
import java.awt.event.MouseEvent;
48
import java.awt.event.MouseListener;
49
import java.awt.event.MouseMotionListener;
50
import java.io.File;
51
import java.util.ArrayList;
52
import java.util.Date;
53

  
54
import javax.swing.JMenuItem;
55
import javax.swing.JOptionPane;
56
import javax.swing.JPanel;
57
import javax.swing.JPopupMenu;
58
import javax.swing.JTree;
59
import javax.swing.event.TreeModelEvent;
60
import javax.swing.event.TreeModelListener;
61
import javax.swing.event.TreeSelectionListener;
62
import javax.swing.tree.DefaultMutableTreeNode;
63
import javax.swing.tree.TreePath;
64

  
65
//import org.gvsig.andami.PluginServices;
66
//import org.gvsig.andami.messages.NotificationManager;
67
//import org.gvsig.andami.ui.mdiFrame.JMenuItem;
68
//import org.gvsig.andami.ui.mdiFrame.JPopUpMenu;
69
import org.gvsig.i18n.Messages;
70
import org.slf4j.Logger;
71
import org.slf4j.LoggerFactory;
72

  
73

  
74

  
75
/**
76
 * 
77
 * LibraryBrowser.java
78
 *
79
 * 
80
 * @author jaume dominguez faus - jaume.dominguez@iver.es Dec 7, 2007
81
 *
82
 */
83
public class LibraryBrowser extends JPanel implements TreeModelListener {
84
	private static final long serialVersionUID = 4322139976928871347L;
85
	
86
	private static final Logger logger = LoggerFactory.getLogger(LibraryBrowser.class);
87

  
88
	private ILibraryModel model;
89
	private JTree tree;
90
	private JPopupMenu popUpMenu;
91
	private JMenuItem newFolder;
92
	private JMenuItem removeFolder;
93
	private ActionListener popUpMenuActions = new ActionListener() {
94
		public void actionPerformed(ActionEvent e) {
95
			Object selectedObject = tree.getLastSelectedPathComponent();
96
			Object source = e.getSource();
97
			removeFolder.setEnabled(selectedObject != null);
98
			try {
99
				if (source.equals(newFolder)) {
100
					String newFolderName = JOptionPane.showInputDialog(Messages.getText("new_name"));
101
					if (newFolderName != null)
102
						model.addFolder(selectedObject, newFolderName);
103
				} else if (source.equals(removeFolder)) {
104
					model.removeFolder(selectedObject);
105
				}
106
			} catch (Exception ex) {
107
				logger.error(Messages
108
						.getText("notification_text"
109
								+ " ["
110
								+ new Date(System.currentTimeMillis())
111
										.toString() + "]"), ex);
112
			} finally {
113
				popUpMenu.setVisible(false);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff