📄 permisminimalmanual.java
字号:
/*
* Copyright (c) 2000-2005, University of Salford
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the University of Salford nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* PermisMinimalmanual.java
*
* Created on 02 August 2004, 14:23
*/
package issrg.editor.gui;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeSelectionModel;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.ToolTipManager;
import javax.swing.ImageIcon;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import java.util.ResourceBundle;
import java.net.URL;
import java.io.IOException;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Component;
import java.util.ResourceBundle;
/**
* Classname: PermisMinimalmanual
*
* Description: A class that generates the minimal help contents
*
* Version 1.2.4.
*
* Copyright (c) the authors April 2004
*
* @author Professor D.W.Chadwick
*
* U. Mbanaso
*/
public class PermisMinimalmanual extends javax.swing.JFrame implements TreeSelectionListener{
private JEditorPane htmlPane;
private JTree tree;
private URL helpURL;
private static boolean DEBUG = false;
private PermisPolicyEditorMain parent;
/** Creates a new instance of PermisMinimalmanual */
public PermisMinimalmanual(PermisPolicyEditorMain parent) {
// super(parent, ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
// getString("directory_setup"), false);
//(new GridLayout(1,0));
this.parent = parent;
initiComponenets();
this.setSize(650, 497);
this.setTitle( ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_help_minimal_title"));
this.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
this.setResizable(true);
}
private void initiComponenets()
{
//Create the nodes.
DefaultMutableTreeNode top =
new DefaultMutableTreeNode(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_help_content_title"));
createNodes(top);
//Create a tree that allows one selection at a time.
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode
(TreeSelectionModel.SINGLE_TREE_SELECTION);
//Enable tool tips.
ToolTipManager.sharedInstance().registerComponent(tree);
ImageIcon parentIcon = createImageIcon("cross.gif");
if (parentIcon != null) {
tree.setCellRenderer(new MyRenderer(parentIcon));
} else {
// System.err.println("");
}
//Set the icon for leaf nodes.
ImageIcon tutorialIcon = createImageIcon("arrow.gif");
if (tutorialIcon != null) {
tree.setCellRenderer(new MyRenderer(tutorialIcon));
} else {
//System.err.println("");
}
//Listen for when the selection changes.
tree.addTreeSelectionListener(this);
//Create the scroll pane and add the tree to it.
JScrollPane treeView = new JScrollPane(tree);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
//Create the HTML viewing pane.
htmlPane = new JEditorPane();
htmlPane.addHyperlinkListener(new LinkFollower(htmlPane));
htmlPane.setEditable(false);
initHelp();
JScrollPane htmlView = new JScrollPane(htmlPane);
//Add the scroll panes to a split pane.
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setTopComponent(treeView);
splitPane.setBottomComponent(htmlView);
Dimension minimumSize = new Dimension(200, 50);
htmlView.setMinimumSize(minimumSize);
treeView.setMinimumSize(minimumSize);
splitPane.setDividerLocation(100); // ignored in some releases
//of Swing. bug 4101306
//workaround for bug 4101306:
//treeView.setPreferredSize(new Dimension(100, 100));
splitPane.setPreferredSize(new Dimension(500, 500));
//Add the split pane to this panel.
getContentPane().add(splitPane, java.awt.BorderLayout.CENTER);
pack();
// this.getContentPane().add(splitPane);
}
public void exitForm(java.awt.event.WindowEvent evt) {
this.dispose();
}
/** Required by TreeSelectionListener interface. */
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
tree.getLastSelectedPathComponent();
if (node == null) return;
Object nodeInfo = node.getUserObject();
if (node.isLeaf()) {
PermisHelpContents helpNode = (PermisHelpContents)nodeInfo;
displayURL(helpNode.helpURL);
if (DEBUG) {
//System.out.print(helpNode.helpURL + ": \n ");
}
} else {
displayURL(helpURL);
}
if (DEBUG) {
System.out.println(nodeInfo.toString());
}
}
private class PermisHelpContents {
public String helpTextNode;
public URL helpURL;
public PermisHelpContents(String helpNode, String filename) {
helpTextNode = helpNode;
helpURL = PermisHelpContent.class.getResource(filename);
if (helpURL == null) {
//System.err.println(": "
// + filename);
}
}
public String toString() {
return helpTextNode;
}
}
private void initHelp() {
String s = "introduction.html";
//helpURL = HelpTest_2.class.getResource(s);
helpURL = PermisHelpContent.class.getResource(s);
if (helpURL == null) {
// System.err.println("Couldn't open help file: " + s);
} else if (DEBUG) {
// System.out.println("Help URL is " + helpURL);
}
displayURL(helpURL);
}
private void displayURL(URL url) {
try {
if (url != null) {
htmlPane.setPage(url);
} else { //null url
htmlPane.setText(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_help_content_file_not_found"));
if (DEBUG) {
// System.out.println("");
}
}
} catch (IOException e) {
// System.err.println();
}
}
private void createNodes(DefaultMutableTreeNode top) {
DefaultMutableTreeNode category = null;
DefaultMutableTreeNode helpNode = null;
DefaultMutableTreeNode help = null;
category = new DefaultMutableTreeNode("Minimal Manual");
top.add(category);
helpNode = new DefaultMutableTreeNode("Table of Contents");
category.add(helpNode);
/* help = new DefaultMutableTreeNode(new PermisHelpContents
(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_help_tutorial"),
"help.html"));
helpNode.add(help);
*/
help = new DefaultMutableTreeNode(new PermisHelpContents
("Entering an ID",
"entering_id.html"));
helpNode.add(help);
help = new DefaultMutableTreeNode(new PermisHelpContents
(" Specifying LDAP DNs",
"ldap_dn.html"));
helpNode.add(help);
/* help = new DefaultMutableTreeNode(new PermisHelpContents
("Specifying URL (Uniform Resource Locator)",
"url.html"));
helpNode.add(help);
*/
help = new DefaultMutableTreeNode(new PermisHelpContents
("Saying what users can do",
"users_can_do.html"));
helpNode.add(help);
help = new DefaultMutableTreeNode(new PermisHelpContents
(" Saying who can create users",
"create_users.html"));
helpNode.add(help);
help = new DefaultMutableTreeNode(new PermisHelpContents
("Creating a kind of user",
"user_kind.html"));
helpNode.add(help);
help = new DefaultMutableTreeNode(new PermisHelpContents
("Saying what services and machines are available in your part of the grid",
"service_grid.html"));
helpNode.add(help);
help = new DefaultMutableTreeNode(new PermisHelpContents
(" Using Resource Type",
"resource_type.html"));
helpNode.add(help);
}
/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = PermisHelpContent.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
private class MyRenderer extends DefaultTreeCellRenderer {
Icon tutorialIcon;
Icon parentIcon;
public MyRenderer(Icon icon) {
tutorialIcon = icon;
}
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(
tree, value, sel,
expanded, leaf, row,
hasFocus);
if (leaf) {
setIcon(tutorialIcon);
setToolTipText("This is minimal help document");
} else {
setIcon(parentIcon);
setToolTipText(null); //no tool tip
}
return this;
}
protected boolean isTutorialBook(Object value) {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)value;
PermisHelpContents nodeInfo =
(PermisHelpContents)(node.getUserObject());
String title = nodeInfo.helpTextNode;
if (title.indexOf("Tutorial") >= 0) {
return true;
}
return false;
}
}
/*************************************************************************\
* dialog *
\*************************************************************************/
/**
*
*
*/
public void dialog(String title, String message)
{
javax.swing.JOptionPane.showMessageDialog(this.parent,message,title,
JOptionPane.ERROR_MESSAGE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -