components/visual-panels/firewall/src/java/vpanels/app/firewall/com/oracle/solaris/vp/panels/firewall/client/swing/PolicyEditPanel.java
changeset 3553 f1d133b09a8c
parent 3552 077ebe3d0d24
child 3554 ef58713bafc4
equal deleted inserted replaced
3552:077ebe3d0d24 3553:f1d133b09a8c
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  */
       
    21 
       
    22 /*
       
    23  * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.panels.firewall.client.swing;
       
    27 
       
    28 import java.awt.Component;
       
    29 import javax.swing.*;
       
    30 import javax.swing.table.*;
       
    31 import com.oracle.solaris.vp.util.swing.InfoLabel;
       
    32 
       
    33 @SuppressWarnings({"serial"})
       
    34 public class PolicyEditPanel extends JPanel {
       
    35 
       
    36     //
       
    37     // Instance data
       
    38     //
       
    39 
       
    40     private InfoLabel info;
       
    41     private PolicyTablePanel applyList;
       
    42     private PolicyTablePanel exceptionList;
       
    43 
       
    44     //
       
    45     // Constructors
       
    46     //
       
    47 
       
    48     public PolicyEditPanel(String applyTitle) {
       
    49         applyList = new PolicyTablePanel(applyTitle);
       
    50     	add(applyList);
       
    51     	setOpaque(false);
       
    52     }
       
    53 
       
    54     public PolicyEditPanel(String applyTitle, String exceptionsTitle) {
       
    55 	this(applyTitle);
       
    56 
       
    57 	exceptionList = new PolicyTablePanel(exceptionsTitle);
       
    58 	add(exceptionList);
       
    59     }
       
    60 
       
    61     //
       
    62     // PolicyEditPanel methods
       
    63     //
       
    64 
       
    65     public void adjustSize() {
       
    66 
       
    67 	JTable table = applyList.getTable();
       
    68 	TableColumnModel model = table.getColumnModel();
       
    69 	TableColumn column = model.getColumn(0);
       
    70 
       
    71 	// A datum of maximum width
       
    72 	String value = "000.000.000.000/00   ";
       
    73 
       
    74 	TableCellRenderer tableRenderer = column.getCellRenderer();
       
    75 	if (tableRenderer == null) {
       
    76 	    tableRenderer = new DefaultTableCellRenderer();
       
    77 	}
       
    78 
       
    79 	Component renderer = tableRenderer.getTableCellRendererComponent(
       
    80 	    table, value, false, false, 0, 0);
       
    81 
       
    82 	// Preferred width: datum + icon size + gap
       
    83 	int width = renderer.getPreferredSize().width + 16 + 6;
       
    84 	column.setPreferredWidth(width);
       
    85 
       
    86 	if (exceptionList != null) {
       
    87 	    exceptionList.getTable().getColumnModel().getColumn(0).
       
    88 		setPreferredWidth(width);
       
    89 	}
       
    90     }
       
    91 
       
    92     public PolicyTablePanel getApplyList() {
       
    93 	return applyList;
       
    94     }
       
    95 
       
    96     public PolicyTablePanel getExceptionList() {
       
    97 	return exceptionList;
       
    98     }
       
    99 
       
   100     public void setVisibleRowCount(int visRow) {
       
   101 	applyList.getTable().setVisibleRowCount(visRow);
       
   102 
       
   103 	if (exceptionList != null)
       
   104 	    exceptionList.getTable().setVisibleRowCount(visRow);
       
   105     }
       
   106 
       
   107     public void setPanelDescriptor(FirewallPanelDescriptor descriptor) {
       
   108 	applyList.setPanelDescriptor(descriptor);
       
   109 
       
   110 	if (exceptionList != null)
       
   111 	    exceptionList.setPanelDescriptor(descriptor);
       
   112     }
       
   113 }