/** Constructor. */ CellRenderer() { label = new BaseXLabel() { @Override public void paintComponent(final Graphics g) { super.paintComponent(g); BaseXLayout.hints(g); if (fm == null) fm = g.getFontMetrics(label.getFont()); final int y = Math.min(fm.getHeight(), (int) label.getPreferredSize().getHeight()) - 2; int x = (int) label.getPreferredSize().getWidth() + 2; final String s = file.name(); g.setColor(GUIConstants.TEXT); g.drawString(s, x, y); x += fm.stringWidth(s); final String[] names = file.file().getParent().split("/|\\\\"); final StringBuilder sb = new StringBuilder(" "); for (int n = names.length - 1; n >= 0; n--) sb.append('/').append(names[n]); g.setColor(GUIConstants.gray); g.drawString(sb.toString(), x, y); } }; label.setOpaque(true); }
@Override public Component getListCellRendererComponent( final JList<?> list, final Object value, final int index, final boolean selected, final boolean expanded) { file = new IOFile(value.toString()); label.setIcon(BaseXImages.file(file)); label.setText(""); label.setToolTipText(ProjectFile.toString(file, true)); if (selected) { label.setBackground(getSelectionBackground()); label.setForeground(getSelectionForeground()); } else { label.setBackground(GUIConstants.BACK); label.setForeground(GUIConstants.TEXT); } return label; }