Beispiel #1
0
 /** Redoes the text. */
 final void redo() {
   if (undo == null) return;
   text = new BaseXTextTokens(undo.next());
   rend.setText(text);
   text.pos(undo.cursor());
   text.setCaret();
 }
Beispiel #2
0
 void scale(ImageProcessor ip) {
   if (newWindow) {
     Rectangle r = ip.getRoi();
     ImagePlus imp2 = imp.createImagePlus();
     imp2.setProcessor(title, ip.resize(newWidth, newHeight));
     Calibration cal = imp2.getCalibration();
     if (cal.scaled()) {
       cal.pixelWidth *= 1.0 / xscale;
       cal.pixelHeight *= 1.0 / yscale;
     }
     imp2.show();
     imp.trimProcessor();
     imp2.trimProcessor();
     imp2.changes = true;
   } else {
     if (processStack && imp.getStackSize() > 1) {
       Undo.reset();
       StackProcessor sp = new StackProcessor(imp.getStack(), ip);
       sp.scale(xscale, yscale, bgValue);
     } else {
       ip.snapshot();
       Undo.setup(Undo.FILTER, imp);
       ip.setSnapshotCopyMode(true);
       ip.scale(xscale, yscale);
       ip.setSnapshotCopyMode(false);
     }
     imp.killRoi();
     imp.updateAndDraw();
     imp.changes = true;
   }
 }
Beispiel #3
0
 /** Deletes the selected text. */
 final void delete() {
   if (undo == null) return;
   text.pos(text.cursor());
   undo.cursor(text.cursor());
   text.delete();
   undo.store(text.text(), text.cursor());
   text.setCaret();
 }
Beispiel #4
0
 /**
  * Pastes the specified string.
  *
  * @param txt string to be pasted
  * @return success flag
  */
 final boolean paste(final String txt) {
   if (txt == null || undo == null) return false;
   text.pos(text.cursor());
   undo.cursor(text.cursor());
   if (text.marked()) text.delete();
   text.add(txt);
   undo.store(text.text(), text.cursor());
   return true;
 }
Beispiel #5
0
  /**
   * Sets the output text.
   *
   * @param t output text
   * @param s text size
   */
  public final void setText(final byte[] t, final int s) {
    // remove invalid characters and compare old with new string
    int ns = 0;
    final int ts = text.size();
    final byte[] tt = text.text();
    boolean eq = true;
    for (int r = 0; r < s; ++r) {
      final byte b = t[r];
      // support characters, highlighting codes, tabs and newlines
      if (b >= ' ' || b <= TokenBuilder.MARK || b == 0x09 || b == 0x0A) {
        t[ns++] = t[r];
      }
      eq &= ns < ts && ns < s && t[ns] == tt[ns];
    }
    eq &= ns == ts;

    // new text is different...
    if (!eq) {
      text = new BaseXTextTokens(Arrays.copyOf(t, ns));
      rend.setText(text);
      scroll.pos(0);
    }
    if (undo != null) undo.store(t.length != ns ? Arrays.copyOf(t, ns) : t, 0);
    SwingUtilities.invokeLater(calc);
  }
Beispiel #6
0
 public void undoableEditHappened(UndoableEditEvent e) {
   UndoManager mgr = Undo.getCurrentUndoMgr();
   if (mgr != null && mgr.canRedo()) {
     setToolTipText(mgr.getRedoPresentationName());
     setEnabled(true);
   } else {
     setToolTipText(tipStr);
     setEnabled(false);
   }
 }
Beispiel #7
0
 public VRedoButton(SessionShare sshare, ButtonIF vif, String typ) {
   super(sshare, vif, typ);
   addFocusListener(
       new FocusAdapter() {
         public void focusGained(FocusEvent evt) {
           Undo.restoreLastUndoMgr();
         }
       });
   Undo.addUndoListener(this);
 }
Beispiel #8
0
 public void mousePressed(MouseEvent e) {
   Undo.reset();
   if (!Prefs.noClickToGC) System.gc();
   IJ.showStatus(version() + IJ.freeMemory());
   if (IJ.debugMode) IJ.log("Windows: " + WindowManager.getWindowCount());
 }
