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 |
private void |
263 |
setSearchResults(DbDirectoryInfo[] dirs, DbInstrumentInfo[] instruments) { |
264 |
directoryResults = dirs; |
265 |
instrumentResults = instruments; |
266 |
fireSearchResultsChanged(); |
267 |
} |
268 |
|
269 |
protected abstract JComponent createCriteriaPane(String title, JComponent mainPane); |
270 |
|
271 |
private void |
272 |
find() { |
273 |
if(!btnFind.isEnabled()) return; |
274 |
btnFind.setEnabled(false); |
275 |
DbSearchQuery query = new DbSearchQuery(); |
276 |
query.name = tfName.getText(); |
277 |
query.description = tfDescription.getText(); |
278 |
query.createdAfter = dateCreatedPane.getDateAfter(); |
279 |
query.createdBefore = dateCreatedPane.getDateBefore(); |
280 |
query.modifiedAfter = dateModifiedPane.getDateAfter(); |
281 |
query.modifiedBefore = dateModifiedPane.getDateBefore(); |
282 |
query.minSize = sizeCriteriaPane.getMinSize(); |
283 |
query.maxSize = sizeCriteriaPane.getMaxSize(); |
284 |
query.product = moreCriteriasPane.getProduct(); |
285 |
query.artists = moreCriteriasPane.getArtists(); |
286 |
query.keywords = moreCriteriasPane.getKeywords(); |
287 |
query.instrumentType = isDrumCriteriaPane.getInstrumentType(); |
288 |
|
289 |
final InstrumentsDb.FindInstruments t; |
290 |
final InstrumentsDb.FindDirectories t2; |
291 |
|
292 |
if(typeCriteriaPane.getSearchInstruments()) { |
293 |
t = new InstrumentsDb.FindInstruments(tfLookIn.getText(), query); |
294 |
|
295 |
t.addTaskListener(new TaskListener() { |
296 |
public void |
297 |
taskPerformed(TaskEvent e) { |
298 |
if(!typeCriteriaPane.getSearchDirectories()) { |
299 |
updateState(); |
300 |
if(t.doneWithErrors()) return; |
301 |
setSearchResults(null, t.getResult()); |
302 |
} |
303 |
} |
304 |
}); |
305 |
} else { |
306 |
t = null; |
307 |
} |
308 |
|
309 |
if(typeCriteriaPane.getSearchDirectories()) { |
310 |
t2 = new InstrumentsDb.FindDirectories(tfLookIn.getText(), query); |
311 |
|
312 |
t2.addTaskListener(new TaskListener() { |
313 |
public void |
314 |
taskPerformed(TaskEvent e) { |
315 |
updateState(); |
316 |
if(t2.doneWithErrors()) return; |
317 |
|
318 |
if(t == null) { |
319 |
setSearchResults(t2.getResult(), null); |
320 |
} else { |
321 |
setSearchResults(t2.getResult(), t.getResult()); |
322 |
} |
323 |
} |
324 |
}); |
325 |
} else { |
326 |
t2 = null; |
327 |
} |
328 |
|
329 |
if(t != null) CC.getTaskQueue().add(t); |
330 |
if (t2 != null) CC.getTaskQueue().add(t2); |
331 |
} |
332 |
|
333 |
private void |
334 |
updateState() { |
335 |
boolean b = tfName.getText().length() != 0 || tfDescription.getText().length() != 0; |
336 |
b = b && tfLookIn.getText().length() != 0; |
337 |
btnFind.setEnabled(b); |
338 |
} |
339 |
|
340 |
private final Handler eventHandler = new Handler(); |
341 |
|
342 |
private Handler |
343 |
getHandler() { return eventHandler; } |
344 |
|
345 |
private class Handler implements DocumentListener, ActionListener { |
346 |
// DocumentListener |
347 |
public void |
348 |
insertUpdate(DocumentEvent e) { updateState(); } |
349 |
|
350 |
public void |
351 |
removeUpdate(DocumentEvent e) { updateState(); } |
352 |
|
353 |
public void |
354 |
changedUpdate(DocumentEvent e) { updateState(); } |
355 |
|
356 |
public void |
357 |
actionPerformed(ActionEvent e) { find(); } |
358 |
} |
359 |
|
360 |
class TypeCriteriaPane extends JPanel implements ActionListener { |
361 |
private JRadioButton rbInstruments = |
362 |
new JRadioButton(i18n.getLabel("TypeCriteriaPane.rbInstruments")); |
363 |
private JRadioButton rbDirectories = |
364 |
new JRadioButton(i18n.getLabel("TypeCriteriaPane.rbDirectories")); |
365 |
private JRadioButton rbBoth = |
366 |
new JRadioButton(i18n.getLabel("TypeCriteriaPane.rbBoth")); |
367 |
|
368 |
TypeCriteriaPane() { |
369 |
setOpaque(false); |
370 |
|
371 |
ButtonGroup group = new ButtonGroup(); |
372 |
group.add(rbInstruments); |
373 |
group.add(rbDirectories); |
374 |
group.add(rbBoth); |
375 |
rbInstruments.doClick(0); |
376 |
|
377 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
378 |
rbInstruments.setAlignmentX(LEFT_ALIGNMENT); |
379 |
rbInstruments.setOpaque(false); |
380 |
add(rbInstruments); |
381 |
rbDirectories.setAlignmentX(LEFT_ALIGNMENT); |
382 |
rbDirectories.setOpaque(false); |
383 |
add(rbDirectories); |
384 |
rbBoth.setAlignmentX(LEFT_ALIGNMENT); |
385 |
rbBoth.setOpaque(false); |
386 |
add(rbBoth); |
387 |
|
388 |
setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 9)); |
389 |
|
390 |
rbInstruments.addActionListener(this); |
391 |
rbDirectories.addActionListener(this); |
392 |
rbBoth.addActionListener(this); |
393 |
} |
394 |
|
395 |
public void |
396 |
actionPerformed(ActionEvent e) { |
397 |
boolean b = !rbDirectories.isSelected(); |
398 |
sizeCriteriaPane.setEnabled(b); |
399 |
isDrumCriteriaPane.setEnabled(b); |
400 |
moreCriteriasPane.setEnabled(b); |
401 |
} |
402 |
|
403 |
public boolean |
404 |
getSearchInstruments() { |
405 |
return rbInstruments.isSelected() || rbBoth.isSelected(); |
406 |
} |
407 |
|
408 |
public boolean |
409 |
getSearchDirectories() { |
410 |
return rbDirectories.isSelected() || rbBoth.isSelected(); |
411 |
} |
412 |
} |
413 |
|
414 |
class DateCriteriaPane extends JPanel implements ActionListener { |
415 |
private JRadioButton rbDontRemember = |
416 |
new JRadioButton(i18n.getLabel("DateCriteriaPane.rbDontRemember")); |
417 |
private JRadioButton rbSpecifyDates = |
418 |
new JRadioButton(i18n.getLabel("DateCriteriaPane.rbSpecifyDates")); |
419 |
private JSpinner spinnerBefore = new JSpinner(new SpinnerDateModel()); |
420 |
private JSpinner spinnerAfter = new JSpinner(new SpinnerDateModel()); |
421 |
|
422 |
DateCriteriaPane() { |
423 |
setOpaque(false); |
424 |
|
425 |
ButtonGroup group = new ButtonGroup(); |
426 |
group.add(rbDontRemember); |
427 |
group.add(rbSpecifyDates); |
428 |
rbDontRemember.doClick(0); |
429 |
|
430 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
431 |
rbDontRemember.setAlignmentX(LEFT_ALIGNMENT); |
432 |
rbDontRemember.setOpaque(false); |
433 |
add(rbDontRemember); |
434 |
rbSpecifyDates.setAlignmentX(LEFT_ALIGNMENT); |
435 |
rbSpecifyDates.setOpaque(false); |
436 |
add(rbSpecifyDates); |
437 |
|
438 |
JPanel p = new JPanel(); |
439 |
GridBagLayout gridbag = new GridBagLayout(); |
440 |
GridBagConstraints c = new GridBagConstraints(); |
441 |
p.setLayout(gridbag); |
442 |
|
443 |
c.fill = GridBagConstraints.NONE; |
444 |
|
445 |
JLabel l = new JLabel(i18n.getLabel("DateCriteriaPane.from")); |
446 |
c.gridx = 0; |
447 |
c.gridy = 0; |
448 |
c.anchor = GridBagConstraints.WEST; |
449 |
c.insets = new Insets(3, 18, 3, 3); |
450 |
gridbag.setConstraints(l, c); |
451 |
p.add(l); |
452 |
|
453 |
l = new JLabel(i18n.getLabel("DateCriteriaPane.to")); |
454 |
c.gridx = 0; |
455 |
c.gridy = 1; |
456 |
gridbag.setConstraints(l, c); |
457 |
p.add(l); |
458 |
|
459 |
spinnerAfter.setEnabled(false); |
460 |
c.gridx = 1; |
461 |
c.gridy = 0; |
462 |
c.insets = new Insets(3, 3, 3, 3); |
463 |
c.fill = GridBagConstraints.HORIZONTAL; |
464 |
c.weightx = 1.0; |
465 |
gridbag.setConstraints(spinnerAfter, c); |
466 |
p.add(spinnerAfter); |
467 |
|
468 |
spinnerBefore.setEnabled(false); |
469 |
c.gridx = 1; |
470 |
c.gridy = 1; |
471 |
gridbag.setConstraints(spinnerBefore, c); |
472 |
p.add(spinnerBefore); |
473 |
|
474 |
p.setAlignmentX(LEFT_ALIGNMENT); |
475 |
p.setOpaque(false); |
476 |
add(p); |
477 |
|
478 |
setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 9)); |
479 |
|
480 |
rbDontRemember.addActionListener(this); |
481 |
rbSpecifyDates.addActionListener(this); |
482 |
|
483 |
Calendar calendar = Calendar.getInstance(); |
484 |
calendar.add(Calendar.MONTH, -1); |
485 |
spinnerAfter.setValue(calendar.getTime()); |
486 |
} |
487 |
|
488 |
public void |
489 |
actionPerformed(ActionEvent e) { |
490 |
boolean b = rbSpecifyDates.isSelected(); |
491 |
spinnerAfter.setEnabled(b); |
492 |
spinnerBefore.setEnabled(b); |
493 |
} |
494 |
|
495 |
public Date |
496 |
getDateAfter() { |
497 |
if(!rbSpecifyDates.isSelected()) return null; |
498 |
return (Date)spinnerAfter.getValue(); |
499 |
} |
500 |
|
501 |
public Date |
502 |
getDateBefore() { |
503 |
if(!rbSpecifyDates.isSelected()) return null; |
504 |
return (Date)spinnerBefore.getValue(); |
505 |
} |
506 |
} |
507 |
|
508 |
class SizeCriteriaPane extends JPanel implements ActionListener { |
509 |
private JRadioButton rbDontRemember = |
510 |
new JRadioButton(i18n.getLabel("SizeCriteriaPane.rbDontRemember")); |
511 |
private JRadioButton rbSpecifySize = |
512 |
new JRadioButton(i18n.getLabel("SizeCriteriaPane.rbSpecifySize")); |
513 |
private JSpinner spinnerFrom = new JSpinner(new SpinnerNumberModel()); |
514 |
private JSpinner spinnerTo = new JSpinner(new SpinnerNumberModel()); |
515 |
|
516 |
private final JComboBox cbEntity = new JComboBox(); |
517 |
|
518 |
|
519 |
SizeCriteriaPane() { |
520 |
setOpaque(false); |
521 |
|
522 |
ButtonGroup group = new ButtonGroup(); |
523 |
group.add(rbDontRemember); |
524 |
group.add(rbSpecifySize); |
525 |
rbDontRemember.doClick(0); |
526 |
|
527 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
528 |
rbDontRemember.setAlignmentX(LEFT_ALIGNMENT); |
529 |
rbDontRemember.setOpaque(false); |
530 |
add(rbDontRemember); |
531 |
|
532 |
JPanel p = new JPanel(); |
533 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
534 |
p.setAlignmentX(LEFT_ALIGNMENT); |
535 |
rbSpecifySize.setOpaque(false); |
536 |
p.add(rbSpecifySize); |
537 |
p.add(Box.createRigidArea(new Dimension(3, 0))); |
538 |
p.add(cbEntity); |
539 |
add(p); |
540 |
p.setOpaque(false); |
541 |
|
542 |
cbEntity.addItem("KB"); |
543 |
cbEntity.addItem("MB"); |
544 |
cbEntity.addItem("GB"); |
545 |
cbEntity.setSelectedIndex(1); |
546 |
cbEntity.setMaximumSize(cbEntity.getPreferredSize()); |
547 |
|
548 |
p = new JPanel(); |
549 |
GridBagLayout gridbag = new GridBagLayout(); |
550 |
GridBagConstraints c = new GridBagConstraints(); |
551 |
p.setLayout(gridbag); |
552 |
|
553 |
c.fill = GridBagConstraints.NONE; |
554 |
|
555 |
JLabel l = new JLabel(i18n.getLabel("SizeCriteriaPane.from")); |
556 |
c.gridx = 0; |
557 |
c.gridy = 0; |
558 |
c.anchor = GridBagConstraints.WEST; |
559 |
c.insets = new Insets(3, 18, 3, 3); |
560 |
gridbag.setConstraints(l, c); |
561 |
p.add(l); |
562 |
|
563 |
l = new JLabel(i18n.getLabel("SizeCriteriaPane.to")); |
564 |
c.gridx = 0; |
565 |
c.gridy = 1; |
566 |
gridbag.setConstraints(l, c); |
567 |
p.add(l); |
568 |
|
569 |
spinnerFrom.setEnabled(false); |
570 |
c.gridx = 1; |
571 |
c.gridy = 0; |
572 |
c.insets = new Insets(3, 3, 3, 3); |
573 |
c.fill = GridBagConstraints.HORIZONTAL; |
574 |
c.weightx = 1.0; |
575 |
gridbag.setConstraints(spinnerFrom, c); |
576 |
p.add(spinnerFrom); |
577 |
|
578 |
spinnerTo.setEnabled(false); |
579 |
c.gridx = 1; |
580 |
c.gridy = 1; |
581 |
gridbag.setConstraints(spinnerTo, c); |
582 |
p.add(spinnerTo); |
583 |
|
584 |
p.setAlignmentX(LEFT_ALIGNMENT); |
585 |
p.setOpaque(false); |
586 |
add(p); |
587 |
|
588 |
setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 9)); |
589 |
|
590 |
rbDontRemember.addActionListener(this); |
591 |
rbSpecifySize.addActionListener(this); |
592 |
} |
593 |
|
594 |
public void |
595 |
actionPerformed(ActionEvent e) { |
596 |
boolean b = rbSpecifySize.isSelected(); |
597 |
spinnerFrom.setEnabled(b); |
598 |
spinnerTo.setEnabled(b); |
599 |
} |
600 |
|
601 |
public long |
602 |
getMinSize() { |
603 |
if(!rbSpecifySize.isSelected()) return -1; |
604 |
return calcSize(Long.parseLong(spinnerFrom.getValue().toString())); |
605 |
} |
606 |
|
607 |
public long |
608 |
getMaxSize() { |
609 |
if(!rbSpecifySize.isSelected()) return -1; |
610 |
return calcSize(Long.parseLong(spinnerTo.getValue().toString())); |
611 |
} |
612 |
|
613 |
private long |
614 |
calcSize(long size) { |
615 |
switch(cbEntity.getSelectedIndex()) { |
616 |
case 0: |
617 |
size *= 1024; |
618 |
break; |
619 |
case 1: |
620 |
size *= (1024 * 1024); |
621 |
break; |
622 |
case 2: |
623 |
size *= (1024 * 1024 * 1024); |
624 |
break; |
625 |
} |
626 |
|
627 |
return size; |
628 |
} |
629 |
|
630 |
public void |
631 |
setEnabled(boolean b) { |
632 |
super.setEnabled(b); |
633 |
rbDontRemember.setEnabled(b); |
634 |
rbSpecifySize.setEnabled(b); |
635 |
spinnerFrom.setEnabled(b); |
636 |
spinnerTo.setEnabled(b); |
637 |
cbEntity.setEnabled(b); |
638 |
if(b) actionPerformed(null); |
639 |
} |
640 |
} |
641 |
|
642 |
class FormatCriteriaPane extends JPanel implements ItemListener { |
643 |
private JCheckBox checkAllFormats = |
644 |
new JCheckBox(i18n.getLabel("FormatCriteriaPane.checkAllFormats")); |
645 |
private JCheckBox checkGigFormat = |
646 |
new JCheckBox(i18n.getLabel("FormatCriteriaPane.checkGigFormat")); |
647 |
|
648 |
FormatCriteriaPane() { |
649 |
setOpaque(false); |
650 |
|
651 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
652 |
checkAllFormats.setAlignmentX(LEFT_ALIGNMENT); |
653 |
checkAllFormats.setOpaque(false); |
654 |
add(checkAllFormats); |
655 |
|
656 |
JPanel p = new JPanel(); |
657 |
p.setOpaque(false); |
658 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
659 |
p.setAlignmentX(LEFT_ALIGNMENT); |
660 |
p.setBorder(BorderFactory.createEmptyBorder(0, 12, 0, 0)); |
661 |
|
662 |
p.add(checkGigFormat); |
663 |
add(p); |
664 |
|
665 |
setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 9)); |
666 |
|
667 |
checkAllFormats.addItemListener(this); |
668 |
checkGigFormat.addItemListener(this); |
669 |
} |
670 |
|
671 |
public void |
672 |
itemStateChanged(ItemEvent e) { |
673 |
Object source = e.getItemSelectable(); |
674 |
if(source == checkAllFormats) { |
675 |
|
676 |
} else if(source == checkGigFormat) { |
677 |
|
678 |
} |
679 |
} |
680 |
} |
681 |
|
682 |
class IsDrumCriteriaPane extends JPanel { |
683 |
private JRadioButton rbBoth = |
684 |
new JRadioButton(i18n.getLabel("IsDrumCriteriaPane.rbBoth")); |
685 |
private JRadioButton rbChromatic = |
686 |
new JRadioButton(i18n.getLabel("IsDrumCriteriaPane.rbChromatic")); |
687 |
private JRadioButton rbDrum = |
688 |
new JRadioButton(i18n.getLabel("IsDrumCriteriaPane.rbDrum")); |
689 |
|
690 |
|
691 |
IsDrumCriteriaPane() { |
692 |
setOpaque(false); |
693 |
|
694 |
ButtonGroup group = new ButtonGroup(); |
695 |
group.add(rbBoth); |
696 |
group.add(rbChromatic); |
697 |
group.add(rbDrum); |
698 |
rbBoth.doClick(0); |
699 |
|
700 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
701 |
|
702 |
rbBoth.setAlignmentX(LEFT_ALIGNMENT); |
703 |
rbBoth.setOpaque(false); |
704 |
add(rbBoth); |
705 |
|
706 |
rbChromatic.setAlignmentX(LEFT_ALIGNMENT); |
707 |
rbChromatic.setOpaque(false); |
708 |
add(rbChromatic); |
709 |
|
710 |
rbDrum.setAlignmentX(LEFT_ALIGNMENT); |
711 |
rbDrum.setOpaque(false); |
712 |
add(rbDrum); |
713 |
|
714 |
setBorder(BorderFactory.createEmptyBorder(0, 6, 0, 9)); |
715 |
} |
716 |
|
717 |
public DbSearchQuery.InstrumentType |
718 |
getInstrumentType() { |
719 |
if(rbChromatic.isSelected()) { |
720 |
return DbSearchQuery.InstrumentType.CHROMATIC; |
721 |
} |
722 |
|
723 |
if(rbDrum.isSelected()) { |
724 |
return DbSearchQuery.InstrumentType.DRUM; |
725 |
} |
726 |
|
727 |
return DbSearchQuery.InstrumentType.BOTH; |
728 |
} |
729 |
|
730 |
public void |
731 |
setEnabled(boolean b) { |
732 |
super.setEnabled(b); |
733 |
rbBoth.setEnabled(b); |
734 |
rbChromatic.setEnabled(b); |
735 |
rbDrum.setEnabled(b); |
736 |
} |
737 |
} |
738 |
|
739 |
class MoreCriteriasPane extends JPanel { |
740 |
private final JLabel lProduct = |
741 |
new JLabel(i18n.getLabel("MoreCriteriasPane.lProduct")); |
742 |
private final JLabel lArtists = |
743 |
new JLabel(i18n.getLabel("MoreCriteriasPane.lArtists")); |
744 |
private final JLabel lKeywords = |
745 |
new JLabel(i18n.getLabel("MoreCriteriasPane.lKeywords")); |
746 |
|
747 |
private final JTextField tfProduct = new JTextField(); |
748 |
private final JTextField tfArtists = new JTextField(); |
749 |
private final JTextField tfKeywords = new JTextField(); |
750 |
|
751 |
MoreCriteriasPane() { |
752 |
setOpaque(false); |
753 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
754 |
|
755 |
lProduct.setAlignmentX(LEFT_ALIGNMENT); |
756 |
add(lProduct); |
757 |
add(Box.createRigidArea(new Dimension(0, 3))); |
758 |
tfProduct.setAlignmentX(LEFT_ALIGNMENT); |
759 |
add(tfProduct); |
760 |
|
761 |
add(Box.createRigidArea(new Dimension(0, 3))); |
762 |
|
763 |
lArtists.setAlignmentX(LEFT_ALIGNMENT); |
764 |
add(lArtists); |
765 |
add(Box.createRigidArea(new Dimension(0, 3))); |
766 |
tfArtists.setAlignmentX(LEFT_ALIGNMENT); |
767 |
add(tfArtists); |
768 |
|
769 |
add(Box.createRigidArea(new Dimension(0, 3))); |
770 |
|
771 |
lKeywords.setAlignmentX(LEFT_ALIGNMENT); |
772 |
add(lKeywords); |
773 |
add(Box.createRigidArea(new Dimension(0, 3))); |
774 |
tfKeywords.setAlignmentX(LEFT_ALIGNMENT); |
775 |
add(tfKeywords); |
776 |
|
777 |
setBorder(BorderFactory.createEmptyBorder(0, 9, 0, 9)); |
778 |
} |
779 |
|
780 |
public String |
781 |
getProduct() { return tfProduct.getText(); } |
782 |
|
783 |
public String |
784 |
getArtists() { return tfArtists.getText(); } |
785 |
|
786 |
public String |
787 |
getKeywords() { return tfKeywords.getText(); } |
788 |
|
789 |
public void |
790 |
setEnabled(boolean b) { |
791 |
super.setEnabled(b); |
792 |
tfProduct.setEnabled(b); |
793 |
tfArtists.setEnabled(b); |
794 |
tfKeywords.setEnabled(b); |
795 |
} |
796 |
} |
797 |
} |