Webber: A Website Construction Application
HtmlViewer.java
// HTML viewer window
package library.html;
import java.awt.*;
import java.awt.event.*;
import library.*;
public class HtmlViewer extends HtmlWindow {
// Viewer File menu
private String[] FileMenu = { "File",
"New", "New", // Create an empty editor
"Open", "Open", // Load a file into this viewer
"Close", "Close", // Close this viewer
"Save", "Save", // Save this text
"Save As", "SaveAs", // Save this text with a new name
"-", "", // Separator
"Open Editor", "Edit", // Edit the text in this viewer
"Clone Viewer", "View", // Create a clone of this viewer
"-", "", // Separator
"Prior", "Last", // Prior document in history list
"Next", "Next", // Next document in history list
"-", "", // Separator
"Exit", "Exit" // Exit the program
};
// Create and return the viewer button panel
private Panel getButtonPanel() {
Panel p = new Panel(new GridLayout());
p.add(Lib.newButton("<<", "Last", this));
p.add(Lib.newButton(">>", "Next", this));
p.add(Lib.newButton("Clone", "View", this));
p.add(Lib.newButton("Editor", "Edit", this));
return p;
}
// Process action events
public void actionPerformed(ActionEvent e) {
switch (getMenuActionIndex(FileMenu, e.getActionCommand())) {
case 0: htmlFile.emptyEditor(); break; // New file
case 1: htmlFile.openFile(); break; // Open file
case 2: closeWindow(this); break; // Close window
case 3: htmlFile.saveText(); break; // Save file
case 4: htmlFile.saveTextAs(); break; // Save file As
case 6: htmlFile.startEditor(); break; // Edit text
case 7: htmlFile.newViewer(); break; // Clone window
case 9: htmlFile.goHistory(-1); break; // Prior document
case 10: htmlFile.goHistory(1); break; // Next document
case 12: closeAllWindows(); break; // Exit program
default: super.actionPerformed(e); // Propagate
}
}
// Process window activated event to update the text
public void windowActivated(WindowEvent e) {
char[] text = htmlFile.getText(); // Get latest text
if (text!=getText()) setText(text); // Any changes?
super.windowActivated(e); // Call super-class
}
// Process window closed event to update the parent HtmlFile object
public void windowClosed(WindowEvent e) {
super.windowClosed(e); // Call super-class
htmlFile.viewer = null; // Update HtmlFile
}
// Viewer constructor
public HtmlViewer(String title, char[] text, HtmlFile f) {
super(title, f);
reader = new HtmlPage(text) { // Create & customize HTML viewer
public Object getHref(String name) { // Resolve HREF
return htmlFile.getHref(name);
}
public boolean openUrl(String file) { // Retrieve URL text
return htmlFile.openUrl(file);
}
};
initWindow(FileMenu, getButtonPanel(), title, text);
}
}
Go To:
Source Code