1 19 package org.lucane.applications.whiteboard.gui; 20 21 import java.awt.Color ; 22 import java.awt.Graphics ; 23 import java.awt.event.MouseEvent ; 24 import java.awt.event.MouseListener ; 25 26 import javax.swing.JButton ; 27 28 import org.lucane.applications.whiteboard.WhiteBoard; 29 30 public class LineWidthButton extends JButton 31 implements MouseListener 32 { 33 private WhiteBoard plugin; 34 35 public LineWidthButton(WhiteBoard plugin) 36 { 37 super(plugin.getImageIcon("blank.png")); 38 setToolTipText(plugin.tr("tip.lineWidth")); 39 setFocusable(false); 40 addMouseListener(this); 41 42 this.plugin = plugin; 43 } 44 45 protected void paintChildren(Graphics g) 46 { 47 g.setColor(Color.BLACK); 48 int x1 = 4; 49 int x2 = g.getClipBounds().width-6; 50 int y = (g.getClipBounds().height-plugin.getGraph().getLineWidth())/2; 51 for(int i=0;i<plugin.getGraph().getLineWidth();i++) 52 g.drawLine(x1, y+i, x2, y+i); 53 } 54 55 public void mouseEntered(MouseEvent e) {} 56 public void mouseExited(MouseEvent e) {} 57 public void mouseReleased(MouseEvent e) {} 58 public void mousePressed(MouseEvent e) {} 59 public void mouseClicked(MouseEvent e) 60 { 61 if(!isEnabled()) 62 return; 63 64 if(e.getButton() == MouseEvent.BUTTON3) 65 { 66 plugin.getGraph().setLineWidth(1); 67 return; 68 } 69 70 int width = plugin.getGraph().getLineWidth() +1; 71 if(width > 4) 72 width = 1; 73 plugin.getGraph().setLineWidth(width); 74 repaint(); 75 } 76 77 } | Popular Tags |