Statistics
| Revision:

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

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
import org.gvsig.i18n.Messages;
40
import org.gvsig.tools.dynobject.DynClass;
41
import org.gvsig.tools.dynobject.DynField;
42
import org.gvsig.tools.dynobject.DynObject;
43

    
44

    
45
public class DynObjectViewer extends JPanel {
46

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
158
        }
159
}