Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / decisiontrees / gui / ClassEditorPanel.java @ 17773

History | View | Annotate | Download (4.22 KB)

1
package org.gvsig.remotesensing.decisiontrees.gui;
2

    
3
import java.awt.Color;
4
import java.awt.Dimension;
5
import java.awt.GridBagConstraints;
6
import java.awt.GridBagLayout;
7
import java.awt.Insets;
8

    
9
import javax.swing.JButton;
10
import javax.swing.JLabel;
11
import javax.swing.JTextField;
12

    
13
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
14
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
15
import org.gvsig.remotesensing.decisiontrees.DecisionTreeNode;
16
import org.gvsig.remotesensing.decisiontrees.gui.listener.ClassEditorPanelListener;
17
import org.jgraph.graph.DefaultGraphCell;
18
import org.jgraph.graph.GraphConstants;
19

    
20
import com.iver.andami.PluginServices;
21

    
22
public class ClassEditorPanel extends DefaultButtonsPanel {
23

    
24
        /**
25
         * 
26
         */
27
        private static final long serialVersionUID = 313490261946450414L;
28
        
29
        private ClassEditorDialog                         classEditorDialog         = null;
30
        private JLabel                                                jLabelName                        = null;
31
        private JLabel                                                jLabelValue                        = null;
32
        private JLabel                                                jLabelColor                 = null;
33
        private JTextField                                        jtextColor                         = null;
34
        private JTextField                                        jtextValue                        = null;
35
        private JButton                                                jButtonColor                = null;
36
        private ClassEditorPanelListener         listener                         = null;
37
        private DecisionTreePanel                         decisionTreePanel = null;
38
        
39

    
40
        public ClassEditorPanel(ClassEditorDialog classEditorDialog, DecisionTreePanel decisionTreePanel) {
41
                super(ButtonsPanel.BUTTONS_ACCEPTCANCEL);
42
                this.classEditorDialog = classEditorDialog;
43
                this.decisionTreePanel = decisionTreePanel;
44
                initialize();
45
        }
46

    
47
        private void initialize() {
48
                setLayout(new GridBagLayout());
49
                GridBagConstraints constraints = new GridBagConstraints();
50
                constraints.gridx=0;
51
                constraints.gridy=0;
52
                constraints.anchor = GridBagConstraints.WEST;
53
                add(getJLabelName(),constraints);
54
                constraints.gridx=0;
55
                constraints.gridy=1;
56
                constraints.anchor = GridBagConstraints.WEST;
57
                add(getJLabelValue(),constraints);
58
                constraints.gridx=0;
59
                constraints.gridy=2;
60
                constraints.anchor = GridBagConstraints.WEST;
61
                add(getJLabelColor(),constraints);
62
                constraints.gridx=1;
63
                constraints.gridy=0;
64
                constraints.insets = new Insets(3,3,3,3);
65
                constraints.fill = GridBagConstraints.HORIZONTAL;
66
                constraints.gridwidth = GridBagConstraints.REMAINDER;
67
                add(getJtextColor(),constraints);
68
                constraints.gridx=1;
69
                constraints.gridy=1;
70
                constraints.insets = new Insets(3,3,3,3);
71
                constraints.fill = GridBagConstraints.HORIZONTAL;
72
                constraints.gridwidth = GridBagConstraints.REMAINDER;
73
                add(getJtextValue(),constraints);
74
                constraints.gridx=1;
75
                constraints.gridy=2;
76
                constraints.insets = new Insets(3,3,3,3);
77
                constraints.fill = GridBagConstraints.HORIZONTAL;
78
                constraints.gridwidth = GridBagConstraints.REMAINDER;
79
                add(getJButtonColor(),constraints);
80
                
81
                listener  = new ClassEditorPanelListener(this);
82
                getJButtonColor().addActionListener(listener);
83
                addButtonPressedListener(listener);
84
        }
85

    
86
        public ClassEditorDialog getClassEditorDialog() {
87
                return classEditorDialog;
88
        }
89

    
90
        public JTextField getJtextColor() {
91
                if (jtextColor == null)
92
                        jtextColor = new JTextField();
93
                return jtextColor;
94
        }
95

    
96
        public JButton getJButtonColor() {
97
                if (jButtonColor == null){
98
                        jButtonColor = new JButton();
99
                        DefaultGraphCell cell = getDecisionTreePanel().getSelectedCell();
100
                        Color color = GraphConstants.getBackground(cell.getAttributes());
101
                        jButtonColor.setBackground(color);
102
                        jButtonColor.setPreferredSize(new Dimension(60, 20));
103
                }
104
                return jButtonColor;
105
        }
106

    
107
        public JLabel getJLabelColor() {
108
                if (jLabelColor == null)
109
                        jLabelColor = new JLabel(PluginServices.getText(this,"class_color")+":");
110
                return jLabelColor;
111
        }
112

    
113
        public JLabel getJLabelName() {
114
                if (jLabelName == null)
115
                        jLabelName = new JLabel(PluginServices.getText(this, "nombre")+":");
116
                return jLabelName;
117
        }
118

    
119
        public JLabel getJLabelValue() {
120
                if (jLabelValue == null)
121
                        jLabelValue = new JLabel(PluginServices.getText(this,"valor")+":");
122
                return jLabelValue;
123
        }
124

    
125
        public JTextField getJtextValue() {
126
                if (jtextValue == null){
127
                        jtextValue = new  JTextField();
128
                        DefaultGraphCell cell = getDecisionTreePanel().getSelectedCell();
129
                        DecisionTreeNode node = (DecisionTreeNode)cell.getUserObject();
130
                        jtextValue.setText(String.valueOf(node.getClassID()));
131
                }
132
                return jtextValue;
133
        }
134

    
135
        public DecisionTreePanel getDecisionTreePanel() {
136
                return decisionTreePanel;
137
        }
138
}