1 43 44 package org.jfree.ui; 45 46 import java.awt.Dimension ; 47 import java.awt.Graphics ; 48 import java.awt.Graphics2D ; 49 import java.awt.Insets ; 50 import java.awt.Polygon ; 51 import java.awt.Shape ; 52 import java.awt.geom.Rectangle2D ; 53 54 import javax.swing.JPanel ; 55 56 61 public class ArrowPanel extends JPanel { 62 63 64 public static final int UP = 0; 65 66 67 public static final int DOWN = 1; 68 69 70 private int type = UP; 71 72 73 private Rectangle2D available = new Rectangle2D.Float (); 74 75 80 public ArrowPanel(final int type) { 81 this.type = type; 82 setPreferredSize(new Dimension (14, 9)); 83 } 84 85 90 public void paintComponent(final Graphics g) { 91 92 super.paintComponent(g); 93 final Graphics2D g2 = (Graphics2D ) g; 94 95 final Dimension size = getSize(); 97 final Insets insets = getInsets(); 98 this.available.setRect(insets.left, insets.top, 99 size.getWidth() - insets.left - insets.right, 100 size.getHeight() - insets.top - insets.bottom); 101 g2.translate(insets.left, insets.top); 102 g2.fill(getArrow(this.type)); 103 104 } 105 106 113 private Shape getArrow(final int t) { 114 switch (t) { 115 case UP : return getUpArrow(); 116 case DOWN : return getDownArrow(); 117 default : return getUpArrow(); 118 } 119 } 120 121 126 private Shape getUpArrow() { 127 final Polygon result = new Polygon (); 128 result.addPoint(7, 2); 129 result.addPoint(2, 7); 130 result.addPoint(12, 7); 131 return result; 132 } 133 134 139 private Shape getDownArrow() { 140 final Polygon result = new Polygon (); 141 result.addPoint(7, 7); 142 result.addPoint(2, 2); 143 result.addPoint(12, 2); 144 return result; 145 } 146 147 } 148 | Popular Tags |