Exemplo n.º 1
0
  public void mousePressed(MouseEvent e) {
    // super.mousePressed(e);
    ImageProcessor ip = imp.getProcessor();
    ip.setLineWidth(1);
    if (Toolbar.getToolId() == Toolbar.DROPPER) IJ.setTool(Toolbar.RECTANGLE);

    Rectangle flipperRect = new Rectangle(86, 268, 18, 18);
    Rectangle resetRect = new Rectangle(86, 294, 18, 18);
    Rectangle foreground1Rect = new Rectangle(9, 266, 45, 10);
    Rectangle foreground2Rect = new Rectangle(9, 276, 23, 25);
    Rectangle background1Rect = new Rectangle(33, 302, 45, 10);
    Rectangle background2Rect = new Rectangle(56, 277, 23, 25);
    int x = offScreenX(e.getX());
    int y = offScreenY(e.getY());
    long difference = System.currentTimeMillis() - mouseDownTime;
    boolean doubleClick = (difference <= 250);
    mouseDownTime = System.currentTimeMillis();
    if (flipperRect.contains(x, y)) {
      Color c = Toolbar.getBackgroundColor();
      Toolbar.setBackgroundColor(Toolbar.getForegroundColor());
      Toolbar.setForegroundColor(c);
    } else if (resetRect.contains(x, y)) {
      Toolbar.setForegroundColor(new Color(0x000000));
      Toolbar.setBackgroundColor(new Color(0xffffff));
    } else if ((background1Rect.contains(x, y)) || (background2Rect.contains(x, y))) {
      background = true;
      if (doubleClick) editColor();
      ((ColorGenerator) ip).refreshForeground();
      ((ColorGenerator) ip).refreshBackground();
    } else if ((foreground1Rect.contains(x, y)) || (foreground2Rect.contains(x, y))) {
      background = false;
      if (doubleClick) editColor();
      ((ColorGenerator) ip).refreshBackground();
      ((ColorGenerator) ip).refreshForeground();
    } else {
      // IJ.log(" " + difference + " " + doubleClick);
      if (doubleClick) editColor();
      else {
        setDrawingColor(offScreenX(e.getX()), offScreenY(e.getY()), background);
      }
    }
    if (ip instanceof ColorGenerator) {
      if (background) {
        ((ColorGenerator) ip).refreshForeground();
        ((ColorGenerator) ip).refreshBackground();
      } else {
        ((ColorGenerator) ip).refreshBackground();
        ((ColorGenerator) ip).refreshForeground();
      }
    }
  }
Exemplo n.º 2
0
 void editColor() {
   Color c = background ? Toolbar.getBackgroundColor() : Toolbar.getForegroundColor();
   ColorChooser cc =
       new ColorChooser((background ? "Background" : "Foreground") + " Color", c, false);
   c = cc.getColor();
   if (background) Toolbar.setBackgroundColor(c);
   else Toolbar.setForegroundColor(c);
 }
Exemplo n.º 3
0
 private void setBackgroundColor(Color c) {
   Toolbar.setBackgroundColor(c);
   if (Recorder.record)
     Recorder.record("setBackgroundColor", c.getRed(), c.getGreen(), c.getBlue());
 }