Revision 37589 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
SelectFilesTreeCellRenderer.java | ||
---|---|---|
45 | 45 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a> |
46 | 46 |
*/ |
47 | 47 |
public class SelectFilesTreeCellRenderer extends JPanel implements |
48 |
TreeCellRenderer {
|
|
48 |
TreeCellRenderer {
|
|
49 | 49 |
|
50 |
/**
|
|
50 |
/**
|
|
51 | 51 |
* |
52 | 52 |
*/ |
53 |
private static final long serialVersionUID = 3880990147213047185L;
|
|
54 |
protected JCheckBox check;
|
|
53 |
private static final long serialVersionUID = 3880990147213047185L;
|
|
54 |
protected JCheckBox check;
|
|
55 | 55 |
|
56 |
public SelectFilesTreeCellRenderer() {
|
|
57 |
setLayout(null);
|
|
58 |
add(check = new JCheckBox());
|
|
59 |
check.setBackground(UIManager.getColor("Tree.textBackground"));
|
|
60 |
}
|
|
56 |
public SelectFilesTreeCellRenderer() {
|
|
57 |
setLayout(null);
|
|
58 |
add(check = new JCheckBox());
|
|
59 |
check.setBackground(UIManager.getColor("Tree.textBackground"));
|
|
60 |
}
|
|
61 | 61 |
|
62 |
public Component getTreeCellRendererComponent(JTree tree, Object value, |
|
63 |
boolean isSelected, boolean expanded, boolean leaf, int row, |
|
64 |
boolean hasFocus) { |
|
65 |
String stringValue = |
|
66 |
tree.convertValueToText(value, isSelected, expanded, leaf, row, |
|
67 |
hasFocus); |
|
62 |
public Component getTreeCellRendererComponent(JTree tree, Object value, |
|
63 |
boolean isSelected, boolean expanded, boolean leaf, int row, |
|
64 |
boolean hasFocus) { |
|
65 |
String stringValue = tree.convertValueToText(value, isSelected, |
|
66 |
expanded, leaf, row, hasFocus); |
|
68 | 67 |
|
69 |
setEnabled(tree.isEnabled());
|
|
70 |
check.setSelected(((SelectFilesTreeCheckNode) value).isSelected());
|
|
71 |
check.setText(stringValue);
|
|
72 |
return this;
|
|
73 |
}
|
|
68 |
setEnabled(tree.isEnabled());
|
|
69 |
check.setSelected(((SelectFilesTreeCheckNode) value).isSelected());
|
|
70 |
check.setText(stringValue);
|
|
71 |
return this;
|
|
72 |
}
|
|
74 | 73 |
|
75 |
@Override
|
|
76 |
public Dimension getPreferredSize() {
|
|
77 |
Dimension d_check = check.getPreferredSize();
|
|
78 |
return new Dimension(d_check.width, d_check.height);
|
|
74 |
@Override
|
|
75 |
public Dimension getPreferredSize() {
|
|
76 |
Dimension d_check = check.getPreferredSize();
|
|
77 |
return new Dimension(d_check.width, d_check.height);
|
|
79 | 78 |
|
80 |
}
|
|
79 |
}
|
|
81 | 80 |
|
82 |
@Override
|
|
83 |
public void doLayout() {
|
|
84 |
Dimension d_check = check.getPreferredSize();
|
|
85 |
int y_check = 0;
|
|
86 |
check.setLocation(0, y_check);
|
|
87 |
check.setBounds(0, y_check, d_check.width, d_check.height);
|
|
88 |
}
|
|
81 |
@Override
|
|
82 |
public void doLayout() {
|
|
83 |
Dimension d_check = check.getPreferredSize();
|
|
84 |
int y_check = 0;
|
|
85 |
check.setLocation(0, y_check);
|
|
86 |
check.setBounds(0, y_check, d_check.width, d_check.height);
|
|
87 |
}
|
|
89 | 88 |
|
90 |
@Override
|
|
91 |
public void setBackground(Color color) {
|
|
92 |
if (color instanceof ColorUIResource) {
|
|
93 |
color = null;
|
|
94 |
}
|
|
95 |
super.setBackground(color);
|
|
96 |
}
|
|
89 |
@Override
|
|
90 |
public void setBackground(Color color) {
|
|
91 |
if (color instanceof ColorUIResource) {
|
|
92 |
color = null;
|
|
93 |
}
|
|
94 |
super.setBackground(color);
|
|
95 |
}
|
|
97 | 96 |
|
98 |
public class TreeLabel extends JLabel {
|
|
97 |
public class TreeLabel extends JLabel {
|
|
99 | 98 |
|
100 |
/**
|
|
99 |
/**
|
|
101 | 100 |
* |
102 | 101 |
*/ |
103 |
private static final long serialVersionUID = -6969544786323247161L;
|
|
102 |
private static final long serialVersionUID = -6969544786323247161L;
|
|
104 | 103 |
|
105 |
boolean isSelected;
|
|
104 |
boolean isSelected;
|
|
106 | 105 |
|
107 |
boolean hasFocus;
|
|
106 |
boolean hasFocus;
|
|
108 | 107 |
|
109 |
public TreeLabel() {
|
|
110 |
}
|
|
108 |
public TreeLabel() {
|
|
109 |
}
|
|
111 | 110 |
|
112 |
@Override
|
|
113 |
public void setBackground(Color color) {
|
|
114 |
if (color instanceof ColorUIResource) {
|
|
115 |
color = null;
|
|
116 |
}
|
|
117 |
super.setBackground(color);
|
|
118 |
}
|
|
111 |
@Override
|
|
112 |
public void setBackground(Color color) {
|
|
113 |
if (color instanceof ColorUIResource) {
|
|
114 |
color = null;
|
|
115 |
}
|
|
116 |
super.setBackground(color);
|
|
117 |
}
|
|
119 | 118 |
|
120 |
@Override |
|
121 |
public void paint(Graphics g) { |
|
122 |
String str; |
|
123 |
if ((str = getText()) != null) { |
|
124 |
if (0 < str.length()) { |
|
125 |
if (isSelected) { |
|
126 |
g.setColor(UIManager |
|
127 |
.getColor("Tree.selectionBackground")); |
|
128 |
} else { |
|
129 |
g.setColor(UIManager.getColor("Tree.textBackground")); |
|
130 |
} |
|
131 |
Dimension d = getPreferredSize(); |
|
132 |
int imageOffset = 0; |
|
133 |
Icon currentI = getIcon(); |
|
134 |
if (currentI != null) { |
|
135 |
imageOffset = |
|
136 |
currentI.getIconWidth() |
|
137 |
+ Math.max(0, getIconTextGap() - 1); |
|
138 |
} |
|
139 |
g.fillRect(imageOffset, 0, d.width - 1 - imageOffset, |
|
140 |
d.height); |
|
141 |
if (hasFocus) { |
|
142 |
g.setColor(UIManager |
|
143 |
.getColor("Tree.selectionBorderColor")); |
|
144 |
g.drawRect(imageOffset, 0, d.width - 1 - imageOffset, |
|
145 |
d.height - 1); |
|
146 |
} |
|
147 |
} |
|
148 |
} |
|
149 |
super.paint(g); |
|
150 |
} |
|
119 |
@Override |
|
120 |
public void paint(Graphics g) { |
|
121 |
String str; |
|
122 |
if ((str = getText()) != null) { |
|
123 |
if (0 < str.length()) { |
|
124 |
if (isSelected) { |
|
125 |
g.setColor(UIManager |
|
126 |
.getColor("Tree.selectionBackground")); |
|
127 |
} else { |
|
128 |
g.setColor(UIManager.getColor("Tree.textBackground")); |
|
129 |
} |
|
130 |
Dimension d = getPreferredSize(); |
|
131 |
int imageOffset = 0; |
|
132 |
Icon currentI = getIcon(); |
|
133 |
if (currentI != null) { |
|
134 |
imageOffset = currentI.getIconWidth() |
|
135 |
+ Math.max(0, getIconTextGap() - 1); |
|
136 |
} |
|
137 |
g.fillRect(imageOffset, 0, d.width - 1 - imageOffset, |
|
138 |
d.height); |
|
139 |
if (hasFocus) { |
|
140 |
g.setColor(UIManager |
|
141 |
.getColor("Tree.selectionBorderColor")); |
|
142 |
g.drawRect(imageOffset, 0, d.width - 1 - imageOffset, |
|
143 |
d.height - 1); |
|
144 |
} |
|
145 |
} |
|
146 |
} |
|
147 |
super.paint(g); |
|
148 |
} |
|
151 | 149 |
|
152 |
@Override
|
|
153 |
public Dimension getPreferredSize() {
|
|
154 |
Dimension retDimension = super.getPreferredSize();
|
|
155 |
if (retDimension != null) {
|
|
156 |
retDimension =
|
|
157 |
new Dimension(retDimension.width + 3, retDimension.height);
|
|
158 |
}
|
|
159 |
return retDimension;
|
|
160 |
}
|
|
150 |
@Override
|
|
151 |
public Dimension getPreferredSize() {
|
|
152 |
Dimension retDimension = super.getPreferredSize();
|
|
153 |
if (retDimension != null) {
|
|
154 |
retDimension = new Dimension(retDimension.width + 3,
|
|
155 |
retDimension.height);
|
|
156 |
}
|
|
157 |
return retDimension;
|
|
158 |
}
|
|
161 | 159 |
|
162 |
public void setSelected(boolean isSelected) {
|
|
163 |
this.isSelected = isSelected;
|
|
164 |
}
|
|
160 |
public void setSelected(boolean isSelected) {
|
|
161 |
this.isSelected = isSelected;
|
|
162 |
}
|
|
165 | 163 |
|
166 |
public void setFocus(boolean hasFocus) {
|
|
167 |
this.hasFocus = hasFocus;
|
|
168 |
}
|
|
169 |
}
|
|
164 |
public void setFocus(boolean hasFocus) {
|
|
165 |
this.hasFocus = hasFocus;
|
|
166 |
}
|
|
167 |
}
|
|
170 | 168 |
} |
Also available in: Unified diff