/[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 1323 - (hide annotations) (download)
Tue Sep 4 15:41:13 2007 UTC (16 years, 7 months ago) by iliev
File size: 7321 byte(s)
* Fantasia: added new menu items - Edit/Add Channel,
  Edit/Create MIDI Device, Edit/Create Audio Device,
  View/Toolbar, View/Side Pane, View/Devices Pane

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 iliev 1318 import static org.jvnet.substance.SubstanceLookAndFeel.SCROLL_PANE_BUTTONS_POLICY;
50     import static org.jvnet.substance.utils.SubstanceConstants.ScrollPaneButtonPolicyKind;
51 iliev 1286
52    
53     /**
54     *
55     * @author Grigor Iliev
56     */
57     public class MainPane extends JPanel {
58     private final ChannelsBar channelsBar = new ChannelsBar();
59 iliev 1318 private final ChannelsPane channelsPane;
60 iliev 1286
61 iliev 1318 final JScrollPane scrollPane;
62    
63 iliev 1286 /** Creates a new instance of <code>MainPane</code> */
64     public MainPane() {
65 iliev 1318 channelsPane = new ChannelsPane("", new ActionListener() {
66     public void
67     actionPerformed(ActionEvent e) { scrollToBottom(); }
68     });
69    
70 iliev 1286 GridBagLayout gridbag = new GridBagLayout();
71     GridBagConstraints c = new GridBagConstraints();
72    
73     setLayout(gridbag);
74    
75 iliev 1318 JPanel p = new JPanel();
76     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     p.setAlignmentX(LEFT_ALIGNMENT);
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     JPanel p = new JPanel();
131     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 1286 return p;
142     }
143    
144 iliev 1318 private void
145     onScrollBarVisibilityChanged() {
146 iliev 1323 int w = 420;
147 iliev 1318 int h = scrollPane.getPreferredSize().height;
148     int scrollbarWidth = scrollPane.getVerticalScrollBar().getPreferredSize().width;
149    
150 iliev 1323 if(scrollPane.getVerticalScrollBar().isVisible()) w += scrollbarWidth;
151    
152     scrollPane.setMinimumSize(new Dimension(w, scrollPane.getPreferredSize().height));
153     scrollPane.setPreferredSize(new Dimension(w, h));
154     scrollPane.setMaximumSize(new Dimension(w, Short.MAX_VALUE));
155     setMaximumSize(new Dimension(w, Short.MAX_VALUE));
156    
157     if(CC.getMainFrame() != null && !CC.getMainFrame().isResizable()) {
158     // this means that there are no visible side panes
159    
160     w = CC.getMainFrame().getPreferredSize().width;
161     CC.getMainFrame().setSize(w, CC.getMainFrame().getHeight());
162 iliev 1318 }
163    
164     revalidate();
165     }
166    
167     public void
168     scrollToBottom() {
169     int h = scrollPane.getViewport().getView().getHeight();
170     scrollPane.getViewport().scrollRectToVisible(new Rectangle(0, h - 2, 1, 1));
171     }
172    
173 iliev 1286 public ChannelsPane
174     getChannelsPane() { return channelsPane; }
175    
176     protected void
177     paintComponent(Graphics g) {
178     super.paintComponent(g);
179     int h = Res.gfxChannelsBg.getIconHeight();
180     if(h < 1) return;
181     int i = 0;
182     while(i < getHeight()) {
183     Res.gfxChannelsBg.paintIcon(this, g, 0, i);
184     i += h;
185     }
186     }
187    
188     class NewChannelPane extends PixmapPane implements ActionListener {
189     private final PixmapButton btnNew = new PixmapButton(Res.gfxPowerOff);
190    
191     NewChannelPane() {
192     super(Res.gfxCreateChannel);
193     setPixmapInsets(new Insets(3, 3, 3, 3));
194    
195     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
196     add(Box.createRigidArea(new Dimension(4, 0)));
197     add(btnNew);
198     add(Box.createRigidArea(new Dimension(3, 0)));
199    
200     add(createVSeparator());
201    
202     add(Box.createRigidArea(new Dimension(275, 0)));
203    
204     add(createVSeparator());
205    
206     add(Box.createRigidArea(new Dimension(29, 0)));
207    
208     add(createVSeparator());
209    
210     add(Box.createRigidArea(new Dimension(40, 0)));
211    
212     add(createVSeparator());
213    
214     setPreferredSize(new Dimension(420, 29));
215     setMinimumSize(getPreferredSize());
216     setMaximumSize(getPreferredSize());
217    
218     btnNew.setPressedIcon(Res.gfxPowerOn);
219     btnNew.addActionListener(this);
220    
221     addMouseListener(new MouseAdapter() {
222     public void
223     mouseClicked(MouseEvent e) {
224     if(e.getButton() != e.BUTTON1) {
225     return;
226     }
227    
228     CC.getSamplerModel().addBackendChannel();
229     }
230     });
231    
232     setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
233    
234     String s = i18n.getLabel("MainPane.NewChannelPane.newChannel");
235     btnNew.setToolTipText(s);
236     setToolTipText(s);
237     }
238    
239     public void
240     actionPerformed(ActionEvent e) {
241     CC.getSamplerModel().addBackendChannel();
242     }
243    
244     private JPanel
245     createVSeparator() {
246     PixmapPane p = new PixmapPane(Res.gfxVLine);
247     p.setOpaque(false);
248     p.setPreferredSize(new Dimension(2, 29));
249     p.setMinimumSize(p.getPreferredSize());
250     p.setMaximumSize(p.getPreferredSize());
251     return p;
252     }
253     }
254     }

  ViewVC Help
Powered by ViewVC