root / tags / v1_0_1_RELEASE / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / snapping / panels / SnapConfig2.java @ 9531
History | View | Annotate | Download (5.43 KB)
1 |
/* 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui.cad.snapping.panels; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.GridLayout; |
46 |
import java.awt.Point; |
47 |
import java.awt.image.BufferedImage; |
48 |
import java.util.ArrayList; |
49 |
|
50 |
import javax.swing.JCheckBox; |
51 |
import javax.swing.JList; |
52 |
import javax.swing.JPanel; |
53 |
import javax.swing.JScrollPane; |
54 |
import javax.swing.ListCellRenderer; |
55 |
|
56 |
import com.iver.cit.gvsig.gui.cad.snapping.ISnapper; |
57 |
; |
58 |
|
59 |
public class SnapConfig2 extends JPanel { |
60 |
|
61 |
private JCheckBox jChkBoxRefentActive = null; |
62 |
private JPanel jPanel = null; |
63 |
private JScrollPane jScrollPane = null; |
64 |
|
65 |
private BufferedImage myCanvas = new BufferedImage(12, 12, BufferedImage.TYPE_INT_ARGB); |
66 |
|
67 |
private ArrayList snappers; |
68 |
|
69 |
class MyCellRenderer extends JCheckBox implements ListCellRenderer { |
70 |
|
71 |
// This is the only method defined by ListCellRenderer.
|
72 |
// We just reconfigure the JLabel each time we're called.
|
73 |
|
74 |
|
75 |
public Component getListCellRendererComponent( |
76 |
JList list,
|
77 |
Object value, // value to display |
78 |
int index, // cell index |
79 |
boolean isSelected, // is the cell selected |
80 |
boolean cellHasFocus) // the list and the cell have the focus |
81 |
{ |
82 |
ISnapper snapper = (ISnapper) value; |
83 |
String s = snapper.getToolTipText();
|
84 |
setText(s); |
85 |
|
86 |
if (isSelected) {
|
87 |
setBackground(list.getSelectionBackground()); |
88 |
setForeground(list.getSelectionForeground()); |
89 |
} |
90 |
else {
|
91 |
setBackground(list.getBackground()); |
92 |
setForeground(list.getForeground()); |
93 |
} |
94 |
setEnabled(list.isEnabled()); |
95 |
setFont(list.getFont()); |
96 |
setOpaque(true);
|
97 |
return this; |
98 |
} |
99 |
|
100 |
public void doClick() { |
101 |
super.doClick();
|
102 |
System.out.println("Click"); |
103 |
} |
104 |
|
105 |
|
106 |
} |
107 |
|
108 |
|
109 |
/**
|
110 |
* This method initializes
|
111 |
*
|
112 |
*/
|
113 |
public SnapConfig2() {
|
114 |
super();
|
115 |
initialize(); |
116 |
} |
117 |
|
118 |
/**
|
119 |
* This method initializes this
|
120 |
*
|
121 |
*/
|
122 |
private void initialize() { |
123 |
this.setLayout(null); |
124 |
this.setSize(new java.awt.Dimension(463,239)); |
125 |
this.setPreferredSize(new java.awt.Dimension(463,239)); |
126 |
this.add(getJChkBoxRefentActive(), null); |
127 |
this.add(getJPanel(), null); |
128 |
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* This method initializes jChkBoxRefentActive
|
133 |
*
|
134 |
* @return javax.swing.JCheckBox
|
135 |
*/
|
136 |
private JCheckBox getJChkBoxRefentActive() { |
137 |
if (jChkBoxRefentActive == null) { |
138 |
jChkBoxRefentActive = new JCheckBox(); |
139 |
jChkBoxRefentActive.setText("Referencia a Objetos Activada:");
|
140 |
jChkBoxRefentActive.setBounds(new java.awt.Rectangle(26,10,418,23)); |
141 |
} |
142 |
return jChkBoxRefentActive;
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* This method initializes jPanel
|
147 |
*
|
148 |
* @return javax.swing.JPanel
|
149 |
*/
|
150 |
private JPanel getJPanel() { |
151 |
if (jPanel == null) { |
152 |
jPanel = new JPanel(); |
153 |
jPanel.setLayout(null);
|
154 |
jPanel.setBounds(new java.awt.Rectangle(19,40,423,181)); |
155 |
jPanel.add(getJScrollPane(), null);
|
156 |
} |
157 |
return jPanel;
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* This method initializes jScrollPane
|
162 |
*
|
163 |
* @return javax.swing.JScrollPane
|
164 |
*/
|
165 |
private JScrollPane getJScrollPane() { |
166 |
if (jScrollPane == null) { |
167 |
jScrollPane = new JScrollPane(); |
168 |
jScrollPane.setBounds(new java.awt.Rectangle(9,9,402,163)); |
169 |
jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
170 |
jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
171 |
|
172 |
} |
173 |
return jScrollPane;
|
174 |
} |
175 |
|
176 |
public ArrayList getSnappers() { |
177 |
return snappers;
|
178 |
} |
179 |
|
180 |
public void setSnappers(ArrayList snappers) { |
181 |
this.snappers = snappers;
|
182 |
JPanel newPanel = new JPanel(); |
183 |
GridLayout layout = new GridLayout(snappers.size()/2, 2); |
184 |
newPanel.setLayout(layout); |
185 |
newPanel.setSize(getJScrollPane().getSize()); |
186 |
for (int i=0; i < snappers.size(); i++) |
187 |
{ |
188 |
ISnapper s = (ISnapper) snappers.get(i); |
189 |
JCheckBox snapperComponent = new JCheckBox(s.getToolTipText()); |
190 |
// snapperComponent.setPreferredSize(new Dimension(200, 30));
|
191 |
Graphics2D g2 = myCanvas.createGraphics();
|
192 |
g2.clearRect(0,0, 12, 12); |
193 |
s.draw(g2, new Point(5,5)); |
194 |
g2.dispose(); |
195 |
// snapperComponent.getLabel().setIcon(new ImageIcon(myCanvas));
|
196 |
|
197 |
newPanel.add(snapperComponent); |
198 |
} |
199 |
getJScrollPane().setViewportView(newPanel); |
200 |
|
201 |
} |
202 |
|
203 |
|
204 |
} // @jve:decl-index=0:visual-constraint="10,10"
|
205 |
|
206 |
|