📄 permispolicynumber.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.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.StringTokenizer;
import javax.swing.border.TitledBorder;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.netbeans.lib.awtextra.AbsoluteLayout;
import org.netbeans.lib.awtextra.AbsoluteConstraints;
/**
* Classname: PermisPolicyNumber
*
* Description: This class creates the Policy Number window, its associated
* buttons and their methods.
* Version 1.0.
*
* Copyright (c) the authors April 2004
*
* @author Professor D.W.Chadwick
* P. Langley
* U. Mbanaso
*/
public class PermisPolicyNumber extends PermisPolicyPanel
{
private JButton policyCancelButton;
private JButton policyCloseButton;
private JButton policyOkButton;
private JInternalFrame policyNumberInternalFrame;
private JLabel policyNumberLabel;
private JPanel policyButtonPanel;
private JPanel policyIDPanel;
private JTextArea policyNumberTextArea;
private JTextArea policyStatementTextArea;
private JTextField policyNumberTextField;
private PermisPolicyLoader loader;
private PermisPolicyEditorButton parent;
boolean pressed = false;
/**************************************************************************\
* Constructor *
\**************************************************************************/
/**
* Constructor
*/
public PermisPolicyNumber(PermisPolicyEditorButton parent)
{
this.parent = parent;
this.loader = parent.getLoader();
}
public void setPressed(boolean set)
{
this.pressed = set;
}
/**************************************************************************\
* createPolicyNumber *
\**************************************************************************/
/**
* This method creates an instance of the classs and initilaises all the
* relevant variables.
*
* @return A JInternalFrame containing the Policy Number window.
*/
public JInternalFrame createPolicy()
{
policyCancelButton = new JButton();
policyCloseButton = new JButton();
policyOkButton = new JButton();
policyNumberInternalFrame = new JInternalFrame();
policyNumberLabel = new JLabel();
policyButtonPanel = new JPanel();
policyIDPanel = new JPanel();
policyNumberTextArea = new JTextArea();
policyStatementTextArea = new JTextArea();
policyNumberTextField = new JTextField();
setLayout(new BorderLayout());
policyNumberInternalFrame.getContentPane().setLayout(
new AbsoluteLayout());
policyNumberInternalFrame.setTitle(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_frm_title"));
policyNumberInternalFrame.setPreferredSize(new Dimension(300, 300));
policyIDPanel.setLayout(new AbsoluteLayout());
policyIDPanel.setBorder(new TitledBorder(
null,
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_brd"),
TitledBorder.DEFAULT_JUSTIFICATION,
TitledBorder.DEFAULT_POSITION,
new Font("Dialog", 1, 14)));
policyNumberLabel.setText(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_lbl"));
policyIDPanel.add(policyNumberLabel,
new AbsoluteConstraints(10, 40, 90, 30));
policyIDPanel.add(policyNumberTextField,
new AbsoluteConstraints(100, 40, 380, 30));
policyNumberTextArea.setBackground(new Color(204, 204, 204));
policyNumberTextArea.setFont(new Font("Dialog", 0, 14));
policyNumberTextArea.setForeground(new Color(255, 0, 0));
policyNumberTextArea.setLineWrap(true);
policyNumberTextArea.setText(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_desc1"));
policyNumberTextArea.setWrapStyleWord(true);
policyIDPanel.add(policyNumberTextArea,
new AbsoluteConstraints(100, 80, 380, 40));
policyNumberInternalFrame.getContentPane().add(policyIDPanel,
new AbsoluteConstraints(10, 30, 500, 170));
policyOkButton.setMnemonic('O');
policyOkButton.setText(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_btn_ok"));
policyOkButton.setToolTipText(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_tt_btn_ok"));
policyOkButton.setMaximumSize(new Dimension(73, 26));
policyOkButton.setMinimumSize(new Dimension(73, 26));
policyOkButton.setPreferredSize(new Dimension(73, 26));
policyOkButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
policyOkButtonActionPerformed(evt);
}
});
policyButtonPanel.add(policyOkButton);
policyCancelButton.setMnemonic('C');
policyCancelButton.setText(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_btn_cancel"));
policyCancelButton.setToolTipText(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_tt_btn_cancel"));
policyCancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
policyCancelButtonActionPerformed(evt);
}
});
policyButtonPanel.add(policyCancelButton);
policyCloseButton.setMnemonic('l');
policyCloseButton.setText(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_btn_close"));
policyCloseButton.setToolTipText(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_tt_btn_close"));
policyCloseButton.setMaximumSize(new Dimension(73, 26));
policyCloseButton.setMinimumSize(new Dimension(73, 26));
policyCloseButton.setPreferredSize(new Dimension(73, 26));
policyCloseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
policyCloseButtonActionPerformed(evt);
}
});
policyButtonPanel.add(policyCloseButton);
policyNumberInternalFrame.getContentPane().add(policyButtonPanel,
new AbsoluteConstraints(60, 470, 410, 40));
policyStatementTextArea.setBackground(new Color(204, 204, 204));
policyStatementTextArea.setFont(new Font("Dialog", 0, 14));
policyStatementTextArea.setForeground(new Color(255, 0, 0));
policyStatementTextArea.setLineWrap(true);
policyStatementTextArea.setText(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_desc2"));
policyStatementTextArea.setWrapStyleWord(true);
policyNumberInternalFrame.getContentPane().add(policyStatementTextArea,
new AbsoluteConstraints(80, 220, 370, 230));
add(policyNumberInternalFrame, BorderLayout.CENTER);
policyNumberInternalFrame.show();
setSize(530, 679);
policyNumberInternalFrame.setBounds(255, 50, 530, 570);
add(policyNumberInternalFrame);
setBackground(new Color(153, 153, 204));
setLocation(150, 45);
return policyNumberInternalFrame;
}
/**************************************************************************\
* policyCloseButtonActionPerformed *
\**************************************************************************/
/**
* Closes the Policy Number window.
*
* @param evt Close button operated.
*/
private void policyCloseButtonActionPerformed(ActionEvent evt)
{
policyNumberInternalFrame.setVisible(false);
}
/**************************************************************************\
* policyCancelButtonActionPerformed *
\**************************************************************************/
/**
* Clears the data entered by the user from all data entry points
*
* @param evt Cancel button operated.
*/
private void policyCancelButtonActionPerformed(ActionEvent evt)
{
if(pressed){
performRefresh();
}
else{
policyNumberTextField.setText("");
}
}
/**************************************************************************\
* policyOkButtonActionPerformed *
\**************************************************************************/
/**
* Collects the data entered by the use and writes it to the Document
* Object Model (DOM), the PERMIS Policy, in memory. Informs the user of the
* outcome of the operation.
*
* @param evt OK button operated.
*/
private void policyOkButtonActionPerformed(ActionEvent evt)
{
if ( policyNumberTextField.getText().equals("")){
PermisPolicyEditorMenu.dialog.showOkDialog(
ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_num_err_msg"));
return;
}
else if(!validateOID(policyNumberTextField.getText().trim())){
return;
}
else{
PermisPolicyEditorMenu.permisXmlDom.setAttrToRoot(
policyNumberTextField.getText());
//refresh the ReadablePolicy view
if(parent.getPermisParent().getMenuItems().
getReadablePolicy() != null){
parent.getPermisParent().getMenuItems().getReadablePolicy().
comboBoxSetSelectedIndex(1);
}
PermisPolicyEditorMenu.permisXmlDom.showMessage();
}
policyNumberInternalFrame.setVisible(false);
}
/**************************************************************************\
* performRefresh() *
\**************************************************************************/
public void performRefresh()
{
loader.readPolicyNumber(policyNumberTextField);
}
/**************************************************************************\
* validateOID *
\**************************************************************************/
/**
*
*
*/
private boolean validateOID(String text)
{
boolean found = false;
String OID = "([\\d]++)([\\.]{1})([\\d]++)(([\\.]{1})([\\d]++))*+";
/* This expression consist of four groups
* (1)([\\d]++) allows a number of digits
* (2) ([\\.]{1}) must occur ones
* (3) ([\\d]++) the same as 1
* (4) (([\\.]{1}) ([\\d]++))*+ a combination of group 2 and 3 which may
* occur zero or more times
*
*/
Pattern pt = Pattern.compile(OID);
Matcher mr;
mr = pt.matcher(text);
found = mr.matches();
if(found){
return true;
}
policyNumberTextField.requestFocus();
javax.swing.JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("pol_object_id_err"));
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -