/Users/lyon/j4p/src/futils/Out.java

1    /* 
2     * @author Douglas A. Lyon 
3     * @version  Oct 28, 2002.8:07:15 AM 
4     */ 
5    package futils; 
6     
7    import javax.swing.*; 
8    import java.awt.*; 
9    import java.awt.image.ImageObserver; 
10   import java.io.FileWriter; 
11   import java.io.PrintWriter; 
12    
13   public class Out { 
14       public static void messageDialog(Object o) { 
15           JOptionPane.showMessageDialog(null, o); 
16       } 
17    
18       public static void println() { 
19           System.out.println(); 
20       } 
21    
22       public static void print(int i) { 
23           System.out.print(i); 
24       } 
25    
26       public static void print(double d) { 
27           System.out.print(d); 
28       } 
29    
30       public static void println(long i) { 
31           System.out.println(i); 
32       } 
33    
34       public static void println(double d) { 
35           System.out.println(d); 
36       } 
37    
38       public static void println(Object i) { 
39           System.out.println(i); 
40       } 
41    
42       public static void print(Object d) { 
43           System.out.print(d); 
44       } 
45    
46       public static void main(String args[]) { 
47           messageDialog("Hello World"); 
48       } 
49    
50       public static void saveAsJava( 
51               PrintWriter pw, Image img, ImageObserver io) { 
52           int g; 
53           int width = img.getWidth(io); 
54           int height = img.getHeight(io); 
55           short r[][] = j2d.ImageUtils.getGreenFromImage(img, io); 
56    
57    
58           pw.println("package ip.gui;\n" 
59                   + "\nclass NumImage {\n" 
60                   + "\tpublic static short gray[][] = {\n"); 
61    
62           for (int y = 0; y < height; y++) { 
63               pw.print("{"); 
64               for (int x = 0; x < width - 1; x++) { 
65                   g = r[x][y]; 
66                   if (g < 10) 
67                       pw.print("  "); 
68                   else if (g < 100) pw.print(" "); 
69                   pw.print(g + ", "); 
70               } 
71               pw.println(r[width - 1][y] + "},"); 
72    
73           } 
74           pw.println("};}"); 
75           System.out.println("Done writing image"); 
76    
77       } 
78    
79       public static void saveAsJava(String fn, Image img, ImageObserver io) { 
80           try { 
81               FileWriter fw = 
82                       new FileWriter(fn); 
83               PrintWriter pw = 
84                       new PrintWriter(fw); 
85               saveAsJava(pw, img, io); 
86               pw.flush(); 
87               fw.close(); 
88           } catch (Exception e) { 
89           } 
90       } 
91   } 
92