package info.seravee.wallmanager.ui.frame.wallpapers;

import java.awt.Color;
import java.awt.Component;
import java.io.File;

import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import info.seravee.wallcreator.ui.components.SolarizedColor;

public class FolderList<T> extends JList<T> {
	private static final long serialVersionUID = 5962590515579500161L;

	protected int hoveredIndex = -1;

	public FolderList(ListModel<T> dataModel) {
		super(dataModel);
		this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		this.setCellRenderer(new FolderListCellRendered());
		this.setBorder(null);
		this.setFixedCellHeight(24);

		this.setSelectionBackground(SolarizedColor.BLUE);
		this.setSelectionForeground(Color.WHITE);
	}

	private class FolderListCellRendered extends DefaultListCellRenderer {
		private static final long serialVersionUID = 1L;

		private final Border baseBorder = new EmptyBorder(0, 5, 0, 5);
		private final Border lineBorder = BorderFactory.createMatteBorder(1, 0, 0, 0, SolarizedColor.BASE2);

		@Override
		public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
				boolean cellHasFocus) {
			File folder = (File) value;

			JLabel component = (JLabel) super.getListCellRendererComponent(list, folder.getName(), index, isSelected,
					cellHasFocus);

			component.setOpaque(true);
			component.setToolTipText(folder.getAbsolutePath());
			
			if (index == hoveredIndex && !isSelected && !cellHasFocus) {
				component.setBackground(SolarizedColor.BASE2);
			}

			if (index > 0) {
				component.setBorder(BorderFactory.createCompoundBorder(lineBorder, baseBorder));
			} else {
				component.setBorder(baseBorder);
			}

			return component;
		}
	}
}

@@ -98,16 +98,50 @@
 ponent;%0A
+import java.awt.event.MouseEvent;%0A
 import j
@@ -976,16 +976,656 @@
 ITE);%0A%09%7D
+%0A%09%0A%09private boolean processEvent(MouseEvent e) %7B%0A        int index = locationToIndex(e.getPoint());%0A        return index %3E -1 && getCellBounds(index, index).contains(e.getPoint());%0A    %7D%0A%09%0A%09@Override%0A%09protected void processMouseEvent(MouseEvent e) %7B%0A%09%09if (processEvent(e)) %7B%0A%09%09%09super.processMouseEvent(e);%0A%09%09%7D%0A%09%09%0A%09%09if (e.getID() == MouseEvent.MOUSE_EXITED) %7B%0A%09%09%09hoveredIndex = -1;%0A%09%09%09repaint();%0A%09%09%7D%0A%09%7D%0A%09%0A%09@Override%0A%09protected void processMouseMotionEvent(MouseEvent e) %7B%0A%09%09if (processEvent(e)) %7B%0A%09%09%09super.processMouseMotionEvent(e);%0A%09%09%09%0A%09%09%09hoveredIndex = locationToIndex(e.getPoint());%0A%09%09%7D%0A%09%09else %7B%0A%09%09%09hoveredIndex = -1;%0A%09%09%7D%0A%09%09repaint();%0A%09%7D
 %0A%0A%09priva

Improve folder list UI