KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > whiteboard > gui > LineWidthButton


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.whiteboard.gui;
20
21 import java.awt.Color JavaDoc;
22 import java.awt.Graphics JavaDoc;
23 import java.awt.event.MouseEvent JavaDoc;
24 import java.awt.event.MouseListener JavaDoc;
25
26 import javax.swing.JButton JavaDoc;
27
28 import org.lucane.applications.whiteboard.WhiteBoard;
29
30 public class LineWidthButton extends JButton JavaDoc
31 implements MouseListener JavaDoc
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 JavaDoc 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 JavaDoc e) {}
56     public void mouseExited(MouseEvent JavaDoc e) {}
57     public void mouseReleased(MouseEvent JavaDoc e) {}
58     public void mousePressed(MouseEvent JavaDoc e) {}
59     public void mouseClicked(MouseEvent JavaDoc 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