Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
Java2.java
1 package ij.util;
2 import ij.*;
3 import ij.Prefs;
4 import java.awt.*;
5 import javax.swing.*;
6 
11 public class Java2 {
12 
13  private static boolean lookAndFeelSet;
14 
15  public static void setAntialiased(Graphics g, boolean antialiased) {
16  Graphics2D g2d = (Graphics2D)g;
17  if (antialiased)
18  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
19  else
20  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
21  }
22 
23  public static void setAntialiasedText(Graphics g, boolean antialiasedText) {
24  Graphics2D g2d = (Graphics2D)g;
25  if (antialiasedText && Prefs.antialiasedText)
26  g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
27  else
28  g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
29  }
30 
31  public static int getStringWidth(String s, FontMetrics fontMetrics, Graphics g) {
32  java.awt.geom.Rectangle2D r = fontMetrics.getStringBounds(s, g);
33  return (int)r.getWidth();
34  }
35 
36  public static void setBilinearInterpolation(Graphics g, boolean bilinearInterpolation) {
37  Graphics2D g2d = (Graphics2D)g;
38  if (bilinearInterpolation && Prefs.interpolateScaledImages)
39  g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
40  else
41  g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
42  }
43 
45  public static void setSystemLookAndFeel() {
46  if (lookAndFeelSet)
47  return;
48  try {
49  if(IJ.isWindows())
50  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
51  else if(!IJ.isMacintosh()) {
52  String s = System.getProperty("java.version");
53  int dot_ver = Integer.parseInt(s.substring(s.lastIndexOf('.')+1, s.length()));
54  if(dot_ver >= 2)
55  UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
56  else
57  UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
58  }
59  }
60  catch(Throwable t){}
61  lookAndFeelSet = true;
62  IJ.register(Java2.class);
63  }
64 
65 
66 }
67