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.GridBagConstraints; |
29 |
import java.awt.GridBagLayout; |
30 |
import java.awt.Insets; |
31 |
|
32 |
import java.awt.event.ActionEvent; |
33 |
import java.awt.event.ActionListener; |
34 |
import java.awt.event.ItemEvent; |
35 |
import java.awt.event.ItemListener; |
36 |
import java.awt.event.MouseAdapter; |
37 |
import java.awt.event.MouseEvent; |
38 |
|
39 |
import java.util.Calendar; |
40 |
import java.util.Date; |
41 |
|
42 |
import javax.swing.BorderFactory; |
43 |
import javax.swing.Box; |
44 |
import javax.swing.BoxLayout; |
45 |
import javax.swing.ButtonGroup; |
46 |
import javax.swing.JButton; |
47 |
import javax.swing.JCheckBox; |
48 |
import javax.swing.JComboBox; |
49 |
import javax.swing.JLabel; |
50 |
import javax.swing.JPanel; |
51 |
import javax.swing.JRadioButton; |
52 |
import javax.swing.JScrollPane; |
53 |
import javax.swing.JSpinner; |
54 |
import javax.swing.JTextField; |
55 |
import javax.swing.JToggleButton; |
56 |
import javax.swing.SpinnerDateModel; |
57 |
import javax.swing.SpinnerNumberModel; |
58 |
|
59 |
import javax.swing.event.DocumentEvent; |
60 |
import javax.swing.event.DocumentListener; |
61 |
|
62 |
import net.sf.juife.NavigationPage; |
63 |
|
64 |
import net.sf.juife.event.TaskEvent; |
65 |
import net.sf.juife.event.TaskListener; |
66 |
|
67 |
import org.jsampler.CC; |
68 |
import org.jsampler.task.InstrumentsDb; |
69 |
|
70 |
import org.linuxsampler.lscp.DbSearchQuery; |
71 |
|
72 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
73 |
|
74 |
|
75 |
/** |
76 |
* |
77 |
* @author Grigor Iliev |
78 |
*/ |
79 |
public class DbSearchPage extends NavigationPage implements ActionListener { |
80 |
private final JLabel lName = new JLabel(i18n.getLabel("DbSearchPage.lName")); |
81 |
private final JTextField tfName = new JTextField(); |
82 |
|
83 |
private final JLabel lDescription = |
84 |
new JLabel(i18n.getLabel("DbSearchPage.lDescription")); |
85 |
private final JTextField tfDescription = new JTextField(); |
86 |
|
87 |
private final JLabel lLookIn = new JLabel(i18n.getLabel("DbSearchPage.lLookIn")); |
88 |
private final JTextField tfLookIn = new JTextField(); |
89 |
private JButton btnBrowse = new JButton(Res.iconFolderOpen16); |
90 |
|
91 |
private TypeCriteriaPane typeCriteriaPane = new TypeCriteriaPane(); |
92 |
private DateCriteriaPane dateCreatedPane = new DateCriteriaPane(); |
93 |
private DateCriteriaPane dateModifiedPane = new DateCriteriaPane(); |
94 |
private SizeCriteriaPane sizeCriteriaPane = new SizeCriteriaPane(); |
95 |
//private FormatCriteriaPane formatCriteriaPane = new FormatCriteriaPane(); |
96 |
private IsDrumCriteriaPane isDrumCriteriaPane = new IsDrumCriteriaPane(); |
97 |
private MoreCriteriasPane moreCriteriasPane = new MoreCriteriasPane(); |
98 |
private JButton btnFind = new JButton(i18n.getButtonLabel("DbSearchPage.btnFind")); |
99 |
|
100 |
private InstrumentsDbFrame frame; |
101 |
|
102 |
/** Creates a new instance of <code>DbSearchPage</code>. */ |
103 |
public |
104 |
DbSearchPage(final InstrumentsDbFrame frame) { |
105 |
this.frame = frame; |
106 |
|
107 |
setTitle(i18n.getLabel("DbSearchPage.title")); |
108 |
setLayout(new BorderLayout()); |
109 |
|
110 |
JPanel p = new JPanel(); |
111 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
112 |
|
113 |
JPanel p2 = new JPanel(); |
114 |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
115 |
|
116 |
lName.setAlignmentX(LEFT_ALIGNMENT); |
117 |
p2.add(lName); |
118 |
p2.add(Box.createRigidArea(new Dimension(0, 3))); |
119 |
tfName.setAlignmentX(LEFT_ALIGNMENT); |
120 |
p2.add(tfName); |
121 |
|
122 |
p2.add(Box.createRigidArea(new Dimension(0, 6))); |
123 |
|
124 |
lDescription.setAlignmentX(LEFT_ALIGNMENT); |
125 |
p2.add(lDescription); |
126 |
p2.add(Box.createRigidArea(new Dimension(0, 3))); |
127 |
tfDescription.setAlignmentX(LEFT_ALIGNMENT); |
128 |
p2.add(tfDescription); |
129 |
|
130 |
p2.setBorder(BorderFactory.createEmptyBorder(3, 0, 6, 6)); |
131 |
int h = p2.getPreferredSize().height; |
132 |
p2.setMaximumSize(new Dimension(Short.MAX_VALUE, h)); |
133 |
p2.setOpaque(false); |
134 |
p2.setAlignmentX(LEFT_ALIGNMENT); |
135 |
p.add(p2); |
136 |
|
137 |
lLookIn.setAlignmentX(LEFT_ALIGNMENT); |
138 |
p.add(lLookIn); |
139 |
|
140 |
p2 = new JPanel(); |
141 |
p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS)); |
142 |
tfLookIn.setText("/"); |
143 |
p2.add(tfLookIn); |
144 |
p2.add(Box.createRigidArea(new Dimension(6, 0))); |
145 |
btnBrowse.setMargin(new Insets(0, 0, 0, 0)); |
146 |
p2.add(btnBrowse); |
147 |
p2.setBorder(BorderFactory.createEmptyBorder(3, 0, 6, 6)); |
148 |
h = p2.getPreferredSize().height; |
149 |
p2.setMaximumSize(new Dimension(Short.MAX_VALUE, h)); |
150 |
p2.setOpaque(false); |
151 |
p2.setAlignmentX(LEFT_ALIGNMENT); |
152 |
p.add(p2); |
153 |
|
154 |
String s = i18n.getLabel("DbSearchPage.typeCriteria"); |
155 |
p.add(new CriteriaPane(s, typeCriteriaPane)); |
156 |
p.add(Box.createRigidArea(new Dimension(0, 6))); |
157 |
|
158 |
s = i18n.getLabel("DbSearchPage.modifiedCriteria"); |
159 |
p.add(new CriteriaPane(s, dateModifiedPane)); |
160 |
p.add(Box.createRigidArea(new Dimension(0, 6))); |
161 |
|
162 |
s = i18n.getLabel("DbSearchPage.createdCriteria"); |
163 |
p.add(new CriteriaPane(s, dateCreatedPane)); |
164 |
p.add(Box.createRigidArea(new Dimension(0, 6))); |
165 |
|
166 |
s = i18n.getLabel("DbSearchPage.sizeCriteria"); |
167 |
p.add(new CriteriaPane(s, sizeCriteriaPane)); |
168 |
p.add(Box.createRigidArea(new Dimension(0, 6))); |
169 |
|
170 |
/*s = i18n.getLabel("DbSearchPage.formatCriteria"); |
171 |
p.add(new CriteriaPane(s, formatCriteriaPane)); |
172 |
p.add(Box.createRigidArea(new Dimension(0, 6)));*/ |
173 |
|
174 |
s = i18n.getLabel("DbSearchPage.isDrumCriteria"); |
175 |
p.add(new CriteriaPane(s, isDrumCriteriaPane)); |
176 |
p.add(Box.createRigidArea(new Dimension(0, 6))); |
177 |
|
178 |
s = i18n.getLabel("DbSearchPage.moreCriterias"); |
179 |
p.add(new CriteriaPane(s, moreCriteriasPane)); |
180 |
|
181 |
p2 = new JPanel(); |
182 |
p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS)); |
183 |
p2.add(Box.createGlue()); |
184 |
p2.add(btnFind); |
185 |
h = p2.getPreferredSize().height; |
186 |
p2.setMaximumSize(new Dimension(Short.MAX_VALUE, h)); |
187 |
p2.setBorder(BorderFactory.createEmptyBorder(12, 0, 6, 6)); |
188 |
p2.setOpaque(false); |
189 |
p2.setAlignmentX(LEFT_ALIGNMENT); |
190 |
p.add(p2); |
191 |
|
192 |
p.add(Box.createGlue()); |
193 |
p.setBorder(BorderFactory.createEmptyBorder(3, 6, 3, 3)); |
194 |
p.setBackground(java.awt.Color.WHITE); |
195 |
|
196 |
add(new JScrollPane(p)); |
197 |
|
198 |
tfName.addActionListener(this); |
199 |
tfName.getDocument().addDocumentListener(getHandler()); |
200 |
|
201 |
tfDescription.addActionListener(this); |
202 |
tfDescription.getDocument().addDocumentListener(getHandler()); |
203 |
|
204 |
tfLookIn.getDocument().addDocumentListener(getHandler()); |
205 |
|
206 |
btnFind.addActionListener(this); |
207 |
btnFind.setEnabled(false); |
208 |
|
209 |
btnBrowse.addActionListener(new ActionListener() { |
210 |
public void |
211 |
actionPerformed(ActionEvent e) { |
212 |
DbDirectoryChooser dlg; |
213 |
dlg = new DbDirectoryChooser(frame); |
214 |
String s = tfLookIn.getText(); |
215 |
if(s.length() > 0) dlg.setSelectedDirectory(s); |
216 |
dlg.setVisible(true); |
217 |
if(dlg.isCancelled()) return; |
218 |
tfLookIn.setText(dlg.getSelectedDirectory()); |
219 |
} |
220 |
}); |
221 |
} |
222 |
|
223 |
public void |
224 |
actionPerformed(ActionEvent e) { find(); } |
225 |
|
226 |
private void |
227 |
find() { |
228 |
if(!btnFind.isEnabled()) return; |
229 |
btnFind.setEnabled(false); |
230 |
DbSearchQuery query = new DbSearchQuery(); |
231 |
query.name = tfName.getText(); |
232 |
query.description = tfDescription.getText(); |
233 |
query.createdAfter = dateCreatedPane.getDateAfter(); |
234 |
query.createdBefore = dateCreatedPane.getDateBefore(); |
235 |
query.modifiedAfter = dateModifiedPane.getDateAfter(); |
236 |
query.modifiedBefore = dateModifiedPane.getDateBefore(); |
237 |
query.minSize = sizeCriteriaPane.getMinSize(); |
238 |
query.maxSize = sizeCriteriaPane.getMaxSize(); |
239 |
query.product = moreCriteriasPane.getProduct(); |
240 |
query.artists = moreCriteriasPane.getArtists(); |
241 |
query.keywords = moreCriteriasPane.getKeywords(); |
242 |
query.instrumentType = isDrumCriteriaPane.getInstrumentType(); |
243 |
|
244 |
final InstrumentsDb.FindInstruments t; |
245 |
final InstrumentsDb.FindDirectories t2; |
246 |
|
247 |
if(typeCriteriaPane.getSearchInstruments()) { |
248 |
t = new InstrumentsDb.FindInstruments(tfLookIn.getText(), query); |
249 |
|
250 |
t.addTaskListener(new TaskListener() { |
251 |
public void |
252 |
taskPerformed(TaskEvent e) { |
253 |
if(!typeCriteriaPane.getSearchDirectories()) { |
254 |
updateState(); |
255 |
if(t.doneWithErrors()) return; |
256 |
frame.setSearchResults(t.getResult()); |
257 |
} |
258 |
} |
259 |
}); |
260 |
} else { |
261 |
t = null; |
262 |
} |
263 |
|
264 |
if(typeCriteriaPane.getSearchDirectories()) { |
265 |
t2 = new InstrumentsDb.FindDirectories(tfLookIn.getText(), query); |
266 |
|
267 |
t2.addTaskListener(new TaskListener() { |
268 |
public void |
269 |
taskPerformed(TaskEvent e) { |
270 |
updateState(); |
271 |
if(t2.doneWithErrors()) return; |
272 |
|
273 |
if(t == null) frame.setSearchResults(t2.getResult()); |
274 |
else frame.setSearchResults(t2.getResult(), t.getResult()); |
275 |
} |
276 |
}); |
277 |
} else { |
278 |
t2 = null; |
279 |
} |
280 |
|
281 |
if(t != null) CC.getTaskQueue().add(t); |
282 |
if (t2 != null) CC.getTaskQueue().add(t2); |
283 |
} |
284 |
|
285 |
private void |
286 |
updateState() { |
287 |
boolean b = tfName.getText().length() != 0 || tfDescription.getText().length() != 0; |
288 |
b = b && tfLookIn.getText().length() != 0; |
289 |
btnFind.setEnabled(b); |
290 |
} |
291 |
|
292 |
private final Handler eventHandler = new Handler(); |
293 |
|
294 |
private Handler |
295 |
getHandler() { return eventHandler; } |
296 |
|
297 |
private class Handler implements DocumentListener { |
298 |
// DocumentListener |
299 |
public void |
300 |
insertUpdate(DocumentEvent e) { updateState(); } |
301 |
|
302 |
public void |
303 |
removeUpdate(DocumentEvent e) { updateState(); } |
304 |
|
305 |
public void |
306 |
changedUpdate(DocumentEvent e) { updateState(); } |
307 |
} |
308 |
|
309 |
class CriteriaPane extends JPanel { |
310 |
|
311 |
CriteriaPane(String title, final JPanel mainPane) { |
312 |
setOpaque(false); |
313 |
|
314 |
final JToggleButton btn = new JToggleButton(); |
315 |
btn.setBorderPainted(false); |
316 |
btn.setContentAreaFilled(false); |
317 |
btn.setFocusPainted(false); |
318 |
btn.setIcon(Res.iconBack16); |
319 |
btn.setSelectedIcon(Res.iconDown16); |
320 |
btn.setMargin(new Insets(0, 0, 0, 0)); |
321 |
btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
322 |
btn.setOpaque(false); |
323 |
|
324 |
final JLabel l = new JLabel(title); |
325 |
l.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
326 |
int h = l.getMaximumSize().height; |
327 |
Dimension d = new Dimension(Short.MAX_VALUE, h); |
328 |
l.setMaximumSize(d); |
329 |
l.setOpaque(false); |
330 |
|
331 |
setLayout(new BorderLayout()); |
332 |
JPanel p = new JPanel(); |
333 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
334 |
p.add(l); |
335 |
p.add(btn); |
336 |
add(p, BorderLayout.NORTH); |
337 |
p.setOpaque(false); |
338 |
|
339 |
mainPane.setVisible(false); |
340 |
add(mainPane); |
341 |
|
342 |
h = getMaximumSize().height; |
343 |
d = new Dimension(Short.MAX_VALUE, h); |
344 |
setMaximumSize(d); |
345 |
|
346 |
btn.addActionListener(new ActionListener() { |
347 |
public void |
348 |
actionPerformed(ActionEvent e) { |
349 |
mainPane.setVisible(btn.isSelected()); |
350 |
} |
351 |
}); |
352 |
|
353 |
l.addMouseListener(new MouseAdapter() { |
354 |
public void |
355 |
mouseClicked(MouseEvent e) { |
356 |
if(e.getButton() != e.BUTTON1) return; |
357 |
if(e.getClickCount() != 1) return; |
358 |
|
359 |
btn.doClick(); |
360 |
} |
361 |
}); |
362 |
|
363 |
h = getPreferredSize().height; |
364 |
setMaximumSize(new Dimension(Short.MAX_VALUE, h)); |
365 |
|
366 |
setAlignmentX(LEFT_ALIGNMENT); |
367 |
} |
368 |
} |
369 |
|
370 |
class TypeCriteriaPane extends JPanel implements ActionListener { |
371 |
private JRadioButton rbInstruments = |
372 |
new JRadioButton(i18n.getLabel("TypeCriteriaPane.rbInstruments")); |
373 |
private JRadioButton rbDirectories = |
374 |
new JRadioButton(i18n.getLabel("TypeCriteriaPane.rbDirectories")); |
375 |
private JRadioButton rbBoth = |
376 |
new JRadioButton(i18n.getLabel("TypeCriteriaPane.rbBoth")); |
377 |
|
378 |
TypeCriteriaPane() { |
379 |
setOpaque(false); |
380 |
|
381 |
ButtonGroup group = new ButtonGroup(); |
382 |
group.add(rbInstruments); |
383 |
group.add(rbDirectories); |
384 |
group.add(rbBoth); |
385 |
rbInstruments.doClick(0); |
386 |
|
387 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
388 |
rbInstruments.setAlignmentX(LEFT_ALIGNMENT); |
389 |
rbInstruments.setOpaque(false); |
390 |
add(rbInstruments); |
391 |
rbDirectories.setAlignmentX(LEFT_ALIGNMENT); |
392 |
rbDirectories.setOpaque(false); |
393 |
add(rbDirectories); |
394 |
rbBoth.setAlignmentX(LEFT_ALIGNMENT); |
395 |
rbBoth.setOpaque(false); |
396 |
add(rbBoth); |
397 |
|
398 |
setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 9)); |
399 |
|
400 |
rbInstruments.addActionListener(this); |
401 |
rbDirectories.addActionListener(this); |
402 |
rbBoth.addActionListener(this); |
403 |
} |
404 |
|
405 |
public void |
406 |
actionPerformed(ActionEvent e) { |
407 |
boolean b = !rbDirectories.isSelected(); |
408 |
sizeCriteriaPane.setEnabled(b); |
409 |
isDrumCriteriaPane.setEnabled(b); |
410 |
moreCriteriasPane.setEnabled(b); |
411 |
} |
412 |
|
413 |
public boolean |
414 |
getSearchInstruments() { |
415 |
return rbInstruments.isSelected() || rbBoth.isSelected(); |
416 |
} |
417 |
|
418 |
public boolean |
419 |
getSearchDirectories() { |
420 |
return rbDirectories.isSelected() || rbBoth.isSelected(); |
421 |
} |
422 |
} |
423 |
|
424 |
class DateCriteriaPane extends JPanel implements ActionListener { |
425 |
private JRadioButton rbDontRemember = |
426 |
new JRadioButton(i18n.getLabel("DateCriteriaPane.rbDontRemember")); |
427 |
private JRadioButton rbSpecifyDates = |
428 |
new JRadioButton(i18n.getLabel("DateCriteriaPane.rbSpecifyDates")); |
429 |
private JSpinner spinnerBefore = new JSpinner(new SpinnerDateModel()); |
430 |
private JSpinner spinnerAfter = new JSpinner(new SpinnerDateModel()); |
431 |
|
432 |
DateCriteriaPane() { |
433 |
setOpaque(false); |
434 |
|
435 |
ButtonGroup group = new ButtonGroup(); |
436 |
group.add(rbDontRemember); |
437 |
group.add(rbSpecifyDates); |
438 |
rbDontRemember.doClick(0); |
439 |
|
440 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
441 |
rbDontRemember.setAlignmentX(LEFT_ALIGNMENT); |
442 |
rbDontRemember.setOpaque(false); |
443 |
add(rbDontRemember); |
444 |
rbSpecifyDates.setAlignmentX(LEFT_ALIGNMENT); |
445 |
rbSpecifyDates.setOpaque(false); |
446 |
add(rbSpecifyDates); |
447 |
|
448 |
JPanel p = new JPanel(); |
449 |
GridBagLayout gridbag = new GridBagLayout(); |
450 |
GridBagConstraints c = new GridBagConstraints(); |
451 |
p.setLayout(gridbag); |
452 |
|
453 |
c.fill = GridBagConstraints.NONE; |
454 |
|
455 |
JLabel l = new JLabel(i18n.getLabel("DateCriteriaPane.from")); |
456 |
c.gridx = 0; |
457 |
c.gridy = 0; |
458 |
c.anchor = GridBagConstraints.WEST; |
459 |
c.insets = new Insets(3, 18, 3, 3); |
460 |
gridbag.setConstraints(l, c); |
461 |
p.add(l); |
462 |
|
463 |
l = new JLabel(i18n.getLabel("DateCriteriaPane.to")); |
464 |
c.gridx = 0; |
465 |
c.gridy = 1; |
466 |
gridbag.setConstraints(l, c); |
467 |
p.add(l); |
468 |
|
469 |
spinnerAfter.setEnabled(false); |
470 |
c.gridx = 1; |
471 |
c.gridy = 0; |
472 |
c.insets = new Insets(3, 3, 3, 3); |
473 |
c.fill = GridBagConstraints.HORIZONTAL; |
474 |
c.weightx = 1.0; |
475 |
gridbag.setConstraints(spinnerAfter, c); |
476 |
p.add(spinnerAfter); |
477 |
|
478 |
spinnerBefore.setEnabled(false); |
479 |
c.gridx = 1; |
480 |
c.gridy = 1; |
481 |
gridbag.setConstraints(spinnerBefore, c); |
482 |
p.add(spinnerBefore); |
483 |
|
484 |
p.setAlignmentX(LEFT_ALIGNMENT); |
485 |
p.setOpaque(false); |
486 |
add(p); |
487 |
|
488 |
setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 9)); |
489 |
|
490 |
rbDontRemember.addActionListener(this); |
491 |
rbSpecifyDates.addActionListener(this); |
492 |
|
493 |
Calendar calendar = Calendar.getInstance(); |
494 |
calendar.add(Calendar.MONTH, -1); |
495 |
spinnerAfter.setValue(calendar.getTime()); |
496 |
} |
497 |
|
498 |
public void |
499 |
actionPerformed(ActionEvent e) { |
500 |
boolean b = rbSpecifyDates.isSelected(); |
501 |
spinnerAfter.setEnabled(b); |
502 |
spinnerBefore.setEnabled(b); |
503 |
} |
504 |
|
505 |
public Date |
506 |
getDateAfter() { |
507 |
if(!rbSpecifyDates.isSelected()) return null; |
508 |
return (Date)spinnerAfter.getValue(); |
509 |
} |
510 |
|
511 |
public Date |
512 |
getDateBefore() { |
513 |
if(!rbSpecifyDates.isSelected()) return null; |
514 |
return (Date)spinnerBefore.getValue(); |
515 |
} |
516 |
} |
517 |
|
518 |
class SizeCriteriaPane extends JPanel implements ActionListener { |
519 |
private JRadioButton rbDontRemember = |
520 |
new JRadioButton(i18n.getLabel("SizeCriteriaPane.rbDontRemember")); |
521 |
private JRadioButton rbSpecifySize = |
522 |
new JRadioButton(i18n.getLabel("SizeCriteriaPane.rbSpecifySize")); |
523 |
private JSpinner spinnerFrom = new JSpinner(new SpinnerNumberModel()); |
524 |
private JSpinner spinnerTo = new JSpinner(new SpinnerNumberModel()); |
525 |
|
526 |
private final JComboBox cbEntity = new JComboBox(); |
527 |
|
528 |
|
529 |
SizeCriteriaPane() { |
530 |
setOpaque(false); |
531 |
|
532 |
ButtonGroup group = new ButtonGroup(); |
533 |
group.add(rbDontRemember); |
534 |
group.add(rbSpecifySize); |
535 |
rbDontRemember.doClick(0); |
536 |
|
537 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
538 |
rbDontRemember.setAlignmentX(LEFT_ALIGNMENT); |
539 |
rbDontRemember.setOpaque(false); |
540 |
add(rbDontRemember); |
541 |
|
542 |
JPanel p = new JPanel(); |
543 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
544 |
p.setAlignmentX(LEFT_ALIGNMENT); |
545 |
rbSpecifySize.setOpaque(false); |
546 |
p.add(rbSpecifySize); |
547 |
p.add(Box.createRigidArea(new Dimension(3, 0))); |
548 |
p.add(cbEntity); |
549 |
add(p); |
550 |
p.setOpaque(false); |
551 |
|
552 |
cbEntity.addItem("KB"); |
553 |
cbEntity.addItem("MB"); |
554 |
cbEntity.addItem("GB"); |
555 |
cbEntity.setSelectedIndex(1); |
556 |
cbEntity.setMaximumSize(cbEntity.getPreferredSize()); |
557 |
|
558 |
p = new JPanel(); |
559 |
GridBagLayout gridbag = new GridBagLayout(); |
560 |
GridBagConstraints c = new GridBagConstraints(); |
561 |
p.setLayout(gridbag); |
562 |
|
563 |
c.fill = GridBagConstraints.NONE; |
564 |
|
565 |
JLabel l = new JLabel(i18n.getLabel("SizeCriteriaPane.from")); |
566 |
c.gridx = 0; |
567 |
c.gridy = 0; |
568 |
c.anchor = GridBagConstraints.WEST; |
569 |
c.insets = new Insets(3, 18, 3, 3); |
570 |
gridbag.setConstraints(l, c); |
571 |
p.add(l); |
572 |
|
573 |
l = new JLabel(i18n.getLabel("SizeCriteriaPane.to")); |
574 |
c.gridx = 0; |
575 |
c.gridy = 1; |
576 |
gridbag.setConstraints(l, c); |
577 |
p.add(l); |
578 |
|
579 |
spinnerFrom.setEnabled(false); |
580 |
c.gridx = 1; |
581 |
c.gridy = 0; |
582 |
c.insets = new Insets(3, 3, 3, 3); |
583 |
c.fill = GridBagConstraints.HORIZONTAL; |
584 |
c.weightx = 1.0; |
585 |
gridbag.setConstraints(spinnerFrom, c); |
586 |
p.add(spinnerFrom); |
587 |
|
588 |
spinnerTo.setEnabled(false); |
589 |
c.gridx = 1; |
590 |
c.gridy = 1; |
591 |
gridbag.setConstraints(spinnerTo, c); |
592 |
p.add(spinnerTo); |
593 |
|
594 |
p.setAlignmentX(LEFT_ALIGNMENT); |
595 |
p.setOpaque(false); |
596 |
add(p); |
597 |
|
598 |
setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 9)); |
599 |
|
600 |
rbDontRemember.addActionListener(this); |
601 |
rbSpecifySize.addActionListener(this); |
602 |
} |
603 |
|
604 |
public void |
605 |
actionPerformed(ActionEvent e) { |
606 |
boolean b = rbSpecifySize.isSelected(); |
607 |
spinnerFrom.setEnabled(b); |
608 |
spinnerTo.setEnabled(b); |
609 |
} |
610 |
|
611 |
public long |
612 |
getMinSize() { |
613 |
if(!rbSpecifySize.isSelected()) return -1; |
614 |
return calcSize(Long.parseLong(spinnerFrom.getValue().toString())); |
615 |
} |
616 |
|
617 |
public long |
618 |
getMaxSize() { |
619 |
if(!rbSpecifySize.isSelected()) return -1; |
620 |
return calcSize(Long.parseLong(spinnerTo.getValue().toString())); |
621 |
} |
622 |
|
623 |
private long |
624 |
calcSize(long size) { |
625 |
switch(cbEntity.getSelectedIndex()) { |
626 |
case 0: |
627 |
size *= 1024; |
628 |
break; |
629 |
case 1: |
630 |
size *= (1024 * 1024); |
631 |
break; |
632 |
case 2: |
633 |
size *= (1024 * 1024 * 1024); |
634 |
break; |
635 |
} |
636 |
|
637 |
return size; |
638 |
} |
639 |
|
640 |
public void |
641 |
setEnabled(boolean b) { |
642 |
super.setEnabled(b); |
643 |
rbDontRemember.setEnabled(b); |
644 |
rbSpecifySize.setEnabled(b); |
645 |
spinnerFrom.setEnabled(b); |
646 |
spinnerTo.setEnabled(b); |
647 |
cbEntity.setEnabled(b); |
648 |
if(b) actionPerformed(null); |
649 |
} |
650 |
} |
651 |
|
652 |
class FormatCriteriaPane extends JPanel implements ItemListener { |
653 |
private JCheckBox checkAllFormats = |
654 |
new JCheckBox(i18n.getLabel("FormatCriteriaPane.checkAllFormats")); |
655 |
private JCheckBox checkGigFormat = |
656 |
new JCheckBox(i18n.getLabel("FormatCriteriaPane.checkGigFormat")); |
657 |
|
658 |
FormatCriteriaPane() { |
659 |
setOpaque(false); |
660 |
|
661 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
662 |
checkAllFormats.setAlignmentX(LEFT_ALIGNMENT); |
663 |
checkAllFormats.setOpaque(false); |
664 |
add(checkAllFormats); |
665 |
|
666 |
JPanel p = new JPanel(); |
667 |
p.setOpaque(false); |
668 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
669 |
p.setAlignmentX(LEFT_ALIGNMENT); |
670 |
p.setBorder(BorderFactory.createEmptyBorder(0, 12, 0, 0)); |
671 |
|
672 |
p.add(checkGigFormat); |
673 |
add(p); |
674 |
|
675 |
setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 9)); |
676 |
|
677 |
checkAllFormats.addItemListener(this); |
678 |
checkGigFormat.addItemListener(this); |
679 |
} |
680 |
|
681 |
public void |
682 |
itemStateChanged(ItemEvent e) { |
683 |
Object source = e.getItemSelectable(); |
684 |
if(source == checkAllFormats) { |
685 |
|
686 |
} else if(source == checkGigFormat) { |
687 |
|
688 |
} |
689 |
} |
690 |
} |
691 |
|
692 |
class IsDrumCriteriaPane extends JPanel { |
693 |
private JRadioButton rbBoth = |
694 |
new JRadioButton(i18n.getLabel("IsDrumCriteriaPane.rbBoth")); |
695 |
private JRadioButton rbChromatic = |
696 |
new JRadioButton(i18n.getLabel("IsDrumCriteriaPane.rbChromatic")); |
697 |
private JRadioButton rbDrum = |
698 |
new JRadioButton(i18n.getLabel("IsDrumCriteriaPane.rbDrum")); |
699 |
|
700 |
|
701 |
IsDrumCriteriaPane() { |
702 |
setOpaque(false); |
703 |
|
704 |
ButtonGroup group = new ButtonGroup(); |
705 |
group.add(rbBoth); |
706 |
group.add(rbChromatic); |
707 |
group.add(rbDrum); |
708 |
rbBoth.doClick(0); |
709 |
|
710 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
711 |
|
712 |
rbBoth.setAlignmentX(LEFT_ALIGNMENT); |
713 |
rbBoth.setOpaque(false); |
714 |
add(rbBoth); |
715 |
|
716 |
rbChromatic.setAlignmentX(LEFT_ALIGNMENT); |
717 |
rbChromatic.setOpaque(false); |
718 |
add(rbChromatic); |
719 |
|
720 |
rbDrum.setAlignmentX(LEFT_ALIGNMENT); |
721 |
rbDrum.setOpaque(false); |
722 |
add(rbDrum); |
723 |
|
724 |
setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 9)); |
725 |
} |
726 |
|
727 |
public DbSearchQuery.InstrumentType |
728 |
getInstrumentType() { |
729 |
if(rbChromatic.isSelected()) { |
730 |
return DbSearchQuery.InstrumentType.CHROMATIC; |
731 |
} |
732 |
|
733 |
if(rbDrum.isSelected()) { |
734 |
return DbSearchQuery.InstrumentType.DRUM; |
735 |
} |
736 |
|
737 |
return DbSearchQuery.InstrumentType.BOTH; |
738 |
} |
739 |
|
740 |
public void |
741 |
setEnabled(boolean b) { |
742 |
super.setEnabled(b); |
743 |
rbBoth.setEnabled(b); |
744 |
rbChromatic.setEnabled(b); |
745 |
rbDrum.setEnabled(b); |
746 |
} |
747 |
} |
748 |
|
749 |
class MoreCriteriasPane extends JPanel { |
750 |
private final JLabel lProduct = |
751 |
new JLabel(i18n.getLabel("MoreCriteriasPane.lProduct")); |
752 |
private final JLabel lArtists = |
753 |
new JLabel(i18n.getLabel("MoreCriteriasPane.lArtists")); |
754 |
private final JLabel lKeywords = |
755 |
new JLabel(i18n.getLabel("MoreCriteriasPane.lKeywords")); |
756 |
|
757 |
private final JTextField tfProduct = new JTextField(); |
758 |
private final JTextField tfArtists = new JTextField(); |
759 |
private final JTextField tfKeywords = new JTextField(); |
760 |
|
761 |
MoreCriteriasPane() { |
762 |
setOpaque(false); |
763 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
764 |
|
765 |
lProduct.setAlignmentX(LEFT_ALIGNMENT); |
766 |
add(lProduct); |
767 |
add(Box.createRigidArea(new Dimension(0, 3))); |
768 |
tfProduct.setAlignmentX(LEFT_ALIGNMENT); |
769 |
add(tfProduct); |
770 |
|
771 |
add(Box.createRigidArea(new Dimension(0, 3))); |
772 |
|
773 |
lArtists.setAlignmentX(LEFT_ALIGNMENT); |
774 |
add(lArtists); |
775 |
add(Box.createRigidArea(new Dimension(0, 3))); |
776 |
tfArtists.setAlignmentX(LEFT_ALIGNMENT); |
777 |
add(tfArtists); |
778 |
|
779 |
add(Box.createRigidArea(new Dimension(0, 3))); |
780 |
|
781 |
lKeywords.setAlignmentX(LEFT_ALIGNMENT); |
782 |
add(lKeywords); |
783 |
add(Box.createRigidArea(new Dimension(0, 3))); |
784 |
tfKeywords.setAlignmentX(LEFT_ALIGNMENT); |
785 |
add(tfKeywords); |
786 |
|
787 |
setBorder(BorderFactory.createEmptyBorder(0, 9, 0, 9)); |
788 |
} |
789 |
|
790 |
public String |
791 |
getProduct() { return tfProduct.getText(); } |
792 |
|
793 |
public String |
794 |
getArtists() { return tfArtists.getText(); } |
795 |
|
796 |
public String |
797 |
getKeywords() { return tfKeywords.getText(); } |
798 |
|
799 |
public void |
800 |
setEnabled(boolean b) { |
801 |
super.setEnabled(b); |
802 |
tfProduct.setEnabled(b); |
803 |
tfArtists.setEnabled(b); |
804 |
tfKeywords.setEnabled(b); |
805 |
} |
806 |
} |
807 |
} |