svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / openfile / OpenFileContainer.java @ 40561
History | View | Annotate | Download (5.25 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.gui.beans.openfile; |
25 |
|
26 |
import java.awt.GridBagConstraints; |
27 |
import java.awt.GridBagLayout; |
28 |
import java.io.File; |
29 |
|
30 |
import javax.swing.JButton; |
31 |
import javax.swing.JPanel; |
32 |
import javax.swing.JTextField; |
33 |
|
34 |
import org.gvsig.gui.beans.Messages; |
35 |
import org.gvsig.gui.beans.openfile.listeners.OpenFileListener; |
36 |
/**
|
37 |
*
|
38 |
* @version 13/07/2007
|
39 |
*/
|
40 |
public class OpenFileContainer extends JPanel { |
41 |
private static final long serialVersionUID = 5823371652872582451L; |
42 |
private int wComp = 500, hComp = 55; |
43 |
private int wButton = 165; |
44 |
private int wText = (int)Math.floor(0.63 * wComp); |
45 |
private int hButton = 22; |
46 |
private boolean border = true; |
47 |
|
48 |
private JButton jButton = null; |
49 |
private JTextField tOpen = null; |
50 |
private OpenFileListener listener = null; |
51 |
|
52 |
private boolean isButtonVisible = true; |
53 |
|
54 |
public OpenFileContainer() {
|
55 |
super();
|
56 |
listener = new OpenFileListener(this); |
57 |
initialize(); |
58 |
listener.setButton(this.getJButton());
|
59 |
} |
60 |
|
61 |
public OpenFileContainer(boolean border) { |
62 |
super();
|
63 |
this.border = border;
|
64 |
listener = new OpenFileListener(this); |
65 |
initialize(); |
66 |
listener.setButton(this.getJButton());
|
67 |
} |
68 |
|
69 |
/**
|
70 |
* Constructor
|
71 |
* @param WIDTH
|
72 |
* Window width
|
73 |
* @param HEIGHT
|
74 |
* Window height
|
75 |
* @param isButtonVisible
|
76 |
* If the open button is visible
|
77 |
*/
|
78 |
public OpenFileContainer(int WIDTH,int HEIGHT,boolean isButtonVisible){ |
79 |
super();
|
80 |
this.isButtonVisible = isButtonVisible;
|
81 |
this.wComp = WIDTH;
|
82 |
this.hComp = HEIGHT;
|
83 |
listener = new OpenFileListener(this); |
84 |
initialize(); |
85 |
listener.setButton(this.getJButton());
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* This method initializes this
|
90 |
*
|
91 |
*/
|
92 |
private void initialize() { |
93 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
94 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
95 |
gridBagConstraints1.gridx = 1;
|
96 |
gridBagConstraints1.gridy = 0;
|
97 |
gridBagConstraints1.weightx = 10.0;
|
98 |
gridBagConstraints1.insets = new java.awt.Insets(0,2,0,0); |
99 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
100 |
gridBagConstraints.insets = new java.awt.Insets(0,0,0,2); |
101 |
gridBagConstraints.gridy = 0;
|
102 |
gridBagConstraints.gridx = 0;
|
103 |
gridBagConstraints.weightx = 1.0;
|
104 |
this.setLayout(new GridBagLayout()); |
105 |
this.setSize(new java.awt.Dimension(500,50)); |
106 |
if(border)
|
107 |
this.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Messages.getText("open_file"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
108 |
this.add(getJButton(), gridBagConstraints);
|
109 |
this.add(getTOpen(), gridBagConstraints1);
|
110 |
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* This method initializes jButton
|
115 |
*
|
116 |
* @return javax.swing.JButton
|
117 |
*/
|
118 |
private JButton getJButton() { |
119 |
if (jButton == null) { |
120 |
jButton = new JButton(); |
121 |
jButton.setPreferredSize(new java.awt.Dimension(wButton,hButton));
|
122 |
jButton.addActionListener(listener); |
123 |
jButton.setSize(wButton, hButton); |
124 |
jButton.setText(Messages.getText("abrir..."));
|
125 |
jButton.setVisible(isButtonVisible); |
126 |
getTOpen().setEnabled(isButtonVisible); |
127 |
} |
128 |
return jButton;
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* This method initializes jTextField
|
133 |
*
|
134 |
* @return javax.swing.JTextField
|
135 |
*/
|
136 |
public JTextField getTOpen() { |
137 |
if (tOpen == null) { |
138 |
tOpen = new JTextField(); |
139 |
if (isButtonVisible){
|
140 |
tOpen.setPreferredSize(new java.awt.Dimension(wText,hButton));
|
141 |
}else{
|
142 |
tOpen.setPreferredSize(new java.awt.Dimension((int)Math.floor(wComp * 0.95),hButton)); |
143 |
} |
144 |
} |
145 |
return tOpen;
|
146 |
} |
147 |
|
148 |
/**
|
149 |
* Pone el texto que le pasamos como texto del borde del panel.
|
150 |
* @param text
|
151 |
*/
|
152 |
/*
|
153 |
public void setBorderText(String text){
|
154 |
this.borderText = text;
|
155 |
}
|
156 |
*/
|
157 |
|
158 |
|
159 |
public void setComponentSize(int w, int h){ |
160 |
wComp = w; |
161 |
hComp = 55;
|
162 |
wText = (int)Math.floor(0.63 * wComp); |
163 |
|
164 |
this.setPreferredSize(new java.awt.Dimension(wComp, hComp)); |
165 |
if (isButtonVisible){
|
166 |
this.getTOpen().setPreferredSize(new java.awt.Dimension(wText, hButton)); |
167 |
}else{
|
168 |
this.getTOpen().setPreferredSize(new java.awt.Dimension((int)Math.floor(wComp * 0.95), hButton)); |
169 |
} |
170 |
} |
171 |
|
172 |
|
173 |
/**
|
174 |
* Devuelve el file cuya ruta corresponde con el campo de texto.
|
175 |
* @return
|
176 |
*/
|
177 |
public File getFile(){ |
178 |
File fil = null; |
179 |
if(this.getTOpen().getText() != ""){ |
180 |
try{
|
181 |
fil = new File(this.getTOpen().getText()); |
182 |
}catch(Exception exc){ |
183 |
System.err.println("Ruta o archivo no v?lido"); |
184 |
} |
185 |
} |
186 |
return fil;
|
187 |
} |
188 |
|
189 |
} |