⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ifconstraintspaneladvanced.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (c) 2006, University of Kent
 * 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.
 *
 * 1. Neither the name of the University of Kent nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * 2. 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.
 *
 * 3. 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.
 *
 * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
 * IN THE CIRCUMSTANCES.  IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
 * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
 * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
 * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
 * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
 * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
 * SERIOUS FAULTS, IN THIS SOFTWARE.
 *
 * 5. This license is governed, except to the extent that local laws
 * necessarily apply, by the laws of England and Wales.
 */

/*
 * IFConstraintsPanelAdvanced.java - 7/06/06
 */
package issrg.editor2.ifcondition;

import issrg.editor2.*;
import issrg.utils.xml.XMLEditor;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.util.ResourceBundle;
import java.util.Vector;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 *
 * @author Christian Azzopardi
 */
public class IFConstraintsPanelAdvanced extends JPanel implements ActionListener, ItemListener, ChangeListener {
    JPanel advancedPanel;
    JTabbedPane conditionsTabbedPane;
    
    XMLEditor xmlED;
    int index;
    
    GridBagConstraints constraints;
    JRadioButton andSelected;
    JRadioButton orSelected;
    JButton addConditionsBlocks;
    JButton deleteConditionsBlocks;
    
    JFrame owner;
    
    Vector conditionTables;
    
    ResourceBundle rbl = ResourceBundle.getBundle("issrg/editor2/PEComponent_i18n");
    ResourceBundle rb = ResourceBundle.getBundle("issrg/editor2/PEIFConditions_i18n");
    String errorHeader = rbl.getString("ErrorHeader"); //contains Error!
    String andRadioButtonCaption = rbl.getString("IfCondition_Advanced_RadioButton_AND"); //contains Match all of the tabs
    String andRadioButtonCaptionTtip = rbl.getString("IfCondition_RadioButton_AND_Ttip"); //contains Safest Option
    String orRadioButtonCaption = rbl.getString("IfCondition_Advanced_RadioButton_OR"); //contains Match one of the tabs
    String orRadioButtonCaptionTtip = rbl.getString("IfCondition_RadioButton_OR_Ttip"); //contains More Liberal
    String addTabCaption = rbl.getString("IfCondition_AdvancedPanel_Button_Add_Caption"); //contains Add Tab
    String deleteTabCaption = rbl.getString("IfCondition_AdvancedPanel_Button_Remove_Caption"); //contains Remove Tab
    String addButtonTtipCaption = rbl.getString("IfCondition_AdvancedPanel_Add_Ttip"); //contains Adds a new Block
    String deleteButtonTtipCaption = rbl.getString("IfCondition_AdvancedPanel_Delete_Ttip"); //contains Deletes the currently selected Block
    String allOfTheFollowingCaption = rbl.getString("IfCondition_AdvancedPanel_TabName_AND"); //contains Match all of the following
    String oneOfTheFollowingCaption = rbl.getString("IfCondition_AdvancedPanel_TabName_OR"); //contains Match one of the following
    String allConditionsListCaption = rbl.getString("IfCondition_AdvancedPanel_ConditionsList2"); //contains Match all of the following
    String oneConditionsListCaption = rbl.getString("IfCondition_AdvancedPanel_ConditionsList1"); //contains Match one of the following
    String selectDateCaption = rbl.getString("TimeDatePanel_DateDialog_Name"); //contains Select Date
    String selectTimeCaption = rbl.getString("TimePanel_Dialog_Name"); //contains Select Time
    String errorMSG1 = rbl.getString("IfCondition_Error_Empty_Field"); //contains Error! Do not Leave Empty Values!
    
    /** Creates a new instance of IFConstraintsPanelAdvanced */
    public IFConstraintsPanelAdvanced(XMLEditor xmlED, int index, JFrame owner) {
        this.setLayout(new BorderLayout());
        this.xmlED = xmlED;
        this.index = index;
        this.conditionTables = new Vector();
        this.owner = owner;
        
        conditionTables = new Vector();
        this.add(getAdvancedPanel(), BorderLayout.CENTER);
        refresh();
    }
    
