Webber: A Website Construction Application
HtmlEditor.java
// HTML editor window
package library.html;
import java.awt.*;
import java.awt.event.*;
import library.*;
public class HtmlEditor extends HtmlWindow implements TextListener {
// Editor File menu
private String[] FileMenu = { "File",
"New", "New", // Create an empty editor
"Open", "Open", // Load a file into this editor
"Close", "Close", // Close this editor
"Save", "Save", // Save this text
"Save As", "SaveAs", // Save this text with a new name
"-", "", // Separator
"Open Viewer", "View", // View the text in this editor
"Clone Editor", "Edit", // Create a clone of this editor
"-", "", // 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 editor 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", "Edit", this));
p.add(Lib.newButton("Viewer", "View", 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.startViewer(); break; // View text
case 7: htmlFile.newEditor(); 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 closed event to update the parent HtmlFile object
public void windowClosed(WindowEvent e) {
super.windowClosed(e); // Call super-class
htmlFile.editor = null; // Update HtmlFile
}
// Dummy handler for text-changed events
public void textValueChanged(TextEvent e) {}
// Editor constructor
public HtmlEditor(String title, char[] text, HtmlFile f) {
super(title, f);
reader = new HtmlEdit(text) { // Create & customize HTML editor
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);
((HtmlEdit)reader).addTextListener(this); // Monitor text changes
}
}
Go To:
Source Code