Beispiel #9
0
 @Override
 public void keyReleased(final KeyEvent e) {
   if (undo != null) undo.store(text.text(), text.cursor());
 }
Beispiel #10
0
  @Override
  public void keyPressed(final KeyEvent e) {
    if (modifier(e)) return;

    // operations that change the focus are put first..
    if (PREVTAB.is(e)) {
      transferFocusBackward();
      return;
    }
    if (NEXTTAB.is(e)) {
      transferFocus();
      return;
    }
    if (FIND.is(e)) {
      if (find != null) find.requestFocusInWindow();
      return;
    }

    // re-animate cursor
    cursor(true);

    // operations without cursor movement...
    final int fh = rend.fontH();
    if (SCROLLDOWN.is(e)) {
      scroll.pos(scroll.pos() + fh);
      return;
    }
    if (SCROLLUP.is(e)) {
      scroll.pos(scroll.pos() - fh);
      return;
    }
    if (COPY1.is(e) || COPY2.is(e)) {
      copy();
      return;
    }

    // set cursor position and reset last column
    text.pos(text.cursor());
    if (!PREVLINE.is(e) && !NEXTLINE.is(e)) lastCol = -1;

    if (FINDNEXT.is(e) || FINDNEXT2.is(e)) {
      scroll(rend.find(true, true));
      return;
    }
    if (FINDPREV.is(e) || FINDPREV2.is(e)) {
      scroll(rend.find(false, true));
      return;
    }
    if (SELECTALL.is(e)) {
      selectAll();
      return;
    }

    // necessary on Macs as the shift button is pressed for REDO
    final boolean marking =
        e.isShiftDown()
            && !DELNEXT.is(e)
            && !DELPREV.is(e)
            && !PASTE2.is(e)
            && !COMMENT.is(e)
            && !DELLINE.is(e)
            && !REDOSTEP.is(e);
    final boolean nomark = !text.marked();
    if (marking && nomark) text.startMark();
    boolean down = true;
    boolean consumed = true;

    // operations that consider the last text mark..
    final byte[] txt = text.text();
    if (NEXTWORD.is(e)) {
      text.nextToken(marking);
    } else if (PREVWORD.is(e)) {
      text.prevToken(marking);
      down = false;
    } else if (TEXTSTART.is(e)) {
      if (!marking) text.noMark();
      text.pos(0);
      down = false;
    } else if (TEXTEND.is(e)) {
      if (!marking) text.noMark();
      text.pos(text.size());
    } else if (LINESTART.is(e)) {
      text.bol(marking);
      down = false;
    } else if (LINEEND.is(e)) {
      text.eol(marking);
    } else if (NEXTPAGE.is(e)) {
      down(getHeight() / fh, marking);
    } else if (PREVPAGE.is(e)) {
      up(getHeight() / fh, marking);
      down = false;
    } else if (NEXT.is(e)) {
      text.next(marking);
    } else if (PREV.is(e)) {
      text.prev(marking);
      down = false;
    } else if (PREVLINE.is(e)) {
      up(1, marking);
      down = false;
    } else if (NEXTLINE.is(e)) {
      down(1, marking);
    } else if (FINDERROR.is(e)) {
      final int p = text.error();
      if (p != -1) setCaret(p);
    } else {
      consumed = false;
    }

    if (marking) {
      // refresh scroll position
      text.endMark();
      text.checkMark();
    } else if (undo != null) {
      // edit operations...
      if (CUT1.is(e) || CUT2.is(e)) {
        cut();
      } else if (PASTE1.is(e) || PASTE2.is(e)) {
        paste();
      } else if (UNDOSTEP.is(e)) {
        undo();
      } else if (REDOSTEP.is(e)) {
        redo();
      } else if (COMMENT.is(e)) {
        text.comment(rend.getSyntax());
      } else if (DELLINE.is(e)) {
        text.deleteLine();
      } else if (DELLINEEND.is(e) || DELNEXTWORD.is(e) || DELNEXT.is(e)) {
        if (nomark) {
          if (text.pos() == text.size()) return;
          text.startMark();
          if (DELNEXTWORD.is(e)) {
            text.nextToken(true);
          } else if (DELLINEEND.is(e)) {
            text.eol(true);
          } else {
            text.next(true);
          }
          text.endMark();
        }
        undo.cursor(text.cursor());
        text.delete();
      } else if (DELLINESTART.is(e) || DELPREVWORD.is(e) || DELPREV.is(e)) {
        if (nomark) {
          if (text.pos() == 0) return;
          text.startMark();
          if (DELPREVWORD.is(e)) {
            text.prevToken(true);
          } else if (DELLINESTART.is(e)) {
            text.bol(true);
          } else {
            text.prev();
          }
          text.endMark();
        }
        undo.cursor(text.cursor());
        text.delete();
        down = false;
      } else {
        consumed = false;
      }
    }
    if (consumed) e.consume();

    text.setCaret();
    if (txt != text.text()) rend.calc();
    showCursor(down ? 2 : 0);
  }
