1 2 package org.catacomb.druid.blocks; 3 4 import org.catacomb.druid.gui.edit.DruButton; 5 import org.catacomb.druid.swing.RolloverEffect; 6 import org.catacomb.interlish.structure.AddableTo; 7 import org.catacomb.report.E; 8 9 10 import java.util.ArrayList; 11 12 13 14 public abstract class AbstractButton extends Panel implements AddableTo { 15 16 17 public String image; 18 19 public String label; 20 public String action; 21 22 public int padding; 23 24 public int xPadding; 25 public int yPadding; 26 27 public String hover; 28 29 public boolean able = true; 30 31 public ArrayList<BaseEffect> effects; 32 33 34 35 public AbstractButton() { 36 } 37 38 39 40 public AbstractButton(String slab) { 41 label = slab; 42 action = label; 43 } 44 45 46 private int getRo(String s, int idef) { 47 int ret = idef; 48 if (s == null) { 49 ret = idef; 50 51 } else if (s.equals("none")) { 52 ret = RolloverEffect.NONE; 53 54 } else if (s.equals("up")) { 55 ret = RolloverEffect.ETCHED_UP; 56 57 } else if (s.equals("down")) { 58 ret = RolloverEffect.ETCHED_DOWN; 59 60 } else { 61 E.warning("unrecognized hover " + s); 62 } 63 return ret; 64 } 65 66 public void applyMenuRollover(DruButton drup) { 67 drup.setRolloverPolicy(getRo(border, RolloverEffect.NONE), 68 getRo(hover, RolloverEffect.ETCHED_UP)); 69 } 70 71 72 public void applyDefaultRollover(DruButton drup) { 73 drup.setRolloverPolicy(getRo(border, RolloverEffect.ETCHED_DOWN), 74 getRo(hover, RolloverEffect.ETCHED_UP)); 75 } 76 77 78 public void applyPadding(DruButton drup) { 79 80 if (xPadding > 0 || yPadding > 0) { 81 drup.setPadding(xPadding, xPadding, yPadding, yPadding); 82 83 } else if (padding > 0) { 84 drup.setPadding(padding); 85 86 } else { 87 drup.setPadding(6, 6, 2, 2); 88 } 89 } 90 91 92 93 94 95 public void add(Object obj) { 96 if (effects == null) { 97 effects = new ArrayList<BaseEffect>(); 98 } 99 if (obj instanceof BaseEffect) { 100 effects.add((BaseEffect)obj); 101 } else { 102 E.error("cant add non effect " + obj); 103 } 104 } 105 106 }