Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / table / gui / ComplexValuePanel.java @ 24986

History | View | Annotate | Download (6.4 KB)

1
package com.iver.cit.gvsig.project.documents.table.gui;
2

    
3
import java.awt.Color;
4
import java.awt.Dimension;
5
import java.awt.FlowLayout;
6
import java.awt.Insets;
7
import java.awt.event.ActionEvent;
8
import java.awt.event.ActionListener;
9
import java.util.Iterator;
10
import java.util.Map;
11

    
12
import javax.swing.BoxLayout;
13
import javax.swing.JPanel;
14
import javax.swing.JScrollPane;
15
import javax.swing.JTextField;
16

    
17
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
18
import org.gvsig.gui.beans.swing.JButton;
19

    
20
import com.hardcode.gdbms.engine.values.ComplexValue;
21
import com.hardcode.gdbms.engine.values.Value;
22
import com.iver.andami.PluginServices;
23
import com.iver.andami.ui.mdiManager.IWindow;
24
import com.iver.andami.ui.mdiManager.WindowInfo;
25

    
26
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
27
 *
28
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
29
 *
30
 * This program is free software; you can redistribute it and/or
31
 * modify it under the terms of the GNU General Public License
32
 * as published by the Free Software Foundation; either version 2
33
 * of the License, or (at your option) any later version.
34
 *
35
 * This program is distributed in the hope that it will be useful,
36
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38
 * GNU General Public License for more details.
39
 *
40
 * You should have received a copy of the GNU General Public License
41
 * along with this program; if not, write to the Free Software
42
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
43
 *
44
 * For more information, contact:
45
 *
46
 *  Generalitat Valenciana
47
 *   Conselleria d'Infraestructures i Transport
48
 *   Av. Blasco Ib??ez, 50
49
 *   46010 VALENCIA
50
 *   SPAIN
51
 *
52
 *      +34 963862235
53
 *   gvsig@gva.es
54
 *      www.gvsig.gva.es
55
 *
56
 *    or
57
 *
58
 *   IVER T.I. S.A
59
 *   Salamanca 50
60
 *   46005 Valencia
61
 *   Spain
62
 *
63
 *   +34 963163400
64
 *   dac@iver.es
65
 */
66
/* CVS MESSAGES:
67
 *
68
 * $Id: ComplexValuePanel.java 24986 2008-11-12 12:02:30Z jcampos $
69
 * $Log$
70
 * Revision 1.4  2007-01-10 12:43:26  jorpiell
71
 * The panel for a complexFeature is not editable
72
 *
73
 * Revision 1.3  2006/11/01 17:26:56  jorpiell
74
 * La ventana se reajusta en tama?o dependiendo de la feature compleja
75
 *
76
 * Revision 1.2  2006/10/11 16:28:19  jorpiell
77
 * A?adido un bot?n para cerrar la ventana
78
 *
79
 * Revision 1.1  2006/10/11 08:30:09  jorpiell
80
 * Panel usado para representar features complejas
81
 *
82
 *
83
 */
84
/**
85
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
86
 */
