1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2010 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.fantasia.basic; |
24 |
|
25 |
import java.awt.Graphics; |
26 |
import java.awt.Insets; |
27 |
|
28 |
import javax.swing.BorderFactory; |
29 |
import javax.swing.JComboBox; |
30 |
import javax.swing.JTextField; |
31 |
|
32 |
import javax.swing.plaf.basic.BasicComboBoxEditor; |
33 |
|
34 |
import org.jsampler.view.fantasia.Res; |
35 |
|
36 |
import org.pushingpixels.substance.api.SubstanceLookAndFeel; |
37 |
import org.pushingpixels.substance.api.combo.ComboPopupPrototypeCallback; |
38 |
|
39 |
/** |
40 |
* |
41 |
* @author Grigor Iliev |
42 |
*/ |
43 |
public class FantasiaComboBox extends JComboBox { |
44 |
public |
45 |
FantasiaComboBox() { |
46 |
setOpaque(true); |
47 |
setBackground(new java.awt.Color(0x818181)); |
48 |
setBorder(BorderFactory.createEmptyBorder()); |
49 |
setRenderer(new FantasiaListCellRenderer()); |
50 |
//putClientProperty(SubstanceLookAndFeel.COLORIZATION_FACTOR, 1.0); |
51 |
//putClientProperty(SubstanceLookAndFeel.FLAT_PROPERTY, Boolean.TRUE); |
52 |
//putClientProperty(SubstanceLookAndFeel.PAINT_ACTIVE_PROPERTY, Boolean.TRUE); |
53 |
} |
54 |
|
55 |
@Override |
56 |
public void |
57 |
updateUI() { setUI(new FantasiaComboBoxUI(this)); } |
58 |
|
59 |
public static class WidestComboPopupPrototype implements ComboPopupPrototypeCallback { |
60 |
@Override |
61 |
public Object |
62 |
getPopupPrototypeDisplayValue(JComboBox jc) { |
63 |
Object prototype = ""; |
64 |
for(int i = 0; i < jc.getItemCount(); i++) { |
65 |
if(jc.getItemAt(i).toString().length() > prototype.toString().length()) { |
66 |
prototype = jc.getItemAt(i); |
67 |
} |
68 |
} |
69 |
return prototype; |
70 |
} |
71 |
} |
72 |
} |
73 |
|
74 |
class FantasiaComboBoxEditor extends BasicComboBoxEditor { |
75 |
|
76 |
/** Creates a new instance of <code>FantasiaComboBoxEditor</code> */ |
77 |
public |
78 |
FantasiaComboBoxEditor() { |
79 |
} |
80 |
|
81 |
@Override |
82 |
protected JTextField |
83 |
createEditorComponent() { return new TextEditor(); } |
84 |
|
85 |
static class TextEditor extends JTextField { |
86 |
private static Insets pixmapInsets = new Insets(1, 1, 1, 1); |
87 |
|
88 |
TextEditor() { |
89 |
setOpaque(false); |
90 |
setBorder(BorderFactory.createEmptyBorder()); |
91 |
} |
92 |
|
93 |
@Override |
94 |
public void |
95 |
setText(String s) { |
96 |
if(getText().equals(s)) return; |
97 |
setText(s); |
98 |
} |
99 |
|
100 |
@Override |
101 |
protected void |
102 |
paintComponent(Graphics g) { |
103 |
super.paintComponent(g); |
104 |
|
105 |
PixmapPane.paintComponent(this, g, Res.gfxTextField, pixmapInsets); |
106 |
} |
107 |
} |
108 |
} |