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