1 11 12 package org.objectweb.jac.ide.diagrams; 13 14 import CH.ifa.draw.framework.Tool; 15 import CH.ifa.draw.framework.ToolListener; 16 import CH.ifa.draw.util.PaletteButton; 17 import CH.ifa.draw.util.PaletteListener; 18 import java.util.EventObject ; 19 import javax.swing.BorderFactory ; 20 import javax.swing.ImageIcon ; 21 import javax.swing.border.BevelBorder ; 22 import javax.swing.border.Border ; 23 24 31 public class ToolButton extends PaletteButton implements ToolListener { 32 33 private String name; 34 private Tool tool; 35 36 public ToolButton(PaletteListener listener, ImageIcon icon, String name, Tool tool) { 37 super(listener); 38 tool.addToolListener(this); 39 setEnabled(tool.isUsable()); 40 41 this.tool = tool; 42 this.name = name; 43 44 setIcon(icon); 45 setToolTipText(name); 46 setEnabled(true); 47 setBorder(normalBorder); 48 } 49 50 Border normalBorder = 51 BorderFactory.createCompoundBorder( 52 BorderFactory.createBevelBorder(BevelBorder.RAISED), 53 BorderFactory.createEmptyBorder(2,2,2,2)); 54 Border pressedBorder = 55 BorderFactory.createCompoundBorder( 56 BorderFactory.createBevelBorder(BevelBorder.LOWERED), 57 BorderFactory.createEmptyBorder(2,2,2,2)); 58 59 public Tool getTool() { 60 return tool; 61 } 62 63 public String getName() { 64 return name; 65 } 66 67 public Object attributeValue() { 68 return getTool(); 69 } 70 71 public void toolUsable(EventObject toolEvent) { 72 setEnabled(true); 73 } 74 75 public void toolUnusable(EventObject toolEvent) { 76 setEnabled(false); 77 setSelected(false); 78 } 79 80 public void toolActivated(EventObject toolEvent) { 81 setBorder(pressedBorder); 82 } 83 84 public void toolDeactivated(EventObject toolEvent) { 85 setBorder(normalBorder); 86 } 87 88 public void toolEnabled(EventObject toolEvent) { 89 setEnabled(true); 90 } 91 92 public void toolDisabled(EventObject toolEvent) { 93 setEnabled(false); 94 } 95 } 96 | Popular Tags |