/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/DevicePane.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/fantasia/DevicePane.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1286 - (hide annotations) (download)
Fri Aug 10 20:24:23 2007 UTC (16 years, 8 months ago) by iliev
File size: 6137 byte(s)
- Updated to version 0.6a. The Fantasia distribution is now
  capable of controlling all features available in LinuxSampler

1 iliev 1286 /*
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.fantasia;
24    
25     import java.awt.Cursor;
26     import java.awt.Dimension;
27     import java.awt.Insets;
28    
29     import java.awt.event.ActionEvent;
30     import java.awt.event.ActionListener;
31    
32     import java.beans.PropertyChangeEvent;
33     import java.beans.PropertyChangeListener;
34    
35     import javax.swing.BorderFactory;
36     import javax.swing.Box;
37     import javax.swing.BoxLayout;
38     import javax.swing.JPanel;
39    
40     import org.jdesktop.swingx.JXCollapsiblePane;
41    
42     import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
43     import static org.jsampler.view.fantasia.FantasiaPrefs.*;
44    
45     /**
46     *
47     * @author Grigor Iliev
48     */
49     public class DevicePane extends JPanel {
50     private final PowerButton btnDestroy;
51     private final OptionsButton btnOptions = new OptionsButton();
52     private final FantasiaLabel lDevName;
53    
54     private final JXCollapsiblePane mainPane = new JXCollapsiblePane();
55     private final JXCollapsiblePane optionsPane = new JXCollapsiblePane();
56    
57     /** Creates a new instance of <code>DevicePane</code> */
58     public
59     DevicePane() {
60     setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
61    
62     mainPane.getContentPane().setLayout (
63     new BoxLayout(mainPane.getContentPane(), BoxLayout.Y_AXIS)
64     );
65    
66     PixmapPane p = new PixmapPane(Res.gfxDeviceBg);
67     p.setPixmapInsets(new Insets(1, 1, 1, 1));
68     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
69     p.add(Box.createRigidArea(new Dimension(3, 0)));
70     btnDestroy = new PowerButton();
71     p.add(btnDestroy);
72     p.add(Box.createRigidArea(new Dimension(3, 0)));
73    
74     p.add(createVSeparator());
75    
76     p.add(Box.createRigidArea(new Dimension(6, 0)));
77    
78     lDevName = new FantasiaLabel("");
79     lDevName.setOpaque(false);
80     lDevName.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
81     Dimension d = new Dimension(Short.MAX_VALUE, lDevName.getPreferredSize().height);
82     lDevName.setMaximumSize(d);
83     p.add(lDevName);
84    
85     p.add(Box.createRigidArea(new Dimension(5, 0)));
86    
87     p.add(btnOptions);
88    
89     p.add(Box.createRigidArea(new Dimension(5, 0)));
90    
91     d = new Dimension(77, 24);
92     p.setPreferredSize(d);
93     p.setMinimumSize(d);
94     p.setMaximumSize(new Dimension(Short.MAX_VALUE, 24));
95     p.setAlignmentX(LEFT_ALIGNMENT);
96     mainPane.add(p);
97    
98     optionsPane.setAlignmentX(LEFT_ALIGNMENT);
99     optionsPane.setAnimated(false);
100     optionsPane.setCollapsed(true);
101     optionsPane.setAnimated(preferences().getBoolProperty(ANIMATED));
102    
103     preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() {
104     public void
105     propertyChange(PropertyChangeEvent e) {
106     optionsPane.setAnimated(preferences().getBoolProperty(ANIMATED));
107     }
108     });
109    
110     mainPane.add(optionsPane);
111    
112     add(mainPane);
113    
114     mainPane.setAnimated(false);
115     mainPane.setCollapsed(true);
116     mainPane.setAnimated(preferences().getBoolProperty(ANIMATED));
117     mainPane.setCollapsed(false);
118    
119     preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() {
120     public void
121     propertyChange(PropertyChangeEvent e) {
122     mainPane.setAnimated(preferences().getBoolProperty(ANIMATED));
123     }
124     });
125     }
126    
127     protected void
128     setDeviceName(String s) {
129     lDevName.setText(s);
130     Dimension d = new Dimension(Short.MAX_VALUE, lDevName.getPreferredSize().height);
131     lDevName.setMaximumSize(d);
132     }
133    
134     protected void
135     destroyDevice() { }
136    
137     protected void
138     restoreDevice() {
139     btnDestroy.setSelected(true);
140     mainPane.setCollapsed(false);
141    
142     }
143    
144     protected void
145     setOptionsPane(javax.swing.JComponent c) {
146     optionsPane.setContentPane(c);
147     }
148    
149     protected JPanel
150     createVSeparator() {
151     PixmapPane p = new PixmapPane(Res.gfxVLine);
152     p.setOpaque(false);
153     p.setPreferredSize(new Dimension(2, 24));
154     p.setMinimumSize(p.getPreferredSize());
155     p.setMaximumSize(p.getPreferredSize());
156     return p;
157     }
158    
159     protected JPanel
160     createHSeparator() {
161     PixmapPane p = new PixmapPane(Res.gfxHLine);
162     p.setOpaque(false);
163     p.setPreferredSize(new Dimension(77, 2));
164     p.setMinimumSize(p.getPreferredSize());
165     p.setMaximumSize(new Dimension(Short.MAX_VALUE, 2));
166     return p;
167     }
168    
169     private class OptionsButton extends PixmapToggleButton implements ActionListener {
170     OptionsButton() {
171     super(Res.gfxOptionsOff, Res.gfxOptionsOn);
172     setRolloverIcon(Res.gfxOptionsOffRO);
173     this.setRolloverSelectedIcon(Res.gfxOptionsOnRO);
174     addActionListener(this);
175     }
176    
177     public void
178     actionPerformed(ActionEvent e) {
179     showOptionsPane(isSelected());
180    
181     String s;
182     if(isSelected()) s = i18n.getButtonLabel("OptionsButton.ttHideOptions");
183     else s = i18n.getButtonLabel("OptionsButton.ttShowOptions");
184    
185     setToolTipText(s);
186     }
187    
188     private void
189     showOptionsPane(boolean show) {
190     optionsPane.setCollapsed(!show);
191     }
192    
193     public boolean
194     contains(int x, int y) { return super.contains(x, y) & y < 13; }
195     }
196    
197     private class PowerButton extends PixmapToggleButton
198     implements ActionListener, PropertyChangeListener {
199    
200     PowerButton() {
201     super(Res.gfxPowerOff18, Res.gfxPowerOn18);
202    
203     setSelected(true);
204     addActionListener(this);
205     String s = JXCollapsiblePane.ANIMATION_STATE_KEY;
206     mainPane.addPropertyChangeListener(s, this);
207     }
208    
209     public void
210     actionPerformed(ActionEvent e) {
211     if(!mainPane.isAnimated()) {
212     destroyDevice();
213     return;
214     }
215    
216     mainPane.setCollapsed(true);
217     }
218    
219     public void
220     propertyChange(PropertyChangeEvent e) {
221     if(e.getNewValue() == "collapsed") {
222     destroyDevice();
223     }
224     }
225     }
226    
227     }

  ViewVC Help
Powered by ViewVC