1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/*
* Copyright 2011 gitblit.com.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitblit.client;
import java.awt.Component;
import java.awt.FlowLayout;
import java.io.Serializable;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import com.gitblit.models.RepositoryModel;
/**
* Renders the type indicators (tickets, frozen, access restriction, etc) in a
* single cell.
*
* @author James Moger
*
*/
public class IndicatorsRenderer extends JPanel implements TableCellRenderer, Serializable {
private static final long serialVersionUID = 1L;
private final ImageIcon blankIcon;
private final ImageIcon pushIcon;
private final ImageIcon pullIcon;
private final ImageIcon viewIcon;
private final ImageIcon doxIcon;
private final ImageIcon frozenIcon;
private final ImageIcon federatedIcon;
private final ImageIcon forkIcon;
private final ImageIcon sparkleshareIcon;
private final ImageIcon mirrorIcon;
public IndicatorsRenderer() {
super(new FlowLayout(FlowLayout.RIGHT, 1, 0));
blankIcon = new ImageIcon(getClass().getResource("/blank.png"));
pushIcon = new ImageIcon(getClass().getResource("/lock_go_16x16.png"));
pullIcon = new ImageIcon(getClass().getResource("/lock_pull_16x16.png"));
viewIcon = new ImageIcon(getClass().getResource("/shield_16x16.png"));
doxIcon = new ImageIcon(getClass().getResource("/book_16x16.png"));
frozenIcon = new ImageIcon(getClass().getResource("/cold_16x16.png"));
federatedIcon = new ImageIcon(getClass().getResource("/federated_16x16.png"));
forkIcon = new ImageIcon(getClass().getResource("/commit_divide_16x16.png"));
sparkleshareIcon = new ImageIcon(getClass().getResource("/star_16x16.png"));
mirrorIcon = new ImageIcon(getClass().getResource("/mirror_16x16.png"));
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
if (isSelected)
setBackground(table.getSelectionBackground());
else
setBackground(table.getBackground());
removeAll();
if (value instanceof RepositoryModel) {
StringBuilder tooltip = new StringBuilder();
RepositoryModel model = (RepositoryModel) value;
if (model.isSparkleshared()) {
JLabel icon = new JLabel(sparkleshareIcon);
tooltip.append(Translation.get("gb.isSparkleshared")).append("<br/>");
add(icon);
}
if (model.isMirror) {
JLabel icon = new JLabel(mirrorIcon);
tooltip.append(Translation.get("gb.isMirror")).append("<br/>");
add(icon);
}
if (model.isFork()) {
JLabel icon = new JLabel(forkIcon);
tooltip.append(Translation.get("gb.isFork")).append("<br/>");
add(icon);
}
if (model.isFrozen) {
JLabel icon = new JLabel(frozenIcon);
tooltip.append(Translation.get("gb.isFrozen")).append("<br/>");
add(icon);
}
if (model.isFederated) {
JLabel icon = new JLabel(federatedIcon);
tooltip.append(Translation.get("gb.isFederated")).append("<br/>");
add(icon);
}
switch (model.accessRestriction) {
case NONE: {
add(new JLabel(blankIcon));
break;
}
case PUSH: {
JLabel icon = new JLabel(pushIcon);
tooltip.append(Translation.get("gb.pushRestricted")).append("<br/>");
add(icon);
break;
}
case CLONE: {
JLabel icon = new JLabel(pullIcon);
tooltip.append(Translation.get("gb.cloneRestricted")).append("<br/>");
add(icon);
break;
}
case VIEW: {
JLabel icon = new JLabel(viewIcon);
tooltip.append(Translation.get("gb.viewRestricted")).append("<br/>");
add(icon);
break;
}
default:
add(new JLabel(blankIcon));
}
if (tooltip.length() > 0) {
tooltip.insert(0, "<html><body>");
setToolTipText(tooltip.toString().trim());
}
}
return this;
}
}
|