gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.main / src / main / java / org / gvsig / tools / main / dynobject / DynObjectComponentAction.java @ 230
History | View | Annotate | Download (3.86 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2010 {} {{Task}}
|
26 |
*/
|
27 |
package org.gvsig.tools.main.dynobject; |
28 |
|
29 |
import java.awt.BorderLayout; |
30 |
import java.awt.Component; |
31 |
import java.awt.Dimension; |
32 |
import java.awt.event.ActionEvent; |
33 |
import java.awt.event.ActionListener; |
34 |
|
35 |
import javax.swing.JButton; |
36 |
import javax.swing.JComponent; |
37 |
import javax.swing.JFrame; |
38 |
import javax.swing.JPanel; |
39 |
import javax.swing.JTabbedPane; |
40 |
|
41 |
import org.gvsig.tools.ToolsLocator; |
42 |
import org.gvsig.tools.dynobject.DynObjectManager; |
43 |
import org.gvsig.tools.main.MainAction; |
44 |
import org.gvsig.tools.service.ServiceException; |
45 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
46 |
import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager; |
47 |
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent; |
48 |
|
49 |
/**
|
50 |
* Action used to show the DynObject components panel
|
51 |
*
|
52 |
* @author 2010- C?sar Ordi?ana - gvSIG team
|
53 |
*/
|
54 |
public class DynObjectComponentAction extends MainAction { |
55 |
|
56 |
private static final long serialVersionUID = -3386010046112585198L; |
57 |
|
58 |
private static DynObjectManager dynManager = ToolsLocator |
59 |
.getDynObjectManager(); |
60 |
|
61 |
private static DynObjectSwingManager swingManager = ToolsSwingLocator |
62 |
.getDynObjectSwingManager(); |
63 |
|
64 |
/**
|
65 |
* @see MainAction#MainAction(JTabbedPane)
|
66 |
*/
|
67 |
public DynObjectComponentAction(JTabbedPane tabbedPane) { |
68 |
super("DynObject", tabbedPane); |
69 |
putValue(SHORT_DESCRIPTION, "DynObject viewer components");
|
70 |
registerDynObjects(); |
71 |
} |
72 |
|
73 |
public void registerDynObjects() { |
74 |
TestDynObject.registerDynObject(); |
75 |
Address.registerDynObject(); |
76 |
} |
77 |
|
78 |
@Override
|
79 |
protected JComponent createComponent() { |
80 |
final JDynObjectComponent dynObjectView;
|
81 |
JPanel mainPane = new JPanel(new BorderLayout()); |
82 |
dynObjectView = getDynObjectView(); |
83 |
if (dynObjectView == null) |
84 |
return mainPane;
|
85 |
|
86 |
JComponent component = dynObjectView.getJComponent();
|
87 |
mainPane.add(component, BorderLayout.CENTER);
|
88 |
component.setPreferredSize(new Dimension(100, 100)); |
89 |
JButton button = new JButton("Save"); |
90 |
button.addActionListener(new ActionListener() { |
91 |
public void actionPerformed(ActionEvent e) { |
92 |
launchNewFrame(dynObjectView); |
93 |
} |
94 |
}); |
95 |
mainPane.add(button, BorderLayout.SOUTH);
|
96 |
|
97 |
return mainPane;
|
98 |
} |
99 |
|
100 |
/**
|
101 |
* @return
|
102 |
*/
|
103 |
private JDynObjectComponent getDynObjectView() {
|
104 |
try {
|
105 |
TestDynObject testDynObject = (TestDynObject) dynManager |
106 |
.get("Test");
|
107 |
return swingManager.createJDynObjectComponent(testDynObject
|
108 |
.createDynObject(), testDynObject.createDynModel()); |
109 |
} catch (ServiceException e) {
|
110 |
return null; |
111 |
} |
112 |
} |
113 |
|
114 |
@Override
|
115 |
protected String getComponentTitle() { |
116 |
return "DynObject"; |
117 |
} |
118 |
|
119 |
/**
|
120 |
* @param dynObjectView
|
121 |
*/
|
122 |
protected void launchNewFrame(JDynObjectComponent dynObjectView) { |
123 |
|
124 |
dynObjectView.saveStatus(); |
125 |
|
126 |
final JFrame frame = new JFrame("Tools swing components test app"); |
127 |
// frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
128 |
|
129 |
frame.getContentPane().add( |
130 |
(Component) getDynObjectView().getJComponent());
|
131 |
|
132 |
// Display the window.
|
133 |
frame.pack(); |
134 |
frame.setVisible(true);
|
135 |
} |
136 |
|
137 |
} |