Package tableWidget

Source Code of tableWidget.Arrow

package tableWidget;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;

import javax.swing.Icon;

/**
*
* priority = 0 makes the triangle the biggest. Increasing from there decreases the size
*
*/

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

    public Arrow(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 successive 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);
        int z = descending? 7 : 0;//TODO remove magic number 7
        g.drawString(""+(this.priority+1), -20, z);

        // 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.drawString(""+(this.priority+1), -20, 0);
        g.setColor(color);
        g.translate(-x, -y);
    }

    public int getIconWidth() {
        return size;
    }

    public int getIconHeight() {
        return size;
    }
}
TOP

Related Classes of tableWidget.Arrow

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.