📄 htmlviewerhelpdialog.java
字号:
/*
* Copyright (c) 1996-2001 Borland Software Corporation. All Rights Reserved.
*
* This SOURCE CODE FILE, which has been provided by Borland Software as part
* of an Borland Software product for use ONLY by licensed users of the product,
* includes CONFIDENTIAL and PROPRIETARY information of Borland Software.
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
* OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
* THE PRODUCT.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND SOFTWARE, ITS
* RELATED COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY
* CLAIMS OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR
* DISTRIBUTION OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES
* ARISING OUT OF OR RESULTING FROM THE USE, MODIFICATION, OR
* DISTRIBUTION OF PROGRAMS OR FILES CREATED FROM, BASED ON, AND/OR
* DERIVED FROM THIS SOURCE CODE FILE.
*/
//------------------------------------------------------------------------------
// Copyright (c) 1996-2001 Borland Software Corporation. All Rights Reserved.
//------------------------------------------------------------------------------
package com.borland.samples.dbswing.htmlviewer;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import com.borland.dbswing.*;
import com.borland.dx.dataset.*;
import com.borland.jbcl.control.*;
public class HtmlViewerHelpDialog extends JDialog {
// Data Express
TableDataSet urlTds = new TableDataSet();
Column urlNodeIdCol = new Column();
Column urlUrlCol = new Column();
Column urlHtmlPageCol = new Column();
// Visual components
JSplitPane jSplitPane1 = new JSplitPane();
JSplitPane jSplitPane2 = new JSplitPane();
JdbNavTree urlNameTree = new JdbNavTree();
JdbTable jdbTable1 = new JdbTable();
JdbEditorPane jdbEditorPane1 = new JdbEditorPane();
JdbStatusLabel statusBar = new JdbStatusLabel();
// Layout
JPanel dialogPanel = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
JScrollPane treeScrollPane = new JScrollPane();
TableScrollPane tableScrollPane = new TableScrollPane();
JScrollPane editorPaneScrollPane = new JScrollPane();
// Data for tree nodes and URLs
String protocol = "file:";
String[][] nodeData =
{ { "<root>", "/", "" },
{ "/", "Help system overview", "Overview.html" },
{ "/Help system overview", "Concepts", "Concepts.html" },
{ "/Help system overview/Concepts", "Tree basics", "Concepts_TreeBasics.html" },
{ "/Help system overview/Concepts", "The user data object", "Concepts_TreeDataObject.html" },
{ "/Help system overview/Concepts", "JdbEditorPane", "Concepts_JdbEditorPane.html" },
{ "/Help system overview", "Building help", "BuildingHelp.html" },
{ "/Help system overview/Building help", "JSplitPane", "BuildingHelp_JSplitPane.html" },
{ "/Help system overview/Building help", "Scroll panes", "BuildingHelp_ScrollPanes.html" },
{ "/Help system overview/Building help", "Loading the tree", "BuildingHelp_LoadTree.html" },
{ "/Help system overview", "Using help", "UsingHelp.html" }};
//Construct the dialog
public HtmlViewerHelpDialog(Frame parent) {
super(parent);
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
setup();
}
catch(Exception e) {
DBExceptionHandler.handleException(e);
}
pack();
}
//Component initialization
private void jbInit() throws Exception {
this.setTitle("Sample Help Window");
dialogPanel.setLayout(borderLayout1);
// DataSet columns
urlNodeIdCol.setColumnName("NodeId");
urlNodeIdCol.setDataType(Variant.STRING);
urlNodeIdCol.setCaption("Node ID");
urlUrlCol.setColumnName("URL");
urlUrlCol.setDataType(Variant.STRING);
urlUrlCol.setCaption("URL");
urlHtmlPageCol.setColumnName("HtmlPage");
urlHtmlPageCol.setDataType(Variant.OBJECT);
urlHtmlPageCol.setCaption("HTML Page");
urlNameTree.setCellRenderer(new HtmlViewerTreeRenderer());
urlNameTree.setRootVisible(false); urlNameTree.setDataSet(urlTds);
jdbEditorPane1.setDataSet(urlTds);
jdbEditorPane1.setEnableFileLoading(false);
jdbEditorPane1.setEnableURLLoading(false);
// See note for urlTds_updating() method
jdbTable1.setDataSet(urlTds);
urlTds.addEditListener(new com.borland.dx.dataset.EditAdapter() {
public void updating(DataSet dataSet, ReadWriteRow newRow, ReadRow oldRow) throws Exception {
//urlTds_updating(dataSet, newRow, oldRow);
}
});
jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
treeScrollPane.setMinimumSize(new Dimension(100, 100));
treeScrollPane.setPreferredSize(new Dimension(175, 300));
editorPaneScrollPane.setMinimumSize(new Dimension(200, 100));
tableScrollPane.setMinimumSize(new Dimension(0, 0));
this.getContentPane().add(dialogPanel, null);
dialogPanel.add(statusBar, BorderLayout.SOUTH);
dialogPanel.add(jSplitPane1, BorderLayout.CENTER);
jSplitPane1.add(tableScrollPane, JSplitPane.RIGHT);
jSplitPane1.add(jSplitPane2, JSplitPane.LEFT);
tableScrollPane.getViewport().add(jdbTable1, null);
jSplitPane2.add(editorPaneScrollPane, JSplitPane.RIGHT);
jSplitPane2.add(treeScrollPane, JSplitPane.LEFT);
treeScrollPane.getViewport().add(urlNameTree, null);
editorPaneScrollPane.getViewport().add(jdbEditorPane1, null);
urlTds.setColumns(new Column[] { urlNodeIdCol, urlUrlCol, urlHtmlPageCol });
statusBar.setDataSet(urlTds);
} // jbInit
private void setup() {
// Create a tree model from our data and assign it to our tree. Load the
// data set of URLs; this leaves the data set open and at the first row.
// Now that we're done navigating, connect the two so tree selection
// navigates the data set. Also connect the editor pane to the data set
// so navigation to a new data set row loads its html page. We load the
// first one manually because we don't do any navigation that would trigger
// the load.
urlNameTree.setModel(new TreeModelMaker(nodeData).getModel());
loadDataSet();
urlNameTree.setDataSet(urlTds);
urlNameTree.setColumnName("NodeId");
// Add listener here so we don't try to load pages when creating the table,
// only afterwards, when user requests a page
urlTds.addNavigationListener(new com.borland.dx.dataset.NavigationListener() {
public void navigated(NavigationEvent e) {
urlTds_navigated(e);
}
});
jdbEditorPane1.setDataSet(urlTds);
jdbEditorPane1.setColumnName("HTMLPage");
jdbEditorPane1.setColumnNameURL("URL");
// Load the first page
try {
jdbEditorPane1.setPageURL(urlTds.getString("URL"));
}
catch (DataSetException dse) {
DBExceptionHandler.handleException(dse);
}
}
// Don't load root because it's not visible in tree. To get the effect of a
// root, have a single child under the root. Leaves dataset open and at first row.
private void loadDataSet() {
try {
urlTds.open();
URL url = this.getClass().getResource("HtmlViewerHelpDialog.class");
String path = protocol + url.getFile().substring(0, url.getFile().length() - "classes/com/borland/samples/dbswing/htmlviewer/HtmlViewerHelpDialog.class".length()) + "helpcontent/";
for (int i = 1; i < nodeData.length; ++i) {
urlTds.insertRow(false);
urlTds.setString("NodeId", (nodeData[i][0].equals("/") ? "" : nodeData[i][0]) + "/" + nodeData[i][1]);
System.out.println("HtmlViewerHelpDialog.loadDataSet() loading help content from: " + path + nodeData[i][2]);
urlTds.setString("URL", path + nodeData[i][2]);
urlTds.post();
}
urlTds.first();
}
catch (DataSetException dse) {
DBExceptionHandler.handleException(dse);
}
}
protected void processWindowEvent(WindowEvent e) {
if(e.getID() == WindowEvent.WINDOW_CLOSING) {
dispose();
}
super.processWindowEvent(e);
}
void urlTds_navigated(NavigationEvent e) {
try {
if (urlTds.isNull("HtmlPage")) {
jdbEditorPane1.setPageURL(urlTds.getString("URL"));
}
}
catch (DataSetException dse) {
DBExceptionHandler.handleException(dse);
}
}
// Our goal in this application is to use a data set as a cache for HTML pages.
// However, reloading a cached page involves deserializing a complex serialized
// object, and Swing is often unable to do this. As a workaround, we've disabled
// caching by clearing the HTML column whenever a value is saved to it. We still
// bind our JdbEditorPane's to two columns, because we need to use the column containing
// a URL to load our HTML pages. For this application, performance is acceptable
// without a caching because our help files are small and can be loaded quickly.
// JdbEditorPane may not be useful for more demanding applications.
void urlTds_updating(DataSet dataSet, ReadWriteRow newRow, ReadRow oldRow) throws Exception {
if (oldRow.getObject("HtmlPage") != null) {
newRow.setUnassignedNull("HtmlPage");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -