James Moger
2011-10-21 62031355525bef5ebbc04762e8736a22607f416f
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;
56
b7f591 57     public IndicatorsRenderer() {
620313 58         super(new FlowLayout(FlowLayout.RIGHT, 1, 0));
841651 59         blankIcon = new ImageIcon(getClass().getResource("/blank.png"));
JM 60         pushIcon = new ImageIcon(getClass().getResource("/lock_go_16x16.png"));
61         pullIcon = new ImageIcon(getClass().getResource("/lock_pull_16x16.png"));
62         viewIcon = new ImageIcon(getClass().getResource("/shield_16x16.png"));
63         tixIcon = new ImageIcon(getClass().getResource("/bug_16x16.png"));
64         doxIcon = new ImageIcon(getClass().getResource("/book_16x16.png"));
65         frozenIcon = new ImageIcon(getClass().getResource("/cold_16x16.png"));
66         federatedIcon = new ImageIcon(getClass().getResource("/federated_16x16.png"));
67     }
68
69     @Override
70     public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
71             boolean hasFocus, int row, int column) {
72         if (isSelected)
73             setBackground(table.getSelectionBackground());
74         else
75             setBackground(table.getBackground());
76         removeAll();
77         if (value instanceof RepositoryModel) {
b7f591 78             StringBuilder tooltip = new StringBuilder();
841651 79             RepositoryModel model = (RepositoryModel) value;
JM 80             if (model.useTickets) {
b7f591 81                 JLabel icon = new JLabel(tixIcon);
JM 82                 tooltip.append(Translation.get("gb.tickets")).append("<br/>");
83                 add(icon);
841651 84             }
JM 85             if (model.useDocs) {
b7f591 86                 JLabel icon = new JLabel(doxIcon);
JM 87                 tooltip.append(Translation.get("gb.docs")).append("<br/>");
88                 add(icon);
841651 89             }
JM 90             if (model.isFrozen) {
b7f591 91                 JLabel icon = new JLabel(frozenIcon);
JM 92                 tooltip.append(Translation.get("gb.isFrozen")).append("<br/>");
93                 add(icon);
841651 94             }
JM 95             if (model.isFederated) {
b7f591 96                 JLabel icon = new JLabel(federatedIcon);
JM 97                 tooltip.append(Translation.get("gb.isFederated")).append("<br/>");
98                 add(icon);
841651 99             }
JM 100
101             switch (model.accessRestriction) {
b7f591 102             case NONE: {
841651 103                 add(new JLabel(blankIcon));
JM 104                 break;
b7f591 105             }
JM 106             case PUSH: {
107                 JLabel icon = new JLabel(pushIcon);
108                 tooltip.append(Translation.get("gb.pushRestricted")).append("<br/>");
109                 add(icon);
841651 110                 break;
b7f591 111             }
JM 112             case CLONE: {
113                 JLabel icon = new JLabel(pullIcon);
4b430b 114                 tooltip.append(Translation.get("gb.cloneRestricted")).append("<br/>");
b7f591 115                 add(icon);
841651 116                 break;
b7f591 117             }
JM 118             case VIEW: {
119                 JLabel icon = new JLabel(viewIcon);
120                 tooltip.append(Translation.get("gb.viewRestricted")).append("<br/>");
121                 add(icon);
841651 122                 break;
b7f591 123             }
841651 124             default:
JM 125                 add(new JLabel(blankIcon));
126             }
b7f591 127             if (tooltip.length() > 0) {
JM 128                 tooltip.insert(0, "<html><body>");
129                 setToolTipText(tooltip.toString().trim());
130             }
841651 131         }
JM 132         return this;
133     }
134 }