1 package org.catacomb.druid.swing.dnd; 2 3 import org.catacomb.interlish.structure.TextDisplayed; 4 5 6 public class Region { 7 8 9 public static final int DRAG = 1; 10 11 public static final int DROP = 2; 12 13 public static final int DRAG_OR_DROP = 3; 14 15 public static final int CLICK = 0; 16 17 18 19 20 int p_x; 21 int p_y; 22 int p_w; 23 int p_h; 24 25 String p_tag; 26 Object p_ref; 27 int p_action; 28 29 30 public Region(int x, int y, int w, int h, String string, Object object, int a) { 31 p_x = x; 32 p_y = y; 33 p_w = w; 34 p_h = h; 35 p_action = a; 36 } 37 38 39 public Region(int[] xxyy, String s, Object o, int a) { 40 p_x = xxyy[0]; 41 p_y = xxyy[2]; 42 p_w = xxyy[1] - xxyy[0]; 43 p_h = xxyy[3] - xxyy[2]; 44 45 p_tag = s; 46 p_ref = o; 47 p_action = a; 48 } 49 50 51 public String toString() { 52 return ("regoin (" + p_tag + ", " + p_ref + ", " + p_action + ")"); 53 } 54 55 56 public String getTag() { 57 return p_tag; 58 } 59 60 public Object getRef() { 61 return p_ref; 62 } 63 64 65 public boolean equals(Region r) { 66 return (r.p_x == p_x && r.p_y == p_y && r.p_w == p_w && r.p_h == p_h); 67 } 68 69 70 public int getX() { 71 return p_x; 72 } 73 74 public int getY() { 75 return p_y; 76 } 77 78 public int getW() { 79 return p_w; 80 } 81 82 public int getH() { 83 return p_h; 84 } 85 86 87 public boolean contains(int x, int y) { 88 return (x > p_x && x < (p_x + p_w) && y > p_y && y < (p_y + p_h)); 89 } 90 91 92 public boolean acceptsDrops() { 93 return (p_action == DROP || p_action == DRAG_OR_DROP); 94 } 95 96 97 public String getText() { 98 String sret = "-missing-"; 99 if (p_ref instanceof TextDisplayed) { 100 sret = ((TextDisplayed)p_ref).getDisplayText(); 101 } else if (p_ref != null) { 102 sret = p_ref.toString(); 103 } 104 return sret; 105 } 106 107 108 public static boolean canPress(int i) { 109 return (i == DRAG || i == DRAG_OR_DROP || i == CLICK); 110 } 111 112 113 public boolean draggable() { 114 return (p_action == DRAG || p_action == DRAG_OR_DROP); 115 } 116 117 public boolean clickable() { 118 return (p_action == CLICK); 119 } 120 121 }