svn-gvsig-desktop / tags / v1_1_Build_1000 / libraries / libCq_CMS_praster / src / org / cresques / ui / raster / NameChooserDialog.java @ 11885
History | View | Annotate | Download (5.13 KB)
1 | 8026 | nacho | /*
|
---|---|---|---|
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 | 10645 | nacho | if(panel.getCbList().getSelectedIndex() != 0) |
86 | getTName().setText(panel.getCbList().getSelectedItem().toString()); |
||
87 | else
|
||
88 | getTName().setText("Default Name");
|
||
89 | 8026 | nacho | } |
90 | |||
91 | /**
|
||
92 | * Obtiene el panel principal que contiene el panel de botones y cuadro
|
||
93 | * de texto
|
||
94 | * @return JPanel
|
||
95 | */
|
||
96 | private JPanel getPMain(){ |
||
97 | if(pMain == null){ |
||
98 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
||
99 | gridBagConstraints.gridy = 0;
|
||
100 | gridBagConstraints.gridx = 0;
|
||
101 | gridBagConstraints.insets = new Insets (0,15,10,0); |
||
102 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
103 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
||
104 | gridBagConstraints1.gridy = 1;
|
||
105 | gridBagConstraints1.gridx = 0;
|
||
106 | pMain = new JPanel(); |
||
107 | pMain.setLayout(new GridBagLayout()); |
||
108 | pMain.setPreferredSize(new java.awt.Dimension(widthMargin, height));
|
||
109 | pMain.add(getTName(), gridBagConstraints); |
||
110 | pMain.add(getPButtons(), gridBagConstraints1); |
||
111 | } |
||
112 | return pMain;
|
||
113 | } |
||
114 | |||
115 | /**
|
||
116 | * Obtiene el panel de botones
|
||
117 | * @return JPanel
|
||
118 | */
|
||
119 | private JPanel getPButtons(){ |
||
120 | if(buttons == null){ |
||
121 | buttons = new JPanel(); |
||
122 | buttons.setPreferredSize(new java.awt.Dimension(widthMargin, HBUTTONS));
|
||
123 | FlowLayout flowLayout = new FlowLayout(); |
||
124 | flowLayout.setAlignment(java.awt.FlowLayout.RIGHT); |
||
125 | flowLayout.setVgap(0);
|
||
126 | flowLayout.setHgap(2);
|
||
127 | buttons.setLayout(flowLayout); |
||
128 | buttons.add(getBAccept(), null);
|
||
129 | buttons.add(getBCancel(), null);
|
||
130 | } |
||
131 | return buttons;
|
||
132 | } |
||
133 | |||
134 | /**
|
||
135 | * Obtiene el bot?n de aceptar
|
||
136 | * @return JButton
|
||
137 | */
|
||
138 | public JButton getBAccept(){ |
||
139 | if(bAccept == null){ |
||
140 | bAccept = new JButton("aceptar"); |
||
141 | bAccept.addActionListener(this);
|
||
142 | } |
||
143 | return bAccept;
|
||
144 | } |
||
145 | |||
146 | /**
|
||
147 | * Obtiene el bot?n de cancelar
|
||
148 | * @return JButton
|
||
149 | */
|
||
150 | public JButton getBCancel(){ |
||
151 | if(bCancel == null){ |
||
152 | bCancel = new JButton("cancelar"); |
||
153 | bCancel.addActionListener(this);
|
||
154 | } |
||
155 | return bCancel;
|
||
156 | } |
||
157 | |||
158 | /**
|
||
159 | * Al aceptar asignamos el valor cuadro de texto a la propiedad name y al cancelar cerramos la ventana
|
||
160 | */
|
||
161 | public void actionPerformed(ActionEvent e) { |
||
162 | if(e.getSource() == bAccept){
|
||
163 | if (!getTName().getText().equals("")){ |
||
164 | listener.savePalette(panel.getPalettesPath(),getTName().getText()); |
||
165 | panel.getCbList().addItem(getTName().getText()); |
||
166 | panel.getCbList().setSelectedItem(getTName().getText()); |
||
167 | |||
168 | } |
||
169 | window.hide(); |
||
170 | } |
||
171 | if(e.getSource() == bCancel){
|
||
172 | window.hide(); |
||
173 | } |
||
174 | } |
||
175 | |||
176 | public JFrame getWindow() { |
||
177 | return window;
|
||
178 | } |
||
179 | |||
180 | public JTextField getTName() { |
||
181 | if (tName == null){ |
||
182 | tName = new JTextField(); |
||
183 | tName.setPreferredSize(new Dimension(230,20)); |
||
184 | } |
||
185 | return tName;
|
||
186 | } |
||
187 | } |