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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 912 - (hide annotations) (download)
Mon Aug 7 18:34:40 2006 UTC (17 years, 8 months ago) by iliev
File size: 7453 byte(s)
* updating to JSampler 0.3a

1 iliev 912 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4     * Copyright (C) 2005, 2006 Grigor Kirilov Iliev
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.BorderLayout;
26     import java.awt.Dimension;
27     import java.awt.Point;
28    
29     import java.awt.event.ActionEvent;
30     import java.awt.event.ActionListener;
31     import java.awt.event.MouseAdapter;
32     import java.awt.event.MouseEvent;
33    
34     import java.util.logging.Level;
35    
36     import javax.swing.Box;
37     import javax.swing.BoxLayout;
38     import javax.swing.JCheckBoxMenuItem;
39     import javax.swing.JMenu;
40     import javax.swing.JMenuItem;
41     import javax.swing.JPanel;
42     import javax.swing.JPopupMenu;
43     import javax.swing.JToggleButton;
44     import javax.swing.UIManager;
45     import javax.swing.plaf.synth.SynthLookAndFeel;
46    
47     import net.sf.juife.TitleBar;
48    
49     import org.jsampler.CC;
50     import org.jsampler.HF;
51    
52     import org.jsampler.view.JSChannel;
53     import org.jsampler.view.JSChannelsPane;
54     import org.jsampler.view.JSMainFrame;
55    
56     import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
57    
58    
59     /**
60     *
61     * @author Grigor Iliev
62     */
63     public class MainFrame extends JSMainFrame {
64     private final static int TITLE_BAR_WIDTH = 420;
65     private final static int TITLE_BAR_HEIGHT = 29;
66    
67     private final ChannelsPane channelsPane = new ChannelsPane("");
68    
69     /** Creates a new instance of <code>MainFrame</code> */
70     public
71     MainFrame() {
72     try {
73     SynthLookAndFeel synth = new SynthLookAndFeel();
74     synth.load(MainFrame.class.getResourceAsStream("gui.xml"), MainFrame.class);
75     UIManager.setLookAndFeel(synth);
76     } catch(Exception e) {
77     CC.getLogger().log(Level.INFO, HF.getErrorMessage(e), e);
78     }
79    
80     setTitle(i18n.getLabel("MainFrame.title"));
81     addChannelsPane(channelsPane);
82     add(channelsPane);
83     setUndecorated(true);
84    
85     JToggleButton btn = new PixmapToggleButton(Res.iconPowerOff, Res.iconPowerOn) {
86     public boolean
87     contains(int x, int y) {
88     return (x - 11)*(x - 11) + (y - 11)*(y - 11) < 71;
89     }
90     };
91    
92     btn.setSelected(true);
93     btn.setAlignmentX(JPanel.LEFT_ALIGNMENT);
94     btn.addActionListener(new ActionListener() {
95     public void
96     actionPerformed(ActionEvent e) { onWindowClose(); }
97     });
98    
99    
100     FantasiaTitleBar tb = new FantasiaTitleBar();
101     tb.setName("FantasiaTitleBar");
102     tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS));
103     tb.setOpaque(true);
104     tb.add(Box.createRigidArea(new Dimension(4, 0)));
105     tb.add(btn);
106     tb.add(Box.createRigidArea(new Dimension(3, 0)));
107    
108    
109    
110     tb.add(createVSeparator());
111    
112     tb.add(Box.createRigidArea(new Dimension(275, 0)));
113    
114     tb.add(createVSeparator());
115    
116     tb.add(Box.createRigidArea(new Dimension(29, 0)));
117    
118     tb.add(createVSeparator());
119    
120     tb.add(Box.createRigidArea(new Dimension(40, 0)));
121    
122     tb.add(createVSeparator());
123    
124     tb.setPreferredSize(new Dimension(TITLE_BAR_WIDTH, TITLE_BAR_HEIGHT));
125     tb.setMinimumSize(tb.getPreferredSize());
126     tb.setMaximumSize(tb.getPreferredSize());
127     add(tb, BorderLayout.SOUTH);
128    
129     getContentPane().setBackground(new java.awt.Color(0x818181));
130     getRootPane().setOpaque(false);
131     getLayeredPane().setOpaque(false);
132     //getContentPane().setVisible(false);
133    
134     setAlwaysOnTop(FantasiaPrefs.isAlwaysOnTop());
135     pack();
136    
137     String s = FantasiaPrefs.getWindowLocation();
138    
139     try {
140     if(s == null) {
141     setDefaultLocation();
142     } else {
143     int i = s.indexOf(',');
144     int x = Integer.parseInt(s.substring(0, i));
145    
146     s = s.substring(i + 1);
147     int y = Integer.parseInt(s);
148    
149     setLocation(x, y);
150     }
151     } catch(Exception x) {
152     String msg = "Parsing of window size and location string failed";
153     CC.getLogger().log(Level.INFO, msg, x);
154     setDefaultLocation();
155     }
156     }
157    
158     private void
159     setDefaultLocation() {
160     Dimension d = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
161     setLocation((d.width - TITLE_BAR_WIDTH) / 2, (d.height - TITLE_BAR_HEIGHT) / 2);
162     }
163    
164    
165     /** Invoked when this window is about to close. */
166     protected void
167     onWindowClose() {
168     FantasiaPrefs.setAlwaysOnTop(isAlwaysOnTop());
169    
170     java.awt.Point p = getLocation();
171     Dimension d = getSize();
172     StringBuffer sb = new StringBuffer();
173     sb.append(p.x).append(',').append(p.y + getSize().height - TITLE_BAR_HEIGHT);
174     FantasiaPrefs.setWindowLocation(sb.toString());
175    
176     super.onWindowClose();
177     }
178    
179     private JPanel
180     createVSeparator() {
181     JPanel p = new JPanel();
182     p.setName("VSeparator");
183     p.setOpaque(false);
184     p.setPreferredSize(new Dimension(2, 29));
185     p.setMinimumSize(p.getPreferredSize());
186     p.setMaximumSize(p.getPreferredSize());
187     return p;
188     }
189    
190     /**
191     * This method does nothing, because <b>Fantasia</b> has exactly
192     * one pane containing sampler channels, which can not be changed.
193     */
194     public void
195     insertChannelsPane(JSChannelsPane pane, int idx) {
196     getChannelsPaneList().removeAllElements();
197     addChannelsPane(pane);
198     }
199    
200     /**
201     * This method always returns the <code>JSChannelsPane</code> at index 0,
202     * because the <b>Fantasia</b> view has exactly one pane containing sampler channels.
203     * @return The <code>JSChannelsPane</code> at index 0.
204     */
205     public JSChannelsPane
206     getSelectedChannelsPane() { return getChannelsPane(0); }
207    
208     /**
209     * This method does nothing because the <b>Fantasia</b> view has
210     * exactly one pane containing sampler channels which is always shown.
211     */
212     public void
213     setSelectedChannelsPane(JSChannelsPane pane) { }
214    
215     public static void
216     repack(JSMainFrame frame) {
217     int y = frame.getLocation().y;
218     int height = frame.getSize().height;
219     y += (height - frame.getPreferredSize().height);
220    
221     if((height - frame.getPreferredSize().height) > 0) {
222     frame.pack();
223     frame.setLocation(frame.getLocation().x, y);
224     } else {
225     frame.setLocation(frame.getLocation().x, y);
226     frame.pack();
227     }
228     }
229    
230    
231     }
232    
233     class FantasiaTitleBar extends TitleBar {
234     FantasiaTitleBar() { this.addMouseListener(new ContextMenu()); }
235    
236     class ContextMenu extends MouseAdapter {
237     private final JPopupMenu cmenu = new JPopupMenu();
238    
239     ContextMenu() {
240     JMenuItem mi;
241    
242     final JCheckBoxMenuItem cmi = new JCheckBoxMenuItem (
243     i18n.getMenuLabel("FantasiaTitleBar.AlwaysOnTop")
244     );
245     cmi.setIcon(null);
246     cmi.setSelected(FantasiaPrefs.isAlwaysOnTop());
247    
248     cmenu.add(cmi);
249    
250     cmi.addActionListener(new ActionListener() {
251     public void
252     actionPerformed(ActionEvent e) {
253     CC.getMainFrame().setAlwaysOnTop(cmi.isSelected());
254     }
255     });
256    
257     /*mi = new JMenuItem(A4n.moveChannelsUp);
258     mi.setIcon(null);
259     cmenu.add(mi);
260    
261     cmenu.addSeparator();
262    
263     mi = new JMenuItem(A4n.removeChannels);
264     mi.setIcon(null);
265     cmenu.add(mi);*/
266     }
267    
268     public void
269     mousePressed(MouseEvent e) {
270     if(e.isPopupTrigger()) show(e);
271     }
272    
273     public void
274     mouseReleased(MouseEvent e) {
275     if(e.isPopupTrigger()) show(e);
276     }
277    
278     void
279     show(MouseEvent e) {
280     cmenu.show(e.getComponent(), e.getX(), e.getY());
281     }
282     }
283     }

  ViewVC Help
Powered by ViewVC