Permalink
Browse files

showing path on the right, in grey

  • Loading branch information...
1 parent 3ad2611 commit 134fcb224e35bd1370cf3c6d7a095d6b4b5c20ca @sickill committed Oct 31, 2009
@@ -21,7 +21,7 @@ public Component getListCellRendererComponent(JList list, Object value, int inde
Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
OffListElement e = (OffListElement)value;
((JLabel)comp).setIcon(e.getIcon());
- ((JLabel)comp).setText(e.getLabel());
+ ((JLabel)comp).setText(e.getFilename());
return comp;
}
}
@@ -0,0 +1,61 @@
+package net.sickill.off.common;
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.ListCellRenderer;
+import javax.swing.border.EmptyBorder;
+
+/**
+ *
+ * @author kill
+ */
+public class OffColumnCellRenderer extends JPanel implements ListCellRenderer {
+// private static final long serialVersionUID = 4562757887321715315L;
+ JLabel[] labels = { new JLabel(), new JLabel(), new JLabel() };
+
+ public OffColumnCellRenderer() {
+ setLayout(new BorderLayout(4, 0));
+ setBorder(new EmptyBorder(1, 1, 1, 1));
+ for (JLabel l : labels) l.setOpaque(true);
+ add(labels[0], BorderLayout.WEST);
+ add(labels[1], BorderLayout.CENTER);
+ add(labels[2], BorderLayout.EAST);
+ }
+
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ OffListElement e = (OffListElement)value;
+
+ labels[0].setIcon(e.getIcon());
+ labels[1].setText(e.getFilename());
+ labels[2].setText(e.getPath());
+
+ if (isSelected) {
+ for (JLabel l : labels) {
+ setBackground(list.getSelectionBackground());
+ l.setBackground(list.getSelectionBackground());
+ l.setForeground(list.getSelectionForeground());
+ }
+ labels[2].setForeground(list.getForeground());
+ } else {
+ for (JLabel l : labels) {
+ setBackground(list.getBackground());
+ l.setBackground(list.getBackground());
+ l.setForeground(list.getForeground());
+ }
+ labels[2].setForeground(Color.GRAY);
+ }
+
+ setEnabled(list.isEnabled());
+ setFont(list.getFont());
+ return this;
+ }
+}
@@ -22,7 +22,7 @@
public OffList(OffPanel off, OffListModel listModel) {
super(listModel);
this.off = off;
- setCellRenderer(new OffCellRenderer());
+ setCellRenderer(new OffColumnCellRenderer());
addKeyListener(this);
addMouseListener(this);
}
@@ -13,9 +13,9 @@
* @author kill
*/
public class OffListElement {
+ String filename, path;
ProjectFile file;
Matcher matcher;
- String label;
int priority = 0;
boolean withPath;
@@ -30,39 +30,49 @@ public ProjectFile getFile() {
}
private String generateHighlightedLabel() {
- String filename = file.getName();
+ String fn = file.getName();
String label_ = "";
int lastStart = 0;
for (int i=1; i<=matcher.groupCount(); i++) {
- label_ += filename.substring(lastStart, matcher.start(i)) + "<b>" + filename.charAt(matcher.start(i)) + "</b>";
+ label_ += fn.substring(lastStart, matcher.start(i)) + "<b>" + fn.charAt(matcher.start(i)) + "</b>";
lastStart = matcher.end(i);
}
- label_ += filename.substring(lastStart);
+ label_ += fn.substring(lastStart);
return label_;
}
- private void generateLabel() {
- label = withPath ? file.getName() : generateHighlightedLabel();
+ private void buildFilename() {
+ filename = withPath ? file.getName() : generateHighlightedLabel();
// label = file.getName();
// if (!settings.isShowExt()) {
// label = label.replaceFirst("\\.[^\\.]+$", "");
// }
// if (settings.isShowPath()) {
- String pathInProject = file.getDirectory();
- if (!pathInProject.equals("")) {
- label += " [" + pathInProject.substring(0, pathInProject.length()-1) + "]";
- }
// }
// if (settings.isShowSize()) {
// label += " - " + formatSize(file.getSize());
// }
}
- public String getLabel() {
- if (label == null) {
- generateLabel();
+ public String getFilename() {
+ if (filename == null) {
+ buildFilename();
}
- return "<html>" + label + "</html>";
+ return "<html>" + filename + "</html>";
+ }
+
+ private void buildPath() {
+ path = file.getDirectory();
+ if (!path.equals("")) {
+ path = path.substring(0, path.length()-1) + " ";
+ }
+ }
+
+ public String getPath() {
+ if (path == null) {
+ buildPath();
+ }
+ return path;
}
public Icon getIcon() {
@@ -86,6 +96,6 @@ int getPriority() {
}
public String toString() {
- return getLabel();
+ return getFilename();
}
}
@@ -194,8 +194,8 @@ private int getPopularity(String fullPath) {
class FileNameComparator implements Comparator<OffListElement> {
public int compare(OffListElement o1, OffListElement o2) {
- return o1.getLabel().toLowerCase().compareTo(
- o2.getLabel().toLowerCase());
+ return o1.getFile().getName().toLowerCase().compareTo(
+ o2.getFile().getName().toLowerCase());
}
}

0 comments on commit 134fcb2

Please sign in to comment.