svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / creation / model / SelectFilesTreeCellRenderer.java @ 32296
History | View | Annotate | Download (4.04 KB)
1 | 32290 | jpiera | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2010 {Prodevelop} {Task}
|
||
26 | */
|
||
27 | |||
28 | package org.gvsig.installer.swing.impl.creation.model; |
||
29 | |||
30 | import java.awt.Color; |
||
31 | import java.awt.Component; |
||
32 | import java.awt.Dimension; |
||
33 | import java.awt.Graphics; |
||
34 | |||
35 | import javax.swing.Icon; |
||
36 | import javax.swing.JCheckBox; |
||
37 | import javax.swing.JLabel; |
||
38 | import javax.swing.JPanel; |
||
39 | import javax.swing.JTree; |
||
40 | import javax.swing.UIManager; |
||
41 | import javax.swing.plaf.ColorUIResource; |
||
42 | import javax.swing.tree.TreeCellRenderer; |
||
43 | |||
44 | /**
|
||
45 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
||
46 | */
|
||
47 | public class SelectFilesTreeCellRenderer extends JPanel implements TreeCellRenderer { |
||
48 | protected JCheckBox check; |
||
49 | |||
50 | public SelectFilesTreeCellRenderer() {
|
||
51 | setLayout(null);
|
||
52 | add(check = new JCheckBox()); |
||
53 | check.setBackground(UIManager.getColor("Tree.textBackground")); |
||
54 | } |
||
55 | |||
56 | public Component getTreeCellRendererComponent(JTree tree, Object value, |
||
57 | boolean isSelected, boolean expanded, boolean leaf, int row, |
||
58 | boolean hasFocus) {
|
||
59 | String stringValue = tree.convertValueToText(value, isSelected,
|
||
60 | expanded, leaf, row, hasFocus); |
||
61 | |||
62 | setEnabled(tree.isEnabled()); |
||
63 | check.setSelected(((SelectFilesTreeCheckNode) value).isSelected()); |
||
64 | check.setText(stringValue); |
||
65 | return this; |
||
66 | } |
||
67 | |||
68 | public Dimension getPreferredSize() { |
||
69 | Dimension d_check = check.getPreferredSize();
|
||
70 | return new Dimension(d_check.width , d_check.height ); |
||
71 | |||
72 | } |
||
73 | |||
74 | public void doLayout() { |
||
75 | Dimension d_check = check.getPreferredSize();
|
||
76 | int y_check = 0; |
||
77 | int y_label = 0; |
||
78 | check.setLocation(0, y_check);
|
||
79 | check.setBounds(0, y_check, d_check.width, d_check.height);
|
||
80 | } |
||
81 | |||
82 | public void setBackground(Color color) { |
||
83 | if (color instanceof ColorUIResource) |
||
84 | color = null;
|
||
85 | super.setBackground(color);
|
||
86 | } |
||
87 | |||
88 | public class TreeLabel extends JLabel { |
||
89 | boolean isSelected;
|
||
90 | |||
91 | boolean hasFocus;
|
||
92 | |||
93 | public TreeLabel() {
|
||
94 | } |
||
95 | |||
96 | public void setBackground(Color color) { |
||
97 | if (color instanceof ColorUIResource) |
||
98 | color = null;
|
||
99 | super.setBackground(color);
|
||
100 | } |
||
101 | |||
102 | public void paint(Graphics g) { |
||
103 | String str;
|
||
104 | if ((str = getText()) != null) { |
||
105 | if (0 < str.length()) { |
||
106 | if (isSelected) {
|
||
107 | g.setColor(UIManager
|
||
108 | .getColor("Tree.selectionBackground"));
|
||
109 | } else {
|
||
110 | g.setColor(UIManager.getColor("Tree.textBackground")); |
||
111 | } |
||
112 | Dimension d = getPreferredSize();
|
||
113 | int imageOffset = 0; |
||
114 | Icon currentI = getIcon();
|
||
115 | if (currentI != null) { |
||
116 | imageOffset = currentI.getIconWidth() |
||
117 | + Math.max(0, getIconTextGap() - 1); |
||
118 | } |
||
119 | g.fillRect(imageOffset, 0, d.width - 1 - imageOffset, |
||
120 | d.height); |
||
121 | if (hasFocus) {
|
||
122 | g.setColor(UIManager
|
||
123 | .getColor("Tree.selectionBorderColor"));
|
||
124 | g.drawRect(imageOffset, 0, d.width - 1 - imageOffset, |
||
125 | d.height - 1);
|
||
126 | } |
||
127 | } |
||
128 | } |
||
129 | super.paint(g);
|
||
130 | } |
||
131 | |||
132 | public Dimension getPreferredSize() { |
||
133 | Dimension retDimension = super.getPreferredSize(); |
||
134 | if (retDimension != null) { |
||
135 | retDimension = new Dimension(retDimension.width + 3, |
||
136 | retDimension.height); |
||
137 | } |
||
138 | return retDimension;
|
||
139 | } |
||
140 | |||
141 | public void setSelected(boolean isSelected) { |
||
142 | this.isSelected = isSelected;
|
||
143 | } |
||
144 | |||
145 | public void setFocus(boolean hasFocus) { |
||
146 | this.hasFocus = hasFocus;
|
||
147 | } |
||
148 | } |
||
149 | } |