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
|
package org.openslx.dozmod.gui.control.table;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.UIManager;
import org.openslx.bwlp.thrift.iface.LectureSummary;
import org.openslx.dozmod.gui.helper.ColorUtil;
import org.openslx.dozmod.thrift.Session;
import org.openslx.dozmod.thrift.Sorters;
import org.openslx.dozmod.thrift.cache.UserCache;
import org.openslx.dozmod.util.FormatHelper;
@SuppressWarnings("serial")
public class LectureTable extends ListTable<LectureSummary> {
public static final ListTableColumn COL_NAME = new ListTableColumn("Name");
public static final ListTableColumn COL_OWNER = new ListTableColumn("Besitzer", Sorters.userNameById);
public static final ListTableColumn COL_STARTTIME = new ListTableColumn("Startdatum", Long.class);
public static final ListTableColumn COL_ENDTIME = new ListTableColumn("Ablaufdatum", Long.class);
public static final ListTableColumn COL_ENABLED = new ListTableColumn("Aktiviert", Boolean.class);
public static final ListTableColumn COL_VALID = new ListTableColumn("VM gültig", Boolean.class);
private final Font boldFont;
private final Color invalidColor;
private boolean highlightOwn = false;
public LectureTable() {
super(COL_NAME, COL_OWNER, COL_STARTTIME, COL_ENDTIME, COL_ENABLED, COL_VALID);
boldFont = getFont().deriveFont(Font.BOLD);
Color fg = UIManager.getColor("Table.foreground");
Color bg = UIManager.getColor("Table.background");
invalidColor = ColorUtil.blend(fg, bg, .66f);
}
@Override
protected Object getValueAtInternal(LectureSummary row, ListTableColumn columnIndex) {
if (columnIndex == COL_NAME)
return row.getLectureName();
if (columnIndex == COL_OWNER)
return row.getOwnerId();
if (columnIndex == COL_STARTTIME)
return row.getStartTime();
if (columnIndex == COL_ENDTIME)
return row.getEndTime();
if (columnIndex == COL_ENABLED)
return row.isIsEnabled();
if (columnIndex == COL_VALID)
return row.isIsImageVersionUsable();
throw new IndexOutOfBoundsException();
}
@Override
public Component prepareRenderHook(Component component, LectureSummary row, ListTableColumn column,
boolean isSelected) {
Color fgOverride = null;
if (highlightOwn && column == COL_OWNER && Session.getUserId().equals(row.ownerId)) {
component.setFont(boldFont);
}
long now = System.currentTimeMillis() / 1000;
boolean dateInvalid = ((column == COL_STARTTIME && row.startTime > now) || (column == COL_ENDTIME && row.endTime < now));
if (column == COL_STARTTIME || column == COL_ENDTIME) {
if (dateInvalid) {
fgOverride = Color.RED;
}
}
if (fgOverride == null) {
if (dateInvalid || !row.isImageVersionUsable) {
component.setForeground(invalidColor);
} else {
component.setForeground(isSelected ? getSelectionForeground() : getForeground());
}
} else {
component.setForeground(Color.RED);
}
return component;
}
@Override
public Object modelValueToDisplayFormat(Object value, ListTableColumn column) {
if (column == COL_NAME || column == COL_ENABLED || column == COL_VALID)
return value;
if (column == COL_OWNER)
return FormatHelper.userName(UserCache.find((String) value));
if (column == COL_STARTTIME || column == COL_ENDTIME)
return FormatHelper.shortDate((long) value);
throw new IndexOutOfBoundsException();
}
public void setHighlightOwn(boolean enabled) {
highlightOwn = enabled;
}
}
|