// Job: Jay's Own Browser, a web browser written in Java by Jay Skeer // Copyright (C) 1996 Jay Skeer, Jay Prime Positive // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // import Jdb; import java.awt.*; import HtmlDocumentPanel; /* History: 1996 02 10: Got a menu bar with working exit item (must be an easyer way) 1996 02 09: Base app works stand-alone, and quits too! 1996 02 12: Begin integration with HTML lexer, parser, and displayer. First test the lexer with stubed parser and displayer. 1996 02 21: Version which displayed text with extra breaks, but would do local hyper links 1996 02 21: Begin reorganizing to fix breaks problem, and to make the browser more general, better organized, and conform to the applet context interface a bit better. 1996 02 23: Still reorganizing -- sigh. */ /** Jay's Own (Html/web/...) Browser (a stand-alone aplication, not an applet) */ public class Job extends Frame implements Runnable { Thread my_thread= null; HtmlDocumentPanel document_panel= null; MenuBar my_menu_bar= null; Menu my_file_menu= null; MenuItem my_file_exit_item= null; MenuItem my_file_sep_item= null; MenuItem my_file_open_item= null; Label my_status_bar= null; String file_path= "No file yet"; // MenuItem my_history_item= null; // String event_history= new String(); public Job() { super("NoName"); Jdb.trace("Job()"); my_thread= new Thread(this); my_thread.start(); } public Job(String s) { super(s); Jdb.trace("Job(\"" + s + "\")"); my_thread= new Thread(this); my_thread.start(); } public void doFileDialog(int x, int y) { Jdb.enter("Job.doFileDialog(x,y)"); JppFileDialog myFileDialog= new JppFileDialog(this, "Open File"); myFileDialog.move(x,y); myFileDialog.show(); Jdb.exit("Job.doFileDialog()"); } public void crashing_doFileDialog(int x, int y) { Jdb.enter("Job.doFileDialog(x,y)"); FileDialog myFileDialog= new FileDialog(this, "Open File", FileDialog.LOAD); myFileDialog.move(x,y); myFileDialog.show(); Jdb.exit("Job.doFileDialog()"); } void showDocument(String url) { document_panel.showDocument(url); } public void doFileOpen(Event e) { JppFileDialog myFileDialog= ((JppFileDialog)e.target); if (null != myFileDialog) { String new_file_path= myFileDialog.getFilePath(); if (null != new_file_path) { if (myFileDialog.fileExists()) { file_path= new_file_path; showDocument(file_path); } else { file_path= "Can't open "+new_file_path; } } } } public boolean action(Event e, Object arg) { boolean rv= false; String trace_line= "Job.action("; if (my_file_exit_item == e.target) { trace_line= trace_line + "exit_item"; my_thread= null; rv= true; } else if (my_file_open_item == e.target) { trace_line= trace_line + "open_item"; rv= true; // } else if (my_history_item == e.target) { // trace_line= trace_line + "history_item"; // rv= true; } else { trace_line= trace_line + "?" + e.target.toString() + "?"; } trace_line= trace_line + ", ?" + e.arg.toString() + "?"; trace_line= trace_line + ", ?" + arg.toString() + "?"; trace_line= trace_line + ")"; Jdb.trace(trace_line); if (my_file_exit_item == e.target) { my_thread= null; rv= true; // } else if (my_history_item == e.target) { // document_panel.setText(event_history); // event_history= new String(); // invalidate(); // rv= true; } else if (my_file_open_item == e.target) { doFileDialog(e.x, e.y); rv= true; } return rv; } public boolean handleEvent(Event e) { switch (e.id) { case Event.WINDOW_DESTROY: my_thread= null; return true; case Event.LOAD_FILE: // generated in nasty fashion in JppFileDialog doFileOpen(e); return true; case Event.MOUSE_DOWN: case Event.MOUSE_UP: JppEvent bogus= new JppEvent(); boolean rv; Jdb.enter("Job.handleEvent(" + bogus.getEventIdName(e.id) + ")"); if (document_panel.insideText(e.x, e.y)) { Jdb.trace("document_panel.insideText("+e.x+","+e.y+")==true"); HotItem i= document_panel.hotItemAt(e.x, e.y); if (null != i) { my_status_bar.setText(i.toString()); String url= i.getUrl(); if (null != url) { showDocument(url); } } rv= true; } else { Jdb.trace("document_panel.insideText("+e.x+","+e.y+")==false"); rv= super.handleEvent(e); } Jdb.exit("Job.handleEvent(" + bogus.getEventIdName(e.id) + ")"); return rv; case Event.MOUSE_MOVE: if (document_panel.insideText(e.x, e.y)) { HotItem i= document_panel.hotItemAt(e.x, e.y); if (null != i) { my_status_bar.setText(i.toString()); } else { my_status_bar.setText( file_path + ":" + document_panel.top_line + "(" + document_panel.doc_lines + ")" ); } rv= true; } else { rv= super.handleEvent(e); } return rv; default: return super.handleEvent(e); } } public void start() { Jdb.trace("Job.start()"); document_panel= new HtmlDocumentPanel(); document_panel.setFont(new Font("Times New Roman", Font.PLAIN, 15)); my_menu_bar= new MenuBar(); my_file_menu= new Menu("File"); my_file_exit_item= new MenuItem("Exit"); my_file_open_item= new MenuItem("Open"); my_file_sep_item= new MenuItem("-"); this.setLayout(new BorderLayout()); my_menu_bar.add(my_file_menu); my_file_menu.add(my_file_open_item); // my_file_menu.add(my_history_item); my_file_menu.add(my_file_sep_item); my_file_menu.add(my_file_exit_item); my_status_bar= new Label("Status"); this.resize(400, 400); this.setMenuBar(my_menu_bar); this.add("South", my_status_bar); this.add("Center", document_panel); // document_panel.setText("This is only a test"); this.show(); } public void stop() { Jdb.trace("Job.stop()"); my_thread= null; } public void run() { Jdb.trace("Job.run()"); start(); while (null != my_thread) { try {Thread.sleep(100);} catch (InterruptedException e){} } my_thread= null; System.exit(0); } public static void main(String args[]) { Job me= new Job("Job"); Jdb.trace("Job.main()"); } }