1 |
iliev |
1729 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
iliev |
2288 |
* Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com> |
5 |
iliev |
1729 |
* |
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 |
iliev |
1752 |
import java.awt.event.ActionEvent; |
29 |
|
|
import java.awt.event.ActionListener; |
30 |
|
|
|
31 |
|
|
import javax.swing.Action; |
32 |
|
|
import javax.swing.JButton; |
33 |
iliev |
1729 |
import javax.swing.JPanel; |
34 |
|
|
import javax.swing.JScrollPane; |
35 |
|
|
import javax.swing.JSplitPane; |
36 |
iliev |
1752 |
import javax.swing.JToolBar; |
37 |
iliev |
1729 |
|
38 |
iliev |
1752 |
import org.jsampler.view.std.JSInstrumentsDbColumnPreferencesDlg; |
39 |
iliev |
1729 |
import org.jsampler.view.std.JSInstrumentsDbTable; |
40 |
iliev |
2288 |
import org.jsampler.view.swing.InstrumentsDbTreeModel; |
41 |
|
|
import org.jsampler.view.swing.SHF; |
42 |
iliev |
1729 |
|
43 |
iliev |
2288 |
import static org.jsampler.view.fantasia.FantasiaPrefs.preferences; |
44 |
iliev |
1743 |
|
45 |
iliev |
2288 |
|
46 |
iliev |
1729 |
/** |
47 |
|
|
* |
48 |
|
|
* @author Grigor Iliev |
49 |
|
|
*/ |
50 |
|
|
public class InstrumentsDbPane extends JPanel { |
51 |
iliev |
1743 |
private final FantasiaInstrumentsDbTree instrumentsDbTree; |
52 |
iliev |
1729 |
private final JSInstrumentsDbTable instrumentsTable; |
53 |
|
|
private final JSplitPane splitPane; |
54 |
|
|
|
55 |
|
|
/** Creates a new instance of <code>InstrumentsDbPane</code> */ |
56 |
|
|
public |
57 |
|
|
InstrumentsDbPane() { |
58 |
|
|
setLayout(new BorderLayout()); |
59 |
iliev |
2288 |
if(SHF.getInstrumentsDbTreeModel() != null) { |
60 |
|
|
instrumentsDbTree = new FantasiaInstrumentsDbTree(SHF.getInstrumentsDbTreeModel()); |
61 |
iliev |
1729 |
} else { |
62 |
iliev |
1743 |
instrumentsDbTree = new FantasiaInstrumentsDbTree(new InstrumentsDbTreeModel(true)); |
63 |
iliev |
1729 |
} |
64 |
|
|
|
65 |
iliev |
1752 |
instrumentsTable = new JSInstrumentsDbTable(instrumentsDbTree, "InstrumentsDbPane."); |
66 |
iliev |
1729 |
instrumentsTable.getModel().setShowDummyColumn(true); |
67 |
iliev |
1752 |
instrumentsTable.loadColumnsVisibleState(); |
68 |
|
|
instrumentsTable.loadColumnWidths(); |
69 |
|
|
instrumentsTable.loadSortOrder(); |
70 |
iliev |
1729 |
|
71 |
|
|
instrumentsDbTree.setSelectedDirectory("/"); |
72 |
|
|
|
73 |
|
|
JScrollPane sp1 = new JScrollPane(instrumentsDbTree); |
74 |
|
|
sp1.setPreferredSize(new Dimension(200, 200)); |
75 |
|
|
JScrollPane sp2 = new JScrollPane(instrumentsTable); |
76 |
|
|
sp2.setPreferredSize(new Dimension(200, 200)); |
77 |
iliev |
1743 |
sp2.setOpaque(false); |
78 |
|
|
sp2.getViewport().setOpaque(false); |
79 |
iliev |
1729 |
|
80 |
|
|
splitPane = new JSplitPane ( |
81 |
|
|
JSplitPane.VERTICAL_SPLIT, |
82 |
|
|
true, // continuousLayout |
83 |
|
|
sp1, |
84 |
|
|
sp2 |
85 |
|
|
); |
86 |
|
|
|
87 |
iliev |
1778 |
splitPane.setResizeWeight(0.4); |
88 |
|
|
|
89 |
iliev |
1729 |
add(splitPane); |
90 |
iliev |
1752 |
add(new ToolBar(), BorderLayout.NORTH); |
91 |
iliev |
1778 |
|
92 |
|
|
int i = preferences().getIntProperty("InstrumentsDbPane.splitDividerLocation", 160); |
93 |
|
|
splitPane.setDividerLocation(i); |
94 |
iliev |
1729 |
} |
95 |
|
|
|
96 |
|
|
protected void |
97 |
|
|
savePreferences() { |
98 |
iliev |
1752 |
instrumentsTable.saveColumnsVisibleState(); |
99 |
|
|
instrumentsTable.saveColumnWidths(); |
100 |
iliev |
1778 |
|
101 |
|
|
int i = splitPane.getDividerLocation(); |
102 |
|
|
preferences().setIntProperty("InstrumentsDbPane.splitDividerLocation", i); |
103 |
iliev |
1752 |
} |
104 |
|
|
|
105 |
|
|
class ToolBar extends JToolBar { |
106 |
|
|
protected final JButton btnGoUp = new ToolbarButton(instrumentsDbTree.actionGoUp); |
107 |
|
|
protected final JButton btnGoBack = new ToolbarButton(instrumentsDbTree.actionGoBack); |
108 |
|
|
protected final JButton btnGoForward = new ToolbarButton(instrumentsDbTree.actionGoForward); |
109 |
|
|
protected final JButton btnReload = new ToolbarButton(instrumentsTable.reloadAction); |
110 |
|
|
protected final JButton btnPreferences = new ToolbarButton(null); |
111 |
iliev |
1729 |
|
112 |
iliev |
1752 |
public ToolBar() { |
113 |
|
|
super(""); |
114 |
|
|
setFloatable(false); |
115 |
|
|
|
116 |
|
|
add(btnGoBack); |
117 |
|
|
add(btnGoForward); |
118 |
|
|
add(btnGoUp); |
119 |
|
|
|
120 |
|
|
instrumentsTable.reloadAction.putValue(Action.SMALL_ICON, Res.iconReload16); |
121 |
|
|
add(btnReload); |
122 |
|
|
|
123 |
|
|
addSeparator(); |
124 |
|
|
|
125 |
|
|
btnPreferences.setIcon(Res.iconPreferences16); |
126 |
|
|
add(btnPreferences); |
127 |
|
|
|
128 |
|
|
btnPreferences.addActionListener(new ActionListener() { |
129 |
|
|
public void |
130 |
|
|
actionPerformed(ActionEvent e) { |
131 |
|
|
new PreferencesDlg().setVisible(true); |
132 |
|
|
} |
133 |
|
|
}); |
134 |
|
|
} |
135 |
iliev |
1729 |
} |
136 |
iliev |
1752 |
|
137 |
|
|
class PreferencesDlg extends JSInstrumentsDbColumnPreferencesDlg { |
138 |
|
|
PreferencesDlg() { |
139 |
iliev |
2288 |
super(SHF.getMainFrame(), instrumentsTable); |
140 |
iliev |
1752 |
} |
141 |
|
|
} |
142 |
iliev |
1729 |
} |