View Javadoc

1   package org.glassbox.graphview;
2   
3   import java.awt.Color;
4   import java.awt.Component;
5   import java.awt.Graphics;
6   import java.awt.Point;
7   import javax.swing.Icon;
8   import javax.swing.Action;
9   
10  import de.fzi.wim.guibase.graphview.graph.*;
11  import de.fzi.wim.guibase.graphview.view.*;
12  
13  /***
14     An abstract implementation of <code>NodeButtonSet.Button</code> which supplies a round button with an icon.
15     The disc of the button will be same size as the icon. So the icon should be designed so the opaque parts fit into a circle.
16   */
17  public abstract class DiscButton implements NodeButtonSet.Button {
18      private Icon _icon;
19      private Color _bg;
20      private Color _bg_activated;
21      private Color _bg_highlighted;
22      private Action _action;
23  
24      /***
25         Creates a <code>DiscButton</code> with the specified background color.
26       */
27      public DiscButton(Action action, Icon icon, Color bg) {
28  	this (action, icon, bg, bg.brighter(), bg.darker());
29      }
30  
31      /***
32         Creates a <code>DiscButton</code> with the specified background colors.
33       */
34      public DiscButton(Action action, Icon icon, Color bg, Color bghighlighted, Color bgactivated) {
35  	_action = action;
36  	_icon = icon;
37  	_bg = bg;
38  	_bg_highlighted = bghighlighted;
39  	_bg_activated = bgactivated;
40      }
41  
42      public abstract boolean affectsNode(Node node);
43      
44      public abstract String getToolTipText(Node node);
45  
46      public Action getAction() {
47  	return _action;
48      }
49  
50      public int getIconWidth() {
51  	return _icon.getIconWidth();
52      }
53  
54      public int getIconHeight() {
55  	return _icon.getIconHeight();
56      }
57  
58      public void paintIcon(Component c, Graphics g, int x, int y) {
59  	g.setColor(_bg);
60  	paintDisc(g, x, y);
61  	_icon.paintIcon(c, g, x, y);
62      }
63  
64      public void paintRolloverIcon(Component c, Graphics g, int x, int y) {
65  	g.setColor(_bg_highlighted);
66  	paintDisc(g, x, y);
67  	_icon.paintIcon(c, g, x, y);
68      }
69  
70      public void paintPressedIcon(Component c, Graphics g, int x, int y) {
71  	g.setColor(_bg_activated);
72  	paintDisc(g, x, y);
73  	_icon.paintIcon(c, g, x, y);
74      }
75  
76      protected void paintDisc(Graphics g, int x, int y) {
77  	g.fillArc(x, y, getIconWidth(), getIconHeight(), 0, 360);
78      }
79  }