87
public class ComplexValuePanel extends JPanel implements IWindow{
88
        private ComplexValue value = null;
89
        private String name = null;
90
        private WindowInfo m_windowInfo = null;
91
        private JButton closeButton = null;
92
        private JPanel buttonsPanel = null;
93
        private JScrollPane scroll = null;
94
        private GridBagLayoutPanel complexPanel = null;        
95
        
96
        public ComplexValuePanel(String name,ComplexValue value) {
97
                super();
98
                this.value = value;
99
                this.name = name;
100
                initialize();        
101
        }
102
        
103
        /**
104
         * This method initializes this
105
         * 
106
         */
107
        private void initialize() {
108
                this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
109
                this.add(getScrollPane());
110
                this.add(getButtonPanel());
111
        }
112
        
113
        private JScrollPane getScrollPane(){
114
                if (scroll == null){
115
                        scroll = new JScrollPane();
116
                        complexPanel = createLevelPanel(name,value);
117
                        Dimension dim = complexPanel.getPreferredSize();
118
                        int widht,heigth = 0;
119
                        if (dim.getHeight()>500){
120
                                heigth = 500;
121
                        }else{
122
                                heigth = new Double(dim.getHeight()).intValue() + 10;
123
                        }
124
                        if (dim.getWidth()>500){
125
                                widht = 500;
126
                        }else{
127
                                widht = new Double(dim.getWidth()).intValue() + 10;
128
                        }
129
                        scroll.setPreferredSize(new Dimension(widht,heigth));
130
                        scroll.setViewportView(complexPanel);
131
                }
132
                return scroll;
133
        }
134
        
135
        /**
136
         * Create a new panel with a row (label + text field)
137
         * by each geometry attribute.
138
         * If one attribute is a complexValue it creates a new
139
         * panel recursively
140
         * @param name
141
         * Param name
142
         * @param map
143
         * Map with the attributes
144
         * @return
145
         */
146
        private GridBagLayoutPanel createLevelPanel(String name,Map map){
147
                GridBagLayoutPanel panel = new GridBagLayoutPanel();
148
                panel.setBorder(javax.swing.BorderFactory.createTitledBorder(
149
                                null, null,
150
                                javax.swing.border.TitledBorder.LEFT,
151
                                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
152
                Iterator keys = map.keySet().iterator();
153
                while (keys.hasNext()){
154
                        String param = (String)keys.next();
155
                        Value value = (Value)map.get(param);
156
                        if (!(value instanceof ComplexValue)){
157
                                JTextField tf = new JTextField(value.toString(),30);
158
                                tf.setEditable(false);
159
                                tf.setBackground(Color.WHITE);
160
                                panel.addComponent(param,
161
                                                tf,new Insets(1,0,1,0));
162
                        }else{
163
                                panel.addComponent(param,
164
                                                createLevelPanel(param,(ComplexValue)value),new Insets(1,0,1,0));
165
                        }
166
                }
167
                return panel;
168
        }
169
        
170
        /*
171
         *  (non-Javadoc)
172
         * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
173
         */
174
        public WindowInfo getWindowInfo() {
175
                if (m_windowInfo == null){
176
                        m_windowInfo = new WindowInfo(WindowInfo.MODALDIALOG);
177
                        m_windowInfo.setTitle(name);
178
                        Dimension dim = getComponent(0).getPreferredSize();
179
                        int widht,heigth = 0;
180
                        if (dim.getHeight()>500){
181
                                heigth = 500 + 15;
182
                        }else{
183
                                heigth = new Double(dim.getHeight()).intValue() + 15;
184
                        }
185
                        if (dim.getWidth()>500){
186
                                widht = 500 + 5;
187
                        }else{
188
                                widht = new Double(dim.getWidth()).intValue() + 5;
189
                        }
190
                        m_windowInfo.setWidth(widht);
191
                        m_windowInfo.setHeight(heigth);
192
                }
193
                return m_windowInfo;
194
        }        
195
        
196
        /**
197
         * Gets the panel where are all the buttons
198
         * 
199
         * 
200
         * @return JPanel
201
         */
202
        public JPanel getButtonPanel() {        
203
                if (buttonsPanel == null) {
204
                        FlowLayout flowLayout = new FlowLayout();
205
                        flowLayout.setAlignment(FlowLayout.RIGHT);
206
                        buttonsPanel = new JPanel(flowLayout);
207
                        buttonsPanel.add(getCloseButton(),null);                                
208
                }
209
                return buttonsPanel;
210
        } 
211
        
212
        /**
213
         * It gets the close button
214
         * @return 
215
         */
216
        public JButton getCloseButton() {        
217
                if (closeButton == null) {
218
                        closeButton = new JButton(PluginServices.getText(this,"close"));
219
                        closeButton.setPreferredSize(new Dimension(80, 23));
220
                        closeButton.setActionCommand("cerrar");
221
                        closeButton.addActionListener(new ActionListener(){
222
                                public void actionPerformed(ActionEvent e) {
223
                                        closeJDialog();
224
                                }                                
225
                        });
226
                }
227
                return closeButton;
228
        } 
229
        
230
        /**
231
         * Closes the dialog
232
         */
233
        private void closeJDialog(){
234
                PluginServices.getMDIManager().closeWindow(this);
235
        }
236

    
237
        public Object getWindowProfile() {
238
                return WindowInfo.DIALOG_PROFILE;
239
        }
240
        
241
}  //  @jve:decl-index=0:visual-constraint="10,10"