001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2006-2008 Sun Microsystems, Inc. 025 */ 026 027package org.opends.quicksetup.ui; 028 029import java.awt.AlphaComposite; 030import java.awt.Component; 031import java.awt.Dimension; 032import java.awt.Graphics; 033import java.awt.Graphics2D; 034import java.awt.GridBagConstraints; 035import java.awt.GridBagLayout; 036 037import javax.swing.Box; 038import javax.swing.Icon; 039import javax.swing.JPanel; 040 041/** 042 * This class is the panel that is displayed in the QuickSetupDialog. It 043 * contains 3 panels that are passed in the constructor: the steps panel, 044 * the buttons panel and the current step panel (the main panel of the three). 045 * 046 * The only remarkable thing of this class is that is responsible for 047 * implementing the background. The three subpanels are transparent and 048 * this class sets a background (with the Open DS logo) and uses some basic 049 * transparency effects. 050 * 051 */ 052public class FramePanel extends JPanel 053{ 054 private static final long serialVersionUID = 7733658951410876078L; 055 056 private Icon backgroundIcon; 057 058 private Component stepsPanel; 059 060 private Component buttonsPanel; 061 062 private int buttonsPanelVerticalInsets; 063 064 private int stepsPanelHorizontalInsets; 065 /** 066 * The constructor of the FramePanel. 067 * @param stepsPanel the steps panel that on the top-left side of the 068 * QuickSetupDialog. 069 * @param currentStepPanel the current step panel (the panel that displays 070 * what is associated to the current step). Is the panel that contains all 071 * the input fields and is located on the top-right side of the 072 * QuickSetupDialog. 073 * @param buttonsPanel the buttons panel that appears on the bottom of the 074 * QuickSetupDialog. 075 */ 076 public FramePanel(Component stepsPanel, Component currentStepPanel, 077 Component buttonsPanel) 078 { 079 super(new GridBagLayout()); 080 setBackground(UIFactory.DEFAULT_BACKGROUND); 081 GridBagConstraints gbc = new GridBagConstraints(); 082 083 gbc.gridwidth = GridBagConstraints.RELATIVE; 084 gbc.weightx = 0.0; 085 gbc.weighty = 1.0; 086 gbc.anchor = GridBagConstraints.NORTHWEST; 087 gbc.fill = GridBagConstraints.VERTICAL; 088 gbc.insets = UIFactory.getStepsPanelInsets(); 089 add(stepsPanel, gbc); 090 091 stepsPanelHorizontalInsets = gbc.insets.left + gbc.insets.right; 092 093 JPanel currentPanelContainer = new JPanel(new GridBagLayout()); 094 currentPanelContainer.setBorder(UIFactory.CURRENT_STEP_PANEL_BORDER); 095 currentPanelContainer 096 .setBackground(UIFactory.CURRENT_STEP_PANEL_BACKGROUND); 097 currentPanelContainer.setOpaque(false); 098 099 gbc.gridwidth = GridBagConstraints.REMAINDER; 100 gbc.weightx = 1.0; 101 gbc.weighty = 1.0; 102 gbc.anchor = GridBagConstraints.NORTHWEST; 103 gbc.fill = GridBagConstraints.BOTH; 104 gbc.insets = UIFactory.getCurrentStepPanelInsets(); 105 currentPanelContainer.add(currentStepPanel, gbc); 106 gbc.insets = UIFactory.getEmptyInsets(); 107 add(currentPanelContainer, gbc); 108 109 gbc.gridwidth = GridBagConstraints.RELATIVE; 110 gbc.anchor = GridBagConstraints.WEST; 111 gbc.weightx = 0.0; 112 gbc.weighty = 0.0; 113 add(Box.createHorizontalGlue(), gbc); 114 115 gbc.gridwidth = GridBagConstraints.REMAINDER; 116 gbc.weightx = 1.0; 117 gbc.weighty = 0.0; 118 gbc.anchor = GridBagConstraints.NORTHWEST; 119 gbc.fill = GridBagConstraints.HORIZONTAL; 120 gbc.insets = UIFactory.getButtonsPanelInsets(); 121 add(buttonsPanel, gbc); 122 123 buttonsPanelVerticalInsets = gbc.insets.top + gbc.insets.bottom; 124 125 backgroundIcon = 126 UIFactory.getImageIcon(UIFactory.IconType.BACKGROUND); 127 128 int backGroundIconWidth = 0; 129 int backGroundIconHeight = 0; 130 if (backgroundIcon != null) 131 { 132 backGroundIconWidth = backgroundIcon.getIconWidth(); 133 backGroundIconHeight = backgroundIcon.getIconHeight(); 134 } 135 136 this.buttonsPanel = buttonsPanel; 137 this.stepsPanel = stepsPanel; 138 int width = 139 Math.max((int) getPreferredSize().getWidth(), backGroundIconWidth 140 + UIFactory.LEFT_INSET_BACKGROUND 141 + UIFactory.RIGHT_INSET_BACKGROUND); 142 int height = 143 Math.max((int) getPreferredSize().getHeight(), backGroundIconHeight 144 + UIFactory.TOP_INSET_BACKGROUND 145 + UIFactory.BOTTOM_INSET_BACKGROUND); 146 setPreferredSize(new Dimension(width, height)); 147 } 148 149 /** 150 * {@inheritDoc} 151 * 152 * This method has been overwritten to be able to have a transparency effect 153 * with the OpenDS logo background. 154 */ 155 protected void paintComponent(Graphics g) 156 { 157 // paint background 158 g.setColor(UIFactory.DEFAULT_BACKGROUND); 159 int width = getWidth(); 160 int height = getHeight(); 161 int buttonsTotalHeight = buttonsPanel.getHeight() 162 + buttonsPanelVerticalInsets; 163 int stepsPanelTotalWidth = stepsPanel.getWidth() 164 + stepsPanelHorizontalInsets; 165 166 g.fillRect(0, 0, stepsPanelTotalWidth, height); 167 g.fillRect(stepsPanelTotalWidth, height - buttonsTotalHeight, width, 168 height); 169 g.setColor(UIFactory.CURRENT_STEP_PANEL_BACKGROUND); 170 g.fillRect(stepsPanelTotalWidth, 0, width, height - buttonsTotalHeight); 171 172 if (backgroundIcon != null) 173 { 174 // Draw the icon over and over, right aligned. 175 // Copy the Graphics object, which is actually 176 // a Graphics2D object. Cast it so we can 177 // set alpha composite. 178 Graphics2D g2d = (Graphics2D) g.create(); 179 180 g2d.setComposite(AlphaComposite.getInstance( 181 AlphaComposite.SRC_OVER, 0.1f)); 182 183 backgroundIcon.paintIcon(this, g2d, 184 UIFactory.LEFT_INSET_BACKGROUND, 185 UIFactory.TOP_INSET_BACKGROUND); 186 187 g2d.dispose(); //clean up 188 } 189 } 190}