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

📄 conditionstable.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.
 */

/*
 * ConditionsTable.java - 31/05/06
 */
package issrg.editor2.ifcondition;

import issrg.editor2.DateChooser;
import issrg.editor2.timedate.DurationDialog;
import issrg.editor2.timedate.TimeDateDialog;
import issrg.editor2.timedate.TimeDialog;
import issrg.utils.xml.XMLEditor;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableColumnModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

/**
 * ConditionsTable creates a table for creating IF conditions. It explicitly
 * initializes column sizes and it uses combo boxes as editors.
 *
 * @author Christian Azzopardi
 */
public class ConditionsTable implements TableColumnModelListener,
        ActionListener, MouseListener {
    public Hashtable varTypeLinks;
    
    /** Model for keeping track of column selections */
    protected ListSelectionModel selectionModel;
    
    public DefaultTableModel tableModel;
    public TableColumnModel model;
    public JTable table;
    XMLEditor xmlED;
    int index;
    int selectedColumn;
    int selectedRow;
    
    ConditionsTableCellEditor rowEditor;
    JFrame owner;
    public JPanel tableView;
    
    Vector column1Store;
    Vector column2Store;
    Vector column3Store;
    Vector column4Store;
    
    /**
     * Loads the String Resources from the '.properties' file.
     */
    ResourceBundle rbl = ResourceBundle.getBundle("issrg/editor2/PEComponent_i18n");
    ResourceBundle rb = ResourceBundle.getBundle("issrg/editor2/PEIFConditions_i18n");
    String cellsToolTip = rbl.getString("ConditionsTable_Cells_Ttip"); //contains Click to make a selection
    String column1 = rbl.getString("ConditionsTable_Column1"); //contains Conditions On
    String column2 = rbl.getString("ConditionsTable_Column2"); //contains Operator
    String column3 = rbl.getString("ConditionsTable_Column3"); //contains Value
    String column4 = rbl.getString("ConditionsTable_Column4"); //contains Delete
    String deleteButtonTtipCaption = rbl.getString("IfCondition_Button_Delete_Ttip"); //contains Deletes this Row.
    String addButtonTtipCaption = rbl.getString("IfCondition_Button_Add_Ttip"); //contains Adds a new Row to the list of Conditions.
    String selectDateCaption = rbl.getString("TimeDatePanel_DateDialog_Name"); //contains Select Date
    String selectTimeCaption = rbl.getString("TimePanel_Dialog_Name"); //contains Select Time
    String selectDurationCaption = rbl.getString("DurationPanel_Dialog_Name"); //contains Select Duration
    
    /**
     * Creates a new instance of ConditionsTable
     */
    public ConditionsTable(XMLEditor xmlED, int index, JFrame owner) {
        this.xmlED = xmlED;
        this.index = index;
        this.owner = owner;
        column1Store = new Vector();
        column2Store = new Vector();
        column3Store = new Vector();
        column4Store = new Vector();
        
        getRelations();
    }
    
    public JPanel getContentPanel() {
        tableView = new JPanel(new GridBagLayout());
        tableModel = new DefaultTableModel();
        tableModel.addColumn(column1);
        tableModel.addColumn(column2);
        tableModel.addColumn(column3);
        tableModel.addColumn(column4);
        
        table = new JTable(tableModel) {
            public TableCellRenderer getCellRenderer(int row, int column) {
                TableColumn tableColumn = getColumnModel().getColumn(column);
                TableCellRenderer renderer = tableColumn.getCellRenderer();
                if (renderer == null) {
                    Class c = getColumnClass(column);
                    if( c.equals(Object.class) ) {
                        Object o = getValueAt(row,column);
                        if( o != null )
                            c = getValueAt(row,column).getClass();
                    }
                    renderer = getDefaultRenderer(c);
                }
                return renderer;
            }
            
            public TableCellEditor getCellEditor(int row, int column) {
                TableColumn tableColumn = getColumnModel().getColumn(column);
                TableCellEditor editor = tableColumn.getCellEditor();
                if (editor == null) {
                    Class c = getColumnClass(column);
                    if( c.equals(Object.class) ) {
                        Object o = getValueAt(row,column);
                        if( o != null )
                            c = getValueAt(row,column).getClass();
                    }
                    editor = getDefaultEditor(c);
                }
                return editor;
            }
        };
        
        rowEditor = new ConditionsTableCellEditor();
        table.setPreferredScrollableViewportSize(new Dimension(500, 120));
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        table.setShowGrid(true);
        
        table.setDefaultRenderer(JComponent.class, new ConditionsTableCellRenderer());
        table.setDefaultEditor(JComponent.class, rowEditor);
        
        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);
        
        //Add the scroll pane to this panel.
        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;
        tableView.add(scrollPane, constraints);
        
        model = table.getColumnModel();
        model.addColumnModelListener(this);
        
        //---- Sets the sizes of the columns... AutoResizeMode must be OFF
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        TableColumn col0 = table.getColumnModel().getColumn(0);
        TableColumn col1 = table.getColumnModel().getColumn(1);
        TableColumn col2 = table.getColumnModel().getColumn(2);
        TableColumn col3 = table.getColumnModel().getColumn(3);
        col0.setPreferredWidth(130);
        col1.setPreferredWidth(100);
        col2.setPreferredWidth(230);
        col3.setPreferredWidth(40);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        
        table.setTableHeader(null);

⌨️ 快捷键说明

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