gvsig-raster / org.gvsig.raster.multifile / trunk / org.gvsig.raster.multifile / org.gvsig.raster.multifile.app.multifileclient / src / main / java / org / gvsig / raster / multifile / app / panel / LayerNameDialog.java @ 1942
History | View | Annotate | Download (5.09 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. 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 |
package org.gvsig.raster.multifile.app.panel; |
20 |
|
21 |
import java.awt.BorderLayout; |
22 |
import java.awt.GridBagConstraints; |
23 |
import java.awt.GridBagLayout; |
24 |
import java.awt.Insets; |
25 |
import java.awt.geom.Point2D; |
26 |
|
27 |
import javax.swing.JOptionPane; |
28 |
import javax.swing.JPanel; |
29 |
import javax.swing.JTextField; |
30 |
|
31 |
import org.gvsig.andami.PluginServices; |
32 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
33 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
34 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
35 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
36 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
37 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
38 |
import org.gvsig.i18n.Messages; |
39 |
|
40 |
/**
|
41 |
* <code>LayerNameDialog</code>.
|
42 |
* Window to introduce the name of the new layer
|
43 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
44 |
*/
|
45 |
public class LayerNameDialog extends DefaultButtonsPanel implements IWindow, ButtonsPanelListener { |
46 |
private static final long serialVersionUID = 7362459094802955247L; |
47 |
private JPanel panel = null; |
48 |
private String layerName = null; |
49 |
private JTextField name = null; |
50 |
private ButtonsPanelListener listener = null; |
51 |
private Point2D position = null; |
52 |
|
53 |
/**
|
54 |
* Builds a new window.
|
55 |
* @param width
|
56 |
* @param height
|
57 |
*/
|
58 |
public LayerNameDialog(Point2D position, int width, int height, ButtonsPanelListener listener) { |
59 |
super(ButtonsPanel.BUTTONS_ACCEPTCANCEL);
|
60 |
this.position = position;
|
61 |
layerName = null;
|
62 |
this.listener = listener;
|
63 |
this.setSize(width, height);
|
64 |
this.setLayout(new BorderLayout(5, 5)); |
65 |
this.add(getMainPanel(), java.awt.BorderLayout.CENTER);
|
66 |
this.addButtonPressedListener(this); |
67 |
} |
68 |
|
69 |
/**
|
70 |
* Gets the main panel
|
71 |
* @return JPanel
|
72 |
*/
|
73 |
public JPanel getMainPanel() { |
74 |
if (panel == null) { |
75 |
panel = new JPanel(); |
76 |
panel.setLayout(new GridBagLayout()); |
77 |
GridBagConstraints gbc = new GridBagConstraints(); |
78 |
gbc.insets = new Insets(0, 0, 0, 0); |
79 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
80 |
gbc.anchor = GridBagConstraints.CENTER;
|
81 |
gbc.weightx = 1.0;
|
82 |
panel.add(getNameField(), gbc); |
83 |
} |
84 |
return panel;
|
85 |
} |
86 |
|
87 |
private JTextField getNameField() { |
88 |
if(name == null) { |
89 |
name = new JTextField(); |
90 |
} |
91 |
return name;
|
92 |
} |
93 |
|
94 |
/*
|
95 |
* (non-Javadoc)
|
96 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
97 |
*/
|
98 |
public WindowInfo getWindowInfo() {
|
99 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
100 |
m_viewinfo.setTitle(Messages.getText("layer_name"));
|
101 |
m_viewinfo.setHeight(this.getHeight());
|
102 |
m_viewinfo.setWidth(this.getWidth());
|
103 |
m_viewinfo.setX((int)position.getX());
|
104 |
m_viewinfo.setY((int)position.getY());
|
105 |
return m_viewinfo;
|
106 |
} |
107 |
|
108 |
/**
|
109 |
* Cancel actions
|
110 |
*/
|
111 |
private void close() { |
112 |
try {
|
113 |
PluginServices.getMDIManager().closeWindow(this);
|
114 |
} catch (ArrayIndexOutOfBoundsException e) { |
115 |
//Si la ventana no se puede eliminar no hacemos nada
|
116 |
} |
117 |
} |
118 |
|
119 |
/**
|
120 |
* Accept actions
|
121 |
*/
|
122 |
private void accept() { |
123 |
String txt = getNameField().getText();
|
124 |
if(txt == null || txt.compareTo("") == 0) { |
125 |
JOptionPane.showMessageDialog(null, Messages.getText("character_not_valid"), "", JOptionPane.ERROR_MESSAGE); |
126 |
return;
|
127 |
} |
128 |
|
129 |
byte[] byteList = txt.getBytes(); |
130 |
for (int i = 0; i < byteList.length; i++) { |
131 |
if(byteList[i] < 45 || |
132 |
(byteList[i] > 45 && byteList[i] < 48) || |
133 |
(byteList[i] > 57 && byteList[i] < 65) || |
134 |
(byteList[i] > 90 && byteList[i] < 95) || |
135 |
(byteList[i] > 95 && byteList[i] < 97) || |
136 |
(byteList[i] > 122 && byteList[i] < 126) || |
137 |
(byteList[i] > 126)) {
|
138 |
JOptionPane.showMessageDialog(null, Messages.getText("character_not_valid"), "", JOptionPane.ERROR_MESSAGE); |
139 |
return;
|
140 |
} |
141 |
} |
142 |
|
143 |
layerName = txt; |
144 |
close(); |
145 |
listener.actionButtonPressed(new ButtonsPanelEvent(layerName, ButtonsPanel.BUTTON_ACCEPT));
|
146 |
} |
147 |
|
148 |
/*
|
149 |
* (non-Javadoc)
|
150 |
* @see org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener#actionButtonPressed(org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent)
|
151 |
*/
|
152 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
153 |
if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
|
154 |
close(); |
155 |
} |
156 |
|
157 |
if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
|
158 |
accept(); |
159 |
} |
160 |
} |
161 |
|
162 |
public Object getWindowProfile() { |
163 |
return WindowInfo.PROPERTIES_PROFILE;
|
164 |
} |
165 |
} |