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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1778 - (hide annotations) (download)
Sun Sep 28 20:38:36 2008 UTC (15 years, 7 months ago) by iliev
File size: 7638 byte(s)
* Fantasia: Improved look and feel
* Fantasia: Added buttons for increasing/decreasing the key number
  of the MIDI keyboard (Ctrl+Up Arrow/Ctrl+Down Arrow)
* Fantasia: Added buttons for scrolling left/right on the MIDI keyboard
  (Ctrl+Left Arrow/Ctrl+Right Arrow)
* Added key bindings for triggering MIDI notes using the computer keyboard
  (from a to ' for the white keys and from 0 to 7 for changing the octaves)
* Notes are now triggered when dragging the mouse over the MIDI keyboard

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.Graphics;
28     import java.awt.GridBagConstraints;
29     import java.awt.GridBagLayout;
30     import java.awt.Insets;
31 iliev 1318 import java.awt.Rectangle;
32 iliev 1286
33     import java.awt.event.ActionEvent;
34     import java.awt.event.ActionListener;
35 iliev 1318 import java.awt.event.HierarchyEvent;
36     import java.awt.event.HierarchyListener;
37 iliev 1286 import java.awt.event.MouseAdapter;
38     import java.awt.event.MouseEvent;
39    
40 iliev 1318 import javax.swing.BorderFactory;
41 iliev 1286 import javax.swing.Box;
42     import javax.swing.BoxLayout;
43     import javax.swing.JPanel;
44 iliev 1318 import javax.swing.JScrollPane;
45 iliev 1286
46     import org.jsampler.CC;
47    
48     import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
49    
50    
51     /**
52     *
53     * @author Grigor Iliev
54     */
55 iliev 1778 public class MainPane extends FantasiaPanel {
56 iliev 1286 private final ChannelsBar channelsBar = new ChannelsBar();
57 iliev 1318 private final ChannelsPane channelsPane;
58 iliev 1286
59 iliev 1318 final JScrollPane scrollPane;
60    
61 iliev 1286 /** Creates a new instance of <code>MainPane</code> */
62     public MainPane() {
63 iliev 1778 setOpaque(false);
64 iliev 1318 channelsPane = new ChannelsPane("", new ActionListener() {
65     public void
66     actionPerformed(ActionEvent e) { scrollToBottom(); }
67     });
68    
69 iliev 1286 GridBagLayout gridbag = new GridBagLayout();
70     GridBagConstraints c = new GridBagConstraints();
71    
72     setLayout(gridbag);
73    
74 iliev 1778 JPanel p = new FantasiaPanel();
75     p.setOpaque(false);
76 iliev 1318 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
77     p.add(channelsBar);
78     p.add(Box.createGlue());
79    
80 iliev 1286 c.gridx = 0;
81     c.gridy = 0;
82     c.weightx = 1.0;
83 iliev 1318 c.insets = new Insets(0, 0, 0, 0);
84 iliev 1286 c.fill = GridBagConstraints.HORIZONTAL;
85 iliev 1318 gridbag.setConstraints(p, c);
86     add(p);
87 iliev 1286
88 iliev 1318 p = createChannelsPane();
89 iliev 1776 p.addMouseListener(getHandler());
90 iliev 1286
91 iliev 1318 scrollPane = new JScrollPane(p);
92     JScrollPane sp = scrollPane;
93     sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
94     //sp.putClientProperty(SCROLL_PANE_BUTTONS_POLICY, ScrollPaneButtonPolicyKind.NONE);
95     sp.setBorder(BorderFactory.createEmptyBorder());
96     sp.setOpaque(false);
97     javax.swing.JViewport wp = sp.getViewport();
98 iliev 1323 wp.setMinimumSize(new Dimension(400, wp.getMinimumSize().height));
99 iliev 1318 wp.setOpaque(false);
100     sp.setMaximumSize(new Dimension(sp.getMaximumSize().width, Short.MAX_VALUE));
101     sp.getVerticalScrollBar().setBorder(BorderFactory.createEmptyBorder(7, 4, 0, 1));
102     //sp.getVerticalScrollBar().setUnitIncrement(12);
103     sp.setPreferredSize(new Dimension(420, sp.getPreferredSize().height));
104    
105     sp.getVerticalScrollBar().addHierarchyListener(new HierarchyListener() {
106     public void
107     hierarchyChanged(HierarchyEvent e) {
108     if((e.getChangeFlags() & e.SHOWING_CHANGED) != e.SHOWING_CHANGED) {
109     return;
110     }
111    
112     onScrollBarVisibilityChanged();
113     }
114     });
115    
116 iliev 1286 c.gridx = 0;
117     c.gridy = 2;
118     c.weightx = 1.0;
119     c.weighty = 1.0;
120     c.insets = new Insets(0, 0, 0, 0);
121     c.fill = GridBagConstraints.BOTH;
122 iliev 1318 gridbag.setConstraints(sp, c);
123     add(sp);
124 iliev 1286
125 iliev 1323 setMaximumSize(new Dimension(420, Short.MAX_VALUE));
126 iliev 1286 }
127    
128     private JPanel
129     createChannelsPane() {
130 iliev 1778 JPanel p = new FantasiaPanel();
131 iliev 1286 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
132 iliev 1318 channelsPane.setAlignmentX(LEFT_ALIGNMENT);
133 iliev 1286 p.add(channelsPane);
134 iliev 1318 JPanel p2 = new NewChannelPane();
135     p2.setAlignmentX(LEFT_ALIGNMENT);
136     p.add(p2);
137 iliev 1286 p.add(Box.createGlue());
138     p.setOpaque(false);
139 iliev 1318 p.setBorder(BorderFactory.createEmptyBorder(7, 0, 0, 0));
140     p.setMinimumSize(new Dimension(420, p.getMinimumSize().height));
141 iliev 1776 p.setAlignmentX(LEFT_ALIGNMENT);
142 iliev 1286 return p;
143     }
144    
145 iliev 1318 private void
146     onScrollBarVisibilityChanged() {
147 iliev 1323 int w = 420;
148 iliev 1318 int h = scrollPane.getPreferredSize().height;
149     int scrollbarWidth = scrollPane.getVerticalScrollBar().getPreferredSize().width;
150    
151 iliev 1323 if(scrollPane.getVerticalScrollBar().isVisible()) w += scrollbarWidth;
152    
153     scrollPane.setMinimumSize(new Dimension(w, scrollPane.getPreferredSize().height));
154     scrollPane.setPreferredSize(new Dimension(w, h));
155     scrollPane.setMaximumSize(new Dimension(w, Short.MAX_VALUE));
156     setMaximumSize(new Dimension(w, Short.MAX_VALUE));
157    
158     if(CC.getMainFrame() != null && !CC.getMainFrame().isResizable()) {
159     // this means that there are no visible side panes
160    
161     w = CC.getMainFrame().getPreferredSize().width;
162     CC.getMainFrame().setSize(w, CC.getMainFrame().getHeight());
163 iliev 1318 }
164    
165     revalidate();
166     }
167    
168     public void
169     scrollToBottom() {
170     int h = scrollPane.getViewport().getView().getHeight();
171     scrollPane.getViewport().scrollRectToVisible(new Rectangle(0, h - 2, 1, 1));
172     }
173    
174 iliev 1286 public ChannelsPane
175     getChannelsPane() { return channelsPane; }
176    
177     protected void
178     paintComponent(Graphics g) {
179     super.paintComponent(g);
180     int h = Res.gfxChannelsBg.getIconHeight();
181     if(h < 1) return;
182     int i = 0;
183     while(i < getHeight()) {
184     Res.gfxChannelsBg.paintIcon(this, g, 0, i);
185     i += h;
186     }
187     }
188    
189 iliev 1776 private final EventHandler eventHandler = new EventHandler();
190    
191     private EventHandler
192     getHandler() { return eventHandler; }
193    
194     private class EventHandler extends MouseAdapter {
195     public void
196     mouseClicked(MouseEvent e) {
197     if(e.getButton() != e.BUTTON1) return;
198     // TAG: channel selection system
199     CC.getMainFrame().getChannelsPane(0).setSelectedChannel(null);
200     ///////
201     }
202     }
203    
204 iliev 1286 class NewChannelPane extends PixmapPane implements ActionListener {
205     private final PixmapButton btnNew = new PixmapButton(Res.gfxPowerOff);
206    
207     NewChannelPane() {
208     super(Res.gfxCreateChannel);
209     setPixmapInsets(new Insets(3, 3, 3, 3));
210    
211     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
212 iliev 1732 add(Box.createRigidArea(new Dimension(3, 0)));
213     add(btnNew);
214 iliev 1286 add(Box.createRigidArea(new Dimension(4, 0)));
215    
216     add(createVSeparator());
217    
218     add(Box.createRigidArea(new Dimension(275, 0)));
219    
220     add(createVSeparator());
221    
222     add(Box.createRigidArea(new Dimension(29, 0)));
223    
224     add(createVSeparator());
225    
226     add(Box.createRigidArea(new Dimension(40, 0)));
227    
228     add(createVSeparator());
229    
230     setPreferredSize(new Dimension(420, 29));
231     setMinimumSize(getPreferredSize());
232     setMaximumSize(getPreferredSize());
233    
234     btnNew.setPressedIcon(Res.gfxPowerOn);
235     btnNew.addActionListener(this);
236    
237     addMouseListener(new MouseAdapter() {
238     public void
239     mouseClicked(MouseEvent e) {
240     if(e.getButton() != e.BUTTON1) {
241     return;
242     }
243    
244     CC.getSamplerModel().addBackendChannel();
245     }
246     });
247    
248     setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
249    
250     String s = i18n.getLabel("MainPane.NewChannelPane.newChannel");
251     btnNew.setToolTipText(s);
252     setToolTipText(s);
253     }
254    
255     public void
256     actionPerformed(ActionEvent e) {
257     CC.getSamplerModel().addBackendChannel();
258     }
259    
260     private JPanel
261     createVSeparator() {
262     PixmapPane p = new PixmapPane(Res.gfxVLine);
263     p.setOpaque(false);
264     p.setPreferredSize(new Dimension(2, 29));
265     p.setMinimumSize(p.getPreferredSize());
266     p.setMaximumSize(p.getPreferredSize());
267     return p;
268     }
269     }
270     }

  ViewVC Help
Powered by ViewVC