/*
 * ECatalog is a database front-end, with two main features:
 * 1. Use of preferences
 *  A preference-based approach, where the user is allowed to define the importance of each criterion.
 *  Then the items are ranked accordingly to his criteria.
 * 2. Trade-off analysis
 *  A cooperative database approach, where the system "argues" with the user about his criteria.
 *  When there are no matching items, the system explains the minimal conflicting set and
 *  give some possible strong and weak relaxations about his criteria.
 * This package also containts the software and the set-up details used for our User Study,
 * comparing the use or not of the two previous features mentioned above.
 *
 * Copyright (C) 2006 David Portabella Clotet, Artificial Intelligence Laboratory, EPFL
 * 
 * This file is part of ecatalog-1.0.zip
 * 
 * ECatalog is free software and a free user study set-up;
 * you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * ECatalog is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ECatalog; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 * @version 1.0
 * @author David Portabella
 * To contact the author:
 * email: david@portabella.name and david.portabella@epfl.ch
 * 
 * More information about ECatalog:
 *  http://sourceforge.net/projects/ecatalog/
 *  http://icwww.epfl.ch/~portabel/ecatalogs/
 */

package utils;

import javax.swing.Icon;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Color;


public class ArrowIcon implements Icon {
    private boolean descending;
    private int size;
    private int priority;

    public ArrowIcon(boolean descending, int size, int priority) {
	this.descending = descending;
	this.size = size;
	this.priority = priority;
    }

    public void paintIcon(Component c, Graphics g, int x, int y) {
	Color color = c == null ? Color.GRAY : c.getBackground();             
	// In a compound sort, make each succesive triangle 20% 
	// smaller than the previous one. 
	int dx = (int)(size/2*Math.pow(0.8, priority));
	int dy = descending ? dx : -dx;
	// Align icon (roughly) with font baseline. 
	y = y + 5*size/6 + (descending ? -dy : 0);
	int shift = descending ? 1 : -1;
	g.translate(x, y);

	// Right diagonal. 
	g.setColor(color.darker());
	g.drawLine(dx / 2, dy, 0, 0);
	g.drawLine(dx / 2, dy + shift, 0, shift);
            
	// Left diagonal. 
	g.setColor(color.brighter());
	g.drawLine(dx / 2, dy, dx, 0);
	g.drawLine(dx / 2, dy + shift, dx, shift);
            
	// Horizontal line. 
	if (descending) {
	    g.setColor(color.darker().darker());
	} else {
	    g.setColor(color.brighter().brighter());
	}
	g.drawLine(dx, 0, 0, 0);

	g.setColor(color);
	g.translate(-x, -y);
    }

    public int getIconWidth() {
	return size;
    }

    public int getIconHeight() {
	return size;
    }
}

