root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / labelslidertext / LabelSliderTextContainer.java @ 10741
History | View | Annotate | Download (3.17 KB)
1 | 10741 | nacho | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 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 | |||
20 | package org.gvsig.gui.beans.labelslidertext; |
||
21 | |||
22 | import java.awt.BorderLayout; |
||
23 | import java.awt.FlowLayout; |
||
24 | import java.awt.GridBagConstraints; |
||
25 | import java.awt.GridBagLayout; |
||
26 | import java.awt.Insets; |
||
27 | |||
28 | import javax.swing.JLabel; |
||
29 | import javax.swing.JPanel; |
||
30 | |||
31 | import org.gvsig.gui.beans.slidertext.SliderTextContainer; |
||
32 | |||
33 | /**
|
||
34 | * A?ade una etiqueta al componente Slider ajustando el tama?o del componente
|
||
35 | * a la longitud de la etiqueta. Al redimensionar el componente varia el tama?o
|
||
36 | * del slider
|
||
37 | * @author Nacho Brodin(nachobrodin@gmail.com)
|
||
38 | *
|
||
39 | */
|
||
40 | public class LabelSliderTextContainer extends SliderTextContainer { |
||
41 | |||
42 | public JLabel lName = null; |
||
43 | private JPanel pLabel = null; |
||
44 | |||
45 | /**
|
||
46 | * Constructor
|
||
47 | * @param min Valor m?nimo del slider
|
||
48 | * @param max Valor m?ximo del slider
|
||
49 | * @param defaultPos Posici?n inicial
|
||
50 | * @param up Si es true el texto se coloca sobre el componente y si es false a la izquierda
|
||
51 | * @param txt Texto de la etiqueta
|
||
52 | */
|
||
53 | public LabelSliderTextContainer(int min, int max, int defaultPos, boolean up, String txt){ |
||
54 | super(min, max, defaultPos);
|
||
55 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
||
56 | gridBagConstraints1.insets = new Insets(0,0,0,0); |
||
57 | if(!up)
|
||
58 | super.add(getPLabel(up), BorderLayout.WEST); |
||
59 | else
|
||
60 | super.add(getPLabel(up), BorderLayout.NORTH); |
||
61 | getLName().setText(txt); |
||
62 | } |
||
63 | |||
64 | /**
|
||
65 | * This method initializes jPanel
|
||
66 | *
|
||
67 | * @return javax.swing.JPanel
|
||
68 | */
|
||
69 | private JPanel getPLabel(boolean up) { |
||
70 | if (pLabel == null) { |
||
71 | pLabel = new JPanel(); |
||
72 | if(!up){
|
||
73 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
||
74 | gridBagConstraints1.insets = new java.awt.Insets(0, 10, 8, 0); |
||
75 | pLabel.setLayout(new GridBagLayout()); |
||
76 | pLabel.add(getLName(), gridBagConstraints1); |
||
77 | }else{
|
||
78 | FlowLayout fl = new FlowLayout(); |
||
79 | fl.setAlignment(FlowLayout.LEFT);
|
||
80 | pLabel.setLayout(fl); |
||
81 | pLabel.add(getLName(), null);
|
||
82 | } |
||
83 | |||
84 | } |
||
85 | return pLabel;
|
||
86 | } |
||
87 | |||
88 | /**
|
||
89 | * This method initializes JLabel
|
||
90 | * @return
|
||
91 | */
|
||
92 | public JLabel getLName(){ |
||
93 | if(lName == null) |
||
94 | lName = new JLabel(); |
||
95 | return lName;
|
||
96 | } |
||
97 | |||
98 | /**
|
||
99 | * Asigna el texto de la etiqueta
|
||
100 | * @param Texto de la etiqueta
|
||
101 | */
|
||
102 | public void setName(String name){ |
||
103 | lName.setText(name); |
||
104 | } |
||
105 | |||
106 | /**
|
||
107 | * Activa o desactiva el control
|
||
108 | */
|
||
109 | public void setControlEnabled(boolean active){ |
||
110 | this.lName.setEnabled(active);
|
||
111 | super.setControlEnabled(active);
|
||
112 | } |
||
113 | } |