(GenericDialog gd, AWTEvent e)
| 195 | } |
| 196 | |
| 197 | public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) { |
| 198 | int width = imp.getWidth(); |
| 199 | int height = imp.getHeight(); |
| 200 | type = gd.getNextChoice(); |
| 201 | areaPerPoint = gd.getNextNumber(); |
| 202 | color = gd.getNextChoice(); |
| 203 | bold = gd.getNextBoolean(); |
| 204 | centered = gd.getNextBoolean(); |
| 205 | randomOffset = gd.getNextBoolean(); |
| 206 | if (randomOffset) { |
| 207 | centered = false; |
| 208 | if (centerCheckbox!=null) |
| 209 | centerCheckbox.setState(false); |
| 210 | } |
| 211 | double minArea= (width*height)/50000.0; |
| 212 | if (type.equals(types[CROSSES])&&minArea<50.0) |
| 213 | minArea = 50.0; |
| 214 | else if (minArea<16) |
| 215 | minArea = 16.0; |
| 216 | if (areaPerPoint/(pixelWidth*pixelHeight)<minArea) { |
| 217 | String err = "\"Area per Point\" too small"; |
| 218 | if (gd.wasOKed()) |
| 219 | IJ.error("Grid", err); |
| 220 | else |
| 221 | IJ.showStatus(err); |
| 222 | return true; |
| 223 | } |
| 224 | double tileSize = Math.sqrt(areaPerPoint); |
| 225 | tileWidth = tileSize/pixelWidth; |
| 226 | tileHeight = tileSize/pixelHeight; |
| 227 | if (centered) { |
| 228 | xstart = (int)Math.round((width%tileWidth)/2.0); |
| 229 | ystart = (int)Math.round((height%tileHeight)/2.0); |
| 230 | } else if (randomOffset) { |
| 231 | xstart = (int)(random.nextDouble()*tileWidth); |
| 232 | ystart = (int)(random.nextDouble()*tileHeight); |
| 233 | } else { |
| 234 | xstart = (int)(tileWidth/2.0+0.5); |
| 235 | ystart = (int)(tileHeight/2.0+0.5); |
| 236 | } |
| 237 | linesV = (int)((width-xstart)/tileWidth)+1; |
| 238 | linesH = (int)((height-ystart)/tileHeight)+1; |
| 239 | if (gd.invalidNumber()) |
| 240 | return true; |
| 241 | drawGrid(); |
| 242 | return true; |
| 243 | } |
| 244 | |
| 245 | private void drawGrid() { |
| 246 | //IJ.log(centered+" "+xstart+" "+ystart); |
no test coverage detected