Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / openfile / OpenFileContainer.java @ 11445

History | View | Annotate | Download (4.95 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.JPanel;
27
import javax.swing.JTextField;
28

    
29
import org.gvsig.gui.beans.openfile.listeners.OpenFileListener;
30
import org.gvsig.i18n.Messages;
31

    
32
public class OpenFileContainer extends JPanel {
33
        private static final long serialVersionUID = 5823371652872582451L;
34
        private int                                         wComp = 500, hComp = 55;
35
        private int                                                wButton = 165;
36
        private int                                                wText = (int)Math.floor(0.63 * wComp);
37
        private int                                                hButton = 22;
38
        
39
        private JButton jButton = null;
40
        private JTextField tOpen = null;
41
        private OpenFileListener listener = null;
42
        
43
        private boolean isButtonVisible = true;
44
        
45
        public OpenFileContainer() {
46
                super();
47
                listener = new OpenFileListener(this);
48
                initialize();
49
                listener.setButton(this.getJButton());
50
        }
51
        
52
        /**
53
         * Constructor
54
         * @param WIDTH
55
         * Window width
56
         * @param HEIGHT
57
         * Window height
58
         * @param isButtonVisible
59
         * If the open button is visible
60
         */
61
        public OpenFileContainer(int WIDTH,int HEIGHT,boolean isButtonVisible){
62
                super();
63
                this.isButtonVisible = isButtonVisible;
64
                this.wComp = WIDTH;
65
                this.hComp = HEIGHT;
66
                listener = new OpenFileListener(this);
67
                initialize();
68
                listener.setButton(this.getJButton());        
69
        }
70

    
71
        /**
72
         * This method initializes this
73
         * 
74
         */
75
        private void initialize() {
76
        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
77
        gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
78
        gridBagConstraints1.gridx = 1;
79
        gridBagConstraints1.gridy = 0;
80
        gridBagConstraints1.weightx = 10.0;
81
        gridBagConstraints1.insets = new java.awt.Insets(0,2,0,0);
82
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
83
        gridBagConstraints.insets = new java.awt.Insets(0,0,0,2);
84
        gridBagConstraints.gridy = 0;
85
        gridBagConstraints.gridx = 0;
86
        gridBagConstraints.weightx = 1.0;
87
        this.setLayout(new GridBagLayout());
88
        this.setSize(new java.awt.Dimension(500,50));
89
        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));
90
        this.add(getJButton(), gridBagConstraints);
91
        this.add(getTOpen(), gridBagConstraints1);
92
                        
93
        }
94

    
95
        /**
96
         * This method initializes jButton        
97
         *         
98
         * @return javax.swing.JButton        
99
         */
100
        private JButton getJButton() {
101
                if (jButton == null) {
102
                        jButton = new JButton();
103
                        jButton.setPreferredSize(new java.awt.Dimension(wButton,hButton));
104
                        jButton.addActionListener(listener);
105
                        jButton.setSize(wButton, hButton);
106
                        jButton.setText(Messages.getText("abrir..."));
107
                        jButton.setVisible(isButtonVisible);
108
                        getTOpen().setEnabled(isButtonVisible);
109
                }
110
                return jButton;
111
        }
112

    
113
        /**
114
         * This method initializes jTextField        
115
         *         
116
         * @return javax.swing.JTextField        
117
         */
118
        public JTextField getTOpen() {
119
                if (tOpen == null) {
120
                        tOpen = new JTextField();
121
                        if (isButtonVisible){
122
                                tOpen.setPreferredSize(new java.awt.Dimension(wText,hButton));
123
                        }else{
124
                                tOpen.setPreferredSize(new java.awt.Dimension((int)Math.floor(wComp * 0.95),hButton));
125
                        }
126
                }
127
                return tOpen;
128
        }
129
        
130
        /**
131
         * Pone el texto que le pasamos como texto del borde del panel.
132
         * @param text
133
         */
134
/*
135
        public void setBorderText(String text){
136
                this.borderText = text;
137
        }
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
}