1 package com.melloware.jukes.gui.view.component;
2
3 import java.awt.Color;
4 import java.awt.Component;
5 import java.awt.Font;
6 import java.util.Comparator;
7
8 import javax.swing.JLabel;
9 import javax.swing.JList;
10 import javax.swing.ListCellRenderer;
11
12 import org.apache.commons.lang.builder.CompareToBuilder;
13
14 import com.jgoodies.uif.application.Application;
15 import com.melloware.jukes.db.orm.Track;
16 import com.melloware.jukes.gui.tool.Settings;
17 import com.melloware.jukes.gui.view.MainFrame;
18 import com.melloware.jukes.util.JukesValidationMessage;
19
20
21
22
23
24
25
26
27 public final class TrackListCellRenderer
28 extends JLabel
29 implements ListCellRenderer {
30
31
32
33
34 public static final Comparator TRACK_COMPARATOR = new Comparator() {
35 public int compare(Object aObject1, Object aObject2) {
36 final JukesValidationMessage item1 = (JukesValidationMessage)aObject1;
37 final JukesValidationMessage item2 = (JukesValidationMessage)aObject2;
38 final CompareToBuilder builder = new CompareToBuilder();
39 builder.append(item1.formattedText(), item2.formattedText());
40 return builder.toComparison();
41 }
42 };
43 public final Settings settings;
44
45
46
47
48 public TrackListCellRenderer() {
49 super();
50 this.settings = null;
51 }
52
53
54
55
56 public TrackListCellRenderer(Settings aSettings) {
57 super();
58 this.settings = aSettings;
59 }
60
61
62
63
64
65 public Component getListCellRendererComponent(final JList list,
66 final Object value,
67 final int index,
68 final boolean isSelected,
69 final boolean cellHasFocus) {
70
71 final JukesValidationMessage message = (JukesValidationMessage)value;
72
73 final Track track = (Track)message.getDomainObject();
74
75
76 this.setText(track.getDisplayText(" " + this.settings.getDisplayFormatTrack()) + " ");
77 final MainFrame mainFrame = (MainFrame)Application.getDefaultParentFrame();
78 if (isSelected) {
79 setBackground(list.getSelectionBackground());
80 if (track.isNotValid()) {
81 setForeground(Color.RED);
82 } else if (mainFrame.getPlaylist().containsNext(track)) {
83 setForeground(Color.BLUE);
84 } else {
85 setForeground(list.getSelectionForeground());
86 }
87 } else {
88 setBackground(list.getBackground());
89 if (track.isNotValid()) {
90 setForeground(Color.RED);
91 } else if (mainFrame.getPlaylist().containsNext(track)) {
92 setForeground(Color.BLUE);
93 } else {
94 setForeground(list.getForeground());
95 }
96 }
97 setEnabled(list.isEnabled());
98 Font newfont = list.getFont();
99 if (track.isNotValid()) {
100 newfont = newfont.deriveFont(newfont.getStyle() ^ Font.ITALIC);
101 }
102 setFont(newfont);
103 setOpaque(true);
104 return this;
105 }
106
107 }