commit | author | age
|
609a16
|
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.Color;
|
|
19 |
import java.awt.Component;
|
|
20 |
import java.awt.FlowLayout;
|
|
21 |
import java.awt.Font;
|
|
22 |
import java.io.Serializable;
|
|
23 |
|
c7e7e9
|
24 |
import javax.swing.ImageIcon;
|
609a16
|
25 |
import javax.swing.JLabel;
|
JM |
26 |
import javax.swing.JPanel;
|
|
27 |
import javax.swing.JTable;
|
|
28 |
import javax.swing.border.Border;
|
|
29 |
import javax.swing.border.LineBorder;
|
|
30 |
import javax.swing.table.TableCellRenderer;
|
c7e7e9
|
31 |
|
JM |
32 |
import org.eclipse.jgit.lib.Constants;
|
609a16
|
33 |
|
ee458f
|
34 |
import com.gitblit.models.FeedEntryModel;
|
609a16
|
35 |
|
JM |
36 |
/**
|
|
37 |
* Message renderer displays the short log message and then any refs in a style
|
|
38 |
* like the site.
|
|
39 |
*
|
|
40 |
* @author James Moger
|
|
41 |
*
|
|
42 |
*/
|
|
43 |
public class MessageRenderer extends JPanel implements TableCellRenderer, Serializable {
|
|
44 |
|
|
45 |
private static final long serialVersionUID = 1L;
|
|
46 |
|
|
47 |
private final GitblitClient gitblit;
|
c7e7e9
|
48 |
|
JM |
49 |
private final ImageIcon mergeIcon;
|
|
50 |
|
|
51 |
private final ImageIcon blankIcon;
|
|
52 |
|
609a16
|
53 |
private final JLabel messageLabel;
|
JM |
54 |
|
c7e7e9
|
55 |
private final JLabel headLabel;
|
JM |
56 |
|
609a16
|
57 |
private final JLabel branchLabel;
|
c7e7e9
|
58 |
|
JM |
59 |
private final JLabel remoteLabel;
|
|
60 |
|
|
61 |
private final JLabel tagLabel;
|
609a16
|
62 |
|
9119cf
|
63 |
public MessageRenderer() {
|
JM |
64 |
this(null);
|
|
65 |
}
|
|
66 |
|
609a16
|
67 |
public MessageRenderer(GitblitClient gitblit) {
|
c7e7e9
|
68 |
super(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 1));
|
609a16
|
69 |
this.gitblit = gitblit;
|
c7e7e9
|
70 |
|
JM |
71 |
mergeIcon = new ImageIcon(getClass().getResource("/commit_merge_16x16.png"));
|
|
72 |
blankIcon = new ImageIcon(getClass().getResource("/blank.png"));
|
609a16
|
73 |
|
JM |
74 |
messageLabel = new JLabel();
|
c7e7e9
|
75 |
|
JM |
76 |
headLabel = newRefLabel();
|
|
77 |
branchLabel = newRefLabel();
|
|
78 |
remoteLabel = newRefLabel();
|
|
79 |
tagLabel = newRefLabel();
|
|
80 |
|
609a16
|
81 |
add(messageLabel);
|
c7e7e9
|
82 |
add(headLabel);
|
609a16
|
83 |
add(branchLabel);
|
c7e7e9
|
84 |
add(remoteLabel);
|
JM |
85 |
add(tagLabel);
|
|
86 |
}
|
|
87 |
|
|
88 |
private JLabel newRefLabel() {
|
|
89 |
JLabel label = new JLabel();
|
|
90 |
label.setOpaque(true);
|
|
91 |
Font font = label.getFont();
|
|
92 |
label.setFont(font.deriveFont(font.getSize2D() - 1f));
|
|
93 |
return label;
|
|
94 |
}
|
|
95 |
|
|
96 |
private void resetRef(JLabel label) {
|
|
97 |
label.setText("");
|
|
98 |
label.setBackground(messageLabel.getBackground());
|
|
99 |
label.setBorder(null);
|
|
100 |
label.setVisible(false);
|
|
101 |
}
|
|
102 |
|
|
103 |
private void showRef(String ref, JLabel label) {
|
|
104 |
String name = ref;
|
|
105 |
Color bg = getBackground();
|
|
106 |
Border border = null;
|
|
107 |
if (name.startsWith(Constants.R_HEADS)) {
|
|
108 |
// local branch
|
|
109 |
bg = Color.decode("#CCFFCC");
|
|
110 |
name = name.substring(Constants.R_HEADS.length());
|
|
111 |
border = new LineBorder(Color.decode("#00CC33"), 1);
|
|
112 |
} else if (name.startsWith(Constants.R_REMOTES)) {
|
|
113 |
// remote branch
|
|
114 |
bg = Color.decode("#CAC2F5");
|
|
115 |
name = name.substring(Constants.R_REMOTES.length());
|
|
116 |
border = new LineBorder(Color.decode("#6C6CBF"), 1);
|
|
117 |
} else if (name.startsWith(Constants.R_TAGS)) {
|
|
118 |
// tag
|
|
119 |
bg = Color.decode("#FFFFAA");
|
|
120 |
name = name.substring(Constants.R_TAGS.length());
|
|
121 |
border = new LineBorder(Color.decode("#FFCC00"), 1);
|
|
122 |
} else if (name.equals(Constants.HEAD)) {
|
|
123 |
// HEAD
|
|
124 |
bg = Color.decode("#FFAAFF");
|
|
125 |
border = new LineBorder(Color.decode("#FF00EE"), 1);
|
|
126 |
} else {
|
|
127 |
}
|
|
128 |
label.setText(name);
|
|
129 |
label.setBackground(bg);
|
|
130 |
label.setBorder(border);
|
|
131 |
label.setVisible(true);
|
609a16
|
132 |
}
|
JM |
133 |
|
|
134 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
|
|
135 |
boolean hasFocus, int row, int column) {
|
|
136 |
if (isSelected)
|
|
137 |
setBackground(table.getSelectionBackground());
|
|
138 |
else
|
|
139 |
setBackground(table.getBackground());
|
|
140 |
messageLabel.setForeground(isSelected ? table.getSelectionForeground() : table
|
|
141 |
.getForeground());
|
41cffb
|
142 |
if (value == null) {
|
JM |
143 |
return this;
|
|
144 |
}
|
ee458f
|
145 |
FeedEntryModel entry = (FeedEntryModel) value;
|
9119cf
|
146 |
|
JM |
147 |
if (gitblit == null) {
|
|
148 |
// no gitblit client, just display message
|
609a16
|
149 |
messageLabel.setText(entry.title);
|
9119cf
|
150 |
} else {
|
JM |
151 |
// show message in BOLD if its a new entry
|
|
152 |
if (entry.published.after(gitblit.getLastFeedRefresh(entry.repository, entry.branch))) {
|
|
153 |
messageLabel.setText("<html><body><b>" + entry.title);
|
|
154 |
} else {
|
|
155 |
messageLabel.setText(entry.title);
|
|
156 |
}
|
609a16
|
157 |
}
|
JM |
158 |
|
|
159 |
// reset ref label
|
c7e7e9
|
160 |
resetRef(headLabel);
|
JM |
161 |
resetRef(branchLabel);
|
|
162 |
resetRef(remoteLabel);
|
|
163 |
resetRef(tagLabel);
|
609a16
|
164 |
|
c7e7e9
|
165 |
int parentCount = 0;
|
609a16
|
166 |
if (entry.tags != null) {
|
JM |
167 |
for (String tag : entry.tags) {
|
c7e7e9
|
168 |
if (tag.startsWith("ref:")) {
|
JM |
169 |
// strip ref:
|
|
170 |
tag = tag.substring("ref:".length());
|
|
171 |
} else {
|
|
172 |
// count parents
|
|
173 |
if (tag.startsWith("parent:")) {
|
|
174 |
parentCount++;
|
|
175 |
}
|
|
176 |
}
|
609a16
|
177 |
if (tag.equals(entry.branch)) {
|
c7e7e9
|
178 |
// skip current branch label
|
609a16
|
179 |
continue;
|
JM |
180 |
}
|
c7e7e9
|
181 |
if (tag.startsWith(Constants.R_HEADS)) {
|
609a16
|
182 |
// local branch
|
c7e7e9
|
183 |
showRef(tag, branchLabel);
|
JM |
184 |
} else if (tag.startsWith(Constants.R_REMOTES)) {
|
|
185 |
// remote branch
|
|
186 |
showRef(tag, remoteLabel);
|
|
187 |
} else if (tag.startsWith(Constants.R_TAGS)) {
|
609a16
|
188 |
// tag
|
c7e7e9
|
189 |
showRef(tag, tagLabel);
|
JM |
190 |
} else if (tag.equals(Constants.HEAD)) {
|
609a16
|
191 |
// HEAD
|
c7e7e9
|
192 |
showRef(tag, headLabel);
|
609a16
|
193 |
}
|
JM |
194 |
}
|
|
195 |
}
|
|
196 |
|
c7e7e9
|
197 |
if (parentCount > 1) {
|
JM |
198 |
// multiple parents, show merge icon
|
|
199 |
messageLabel.setIcon(mergeIcon);
|
|
200 |
} else {
|
|
201 |
messageLabel.setIcon(blankIcon);
|
|
202 |
}
|
609a16
|
203 |
return this;
|
JM |
204 |
}
|
|
205 |
} |