root / trunk / libraries / libUIComponent_praster / src / org / gvsig / gui / beans / openFile / OpenFileContainer.java @ 8026
History | View | Annotate | Download (4.94 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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.gui.beans.openFile; |
20 |
|
21 |
import java.awt.GridBagConstraints; |
22 |
import java.awt.GridBagLayout; |
23 |
import java.io.File; |
24 |
|
25 |
import javax.swing.JButton; |
26 |
import javax.swing.JTextField; |
27 |
|
28 |
import org.gvsig.gui.beans.BaseComponent; |
29 |
import org.gvsig.gui.beans.openFile.listeners.OpenFileListener; |
30 |
import org.gvsig.i18n.Messages; |
31 |
|
32 |
public class OpenFileContainer extends BaseComponent{ |
33 |
|
34 |
|
35 |
private int wComp = 500, hComp = 55; |
36 |
private int wButton = 165; |
37 |
private int wText = (int)Math.floor(0.63 * wComp); |
38 |
private int hButton = 22; |
39 |
|
40 |
private JButton jButton = null; |
41 |
private JTextField tOpen = null; |
42 |
private OpenFileListener listener = null; |
43 |
|
44 |
private String borderText = "Open"; |
45 |
private boolean isButtonVisible = true; |
46 |
|
47 |
public OpenFileContainer() {
|
48 |
super();
|
49 |
listener = new OpenFileListener(this); |
50 |
initialize(); |
51 |
listener.setButton(this.getJButton());
|
52 |
} |
53 |
|
54 |
/**
|
55 |
* Constructor
|
56 |
* @param WIDTH
|
57 |
* Window width
|
58 |
* @param HEIGHT
|
59 |
* Window height
|
60 |
* @param isButtonVisible
|
61 |
* If the open button is visible
|
62 |
*/
|
63 |
public OpenFileContainer(int WIDTH,int HEIGHT,boolean isButtonVisible){ |
64 |
super();
|
65 |
this.isButtonVisible = isButtonVisible;
|
66 |
this.wComp = WIDTH;
|
67 |
this.hComp = HEIGHT;
|
68 |
listener = new OpenFileListener(this); |
69 |
initialize(); |
70 |
listener.setButton(this.getJButton());
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* This method initializes this
|
75 |
*
|
76 |
*/
|
77 |
private void initialize() { |
78 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
79 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
80 |
gridBagConstraints1.gridx = 1;
|
81 |
gridBagConstraints1.gridy = 0;
|
82 |
gridBagConstraints1.weightx = 10.0;
|
83 |
gridBagConstraints1.insets = new java.awt.Insets(0,2,0,0); |
84 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
85 |
gridBagConstraints.insets = new java.awt.Insets(0,0,0,2); |
86 |
gridBagConstraints.gridy = 0;
|
87 |
gridBagConstraints.gridx = 0;
|
88 |
gridBagConstraints.weightx = 1.0;
|
89 |
this.setLayout(new GridBagLayout()); |
90 |
this.setSize(new java.awt.Dimension(500,50)); |
91 |
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)); |
92 |
this.add(getJButton(), gridBagConstraints);
|
93 |
this.add(getTOpen(), gridBagConstraints1);
|
94 |
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* This method initializes jButton
|
99 |
*
|
100 |
* @return javax.swing.JButton
|
101 |
*/
|
102 |
private JButton getJButton() { |
103 |
if (jButton == null) { |
104 |
jButton = new JButton(); |
105 |
jButton.setPreferredSize(new java.awt.Dimension(wButton,hButton));
|
106 |
jButton.addActionListener(listener); |
107 |
jButton.setSize(wButton, hButton); |
108 |
jButton.setText(Messages.getText("abrir..."));
|
109 |
jButton.setVisible(isButtonVisible); |
110 |
getTOpen().setEnabled(isButtonVisible); |
111 |
} |
112 |
return jButton;
|
113 |
} |
114 |
|
115 |
/**
|
116 |
* This method initializes jTextField
|
117 |
*
|
118 |
* @return javax.swing.JTextField
|
119 |
*/
|
120 |
public JTextField getTOpen() { |
121 |
if (tOpen == null) { |
122 |
tOpen = new JTextField(); |
123 |
if (isButtonVisible){
|
124 |
tOpen.setPreferredSize(new java.awt.Dimension(wText,hButton));
|
125 |
}else{
|
126 |
tOpen.setPreferredSize(new java.awt.Dimension((int)Math.floor(wComp * 0.95),hButton)); |
127 |
} |
128 |
} |
129 |
return tOpen;
|
130 |
} |
131 |
|
132 |
/**
|
133 |
* Pone el texto que le pasamos como texto del borde del panel.
|
134 |
* @param text
|
135 |
*/
|
136 |
public void setBorderText(String text){ |
137 |
this.borderText = text;
|
138 |
} |
139 |
|
140 |
|
141 |
public void setComponentSize(int w, int h){ |
142 |
wComp = w; |
143 |
hComp = 55;
|
144 |
wText = (int)Math.floor(0.63 * wComp); |
145 |
|
146 |
this.setPreferredSize(new java.awt.Dimension(wComp, hComp)); |
147 |
if (isButtonVisible){
|
148 |
this.getTOpen().setPreferredSize(new java.awt.Dimension(wText, hButton)); |
149 |
}else{
|
150 |
this.getTOpen().setPreferredSize(new java.awt.Dimension((int)Math.floor(wComp * 0.95), hButton)); |
151 |
} |
152 |
} |
153 |
|
154 |
|
155 |
/**
|
156 |
* Devuelve el file cuya ruta corresponde con el campo de texto.
|
157 |
* @return
|
158 |
*/
|
159 |
public File getFile(){ |
160 |
File fil = null; |
161 |
if(this.getTOpen().getText() != ""){ |
162 |
try{
|
163 |
fil = new File(this.getTOpen().getText()); |
164 |
}catch(Exception exc){ |
165 |
System.err.println("Ruta o archivo no v?lido"); |
166 |
} |
167 |
} |
168 |
return fil;
|
169 |
} |
170 |
|
171 |
} |