
it.tidalwave.netbeans.lookandfeel.ui.HeaderPanelUI Maven / Gradle / Ivy
The newest version!
/***********************************************************************************************************************
*
* SolidBlue - open source safe data
* Copyright (C) 2011-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* WWW: http://solidblue.java.net
* SCM: https://bitbucket.org/tidalwave/solidblue-src
*
**********************************************************************************************************************/
package it.tidalwave.netbeans.lookandfeel.ui;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import javax.swing.JComponent;
import javax.swing.plaf.basic.BasicPanelUI;
import org.openide.windows.TopComponent;
import org.openide.windows.TopComponent.Registry;
import org.openide.windows.WindowManager;
/*******************************************************************************
*
* @author Fabrizio Giudici
* @version $Id$
*
******************************************************************************/
public class HeaderPanelUI extends BasicPanelUI
{
public static final String HEADER_PANEL_CP = HeaderPanelUI.class.getName();
private static HeaderPanelUI instance;
private static Registry registry;
/***************************************************************************
*
*
**************************************************************************/
public static HeaderPanelUI createUI (final JComponent component)
{
if (instance == null)
{
instance = new HeaderPanelUI();
}
component.putClientProperty(HEADER_PANEL_CP, true);
return instance;
}
/***************************************************************************
*
*
**************************************************************************/
@Override
public void paint (final Graphics g, final JComponent component)
{
final Graphics2D g2 = (Graphics2D)g;
Color baseColor = component.getBackground();
if (!isInActivatedTopComponent(component))
{
baseColor = variant(baseColor, 0.7);
}
final Color color1 = variant(baseColor, 1.0 / 0.88);
final Color color2 = variant(baseColor, 0.88);
final GradientPaint gradientPaint = new GradientPaint(0, 0, color1, 0, component.getHeight(), color2);
final Paint savePaint = g2.getPaint();
g2.setPaint(gradientPaint);
g2.fillRect(0, 0, component.getWidth(), component.getHeight());
g2.setPaint(savePaint);
}
/***************************************************************************
*
*
**************************************************************************/
public static Color variant (final Color color, final double factor)
{
return new Color(Math.min((int)(color.getRed() * factor), 255),
Math.min((int)(color.getGreen() * factor), 255),
Math.min((int)(color.getBlue() * factor), 255));
}
/***************************************************************************
*
*
**************************************************************************/
public static boolean isInActivatedTopComponent (final JComponent component)
{
if (registry == null)
{
registry = WindowManager.getDefault().getRegistry();
}
return registry.getActivated() == findTopComponent(component);
}
/***************************************************************************
*
*
**************************************************************************/
private static TopComponent findTopComponent (final Component component)
{
if (component instanceof TopComponent)
{
return (TopComponent)component;
}
final Container parent = component.getParent();
return (parent != null) ? findTopComponent(parent) : null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy