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