root / trunk / libraries / libCq_CMS_praster / src / org / cresques / ui / raster / NameChooserDialog.java @ 8026
History | View | Annotate | Download (4.97 KB)
1 |
/*
|
---|---|
2 |
* Created on 11-ago-2006
|
3 |
*
|
4 |
*/
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
6 |
*
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
8 |
*
|
9 |
* This program is free software; you can redistribute it and/or
|
10 |
* modify it under the terms of the GNU General Public License
|
11 |
* as published by the Free Software Foundation; either version 2
|
12 |
* of the License, or (at your option) any later version.
|
13 |
*
|
14 |
* This program is distributed in the hope that it will be useful,
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
* GNU General Public License for more details.
|
18 |
*
|
19 |
* You should have received a copy of the GNU General Public License
|
20 |
* along with this program; if not, write to the Free Software
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
22 |
*/
|
23 |
package org.cresques.ui.raster; |
24 |
|
25 |
import java.awt.Dimension; |
26 |
import java.awt.FlowLayout; |
27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.GridBagLayout; |
29 |
import java.awt.Insets; |
30 |
import java.awt.Toolkit; |
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
|
34 |
import javax.swing.JButton; |
35 |
import javax.swing.JFrame; |
36 |
import javax.swing.JPanel; |
37 |
import javax.swing.JTextField; |
38 |
|
39 |
import org.cresques.ui.raster.listener.PalettePanelListener; |
40 |
import org.gvsig.i18n.Messages; |
41 |
|
42 |
/**
|
43 |
* Ventana para la selecci?n del nombre al salvar una paleta de color.
|
44 |
*
|
45 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
46 |
*
|
47 |
*/
|
48 |
|
49 |
public class NameChooserDialog extends BaseComponent implements ActionListener{ |
50 |
|
51 |
private int HBUTTONS = 30; |
52 |
private JPanel buttons = null; |
53 |
private JPanel pMain = null; |
54 |
private int width = 315, height = 115; |
55 |
private int widthMargin = 300; |
56 |
private JButton bAccept = null; |
57 |
private JButton bCancel = null; |
58 |
private JFrame window = new JFrame(); |
59 |
private JTextField tName = null; |
60 |
private PalettePanelListener listener = null; |
61 |
private PalettePanel panel = null; |
62 |
|
63 |
|
64 |
/**
|
65 |
* Constructor
|
66 |
* @param pp PalettePanel
|
67 |
*/
|
68 |
public NameChooserDialog(PalettePanel pp, PalettePanelListener listener){
|
69 |
this.panel = pp;
|
70 |
this.listener = listener;
|
71 |
|
72 |
window.getContentPane().add(getPMain()); |
73 |
init(); |
74 |
} |
75 |
|
76 |
public void init(){ |
77 |
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); |
78 |
window.setLocation( (((int)d.getWidth()) >> 1) - (width >> 1), |
79 |
(((int)d.getHeight()) >> 1) - height); |
80 |
window.setSize(width, height); |
81 |
window.setFocusable(true);
|
82 |
window.setResizable(false);
|
83 |
window.setTitle(Messages.getText("nombre_paleta"));
|
84 |
window.show(); |
85 |
} |
86 |
|
87 |
/**
|
88 |
* Obtiene el panel principal que contiene el panel de botones y cuadro
|
89 |
* de texto
|
90 |
* @return JPanel
|
91 |
*/
|
92 |
private JPanel getPMain(){ |
93 |
if(pMain == null){ |
94 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
95 |
gridBagConstraints.gridy = 0;
|
96 |
gridBagConstraints.gridx = 0;
|
97 |
gridBagConstraints.insets = new Insets (0,15,10,0); |
98 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
99 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
100 |
gridBagConstraints1.gridy = 1;
|
101 |
gridBagConstraints1.gridx = 0;
|
102 |
pMain = new JPanel(); |
103 |
pMain.setLayout(new GridBagLayout()); |
104 |
pMain.setPreferredSize(new java.awt.Dimension(widthMargin, height));
|
105 |
pMain.add(getTName(), gridBagConstraints); |
106 |
pMain.add(getPButtons(), gridBagConstraints1); |
107 |
} |
108 |
return pMain;
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* Obtiene el panel de botones
|
113 |
* @return JPanel
|
114 |
*/
|
115 |
private JPanel getPButtons(){ |
116 |
if(buttons == null){ |
117 |
buttons = new JPanel(); |
118 |
buttons.setPreferredSize(new java.awt.Dimension(widthMargin, HBUTTONS));
|
119 |
FlowLayout flowLayout = new FlowLayout(); |
120 |
flowLayout.setAlignment(java.awt.FlowLayout.RIGHT); |
121 |
flowLayout.setVgap(0);
|
122 |
flowLayout.setHgap(2);
|
123 |
buttons.setLayout(flowLayout); |
124 |
buttons.add(getBAccept(), null);
|
125 |
buttons.add(getBCancel(), null);
|
126 |
} |
127 |
return buttons;
|
128 |
} |
129 |
|
130 |
/**
|
131 |
* Obtiene el bot?n de aceptar
|
132 |
* @return JButton
|
133 |
*/
|
134 |
public JButton getBAccept(){ |
135 |
if(bAccept == null){ |
136 |
bAccept = new JButton("aceptar"); |
137 |
bAccept.addActionListener(this);
|
138 |
} |
139 |
return bAccept;
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* Obtiene el bot?n de cancelar
|
144 |
* @return JButton
|
145 |
*/
|
146 |
public JButton getBCancel(){ |
147 |
if(bCancel == null){ |
148 |
bCancel = new JButton("cancelar"); |
149 |
bCancel.addActionListener(this);
|
150 |
} |
151 |
return bCancel;
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* Al aceptar asignamos el valor cuadro de texto a la propiedad name y al cancelar cerramos la ventana
|
156 |
*/
|
157 |
public void actionPerformed(ActionEvent e) { |
158 |
if(e.getSource() == bAccept){
|
159 |
if (!getTName().getText().equals("")){ |
160 |
listener.savePalette(panel.getPalettesPath(),getTName().getText()); |
161 |
panel.getCbList().addItem(getTName().getText()); |
162 |
panel.getCbList().setSelectedItem(getTName().getText()); |
163 |
|
164 |
} |
165 |
window.hide(); |
166 |
} |
167 |
if(e.getSource() == bCancel){
|
168 |
window.hide(); |
169 |
} |
170 |
} |
171 |
|
172 |
public JFrame getWindow() { |
173 |
return window;
|
174 |
} |
175 |
|
176 |
public JTextField getTName() { |
177 |
if (tName == null){ |
178 |
tName = new JTextField(); |
179 |
tName.setPreferredSize(new Dimension(230,20)); |
180 |
} |
181 |
return tName;
|
182 |
} |
183 |
} |