1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2007 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.classic; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Cursor; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.Frame; |
29 |
import java.awt.Insets; |
30 |
|
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
import java.awt.event.MouseAdapter; |
34 |
import java.awt.event.MouseEvent; |
35 |
|
36 |
import javax.swing.BoxLayout; |
37 |
import javax.swing.JComponent; |
38 |
import javax.swing.JLabel; |
39 |
import javax.swing.JPanel; |
40 |
import javax.swing.JToggleButton; |
41 |
|
42 |
import javax.swing.event.ChangeEvent; |
43 |
import javax.swing.event.ChangeListener; |
44 |
|
45 |
import net.sf.juife.NavigationPage; |
46 |
|
47 |
import org.jsampler.view.std.JSDbSearchPane; |
48 |
|
49 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
50 |
|
51 |
/** |
52 |
* |
53 |
* @author Grigor Iliev |
54 |
*/ |
55 |
public class DbSearchPage extends NavigationPage { |
56 |
private final DbSearchPane dbSearchPane; |
57 |
|
58 |
/** Creates a new instance of <code>DbSearchPage</code> */ |
59 |
public |
60 |
DbSearchPage(final InstrumentsDbFrame frame) { |
61 |
setTitle(i18n.getLabel("DbSearchPage.title")); |
62 |
setLayout(new BorderLayout()); |
63 |
|
64 |
dbSearchPane = new DbSearchPane(frame); |
65 |
dbSearchPane.setBackgroundColor(java.awt.Color.WHITE); |
66 |
add(dbSearchPane); |
67 |
|
68 |
dbSearchPane.addChangeListener(new ChangeListener() { |
69 |
public void |
70 |
stateChanged(ChangeEvent e) { |
71 |
frame.setSearchResults ( |
72 |
dbSearchPane.getDirectoryResults(), |
73 |
dbSearchPane.getInstrumentResults() |
74 |
); |
75 |
} |
76 |
}); |
77 |
} |
78 |
|
79 |
public void |
80 |
setSearchPath(String path) { dbSearchPane.setSearchPath(path); } |
81 |
|
82 |
class DbSearchPane extends JSDbSearchPane { |
83 |
DbSearchPane(Frame owner) { |
84 |
super(owner); |
85 |
|
86 |
|
87 |
} |
88 |
|
89 |
protected JComponent |
90 |
createCriteriaPane(String title, JComponent mainPane) { |
91 |
return new CriteriaPane(title, mainPane); |
92 |
} |
93 |
} |
94 |
|
95 |
class CriteriaPane extends JPanel { |
96 |
|
97 |
CriteriaPane(String title, final JComponent mainPane) { |
98 |
setOpaque(false); |
99 |
|
100 |
final JToggleButton btn = new JToggleButton(); |
101 |
btn.setBorderPainted(false); |
102 |
btn.setContentAreaFilled(false); |
103 |
btn.setFocusPainted(false); |
104 |
btn.setIcon(Res.iconBack16); |
105 |
btn.setSelectedIcon(Res.iconDown16); |
106 |
btn.setMargin(new Insets(0, 0, 0, 0)); |
107 |
btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
108 |
btn.setOpaque(false); |
109 |
|
110 |
final JLabel l = new JLabel(title); |
111 |
l.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
112 |
int h = l.getMaximumSize().height; |
113 |
Dimension d = new Dimension(Short.MAX_VALUE, h); |
114 |
l.setMaximumSize(d); |
115 |
l.setOpaque(false); |
116 |
|
117 |
setLayout(new BorderLayout()); |
118 |
JPanel p = new JPanel(); |
119 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
120 |
p.add(l); |
121 |
p.add(btn); |
122 |
add(p, BorderLayout.NORTH); |
123 |
p.setOpaque(false); |
124 |
|
125 |
mainPane.setVisible(false); |
126 |
add(mainPane); |
127 |
|
128 |
h = getMaximumSize().height; |
129 |
d = new Dimension(Short.MAX_VALUE, h); |
130 |
setMaximumSize(d); |
131 |
|
132 |
btn.addActionListener(new ActionListener() { |
133 |
public void |
134 |
actionPerformed(ActionEvent e) { |
135 |
mainPane.setVisible(btn.isSelected()); |
136 |
} |
137 |
}); |
138 |
|
139 |
l.addMouseListener(new MouseAdapter() { |
140 |
public void |
141 |
mouseClicked(MouseEvent e) { |
142 |
if(e.getButton() != e.BUTTON1) return; |
143 |
if(e.getClickCount() != 1) return; |
144 |
|
145 |
btn.doClick(); |
146 |
} |
147 |
}); |
148 |
|
149 |
h = getPreferredSize().height; |
150 |
setMaximumSize(new Dimension(Short.MAX_VALUE, h)); |
151 |
|
152 |
setAlignmentX(LEFT_ALIGNMENT); |
153 |
} |
154 |
} |
155 |
} |