示例#1
0
 public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
   this.pfr = pfr;
   String macroOptions = Macro.getOptions();
   if (macroOptions != null) {
     if (macroOptions.indexOf(" interpolate") != -1)
       macroOptions.replaceAll(" interpolate", " interpolation=Bilinear");
     else if (macroOptions.indexOf(" interpolation=") == -1)
       macroOptions = macroOptions + " interpolation=None";
     Macro.setOptions(macroOptions);
   }
   gd = new GenericDialog("Rotate", IJ.getInstance());
   gd.addNumericField("Angle (degrees):", angle, (int) angle == angle ? 1 : 2);
   gd.addNumericField("Grid Lines:", gridLines, 0);
   gd.addChoice("Interpolation:", methods, methods[interpolationMethod]);
   if (bitDepth == 8 || bitDepth == 24)
     gd.addCheckbox("Fill with Background Color", fillWithBackground);
   if (canEnlarge) gd.addCheckbox("Enlarge Image to Fit Result", enlarge);
   else enlarge = false;
   gd.addPreviewCheckbox(pfr);
   gd.addDialogListener(this);
   gd.showDialog();
   drawGridLines(0);
   if (gd.wasCanceled()) {
     return DONE;
   }
   if (!enlarge) flags |= KEEP_PREVIEW; // standard filter without enlarge
   else if (imp.getStackSize() == 1) flags |= NO_CHANGES; // undoable as a "compound filter"
   return IJ.setupDialog(imp, flags);
 }
 public void loadMacros() {
   File f = new File(System.getProperty("user.dir"));
   String[] files = f.list();
   for (int i = 0; i < files.length; i++) {
     try {
       if (files[i].startsWith("macro_")
           && files[i].endsWith(".class")
           && files[i].indexOf('$') == -1) {
         System.out.println(files[i]);
         Class clazz = Class.forName(files[i].substring(0, files[i].length() - ".class".length()));
         Macro macro =
             (Macro)
                 clazz
                     .getConstructor(new Class[] {mudclient_Debug.class})
                     .newInstance(new Object[] {inner});
         String[] commands = macro.getCommands();
         for (int j = 0; j < commands.length; j++) {
           System.out.println("command registered:" + commands[j]);
           mudclient_Debug.macros.put(commands[j], macro);
         }
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
 public String interpret(String text) {
   String textReplaced = text;
   for (Macro macro : macros) {
     textReplaced = textReplaced.replaceAll(macro.getRegex(), macro.getReplacement());
   }
   return textReplaced;
 }
示例#4
0
 public void addMacro(Macro macro) {
   try {
     cpp.addMacro(macro.getName(), FeatureExprLib.True(), macro.getValue());
   } catch (LexerException e) {
     throw new BuildException(e);
   }
 }
示例#5
0
 /** Returns the contents of the next textarea. */
 public String getNextText() {
   String text;
   if (textAreaIndex == 0 && textArea1 != null) {
     // textArea1.selectAll();
     text = textArea1.getText();
     textAreaIndex++;
     if (macro) text = Macro.getValue(macroOptions, "text1", text);
     if (recorderOn) {
       String text2 = text;
       String cmd = Recorder.getCommand();
       if (cmd != null && cmd.equals("Convolve...")) {
         text2 = text.replaceAll("\n", "\\\\n");
         if (!text.endsWith("\n")) text2 = text2 + "\\n";
       } else text2 = text.replace('\n', ' ');
       Recorder.recordOption("text1", text2);
     }
   } else if (textAreaIndex == 1 && textArea2 != null) {
     textArea2.selectAll();
     text = textArea2.getText();
     textAreaIndex++;
     if (macro) text = Macro.getValue(macroOptions, "text2", text);
     if (recorderOn) Recorder.recordOption("text2", text.replace('\n', ' '));
   } else text = null;
   return text;
 }
示例#6
0
 public Macro create(int id, String name) {
   Macro m = (Macro) db.createModel(NAME);
   m.setId(id);
   m.setName(name);
   update(m);
   return m;
 }
  private void save() {
    try {
      File macroFolder = new File(MACRO_FOLDER);
      if (!macroFolder.exists()) {
        macroFolder.mkdir();
      }

      for (Macro macro : macros.values()) {
        if (!macro.isTransient()) {
          // write JSON to config file
          File file = new File(MACRO_FOLDER + "/" + macro.getName() + ".json");
          FileWriter fileWriter = new FileWriter(file);
          try {
            fileWriter.write(macro.toJSON().toJSONString());
          } finally {
            // close file
            fileWriter.close();
          }
        }
      }
    } catch (IOException e) {
      // deal with exception
      e.printStackTrace();
    }
  }
示例#8
0
 void interpolate() {
   Roi roi = imp.getRoi();
   if (roi == null) {
     noRoi("Interpolate");
     return;
   }
   if (roi.getType() == Roi.POINT) return;
   if (IJ.isMacro() && Macro.getOptions() == null) Macro.setOptions("interval=1");
   GenericDialog gd = new GenericDialog("Interpolate");
   gd.addNumericField("Interval:", 1.0, 1, 4, "pixel");
   gd.addCheckbox("Smooth", IJ.isMacro() ? false : smooth);
   gd.showDialog();
   if (gd.wasCanceled()) return;
   double interval = gd.getNextNumber();
   smooth = gd.getNextBoolean();
   Undo.setup(Undo.ROI, imp);
   FloatPolygon poly = roi.getInterpolatedPolygon(interval, smooth);
   int t = roi.getType();
   int type = roi.isLine() ? Roi.FREELINE : Roi.FREEROI;
   if (t == Roi.POLYGON && interval > 1.0) type = Roi.POLYGON;
   if ((t == Roi.RECTANGLE || t == Roi.OVAL || t == Roi.FREEROI) && interval >= 5.0)
     type = Roi.POLYGON;
   if ((t == Roi.LINE || t == Roi.FREELINE) && interval >= 5.0) type = Roi.POLYLINE;
   if (t == Roi.POLYLINE && interval >= 1.0) type = Roi.POLYLINE;
   ImageCanvas ic = imp.getCanvas();
   if (poly.npoints <= 150 && ic != null && ic.getMagnification() >= 12.0)
     type = roi.isLine() ? Roi.POLYLINE : Roi.POLYGON;
   Roi p = new PolygonRoi(poly, type);
   if (roi.getStroke() != null) p.setStrokeWidth(roi.getStrokeWidth());
   p.setStrokeColor(roi.getStrokeColor());
   p.setName(roi.getName());
   transferProperties(roi, p);
   imp.setRoi(p);
 }
  /**
   * @param name
   * @param location
   * @param callback
   */
  public static void run(String name, Location location, MacroCallback callback) {
    MacroCommandExecuter macroCommandExecuter = MacroCommandExecuter.getInstance();

    Macro macro = macroCommandExecuter.getMacro(name);
    if (macro == null) {
      throw new RuntimeException("Can not find macro " + name);
    }

    macro.run(location, callback);
  }
 public void load(Reader reader) {
   try {
     JSONParser jsonParser = new JSONParser();
     JSONObject jsonMacro = (JSONObject) jsonParser.parse(reader);
     Macro macro = Macro.fromJSON(jsonMacro);
     macros.put(macro.getName(), macro);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
示例#11
0
 public void process(long start, long end, String query) throws Throwable {
   try {
     Macro macroProcessor = new Macro(start, end, query);
     query = macroProcessor.toString();
     db.execute(query);
   } catch (Exception e) {
     log.error("Query: " + query);
     throw new Exception("Aggregation failed for: " + query);
   }
 }
示例#12
0
 public Macro get(String name) {
   Map m = db.getMap(NAME);
   Macro c;
   for (Iterator i = m.values().iterator(); i.hasNext(); ) {
     c = (Macro) i.next();
     if (c.getName().equals(name)) {
       return c;
     }
   }
   return null;
 }
示例#13
0
文件: Set.java 项目: tengstrand/Laja
  private void setContextToMacroLocalContextIfVariableExistsInParamaterList() {
    AttributeRef attributeRef = target.getAttributeRef();

    if (attributeRef != null) {
      String variableToSet = attributeRef.getVariableName();

      if (macro != null && macro.getParameters().contains(variableToSet)) {
        context = macro.getLocalContext();
      } else if (target.isNamespaceRef()) {
        throw new RuntimeException("Setting namespaces not implemented.");
      }
    }
  }
 @Nullable
 private String expandMacroSet(
     String str, boolean firstQueueExpand, DataContext dataContext, Iterator<Macro> macros)
     throws Macro.ExecutionCancelledException {
   if (str == null) return null;
   while (macros.hasNext()) {
     Macro macro = macros.next();
     if (macro instanceof SecondQueueExpandMacro && firstQueueExpand) continue;
     String name = "$" + macro.getName() + "$";
     String macroNameWithParamStart = "$" + macro.getName() + "(";
     if (str.contains(name)) {
       String expanded = macro.expand(dataContext);
       // if (dataContext instanceof DataManagerImpl.MyDataContext) {
       //  // hack: macro.expand() can cause UI events such as showing dialogs ('Prompt' macro)
       // which may 'invalidate' the datacontext
       //  // since we know exactly that context is valid, we need to update its event count
       //
       // ((DataManagerImpl.MyDataContext)dataContext).setEventCount(IdeEventQueue.getInstance().getEventCount());
       // }
       if (expanded == null) {
         expanded = "";
       }
       str = StringUtil.replace(str, name, expanded);
     } else if (str.contains(macroNameWithParamStart)) {
       String macroNameWithParamEnd = ")$";
       Map<String, String> toReplace = null;
       int i = str.indexOf(macroNameWithParamStart);
       while (i != -1) {
         int j = str.indexOf(macroNameWithParamEnd, i + macroNameWithParamStart.length());
         if (j > i) {
           String param = str.substring(i + macroNameWithParamStart.length(), j);
           if (toReplace == null) toReplace = new THashMap<String, String>();
           String expanded = macro.expand(dataContext, param);
           if (expanded == null) {
             expanded = "";
           }
           toReplace.put(macroNameWithParamStart + param + macroNameWithParamEnd, expanded);
           i = j + macroNameWithParamEnd.length();
         } else {
           break;
         }
       }
       if (toReplace != null) {
         for (Map.Entry<String, String> entry : toReplace.entrySet()) {
           str = StringUtil.replace(str, entry.getKey(), entry.getValue());
         }
       }
     }
   }
   return str;
 }
 boolean updateMacroOptions() {
   String options = Macro.getOptions();
   int index = options.indexOf("maximum=");
   if (index == -1) return false;
   index += 8;
   int len = options.length();
   while (index < len - 1 && options.charAt(index) != ' ') index++;
   if (index == len - 1) return false;
   int min = (int) Tools.parseDouble(Macro.getValue(options, "minimum", "1"));
   int max = (int) Tools.parseDouble(Macro.getValue(options, "maximum", "999999"));
   options = "size=" + min + "-" + max + options.substring(index, len);
   Macro.setOptions(options);
   return true;
 }
示例#16
0
 /*
  * (non-Javadoc)
  *
  * @see com.hifiremote.jp1.KeyMove#getValueString(com.hifiremote.jp1.RemoteConfiguration)
  */
 public String getValueString(RemoteConfiguration remoteConfig) {
   Remote remote = remoteConfig.getRemote();
   StringBuilder buff = new StringBuilder();
   int keyCode = getMacroKeyCode();
   buff.append(remote.getButtonName(keyCode));
   for (Macro m : remoteConfig.getMacros()) {
     if (m.getKeyCode() == keyCode) {
       buff.append(": (");
       buff.append(m.getValueString(remoteConfig));
       buff.append(')');
       break;
     }
   }
   return buff.toString();
 }
示例#17
0
 /** Returns the contents of the next text field. */
 public String getNextString() {
   String theText;
   if (stringField == null) return "";
   TextField tf = (TextField) (stringField.elementAt(sfIndex));
   theText = tf.getText();
   if (macro) {
     String label = (String) labels.get((Object) tf);
     theText = Macro.getValue(macroOptions, label, theText);
     if (theText != null
         && (theText.startsWith("&") || label.toLowerCase(Locale.US).startsWith(theText))) {
       // Is the value a macro variable?
       if (theText.startsWith("&")) theText = theText.substring(1);
       Interpreter interp = Interpreter.getInstance();
       String s = interp != null ? interp.getVariableAsString(theText) : null;
       if (s != null) theText = s;
     }
   }
   if (recorderOn) {
     String s = theText;
     if (s != null
         && s.length() >= 3
         && Character.isLetter(s.charAt(0))
         && s.charAt(1) == ':'
         && s.charAt(2) == '\\')
       s = s.replaceAll("\\\\", "\\\\\\\\"); // replace "\" with "\\" in Windows file paths
     if (!smartRecording || !s.equals((String) defaultStrings.elementAt(sfIndex)))
       recordOption(tf, s);
     else if (Recorder.getCommandOptions() == null) Recorder.recordOption(" ");
   }
   sfIndex++;
   return theText;
 }
示例#18
0
 /** Returns the index of the selected item in the next popup menu. */
 public int getNextChoiceIndex() {
   if (choice == null) return -1;
   Choice thisChoice = (Choice) (choice.elementAt(choiceIndex));
   int index = thisChoice.getSelectedIndex();
   if (macro) {
     String label = (String) labels.get((Object) thisChoice);
     String oldItem = thisChoice.getSelectedItem();
     int oldIndex = thisChoice.getSelectedIndex();
     String item = Macro.getValue(macroOptions, label, oldItem);
     if (item != null && item.startsWith("&")) // value is macro variable
     item = getChoiceVariable(item);
     thisChoice.select(item);
     index = thisChoice.getSelectedIndex();
     if (index == oldIndex && !item.equals(oldItem)) {
       // is value a macro variable?
       Interpreter interp = Interpreter.getInstance();
       String s = interp != null ? interp.getStringVariable(item) : null;
       if (s == null)
         IJ.error(getTitle(), "\"" + item + "\" is not a valid choice for \"" + label + "\"");
       else item = s;
     }
   }
   if (recorderOn) {
     int defaultIndex = ((Integer) (defaultChoiceIndexes.elementAt(choiceIndex))).intValue();
     if (!(smartRecording && index == defaultIndex)) {
       String item = thisChoice.getSelectedItem();
       if (!(item.equals("*None*") && getTitle().equals("Merge Channels")))
         recordOption(thisChoice, thisChoice.getSelectedItem());
     }
   }
   choiceIndex++;
   return index;
 }
示例#19
0
 public static String applyMacroes(String aboutLocal) {
   return Arrays.asList(Macro.values())
       .stream()
       .map(x -> (Function<String, String>) x)
       .reduce(x -> x, (x, y) -> x.compose(y))
       .apply(aboutLocal);
 }
示例#20
0
 void fitSpline() {
   Roi roi = imp.getRoi();
   if (roi == null) {
     noRoi("Spline");
     return;
   }
   int type = roi.getType();
   boolean segmentedSelection = type == Roi.POLYGON || type == Roi.POLYLINE;
   if (!(segmentedSelection
       || type == Roi.FREEROI
       || type == Roi.TRACED_ROI
       || type == Roi.FREELINE)) {
     IJ.error("Spline", "Polygon or polyline selection required");
     return;
   }
   if (roi instanceof EllipseRoi) return;
   PolygonRoi p = (PolygonRoi) roi;
   if (!segmentedSelection) {
     if (p.subPixelResolution()) p = trimFloatPolygon(p, p.getUncalibratedLength());
     else p = trimPolygon(p, p.getUncalibratedLength());
   }
   String options = Macro.getOptions();
   if (options != null && options.indexOf("straighten") != -1) p.fitSplineForStraightening();
   else if (options != null && options.indexOf("remove") != -1) p.removeSplineFit();
   else p.fitSpline();
   imp.draw();
   LineWidthAdjuster.update();
 }
示例#21
0
 void runMacro(String arg) {
   Roi roi = imp.getRoi();
   if (IJ.macroRunning()) {
     String options = Macro.getOptions();
     if (options != null
         && (options.indexOf("grid=") != -1 || options.indexOf("interpolat") != -1)) {
       IJ.run("Rotate... ", options); // run Image>Transform>Rotate
       return;
     }
   }
   if (roi == null) {
     noRoi("Rotate>Selection");
     return;
   }
   roi = (Roi) roi.clone();
   if (arg.equals("rotate")) {
     double d = Tools.parseDouble(angle);
     if (Double.isNaN(d)) angle = "15";
     String value = IJ.runMacroFile("ij.jar:RotateSelection", angle);
     if (value != null) angle = value;
   } else if (arg.equals("enlarge")) {
     String value = IJ.runMacroFile("ij.jar:EnlargeSelection", enlarge);
     if (value != null) enlarge = value;
     Roi.previousRoi = roi;
   }
 }
 /**
  * Saves statistics for one particle in a results table. This is a method subclasses may want to
  * override.
  */
 protected void saveResults(ImageStatistics stats, Roi roi) {
   analyzer.saveResults(stats, roi);
   if (recordStarts) {
     rt.addValue("XStart", stats.xstart);
     rt.addValue("YStart", stats.ystart);
   }
   if (addToManager) {
     if (roiManager == null) {
       if (Macro.getOptions() != null && Interpreter.isBatchMode())
         roiManager = Interpreter.getBatchModeRoiManager();
       if (roiManager == null) {
         Frame frame = WindowManager.getFrame("ROI Manager");
         if (frame == null) IJ.run("ROI Manager...");
         frame = WindowManager.getFrame("ROI Manager");
         if (frame == null || !(frame instanceof RoiManager)) {
           addToManager = false;
           return;
         }
         roiManager = (RoiManager) frame;
       }
       if (resetCounter) roiManager.runCommand("reset");
     }
     if (imp.getStackSize() > 1) roi.setPosition(imp.getCurrentSlice());
     if (lineWidth != 1) roi.setStrokeWidth(lineWidth);
     roiManager.add(imp, roi, rt.getCounter());
   }
   if (showResults) rt.addResults();
 }
示例#23
0
 @SuppressWarnings("unchecked")
 @Override
 public Component getTableCellEditorComponent(
     JTable table, Object value, boolean isSelected, int row, int column) {
   if (value == null) {
     return null;
   }
   this.value = (T) value;
   this.table = table;
   if (panelClass == (Class<?>) MacroDefinitionBox.class) {
     if (value instanceof Hex) {
       button.setText(Macro.getValueString((Hex) value, remoteConfig));
     } else {
       button.setText(Macro.getValueString((List<KeySpec>) value));
     }
   } else {
     button.setText(this.value.toString());
   }
   return button;
 }
示例#24
0
 private void parsePPDefine(CElement parent) throws CModelException, OffsetLimitReachedException {
   int startOffset = fLexer.currentToken().getOffset();
   int nameStart = 0;
   int nameEnd = 0;
   String name = null;
   IToken t = nextToken();
   if (t.getType() == IToken.tIDENTIFIER) {
     nameStart = fLexer.currentToken().getOffset();
     nameEnd = fLexer.currentToken().getEndOffset();
     name = t.getImage();
   }
   if (name == null) {
     return;
   }
   int endOffset = skipToNewLine();
   Macro macro = new Macro(parent, name);
   SourceManipulationInfo macroInfo = macro.getSourceManipulationInfo();
   macroInfo.setIdPos(nameStart, nameEnd - nameStart);
   macroInfo.setPos(startOffset, endOffset - startOffset);
   parent.addChild(macro);
 }
示例#25
0
 void abortPluginOrMacro(ImagePlus imp) {
   if (imp != null) {
     ImageWindow win = imp.getWindow();
     if (win != null) {
       win.running = false;
       win.running2 = false;
     }
   }
   Macro.abort();
   Interpreter.abort();
   if (Interpreter.getInstance() != null) IJ.beep();
 }
示例#26
0
 private void rotate(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (IJ.macroRunning()) {
     String options = Macro.getOptions();
     if (options != null
         && (options.indexOf("grid=") != -1 || options.indexOf("interpolat") != -1)) {
       IJ.run("Rotate... ", options); // run Image>Transform>Rotate
       return;
     }
   }
   (new RoiRotator()).run("");
 }
示例#27
0
 /**
  * Returns the contents of the next numeric field, or NaN if the field does not contain a number.
  */
 public double getNextNumber() {
   if (numberField == null) return -1.0;
   TextField tf = (TextField) numberField.elementAt(nfIndex);
   String theText = tf.getText();
   String label = null;
   if (macro) {
     label = (String) labels.get((Object) tf);
     theText = Macro.getValue(macroOptions, label, theText);
     // IJ.write("getNextNumber: "+label+"  "+theText);
   }
   String originalText = (String) defaultText.elementAt(nfIndex);
   double defaultValue = ((Double) (defaultValues.elementAt(nfIndex))).doubleValue();
   double value;
   boolean skipRecording = false;
   if (theText.equals(originalText)) {
     value = defaultValue;
     if (smartRecording) skipRecording = true;
   } else {
     Double d = getValue(theText);
     if (d != null) value = d.doubleValue();
     else {
       // Is the value a macro variable?
       if (theText.startsWith("&")) theText = theText.substring(1);
       Interpreter interp = Interpreter.getInstance();
       value = interp != null ? interp.getVariable2(theText) : Double.NaN;
       if (Double.isNaN(value)) {
         invalidNumber = true;
         errorMessage = "\"" + theText + "\" is an invalid number";
         value = Double.NaN;
         if (macro) {
           IJ.error(
               "Macro Error",
               "Numeric value expected in run() function\n \n"
                   + "   Dialog box title: \""
                   + getTitle()
                   + "\"\n"
                   + "   Key: \""
                   + label.toLowerCase(Locale.US)
                   + "\"\n"
                   + "   Value or variable name: \""
                   + theText
                   + "\"");
         }
       }
     }
   }
   if (recorderOn && !skipRecording) {
     recordOption(tf, trim(theText));
   }
   nfIndex++;
   return value;
 }
示例#28
0
 /** Returns the state of the next checkbox. */
 public boolean getNextBoolean() {
   if (checkbox == null) return false;
   Checkbox cb = (Checkbox) (checkbox.elementAt(cbIndex));
   if (recorderOn) recordCheckboxOption(cb);
   boolean state = cb.getState();
   if (macro) {
     String label = (String) labels.get((Object) cb);
     String key = Macro.trimKey(label);
     state = isMatch(macroOptions, key + " ");
   }
   cbIndex++;
   return state;
 }
示例#29
0
 /** Returns the selected item in the next popup menu. */
 public String getNextChoice() {
   if (choice == null) return "";
   Choice thisChoice = (Choice) (choice.elementAt(choiceIndex));
   String item = thisChoice.getSelectedItem();
   if (macro) {
     String label = (String) labels.get((Object) thisChoice);
     item = Macro.getValue(macroOptions, label, item);
     if (item != null && item.startsWith("&")) // value is macro variable
     item = getChoiceVariable(item);
   }
   if (recorderOn) recordOption(thisChoice, item);
   choiceIndex++;
   return item;
 }
示例#30
0
 /** Returns the selected item in the next radio button group. */
 public String getNextRadioButton() {
   if (radioButtonGroups == null) return null;
   CheckboxGroup cg = (CheckboxGroup) (radioButtonGroups.elementAt(radioButtonIndex));
   radioButtonIndex++;
   Checkbox checkbox = cg.getSelectedCheckbox();
   String item = "null";
   if (checkbox != null) item = checkbox.getLabel();
   if (macro) {
     String label = (String) labels.get((Object) cg);
     item = Macro.getValue(macroOptions, label, item);
   }
   if (recorderOn) recordOption(cg, item);
   return item;
 }