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