Statistics
| Revision:

root / trunk / extensions / extGraph / src / org / gvsig / graph / gui / solvers / ClosestFacilityProperties.java @ 24989

History | View | Annotate | Download (5.11 KB)

1
package org.gvsig.graph.gui.solvers;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.GridLayout;
5
import java.awt.event.ActionEvent;
6
import java.awt.event.ActionListener;
7
import java.util.ArrayList;
8
import java.util.Hashtable;
9
import java.util.Iterator;
10

    
11
import javax.swing.JButton;
12
import javax.swing.JLabel;
13
import javax.swing.JPanel;
14

    
15
import com.iver.andami.PluginServices;
16
import com.iver.andami.ui.mdiManager.IWindow;
17
import com.iver.andami.ui.mdiManager.WindowInfo;
18
import com.iver.utiles.swing.JComboBox;
19

    
20
public class ClosestFacilityProperties extends JPanel implements IWindow, ActionListener {
21
    
22
        private JPanel panelMain;
23
    private JButton buttonAccept;
24
    private JButton buttonCancel;
25
    private JComboBox comboCostFieldValues;
26
    private JComboBox comboRoundValues;
27
    private JLabel labelCostField;
28
    private JLabel labelCostUnits;
29
    private JLabel labelCostUnitsValue;
30
    private JLabel labelLinesLayer;
31
    private JLabel labelLinesLayerValue;
32
    private JLabel labelRoundValues;
33
    
34
    private WindowInfo wi;
35
    private Hashtable properties;
36
        
37
    public ClosestFacilityProperties(Hashtable properties) {
38
            this.properties=properties;
39
        initComponents();
40
    }
41
    
42
    private void initComponents() {
43
        labelLinesLayer = new JLabel("Capa de l?neas:", JLabel.RIGHT);
44
        String linesLayerName=null;
45
        try{
46
                linesLayerName=(String)this.properties.get("LINES_LAYER_NAME");
47
        }
48
        catch(NullPointerException except){
49
                
50
        }
51
        if(linesLayerName==null) linesLayerName="<sin especificar>";
52
        labelLinesLayerValue = new JLabel(linesLayerName, JLabel.LEFT);
53
        labelCostField = new JLabel("Campo de coste:", JLabel.RIGHT);
54
        Iterator it=null;
55
        try{
56
                it=((ArrayList)properties.get("LAYER_FIELDS")).iterator();
57
        }
58
        catch(NullPointerException except){
59
                
60
        }
61
        comboCostFieldValues = new JComboBox();
62
        comboCostFieldValues.addItem("<Longitud de l?nea>");
63
        if(it!=null){
64
                while(it.hasNext()){
65
                        comboCostFieldValues.addItem(String.valueOf(it.next()));
66
                }
67
        }
68
        try{
69
                comboCostFieldValues.setSelectedIndex(0);
70
                String fieldName=(String)this.properties.get("COST_FIELD");
71
                if(fieldName!=null) comboCostFieldValues.setSelectedItem(fieldName);
72
        }
73
        catch(NullPointerException except){
74
                
75
        }
76
        
77
        labelCostUnits = new JLabel("Unidades de coste:", JLabel.RIGHT);
78
        labelCostUnitsValue = new JLabel("<sin especificar>", JLabel.LEFT);
79
        labelRoundValues = new JLabel("Valores redondeados a:", JLabel.RIGHT);
80
        comboRoundValues = new JComboBox();
81
        comboRoundValues.addItem("d");
82
        comboRoundValues.addItem("d.d");
83
        comboRoundValues.addItem("d.dd");
84
        comboRoundValues.addItem("d.ddd");
85
        comboRoundValues.addItem("d.dddd");
86
        comboRoundValues.addItem("d.ddddd");
87
        try{
88
                int roundValue=((Integer)this.properties.get("ROUND_VALUE")).intValue();
89
                comboRoundValues.setSelectedIndex(roundValue);
90
        }
91
        catch(IndexOutOfBoundsException except){
92

    
93
        }
94
        catch(NullPointerException except){
95
                
96
        }
97
        buttonAccept = new JButton("Aceptar");
98
        this.buttonAccept.addActionListener(this);
99
        buttonCancel = new JButton("Cancelar");
100
        this.buttonCancel.addActionListener(this);
101
        
102
        this.panelMain=new JPanel();
103
        this.panelMain.setLayout(new GridLayout(6, 2, 7, 7));
104
        this.panelMain.add(labelLinesLayer);
105
        this.panelMain.add(labelLinesLayerValue);
106
        this.panelMain.add(labelCostField);
107
        this.panelMain.add(comboCostFieldValues);
108
        this.panelMain.add(labelCostUnits);
109
        this.panelMain.add(labelCostUnitsValue);
110
        this.panelMain.add(labelRoundValues);
111
        this.panelMain.add(comboRoundValues);
112
        this.panelMain.add(new JPanel());
113
        this.panelMain.add(new JPanel());
114
        this.panelMain.add(buttonAccept);
115
        this.panelMain.add(buttonCancel);
116
        
117
        this.setLayout(new BorderLayout(50, 50));
118
        this.add(this.panelMain, BorderLayout.CENTER);
119
    }
120
    
121
    public Hashtable getProperties(){
122
            return this.properties;
123
    }
124
    
125
        public WindowInfo getWindowInfo() {
126
                if(this.wi==null){
127
                        this.wi=new WindowInfo(WindowInfo.MODALDIALOG);
128
                        this.wi.setTitle("Propiedades");
129
                        this.wi.setWidth(300);
130
                        this.wi.setHeight(150);
131
                }
132
                
133
                return wi;
134
        }
135
        
136
        public Object getWindowProfile(){
137
                return WindowInfo.DIALOG_PROFILE;
138
        }
139

    
140
        public void actionPerformed(ActionEvent e) {
141
                if(e.getSource()==this.buttonAccept){
142
                        String costFieldName=null;
143
                        try{
144
                                costFieldName=(String)this.comboCostFieldValues.getSelectedItem();
145
                                this.properties.put("COST_FIELD", costFieldName);
146
                        }
147
                        catch(NullPointerException except){
148
                                
149
                        }
150
                        try{
151
                                this.properties.put("ROUND_VALUE", Integer.valueOf(this.comboRoundValues.getSelectedIndex()));
152
                        }
153
                        catch(NullPointerException except){
154
                                
155
                        }
156
                        PluginServices.getMDIManager().closeWindow(this);
157
                }
158
                else if(e.getSource()==this.buttonCancel){
159
                        PluginServices.getMDIManager().closeWindow(this);
160
                }
161
        }
162
}