Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / creation / model / SelectFilesTreeCellRenderer.java @ 40560

History | View | Annotate | Download (4.33 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2010 {Prodevelop}   {Task}
27
 */
28

    
29
package org.gvsig.installer.swing.impl.creation.model;
30

    
31
import java.awt.Color;
32
import java.awt.Component;
33
import java.awt.Dimension;
34
import java.awt.Graphics;
35

    
36
import javax.swing.Icon;
37
import javax.swing.JCheckBox;
38
import javax.swing.JLabel;
39
import javax.swing.JPanel;
40
import javax.swing.JTree;
41
import javax.swing.UIManager;
42
import javax.swing.plaf.ColorUIResource;
43
import javax.swing.tree.TreeCellRenderer;
44

    
45
/**
46
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
47
 */
48
public class SelectFilesTreeCellRenderer extends JPanel implements
49
                TreeCellRenderer {
50

    
51
        /**
52
     * 
53
     */
54
        private static final long serialVersionUID = 3880990147213047185L;
55
        protected JCheckBox check;
56

    
57
        public SelectFilesTreeCellRenderer() {
58
                setLayout(null);
59
                add(check = new JCheckBox());
60
                check.setBackground(UIManager.getColor("Tree.textBackground"));
61
        }
62

    
63
        public Component getTreeCellRendererComponent(JTree tree, Object value,
64
                        boolean isSelected, boolean expanded, boolean leaf, int row,
65
                        boolean hasFocus) {
66
                String stringValue = tree.convertValueToText(value, isSelected,
67
                                expanded, leaf, row, hasFocus);
68

    
69
                setEnabled(tree.isEnabled());
70
                check.setSelected(((SelectFilesTreeCheckNode) value).isSelected());
71
                check.setText(stringValue);
72
                return this;
73
        }
74

    
75
        @Override
76
        public Dimension getPreferredSize() {
77
                Dimension d_check = check.getPreferredSize();
78
                return new Dimension(d_check.width, d_check.height);
79

    
80
        }
81

    
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
        }
89

    
90
        @Override
91
        public void setBackground(Color color) {
92
                if (color instanceof ColorUIResource) {
93
                        color = null;
94
                }
95
                super.setBackground(color);
96
        }
97

    
98
        public class TreeLabel extends JLabel {
99

    
100
                /**
101
         * 
102
         */
103
                private static final long serialVersionUID = -6969544786323247161L;
104

    
105
                boolean isSelected;
106

    
107
                boolean hasFocus;
108

    
109
                public TreeLabel() {
110
                }
111

    
112
                @Override
113
                public void setBackground(Color color) {
114
                        if (color instanceof ColorUIResource) {
115
                                color = null;
116
                        }
117
                        super.setBackground(color);
118
                }
119

    
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 = currentI.getIconWidth()
136
                                                                + Math.max(0, getIconTextGap() - 1);
137
                                        }
138
                                        g.fillRect(imageOffset, 0, d.width - 1 - imageOffset,
139
                                                        d.height);
140
                                        if (hasFocus) {
141
                                                g.setColor(UIManager
142
                                                                .getColor("Tree.selectionBorderColor"));
143
                                                g.drawRect(imageOffset, 0, d.width - 1 - imageOffset,
144
                                                                d.height - 1);
145
                                        }
146
                                }
147
                        }
148
                        super.paint(g);
149
                }
150

    
151
                @Override
152
                public Dimension getPreferredSize() {
153
                        Dimension retDimension = super.getPreferredSize();
154
                        if (retDimension != null) {
155
                                retDimension = new Dimension(retDimension.width + 3,
156
                                                retDimension.height);
157
                        }
158
                        return retDimension;
159
                }
160

    
161
                public void setSelected(boolean isSelected) {
162
                        this.isSelected = isSelected;
163
                }
164

    
165
                public void setFocus(boolean hasFocus) {
166
                        this.hasFocus = hasFocus;
167
                }
168
        }
169
}