1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
6 |
* This file is part of JSampler. |
7 |
* |
8 |
* JSampler is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License version 2 |
10 |
* as published by the Free Software Foundation. |
11 |
* |
12 |
* JSampler is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with JSampler; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
* MA 02111-1307 USA |
21 |
*/ |
22 |
|
23 |
package org.jsampler.view.fantasia; |
24 |
|
25 |
import java.awt.Color; |
26 |
import java.awt.Component; |
27 |
import java.awt.Composite; |
28 |
import java.awt.Dimension; |
29 |
import java.awt.Graphics; |
30 |
import java.awt.Graphics2D; |
31 |
import java.awt.Insets; |
32 |
import java.awt.Paint; |
33 |
|
34 |
import java.awt.geom.Rectangle2D; |
35 |
|
36 |
import javax.swing.BorderFactory; |
37 |
import javax.swing.Icon; |
38 |
import javax.swing.ImageIcon; |
39 |
import javax.swing.JComponent; |
40 |
|
41 |
import javax.swing.border.Border; |
42 |
|
43 |
import javax.swing.plaf.ComponentUI; |
44 |
|
45 |
import org.jdesktop.swingx.JXTaskPane; |
46 |
import org.jdesktop.swingx.plaf.basic.BasicTaskPaneUI; |
47 |
|
48 |
/** |
49 |
* |
50 |
* @author Grigor Iliev |
51 |
*/ |
52 |
public class FantasiaTaskPane extends JXTaskPane { |
53 |
public |
54 |
FantasiaTaskPane() { |
55 |
setUI(new FantasiaTaskPaneUI()); |
56 |
|
57 |
JComponent c = (JComponent)getContentPane(); |
58 |
while(c != null) { |
59 |
c.setOpaque(false); |
60 |
c = (JComponent)c.getParent(); |
61 |
} |
62 |
setOpaque(false); |
63 |
} |
64 |
} |
65 |
|
66 |
class FantasiaTaskPaneUI extends BasicTaskPaneUI { |
67 |
private final Color titleColor = new Color(0xaaaaaa); |
68 |
|
69 |
public static ComponentUI |
70 |
createUI(JComponent c) { return new FantasiaTaskPaneUI(); } |
71 |
|
72 |
@Override |
73 |
protected Border |
74 |
createContentPaneBorder() { |
75 |
return BorderFactory.createEmptyBorder(0, 0, 0, 0); |
76 |
} |
77 |
|
78 |
@Override |
79 |
protected Border |
80 |
createPaneBorder() { |
81 |
//return super.createPaneBorder(); |
82 |
return new FantasiaPaneBorder(); |
83 |
} |
84 |
|
85 |
@Override |
86 |
public void |
87 |
paint(Graphics g, JComponent c) { |
88 |
double h = c.getSize().getHeight(); |
89 |
double w = c.getSize().getWidth(); |
90 |
FantasiaPainter.paintDarkGradient((Graphics2D)g, 1, 1, w - 3, h - 3); |
91 |
|
92 |
super.paint(g, c); |
93 |
} |
94 |
|
95 |
private class FantasiaPaneBorder extends PaneBorder { |
96 |
protected ImageIcon expandedIcon; |
97 |
protected ImageIcon collapsedIcon; |
98 |
|
99 |
FantasiaPaneBorder() { |
100 |
//super(5, 5, 5, 5); |
101 |
this.expandedIcon = Res.iconArrowUp; |
102 |
this.collapsedIcon = Res.iconArrowDown; |
103 |
} |
104 |
|
105 |
@Override |
106 |
public void |
107 |
paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
108 |
Graphics2D g2 = (Graphics2D)g; |
109 |
|
110 |
Paint oldPaint = g2.getPaint(); |
111 |
Composite oldComposite = g2.getComposite(); |
112 |
|
113 |
int titleX = 3; |
114 |
int titleY = 1; |
115 |
int titleWidth = group.getWidth() - getTitleHeight(group) - 3; |
116 |
int titleHeight = getTitleHeight(group); |
117 |
paintTitle(group, g, titleColor, titleX, titleY, titleWidth, titleHeight); |
118 |
|
119 |
Rectangle2D.Double rect = new Rectangle2D.Double(x + 1, y + 1, width - 3, height - 3); |
120 |
g2.setPaint(new Color(0x2b2b2b)); |
121 |
g2.draw(rect); |
122 |
|
123 |
int x2 = x + width - 1; |
124 |
int y2 = y + height - 1; |
125 |
FantasiaPainter.paintOuterBorder(g2, x + 2, y + 2, x2 - 2, y2 - 2, true, 0.5f, 1.0f); |
126 |
FantasiaPainter.paintInnerBorder(g2, x, y, x2, y2, true); |
127 |
|
128 |
int controlWidth = getTitleHeight(group) - 2 * getRoundHeight(); |
129 |
int controlX = group.getWidth() - getTitleHeight(group); |
130 |
int controlY = getRoundHeight() - 1; |
131 |
|
132 |
g2.setPaint(oldPaint); |
133 |
g2.setComposite(oldComposite); |
134 |
|
135 |
paintExpandedControls(group, g, controlX, controlY, controlWidth, controlWidth); |
136 |
} |
137 |
|
138 |
@Override |
139 |
public Insets |
140 |
getBorderInsets(Component c) { |
141 |
return new Insets(getTitleHeight(c), 5, 3, 5); |
142 |
} |
143 |
|
144 |
@Override |
145 |
protected void |
146 |
paintExpandedControls(JXTaskPane group, Graphics g, int x, int y, int width, int height) { |
147 |
Icon arrowIcon = group.isCollapsed() ? collapsedIcon : expandedIcon; |
148 |
int iconHeight = arrowIcon.getIconHeight(); |
149 |
arrowIcon.paintIcon(group, g, x + 3, y + (height - iconHeight) / 2 + 2); |
150 |
} |
151 |
|
152 |
@Override |
153 |
public Dimension |
154 |
getPreferredSize(JXTaskPane group) { |
155 |
// calculate the title width so it is fully visible |
156 |
// it starts with the title width |
157 |
configureLabel(group); |
158 |
Dimension dim = label.getPreferredSize(); |
159 |
// add the title left offset |
160 |
dim.width += 3; |
161 |
// add the controls width |
162 |
dim.width += getTitleHeight(group); |
163 |
// and some space between label and controls |
164 |
dim.width += 3; |
165 |
|
166 |
dim.height = getTitleHeight(group) + 3; |
167 |
return dim; |
168 |
} |
169 |
} |
170 |
} |