This plugin implements the Edit/Options/Fonts command and the dialog displayed when you double click on the text tool.
| 7 | /** This plugin implements the Edit/Options/Fonts command and |
| 8 | the dialog displayed when you double click on the text tool. */ |
| 9 | public class Text implements PlugIn, DialogListener { |
| 10 | private static final String LOC_KEY = "fonts.loc"; |
| 11 | private static final String[] styles = {"Plain", "Bold", "Italic", "Bold+Italic"}; |
| 12 | private static final String[] justifications = {"Left", "Center", "Right"}; |
| 13 | private static GenericDialog gd; |
| 14 | private String font = TextRoi.getDefaultFontName(); |
| 15 | private int fontSize = TextRoi.getDefaultFontSize(); |
| 16 | private int style = TextRoi.getDefaultFontStyle(); |
| 17 | private int justification = TextRoi.getGlobalJustification(); |
| 18 | private int angle; |
| 19 | private boolean antialiased = TextRoi.isAntialiased(); |
| 20 | private Color color = Toolbar.getForegroundColor(); |
| 21 | private String colorName; |
| 22 | |
| 23 | public synchronized void run(String arg) { |
| 24 | if (gd!=null && gd.isVisible()) |
| 25 | gd.toFront(); |
| 26 | else |
| 27 | showDialog(); |
| 28 | } |
| 29 | |
| 30 | private void showDialog() { |
| 31 | ImagePlus imp = WindowManager.getCurrentImage(); |
| 32 | Roi roi = imp!=null?imp.getRoi():null; |
| 33 | TextRoi textRoi = roi!=null&&(roi instanceof TextRoi)?(TextRoi)roi:null; |
| 34 | String fillc = "None"; |
| 35 | TextRoi.setDefaultFillColor(null); |
| 36 | TextRoi.setDefaultAngle(0.0); |
| 37 | if (textRoi!=null) { |
| 38 | Font font = textRoi.getCurrentFont(); |
| 39 | fontSize = font.getSize(); |
| 40 | angle = (int)textRoi.getAngle(); |
| 41 | style = font.getStyle(); |
| 42 | justification = textRoi.getJustification(); |
| 43 | Color c = textRoi.getStrokeColor(); |
| 44 | if (c!=null) color=c; |
| 45 | fillc = Colors.colorToString2(textRoi.getFillColor()); |
| 46 | antialiased = textRoi.getAntiAlias(); |
| 47 | } |
| 48 | colorName = Colors.colorToString2(color); |
| 49 | gd =GUI.newNonBlockingDialog("Fonts"); |
| 50 | gd.addChoice("Font:", getFonts(), font); |
| 51 | gd.addChoice("Style:", styles, styles[style]); |
| 52 | gd.addChoice("Just:", justifications, justifications[justification]); |
| 53 | gd.addChoice("Color:", Colors.getColors(colorName), colorName); |
| 54 | gd.addChoice("Bkgd:", Colors.getColors("None",!"None".equals(fillc)?fillc:null), fillc); |
| 55 | gd.addSlider("Size:", 9, 200, fontSize); |
| 56 | gd.addSlider("Angle:", -90, 90, angle); |
| 57 | gd.addCheckbox("Antialiased text", antialiased); |
| 58 | Point loc = Prefs.getLocation(LOC_KEY); |
| 59 | if (IJ.debugMode) { |
| 60 | Dimension screen = IJ.getScreenSize(); |
| 61 | IJ.log("Fonts: "+loc+" "+screen); |
| 62 | } |
| 63 | if (loc!=null) { |
| 64 | gd.centerDialog(false); |
| 65 | gd.setLocation (loc); |
| 66 | } |
nothing calls this directly
no test coverage detected