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.BorderLayout; |
26 |
import java.awt.Dimension; |
27 |
|
28 |
import java.beans.PropertyChangeEvent; |
29 |
import java.beans.PropertyChangeListener; |
30 |
|
31 |
import javax.swing.BorderFactory; |
32 |
import javax.swing.JScrollPane; |
33 |
import javax.swing.JTabbedPane; |
34 |
|
35 |
import javax.swing.event.ChangeEvent; |
36 |
import javax.swing.event.ChangeListener; |
37 |
|
38 |
import org.jvnet.substance.SubstanceLookAndFeel; |
39 |
|
40 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
41 |
import static org.jsampler.view.fantasia.FantasiaPrefs.preferences; |
42 |
|
43 |
|
44 |
/** |
45 |
* |
46 |
* @author Grigor Iliev |
47 |
*/ |
48 |
public class RightSidePane extends PixmapPane { |
49 |
private JTabbedPane tabbedPane = new JTabbedPane(); |
50 |
private InstrumentsDbPane instrumentsDbPane = null; |
51 |
private final DevicesPane devicesPane = new DevicesPane(); |
52 |
private final JScrollPane spDevicesPane = new JScrollPane(); |
53 |
|
54 |
|
55 |
/** |
56 |
* Creates a new instance of <code>RightSidePane</code> |
57 |
*/ |
58 |
public |
59 |
RightSidePane() { |
60 |
super(Res.gfxRoundBg14); |
61 |
setOpaque(false); |
62 |
setPixmapInsets(new java.awt.Insets(6, 6, 6, 6)); |
63 |
setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
64 |
setLayout(new BorderLayout()); |
65 |
|
66 |
spDevicesPane.setOpaque(false); |
67 |
spDevicesPane.getViewport().setOpaque(false); |
68 |
spDevicesPane.setViewportView(devicesPane); |
69 |
spDevicesPane.setBorder(BorderFactory.createEmptyBorder()); |
70 |
int h = spDevicesPane.getMinimumSize().height; |
71 |
spDevicesPane.setMinimumSize(new Dimension(200, h)); |
72 |
|
73 |
final String s = "rightSidePane.showInstrumentsDb"; |
74 |
setTabbedView(preferences().getBoolProperty(s)); |
75 |
|
76 |
tabbedPane.setBackground(new java.awt.Color(0x828282)); |
77 |
tabbedPane.putClientProperty(SubstanceLookAndFeel.COLORIZATION_FACTOR, 1.0); |
78 |
|
79 |
preferences().addPropertyChangeListener(s, getHandler()); |
80 |
} |
81 |
|
82 |
public DevicesPane |
83 |
getDevicesPane() { return devicesPane; } |
84 |
|
85 |
private void |
86 |
setTabbedView(boolean b) { |
87 |
remove(spDevicesPane); |
88 |
remove(tabbedPane); |
89 |
|
90 |
tabbedPane.removeChangeListener(getHandler()); |
91 |
tabbedPane.removeAll(); |
92 |
|
93 |
if(b) { |
94 |
if(instrumentsDbPane == null) instrumentsDbPane = new InstrumentsDbPane(); |
95 |
tabbedPane.addTab(i18n.getLabel("RightSidePane.tabDevices"), spDevicesPane); |
96 |
tabbedPane.addTab(i18n.getLabel("RightSidePane.tabInstrumentsDb"), instrumentsDbPane); |
97 |
tabbedPane.addChangeListener(getHandler()); |
98 |
add(tabbedPane); |
99 |
|
100 |
int i = preferences().getIntProperty("rightSidePane.tabIndex", 0); |
101 |
if(tabbedPane.getTabCount() > i) tabbedPane.setSelectedIndex(i); |
102 |
} else { |
103 |
add(spDevicesPane); |
104 |
} |
105 |
|
106 |
validate(); |
107 |
} |
108 |
|
109 |
protected void |
110 |
savePreferences() { |
111 |
if(instrumentsDbPane != null) instrumentsDbPane.savePreferences(); |
112 |
} |
113 |
|
114 |
private final EventHandler eventHandler = new EventHandler(); |
115 |
|
116 |
private EventHandler |
117 |
getHandler() { return eventHandler; } |
118 |
|
119 |
private class EventHandler implements ChangeListener, PropertyChangeListener { |
120 |
public void |
121 |
stateChanged(ChangeEvent e) { |
122 |
int idx = tabbedPane.getSelectedIndex(); |
123 |
if(idx == -1) return; |
124 |
preferences().setIntProperty("rightSidePane.tabIndex", idx); |
125 |
} |
126 |
|
127 |
public void |
128 |
propertyChange(PropertyChangeEvent e) { |
129 |
setTabbedView(preferences().getBoolProperty("rightSidePane.showInstrumentsDb")); |
130 |
} |
131 |
} |
132 |
} |