📄 permisreadablepolicy.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.
*/
package issrg.editor.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
import javax.swing.border.TitledBorder;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.netbeans.lib.awtextra.AbsoluteConstraints;
import org.netbeans.lib.awtextra.AbsoluteLayout;
import java.awt.geom.*;
import java.awt.print.*;
import java.text.AttributedString;
/**
* Classname: PermisReadablePolicy
*
* Description: Provides methods to translate the Document Object Model in
* memory into a series of human readable displays and allows the
* user to select which section is displayed.
* Version 1.0.
*
* Copyright (c) authors April 2004
*
* @author Professor D.W.Chadwick
* P. Langley
* U. Mbanaso
*/
public class PermisReadablePolicy extends JPanel implements ActionListener
{
private static final String PRINT_ACTION = "print";
private static final String EDIT_ACTION = "edit";
private static final String CLOSE_ACTION = "close";
private static final String VIEW_ACTION = "view";
private JButton textPreviewCloseButton;
private JButton textPreviewEditButton;
private JButton textPreviewPrintButton;
private JComboBox textViewComboBox;
private JInternalFrame textPreviewInternalFrame;
private JPanel textPreviewButtonPanel;
private JPanel textPreviewSelectionPanel;
private JScrollPane textPreviewScrollPane;
private JTextArea previewTextArea;
private Document doc;
private PermisPolicyLoader loader;
private PermisPolicyEditorButton parent;
public PermisReadablePolicy()
{
}
/**
* @return
*/
public JInternalFrame createReadablePolicy()
{
textPreviewCloseButton = new JButton();
textPreviewEditButton = new JButton();
textPreviewPrintButton = new JButton();
textViewComboBox = new JComboBox();
textPreviewInternalFrame = new JInternalFrame();
textPreviewButtonPanel = new JPanel();
textPreviewSelectionPanel = new JPanel();
previewTextArea = new JTextArea();
textPreviewScrollPane = new JScrollPane( previewTextArea,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
setLayout(new BorderLayout());
textPreviewInternalFrame.getContentPane().setLayout(
new AbsoluteLayout());
textPreviewInternalFrame.setTitle(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("rea_pol_frm_title"));
textPreviewInternalFrame.setPreferredSize(new Dimension(300, 300));
textPreviewPrintButton.setMnemonic('P');
textPreviewPrintButton.setText("Print");
//enable for printing readable policy
textPreviewPrintButton.setEnabled(false);
textPreviewPrintButton.setText(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("xml_v_btn_print"));
textPreviewPrintButton.setToolTipText(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("xml_v_tt_btn_print"));
textPreviewPrintButton.setMaximumSize(new Dimension(73, 26));
textPreviewPrintButton.setMinimumSize(new Dimension(73, 26));
textPreviewPrintButton.setPreferredSize(new Dimension(73, 26));
textPreviewPrintButton.setActionCommand(PRINT_ACTION);
textPreviewPrintButton.addActionListener(this);
textPreviewButtonPanel.add(textPreviewPrintButton);
textPreviewEditButton.setMnemonic('e');
textPreviewEditButton.setText("Edit");
textPreviewEditButton.setToolTipText("");
textPreviewEditButton.setMaximumSize(new Dimension(73, 26));
textPreviewEditButton.setMinimumSize(new Dimension(73, 26));
textPreviewEditButton.setPreferredSize(new Dimension(73, 26));
textPreviewEditButton.setActionCommand(EDIT_ACTION);
textPreviewEditButton.addActionListener(this);
//textPreviewEditButton.setVisible(false);
//textPreviewButtonPanel.add(textPreviewEditButton);
textPreviewCloseButton.setMnemonic('c');
textPreviewCloseButton.setText(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_btn_close_1"));
textPreviewCloseButton.setToolTipText(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_tt_btn_close"));
textPreviewCloseButton.setMaximumSize(new Dimension(73, 26));
textPreviewCloseButton.setMinimumSize(new Dimension(73, 26));
textPreviewCloseButton.setPreferredSize(new Dimension(73, 26));
textPreviewCloseButton.setActionCommand(CLOSE_ACTION);
textPreviewCloseButton.addActionListener(this);
textPreviewButtonPanel.add(textPreviewCloseButton);
textPreviewInternalFrame.getContentPane().add(textPreviewButtonPanel,
new AbsoluteConstraints(60, 460, 410, 40));
textPreviewSelectionPanel.setLayout(new GridLayout());
textPreviewSelectionPanel.setBorder(new TitledBorder(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("rea_pol_brd_policies")));
textViewComboBox.setBackground(new Color(255, 255, 204));
textViewComboBox.setActionCommand(VIEW_ACTION);
textViewComboBox.addActionListener(this);
textPreviewSelectionPanel.add(textViewComboBox);
textPreviewInternalFrame.getContentPane().add(textPreviewSelectionPanel,
new AbsoluteConstraints(10, 10, 500, 60));
previewTextArea.setEditable(false);
previewTextArea.setLineWrap(true);
previewTextArea.setWrapStyleWord(true);
textPreviewScrollPane.setViewportView(previewTextArea);
textPreviewInternalFrame.getContentPane().add(textPreviewScrollPane,
new AbsoluteConstraints(10, 90, 500, 360));
add(textPreviewInternalFrame, BorderLayout.CENTER);
textPreviewInternalFrame.show();
setSize(530, 679);
textPreviewInternalFrame.setBounds(255, 50, 530, 570);
add(textPreviewInternalFrame);
setBackground(new Color(153, 153, 204));
setLocation(150, 45);
addItems();
return textPreviewInternalFrame;
}
/**
* @param evt
*/
private void textPreviewCloseButtonActionPerformed()
{
textPreviewInternalFrame.setVisible(false);
}
private void textPreviewPrintButtonActionPerformed()
{
}
private void textPreviewEditButtonActionPerformed()
{
}
public void textViewComboBoxActionPerformed()
{
previewTextArea.setText("");
if (textViewComboBox.getItemCount() != 0) {
if ( textViewComboBox.getSelectedIndex() != -1){
int item = textViewComboBox.getSelectedIndex();
switch (item) {
case 0 :
completePolicy();
break;
case 1:
policyNumber();
break;
case 2:
subjectPolicy();
break;
case 3:
soaPolicy();
break;
case 4:
roleHiearchyPolicy();
break;
case 5:
roleAssignmentPolicy();
break;
case 6:
targetPolicy();
break;
case 7:
targetAccessPolicy();
break;
case 8:
actionPolicy();
break;
default:
}
}
}
}
/**
* Add items to the ComboBox
*
*/
private void addItems()
{
textViewComboBox.insertItemAt("Complete Policy", 0);
textViewComboBox.insertItemAt(
ResourceBundle.getBundle( "issrg/editor/gui/Editor_GUI_i18n").
getString("ed_but_btn_Pol_Num"), 1);
textViewComboBox.insertItemAt(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("ed_but_btn_users"), 2);
textViewComboBox.insertItemAt(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("ed_but_btn_tru_man"), 3);
textViewComboBox.insertItemAt(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("ed_but_btn_roles"), 4);
textViewComboBox.insertItemAt(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("ed_but_btn_rol_all"), 5);
textViewComboBox.insertItemAt(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("ed_but_btn_target"), 6);
textViewComboBox.insertItemAt(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("ed_but_btn_Acc_Con"), 7);
textViewComboBox.insertItemAt(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("ed_but_btn_act"), 8);
}
public void completePolicy()
{
policyNumber();
addSeparationLine();
subjectPolicy();
addSeparationLine();
soaPolicy();
addSeparationLine();
roleHiearchyPolicy();
addSeparationLine();
roleAssignmentPolicy();
addSeparationLine();
targetPolicy();
addSeparationLine();
actionPolicy();
addSeparationLine();
targetAccessPolicy();
}
private void policyNumber()
{
this.doc = PermisPolicyEditorMenu.permisXmlDom.getDoc();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -