commit | author | age
|
19c634
|
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 |
|
841651
|
18 |
import java.awt.Color;
|
19c634
|
19 |
import java.awt.Component;
|
JM |
20 |
import java.text.SimpleDateFormat;
|
|
21 |
import java.util.Date;
|
|
22 |
|
|
23 |
import javax.swing.JTable;
|
841651
|
24 |
import javax.swing.SwingConstants;
|
19c634
|
25 |
import javax.swing.table.DefaultTableCellRenderer;
|
JM |
26 |
|
841651
|
27 |
/**
|
JM |
28 |
* Time ago cell renderer with real date tooltip.
|
|
29 |
*
|
|
30 |
* @author James Moger
|
|
31 |
*
|
|
32 |
*/
|
19c634
|
33 |
public class DateCellRenderer extends DefaultTableCellRenderer {
|
JM |
34 |
|
|
35 |
private static final long serialVersionUID = 1L;
|
|
36 |
|
|
37 |
private final String pattern;
|
9adf62
|
38 |
|
841651
|
39 |
public DateCellRenderer(String pattern, Color foreground) {
|
19c634
|
40 |
this.pattern = (pattern == null ? "yyyy-MM-dd HH:mm" : pattern);
|
841651
|
41 |
setForeground(foreground);
|
JM |
42 |
setHorizontalAlignment(SwingConstants.CENTER);
|
19c634
|
43 |
}
|
JM |
44 |
|
|
45 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
|
|
46 |
boolean hasFocus, int row, int column) {
|
|
47 |
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
|
48 |
if (value instanceof Date) {
|
841651
|
49 |
Date date = (Date) value;
|
4cac0d
|
50 |
String title;
|
JM |
51 |
String dateString;
|
3f5a93
|
52 |
if (date.getTime() == 0) {
|
4cac0d
|
53 |
title = "--";
|
JM |
54 |
dateString = "never";
|
3f5a93
|
55 |
} else {
|
4ad1eb
|
56 |
if (date.getTime() - System.currentTimeMillis() > 0) {
|
JM |
57 |
// future
|
|
58 |
title = Translation.getTimeUtils().inFuture(date);
|
|
59 |
} else {
|
|
60 |
// past
|
|
61 |
title = Translation.getTimeUtils().timeAgo(date);
|
|
62 |
}
|
4cac0d
|
63 |
dateString = new SimpleDateFormat(pattern).format((Date) value);
|
3f5a93
|
64 |
}
|
JM |
65 |
|
4cac0d
|
66 |
if ((System.currentTimeMillis() - date.getTime()) > 10 * 24 * 60 * 60 * 1000L) {
|
JM |
67 |
String tmp = dateString;
|
|
68 |
dateString = title;
|
|
69 |
title = tmp;
|
|
70 |
}
|
|
71 |
this.setText(title);
|
|
72 |
this.setToolTipText(dateString);
|
19c634
|
73 |
}
|
JM |
74 |
return this;
|
|
75 |
}
|
|
76 |
} |