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

📄 applicationpreferencespanel.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 JAVA
字号:
/*
* 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.
*/

/*
 * ApplicationPreferencesPanel.java - 14/07/06
 */

package issrg.editor2.configurations;

import issrg.editor2.*;
import issrg.utils.xml.XMLChangeEvent;
import issrg.utils.xml.XMLChangeListener;
import issrg.utils.xml.XMLEditor;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.ResourceBundle;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
 * This class will contain, and collect, the user configured, application
 * settings.
 * <p>
 * This will be found in the Configuration dialog.
 *
 * @author Christian Azzopardi
 */
public class ApplicationPreferencesPanel extends JPanel implements ActionListener, XMLChangeListener
{
    
    JPanel contentPanel;
    private JLabel defaultSigningKey;
    private JTextField signingKeyPath;
    private JButton changeKey;
    private XMLEditor xmlED;
    
    private FileListNodeList WSDLNodeList;
    private FileListNodeList TAPFilesNodeList;
    
    private JPanel WSDLpanel, TAPpanel;
    
    ResourceBundle rbl = ResourceBundle.getBundle("issrg/editor2/PEComponent_i18n");
    String errorHeader = rbl.getString("ErrorHeader"); //contains Error!
    String infoHeader = rbl.getString("InfoHeader"); //contains Info!
    String defaultKeyCaption = rbl.getString("Application_Preferences_Default_Key"); //contains Default Signing Key
    String changeKeyCaption = rbl.getString("Application_Preferences_Change_Key"); //contains Select Key
    String errorMSG1 = rbl.getString("Application_Preferences_OpenError1"); //contains Please Enter a valid FileName
    String WSDLBorderCaption = rbl.getString("Application_Preferences_WSDL_Border"); //contains WSDL Files
    String TAPBorderCaption = rbl.getString("Application_Preferences_TAP_Border"); //contains TAP Files
    String applicationSettingsBorder = rbl.getString("Application_Preferences_Settings_Border"); //contains Other Settings
    
    /** Creates a new instance of ApplicationPreferencesPanel */
    public ApplicationPreferencesPanel(XMLEditor that) 
    {
        this.xmlED = that;
        
        this.setLayout(new BorderLayout());        
        this.add(getContentPanel());
        refresh();
    }
    
