/Users/lyon/j4p/src/gui/browser/Main.java

1    package gui.browser; 
2     
3    import futils.WriterUtil; 
4     
5    import javax.swing.*; 
6    import java.awt.*; 
7     
8    /** 
9     * @author  Doug Lyon 
10    * @version 1.0 
11    */ 
12    
13   public class Main extends gui.ClosableJFrame { 
14    
15       private javax.swing.JEditorPane htmlPane = 
16               new javax.swing.JEditorPane(); 
17       private javax.swing.JEditorPane textPane = 
18               new javax.swing.JEditorPane(); 
19    
20       private gui.run.RunTextFieldOld tf; 
21       private gui.run.RunMenuItem om; 
22       private gui.run.RunMenuItem sm; 
23       private gui.run.RunMenuItem vm; 
24       private gui.run.RunMenuItem bm; 
25       private gui.run.RunMenuItem fm; 
26       private gui.run.RunMenuItem em; 
27    
28       BrowserLogic bl = new BrowserLogic(this); 
29    
30       /** 
31        * Overloaded Constructor Browser2 
32        * 
33        */ 
34    
35    
36       public Main() { 
37           super("DocJava Viewer"); 
38           init(); 
39           bl.backward(); 
40       } 
41    
42    
43       public Main(javax.swing.JEditorPane jep) { 
44           super("My BrowserViewer"); 
45           init(); 
46           htmlPane.setText(jep.getText()); 
47       } 
48    
49       public void init() { 
50    
51           java.awt.Container c = getContentPane(); 
52           javax.swing.JMenuBar mb = new javax.swing.JMenuBar(); 
53           gui.keyboard.MnemonicMenu m = new gui.keyboard.MnemonicMenu("File"); 
54    
55           om = new OpenMenuItem(); 
56           sm = new SaveMenuItem(); 
57           vm = new ViewMenuItem(); 
58           fm = new ForwardMenuItem(); 
59           bm = new BackwardMenuItem(); 
60           em = new ExitMenuItem(); 
61           JLabel label = new JLabel("Address"); 
62           tf = new AddressFieldMenuItemOld(); 
63    
64           /** 
65            * Add menuItems to "File" menu. 
66            * 
67            */ 
68    
69    
70           m.add(om); 
71           m.add(sm); 
72           m.add(vm); 
73           m.add(bm); 
74           m.add(fm); 
75           m.add(em); 
76    
77           /** 
78            * Add Components to this container, 
79            * using the default FlowLayout. 
80            */ 
81    
82           mb.add(m); 
83           mb.add(label); 
84           mb.add(tf); 
85           c.add(mb, BorderLayout.NORTH); 
86           c.add(new javax.swing.JScrollPane(htmlPane)); 
87           htmlPane.setEditable(false); 
88           setSize(900, 500); 
89           setLocation(50, 35); 
90           setVisible(true); 
91           htmlPane.addHyperlinkListener(new BrowserListener(bl, tf)); 
92       } 
93    
94       public JEditorPane getHtmlPane() { 
95           return htmlPane; 
96       } 
97    
98    
99       public void setHtml(String s) { 
100          htmlPane.setContentType("text/gui.html"); 
101          htmlPane.setText(s); 
102      } 
103   
104      public void setText(String s) { 
105          textPane.setContentType("text/plain"); 
106          textPane.setText(s); 
107      } 
108   
109      public void setTextField(String s) { 
110          tf.setText(s); 
111      } 
112   
113      public void setString(String s) { 
114          setHtml(s); 
115      } 
116   
117      public static void main(String args[]) { 
118          Main b = new Main(); 
119      } 
120   
121      /** 
122       * The following Named Inner Class that gui.run itseft. 
123       * 
124       */ 
125   
126      class OpenMenuItem extends gui.run.RunMenuItem { 
127          OpenMenuItem() { 
128              super("Open..."); 
129          } 
130   
131          public void run() { 
132              bl.openHtmlFile(); 
133          } 
134      } 
135   
136      class SaveMenuItem extends gui.run.RunMenuItem { 
137          SaveMenuItem() { 
138              super("Save..."); 
139          } 
140   
141          public void run() { 
142              WriterUtil.writeString(htmlPane.getText()); 
143          } 
144      } 
145   
146      class ViewMenuItem extends gui.run.RunMenuItem { 
147          ViewMenuItem() { 
148              super("View Source"); 
149          } 
150   
151          public void run() { 
152              new Main(htmlPane); 
153          } 
154      } 
155   
156      class ForwardMenuItem extends gui.run.RunMenuItem { 
157          ForwardMenuItem() { 
158              super("Forward"); 
159          } 
160   
161          public void run() { 
162              bl.forward(); 
163          } 
164      } 
165   
166      class BackwardMenuItem extends gui.run.RunMenuItem { 
167          BackwardMenuItem() { 
168              super("Backward"); 
169          } 
170   
171          public void run() { 
172              bl.backward(); 
173          } 
174      } 
175   
176      class ExitMenuItem extends gui.run.RunMenuItem { 
177          ExitMenuItem() { 
178              super("Exit"); 
179          } 
180   
181          public void run() { 
182              System.exit(0); 
183          } 
184      } 
185   
186      class AddressFieldMenuItemOld extends gui.run.RunTextFieldOld { 
187          AddressFieldMenuItemOld() { 
188              super(60); 
189          } 
190   
191          public void run() { 
192              bl.processTextField(getText()); 
193          } 
194      } 
195   
196   
197  }