MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / getMacroCode

Method getMacroCode

ij/src/main/java/ij/gui/TextRoi.java:557–604  ·  view source on GitHub ↗

Used by the Recorder for recording the text tool.

(String cmd, ImagePlus imp)

Source from the content-addressed store, hash-verified

555
556 /** Used by the Recorder for recording the text tool. */
557 public String getMacroCode(String cmd, ImagePlus imp) {
558 String code = "";
559 boolean script = Recorder.scriptMode();
560 boolean addSelection = cmd.startsWith("Add");
561 if (script && !addSelection)
562 code += "ip = imp.getProcessor();\n";
563 if (script) {
564 String str = "Font.PLAIN";
565 if (style==Font.BOLD)
566 str = "Font.BOLD";
567 else if (style==Font.ITALIC)
568 str = "Font.ITALIC";
569 code += "font = new Font(\""+name+"\", "+str+", "+size+");\n";
570 if (addSelection)
571 return getAddSelectionScript(code);
572 code += "ip.setFont(font);\n";
573 } else {
574 String options = "";
575 if (style==Font.BOLD)
576 options += "bold";
577 if (style==Font.ITALIC)
578 options += " italic";
579 if (antialiasedText)
580 options += " antialiased";
581 if (options.equals(""))
582 options = "plain";
583 code += "setFont(\""+name+"\", "+size+", \""+options+"\");\n";
584 }
585 ImageProcessor ip = imp.getProcessor();
586 ip.setFont(new Font(name, style, size));
587 FontMetrics metrics = ip.getFontMetrics();
588 int fontHeight = metrics.getHeight();
589 if (script)
590 code += "ip.setColor(new Color("+getColorArgs(getStrokeColor())+"));\n";
591 else
592 code += "setColor(\""+Colors.colorToString(getStrokeColor())+"\");\n";
593 if (addSelection) {
594 code += "Overlay.drawString(\""+text()+"\", "+this.x+", "+(this.y+fontHeight)+", "+getAngle()+");\n";
595 code += "Overlay.show();\n";
596 } else {
597 code += (script?"ip.":"")+"drawString(\""+text()+"\", "+this.x+", "+(this.y+fontHeight)+");\n";
598 if (script)
599 code += "imp.updateAndDraw();\n";
600 else
601 code += "//makeText(\""+text()+"\", "+this.x+", "+(this.y+fontHeight)+");\n";
602 }
603 return (code);
604 }
605
606 private String text() {
607 String text = "";

Callers

nothing calls this directly

Calls 13

scriptModeMethod · 0.95
getAddSelectionScriptMethod · 0.95
setFontMethod · 0.95
getFontMetricsMethod · 0.95
getColorArgsMethod · 0.95
colorToStringMethod · 0.95
textMethod · 0.95
getAngleMethod · 0.95
startsWithMethod · 0.80
getStrokeColorMethod · 0.80
equalsMethod · 0.45
getProcessorMethod · 0.45

Tested by

no test coverage detected