Statistics
| Revision:

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

History | View | Annotate | Download (4.91 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.gui.beans.messages.Messages;
31
/**
32
 *
33
 * @version 13/07/2007
34
 */
35
public class OpenFileContainer extends JPanel {
36
        private static final long serialVersionUID = 5823371652872582451L;
37
        private int                                         wComp = 500, hComp = 55;
38
        private int                                                wButton = 165;
39
        private int                                                wText = (int)Math.floor(0.63 * wComp);
40
        private int                                                hButton = 22;
41

    
42
        private JButton jButton = null;
43
        private JTextField tOpen = null;
44
        private OpenFileListener listener = null;
45

    
46
        private boolean isButtonVisible = true;
47

    
48
        public OpenFileContainer() {
49
                super();
50
                listener = new OpenFileListener(this);
51
                initialize();
52
                listener.setButton(this.getJButton());
53
        }
54

    
55
        /**
56
         * Constructor
57
         * @param WIDTH
58
         * Window width
59
         * @param HEIGHT
60
         * Window height
61
         * @param isButtonVisible
62
         * If the open button is visible
63
         */
64
        public OpenFileContainer(int WIDTH,int HEIGHT,boolean isButtonVisible){
65
                super();
66
                this.isButtonVisible = isButtonVisible;
67
                this.wComp = WIDTH;
68
                this.hComp = HEIGHT;
69
                listener = new OpenFileListener(this);
70
                initialize();
71
                listener.setButton(this.getJButton());
72
        }
73

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

    
96
        }
97

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

    
116
        /**
117
         * This method initializes jTextField
118
         *
119
         * @return javax.swing.JTextField
120
         */
121
        public JTextField getTOpen() {
122
                if (tOpen == null) {
123
                        tOpen = new JTextField();
124
                        if (isButtonVisible){
125
                                tOpen.setPreferredSize(new java.awt.Dimension(wText,hButton));
126
                        }else{
127
                                tOpen.setPreferredSize(new java.awt.Dimension((int)Math.floor(wComp * 0.95),hButton));
128
                        }
129
                }
130
                return tOpen;
131
        }
132

    
133
        /**
134
         * Pone el texto que le pasamos como texto del borde del panel.
135
         * @param text
136
         */
137
/*
138
        public void setBorderText(String text){
139
                this.borderText = text;
140
        }
141
*/
142

    
143

    
144
        public void setComponentSize(int w, int h){
145
                wComp = w;
146
                hComp = 55;
147
                wText = (int)Math.floor(0.63 * wComp);
148

    
149
                this.setPreferredSize(new java.awt.Dimension(wComp, hComp));
150
                if (isButtonVisible){
151
                        this.getTOpen().setPreferredSize(new java.awt.Dimension(wText, hButton));
152
                }else{
153
                        this.getTOpen().setPreferredSize(new java.awt.Dimension((int)Math.floor(wComp * 0.95), hButton));
154
                }
155
        }
156

    
157

    
158
        /**
159
         * Devuelve el file cuya ruta corresponde con el campo de texto.
160
         * @return
161
         */
162
        public File getFile(){
163
                File fil = null;
164
                if(this.getTOpen().getText() != ""){
165
                        try{
166
                                fil = new File(this.getTOpen().getText());
167
                        }catch(Exception exc){
168
                                System.err.println("Ruta o archivo no v?lido");
169
                        }
170
                }
171
                return fil;
172
        }
173

    
174
}