Beispiel #11
0
 /**
  * Sets the output text.
  *
  * @param t output text
  */
 public void setText(final byte[] t) {
   setText(t, t.length);
   if (undo != null) undo.reset(t);
 }
Beispiel #12
0
 public void actionPerformed(ActionEvent e) {
   UndoManager mgr = Undo.getLastUndoMgr();
   if (mgr != null && mgr.canRedo()) mgr.redo();
 }
Beispiel #13
0
  /*------------------------------------------------------------------*/
  public void run(String arg) {
    ImagePlus imp = WindowManager.getCurrentImage();
    this.imp = imp;
    if (imp == null) {
      IJ.noImage();
      return;
    }
    if ((1 < imp.getStackSize()) && (imp.getType() == imp.COLOR_256)) {
      IJ.error("Stack of color images not supported (use grayscale)");
      return;
    }
    if (1 < imp.getStackSize()) {
      if (imp.getStack().isRGB()) {
        IJ.error("RGB color images not supported (use grayscale)");
        return;
      }
    }
    if (1 < imp.getStackSize()) {
      if (imp.getStack().isHSB()) {
        IJ.error("HSB color images not supported (use grayscale)");
        return;
      }
    }
    if (imp.getType() == imp.COLOR_256) {
      IJ.error("Indexed color images not supported (use grayscale)");
      return;
    }
    if (imp.getType() == imp.COLOR_RGB) {
      IJ.error("Color images not supported (use grayscale)");
      return;
    }

    differentialsDialog dialog =
        new differentialsDialog(IJ.getInstance(), "Differentials", true, operation);
    GUI.center(dialog);
    dialog.setVisible(true);
    cancel = dialog.getCancel();
    operation = dialog.getOperation();
    dialog.dispose();
    if (cancel) {
      return;
    }

    imp.startTiming();
    if (1 < imp.getStackSize()) {
      if (!(imp.getProcessor().getPixels() instanceof float[])) {
        new StackConverter(imp).convertToGray32();
      }
    } else {
      if (!(imp.getProcessor().getPixels() instanceof float[])) {
        new ImageConverter(imp).convertToGray32();
      }
    }
    ImageStack stack = imp.getStack();
    stackSize = stack.getSize();
    Undo.reset();

    setupProgressBar();
    resetProgressBar();

    for (int i = 1; (i <= stackSize); i++) {
      ImageProcessor ip = stack.getProcessor(i);
      doIt(ip);
      imp.getProcessor().resetMinAndMax();
      imp.setSlice(i);
      imp.updateAndRepaintWindow();
    }
    imp.getProcessor().resetMinAndMax();
    imp.setSlice(1);
    imp.updateAndRepaintWindow();
    cleanUpProgressBar();
    IJ.showTime(imp, imp.getStartTime(), "Differentials: ");
    ImageWindow win = imp.getWindow();
    if (win != null) {
      win.running = false;
    }
  } /* end run */