/[svn]/jsampler/trunk/src/org/jsampler/view/std/JSConnectionPropsPane.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/std/JSConnectionPropsPane.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1767 - (hide annotations) (download)
Mon Sep 8 00:19:27 2008 UTC (15 years, 7 months ago) by iliev
File size: 8465 byte(s)
* Added `Copy To' and `Move To' commands to the MIDI bank context menu
  and to the MIDI instrument context menu
* Added commands to the MIDI instrument context menu for moving
  a MIDI instrument to another program
  (right-click on a MIDI instrument and choose `Change Program')
* Added option to choose between zero-based and one-based
  MIDI bank/program numbering
  (choose Edit/Preferences, then click the `Advanced' button)
* Added option to choose whether to include MIDI instrument
  mappings when exporting a sampler configuration to LSCP script.
  (choose Edit/Preferences, then click the `Advanced' button)
* Added option to set the MIDI instrument loading in background
  when exporting MIDI instrument mappings to LSCP script.
  (choose Edit/Preferences, then click the `Advanced' button)
* Implemented an option to change the socket read timeout
  (choose Edit/Preferences, then click the `Backend' tab)
* Updated LscpTree
* Fantasia: Added option to hide the active stream/voice count statistic
  in the sampler channel's small view
  (choose Edit/Preferences, then click the `Channels' tab)
* Fantasia: `Turn off animation effects' checkbox moved to the `View' tab

1 iliev 1286 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1688 * Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 1286 *
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.std;
24    
25 iliev 1688 import java.awt.Dialog;
26 iliev 1286 import java.awt.Dimension;
27 iliev 1688 import java.awt.Frame;
28 iliev 1286 import java.awt.GridBagConstraints;
29     import java.awt.GridBagLayout;
30     import java.awt.Insets;
31 iliev 1688 import java.awt.Window;
32 iliev 1286
33 iliev 1688 import java.awt.event.ActionEvent;
34     import java.awt.event.ActionListener;
35    
36 iliev 1286 import javax.swing.BorderFactory;
37 iliev 1688 import javax.swing.Box;
38     import javax.swing.BoxLayout;
39     import javax.swing.JButton;
40     import javax.swing.JCheckBox;
41 iliev 1286 import javax.swing.JLabel;
42     import javax.swing.JOptionPane;
43     import javax.swing.JPanel;
44 iliev 1688 import javax.swing.JScrollPane;
45 iliev 1767 import javax.swing.JSpinner;
46 iliev 1286 import javax.swing.JTextField;
47 iliev 1767 import javax.swing.SpinnerNumberModel;
48 iliev 1286
49 iliev 1688 import javax.swing.event.ListSelectionEvent;
50     import javax.swing.event.ListSelectionListener;
51    
52     import net.sf.juife.JuifeUtils;
53    
54 iliev 1286 import org.jsampler.CC;
55 iliev 1688 import org.jsampler.HF;
56     import org.jsampler.JSPrefs;
57 iliev 1286 import org.jsampler.Prefs;
58    
59     import org.jsampler.task.SetServerAddress;
60    
61 iliev 1688 import org.jsampler.view.ServerTable;
62     import org.jsampler.view.ServerTableModel;
63    
64 iliev 1286 import static org.jsampler.view.std.StdI18n.i18n;
65 iliev 1688 import static org.jsampler.view.std.StdPrefs.*;
66 iliev 1286
67    
68     /**
69     *
70     * @author Grigor Iliev
71     */
72     public class JSConnectionPropsPane extends JPanel {
73 iliev 1688 private final JCheckBox checkManualSelect =
74     new JCheckBox(i18n.getLabel("JSConnectionPropsPane.checkManualSelect"));
75 iliev 1286
76 iliev 1767 private final JLabel lReadTimeout =
77     new JLabel(i18n.getLabel("JSConnectionPropsPane.lReadTimeout"));
78    
79     private final JSpinner spinnerTimeout = new JSpinner(new SpinnerNumberModel(0, 0, 2000, 1));
80    
81 iliev 1688 private final ServerListPane serverListPane;
82 iliev 1286
83 iliev 1688
84 iliev 1286 /** Creates a new instance of <code>JSConnectionPropsPane</code> */
85     public
86     JSConnectionPropsPane() {
87 iliev 1688 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
88 iliev 1286
89 iliev 1688 boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP);
90     checkManualSelect.setSelected(b);
91    
92     checkManualSelect.setAlignmentX(LEFT_ALIGNMENT);
93     add(checkManualSelect);
94     add(Box.createRigidArea(new Dimension(0, 6)));
95 iliev 1767
96     JPanel p = new JPanel();
97     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
98    
99     p.add(lReadTimeout);
100     p.add(Box.createRigidArea(new Dimension(6, 0)));
101    
102     int i = preferences().getIntProperty(SOCKET_READ_TIMEOUT);
103     spinnerTimeout.setValue(i);
104     p.add(spinnerTimeout);
105    
106     p.setAlignmentX(LEFT_ALIGNMENT);
107     p.setMaximumSize(new Dimension(Short.MAX_VALUE, p.getPreferredSize().height));
108     add(p);
109     add(Box.createRigidArea(new Dimension(0, 6)));
110    
111 iliev 1688 serverListPane = createServerListPane();
112     add(serverListPane);
113     setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
114     }
115 iliev 1286
116 iliev 1688 private ServerListPane
117     createServerListPane() {
118     ServerListPane p = new ServerListPane();
119     p.setPreferredSize(new Dimension(200, 200));
120     p.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
121 iliev 1286
122 iliev 1688 String s = i18n.getLabel("JSConnectionPropsPane.title");
123     p.setBorder(BorderFactory.createTitledBorder(s));
124     p.setAlignmentX(LEFT_ALIGNMENT);
125 iliev 1286
126 iliev 1688 return p;
127 iliev 1286 }
128    
129 iliev 1688 private static JSPrefs
130     preferences() { return CC.getViewConfig().preferences(); }
131 iliev 1286
132 iliev 1767 /**
133     * Gets the read timeout in seconds.
134     */
135     public int
136     getReadTimeout() { return Integer.parseInt(spinnerTimeout.getValue().toString()); }
137    
138 iliev 1286 public void
139     apply() {
140 iliev 1688 boolean b = checkManualSelect.isSelected();
141     preferences().setBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP, b);
142 iliev 1286
143 iliev 1767 preferences().setIntProperty(SOCKET_READ_TIMEOUT, getReadTimeout());
144    
145     CC.setClientReadTimeout(getReadTimeout());
146    
147 iliev 1688 int i = serverListPane.serverTable.getSelectedRow();
148     if(i != -1) preferences().setIntProperty(SERVER_INDEX, i);
149     }
150    
151     public static class ServerListPane extends JPanel {
152     protected final ServerTable serverTable;
153    
154     private final JButton btnAdd = new JButton(i18n.getButtonLabel("add"));
155     private final JButton btnRemove = new JButton(i18n.getButtonLabel("remove"));
156    
157     private final JButton btnMoveUp =
158     new JButton(i18n.getButtonLabel("JSConnectionPropsPane.btnMoveUp"));
159    
160     private final JButton btnMoveDown =
161     new JButton(i18n.getButtonLabel("JSConnectionPropsPane.btnMoveDown"));
162    
163     public
164     ServerListPane() {
165     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
166    
167     ServerTableModel model = new ServerTableModel(CC.getServerList());
168     serverTable = new ServerTable(model);
169    
170     add(new JScrollPane(serverTable));
171    
172     int h = btnAdd.getPreferredSize().height;
173     btnAdd.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
174    
175     h = btnRemove.getPreferredSize().height;
176     btnRemove.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
177    
178     h = btnMoveUp.getPreferredSize().height;
179     btnMoveUp.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
180    
181     h = btnMoveDown.getPreferredSize().height;
182     btnMoveDown.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
183    
184     JPanel p = new JPanel();
185     p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
186     p.add(btnAdd);
187     p.add(Box.createRigidArea(new Dimension(0, 5)));
188     p.add(btnRemove);
189     p.add(Box.createRigidArea(new Dimension(0, 17)));
190     p.add(btnMoveUp);
191     p.add(Box.createRigidArea(new Dimension(0, 5)));
192     p.add(btnMoveDown);
193     p.add(Box.createGlue());
194    
195     p.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
196    
197     add(p);
198    
199     installListeners();
200    
201     int i = preferences().getIntProperty(JSPrefs.SERVER_INDEX);
202     int size = CC.getServerList().getServerCount();
203     if(size > 0) {
204     if(i < 0 || i >= size) {
205     serverTable.getSelectionModel().setSelectionInterval(0, 0);
206     } else {
207     serverTable.getSelectionModel().setSelectionInterval(i, i);
208     }
209     }
210 iliev 1286 }
211    
212 iliev 1688 private void
213     installListeners() {
214     btnAdd.addActionListener(new ActionListener() {
215     public void
216     actionPerformed(ActionEvent e) { addServer(); }
217     });
218 iliev 1286
219 iliev 1688 btnRemove.addActionListener(new ActionListener() {
220     public void
221     actionPerformed(ActionEvent e) {
222     removeServer();
223     }
224     });
225    
226     btnMoveUp.addActionListener(new ActionListener() {
227     public void
228     actionPerformed(ActionEvent e) {
229     serverTable.moveSelectedServerUp();
230     }
231     });
232    
233     btnMoveDown.addActionListener(new ActionListener() {
234     public void
235     actionPerformed(ActionEvent e) {
236     serverTable.moveSelectedServerDown();
237     }
238     });
239    
240     ServerSelectionHandler l = new ServerSelectionHandler();
241     serverTable.getSelectionModel().addListSelectionListener(l);
242 iliev 1286 }
243    
244 iliev 1688 private void
245     addServer() {
246     int i = serverTable.getSelectedRow();
247    
248     JSAddServerDlg dlg;
249     Window w = JuifeUtils.getWindow(this);
250     if(w instanceof Dialog) dlg = new JSAddServerDlg((Dialog)w);
251     else if(w instanceof Frame) dlg = new JSAddServerDlg((Frame)w);
252     else dlg = new JSAddServerDlg(CC.getMainFrame());
253    
254     dlg.setVisible(true);
255     if(dlg.isCancelled()) return;
256    
257     serverTable.getSelectionModel().setSelectionInterval(i, i);
258     }
259    
260     private void
261     removeServer() {
262     if(CC.getServerList().getServerCount() < 2) {
263     Window w = JuifeUtils.getWindow(this);
264     String s = i18n.getError("JSConnectionPropsPane.cantRemove");
265     if(w instanceof Dialog) HF.showErrorMessage(s, (Dialog)w);
266     else if(w instanceof Frame) HF.showErrorMessage(s, (Frame)w);
267     return;
268     }
269    
270     serverTable.removeSelectedServer();
271     }
272    
273     private class ServerSelectionHandler implements ListSelectionListener {
274     public void
275     valueChanged(ListSelectionEvent e) {
276     if(e.getValueIsAdjusting()) return;
277    
278     if(serverTable.getSelectedServer() == null) {
279     btnMoveUp.setEnabled(false);
280     btnMoveDown.setEnabled(false);
281     return;
282     }
283    
284     int idx = serverTable.getSelectedRow();
285     btnMoveUp.setEnabled(idx != 0);
286     btnMoveDown.setEnabled(idx != serverTable.getRowCount() - 1);
287     }
288     }
289 iliev 1286 }
290     }

  ViewVC Help
Powered by ViewVC