1 package org.catacomb.graph.gui; 2 3 import org.catacomb.datalish.Box; 4 import org.catacomb.report.E; 5 6 import java.awt.Graphics2D; 7 8 import java.awt.Color; 9 10 11 public class PickWorldCanvas extends WorldCanvas { 12 13 static final long serialVersionUID = 1001; 14 15 PickStore pickStore; 16 Builder builder; 17 PickHandler pickHandler; 18 19 BuildPaintInstructor buildPaintInstructor; 20 21 GridPainter gridPainter; 22 23 boolean drawGrid = true; 24 25 26 public PickWorldCanvas(int w, int h, boolean interact) { 27 super(w, h, interact); 28 29 pickStore = new PickStore(); 30 builder = new Builder(getPainter(), pickStore); 31 pickHandler = new PickHandler(pickStore, getWorldTransform()); 32 prependHandler(pickHandler); 33 gridPainter = new GridPainter(); 34 35 } 36 37 38 public void setXAxisLabel(String s) { 39 gridPainter.setXAxisLabel(s); 40 } 41 42 public void setBg(Color c) { 43 super.setBg(c); 44 if (gridPainter != null) { 45 gridPainter.setGridBackground(c); 46 } 47 } 48 49 50 public void setNoGrid() { 51 gridPainter = null; 52 } 53 54 public void setShowGrid(boolean b) { 55 drawGrid = b; 56 } 57 58 59 public void setBuildPaintInstructor(BuildPaintInstructor pi) { 60 buildPaintInstructor = pi; 61 if (pi instanceof PickListener) { 62 setPickListener((PickListener)pi); 63 } 64 } 65 66 67 public void setPickListener(PickListener pl) { 68 pickHandler.setPickListener(pl); 69 } 70 71 72 public void setGridColor(Color c) { 73 if (gridPainter != null) { 74 gridPainter.setGridColor(c); 75 } 76 } 77 78 public void setAxisColor(Color c) { 79 if (gridPainter != null) { 80 gridPainter.setAxisColor(c); 81 } 82 } 83 84 85 public void prePaint(Graphics2D g) { 86 builder.clear(); 87 builder.setCanvasSize(getWidth(), getHeight()); 88 89 if (drawGrid && gridPainter != null) { 90 gridPainter.paint(painter); 91 } 92 93 } 94 95 96 public void postPaint(Graphics2D g) { 97 if (mouse.isDown()) { 98 99 } else { 100 pickHandler.echoPaint(painter, showTooltips()); 101 } 102 } 103 104 105 public void paint2D(Graphics2D g) { 106 107 applyAAPreference(g); 108 109 if (buildPaintInstructor != null) { 110 buildPaintInstructor.instruct(painter, builder); 111 112 } else if (paintInstructor != null) { 113 paintInstructor.instruct(painter); 114 } 115 } 116 117 118 public void attach(Object obj) { 119 boolean done = false; 120 121 if (obj instanceof BuildPaintInstructor) { 122 setBuildPaintInstructor((BuildPaintInstructor)obj); 123 done = true; 124 125 } else if (obj instanceof PaintInstructor) { 126 setPaintInstructor((PaintInstructor)obj); 127 done = true; 128 } 129 130 if (obj instanceof PickListener) { 131 setPickListener((PickListener)obj); 132 done = true; 133 } 134 135 if (!done) { 136 E.error(" - cant attach " + obj + " to a PickWorldCanvas"); 137 } 138 139 } 140 141 142 public void setOnGridAxes() { 143 gridPainter.setOnGridAxes(); 144 } 145 146 147 public void reframe() { 148 if (buildPaintInstructor != null) { 149 Box box = buildPaintInstructor.getLimitBox(painter); 150 frameToBox(box); 151 152 } else if (paintInstructor != null) { 153 Box box = paintInstructor.getLimitBox(); 154 frameToBox(box); 155 156 } else { 157 E.shortWarning("no paint instructor?"); 158 } 159 160 } 161 162 163 164 165 166 167 }