Revision 2271
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.241/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.241/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.241/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.241/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.241/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.241/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.241/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.241/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.241/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.241</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.241/org.gvsig.tools.lib/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<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/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
7 |
<packaging>jar</packaging> |
|
8 |
<name>org.gvsig.tools.lib</name> |
|
9 |
<description>Tools related to application framework architecture |
|
10 |
and implementations of design patterns</description> |
|
11 |
<parent> |
|
12 |
<groupId>org.gvsig</groupId> |
|
13 |
<artifactId>org.gvsig.tools</artifactId> |
|
14 |
<version>3.0.241</version> |
|
15 |
</parent> |
|
16 |
<dependencies> |
|
17 |
<dependency> |
|
18 |
<groupId>org.glassfish</groupId> |
|
19 |
<artifactId>javax.json</artifactId> |
|
20 |
<scope>compile</scope> |
|
21 |
</dependency> |
|
22 |
|
|
23 |
<dependency> |
|
24 |
<groupId>org.apache.commons</groupId> |
|
25 |
<artifactId>commons-lang3</artifactId> |
|
26 |
<scope>compile</scope> |
|
27 |
</dependency> |
|
28 |
|
|
29 |
<dependency> |
|
30 |
<groupId>easymock</groupId> |
|
31 |
<artifactId>easymock</artifactId> |
|
32 |
<scope>test</scope> |
|
33 |
</dependency> |
|
34 |
<dependency> |
|
35 |
<groupId>net.sf.kxml</groupId> |
|
36 |
<artifactId>kxml2</artifactId> |
|
37 |
</dependency> |
|
38 |
<dependency> |
|
39 |
<groupId>commons-io</groupId> |
|
40 |
<artifactId>commons-io</artifactId> |
|
41 |
</dependency> |
|
42 |
</dependencies> |
|
43 |
<build> |
|
44 |
<plugins> |
|
45 |
|
|
46 |
<plugin> |
|
47 |
<groupId>org.apache.maven.plugins</groupId> |
|
48 |
<artifactId>maven-jar-plugin</artifactId> |
|
49 |
<configuration> |
|
50 |
</configuration> |
|
51 |
<executions> |
|
52 |
<!-- Generates a jar file only with the test classes --> |
|
53 |
<execution> |
|
54 |
<goals> |
|
55 |
<goal>test-jar</goal> |
|
56 |
</goals> |
|
57 |
</execution> |
|
58 |
</executions> |
|
59 |
</plugin> |
|
60 |
</plugins> |
|
61 |
</build> |
|
62 |
</project> |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.241/org.gvsig.tools.lib/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 |
The project structure of this project is the following: |
|
26 |
|
|
27 |
Project |
|
28 |
|-pom.xml: Maven 2 configuration file. |
|
29 |
`-src |
|
30 |
|-main: Project source code, resources and configuration |
|
31 |
| |-java: Java source code |
|
32 |
| |-resources: Resources needed by the code (resource bundles, images, etc.) |
|
33 |
| `-javadoc: Javadoc common resources |
|
34 |
`-test: Unit tests source code, resources and configuration |
|
35 |
|-java: Unit tests java source code |
|
36 |
`-resources: Resources needed by the test code (resource bundles, images, etc.) |
|
37 |
|
|
38 |
Look at the main folders for a README.txt file with more information on the |
|
39 |
contents of each folder. |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.241/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/Coercion.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2020 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.dataTypes; |
|
25 |
|
|
26 |
/** |
|
27 |
* |
|
28 |
* @author jjdelcerro |
|
29 |
*/ |
|
30 |
public interface Coercion { |
|
31 |
|
|
32 |
public Object coerce(Object value) throws CoercionException; |
|
33 |
|
|
34 |
public Object coerce(Object value, CoercionContext context) throws CoercionException; |
|
35 |
|
|
36 |
} |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.241/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/DefaultDataTypesManager.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.dataTypes.impl; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import java.math.BigDecimal; |
|
28 |
import java.net.URI; |
|
29 |
import java.net.URL; |
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.Date; |
|
32 |
import java.util.Iterator; |
|
33 |
import java.util.List; |
|
34 |
import java.util.Locale; |
|
35 |
import java.util.Map; |
|
36 |
import java.util.Set; |
|
37 |
|
|
38 |
import org.gvsig.installer.lib.api.Version; |
|
39 |
import org.gvsig.tools.dataTypes.Coercion; |
|
40 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
41 |
import org.gvsig.tools.dataTypes.DataType; |
|
42 |
import static org.gvsig.tools.dataTypes.DataType.BYTE_DEFAULT_PRECISION; |
|
43 |
import static org.gvsig.tools.dataTypes.DataType.BYTE_MAX_PRECISION; |
|
44 |
import static org.gvsig.tools.dataTypes.DataType.DECIMAL_DEFAULT_PRECISION; |
|
45 |
import static org.gvsig.tools.dataTypes.DataType.DECIMAL_DEFAULT_SCALE; |
|
46 |
import static org.gvsig.tools.dataTypes.DataType.DECIMAL_MAX_PRECISION; |
|
47 |
import static org.gvsig.tools.dataTypes.DataType.DOUBLE_DEFAULT_PRECISION; |
|
48 |
import static org.gvsig.tools.dataTypes.DataType.DOUBLE_DEFAULT_SCALE; |
|
49 |
import static org.gvsig.tools.dataTypes.DataType.DOUBLE_MAX_PRECISION; |
|
50 |
import static org.gvsig.tools.dataTypes.DataType.FLAG_FLOATING_POINT; |
|
51 |
import static org.gvsig.tools.dataTypes.DataType.FLAG_NUMBER; |
|
52 |
import static org.gvsig.tools.dataTypes.DataType.FLAG_PREDEFINED_PRECISION; |
|
53 |
import static org.gvsig.tools.dataTypes.DataType.FLAG_SUPPORT_PRECISION; |
|
54 |
import static org.gvsig.tools.dataTypes.DataType.FLAG_SUPPORT_SCALE; |
|
55 |
import static org.gvsig.tools.dataTypes.DataType.FLAG_SUPPORT_SIZE; |
|
56 |
import static org.gvsig.tools.dataTypes.DataType.FLOAT_DEFAULT_PRECISION; |
|
57 |
import static org.gvsig.tools.dataTypes.DataType.FLOAT_DEFAULT_SCALE; |
|
58 |
import static org.gvsig.tools.dataTypes.DataType.FLOAT_MAX_PRECISION; |
|
59 |
import static org.gvsig.tools.dataTypes.DataType.INT_DEFAULT_PRECISION; |
|
60 |
import static org.gvsig.tools.dataTypes.DataType.INT_MAX_PRECISION; |
|
61 |
import static org.gvsig.tools.dataTypes.DataType.LONG_DEFAULT_PRECISION; |
|
62 |
import static org.gvsig.tools.dataTypes.DataType.LONG_MAX_PRECISION; |
|
63 |
import static org.gvsig.tools.dataTypes.DataType.PRECISION_NONE; |
|
64 |
import static org.gvsig.tools.dataTypes.DataType.SCALE_NONE; |
|
65 |
import static org.gvsig.tools.dataTypes.DataType.STRING_DEFAULT_SIZE; |
|
66 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
67 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
68 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToDecimal; |
|
69 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToBoolean; |
|
70 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToByte; |
|
71 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToBytearray; |
|
72 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToDate; |
|
73 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToDouble; |
|
74 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToFile; |
|
75 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToFloat; |
|
76 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToInt; |
|
77 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToLocale; |
|
78 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToLong; |
|
79 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToObject; |
|
80 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToString; |
|
81 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToTime; |
|
82 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToTimestamp; |
|
83 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToURI; |
|
84 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToURL; |
|
85 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToVersion; |
|
86 |
import org.gvsig.tools.dynobject.DynObject; |
|
87 |
import org.slf4j.Logger; |
|
88 |
import org.slf4j.LoggerFactory; |
|
89 |
|
|
90 |
public class DefaultDataTypesManager implements DataTypesManager, DataTypes { |
|
91 |
|
|
92 |
private static final Logger LOG = LoggerFactory |
|
93 |
.getLogger(DefaultDataTypesManager.class); |
|
94 |
|
|
95 |
private static final int NEWINDEXES_AT = OBJECT + 1; |
|
96 |
|
|
97 |
private final DataType[] types = new DefaultDataType[MAX_TYPE_VALUE]; |
|
98 |
|
|
99 |
public DefaultDataTypesManager() { |
|
100 |
|
|
101 |
this.addtype(BOOLEAN, null, DataTypes.BOOLEAN_NAME, Boolean.class, new CoerceToBoolean(), |
|
102 |
"datatype-boolean" |
|
103 |
); |
|
104 |
this.addtype(BYTE, null, DataTypes.BYTE_NAME, Byte.class, new CoerceToByte(), |
|
105 |
"datatype-byte", |
|
106 |
FLAG_NUMBER|FLAG_SUPPORT_PRECISION|FLAG_PREDEFINED_PRECISION, |
|
107 |
BYTE_MAX_PRECISION, BYTE_DEFAULT_PRECISION |
|
108 |
); |
|
109 |
this.addtype(CHAR, null, DataTypes.CHAR_NAME, Character.class, new CoerceToString()); |
|
110 |
this.addtype(INT, null, "Integer", Integer.class, new CoerceToInt(), |
|
111 |
"datatype-integer", |
|
112 |
FLAG_NUMBER|FLAG_SUPPORT_PRECISION|FLAG_PREDEFINED_PRECISION, |
|
113 |
INT_MAX_PRECISION, INT_DEFAULT_PRECISION |
|
114 |
); |
|
115 |
this.addtype(LONG, null, DataTypes.LONG_NAME, Long.class, new CoerceToLong(), |
|
116 |
"datatype-long", |
|
117 |
FLAG_NUMBER|FLAG_SUPPORT_PRECISION|FLAG_PREDEFINED_PRECISION, |
|
118 |
LONG_MAX_PRECISION, LONG_DEFAULT_PRECISION |
|
119 |
); |
|
120 |
this.addtype(FLOAT, null, DataTypes.FLOAT_NAME, Float.class, new CoerceToFloat(), |
|
121 |
"datatype-float", |
|
122 |
FLAG_FLOATING_POINT|FLAG_SUPPORT_PRECISION|FLAG_PREDEFINED_PRECISION|FLAG_SUPPORT_SCALE, |
|
123 |
FLOAT_MAX_PRECISION, FLOAT_DEFAULT_PRECISION, FLOAT_DEFAULT_SCALE |
|
124 |
); |
|
125 |
this.addtype(DOUBLE, null, DataTypes.DOUBLE_NAME, Double.class, new CoerceToDouble(), |
|
126 |
"datatype-double", |
|
127 |
FLAG_FLOATING_POINT|FLAG_SUPPORT_PRECISION|FLAG_PREDEFINED_PRECISION|FLAG_SUPPORT_SCALE, |
|
128 |
DOUBLE_MAX_PRECISION, DOUBLE_DEFAULT_PRECISION, DOUBLE_DEFAULT_SCALE |
|
129 |
); |
|
130 |
this.addtype(DECIMAL, null, DataTypes.DECIMAL_NAME, BigDecimal.class, new CoerceToDecimal(), |
|
131 |
"datatype-decimal", |
|
132 |
FLAG_NUMBER|FLAG_SUPPORT_PRECISION|FLAG_SUPPORT_SCALE, |
|
133 |
DECIMAL_MAX_PRECISION, DECIMAL_DEFAULT_PRECISION, DECIMAL_DEFAULT_SCALE |
|
134 |
); |
|
135 |
this.addtype(STRING, null, DataTypes.STRING_NAME, String.class, new CoerceToString(), |
|
136 |
"datatype-string", |
|
137 |
FLAG_SUPPORT_SIZE |
|
138 |
).setDefaultSize(STRING_DEFAULT_SIZE); |
|
139 |
this.addtype(DATE, SUBTYPE_DATE, DataTypes.DATE_NAME, java.sql.Date.class, new CoerceToDate(), "datatype-date"); |
|
140 |
this.addtype(TIME, SUBTYPE_DATE, DataTypes.TIME_NAME, java.sql.Time.class, new CoerceToTime(), "datatype-time"); |
|
141 |
this.addtype(TIMESTAMP, SUBTYPE_DATE, DataTypes.TIMESTAMP_NAME, java.sql.Timestamp.class, new CoerceToTimestamp(), "datatype-timestamp"); |
|
142 |
|
|
143 |
this.addtype(LOCALE, null, DataTypes.LOCALE_NAME, Locale.class, new CoerceToLocale(), |
|
144 |
"datatype-locale" |
|
145 |
); |
|
146 |
|
|
147 |
|
|
148 |
this.addtype(VERSION, null, DataTypes.VERSION_NAME, Version.class, new CoerceToVersion()); |
|
149 |
|
|
150 |
this.addtype(BYTEARRAY, null, DataTypes.BYTEARRAY_NAME, |
|
151 |
(new byte[1]).getClass(), |
|
152 |
new CoerceToBytearray(), |
|
153 |
"datatype-bytearray", |
|
154 |
FLAG_SUPPORT_SIZE |
|
155 |
); |
|
156 |
this.addtype(FILE, SUBTYPE_FILE, DataTypes.FILE_NAME, File.class, new CoerceToFile()); |
|
157 |
this.addtype(FOLDER, SUBTYPE_FOLDER, DataTypes.FOLDER_NAME, File.class, new CoerceToFile()); |
|
158 |
this.addtype(DYNOBJECT, null, DataTypes.DYNOBJECT_NAME, DynObject.class, null); |
|
159 |
this.addtype(URL, null, DataTypes.URL_NAME, URL.class, new CoerceToURL()); |
|
160 |
this.addtype(URI, null, DataTypes.URI_NAME, URI.class, new CoerceToURI()); |
|
161 |
|
|
162 |
this.addtype(ARRAY, null, DataTypes.ARRAY_NAME, (new Object[1]).getClass(), null); |
|
163 |
this.addtype(LIST, null, DataTypes.LIST_NAME, List.class, null); |
|
164 |
this.addtype(SET, null, DataTypes.SET_NAME, Set.class, null); |
|
165 |
this.addtype(MAP, null, DataTypes.MAP_NAME, Map.class, null); |
|
166 |
|
|
167 |
this.addtype(OBJECT, null, DataTypes.OBJECT_NAME, Object.class, new CoerceToObject(), "datatype-object"); |
|
168 |
} |
|
169 |
|
|
170 |
@Override |
|
171 |
public final synchronized DataType addtype(int type, String subtype, String name, |
|
172 |
Class defaultClass, Coercion coercion) { |
|
173 |
return addtype(type, subtype, name, defaultClass, coercion, null, 0, PRECISION_NONE, PRECISION_NONE, SCALE_NONE); |
|
174 |
} |
|
175 |
|
|
176 |
public final synchronized DataType addtype(int type, String subtype, String name, |
|
177 |
Class defaultClass, Coercion coercion, String iconName) { |
|
178 |
return addtype(type, subtype, name, defaultClass, coercion, iconName, 0, PRECISION_NONE, PRECISION_NONE, SCALE_NONE); |
|
179 |
} |
|
180 |
|
|
181 |
@Override |
|
182 |
public final synchronized DataType addtype(int type, String subtype, String name, |
|
183 |
Class defaultClass, Coercion coercion, String iconName, int flags) { |
|
184 |
return addtype(type, subtype, name, defaultClass, coercion, iconName, |
|
185 |
flags, PRECISION_NONE, PRECISION_NONE, SCALE_NONE |
|
186 |
); |
|
187 |
} |
|
188 |
|
|
189 |
public final synchronized DataType addtype(int type, String subtype, String name, |
|
190 |
Class defaultClass, Coercion coercion, String iconName, |
|
191 |
int flags, int max_precision, int default_precision) { |
|
192 |
return addtype(type, subtype, name, defaultClass, coercion, iconName, |
|
193 |
flags, max_precision, default_precision, SCALE_NONE |
|
194 |
); |
|
195 |
} |
|
196 |
|
|
197 |
@Override |
|
198 |
public final synchronized DataType addtype(int type, String subtype, String name, |
|
199 |
Class defaultClass, Coercion coercion, String iconName, |
|
200 |
int flags, int max_precision, int default_precision, int default_scale) { |
|
201 |
if (type == INVALID) { |
|
202 |
type = getNewObjectIndexType(); |
|
203 |
} |
|
204 |
if (type < 1 || type > MAX_TYPE_VALUE) { |
|
205 |
throw new IllegalArgumentException("Wrong type " |
|
206 |
+ Integer.toHexString(type).toUpperCase() + "."); |
|
207 |
} |
|
208 |
|
|
209 |
try { |
|
210 |
// Check if the type has been already registereds |
|
211 |
get(type); |
|
212 |
throw new IllegalArgumentException("type " |
|
213 |
+ Integer.toHexString(type).toUpperCase() + ", name " + name |
|
214 |
+ ", already registered as " + getTypeName(type) + "."); |
|
215 |
} catch (IllegalArgumentException e) { |
|
216 |
// OK, the type is still not registered. |
|
217 |
} |
|
218 |
|
|
219 |
DataType dataType = new DefaultDataType( |
|
220 |
type, subtype, name, defaultClass, coercion, iconName, |
|
221 |
flags, max_precision, default_precision, default_scale |
|
222 |
); |
|
223 |
types[type] = dataType; |
|
224 |
LOG.info("Registered data type {}.", dataType.toString()); |
|
225 |
return dataType; |
|
226 |
} |
|
227 |
|
|
228 |
private int getNewObjectIndexType() { |
|
229 |
for (int i = NEWINDEXES_AT; i <= MAX_TYPE_VALUE; i++) { |
|
230 |
if (types[i] == null) { |
|
231 |
return i; |
|
232 |
} |
|
233 |
} |
|
234 |
return DataTypes.INVALID; |
|
235 |
} |
|
236 |
|
|
237 |
@Override |
|
238 |
public DataType get(int type) { |
|
239 |
DataType dataType = null; |
|
240 |
if (type > 0 && type <= MAX_TYPE_VALUE) { |
|
241 |
dataType = types[type]; |
|
242 |
} |
|
243 |
|
|
244 |
if (dataType == null) { |
|
245 |
throw new IllegalArgumentException("DataType " + type |
|
246 |
+ " not registered"); |
|
247 |
} |
|
248 |
|
|
249 |
return dataType; |
|
250 |
} |
|
251 |
|
|
252 |
@Override |
|
253 |
public boolean isValidType(int type) { |
|
254 |
return type > 0 && type <= MAX_TYPE_VALUE && this.types[type] != null; |
|
255 |
} |
|
256 |
|
|
257 |
@Override |
|
258 |
public boolean isObject(int type) { |
|
259 |
return (type & DataTypes.OBJECT) == DataTypes.OBJECT; |
|
260 |
} |
|
261 |
|
|
262 |
@Override |
|
263 |
public boolean isContainer(int type) { |
|
264 |
return (type & DataTypes.CONTAINER) == DataTypes.CONTAINER; |
|
265 |
} |
|
266 |
|
|
267 |
@Override |
|
268 |
public int getType(String name) { |
|
269 |
if (name != null) { |
|
270 |
for (int i = 0; i < types.length; i++) { |
|
271 |
if (types[i] != null |
|
272 |
&& name.equalsIgnoreCase(types[i].getName())) { |
|
273 |
return i; |
|
274 |
} |
|
275 |
} |
|
276 |
} |
|
277 |
return DataTypes.INVALID; |
|
278 |
} |
|
279 |
|
|
280 |
@Override |
|
281 |
public String getTypeName(int type) { |
|
282 |
DataType dataType = get(type); |
|
283 |
String name = dataType.getName(); |
|
284 |
if (name == null) { |
|
285 |
return "unknow"; |
|
286 |
} |
|
287 |
return name; |
|
288 |
} |
|
289 |
|
|
290 |
@Override |
|
291 |
public Class getDefaultClass(int type) { |
|
292 |
DataType dataType = get(type); |
|
293 |
return dataType.getDefaultClass(); |
|
294 |
} |
|
295 |
|
|
296 |
@Override |
|
297 |
public String getSubtype(int type) { |
|
298 |
DataType dataType = get(type); |
|
299 |
return dataType.getSubtype(); |
|
300 |
} |
|
301 |
|
|
302 |
@Override |
|
303 |
public Coercion getCoercion(int type) { |
|
304 |
DataType dataType = get(type); |
|
305 |
return dataType.getCoercion(); |
|
306 |
} |
|
307 |
|
|
308 |
// @Override |
|
309 |
// public void setCoercion(int type, Coercion coercion) { |
|
310 |
// DataType dataType = get(type); |
|
311 |
// dataType.setCoercion(coercion); |
|
312 |
// } |
|
313 |
@Override |
|
314 |
public void addCoercion(int type, Coercion coercion) { |
|
315 |
DataType dataType = get(type); |
|
316 |
dataType.addCoercion(coercion); |
|
317 |
} |
|
318 |
|
|
319 |
@Override |
|
320 |
public Object coerce(int type, Object value) throws CoercionException { |
|
321 |
DataType dataType = get(type); |
|
322 |
return dataType.coerce(value); |
|
323 |
} |
|
324 |
|
|
325 |
@Override |
|
326 |
public Iterator iterator() { |
|
327 |
List list = new ArrayList(); |
|
328 |
DataType type; |
|
329 |
for (int i = 0; i < this.types.length; i++) { |
|
330 |
type = this.types[i]; |
|
331 |
if (type != null) { |
|
332 |
list.add(this.types[i]); |
|
333 |
} |
|
334 |
} |
|
335 |
return list.iterator(); |
|
336 |
} |
|
337 |
|
|
338 |
@Override |
|
339 |
public DataType getDataType(Class defaultClass) { |
|
340 |
// First look for a class with exact match |
|
341 |
for (DataType type : types) { |
|
342 |
if (type != null) { |
|
343 |
Class typeClass = type.getDefaultClass(); |
|
344 |
if (typeClass != null && typeClass.equals(defaultClass)) { |
|
345 |
return type; |
|
346 |
} |
|
347 |
} |
|
348 |
} |
|
349 |
// Then look for a class which is an interface or parent |
|
350 |
for (DataType type : types) { |
|
351 |
if (type != null) { |
|
352 |
Class typeClass = type.getDefaultClass(); |
|
353 |
if (typeClass != null |
|
354 |
&& typeClass.isAssignableFrom(defaultClass)) { |
|
355 |
return type; |
|
356 |
} |
|
357 |
} |
|
358 |
} |
|
359 |
throw new IllegalArgumentException( |
|
360 |
"There is not any registered data type with the class or a " |
|
361 |
+ "parent of the class: " + defaultClass); |
|
362 |
} |
|
363 |
|
|
364 |
} |
|
0 | 365 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.241/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/DefaultDataType.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.dataTypes.impl; |
|
25 |
|
|
26 |
import java.text.MessageFormat; |
|
27 |
|
|
28 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
29 |
import org.gvsig.tools.dataTypes.DataType; |
|
30 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
31 |
import org.gvsig.tools.dataTypes.Coercion; |
|
32 |
import org.slf4j.Logger; |
|
33 |
import org.slf4j.LoggerFactory; |
|
34 |
import org.gvsig.tools.dataTypes.CoercionContext; |
|
35 |
|
|
36 |
public class DefaultDataType implements DataType { |
|
37 |
|
|
38 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultDataTypesManager.class); |
|
39 |
|
|
40 |
private static class DefaultNumberPrecisionAndScale implements NumberPrecisionAndScale { |
|
41 |
|
|
42 |
private int precision; |
|
43 |
private int scale; |
|
44 |
|
|
45 |
public DefaultNumberPrecisionAndScale(int precision, int scale) { |
|
46 |
this.precision = precision; |
|
47 |
this.scale = scale; |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public int getPrecision() { |
|
52 |
return this.precision; |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public int getScale() { |
|
57 |
return this.scale; |
|
58 |
} |
|
59 |
|
|
60 |
public void setPrecision(int precision) { |
|
61 |
this.precision = precision; |
|
62 |
} |
|
63 |
|
|
64 |
public void setScale(int scale) { |
|
65 |
this.scale = scale; |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
private static final NumberPrecisionAndScale EMPTY_PRECISION_AND_SCALE = new DefaultNumberPrecisionAndScale(PRECISION_NONE, SCALE_NONE); |
|
70 |
|
|
71 |
private Coercion coercion; |
|
72 |
private Class defaultClass; |
|
73 |
private String subtype; |
|
74 |
private int type; |
|
75 |
private String name; |
|
76 |
private String iconName; |
|
77 |
private int max_precision; |
|
78 |
private int default_precision; |
|
79 |
private int default_scale; |
|
80 |
private int default_size; |
|
81 |
private int flags; |
|
82 |
|
|
83 |
DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion) { |
|
84 |
this(type, subtype, name, defaultClass, coercion, "datatype-any"); |
|
85 |
} |
|
86 |
|
|
87 |
DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName) { |
|
88 |
this(type, subtype, name, defaultClass, coercion, "datatype-any", 0, PRECISION_NONE, PRECISION_NONE, SCALE_NONE); |
|
89 |
} |
|
90 |
|
|
91 |
DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName, int psflag, int max_precision, int default_precision) { |
|
92 |
this(type, subtype, name, defaultClass, coercion, "datatype-any", psflag, max_precision, default_precision, SCALE_NONE); |
|
93 |
} |
|
94 |
|
|
95 |
DefaultDataType(int type, String subtype, String name, Class defaultClass, Coercion coercion, String iconName, int flags, int max_precision, int default_precision, int default_scale) { |
|
96 |
|
|
97 |
if (name == null) { |
|
98 |
LOG.trace("Can't register null type name for type {}.", new Object[]{Integer.toHexString(type).toUpperCase()}); |
|
99 |
throw new IllegalArgumentException(); |
|
100 |
} |
|
101 |
this.type = type; |
|
102 |
this.subtype = subtype; |
|
103 |
this.name = name; |
|
104 |
this.defaultClass = defaultClass; |
|
105 |
this.coercion = coercion; |
|
106 |
this.iconName = iconName == null ? "datatype-any" : iconName; |
|
107 |
|
|
108 |
this.flags = flags; |
|
109 |
if( (this.flags&FLAG_FLOATING_POINT)==FLAG_FLOATING_POINT ) { |
|
110 |
this.flags |= FLAG_NUMBER; |
|
111 |
} |
|
112 |
if( (this.flags&FLAG_SUPPORT_PRECISION)==FLAG_SUPPORT_PRECISION ) { |
|
113 |
this.max_precision = max_precision; |
|
114 |
if( this.default_precision>max_precision ) { |
|
115 |
this.default_precision = max_precision; |
|
116 |
} else { |
|
117 |
this.default_precision = default_precision; |
|
118 |
} |
|
119 |
if( (this.flags&FLAG_SUPPORT_SCALE)==FLAG_SUPPORT_SCALE ) { |
|
120 |
if( this.default_scale>this.max_precision ) { |
|
121 |
this.default_scale = this.max_precision -1; |
|
122 |
} else { |
|
123 |
this.default_scale = default_scale; |
|
124 |
} |
|
125 |
} else { |
|
126 |
this.default_scale = SCALE_NONE; |
|
127 |
} |
|
128 |
} else { |
|
129 |
this.max_precision = PRECISION_NONE; |
|
130 |
this.default_precision = PRECISION_NONE; |
Also available in: Unified diff