Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2060 / libraries / libUIComponent / src / org / gvsig / gui / beans / openfile / OpenFileContainer.java @ 39371

History | View | Annotate | Download (5.15 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.Messages;
30
import org.gvsig.gui.beans.openfile.listeners.OpenFileListener;
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
        private boolean                 border  = true;   
42

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

    
47
        private boolean isButtonVisible = true;
48

    
49
        public OpenFileContainer() {
50
                super();
51
                listener = new OpenFileListener(this);
52
                initialize();
53
                listener.setButton(this.getJButton());
54
        }
55
        
56
        public OpenFileContainer(boolean border) {
57
                super();
58
                this.border = border;
59
                listener = new OpenFileListener(this);
60
                initialize();
61
                listener.setButton(this.getJButton());
62
        }
63

    
64
        /**
65
         * Constructor
66
         * @param WIDTH
67
         * Window width
68
         * @param HEIGHT
69
         * Window height
70
         * @param isButtonVisible
71
         * If the open button is visible
72
         */
73
        public OpenFileContainer(int WIDTH,int HEIGHT,boolean isButtonVisible){
74
                super();
75
                this.isButtonVisible = isButtonVisible;
76
                this.wComp = WIDTH;
77
                this.hComp = HEIGHT;
78
                listener = new OpenFileListener(this);
79
                initialize();
80
                listener.setButton(this.getJButton());
81
        }
82

    
83
        /**
84
         * This method initializes this
85
         *
86
         */
87
        private void initialize() {
88
                                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
89
                                gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
90
                                gridBagConstraints1.gridx = 1;
91
                                gridBagConstraints1.gridy = 0;
92
                                gridBagConstraints1.weightx = 10.0;
93
                                gridBagConstraints1.insets = new java.awt.Insets(0,2,0,0);
94
                                GridBagConstraints gridBagConstraints = new GridBagConstraints();
95
                                gridBagConstraints.insets = new java.awt.Insets(0,0,0,2);
96
                                gridBagConstraints.gridy = 0;
97
                                gridBagConstraints.gridx = 0;
98
                                gridBagConstraints.weightx = 1.0;
99
                                this.setLayout(new GridBagLayout());
100
                                this.setSize(new java.awt.Dimension(500,50));
101
                                if(border)
102
                                        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));
103
                                this.add(getJButton(), gridBagConstraints);
104
                                this.add(getTOpen(), gridBagConstraints1);
105

    
106
        }
107

    
108
        /**
109
         * This method initializes jButton
110
         *
111
         * @return javax.swing.JButton
112
         */
113
        private JButton getJButton() {
114
                if (jButton == null) {
115
                        jButton = new JButton();
116
                        jButton.setPreferredSize(new java.awt.Dimension(wButton,hButton));
117
                        jButton.addActionListener(listener);
118
                        jButton.setSize(wButton, hButton);
119
                        jButton.setText(Messages.getText("abrir..."));
120
                        jButton.setVisible(isButtonVisible);
121
                        getTOpen().setEnabled(isButtonVisible);
122
                }
123
                return jButton;
124
        }
125

    
126
        /**
127
         * This method initializes jTextField
128
         *
129
         * @return javax.swing.JTextField
130
         */
131
        public JTextField getTOpen() {
132
                if (tOpen == null) {
133
                        tOpen = new JTextField();
134
                        if (isButtonVisible){
135
                                tOpen.setPreferredSize(new java.awt.Dimension(wText,hButton));
136
                        }else{
137
                                tOpen.setPreferredSize(new java.awt.Dimension((int)Math.floor(wComp * 0.95),hButton));
138
                        }
139
                }
140
                return tOpen;
141
        }
142

    
143
        /**
144
         * Pone el texto que le pasamos como texto del borde del panel.
145
         * @param text
146
         */
147
/*
148
        public void setBorderText(String text){
149
                this.borderText = text;
150
        }
151
*/
152

    
153

    
154
        public void setComponentSize(int w, int h){
155
                wComp = w;
156
                hComp = 55;
157
                wText = (int)Math.floor(0.63 * wComp);
158

    
159
                this.setPreferredSize(new java.awt.Dimension(wComp, hComp));
160
                if (isButtonVisible){
161
                        this.getTOpen().setPreferredSize(new java.awt.Dimension(wText, hButton));
162
                }else{
163
                        this.getTOpen().setPreferredSize(new java.awt.Dimension((int)Math.floor(wComp * 0.95), hButton));
164
                }
165
        }
166

    
167

    
168
        /**
169
         * Devuelve el file cuya ruta corresponde con el campo de texto.
170
         * @return
171
         */
172
        public File getFile(){
173
                File fil = null;
174
                if(this.getTOpen().getText() != ""){
175
                        try{
176
                                fil = new File(this.getTOpen().getText());
177
                        }catch(Exception exc){
178
                                System.err.println("Ruta o archivo no v?lido");
179
                        }
180
                }
181
                return fil;
182
        }
183

    
184
}