01: /*
02: * Copyright (c) 2005-2008 Flamingo / Substance Kirill Grouchnikov. All Rights Reserved.
03: *
04: * Redistribution and use in source and binary forms, with or without
05: * modification, are permitted provided that the following conditions are met:
06: *
07: * o Redistributions of source code must retain the above copyright notice,
08: * this list of conditions and the following disclaimer.
09: *
10: * o Redistributions in binary form must reproduce the above copyright notice,
11: * this list of conditions and the following disclaimer in the documentation
12: * and/or other materials provided with the distribution.
13: *
14: * o Neither the name of Flamingo Kirill Grouchnikov nor the names of
15: * its contributors may be used to endorse or promote products derived
16: * from this software without specific prior written permission.
17: *
18: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29: */
30: package org.jvnet.substance.flamingo.ribbon.ui;
31:
32: import java.awt.geom.GeneralPath;
33:
34: public class RibbonBorderShaper {
35: public static GeneralPath getRibbonBorderOutline(int startX,
36: int endX, int startSelectedX, int endSelectedX, int topY,
37: int bandTopY, int bottomY, float radius) {
38:
39: int height = bottomY - topY;
40: GeneralPath result = new GeneralPath();
41: float radius3 = (float) (radius / (1.5 * Math.pow(height, 0.5)));
42:
43: // start in the top left corner at the end of the curve
44: result.moveTo(startX + radius, bandTopY);
45:
46: // move to the bottom start of the selected tab and curve up
47: result.lineTo(startSelectedX - radius, bandTopY);
48: result.quadTo(startSelectedX - radius3, bandTopY - radius3,
49: startSelectedX, bandTopY - radius);
50:
51: // move to the top start of the selected tab and curve right
52: result.lineTo(startSelectedX, topY + radius);
53: result.quadTo(startSelectedX + radius3, topY + radius3,
54: startSelectedX + radius, topY);
55:
56: // move to the top end of the selected tab and curve down
57: result.lineTo(endSelectedX - radius - 1, topY);
58: result.quadTo(endSelectedX + radius3 - 1, topY + radius3,
59: endSelectedX - 1, topY + radius);
60:
61: // move to the bottom end of the selected tab and curve right
62: result.lineTo(endSelectedX - 1, bandTopY - radius);
63: result.quadTo(endSelectedX + radius3 - 1, bandTopY - radius3,
64: endSelectedX + radius - 1, bandTopY);
65:
66: // move to the top right corner and curve down
67: result.lineTo(endX - radius - 1, bandTopY);
68: result.quadTo(endX - radius3 - 1, bandTopY + radius3, endX - 1,
69: bandTopY + radius);
70:
71: // move to the bottom right corner and curve left
72: result.lineTo(endX - 1, bottomY - radius - 1);
73: result.quadTo(endX - radius3 - 1, bottomY - 1 - radius3, endX
74: - radius - 1, bottomY - 1);
75:
76: // move to the bottom left corner and curve up
77: result.lineTo(startX + radius, bottomY - 1);
78: result.quadTo(startX + radius3, bottomY - 1 - radius3, startX,
79: bottomY - radius - 1);
80:
81: // move to the top left corner and curve right
82: result.lineTo(startX, bandTopY + radius);
83: result.quadTo(startX + radius3, bandTopY + radius3, startX
84: + radius, bandTopY);
85:
86: return result;
87: }
88:
89: }
|