1 21 22 package com.sshtools.ui.swing; 23 24 import java.awt.Component ; 25 import java.awt.Dimension ; 26 import java.awt.Graphics ; 27 import java.awt.Graphics2D ; 28 import java.awt.Stroke ; 29 30 import javax.swing.Icon ; 31 32 37 public class StrokeIcon implements Icon { 38 private Dimension size; 40 private Stroke stroke; 41 42 45 public StrokeIcon() { 46 this(null); 47 } 48 49 54 public StrokeIcon(Stroke stroke) { 55 this(stroke, null); 56 } 57 58 65 public StrokeIcon(Stroke stroke, Dimension size) { 66 setStroke(stroke); 67 setSize(size); 68 } 69 70 78 public void paintIcon(Component c, Graphics g, int x, int y) { 79 Graphics2D g2 = (Graphics2D )g; 80 g2.setStroke(stroke); 81 g2.drawLine(x, y, x + getIconWidth(), y); 82 } 83 84 89 public void setSize(Dimension size) { 90 this.size = size; 91 } 92 93 98 public void setStroke(Stroke stroke) { 99 this.stroke = stroke; 100 } 101 102 107 public int getIconWidth() { 108 return (size == null) ? 48 : size.width; 109 } 110 111 116 public int getIconHeight() { 117 return (size == null) ? 16 : size.height; 118 } 119 } | Popular Tags |