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.basic; |
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 |
import org.jsampler.view.fantasia.Res; |
49 |
|
50 |
/** |
51 |
* |
52 |
* @author Grigor Iliev |
53 |
*/ |
54 |
public class FantasiaTaskPane extends JXTaskPane { |
55 |
public |
56 |
FantasiaTaskPane() { |
57 |
setUI(new FantasiaTaskPaneUI()); |
58 |
|
59 |
JComponent c = (JComponent)getContentPane(); |
60 |
while(c != null) { |
61 |
c.setOpaque(false); |
62 |
c = (JComponent)c.getParent(); |
63 |
} |
64 |
setOpaque(false); |
65 |
} |
66 |
} |
67 |
|
68 |
class FantasiaTaskPaneUI extends BasicTaskPaneUI { |
69 |
private final Color titleColor = new Color(0xaaaaaa); |
70 |
|
71 |
public static ComponentUI |
72 |
createUI(JComponent c) { return new FantasiaTaskPaneUI(); } |
73 |
|
74 |
@Override |
75 |
protected Border |
76 |
createContentPaneBorder() { |
77 |
return BorderFactory.createEmptyBorder(0, 0, 0, 0); |
78 |
} |
79 |
|
80 |
@Override |
81 |
protected Border |
82 |
createPaneBorder() { |
83 |
//return super.createPaneBorder(); |
84 |
return new FantasiaPaneBorder(); |
85 |
} |
86 |
|
87 |
@Override |
88 |
public void |
89 |
paint(Graphics g, JComponent c) { |
90 |
double h = c.getSize().getHeight(); |
91 |
double w = c.getSize().getWidth(); |
92 |
FantasiaPainter.paintDarkGradient((Graphics2D)g, 1, 1, w - 3, h - 3); |
93 |
|
94 |
super.paint(g, c); |
95 |
} |
96 |
|
97 |
private class FantasiaPaneBorder extends PaneBorder { |
98 |
protected ImageIcon expandedIcon; |
99 |
protected ImageIcon collapsedIcon; |
100 |
|
101 |
FantasiaPaneBorder() { |
102 |
//super(5, 5, 5, 5); |
103 |
this.expandedIcon = Res.iconArrowUp; |
104 |
this.collapsedIcon = Res.iconArrowDown; |
105 |
} |
106 |
|
107 |
@Override |
108 |
public void |
109 |
paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
110 |
Graphics2D g2 = (Graphics2D)g; |
111 |
|
112 |
Paint oldPaint = g2.getPaint(); |
113 |
Composite oldComposite = g2.getComposite(); |
114 |
|
115 |
int titleX = 3; |
116 |
int titleY = 1; |
117 |
int titleWidth = group.getWidth() - getTitleHeight(group) - 3; |
118 |
int titleHeight = getTitleHeight(group); |
119 |
paintTitle(group, g, titleColor, titleX, titleY, titleWidth, titleHeight); |
120 |
|
121 |
Rectangle2D.Double rect = new Rectangle2D.Double(x + 1, y + 1, width - 3, height - 3); |
122 |
g2.setPaint(new Color(0x2b2b2b)); |
123 |
g2.draw(rect); |
124 |
|
125 |
int x2 = x + width - 1; |
126 |
int y2 = y + height - 1; |
127 |
FantasiaPainter.paintOuterBorder(g2, x + 2, y + 2, x2 - 2, y2 - 2, true, 0.5f, 1.0f); |
128 |
FantasiaPainter.paintInnerBorder(g2, x, y, x2, y2, true); |
129 |
|
130 |
int controlWidth = getTitleHeight(group) - 2 * getRoundHeight(); |
131 |
int controlX = group.getWidth() - getTitleHeight(group); |
132 |
int controlY = getRoundHeight() - 1; |
133 |
|
134 |
g2.setPaint(oldPaint); |
135 |
g2.setComposite(oldComposite); |
136 |
|
137 |
paintExpandedControls(group, g, controlX, controlY, controlWidth, controlWidth); |
138 |
} |
139 |
|
140 |
@Override |
141 |
public Insets |
142 |
getBorderInsets(Component c) { |
143 |
return new Insets(getTitleHeight(c), 5, 3, 5); |
144 |
} |
145 |
|
146 |
@Override |
147 |
protected void |
148 |
paintExpandedControls(JXTaskPane group, Graphics g, int x, int y, int width, int height) { |
149 |
Icon arrowIcon = group.isCollapsed() ? collapsedIcon : expandedIcon; |
150 |
int iconHeight = arrowIcon.getIconHeight(); |
151 |
arrowIcon.paintIcon(group, g, x + 3, y + (height - iconHeight) / 2 + 2); |
152 |
} |
153 |
|
154 |
@Override |
155 |
public Dimension |
156 |
getPreferredSize(JXTaskPane group) { |
157 |
// calculate the title width so it is fully visible |
158 |
// it starts with the title width |
159 |
configureLabel(group); |
160 |
Dimension dim = label.getPreferredSize(); |
161 |
// add the title left offset |
162 |
dim.width += 3; |
163 |
// add the controls width |
164 |
dim.width += getTitleHeight(group); |
165 |
// and some space between label and controls |
166 |
dim.width += 3; |
167 |
|
168 |
dim.height = getTitleHeight(group) + 3; |
169 |
return dim; |
170 |
} |
171 |
} |
172 |
} |