Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.main / src / main / java / org / gvsig / tools / main / dynobject / DynObjectComponentAction.java @ 501

History | View | Annotate | Download (4.58 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
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynComponent;
49

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

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

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

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

    
65
    private JDynObjectComponent dynObjectView;
66

    
67
    private String dynObjectID;
68

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

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

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

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

    
97
        return mainPane;
98
    }
99

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

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

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

    
128
        getDynObjectView().saveStatus();
129

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

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

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

    
141
    private JDynObjectComponent getDynObjectView() {
142
        return this.getDynObjectView(dynObjectID);
143
    }
144

    
145
    public static void registerDynObjects() {
146
        TestDynObject.registerDynObject();
147
        Address.registerDynObject();
148
    }
149

    
150
}