Revision 991

View differences:

org.gvsig.tools/library/tags/org.gvsig.tools-3.0.17/org.gvsig.tools.main/src/test/java/org/gvsig/tools/main/AppTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.main;
25

  
26
import junit.framework.Test;
27
import junit.framework.TestCase;
28
import junit.framework.TestSuite;
29

  
30
/**
31
 * Unit test for simple App.
32
 */
33
public class AppTest extends TestCase {
34

  
35
    /**
36
     * @return the suite of tests being tested
37
     */
38
    public static Test suite() {
39
        return new TestSuite(AppTest.class);
40
    }
41

  
42
    /**
43
     * Create the test case
44
     * 
45
     * @param testName
46
     *            name of the test case
47
     */
48
    public AppTest(String testName) {
49
        super(testName);
50
    }
51

  
52
    /**
53
     * Rigourous Test :-)
54
     */
55
    public void testApp() {
56
        assertTrue(true);
57
    }
58
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.17/org.gvsig.tools.main/src/main/resources/log4j.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
28

  
29
<!-- 
30
Log4J configuration file for unit tests execution.
31
 -->
32
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
33

  
34
	<!-- Appender configuration to show logging messages through the console -->
35
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
36
		<layout class="org.apache.log4j.PatternLayout">
37
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
38
		</layout>
39
	</appender>
40

  
41
	<!-- 
42
	Activate logging messages of DEBUG level of higher only for the
43
	org.gvsig.tools packages.
44
	You can put full classes names or packages instead, to configure
45
	logging for all the classes and subpackages of the package.
46
	-->
47
	<category name="org.gvsig.tools">
48
		<priority value="DEBUG" />
49
	</category>
50

  
51
	<!-- 
52
	By default, show only logging messages of INFO level or higher, 
53
	through the previously configured CONSOLE appender. 
54
	-->
55
	<root>
56
		<priority value="INFO" />
57
		<appender-ref ref="CONSOLE" />
58
	</root>
59
</log4j:configuration>
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.17/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/MainAction.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2010 {}  {{Task}}
27
 */
28
package org.gvsig.tools.main;
29

  
30
import java.awt.event.ActionEvent;
31

  
32
import javax.swing.AbstractAction;
33
import javax.swing.Icon;
34
import javax.swing.JComponent;
35
import javax.swing.JTabbedPane;
36

  
37
/**
38
 * @author 2010- C?sar Ordi?ana - gvSIG team
39
 */
40
public abstract class MainAction extends AbstractAction {
41

  
42
    private static final long serialVersionUID = 7286136693329716214L;
43
    private final JTabbedPane tabbedPane;
44

  
45
    /**
46
     * @see AbstractAction#AbstractAction()
47
     */
48
    public MainAction(JTabbedPane tabbedPane) {
49
        super(); 
50
        this.tabbedPane = tabbedPane;
51
    }
52

  
53
    /**
54
     * @see AbstractAction#AbstractAction(String)
55
     */
56
    public MainAction(String name, JTabbedPane tabbedPane) {
57
        super(name);
58
        this.tabbedPane = tabbedPane;
59
    }
60

  
61
    /**
62
     * @see AbstractAction#AbstractAction(String, Icon)
63
     */
64
    public MainAction(String name, Icon icon, JTabbedPane tabbedPane) {
65
        super(name, icon);
66
        this.tabbedPane = tabbedPane;
67
    }
68

  
69
    public void actionPerformed(ActionEvent e) {
70
        String title = getComponentTitle();
71
        int index = tabbedPane.indexOfTab(title);
72
        if (index <= -1) {
73
            tabbedPane.addTab(title, createComponent());
74
            index = tabbedPane.indexOfTab(title);
75
        }
76
        tabbedPane.setSelectedIndex(index);
77
    }
78

  
79
    protected abstract JComponent createComponent();
80

  
81
    protected abstract String getComponentTitle();
82

  
83
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.17/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/Main.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.main;
25

  
26
import java.awt.BorderLayout;
27
import java.awt.Dimension;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30

  
31
import javax.swing.JButton;
32
import javax.swing.JFrame;
33
import javax.swing.JMenu;
34
import javax.swing.JMenuBar;
35
import javax.swing.JMenuItem;
36
import javax.swing.JTabbedPane;
37
import javax.swing.JToolBar;
38
import javax.swing.WindowConstants;
39

  
40
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
41
import org.gvsig.tools.main.dynobject.DynObjectComponentAction;
42
import org.gvsig.tools.main.dynobject.DynObjectSetComponentAction;
43
import org.gvsig.tools.main.dynobject.TestDynObject;
44
import org.gvsig.tools.main.taskstatus.JTaskStatusAction;
45
import org.gvsig.tools.main.usability.UsabilityAction;
46
import org.gvsig.tools.main.window.ModalAction;
47

  
48
/**
49
 * @author 2010- C?sar Ordi?ana - gvSIG team
50
 */
51
public class Main {
52

  
53
    private JTabbedPane tabbedPane;
54
    private JMenuBar menuBar;
55
    private JToolBar toolBar; 
56

  
57
    public static void main(String args[]) {
58
        new DefaultLibrariesInitializer().fullInitialize();
59
        DynObjectComponentAction.registerDynObjects();
60
        Main main = new Main();
61
        main.show();
62
    }
63

  
64
    public void show() {
65

  
66
        final JFrame frame = new JFrame("Tools swing components test app");
67
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
68

  
69
        // Add a tabbed pane as a content pane
70
        tabbedPane = new JTabbedPane();
71
        tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
72
        frame.getContentPane().add(tabbedPane);
73

  
74
        // Create application actions
75
        MainAction[] actions = createActions();
76

  
77
        // Create the menu bar.
78
        menuBar = new JMenuBar();
79

  
80
        // Build the menu.
81
        JMenu menuFile = new JMenu("File");
82
        JMenuItem menuItemExit = new JMenuItem("Exit");
83
        menuItemExit.addActionListener(new ActionListener() {
84

  
85
            public void actionPerformed(ActionEvent e) {
86
                frame.dispose();
87
                System.exit(0);
88
            }
89
        });
90
        menuFile.add(menuItemExit);
91
        menuBar.add(menuFile);
92

  
93
        // Add all actions to the menu bar
94
        JMenu menuDemo = new JMenu("Tools components");
95
        for (int i = 0; i < actions.length; i++) {
96
            menuDemo.add(new JMenuItem(actions[i]));
97
        }
98
        menuBar.add(menuDemo);
99

  
100
        // Build the toolbar
101
        toolBar = new JToolBar("Main toolbar");
102

  
103
        // Add all actions to the toolbar
104
        for (int i = 0; i < actions.length; i++) {
105
            toolBar.add(new JButton(actions[i]));
106
        }
107

  
108
        frame.setPreferredSize(new Dimension(800, 600));
109

  
110
        frame.setJMenuBar(menuBar);
111
        frame.add(toolBar, BorderLayout.PAGE_START);
112

  
113
        // Display the window.
114
        frame.pack();
115
        frame.setVisible(true);
116
    }
117

  
118
    private MainAction[] createActions() {
119
        return new MainAction[] { 
120
        	new DynObjectComponentAction(tabbedPane, TestDynObject.TESTDYNOBJECT_NAME),
121
            new DynObjectComponentAction(tabbedPane, TestDynObject.TESTDYNOBJECTREADONLY_NAME),
122
            new DynObjectSetComponentAction(tabbedPane),
123
            new UsabilityAction(tabbedPane),
124
            new JTaskStatusAction(tabbedPane),
125
            new ModalAction(tabbedPane)
126
        };
127
    }
128

  
129
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.17/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/usability/UsabilityAction.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2010 {}  {{Task}}
27
 */
28
package org.gvsig.tools.main.usability;
29

  
30
import java.awt.Component;
31

  
32
import javax.swing.BoxLayout;
33
import javax.swing.JButton;
34
import javax.swing.JComponent;
35
import javax.swing.JPanel;
36
import javax.swing.JSpinner;
37
import javax.swing.JTabbedPane;
38
import javax.swing.JTextArea;
39

  
40
import org.gvsig.tools.dataTypes.DataTypes;
41
import org.gvsig.tools.main.MainAction;
42
import org.gvsig.tools.swing.api.ToolsSwingLocator;
43
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
44

  
45
/**
46
 * Shows the panel of usability components.
47
 * 
48
 * @author 2010- C?sar Ordi?ana - gvSIG team 
49
 */
50
public class UsabilityAction extends MainAction {
51

  
52
    private static final long serialVersionUID = 6471916708466720365L;
53

  
54
    private static final UsabilitySwingManager manager =
55
        ToolsSwingLocator.getUsabilitySwingManager();
56

  
57
    /**
58
     * @see MainAction#MainAction(JTabbedPane)
59
     */
60
    public UsabilityAction(JTabbedPane tabbedPane) {
61
        super("Usability", tabbedPane);
62
        putValue(SHORT_DESCRIPTION, "Usability components");
63
    }
64

  
65
    @Override
66
    protected JComponent createComponent() {
67
        JTabbedPane tabbedPane = new JTabbedPane();
68
        tabbedPane.setTabPlacement(JTabbedPane.RIGHT);
69

  
70
        tabbedPane.addTab("JButton", createJButtonComponent());
71
        tabbedPane.addTab("JTextArea", createJTextAreaComponent());
72
        tabbedPane.addTab("JNullSpinner", createJNullSpinnerComponent());
73
        return tabbedPane;
74
    }
75

  
76
    @Override
77
    protected String getComponentTitle() {
78
        return "Usability";
79
    }
80

  
81
    private Component createJButtonComponent() {
82
        // Create the container panel
83
        JPanel panel = new JPanel();
84
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
85
        // panel.setLayout(new GridLayout(18, 1));
86
        // panel.setLayout(new );
87
        JButton button = manager.createJButton("+");
88
        panel.add(button); 
89
        button = manager.createJButton("-");
90
        panel.add(button);
91
        button = manager.createJToolButton("+");
92
        panel.add(button); 
93
        button = manager.createJToolButton("-");
94
        panel.add(button);
95
        // Create buttons with different sizes
96
        StringBuffer text = new StringBuffer("012");
97
        for (int i = 4; i < 22; i++) {
98
            text.append(String.valueOf(i % 10));
99
            button = manager.createJButton(text.toString());
100
            panel.add(button);
101
        }
102

  
103
        return panel;
104
    }
105

  
106
    private Component createJTextAreaComponent() {
107
        // Create the container panel
108
        JPanel panel = new JPanel();
109
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
110
        // panel.setLayout(new GridLayout(18, 1));
111
        // panel.setLayout(new );
112
        JTextArea ta = manager.createJTextArea("");       
113
        ta = manager.createJTextArea("test");
114
        panel.add(ta); 
115
        ta = manager.createJTextArea("test longer");
116
        panel.add(ta);
117
        ta = manager.createJTextArea("test much longer");
118
        panel.add(ta); 
119
        ta = manager.createJTextArea("test");
120
        panel.add(ta); 
121
        ta = manager.createJTextArea("test size = 150", 150);
122
        panel.add(ta); 
123
        ta = manager.createJTextArea("test too long", -1);
124
        panel.add(ta);
125
        // Create buttons with different sizes
126
        StringBuffer text = new StringBuffer("012");
127
        for (int i = 4; i < 22; i++) {
128
            text.append(String.valueOf(i % 10));
129
            ta = manager.createJTextArea(text.toString());
130
            panel.add(ta);
131
        }
132
   
133
        
134
        return panel;
135
    }
136

  
137
    private Component createJNullSpinnerComponent() {
138
        // Create the container panel
139
        JPanel panel = new JPanel();
140
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
141
        // panel.setLayout(new GridLayout(18, 1));
142
        // panel.setLayout(new );
143
        JSpinner spinner = manager.createJNullSpinner(DataTypes.FLOAT, "1.05", -1);
144
        panel.add(spinner);
145
        // Create buttons with different sizes
146
        StringBuffer text = new StringBuffer("01287.");
147
        for (int i = 4; i < 22; i++) {
148
            text.append(String.valueOf(i % 10));
149
            spinner = manager.createJNullSpinner(DataTypes.FLOAT, text.toString(), -1);
150
            panel.add(spinner);
151
        }
152

  
153
        return panel;
154
    }
155

  
156
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.17/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/taskstatus/JTaskStatusAction.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.main.taskstatus;
25

  
26
import java.awt.Color;
27
import java.awt.FlowLayout;
28

  
29
import javax.swing.JComponent;
30
import javax.swing.JPanel;
31
import javax.swing.JTabbedPane;
32

  
33
import org.gvsig.tools.main.MainAction;
34
import org.gvsig.tools.swing.api.ToolsSwingLocator;
35
import org.gvsig.tools.swing.api.task.JTaskStatus;
36
import org.gvsig.tools.swing.api.task.JTasksStatus;
37
import org.gvsig.tools.swing.api.task.TaskStatusSwingManager;
38
import org.gvsig.tools.task.AbstractMonitorableTask;
39

  
40
public class JTaskStatusAction extends MainAction {
41

  
42
	/**
43
	 * 
44
	 */
45
	private static final long serialVersionUID = -5408828606365712614L;
46

  
47
	public JTaskStatusAction(JTabbedPane tabbedPane) {
48
		super("Task status", tabbedPane);
49
        putValue(SHORT_DESCRIPTION, "Task status");
50
	}
51

  
52
	private class MiTask extends AbstractMonitorableTask {
53
		
54
		private int max;
55
		private int sleepInterval;
56
		
57
		public MiTask(String tittle, int max, int sleepInterval) {
58
			super(tittle);
59
			this.max = max;
60
			this.sleepInterval = sleepInterval;
61
		}
62
		public MiTask(String tittle, int max) {
63
			this(tittle, max, 100);
64
		}
65
		public void run() {
66
			this.taskStatus.setRangeOfValues(0, this.max);
67
			for(int i=0; i<this.max; i++ ) {
68
				this.taskStatus.setCurValue(i);
69
				try {
70
					Thread.sleep(sleepInterval);
71
				} catch (InterruptedException e) {
72
					// Ignore
73
				}
74
				if( this.taskStatus.isCancellationRequested() ) {
75
					this.taskStatus.cancel();
76
					break;
77
				}
78
			}
79
			if( this.taskStatus.isRunning() ) {
80
				this.taskStatus.terminate();
81
			}
82
		}
83
	}
84
	
85
	protected JComponent createComponent() {
86
		TaskStatusSwingManager manager = ToolsSwingLocator.getTaskStatusSwingManager();
87
		JPanel panel = new JPanel();
88
		panel.setLayout( new FlowLayout());
89
		JTasksStatus tasks = manager.createJTasksStatus();
90
		tasks.setBackground(Color.BLUE.brighter());
91
		panel.add( tasks );
92
		JTaskStatus taskStatusPanel = manager.createJTaskStatus();
93
		panel.add( taskStatusPanel );
94
		
95
		MiTask task1 = new MiTask("Task1",100);
96
		task1.start();
97
		MiTask task2 = new MiTask("Task2",300);
98
		task2.start();
99
		MiTask task3 = new MiTask("Task3",1000);
100
		task3.start();
101
		MiTask task4 = new MiTask("Task4",50,5000);
102
		task4.start();
103

  
104
		taskStatusPanel.bind(task1.getTaskStatus());
105
		return panel;
106
	}
107

  
108
	protected String getComponentTitle() {
109
		return "Task status";
110
	}
111

  
112
}
0 113

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.17/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/window/ModalAction.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2010 {}  {{Task}}
27
 */
28
package org.gvsig.tools.main.window;
29

  
30
import java.awt.Dimension;
31
import java.awt.FlowLayout;
32
import java.awt.event.ActionEvent;
33
import java.beans.PropertyChangeListener;
34

  
35
import javax.swing.Action;
36
import javax.swing.JButton;
37
import javax.swing.JComponent;
38
import javax.swing.JPanel;
39
import javax.swing.JTabbedPane;
40
import javax.swing.JTextArea;
41
import javax.swing.JTextField;
42

  
43
import org.gvsig.tools.main.MainAction;
44
import org.gvsig.tools.swing.api.ToolsSwingLocator;
45
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
46

  
47
/**
48
 * Shows the panel of usability components.
49
 * 
50
 * @author 2010- C?sar Ordi?ana - gvSIG team 
51
 */
52
public class ModalAction extends MainAction {
53

  
54

  
55
    private static final WindowManager manager =
56
        ToolsSwingLocator.getWindowManager();
57

  
58
    /**
59
     * @see MainAction#MainAction(JTabbedPane)
60
     */
61
    public ModalAction(JTabbedPane tabbedPane) {
62
        super("Modal", tabbedPane);
63
        putValue(SHORT_DESCRIPTION, "Modal components");
64
    }
65

  
66
    @Override
67
    protected JComponent createComponent() {
68
        JPanel panel = new JPanel();
69
        panel.setLayout(new FlowLayout());
70
        JButton button = new JButton(new Action() {
71
			
72
			public void actionPerformed(ActionEvent arg0) {
73
				JTextField jtext = new JTextField();
74
				jtext.setPreferredSize(new Dimension(300, 30));
75
				
76
				JPanel auxpanel = new JPanel();
77
				auxpanel.add(jtext);
78
				WindowManager wm = ToolsSwingLocator.getWindowManager();
79
				wm.showWindow(auxpanel, "HOLA", WindowManager.MODE.DIALOG);
80
				System.out.println("Value = "+jtext.getText());
81
			}
82
			
83
			public void setEnabled(boolean b) {
84
				// TODO Auto-generated method stub
85
				
86
			}
87
			
88
			public void removePropertyChangeListener(PropertyChangeListener listener) {
89
				// TODO Auto-generated method stub
90
				
91
			}
92
			
93
			public void putValue(String key, Object value) {
94
				// TODO Auto-generated method stub
95
				
96
			}
97
			
98
			public boolean isEnabled() {
99
				return true;
100
			}
101
			
102
			public Object getValue(String key) {
103
				// TODO Auto-generated method stub
104
				return null;
105
			}
106
			
107
			public void addPropertyChangeListener(PropertyChangeListener listener) {
108
				// TODO Auto-generated method stub
109
				
110
			}
111
		});
112
        button.setText("Show modal window");
113
        panel.add(button);
114

  
115
        return panel;
116
    }
117

  
118
    @Override
119
    protected String getComponentTitle() {
120
        return "Modal";
121
    }
122

  
123
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.17/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/README.txt
1
====
2
    gvSIG. Desktop Geographic Information System.
3

  
4
    Copyright (C) 2007-2013 gvSIG Association.
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
    For any additional information, do not hesitate to contact us
22
    at info AT gvsig.com, or visit our website www.gvsig.com.
23
====
24

  
25
To add a new tab to the application, perform the following steps:
26

  
27
- Create a new class extending the MainAction class, implementing the methods:
28

  
29
  - createComponent(): create your demo panel
30
  
31
  - getComponentTitle(): return the name of the panel
32
  
33
- Add your new action class to the list of actions in the Main.createActions()
34
  method. 
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.17/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/dynobject/DynObjectSetComponentAction.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.main.dynobject;
25

  
26
import javax.swing.JComponent;
27
import javax.swing.JTabbedPane;
28

  
29
import org.gvsig.tools.dispose.DisposableIterator;
30
import org.gvsig.tools.dynobject.DynObject;
31
import org.gvsig.tools.dynobject.DynObjectSet;
32
import org.gvsig.tools.exception.BaseException;
33
import org.gvsig.tools.main.MainAction;
34
import org.gvsig.tools.observer.Observer;
35
import org.gvsig.tools.swing.api.ToolsSwingLocator;
36
import org.gvsig.tools.visitor.VisitCanceledException;
37
import org.gvsig.tools.visitor.Visitor;
38

  
39
/**
40
 * @author gvSIG Team
41
 * @version $Id$
42
 * 
43
 */
44
public class DynObjectSetComponentAction extends MainAction {
45

  
46
	private static final long serialVersionUID = -752711541901464859L;
47

  
48
	public class DummyDynObjectSet implements DynObjectSet {
49

  
50
        private DynObject[] values;
51

  
52
        TestDynObjectManager manager;
53

  
54
        public DummyDynObjectSet() {
55
            manager = new TestDynObjectManager();
56
            manager.initialize();
57
            values = new DynObject[5];
58
            for (int i = 0; i < values.length; i++) {
59
                values[i] = manager.createRandomDynObject();
60
            }
61
        }
62

  
63
        public void dispose() {
64
            // Nothing to do
65
        }
66

  
67
        public void accept(Visitor visitor, long firstValueIndex)
68
            throws BaseException {
69
            try {
70
                for (int i = (int) firstValueIndex; i < values.length; i++) {
71
                    visitor.visit(values[i]);
72
                }
73
            } catch (VisitCanceledException e) {
74
                // Visitation process cancelled
75
            }
76
        }
77

  
78
        public void accept(Visitor visitor) throws BaseException {
79
            accept(visitor, 0);
80
        }
81

  
82
        public long getSize() throws BaseException {
83
            return values.length;
84
        }
85

  
86
        public DisposableIterator iterator(long index) throws BaseException {
87
            return null;
88
        }
89

  
90
        public DisposableIterator iterator() throws BaseException {
91
            return null;
92
        }
93

  
94
        public boolean isEmpty() throws BaseException {
95
            return false;
96
        }
97

  
98
		public void addObserver(Observer o) {
99
			// Nothing to do
100
		}
101

  
102
		public void deleteObserver(Observer o) {
103
			// Nothing to do
104
		}
105

  
106
		public void deleteObservers() {
107
			// Nothing to do
108
		}
109

  
110
		public boolean isDeleteEnabled() {
111
			// Nothing to do
112
			return false;
113
		}
114

  
115
		public void delete(DynObject dynObject) throws BaseException {
116
			// Nothing to do
117
		}
118

  
119
		public boolean isUpdateEnabled() {
120
			// Nothing to do
121
			return false;
122
		}
123

  
124
		public void update(DynObject dynObject) throws BaseException {
125
			// Nothing to do
126
		}
127

  
128
    }
129

  
130
    /**
131
     * @param tabbedPane
132
     */
133
    public DynObjectSetComponentAction(JTabbedPane tabbedPane) {
134
        super("DynObjectSetComponent", tabbedPane);
135
    }
136

  
137
    @Override
138
    protected JComponent createComponent() {
139
        DynObjectSet dynObjectSet = new DummyDynObjectSet();
140

  
141
        try {
142
            return ToolsSwingLocator.getDynObjectSwingManager()
143
                .createJDynObjectSetComponent(dynObjectSet).asJComponent();
144
        } catch (BaseException e) {
145
            e.printStackTrace();
146
            return null;
147
        }
148
    }
149

  
150
    @Override
151
    protected String getComponentTitle() {
152
        return "DynObjectSetComponent";
153
    }
154

  
155
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.17/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/dynobject/TestDynObject.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2010 Institute of New Imaging Technologies (INIT): 
27
 *   http://www.init.uji.es
28
 * Geographic Information research group: 
29
 *   http://www.geoinfo.uji.es
30
 * Universitat Jaume I, Spain
31
 */
32

  
33
/**
34
 * 
35
 */
36
package org.gvsig.tools.main.dynobject;
37

  
38
import java.io.File;
39
import java.util.ArrayList;
40
import java.util.Date;
41
import java.util.List;
42

  
43
import org.gvsig.tools.ToolsLocator;
44
import org.gvsig.tools.dataTypes.DataTypes;
45
import org.gvsig.tools.dynobject.DynObject;
46
import org.gvsig.tools.dynobject.DynObjectManager;
47
import org.gvsig.tools.dynobject.DynObjectValueItem;
48
import org.gvsig.tools.dynobject.impl.DefaultDynClass;
49
import org.gvsig.tools.service.ServiceException;
50
import org.gvsig.tools.swing.api.ToolsSwingLocator;
51
import org.gvsig.tools.swing.api.dynobject.DynObjectModel;
52
import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager;
53

  
54
/**
55
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
56
 * 
57
 */
58
public class TestDynObject extends DefaultDynClass {
59

  
60
    public static final String TESTDYNOBJECT_NAME = "Test";
61
    public static final String TESTDYNOBJECTREADONLY_NAME = "TestReadOnly";
62

  
63
    private static DynObjectSwingManager swingManager =
64
        ToolsSwingLocator.getDynObjectSwingManager();
65

  
66
    private static DynObjectManager dynManager =
67
        ToolsLocator.getDynObjectManager();
68
    
69
    
70

  
71
    public static void registerDynObject() {
72
        dynManager.add(new TestDynObject(TESTDYNOBJECT_NAME, "Test dynclass", false));
73
        dynManager.add(new TestDynObject(TESTDYNOBJECTREADONLY_NAME, "Test dynclass with readonly fields", true));
74
    }
75

  
76

  
77
    /**
78
     * @param manager
79
     * @param name
80
     * @param description
81
     */
82
    public TestDynObject(String name, String description, boolean allReadOnly) {
83
        super(dynManager, name, description);
84
        if(!allReadOnly){
85
            initDynClass();
86
        }else{
87
            initReadOnlyDynClass();
88
        }
89
    }
90

  
91
    /**
92
     * @return
93
     */
94
    // private JDynObjectComponent getAddressDynObjectView() {
95
    // try {
96
    // Adress testDynObject = (TestDynObject) dynManager
97
    // .get("Test");
98
    // return swingManager.createJDynObjectComponent(testDynObject
99
    // .createDynObject(), testDynObject.createDynModel());
100
    // } catch (ServiceException e) {
101
    // return null;
102
    // }
103
    // }
104

  
105
    /**
106
     * @return
107
     * @throws ServiceException
108
     */
109
    public DynObjectModel createDynModel() throws ServiceException {
110
        DynObjectModel model = swingManager.createEmptyDynObjectModel(this);
111
        model.add("text");
112
        model.add("label");
113
        model.add("text-list");
114
        model.add("label-list");
115
        
116
        model.add("boolean");
117
        model.add("boolean-list");
118

  
119
        // model.add("SRS", "srs");
120
        // model.add("SRS", "crs");
121
        model.add("Date", "date");
122
        model.add("Date", "date-only");
123
        model.add("Date", "time-only");
124
        model.add("Date", "timestamp");
125
        model.add("Files", "file");
126
        model.add("Files", "folder");
127
        model.add("Files", "files");
128
        model.add("Files", "folders");
129

  
130
        model.add("integers", "integer");
131
        model.add("integers", "float");
132
        model.add("integers", "dates");
133
        model.add("list", "byte");
134
        model.add("list", "integer-list");
135
        model.add("list", "float-list");
136
        model.add("list", "byte-list");
137

  
138
        model.add("combo-list");
139
        model.add("combo");
140
        model.add("combo");
141

  
142
        model.add("DynObjects", "Address");
143
        model.add("DynObjects", "Address-list");
144
        return model;
145
    }
146

  
147
    public DynObject createDynObject() throws ServiceException {
148
        DynObject dynObject = dynManager.createDynObject(this);
149

  
150
        dynObject.setDynValue("text", "some text");
151
        dynObject.setDynValue("label", "some readonly text");
152

  
153
        // BOOLEAN LIST
154
        List<Boolean> booleanList = new ArrayList<Boolean>();
155
        dynObject.setDynValue("boolean-list", booleanList);
156

  
157
        // adding list values
158
        booleanList.add(true);
159
        booleanList.add(false);
160
        booleanList.add(null);
161

  
162
        // STRING LIST
163
        List<String> stringList = new ArrayList<String>();
164
        dynObject.setDynValue("text-list", stringList);
165

  
166
        // adding list values
167
        stringList.add("string-1");
168
        stringList.add("string-2");
169
        stringList.add("string-3");
170

  
171
        
172
        // LABEL LIST
173
        List<String> labelList = new ArrayList<String>();
174
        dynObject.setDynValue("label-list", labelList);
175

  
176
        // adding list values
177
        labelList.add("label-1");
178
        labelList.add("label-2");
179
        labelList.add("label-3");
180

  
181
        
182
        // INTEGER LIST
183
        List<Integer> integerList = new ArrayList<Integer>();
184
        dynObject.setDynValue("integer-list", integerList);
185

  
186
        // a?ado los valores del list
187
        integerList.add(12345);
188
        integerList.add(123456);
189
        integerList.add(12345);
190
        integerList.add(123457);
191
        integerList.add(12345);
192

  
193
        // DOUBLE LIST
194
        List<Double> floatList = new ArrayList<Double>();
195
        dynObject.setDynValue("float-list", floatList);
196

  
197
        // a?ado los valores del list
198
        floatList.add(12345.45);
199
        floatList.add(123456.3);
200
        floatList.add(12345.2);
201

  
202
        // BIT LIST
203
        List<Byte> byteList = new ArrayList<Byte>();
204
        dynObject.setDynValue("byte-list", byteList);
205

  
206
        byte a = (byte) 0xAA;
207
        byte b = (byte) 0xBB;
208
        byte c = (byte) 0xCC;
209

  
210
        // a?ado los valores del list
211
        byteList.add(a);
212
        byteList.add(b);
213
        byteList.add(c);
214

  
215
        dynObject.setDynValue("float", 12345.321f);
216
        dynObject.setDynValue("integer", 123);
217
        dynObject.setDynValue("combo", 0);
218

  
219
        dynObject.setDynValue("date", new Date());
220
        dynObject.setDynValue("time-only", new Date());
221

  
222
        dynObject.setDynValue("Address", dynManager
223
            .createDynObject(new Address("Address", "Address example")));
224

  
225
        // DYNOBJECT LIST
226
        List<DynObject> dynObjectList = new ArrayList<DynObject>();
227
        dynObjectList.add(dynManager.createDynObject(new Address(
228
            "Address-list", "Address list example")));
229

  
230
        dynObject.setDynValue("Address-list", dynObjectList);
231

  
232
        List<File> folderList = new ArrayList<File>();
233
        dynObject.setDynValue("folders", folderList);
234
        return dynObject;
235
    }
236

  
237
    private void initDynClass() {
238

  
239
        this.addDynFieldList("Address-list").setMandatory(true)
240
            .setElementsType(DataTypes.DYNOBJECT);
241

  
242
        // TODO add all the available data types
243
        this.addDynFieldString("text");
244
        this.addDynFieldString("label").setReadOnly(true);
245

  
246
        this.addDynFieldInt("integer").setReadOnly(true).setMandatory(true);
247

  
248

  
249
        this.addDynFieldList("text-list").setMandatory(true)
250
            .setElementsType(DataTypes.STRING);
251

  
252
        this.addDynFieldList("label-list").setMandatory(true)
253
            .setElementsType(DataTypes.STRING).setReadOnly(true);
254
        
255
        this.addDynFieldList("boolean-list").setMandatory(true)
256
            .setElementsType(DataTypes.BOOLEAN);
257
        this.addDynFieldList("integer-list").setMandatory(true)
258
            .setElementsType(DataTypes.INT);
259
        this.addDynFieldFloat("float");
260
        this.addDynFieldList("float-list").setMandatory(true).setElementsType(
261
            DataTypes.FLOAT);
262
        //revisar esto
263
        this.addDynField("byte").setType(DataTypes.BYTE);
264
        this.addDynFieldList("byte-list").setMandatory(true).setElementsType(
265
            DataTypes.BYTE);
266

  
267
        DynObjectValueItem[] values = new DynObjectValueItem[3];
268
        values[0] = new DynObjectValueItem(0, "monday");
269
        values[1] = new DynObjectValueItem(1, "tuesday");
270
        values[2] = new DynObjectValueItem(2, "wednesday");
271
        this.addDynFieldInt("combo").setDefaultFieldValue(0)
272
            .setAvailableValues(values).setMandatory(true);
273

  
274
        this.addDynFieldList("combo-list").setMandatory(true).setElementsType(
275
            DataTypes.INT).getElementsType().setAvailableValues(values);
276

  
277
        this.addDynField("file").setMandatory(true).setType(DataTypes.FILE);
278
        this.addDynField("folder").setMandatory(true).setType(DataTypes.FOLDER);
279
        this.addDynFieldList("folders").setElementsType(DataTypes.FOLDER);
280
        this.addDynFieldList("files").setElementsType(DataTypes.FILE);
281

  
282
        this.addDynFieldDate("date").setMandatory(true).setSubtype(null);
283
        this.addDynField("date-only").setMandatory(true)
284
            .setType(DataTypes.DATE).setSubtype(DataTypes.SUBTYPE_DATE);
285
        this.addDynFieldDate("time-only").setMandatory(true).setType(
286
            DataTypes.TIME).setSubtype(null);
287
        this.addDynField("timestamp").setMandatory(true).setType(
288
            DataTypes.TIMESTAMP);
289

  
290
        this.addDynFieldBoolean("boolean");
291

  
292
        this.addDynField("Address").setType(DataTypes.DYNOBJECT);
293

  
294
         this.addDynFieldList("dates").setMandatory(true).setElementsType(
295
             DataTypes.DATE);
296
    }
297

  
298
    private void initReadOnlyDynClass() {
299

  
300
        this.addDynFieldList("Address-list").setMandatory(true)
301
            .setElementsType(DataTypes.DYNOBJECT).setReadOnly(true);
302

  
303
        // TODO add all the available data types
304
        this.addDynFieldString("text").setReadOnly(true);
305
        this.addDynFieldString("label").setReadOnly(true);
306

  
307
        this.addDynFieldInt("integer").setReadOnly(true).setMandatory(true);
308

  
309

  
310
        this.addDynFieldList("text-list").setMandatory(true)
311
            .setElementsType(DataTypes.STRING).setReadOnly(true);
312

  
313
        this.addDynFieldList("label-list").setMandatory(true)
314
            .setElementsType(DataTypes.STRING).setReadOnly(true);
315
        
316
        this.addDynFieldList("boolean-list").setMandatory(true)
317
            .setElementsType(DataTypes.BOOLEAN).setReadOnly(true);
318
        this.addDynFieldList("integer-list").setMandatory(true)
319
            .setElementsType(DataTypes.INT).setReadOnly(true);
320
        this.addDynFieldFloat("float").setReadOnly(true);
321
        this.addDynFieldList("float-list").setMandatory(true).setElementsType(
322
            DataTypes.FLOAT).setReadOnly(true);
323
        //revisar esto
324
        this.addDynField("byte").setType(DataTypes.BYTE).setReadOnly(true);
325
        this.addDynFieldList("byte-list").setMandatory(true).setElementsType(
326
            DataTypes.BYTE).setReadOnly(true);
327

  
328
        DynObjectValueItem[] values = new DynObjectValueItem[3];
329
        values[0] = new DynObjectValueItem(0, "monday");
330
        values[1] = new DynObjectValueItem(1, "tuesday");
331
        values[2] = new DynObjectValueItem(2, "wednesday");
332
        this.addDynFieldInt("combo").setDefaultFieldValue(0)
333
            .setAvailableValues(values).setMandatory(true).setReadOnly(true);
334

  
335
        this.addDynFieldList("combo-list").setMandatory(true).setElementsType(
336
            DataTypes.INT).getElementsType().setAvailableValues(values).setReadOnly(true);
337

  
338
        this.addDynField("file").setMandatory(true).setType(DataTypes.FILE).setReadOnly(true);
339
        this.addDynField("folder").setMandatory(true).setType(DataTypes.FOLDER);
340
        this.addDynFieldList("folders").setElementsType(DataTypes.FOLDER);
341
        this.addDynFieldList("files").setElementsType(DataTypes.FILE).setReadOnly(true);
342

  
343
        this.addDynFieldDate("date").setMandatory(true).setSubtype(null).setReadOnly(true);
344
        this.addDynField("date-only").setMandatory(true)
345
            .setType(DataTypes.DATE).setSubtype(DataTypes.SUBTYPE_DATE).setReadOnly(true);
346
        this.addDynFieldDate("time-only").setMandatory(true).setType(
347
            DataTypes.TIME).setSubtype(null).setReadOnly(true);
348
        this.addDynField("timestamp").setMandatory(true).setType(
349
            DataTypes.TIMESTAMP).setReadOnly(true);
350

  
351
        this.addDynFieldBoolean("boolean").setReadOnly(true);
352

  
353
        this.addDynField("Address").setType(DataTypes.DYNOBJECT).setReadOnly(true);
354

  
355
         this.addDynFieldList("dates").setMandatory(true).setElementsType(
356
             DataTypes.DATE).setReadOnly(true);
357
    }
358

  
359
    
360
    // public DynObject createDynObject() {
361
    // DynObject dynObject = dynManager.createDynObject(this);
362
    //
363
    // dynObject.setDynValue("text", "some text");
364
    //
365
    // dynObject.setDynValue("label", "this is a readonly text");
366
    //
367
    // List<Integer> integerList = new ArrayList<Integer>();
368
    // dynObject.setDynValue("integer-list", integerList);
369
    //
370
    // // a?ado los valores del list
371
    // integerList.add(12345);
372
    // integerList.add(123456);
373
    // integerList.add(12345);
374
    // integerList.add(123457);
375
    // integerList.add(12345);
376
    //
377
    // // List<File> folderList = new ArrayList<File>();
378
    //
379
    // dynObject.setDynValue("float", 12345.321f);
380
    // dynObject.setDynValue("integer-readonly", 123);
381
    // dynObject.setDynValue("combo", 0);
382
    // // dynObject.setDynValue("folders", folderList);
383
    //
384
    // return dynObject;
385
    // }
386
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.17/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/dynobject/DynObjectComponentAction.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2010 {}  {{Task}}
27
 */
28
package org.gvsig.tools.main.dynobject;
29

  
30
import java.awt.BorderLayout;
31
import java.awt.Component;
32
import java.awt.Dimension;
33
import java.awt.event.ActionEvent;
34
import java.awt.event.ActionListener;
35

  
36
import javax.swing.JButton;
37
import javax.swing.JComponent;
38
import javax.swing.JFrame;
39
import javax.swing.JPanel;
40
import javax.swing.JTabbedPane;
41

  
42
import org.gvsig.tools.ToolsLocator;
43
import org.gvsig.tools.dynobject.DynObjectManager;
44
import org.gvsig.tools.main.MainAction;
45
import org.gvsig.tools.service.ServiceException;
46
import org.gvsig.tools.swing.api.ToolsSwingLocator;
47
import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager;
48
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent;
49
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynComponent;
50

  
51
/**
52
 * Action used to show the DynObject components panel
53
 * 
54
 * @author 2010- C?sar Ordi?ana - gvSIG team
55
 */
56
public class DynObjectComponentAction extends MainAction {
57

  
58
    private static final long serialVersionUID = -3386010046112585198L;
59

  
60
    private static DynObjectManager dynManager =
61
        ToolsLocator.getDynObjectManager();
62

  
63
    private static DynObjectSwingManager swingManager =
64
        ToolsSwingLocator.getDynObjectSwingManager();
65

  
66
    private JDynObjectComponent dynObjectView;
67

  
68
    private String dynObjectID;
69

  
70
    /**
71
     * @see MainAction#MainAction(JTabbedPane)
72
     */
73
    public DynObjectComponentAction(JTabbedPane tabbedPane, String dynObjectID) {
74
        super(dynObjectID + "Action", tabbedPane);
75
        this.dynObjectID= dynObjectID;
76
        putValue(SHORT_DESCRIPTION, "DynObject viewer components");
77
    }
78

  
79
    @Override
80
    protected JComponent createComponent() {
81
        JPanel mainPane = new JPanel(new BorderLayout());
82
        dynObjectView = getDynObjectView(dynObjectID);
83
        if (dynObjectView == null)
84
            return mainPane;
85

  
86
        JComponent component = dynObjectView.asJComponent();
87
        mainPane.add(component, BorderLayout.CENTER);
88
        component.setPreferredSize(new Dimension(100, 100));
89
        JButton button = new JButton("Save");
90
        button.addActionListener(new ActionListener() {
91

  
92
            public void actionPerformed(ActionEvent e) {
93
                launchNewFrame();
94
            }
95
        });
96
        mainPane.add(button, BorderLayout.SOUTH);
97

  
98
        return mainPane;
99
    }
100

  
101
    @Override
102
    protected String getComponentTitle() {
103
        return "DynObject";
104
    }
105

  
106
    /**
107
     * @return
108
     */
109
    private JDynObjectComponent getDynObjectView(String dynObjectID) {
110
        if (dynObjectView != null)
111
            return dynObjectView;
112
        try {
113
            TestDynObject testDynObject =
114
                (TestDynObject) dynManager.get(dynObjectID);
115
            this.dynObjectView =
116
                swingManager.createJDynObjectComponent(testDynObject
117
                    .createDynObject(), testDynObject.createDynModel());
118
            return this.dynObjectView;
119
        } catch (ServiceException e) {
120
            return null;
121
        }
122
    }
123

  
124
    /**
125
     * @param dynObjectView
126
     */
127
    protected void launchNewFrame() {
128

  
129
        getDynObjectView().saveStatus();
130

  
131
        final JFrame frame = new JFrame("Tools swing components test app");
132
        // frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
133

  
134
        frame.getContentPane().add(
135
            (Component) getDynObjectView().asJComponent());
136

  
137
        // Display the window.
138
        frame.pack();
139
        frame.setVisible(true);
140
    }
141

  
142
    private JDynObjectComponent getDynObjectView() {
143
        return this.getDynObjectView(dynObjectID);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff