components/visual-panels/core/src/java/vpanels/panel/com/oracle/solaris/vp/panel/swing/view/PanelFrame.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.panel.swing.view;
       
    27 
       
    28 import java.awt.*;
       
    29 import java.util.Properties;
       
    30 import javax.swing.*;
       
    31 import javax.swing.border.Border;
       
    32 import com.oracle.solaris.vp.panel.common.control.Navigator;
       
    33 import com.oracle.solaris.vp.util.misc.finder.Finder;
       
    34 import com.oracle.solaris.vp.util.swing.*;
       
    35 import com.oracle.solaris.vp.util.swing.layout.*;
       
    36 
       
    37 @SuppressWarnings({"serial"})
       
    38 public class PanelFrame extends ExtFrame {
       
    39     //
       
    40     // Static data
       
    41     //
       
    42 
       
    43     public static final int HEALTH_ICON_SIZE = 16;
       
    44 
       
    45     //
       
    46     // Instance data
       
    47     //
       
    48 
       
    49     private NavBar navBar;
       
    50     private ReplacingStackPanel mainPanel;
       
    51     private AuthPanel authPanel;
       
    52     private JLabel statusLabel;
       
    53     private JLabel statusTextLabel;
       
    54 
       
    55     //
       
    56     // Constructors
       
    57     //
       
    58 
       
    59     public PanelFrame(Properties hints, Navigator navigator) {
       
    60 	JPanel header = createHeader();
       
    61 
       
    62 	// Prevent resizing below preferred size
       
    63 	getRootPane().setAutoMinSizeEnabled(true);
       
    64 
       
    65 	mainPanel = new ReplacingStackPanel();
       
    66 	mainPanel.setOpaque(false);
       
    67 
       
    68 	JPanel top = new JPanel(new BorderLayout());
       
    69 	top.setOpaque(false);
       
    70 
       
    71 	if (hints.getProperty("vpanels.ui.noheader") == null) {
       
    72 	    top.add(header, BorderLayout.NORTH);
       
    73 	}
       
    74 
       
    75 	if (hints.getProperty("vpanels.ui.navbar") != null) {
       
    76 	    createNavBar(navigator);
       
    77 	    top.add(navBar, BorderLayout.CENTER);
       
    78 	}
       
    79 
       
    80 	JPanel panel = new JPanel(new BorderLayout());
       
    81 	panel.setOpaque(false);
       
    82 
       
    83 	if (top.getComponentCount() != 0) {
       
    84             top.setBorder(new ClippedBorder(GUIUtil.getEmptyBorder(), true,
       
    85 		true, false, true));
       
    86 	    panel.add(top, BorderLayout.NORTH);
       
    87 	}
       
    88 
       
    89 	panel.add(mainPanel, BorderLayout.CENTER);
       
    90 
       
    91 	if (hints.getProperty("vpanels.ui.undecorated") != null) {
       
    92 	    setUndecorated(true);
       
    93 	    Border line = BorderFactory.createLineBorder(Color.black, 1);
       
    94 	    panel.setBorder(line);
       
    95 	}
       
    96 
       
    97 	Container contentPane = getContentPane();
       
    98 	contentPane.setLayout(new BorderLayout());
       
    99 	contentPane.add(panel, BorderLayout.CENTER);
       
   100 
       
   101 	pack();
       
   102 
       
   103 	setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
       
   104 	setInitialFocus(mainPanel);
       
   105     }
       
   106 
       
   107     //
       
   108     // PanelFrame methods
       
   109     //
       
   110 
       
   111     public AuthPanel getAuthPanel() {
       
   112 	return authPanel;
       
   113     }
       
   114 
       
   115     public ReplacingStackPanel getMainPanel() {
       
   116 	return mainPanel;
       
   117     }
       
   118 
       
   119     protected NavBar getNavBar() {
       
   120 	return navBar;
       
   121     }
       
   122 
       
   123     public void setHealth(Health health) {
       
   124 	if (health == null) {
       
   125 	    health = Health.HEALTHY;
       
   126 	}
       
   127 
       
   128 	Icon icon = health.getIcon(HEALTH_ICON_SIZE);
       
   129 	String toolTip = Finder.getString("app.status.tooltip." +
       
   130 	    health.toString().toLowerCase());
       
   131 
       
   132 	statusLabel.setIcon(icon);
       
   133 	statusLabel.setToolTipText(toolTip);
       
   134     }
       
   135 
       
   136     public void setStatusText(String text) {
       
   137 	if (text != null) {
       
   138 	    text = Finder.getString("app.status", text);
       
   139 	}
       
   140 	statusTextLabel.setText(text);
       
   141     }
       
   142 
       
   143     //
       
   144     // Private methods
       
   145     //
       
   146 
       
   147     private JPanel createHeader() {
       
   148 	statusLabel = new JLabel();
       
   149 	statusTextLabel = new JLabel();
       
   150 
       
   151 	authPanel = new AuthPanel();
       
   152 	RowLayout layout = new RowLayout(HorizontalAnchor.FILL);
       
   153 
       
   154 	JPanel row = new JPanel(layout);
       
   155 	row.setOpaque(false);
       
   156 
       
   157 	int hGap = GUIUtil.getHalfGap();
       
   158 	int gap = GUIUtil.getGap();
       
   159 
       
   160 	RowLayoutConstraint r = new RowLayoutConstraint(
       
   161 	    VerticalAnchor.CENTER, hGap);
       
   162 
       
   163 	row.add(statusLabel, r);
       
   164 	row.add(statusTextLabel, r);
       
   165 	row.add(authPanel, r.setWeight(1).setHorizontalAnchor(
       
   166 	    HorizontalAnchor.RIGHT));
       
   167 
       
   168 	return row;
       
   169     }
       
   170 
       
   171     private void createNavBar(Navigator navigator) {
       
   172 	navBar = new NavBar(navigator);
       
   173 
       
   174 	// Let the main part of the window drive the size of the nav bar
       
   175 	AddressPanel addrPanel = navBar.getAddressPanel();
       
   176 	Dimension d = addrPanel.getPreferredSize();
       
   177 	d.width = 0;
       
   178 	addrPanel.setPreferredSize(d);
       
   179     }
       
   180 }