Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / swing / dynobject / DynObjectViewer.java @ 37530

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
* 2009 IVER T.I. S.A.   {{Task}}
26
*/
27

    
28
package org.gvsig.fmap.mapcontrol.swing.dynobject;
29

    
30
import java.awt.Color;
31
import java.awt.GridBagConstraints;
32
import java.awt.GridBagLayout;
33

    
34
import javax.swing.JLabel;
35
import javax.swing.JPanel;
36
import javax.swing.JTextField;
37

    
38
import org.cresques.cts.IProjection;
39

    
40
import org.gvsig.i18n.Messages;
41
import org.gvsig.tools.dynobject.DynClass;
42
import org.gvsig.tools.dynobject.DynField;
43
import org.gvsig.tools.dynobject.DynObject;
44

    
45

    
46
public class DynObjectViewer extends JPanel {
47

    
48
        /**
49
         *
50
         */
51
        private static final long serialVersionUID = -5277036770491043233L;
52
        private GridBagConstraints paramsListLabelConstraint;
53
        private GridBagConstraints paramsListValueConstraint;
54
        private GridBagConstraints paramsListFillConstraint;
55

    
56
        public DynObjectViewer() {
57
                super();
58
                this.intialize();
59
        }
60

    
61
        private void intialize() {
62
                this.setLayout(new GridBagLayout());
63

    
64
                paramsListLabelConstraint = new GridBagConstraints();
65
                paramsListValueConstraint = new GridBagConstraints();
66
                paramsListFillConstraint = new GridBagConstraints();
67

    
68
                paramsListLabelConstraint.ipadx = 3;
69
                paramsListLabelConstraint.ipady = 3;
70
                paramsListLabelConstraint.anchor = GridBagConstraints.FIRST_LINE_START;
71
                paramsListLabelConstraint.gridwidth = GridBagConstraints.RELATIVE;
72
                paramsListLabelConstraint.fill = GridBagConstraints.HORIZONTAL;
73
                paramsListLabelConstraint.weightx = 0.5;
74

    
75
                paramsListValueConstraint.ipadx = 3;
76
                paramsListValueConstraint.ipady = 3;
77
                paramsListValueConstraint.anchor = GridBagConstraints.FIRST_LINE_END;
78
                paramsListValueConstraint.gridwidth = GridBagConstraints.REMAINDER;
79
                paramsListValueConstraint.fill = GridBagConstraints.HORIZONTAL;
80
                paramsListValueConstraint.weightx = 0.5;
81

    
82
                paramsListFillConstraint.ipadx = 3;
83
                paramsListFillConstraint.ipady = 3;
84
                paramsListFillConstraint.anchor = GridBagConstraints.FIRST_LINE_END;
85
                paramsListFillConstraint.gridwidth = GridBagConstraints.REMAINDER;
86
                paramsListFillConstraint.fill = GridBagConstraints.BOTH;
87
                paramsListFillConstraint.weightx = 1;
88
                paramsListFillConstraint.weighty = 1;
89
        }
90

    
91
        private String getLocalizedText(String txt) {
92
                try {
93
                        return Messages.getText(txt);
94
                } catch (Exception e) {
95
                        return txt;
96
                }
97
        }
98

    
99
        public void load(DynObject dynObj) {
100
                this.removeAll();
101

    
102
                if (dynObj == null) {
103
                        this.doLayout();
104
                        return;
105
                }
106
                DynClass dynClass = dynObj.getDynClass();
107

    
108
                JTextField label;
109
                JTextField text;
110
                Object value;
111
                String strValue;
112

    
113
                //                label = new JLabel();
114
                //                label.setText(getLocalizedText("parameter"));
115
                //                label.setBackground(Color.LIGHT_GRAY);
116
                //                this.add(label, paramsListLabelConstraint);
117

    
118
                text = new JTextField();
119
                text.setText(getLocalizedText("parameter"));
120
                text.setEditable(false);
121
                text.setBackground(Color.LIGHT_GRAY);
122
                this.add(text, paramsListLabelConstraint);
123

    
124
                text = new JTextField();
125
                text.setText(getLocalizedText("value"));
126
                text.setEditable(false);
127
                text.setBackground(Color.LIGHT_GRAY);
128
                this.add(text, paramsListValueConstraint);
129

    
130
                for (DynField field : dynClass.getDynFields()) {
131
                        label = new JTextField();
132
                        label.setText(field.getDescription());
133
                        label.setEditable(false);
134
                        this.add(label, paramsListLabelConstraint);
135

    
136
                        strValue = "";
137
                        value = dynObj.getDynValue(field.getName());
138
                        if (value != null) {
139
                                if (value instanceof String) {
140
                                        strValue = (String) value;
141
                                } else if (value instanceof IProjection) {
142
                                        strValue = ((IProjection) value).getAbrev();
143
                                } else {
144
                                        strValue = value.toString();
145
                                }
146

    
147
                        }
148
                        text = new JTextField();
149
                        text.setText(strValue);
150
                        text.setEditable(false);
151
                        this.add(text, paramsListValueConstraint);
152
                }
153

    
154
                this.add(new JLabel(), paramsListFillConstraint);
155

    
156
                this.doLayout();
157
                this.repaint();
158

    
159
        }
160
}