    public JPanel getAdvancedPanel() {
        advancedPanel = new JPanel(new GridBagLayout());
        constraints = new GridBagConstraints();
        
        orSelected = new JRadioButton(orRadioButtonCaption);
        orSelected.setToolTipText(orRadioButtonCaptionTtip);
        orSelected.setMnemonic(KeyEvent.VK_N);
        orSelected.addItemListener(this);
        andSelected = new JRadioButton(andRadioButtonCaption);
        andSelected.setToolTipText(andRadioButtonCaptionTtip);
        andSelected.setMnemonic(KeyEvent.VK_L);
        andSelected.addItemListener(this);
        
        ButtonGroup group = new ButtonGroup();
        group.add(orSelected);
        group.add(andSelected);
        andSelected.setSelected(true);
        
        JPanel andOrPanel = new JPanel(new GridBagLayout());
        constraints.gridx = 0; constraints.gridy = 0;
        constraints.weightx = 1; constraints.weighty = 1;
        constraints.gridwidth = 1; constraints.gridheight = 1;
        constraints.anchor = GridBagConstraints.CENTER;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        andOrPanel.add(andSelected, constraints);
        
        constraints.gridx = 1; constraints.gridy = 0;
        constraints.weightx = 1; constraints.weighty = 1;
        constraints.gridwidth = 1; constraints.gridheight = 1;
        constraints.anchor = GridBagConstraints.CENTER;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        andOrPanel.add(orSelected, constraints);
        
        constraints.gridx = 0; constraints.gridy = 0;
        constraints.weightx = 1; constraints.weighty = 1;
        constraints.gridwidth = 1; constraints.gridheight = 1;
        constraints.anchor = GridBagConstraints.PAGE_START;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.insets = new Insets(10,0,0,0);
        advancedPanel.add(andOrPanel, constraints);
        
        addConditionsBlocks = new JButton(addTabCaption);
        addConditionsBlocks.addActionListener(this);
        addConditionsBlocks.setActionCommand("ADD_BLOCK");
        addConditionsBlocks.setToolTipText(addButtonTtipCaption);
        
        deleteConditionsBlocks = new JButton(deleteTabCaption);
        deleteConditionsBlocks.addActionListener(this);
        deleteConditionsBlocks.setActionCommand("DELETE_BLOCK");
        deleteConditionsBlocks.setToolTipText(deleteButtonTtipCaption);
        deleteConditionsBlocks.setEnabled(false);
        
        JPanel addPanel = new JPanel(new GridBagLayout());
        constraints.gridx = 0; constraints.gridy = 0;
        constraints.weightx = 1; constraints.weighty = 1;
        constraints.gridwidth = 1; constraints.gridheight = 1;
        constraints.anchor = GridBagConstraints.CENTER;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.insets = new Insets(0,0,0,0);
        addPanel.add(addConditionsBlocks, constraints);
        
        constraints.insets = new Insets(0,3,0,0);
        constraints.gridx = 1; constraints.gridy = 0;
        constraints.weightx = 1; constraints.weighty = 1;
        constraints.gridwidth = 1; constraints.gridheight = 1;
        constraints.anchor = GridBagConstraints.CENTER;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        addPanel.add(deleteConditionsBlocks, constraints);
        
        constraints.gridx = 0; constraints.gridy = 1;
        constraints.weightx = 1; constraints.weighty = 1;
        constraints.gridwidth = 1; constraints.gridheight = 1;
        constraints.anchor = GridBagConstraints.LINE_START;
        constraints.fill = GridBagConstraints.NONE;
        constraints.insets = new Insets(10,0,0,0);
        advancedPanel.add(addPanel, constraints);
        
        conditionsTabbedPane = new JTabbedPane();
        conditionsTabbedPane.addChangeListener(this);
        conditionsTabbedPane.setPreferredSize(new Dimension(520, 200));
        JPanel tabbedPanel = new JPanel(new BorderLayout());
        tabbedPanel.add(conditionsTabbedPane, BorderLayout.CENTER);
        constraints.gridx = 0; constraints.gridy = 2;
        constraints.weightx = 1; constraints.weighty = 1;
        constraints.gridwidth = 2; constraints.gridheight = 1;
        constraints.anchor = GridBagConstraints.CENTER;
        constraints.fill = GridBagConstraints.BOTH;
        advancedPanel.add(tabbedPanel, constraints);
        
        
        return advancedPanel;
    }
    
    public boolean writeToPolicy() {
        if (xmlED.DOM == null) return false;
        
        NodeList nodesInPolicy = xmlED.DOM.getElementsByTagName("TargetAccessPolicy");
        Element root = ((Element)nodesInPolicy.item(0));
        
        Node parentTargetAccess = root.getElementsByTagName("TargetAccess").item(this.index);
        Node nodeToModify = ((Element)parentTargetAccess).getElementsByTagName("IF").item(0);
        
        Element child = xmlED.DOM.createElement("IF");
        Element typeElement = null;
        
        if (orSelected.isSelected()) {
            typeElement = createElement("OR");
        } else if (andSelected.isSelected()) {
            typeElement = createElement("AND");
        }
        if (child == null || typeElement == null) return false;
        child.appendChild((Node)typeElement);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -