001/* 002 * Copyright (c) 2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: barseghian $' 006 * '$Date: 2011-02-10 20:02:55 +0000 (Thu, 10 Feb 2011) $' 007 * '$Revision: 27080 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.kepler.reporting.gui; 031 032import java.awt.AlphaComposite; 033import java.awt.BasicStroke; 034import java.awt.Color; 035import java.awt.Component; 036import java.awt.GradientPaint; 037import java.awt.Graphics; 038import java.awt.Graphics2D; 039import java.awt.Insets; 040import java.awt.RenderingHints; 041 042import javax.swing.border.Border; 043 044 045public class OvalBorder implements Border{ 046 047 private static final Color clrGlowInnerHi = new Color(253, 239, 175, 148); 048 private static final Color clrGlowInnerLo = new Color(255, 209, 0); 049 private static final Color clrGlowOuterHi = new Color(253, 239, 175, 124); 050 private static final Color clrGlowOuterLo = new Color(255, 179, 0); 051 052 private int height = 50; 053 private int ovalWidth = 6; 054 private int ovalHeight = 6; 055 private Color lightColor = Color.gray; 056 private Color darkColor = Color.darkGray; 057 058 public OvalBorder(boolean b) { 059 ovalWidth = 6; 060 ovalHeight = 6; 061 } 062 063 public OvalBorder(Color topColor, Color bottomColor) { 064 lightColor = topColor; 065 darkColor = bottomColor; 066 } 067 068 069 public OvalBorder(int w, int h) { 070 ovalWidth = w; 071 ovalHeight = h; 072 } 073 074 075 public OvalBorder(int w, int h, Color topColor, Color bottomColor) { 076 ovalWidth = w; 077 ovalHeight = h; 078 lightColor = topColor; 079 darkColor = bottomColor; 080 } 081 082 public Insets getBorderInsets(Component c) { 083 return new Insets(ovalHeight, ovalWidth, ovalHeight, ovalWidth); 084 } 085 086 087 public boolean isBorderOpaque() { 088 return true; 089 } 090 091 /* 092 private Shape createClipShape() { 093 094 float x1 = border; 095 float y1 = border; 096 float x2 = width - border; 097 float y2 = height - border; 098 099 float adj = 3.0f; // helps round out the sharp corners 100 float arc = 8.0f; 101 float dcx = 0.18f * width; 102 float cx1 = x1-dcx; 103 float cy1 = 0.40f * height; 104 float cx2 = x1+dcx; 105 float cy2 = 0.50f * height; 106 107 GeneralPath gp = new GeneralPath(); 108 gp.moveTo(x1-adj, y1+adj); 109 gp.quadTo(x1, y1, x1+adj, y1); 110 gp.lineTo(x2-arc, y1); 111 gp.quadTo(x2, y1, x2, y1+arc); 112 gp.lineTo(x2, y2-arc); 113 gp.quadTo(x2, y2, x2-arc, y2); 114 gp.lineTo(x1+adj, y2); 115 gp.quadTo(x1, y2, x1, y2-adj); 116 gp.curveTo(cx2, cy2, cx1, cy1, x1-adj, y1+adj); 117 gp.closePath(); 118 return gp; 119 } 120 */ 121 122 123 private static Color getMixedColor(Color c1, float pct1, Color c2, float pct2) { 124 float[] clr1 = c1.getComponents(null); 125 float[] clr2 = c2.getComponents(null); 126 for (int i = 0; i < clr1.length; i++) { 127 clr1[i] = (clr1[i] * pct1) + (clr2[i] * pct2); 128 } 129 return new Color(clr1[0], clr1[1], clr1[2], clr1[3]); 130 } 131 132 private void paintBorderGlow(Graphics2D g2, int glowWidth) { 133 int gw = glowWidth*2; 134 for (int i=gw; i >= 2; i-=2) { 135 float pct = (float)(gw - i) / (gw - 1); 136 137 Color mixHi = getMixedColor(clrGlowInnerHi, pct, 138 clrGlowOuterHi, 1.0f - pct); 139 Color mixLo = getMixedColor(clrGlowInnerLo, pct, 140 clrGlowOuterLo, 1.0f - pct); 141 g2.setPaint(new GradientPaint(0.0f, height*0.25f, mixHi, 142 0.0f, height, mixLo)); 143 //g2.setColor(Color.WHITE); 144 145 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, pct)); 146 g2.setStroke(new BasicStroke(i)); 147 // g2.draw(clipShape); 148 } 149 } 150 151 152 153 private void paintBorderShadow(Graphics2D g2, int shadowWidth) { 154 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 155 RenderingHints.VALUE_ANTIALIAS_ON); 156 int sw = shadowWidth*2; 157 for (int i=sw; i >= 2; i-=2) { 158 float pct = (float)(sw - i) / (sw - 1); 159 g2.setColor(getMixedColor(Color.LIGHT_GRAY, pct, 160 Color.WHITE, 1.0f-pct)); 161 g2.setStroke(new BasicStroke(i)); 162 // g2.draw(clipShape); 163 } 164 } 165 166 167 168 public void paintBorder(Component c, Graphics g, int x, int y, int width, 169 170 int height) { 171 172 width--; 173 174 height--; 175 176 177 178 g.setColor(lightColor); 179 180 g.drawLine(x, y + height - ovalHeight, x, y + ovalHeight); 181 182 g.drawArc(x, y, 2 * ovalWidth, 2 * ovalHeight, 180, -90); 183 184 g.drawLine(x + ovalWidth, y, x + width - ovalWidth, y); 185 186 g.drawArc(x + width - 2 * ovalWidth, y, 2 * ovalWidth, 2 * ovalHeight, 187 188 90, -90); 189 190 191 192 g.setColor(darkColor); 193 194 g.drawLine(x + width, y + ovalHeight, x + width, y + height 195 196 - ovalHeight); 197 198 g.drawArc(x + width - 2 * ovalWidth, y + height - 2 * ovalHeight, 199 200 2 * ovalWidth, 2 * ovalHeight, 0, -90); 201 202 g 203 204 .drawLine(x + ovalWidth, y + height, x + width - ovalWidth, y 205 206 + height); 207 208 g.drawArc(x, y + height - 2 * ovalHeight, 2 * ovalWidth, 209 210 2 * ovalHeight, -90, -90); 211 212 } 213 214 215 216}