Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
Options.java
1 package ij.plugin;
2 import ij.*;
3 import ij.gui.*;
4 import ij.process.*;
5 import ij.io.*;
6 import ij.plugin.filter.*;
7 import java.awt.*;
8 
11 public class Options implements PlugIn {
12 
13  public void run(String arg) {
14  if (arg.equals("misc"))
15  {miscOptions(); return;}
16  else if (arg.equals("width"))
17  {lineWidth(); return;}
18  else if (arg.equals("quality"))
19  {jpegQuality(); return;}
20  else if (arg.equals("cross"))
21  {cross(); return;}
22  else if (arg.equals("conv"))
23  {conversions(); return;}
24  else if (arg.equals("image"))
25  {imageOptions(); return;}
26  }
27 
28  // Miscellaneous Options
29  void miscOptions() {
30  GenericDialog gd = new GenericDialog("Miscellaneous Options", IJ.getInstance());
31  gd.addStringField("Divide by Zero Value:", ""+FloatBlitter.divideByZeroValue, 10);
32  gd.addCheckbox("Use Pointer Cursor", Prefs.usePointerCursor);
33  gd.addCheckbox("Antialiased Text", Prefs.antialiasedText);
34  gd.addCheckbox("Debug Mode", IJ.debugMode);
35  gd.showDialog();
36  if (gd.wasCanceled())
37  return;
38 
39  String divValue = gd.getNextString();
40  if (divValue.equalsIgnoreCase("infinity") || divValue.equalsIgnoreCase("infinite"))
41  FloatBlitter.divideByZeroValue = Float.POSITIVE_INFINITY;
42  else if (divValue.equalsIgnoreCase("NaN"))
43  FloatBlitter.divideByZeroValue = Float.NaN;
44  else if (divValue.equalsIgnoreCase("max"))
45  FloatBlitter.divideByZeroValue = Float.MAX_VALUE;
46  else {
47  Float f;
48  try {f = new Float(divValue);}
49  catch (NumberFormatException e) {f = null;}
50  if (f!=null)
51  FloatBlitter.divideByZeroValue = f.floatValue();
52  }
53 
54  Prefs.usePointerCursor = gd.getNextBoolean();
55  Prefs.antialiasedText = gd.getNextBoolean();
56  IJ.debugMode = gd.getNextBoolean();
57 
58  }
59 
60  void lineWidth() {
61  int width = (int)IJ.getNumber("Line Width:", Line.getWidth());
62  if (width==IJ.CANCELED) return;
63  Line.setWidth(width);
64  ImagePlus imp = IJ.getInstance().getImagePlus();
65  if (imp!=null && imp.isProcessor()) {
66  ImageProcessor ip = imp.getProcessor();
67  ip.setLineWidth(Line.getWidth());
68  }
69  }
70 
71  void jpegQuality() {
72  int quality = (int)IJ.getNumber("JPEG quality (0-100):", JpegWriter.getQuality());
73  if (quality==IJ.CANCELED) return;
74  JpegWriter.setQuality(quality);
75  return;
76  }
77 
78  // Cross hair mark width
79  void cross() {
80  int width = (int)IJ.getNumber("Mark Width:", Analyzer.markWidth);
81  if (width==IJ.CANCELED) return;
82  Analyzer.markWidth = width;
83  return;
84  }
85 
86  // Conversion Options
87  void conversions() {
88  double[] weights = ColorProcessor.getWeightingFactors();
89  boolean unweighted = weights[0]==1d/3d && weights[1]==1d/3d && weights[2]==1d/3d;
90  GenericDialog gd = new GenericDialog("Conversion Options");
91  gd.addCheckbox("Scale When Converting", ImageConverter.getDoScaling());
92  gd.addCheckbox("Unweighted RGB to Grayscale Conversion", unweighted);
93  gd.showDialog();
94  if (gd.wasCanceled())
95  return;
96  ImageConverter.setDoScaling(gd.getNextBoolean());
97  Prefs.unweightedColor = gd.getNextBoolean();
98  if (Prefs.unweightedColor)
99  ColorProcessor.setWeightingFactors(1d/3d, 1d/3d, 1d/3d);
100  else if (unweighted)
101  ColorProcessor.setWeightingFactors(0.299, 0.587, 0.114);
102  return;
103  }
104 
105  void imageOptions() {
106  GenericDialog gd = new GenericDialog("Image Options", IJ.getInstance());
107  gd.addCheckbox("Interpolate Images <100%", Prefs.interpolateScaledImages);
108  gd.addCheckbox("Open Images at 100%", Prefs.open100Percent);
109  gd.addCheckbox("Black Canvas", Prefs.blackCanvas);
110  gd.showDialog();
111  if (gd.wasCanceled())
112  return;
113  boolean interpolate = gd.getNextBoolean();
114  Prefs.open100Percent = gd.getNextBoolean();
115  boolean blackCanvas = gd.getNextBoolean();
116  if (interpolate!=Prefs.interpolateScaledImages) {
117  Prefs.interpolateScaledImages = interpolate;
118  ImagePlus imp = IJ.getInstance().getImagePlus();
119  if (imp!=null)
120  imp.draw();
121  }
122  if (blackCanvas!=Prefs.blackCanvas) {
123  Prefs.blackCanvas = blackCanvas;
124  ImagePlus imp = IJ.getInstance().getImagePlus();
125  if (imp!=null) {
126  ImageCanvas win = imp.getCanvas();
127  if (win!=null) {
128  if (Prefs.blackCanvas) {
129  win.setForeground(Color.white);
130  win.setBackground(Color.black);
131  } else {
132  win.setForeground(Color.black);
133  win.setBackground(Color.white);
134  }
135  imp.repaintWindow();
136  }
137  }
138  }
139  }
140 
141 }