
it.tidalwave.netbeans.lookandfeel.ui.BlueMarineScrollButton 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.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalScrollButton;
import it.tidalwave.netbeans.lookandfeel.LookAndFeel;
/*******************************************************************************
*
* @author Fabrizio Giudici
* @version $Id$
*
******************************************************************************/
public class BlueMarineScrollButton extends MetalScrollButton
{
private static final long serialVersionUID = 1L;
private final int[] x = new int[3];
private final int[] y = new int[3];
/***************************************************************************
*
*
**************************************************************************/
public BlueMarineScrollButton (final int direction, final int width, final boolean freeStanding)
{
super(direction, width + 1, freeStanding);
setOpaque(false);
final int r = width / 3;
final double a0 = ((direction - 1) / 2 - 1) * (2 * Math.PI) / 4;
for (int i = 0; i < 3; i++)
{
final double a = a0 + i * (2 * Math.PI) / 3;
x[i] = (int)Math.floor(r * Math.cos(a)) + width / 2;
y[i] = (int)Math.floor(r * Math.sin(a)) + width / 2;
}
}
/***************************************************************************
*
*
**************************************************************************/
@Override
public void paint (final Graphics g)
{
final Graphics2D g2 = (Graphics2D)g;
final RenderingHints saveRenderingHints = g2.getRenderingHints();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
final Rectangle bounds = new Rectangle(0, 0, getWidth(), getHeight());
final GradientPaint gradient;
final Color trackColor = UIManager.getColor("ScrollBar.track");
final Color color1 = variant(trackColor, 0.8);
final Color color2 = variant(trackColor, 1/0.8);
if ((getDirection() == EAST) || (getDirection() == WEST))
{
gradient = new GradientPaint(bounds.x,
bounds.y,
color1,
bounds.x,
bounds.y + bounds.height,
color2);
}
else
{
gradient = new GradientPaint(bounds.x,
bounds.y,
color2,
bounds.x + bounds.width,
bounds.y,
color1);
}
g2.setPaint(gradient);
g2.fill(bounds);
g2.setColor(UIManager.getColor(LookAndFeel.COLOR_HEADER_FOREGROUND));
g2.fillPolygon(x, y, 3);
g2.setRenderingHints(saveRenderingHints);
}
/***************************************************************************
*
*
**************************************************************************/
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));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy