Revision 1725
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.155/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.155/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.155/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.155/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.taskstatus.JTaskStatusAction; |
|
42 |
import org.gvsig.tools.main.usability.UsabilityAction; |
|
43 |
import org.gvsig.tools.main.window.ModalAction; |
|
44 |
|
|
45 |
/** |
|
46 |
* @author 2010- C?sar Ordi?ana - gvSIG team |
|
47 |
*/ |
|
48 |
public class Main { |
|
49 |
|
|
50 |
private JTabbedPane tabbedPane; |
|
51 |
private JMenuBar menuBar; |
|
52 |
private JToolBar toolBar; |
|
53 |
|
|
54 |
public static void main(String args[]) { |
|
55 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
56 |
Main main = new Main(); |
|
57 |
main.show(); |
|
58 |
} |
|
59 |
|
|
60 |
public void show() { |
|
61 |
|
|
62 |
final JFrame frame = new JFrame("Tools swing components test app"); |
|
63 |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
|
64 |
|
|
65 |
// Add a tabbed pane as a content pane |
|
66 |
tabbedPane = new JTabbedPane(); |
|
67 |
tabbedPane.setTabPlacement(JTabbedPane.BOTTOM); |
|
68 |
frame.getContentPane().add(tabbedPane); |
|
69 |
|
|
70 |
// Create application actions |
|
71 |
MainAction[] actions = createActions(); |
|
72 |
|
|
73 |
// Create the menu bar. |
|
74 |
menuBar = new JMenuBar(); |
|
75 |
|
|
76 |
// Build the menu. |
|
77 |
JMenu menuFile = new JMenu("File"); |
|
78 |
JMenuItem menuItemExit = new JMenuItem("Exit"); |
|
79 |
menuItemExit.addActionListener(new ActionListener() { |
|
80 |
|
|
81 |
public void actionPerformed(ActionEvent e) { |
|
82 |
frame.dispose(); |
|
83 |
System.exit(0); |
|
84 |
} |
|
85 |
}); |
|
86 |
menuFile.add(menuItemExit); |
|
87 |
menuBar.add(menuFile); |
|
88 |
|
|
89 |
// Add all actions to the menu bar |
|
90 |
JMenu menuDemo = new JMenu("Tools components"); |
|
91 |
for (int i = 0; i < actions.length; i++) { |
|
92 |
menuDemo.add(new JMenuItem(actions[i])); |
|
93 |
} |
|
94 |
menuBar.add(menuDemo); |
|
95 |
|
|
96 |
// Build the toolbar |
|
97 |
toolBar = new JToolBar("Main toolbar"); |
|
98 |
|
|
99 |
// Add all actions to the toolbar |
|
100 |
for (int i = 0; i < actions.length; i++) { |
|
101 |
toolBar.add(new JButton(actions[i])); |
|
102 |
} |
|
103 |
|
|
104 |
frame.setPreferredSize(new Dimension(800, 600)); |
|
105 |
|
|
106 |
frame.setJMenuBar(menuBar); |
|
107 |
frame.add(toolBar, BorderLayout.PAGE_START); |
|
108 |
|
|
109 |
// Display the window. |
|
110 |
frame.pack(); |
|
111 |
frame.setVisible(true); |
|
112 |
} |
|
113 |
|
|
114 |
private MainAction[] createActions() { |
|
115 |
return new MainAction[] { |
|
116 |
new UsabilityAction(tabbedPane), |
|
117 |
new JTaskStatusAction(tabbedPane), |
|
118 |
new ModalAction(tabbedPane) |
|
119 |
}; |
|
120 |
} |
|
121 |
|
|
122 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.155/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.155/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.155/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.155/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.155/org.gvsig.tools.main/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<artifactId>org.gvsig.tools.main</artifactId> |
|
4 |
<packaging>jar</packaging> |
|
5 |
<name>org.gvsig.tools.main</name> |
|
6 |
<parent> |
|
7 |
<groupId>org.gvsig</groupId> |
|
8 |
<artifactId>org.gvsig.tools</artifactId> |
|
9 |
<version>3.0.155</version> |
|
10 |
</parent> |
|
11 |
<dependencies> |
|
12 |
<dependency> |
|
13 |
<groupId>org.gvsig</groupId> |
|
14 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
15 |
</dependency> |
|
16 |
<dependency> |
|
17 |
<groupId>org.gvsig</groupId> |
|
18 |
<artifactId>org.gvsig.tools.swing.api</artifactId> |
|
19 |
</dependency> |
|
20 |
<dependency> |
|
21 |
<groupId>org.gvsig</groupId> |
|
22 |
<artifactId>org.gvsig.tools.swing.impl</artifactId> |
|
23 |
<scope>runtime</scope> |
|
24 |
</dependency> |
|
25 |
</dependencies> |
|
26 |
</project> |
|
0 | 27 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.155/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/visitor/impl/AbstractVisitableTest.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 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
25 |
* |
|
26 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
27 |
* of the Valencian Government (CIT) |
|
28 |
* |
|
29 |
* This program is free software; you can redistribute it and/or |
|
30 |
* modify it under the terms of the GNU General Public License |
|
31 |
* as published by the Free Software Foundation; either version 2 |
|
32 |
* of the License, or (at your option) any later version. |
|
33 |
* |
|
34 |
* This program is distributed in the hope that it will be useful, |
|
35 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
36 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
37 |
* GNU General Public License for more details. |
|
38 |
* |
|
39 |
* You should have received a copy of the GNU General Public License |
|
40 |
* along with this program; if not, write to the Free Software |
|
41 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
42 |
* MA 02110-1301, USA. |
|
43 |
* |
|
44 |
*/ |
|
45 |
|
|
46 |
/* |
|
47 |
* AUTHORS (In addition to CIT): |
|
48 |
* 2009 {} {{Task}} |
|
49 |
*/ |
|
50 |
package org.gvsig.tools.visitor.impl; |
|
51 |
|
|
52 |
import junit.framework.TestCase; |
|
53 |
|
|
54 |
import org.gvsig.tools.exception.BaseException; |
|
55 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
56 |
import org.gvsig.tools.visitor.Visitor; |
|
57 |
|
|
58 |
/** |
|
59 |
* Unit tests for the class {@link AbstractVisitable}. |
|
60 |
* |
|
61 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team |
|
62 |
*/ |
|
63 |
public class AbstractVisitableTest extends TestCase { |
|
64 |
|
|
65 |
private static final int COUNT = 10; |
|
66 |
|
|
67 |
private AbstractVisitable visitable; |
|
68 |
|
|
69 |
protected void setUp() throws Exception { |
|
70 |
super.setUp(); |
|
71 |
visitable = new TestVisitable(); |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* Test method for {@link org.gvsig.tools.visitor.impl.AbstractVisitable#accept(org.gvsig.tools.visitor.Visitor)}. |
|
76 |
*/ |
|
77 |
public void testAccept() throws Exception { |
|
78 |
// Check the visitable visits all elements |
|
79 |
CountVisitor count = new CountVisitor(); |
|
80 |
visitable.accept(count); |
|
81 |
assertEquals(COUNT, count.getCount()); |
|
82 |
|
|
83 |
// Check the visitable takes into account the VisitCancelException |
|
84 |
final int limit = 3; |
|
85 |
CountLimitVisitor limitCount = new CountLimitVisitor(limit); |
|
86 |
visitable.accept(limitCount); |
|
87 |
assertEquals(limit, limitCount.getCount()); |
|
88 |
} |
|
89 |
|
|
90 |
private class TestVisitable extends AbstractVisitable { |
|
91 |
protected void doAccept(Visitor visitor) throws VisitCanceledException, |
|
92 |
BaseException { |
|
93 |
for (int i = 0; i < COUNT; i++) { |
|
94 |
visitor.visit("test"); |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
} |
|
99 |
|
|
100 |
public class CountVisitor implements Visitor { |
|
101 |
private int count = 0; |
|
102 |
|
|
103 |
public void visit(Object obj) throws VisitCanceledException, |
|
104 |
BaseException { |
|
105 |
count++; |
|
106 |
} |
|
107 |
|
|
108 |
public int getCount() { |
|
109 |
return count; |
|
110 |
} |
|
111 |
} |
|
112 |
|
|
113 |
public class CountLimitVisitor extends CountVisitor { |
|
114 |
private final int limit; |
|
115 |
|
|
116 |
public CountLimitVisitor(int limit) { |
|
117 |
this.limit = limit; |
|
118 |
} |
|
119 |
|
|
120 |
public void visit(Object obj) throws VisitCanceledException, |
|
121 |
BaseException { |
|
122 |
super.visit(obj); |
|
123 |
if (getCount() == getLimit()) { |
|
124 |
throw new VisitCanceledException(); |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
public int getLimit() { |
|
129 |
return limit; |
|
130 |
} |
|
131 |
} |
|
132 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.155/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/visitor/impl/AbstractIndexedVisitableTest.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 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
25 |
* |
|
26 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
27 |
* of the Valencian Government (CIT) |
|
28 |
* |
|
29 |
* This program is free software; you can redistribute it and/or |
|
30 |
* modify it under the terms of the GNU General Public License |
|
31 |
* as published by the Free Software Foundation; either version 2 |
|
32 |
* of the License, or (at your option) any later version. |
|
33 |
* |
|
34 |
* This program is distributed in the hope that it will be useful, |
|
35 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
36 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
37 |
* GNU General Public License for more details. |
|
38 |
* |
|
39 |
* You should have received a copy of the GNU General Public License |
|
40 |
* along with this program; if not, write to the Free Software |
|
41 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
42 |
* MA 02110-1301, USA. |
|
43 |
* |
|
44 |
*/ |
|
45 |
|
|
46 |
/* |
|
47 |
* AUTHORS (In addition to CIT): |
|
48 |
* 2009 {} {{Task}} |
|
49 |
*/ |
|
50 |
package org.gvsig.tools.visitor.impl; |
|
51 |
|
|
52 |
import org.gvsig.tools.exception.BaseException; |
|
53 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
54 |
import org.gvsig.tools.visitor.Visitor; |
|
55 |
|
|
56 |
/** |
|
57 |
* Unit tests for the class {@link AbstractIndexedVisitable}. |
|
58 |
* |
|
59 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team |
|
60 |
*/ |
|
61 |
public class AbstractIndexedVisitableTest extends AbstractVisitableTest { |
|
62 |
|
|
63 |
private static final int COUNT = 10; |
|
64 |
|
|
65 |
private AbstractIndexedVisitable visitable; |
|
66 |
|
|
67 |
protected void setUp() throws Exception { |
|
68 |
super.setUp(); |
|
69 |
visitable = new TestIndexedVisitable(); |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Test method for |
|
74 |
* {@link org.gvsig.tools.visitor.impl.AbstractIndexedVisitable#accept(Visitor, long) |
|
75 |
* . |
|
76 |
*/ |
|
77 |
public void testAccept() throws Exception { |
|
78 |
final int index = 2; |
|
79 |
final int limit = 3; |
|
80 |
// Check the visitable visits all elements |
|
81 |
CountVisitor count = new CountVisitor(); |
|
82 |
visitable.accept(count, index); |
|
83 |
assertEquals(COUNT - index, count.getCount()); |
|
84 |
|
|
85 |
// Check the visitable takes into account the VisitCancelException |
|
86 |
CountLimitVisitor limitCount = new CountLimitVisitor(limit); |
|
87 |
visitable.accept(limitCount, index); |
|
88 |
assertEquals(limit, limitCount.getCount()); |
|
89 |
} |
|
90 |
|
|
91 |
public class TestIndexedVisitable extends AbstractIndexedVisitable { |
|
92 |
protected void doAccept(Visitor visitor, long index) |
|
93 |
throws VisitCanceledException, |
|
94 |
BaseException { |
|
95 |
for (int i = (int) index; i < COUNT; i++) { |
|
96 |
visitor.visit("test"); |
|
97 |
} |
|
98 |
} |
|
99 |
|
|
100 |
} |
|
101 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.155/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/dynobject/ImportDynClassTest.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.dynobject; |
|
25 |
|
|
26 |
import java.io.IOException; |
|
27 |
import java.io.InputStream; |
|
28 |
import java.util.Map; |
|
29 |
|
|
30 |
import org.gvsig.tools.ToolsLocator; |
|
31 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
32 |
import org.gvsig.tools.evaluator.Evaluator; |
|
33 |
import org.gvsig.tools.exception.BaseRuntimeException; |
|
34 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
35 |
import org.gvsig.tools.visitor.Visitor; |
|
36 |
import org.slf4j.Logger; |
|
37 |
import org.slf4j.LoggerFactory; |
|
38 |
import org.xmlpull.v1.XmlPullParserException; |
|
39 |
|
|
40 |
public class ImportDynClassTest extends AbstractLibraryAutoInitTestCase { |
|
41 |
|
|
42 |
private final static Logger LOG = LoggerFactory |
|
43 |
.getLogger(ImportDynClassTest.class); |
|
44 |
private DynObjectManager manager; |
|
45 |
|
|
46 |
protected void doSetUp() throws Exception { |
|
47 |
this.manager = ToolsLocator.getDynObjectManager(); |
|
48 |
} |
|
49 |
|
|
50 |
public void testTagBasedBasicTypes() throws InstantiationException, |
|
51 |
XmlPullParserException, IOException { |
|
52 |
try { |
|
53 |
InputStream stream = this.getClass().getResourceAsStream( |
|
54 |
"tagBasedImportDynClassTest.xml"); |
|
55 |
|
|
56 |
Map dynClasses = this.manager.importDynClassDefinitions(stream, |
|
57 |
null); |
|
58 |
|
|
59 |
checkDynClassValues(dynClasses); |
|
60 |
} catch (BaseRuntimeException ex) { |
|
61 |
LOG.error(ex.getMessageStack()); |
|
62 |
throw ex; |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
public void testAttrBasedBasicTypes() throws InstantiationException, |
|
67 |
XmlPullParserException, IOException { |
|
68 |
try { |
|
69 |
InputStream stream = this.getClass().getResourceAsStream( |
|
70 |
"attrBasedImportDynClassTest.xml"); |
|
71 |
|
|
72 |
Map dynClasses = this.manager.importDynClassDefinitions(stream, |
|
73 |
null); |
|
74 |
|
|
75 |
checkDynClassValues(dynClasses); |
|
76 |
} catch (BaseRuntimeException ex) { |
|
77 |
LOG.error(ex.getMessageStack()); |
|
78 |
throw ex; |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
private void checkDynClassValues(Map dynClasses) { |
|
83 |
DynField field; |
|
84 |
|
|
85 |
if (dynClasses.isEmpty()) { |
|
86 |
fail("No ha cargado ninguna clase."); |
|
87 |
} |
|
88 |
if (dynClasses.size() != 4) { |
|
89 |
fail("Ha cargado ms clases de las esperadas"); |
|
90 |
} |
|
91 |
DynClass dynClass = (DynClass) dynClasses.get("MyObjectBasicTypes"); |
|
92 |
assertNotNull("No se ha recuperado la clase 'MyObjectBasicTypes'", |
|
93 |
dynClass); |
|
94 |
assertEquals("La descripcion no es la esperada", |
|
95 |
"MyObjectBasicTypes test definition", dynClass.getDescription()); |
|
96 |
|
|
97 |
field = dynClass.getDynField("a"); |
|
98 |
assertNotNull("No se ha encontrado el campo 'a'", field); |
|
99 |
assertEquals("type para el campo 'a' no tiene el valor esperado.", |
|
100 |
DataTypes.INT, field.getType()); |
|
101 |
assertEquals( |
|
102 |
"isMandatory para el campo 'a' no tiene el valor esperado.", |
|
103 |
true, field.isMandatory()); |
|
104 |
assertEquals( |
|
105 |
"isPersistent para el campo 'a' no tiene el valor esperado.", |
|
106 |
true, field.isPersistent()); |
|
107 |
assertEquals("minValue para el campo 'a' no tiene el valor esperado.", |
|
108 |
0, ((Integer) field.getMinValue()).intValue()); |
|
109 |
assertEquals("maxValue para el campo 'a' no tiene el valor esperado.", |
|
110 |
100, ((Integer) field.getMaxValue()).intValue()); |
|
111 |
assertEquals( |
|
112 |
"defaultValue para el campo 'a' no tiene el valor esperado.", |
|
113 |
1, ((Integer) field.getDefaultValue()).intValue()); |
|
114 |
assertEquals("group para el campo 'a' no tiene el valor esperado.", |
|
115 |
"Numbers", field.getGroup()); |
|
116 |
assertEquals("order para el campo 'a' no tiene el valor esperado.", 12, |
|
117 |
field.getOder()); |
|
118 |
|
|
119 |
field = dynClass.getDynField("b"); |
|
120 |
assertNotNull("No se ha encontrado el campo 'b'", field); |
|
121 |
assertEquals("type para el campo 'b' no tiene el valor esperado.", |
|
122 |
DataTypes.LONG, field.getType()); |
|
123 |
assertEquals( |
|
124 |
"isMandatory para el campo 'b' no tiene el valor esperado.", |
|
125 |
true, field.isMandatory()); |
|
126 |
assertEquals( |
|
127 |
"isPersistent para el campo 'b' no tiene el valor esperado.", |
|
128 |
true, field.isPersistent()); |
|
129 |
assertEquals( |
|
130 |
"defaultValue para el campo 'b' no tiene el valor esperado.", |
|
131 |
2, ((Long) field.getDefaultValue()).longValue()); |
|
132 |
assertEquals("group para el campo 'b' no tiene el valor esperado.", |
|
133 |
"Numbers", field.getGroup()); |
|
134 |
|
|
135 |
field = dynClass.getDynField("c"); |
|
136 |
assertNotNull("No se ha encontrado el campo 'c'", field); |
|
137 |
assertEquals("type para el campo 'c' no tiene el valor esperado.", |
|
138 |
DataTypes.DOUBLE, field.getType()); |
|
139 |
assertEquals( |
|
140 |
"isMandatory para el campo 'c' no tiene el valor esperado.", |
|
141 |
false, field.isMandatory()); |
|
142 |
assertEquals( |
|
143 |
"isPersistent para el campo 'c' no tiene el valor esperado.", |
|
144 |
true, field.isPersistent()); |
|
145 |
assertEquals("minValue para el campo 'c' no tiene el valor esperado.", |
|
146 |
0.0, ((Double) field.getMinValue()).doubleValue(), 0.001); |
|
147 |
assertEquals("maxValue para el campo 'c' no tiene el valor esperado.", |
|
148 |
100.0, ((Double) field.getMaxValue()).doubleValue(), 0.001); |
|
149 |
assertEquals( |
|
150 |
"defaultValue para el campo 'c' no tiene el valor esperado.", |
|
151 |
1.1, ((Double) field.getDefaultValue()).doubleValue(), 0.001); |
|
152 |
assertEquals("group para el campo 'c' no tiene el valor esperado.", |
|
153 |
"Numbers", field.getGroup()); |
|
154 |
|
|
155 |
field = dynClass.getDynField("d"); |
|
156 |
assertNotNull("No se ha encontrado el campo 'd'", field); |
|
157 |
assertEquals("type para el campo 'd' no tiene el valor esperado.", |
|
158 |
DataTypes.FLOAT, field.getType()); |
|
159 |
assertEquals( |
|
160 |
"isMandatory para el campo 'd' no tiene el valor esperado.", |
|
161 |
false, field.isMandatory()); |
|
162 |
assertEquals( |
|
163 |
"isPersistent para el campo 'd' no tiene el valor esperado.", |
|
164 |
true, field.isPersistent()); |
|
165 |
assertEquals( |
|
166 |
"defaultValue para el campo 'd' no tiene el valor esperado.", |
|
167 |
1.2, ((Float) field.getDefaultValue()).floatValue(), 0.001); |
|
168 |
assertEquals("group para el campo 'd' no tiene el valor esperado.", |
|
169 |
"Numbers", field.getGroup()); |
|
170 |
|
|
171 |
field = dynClass.getDynField("e"); |
|
172 |
assertNotNull("No se ha encontrado el campo 'e'", field); |
|
173 |
assertEquals("type para el campo 'e' no tiene el valor esperado.", |
|
174 |
DataTypes.BOOLEAN, field.getType()); |
|
175 |
assertEquals( |
|
176 |
"isMandatory para el campo 'e' no tiene el valor esperado.", |
|
177 |
true, field.isMandatory()); |
|
178 |
assertEquals( |
|
179 |
"isPersistent para el campo 'e' no tiene el valor esperado.", |
|
180 |
false, field.isPersistent()); |
|
181 |
assertEquals( |
|
182 |
"defaultValue para el campo 'e' no tiene el valor esperado.", |
|
183 |
true, ((Boolean) field.getDefaultValue()).booleanValue()); |
|
184 |
assertEquals( |
|
185 |
"availableValues[0].value para el campo 'e' no tiene el valor esperado.", |
|
186 |
true, ((Boolean) (field.getAvailableValues()[0].getValue())) |
|
187 |
.booleanValue()); |
|
188 |
assertEquals( |
|
189 |
"availableValues[0].label para el campo 'e' no tiene el valor esperado.", |
|
190 |
"True", field.getAvailableValues()[0].getLabel()); |
|
191 |
assertEquals( |
|
192 |
"availableValues[1].value para el campo 'e' no tiene el valor esperado.", |
|
193 |
false, ((Boolean) (field.getAvailableValues()[1].getValue())) |
|
194 |
.booleanValue()); |
|
195 |
assertEquals( |
|
196 |
"availableValues[1].label para el campo 'e' no tiene el valor esperado.", |
|
197 |
"False", field.getAvailableValues()[1].getLabel()); |
|
198 |
|
|
199 |
field = dynClass.getDynField("f"); |
|
200 |
assertNotNull("No se ha encontrado el campo 'f'", field); |
|
201 |
assertEquals("type para el campo 'f' no tiene el valor esperado.", |
|
202 |
DataTypes.STRING, field.getType()); |
|
203 |
assertEquals( |
|
204 |
"isMandatory para el campo 'f' no tiene el valor esperado.", |
|
205 |
true, field.isMandatory()); |
|
206 |
assertEquals( |
|
207 |
"isPersistent para el campo 'f' no tiene el valor esperado.", |
|
208 |
true, field.isPersistent()); |
|
209 |
assertEquals( |
|
210 |
"defaultValue para el campo 'f' no tiene el valor esperado.", |
|
211 |
"red", field.getDefaultValue()); |
|
212 |
assertEquals( |
|
213 |
"availableValues[0].value para el campo 'f' no tiene el valor esperado.", |
|
214 |
"red", field.getAvailableValues()[0].getValue()); |
|
215 |
assertEquals( |
|
216 |
"availableValues[0].label para el campo 'f' no tiene el valor esperado.", |
|
217 |
"Red", field.getAvailableValues()[0].getLabel()); |
|
218 |
assertEquals( |
|
219 |
"availableValues[1].value para el campo 'f' no tiene el valor esperado.", |
|
220 |
"green", field.getAvailableValues()[1].getValue()); |
|
221 |
assertEquals( |
|
222 |
"availableValues[1].label para el campo 'f' no tiene el valor esperado.", |
|
223 |
"Green", field.getAvailableValues()[1].getLabel()); |
|
224 |
assertEquals( |
|
225 |
"availableValues[2].value para el campo 'f' no tiene el valor esperado.", |
|
226 |
"blue", field.getAvailableValues()[2].getValue()); |
|
227 |
assertEquals( |
|
228 |
"availableValues[2].label para el campo 'f' no tiene el valor esperado.", |
|
229 |
"Blue", field.getAvailableValues()[2].getLabel()); |
|
230 |
|
|
231 |
field = dynClass.getDynField("g"); |
|
232 |
assertNotNull("No se ha encontrado el campo 'g'", field); |
|
233 |
assertEquals("type para el campo 'g' no tiene el valor esperado.", |
|
234 |
DataTypes.DATE, field.getType()); |
|
235 |
assertEquals( |
|
236 |
"isMandatory para el campo 'g' no tiene el valor esperado.", |
|
237 |
true, field.isMandatory()); |
|
238 |
assertEquals( |
|
239 |
"isPersistent para el campo 'g' no tiene el valor esperado.", |
|
240 |
true, field.isPersistent()); |
|
241 |
|
|
242 |
dynClass = (DynClass) dynClasses.get("MyObjectBasicTypes4"); |
|
243 |
assertNotNull("No se ha recuperado la clase 'MyObjectBasicTypes4'", |
|
244 |
dynClass); |
|
245 |
|
|
246 |
field = dynClass.getDynField("obj"); |
|
247 |
assertNotNull("No se ha encontrado el campo 'obj'", field); |
|
248 |
assertEquals("type para el campo 'obj' no tiene el valor esperado.", |
|
249 |
DataTypes.OBJECT, field.getType()); |
|
250 |
assertTrue("El valor de classOfValue del campo obj no es el esperado.", Evaluator.class.isAssignableFrom(field.getClassOfValue()) ) ; |
|
251 |
|
|
252 |
field = dynClass.getDynField("objs"); |
|
253 |
assertNotNull("No se ha encontrado el campo 'objs'", field); |
|
254 |
assertEquals("type para el campo 'objs' no tiene el valor esperado.", |
|
255 |
DataTypes.LIST, field.getType()); |
|
256 |
assertTrue("El valor de classOfItems del campo objs no es el esperado.", Visitor.class.isAssignableFrom(field.getClassOfValue()) ) ; |
|
257 |
} |
|
258 |
|
|
259 |
} |
|
0 | 260 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.155/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/dynobject/DynObjectSetTest.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 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
25 |
* |
|
26 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
27 |
* of the Valencian Government (CIT) |
|
28 |
* |
|
29 |
* This program is free software; you can redistribute it and/or |
|
30 |
* modify it under the terms of the GNU General Public License |
|
31 |
* as published by the Free Software Foundation; either version 2 |
|
32 |
* of the License, or (at your option) any later version. |
|
33 |
* |
|
34 |
* This program is distributed in the hope that it will be useful, |
|
35 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
36 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
37 |
* GNU General Public License for more details. |
|
38 |
* |
|
39 |
* You should have received a copy of the GNU General Public License |
|
40 |
* along with this program; if not, write to the Free Software |
|
41 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
42 |
* MA 02110-1301, USA. |
|
43 |
* |
|
44 |
*/ |
|
45 |
|
|
46 |
/* |
|
47 |
* AUTHORS (In addition to CIT): |
|
48 |
* 2010 {} {{Task}} |
|
49 |
*/ |
|
50 |
package org.gvsig.tools.dynobject; |
|
51 |
|
|
52 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
53 |
import org.gvsig.tools.exception.BaseException; |
|
54 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
55 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
56 |
import org.gvsig.tools.visitor.Visitor; |
|
57 |
|
|
58 |
/** |
|
59 |
* Tests for the {@link DynObjectSet} interface. |
|
60 |
* |
|
61 |
* @author 2010- C?sar Ordi?ana - gvSIG team |
|
62 |
*/ |
|
63 |
public abstract class DynObjectSetTest extends AbstractLibraryAutoInitTestCase { |
|
64 |
|
|
65 |
protected void doSetUp() throws Exception { |
|
66 |
// Nothing to do |
|
67 |
} |
|
68 |
|
|
69 |
public void testIterator() throws Exception { |
|
70 |
DynObjectSet dynObjectSet = createDynObjectSet(); |
|
71 |
testIterator(dynObjectSet); |
|
72 |
dynObjectSet.dispose(); |
|
73 |
} |
|
74 |
|
|
75 |
private void testIterator(DynObjectSet dynObjectSet) throws Exception { |
|
76 |
try { |
|
77 |
DisposableIterator iter = dynObjectSet.iterator(-5); |
|
78 |
iter.dispose(); |
|
79 |
fail("Iterator index accepted with a value < 0"); |
|
80 |
} catch (Exception ex) { |
|
81 |
// Good |
|
82 |
} |
|
83 |
|
|
84 |
try { |
|
85 |
DisposableIterator iter = dynObjectSet.iterator(dynObjectSet |
|
86 |
.getSize() + 2); |
|
87 |
iter.dispose(); |
|
88 |
fail("Iterator index accepted with a value > collection size"); |
|
89 |
} catch (Exception ex) { |
|
90 |
// Good |
|
91 |
} |
|
92 |
|
|
93 |
long index = dynObjectSet.getSize() - 3l; |
|
94 |
DisposableIterator iter = dynObjectSet.iterator(index); |
|
95 |
int iterations = 0; |
|
96 |
while (iter.hasNext()) { |
|
97 |
iter.next(); |
|
98 |
iterations++; |
|
99 |
} |
|
100 |
assertEquals("The number of iterations remaining is not correct", 3, |
|
101 |
iterations); |
|
102 |
iter.dispose(); |
|
103 |
|
|
104 |
iter = dynObjectSet.iterator(0); |
|
105 |
iterations = 0; |
|
106 |
while (iter.hasNext()) { |
|
107 |
iter.next(); |
|
108 |
iterations++; |
|
109 |
} |
|
110 |
assertEquals("The number of iterations is not the " |
|
111 |
+ "total size of the collection", dynObjectSet.getSize(), |
|
112 |
iterations); |
|
113 |
iter.dispose(); |
|
114 |
} |
|
115 |
|
|
116 |
public void testVisitable() throws Exception { |
|
117 |
DynObjectSet dynObjectSet = createDynObjectSet(); |
|
118 |
testVisitable(dynObjectSet); |
|
119 |
dynObjectSet.dispose(); |
|
120 |
} |
|
121 |
|
|
122 |
private void testVisitable(DynObjectSet dynObjectSet) throws Exception { |
|
123 |
long size = dynObjectSet.getSize(); |
|
124 |
|
|
125 |
TestCountVisitor visitor = new TestCountVisitor(); |
|
126 |
dynObjectSet.accept(visitor); |
|
127 |
|
|
128 |
assertEquals("The number of iterations performed is not correct", size, |
|
129 |
visitor.getCount()); |
|
130 |
|
|
131 |
visitor = new TestCountVisitor(); |
|
132 |
dynObjectSet.accept(visitor, 2); |
|
133 |
|
|
134 |
assertEquals("The number of iterations performed is not correct", |
|
135 |
size - 3, visitor.getCount()); |
|
136 |
} |
|
137 |
|
|
138 |
public void testSize() throws Exception { |
|
139 |
DynObjectSet dynObjectSet = createDynObjectSet(); |
|
140 |
testSize(dynObjectSet); |
|
141 |
dynObjectSet.dispose(); |
|
142 |
} |
|
143 |
|
|
144 |
private void testSize(DynObjectSet dynObjectSet) throws Exception { |
Also available in: Unified diff