    public JPanel getContentPanel()
    {
        contentPanel = new JPanel(new GridBagLayout());

        GridBagConstraints constraints = new GridBagConstraints();
//        constraints.gridx = 0; constraints.gridy = 0;
//        constraints.gridwidth = 1; constraints.gridheight = 1;
//        constraints.weightx = 1; constraints.weighty = 1;
//        constraints.fill = GridBagConstraints.BOTH;
//        constraints.anchor = GridBagConstraints.CENTER;
//        
//        WSDLpanel = new JPanel(new BorderLayout());
//        WSDLNodeList = new FileListNodeList(this.xmlED, ".wsdd", this, "WSDDFiles");
//        WSDLNodeList.setCaption("ADD_BUTTON", rbl.getString("AddWSDLButton"));
//        WSDLNodeList.setCaption("DELETE_BUTTON", rbl.getString("DeleteButton"));
//        WSDLNodeList.setCaption("REPLACE_BUTTON", rbl.getString("AddHTTPButton"));
//        WSDLNodeList.setPreferredSize(new Dimension(275,150));
//        WSDLpanel.add(WSDLNodeList, BorderLayout.CENTER);
//        WSDLpanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), WSDLBorderCaption));
//        contentPanel.add(WSDLpanel, constraints);
//        
//        constraints.gridx = 1; constraints.gridy = 0;
//        constraints.gridwidth = 1; constraints.gridheight = 1;
//        constraints.weightx = 1; constraints.weighty = 1;
//        constraints.fill = GridBagConstraints.BOTH;
//        constraints.anchor = GridBagConstraints.CENTER;
//        
//        TAPpanel = new JPanel(new BorderLayout());
//        TAPFilesNodeList = new FileListNodeList(this.xmlED, ".tap", this, "TAPFiles");
//        TAPFilesNodeList.removeReplaceButton();
//        TAPFilesNodeList.setCaption("ADD_BUTTON", rbl.getString("AddButton"));
//        TAPFilesNodeList.setCaption("DELETE_BUTTON", rbl.getString("DeleteButton"));
//        TAPFilesNodeList.setCaption("REPLACE_BUTTON", rbl.getString("ReplaceButton"));
//        TAPFilesNodeList.setPreferredSize(new Dimension(275,150));
//        TAPpanel.add(TAPFilesNodeList, BorderLayout.CENTER);
//        TAPpanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), TAPBorderCaption));
//        contentPanel.add(TAPpanel, constraints);
        
        defaultSigningKey = new JLabel(defaultKeyCaption);
        signingKeyPath = new JTextField();
        changeKey = new JButton(changeKeyCaption);
        changeKey.addActionListener(this);
        changeKey.setActionCommand("Change_Key");        
        
        JPanel applicationSettings = new JPanel(new GridBagLayout());
        constraints.gridx = 0; constraints.gridy = 1;
        constraints.gridwidth = 1; constraints.gridheight = 1;
        constraints.weightx = 1; constraints.weighty = 1;
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.CENTER;
        applicationSettings.add(defaultSigningKey, constraints);
        
        constraints.gridx = 1; constraints.gridy = 1;
        constraints.gridwidth = 1; constraints.gridheight = 1;
        constraints.weightx = 1; constraints.weighty = 1;
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.CENTER;
        applicationSettings.add(signingKeyPath, constraints);
        
        constraints.gridx = 1; constraints.gridy = 2;
        constraints.gridwidth = 1; constraints.gridheight = 1;
        constraints.weightx = 1; constraints.weighty = 1;
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.CENTER;
        applicationSettings.add(changeKey, constraints);
        
        constraints.gridx = 0; constraints.gridy = 1;
        constraints.gridwidth = 2; constraints.gridheight = 1;
        constraints.weightx = 1; constraints.weighty = 1;
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.CENTER;
        applicationSettings.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), applicationSettingsBorder));
        contentPanel.add(applicationSettings, constraints);
        
        return contentPanel;
    }

    public void actionPerformed(ActionEvent e)
    {
        if (e.getActionCommand().intern().equals("Change_Key"))
        {
            JFileChooser jfc = new JFileChooser();
            jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);   //Choose files and not dirs
            jfc.setCurrentDirectory(new File("."));              //Set home diretory
            int returnVal = jfc.showOpenDialog(this);            //return if ok or cancel were pressed 
            if (returnVal == JFileChooser.APPROVE_OPTION)        //If ok was pressed 
            {
                if (jfc.getSelectedFile().exists())               
                {     
                    replaceItem(jfc.getSelectedFile().getAbsolutePath());
                    signingKeyPath.setText(jfc.getSelectedFile().getAbsolutePath());
                }                        
                else
                {
                    JOptionPane.showMessageDialog(null, errorMSG1, errorHeader, JOptionPane.ERROR_MESSAGE);
                }                
            }  
            else                                                //user hits cancel button from fc dialog
            {                                                   
                return;                                          //will return .. thus not creating new policy
            }
        }
    }
       
    public void replaceItem(String fileName)
    {
        //Setting the New Attributes to Replace --
        String attribs[] = { "FileName" };
        String values[] = { fileName }; 
        xmlED.setAttributeValue(((Element)DomainPolicyEditor.getChildElements(getParentNode()).item(0)) , attribs, values);        
    }
    
    /**
     * The root node of the Current Document.
     *
     * @return   a node with the root Element of the 'pe.cfg' XML file.
     */
    public Node getParentNode()
    {
        return xmlED.DOM.getElementsByTagName("ApplicationSettings").item(0);
    }     
    
    public void XMLChanged(XMLChangeEvent e)
    {
        refresh();
    }
    
    public void refresh()
    {
        if (xmlED == null || xmlED.DOM == null) return;
        
        signingKeyPath.setText(((Element)DomainPolicyEditor.getChildElements(getParentNode()).item(0)).getAttribute("FileName"));
    }
}

⌨️ 快捷键说明

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