Java Draw Shadow drawShadedLine(java.awt.Graphics2D g2, float x0, float y0, float x1, float y1, java.awt.Paint topLeftPaint, java.awt.Paint otherPaint, java.awt.Paint bottomRightPaint, java.awt.geom.GeneralPath buffer)

Here you can find the source of drawShadedLine(java.awt.Graphics2D g2, float x0, float y0, float x1, float y1, java.awt.Paint topLeftPaint, java.awt.Paint otherPaint, java.awt.Paint bottomRightPaint, java.awt.geom.GeneralPath buffer)

Description

draw Shaded Line

License

Open Source License

Declaration

private static void drawShadedLine(java.awt.Graphics2D g2, float x0, float y0, float x1, float y1,
            java.awt.Paint topLeftPaint, java.awt.Paint otherPaint, java.awt.Paint bottomRightPaint,
            java.awt.geom.GeneralPath buffer) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006, 2015, Carnegie Mellon University. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. Products derived from the software may not be called "Alice", nor may
 *    "Alice" appear in their name, without prior written permission of
 *    Carnegie Mellon University./*from  w  w w  .  j  a  va 2s  .c  o  m*/
 *
 * 4. All advertising materials mentioning features or use of this software must
 *    display the following acknowledgement: "This product includes software
 *    developed by Carnegie Mellon University"
 *
 * 5. The gallery of art assets and animations provided with this software is
 *    contributed by Electronic Arts Inc. and may be used for personal,
 *    non-commercial, and academic use only. Redistributions of any program
 *    source code that utilizes The Sims 2 Assets must also retain the copyright
 *    notice, list of conditions and the disclaimer contained in
 *    The Alice 3.0 Art Gallery License.
 *
 * DISCLAIMER:
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
 * ANY AND ALL EXPRESS, STATUTORY OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A
 * PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
 * SHALL THE AUTHORS, COPYRIGHT OWNERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING FROM OR OTHERWISE RELATING TO
 * THE USE OF OR OTHER DEALINGS WITH THE SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

public class Main {
    private static void drawShadedLine(java.awt.Graphics2D g2, float x0, float y0, float x1, float y1,
            java.awt.Paint topLeftPaint, java.awt.Paint otherPaint, java.awt.Paint bottomRightPaint,
            java.awt.geom.GeneralPath buffer) {
        //      float xDelta = x1-x0;
        //      float yDelta = y1-y0;
        float xDelta = x0 - x1;
        float yDelta = y0 - y1;
        if (xDelta > 0) {
            if (yDelta > 0) {
                g2.setPaint(otherPaint);
            } else if (yDelta < 0) {
                g2.setPaint(topLeftPaint);
            } else {
                g2.setPaint(topLeftPaint);
            }
        } else if (xDelta < 0) {
            if (yDelta > 0) {
                g2.setPaint(bottomRightPaint);
            } else if (yDelta < 0) {
                g2.setPaint(otherPaint);
            } else {
                g2.setPaint(bottomRightPaint);
            }
        } else {
            if (yDelta > 0) {
                g2.setPaint(bottomRightPaint);
            } else if (yDelta < 0) {
                g2.setPaint(topLeftPaint);
            } else {
                return;
            }
        }
        buffer.reset();
        buffer.moveTo(x0, y0);
        buffer.lineTo(x1, y1);
        g2.draw(buffer);
        //g2.drawLine( (int)( x0+0.5f ), (int)( y0+0.5f ), (int)( x1+0.5f ), (int)( y1+0.5f ) );
    }
}

Related

  1. drawShadow(Graphics2D g2d, Color topColor, float opacity, int shadowWidth, int cornerRadius, int x, int y, int width, int height)
  2. drawShadowedShape(Shape shape, Graphics2D g2d)
  3. drawShadowedString(Graphics2D g2d, String label, Color textColor, Color shadowColor, int x, int y)
  4. drawShadowedString(String string, int x, int y, Graphics2D g2d)