Revision 32437

View differences:

branches/v2_0_0_prep/extensions/org.gvsig.arcims.feature.extension/src/main/java/org/gvsig/arcims/feature/gui/panels/utils/ImageFormatSelector.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Prodevelop Integraci?n de Tecnolog?as SL
34
 *   Conde Salvatierra de ?lava , 34-10
35
 *   46004 Valencia
36
 *   Spain
37
 *
38
 *   +34 963 510 612
39
 *   +34 963 510 968
40
 *   gis@prodevelop.es
41
 *   http://www.prodevelop.es
42
 */
43
package org.gvsig.arcims.feature.gui.panels.utils;
44

  
45
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionListener;
47

  
48
import javax.swing.ButtonGroup;
49
import javax.swing.JPanel;
50
import javax.swing.JRadioButton;
51
import javax.swing.event.ChangeEvent;
52
import javax.swing.event.ChangeListener;
53

  
54

  
55

  
56
public class ImageFormatSelector extends JPanel implements ChangeListener {
57
    private JRadioButton jpgRB;
58
    private JRadioButton gifRB;
59
    private JRadioButton png8RB;
60
    private JRadioButton png24RB;
61
    private ButtonGroup formatBG;
62
    private ActionListener listener;
63

  
64
    public ImageFormatSelector() {
65
        jpgRB = new JRadioButton("JPG", true);
66
        jpgRB.addChangeListener(this);
67
        jpgRB.setBounds(10, 0, 60, 20);
68

  
69
        gifRB = new JRadioButton("GIF", false);
70
        gifRB.addChangeListener(this);
71
        gifRB.setBounds(70, 0, 60, 20);
72

  
73
        png8RB = new JRadioButton("PNG8", false);
74
        png8RB.addChangeListener(this);
75
        png8RB.setBounds(130, 0, 60, 20);
76

  
77
        png24RB = new JRadioButton("PNG24", false);
78
        png24RB.addChangeListener(this);
79
        png24RB.setBounds(190, 0, 60, 20); // llega hasta 10 + 4 * 60 = 250
80

  
81
        formatBG = new ButtonGroup();
82

  
83
        formatBG.add(jpgRB);
84
        formatBG.add(gifRB);
85
        formatBG.add(png8RB);
86
        formatBG.add(png24RB);
87

  
88
        setLayout(null);
89
        setBounds(15, 23, 260, 20);
90

  
91
        add(jpgRB);
92
        add(gifRB);
93
        add(png8RB);
94
        add(png24RB);
95
    }
96

  
97
    public void setSelected(String format) {
98
        setAll(false);
99

  
100
        if (format.compareToIgnoreCase(jpgRB.getText()) == 0) {
101
            jpgRB.setSelected(true);
102
        }
103

  
104
        if (format.compareToIgnoreCase(gifRB.getText()) == 0) {
105
            gifRB.setSelected(true);
106
        }
107

  
108
        if (format.compareToIgnoreCase(png8RB.getText()) == 0) {
109
            png8RB.setSelected(true);
110
        }
111

  
112
        if (format.compareToIgnoreCase(png24RB.getText()) == 0) {
113
            png24RB.setSelected(true);
114
        }
115
    }
116

  
117
    public String getSelected() {
118
        if (jpgRB.isSelected()) {
119
            return jpgRB.getText();
120
        }
121

  
122
        if (gifRB.isSelected()) {
123
            return gifRB.getText();
124
        }
125

  
126
        if (png8RB.isSelected()) {
127
            return png8RB.getText();
128
        }
129

  
130
        if (png24RB.isSelected()) {
131
            return png24RB.getText();
132
        }
133

  
134
        return "";
135
    }
136

  
137
    private void setAll(boolean selected) {
138
        jpgRB.setSelected(selected);
139
        gifRB.setSelected(selected);
140
        png8RB.setSelected(selected);
141
        png24RB.setSelected(selected);
142
    }
143

  
144
    public void setAllEnabled(boolean enabled) {
145
        jpgRB.setEnabled(enabled);
146
        gifRB.setEnabled(enabled);
147
        png8RB.setEnabled(enabled);
148
        png24RB.setEnabled(enabled);
149
    }
150

  
151
    public void setThisEnabled(String format) {
152
        if (format.compareToIgnoreCase(jpgRB.getText()) == 0) {
153
            jpgRB.setEnabled(true);
154
        }
155

  
156
        if (format.compareToIgnoreCase(gifRB.getText()) == 0) {
157
            gifRB.setEnabled(true);
158
        }
159

  
160
        if (format.compareToIgnoreCase(png8RB.getText()) == 0) {
161
            png8RB.setEnabled(true);
162
        }
163

  
164
        if (format.compareToIgnoreCase(png24RB.getText()) == 0) {
165
            png24RB.setEnabled(true);
166
        }
167
    }
168

  
169
    public void addListener(ImageServicePanel panel) {
170
        listener = panel;
171
    }
172

  
173
    public void stateChanged(ChangeEvent arg0) {
174
        if (listener != null) {
175
            ActionEvent ae = new ActionEvent(this,
176
                    ActionEvent.ACTION_PERFORMED, "");
177
            listener.actionPerformed(ae);
178
        }
179
    }
180
}

Also available in: Unified diff