PageRenderTime 54ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/PicnomeSerial.java

https://github.com/tkrworks/pic2osc
Java | 1332 lines | 1135 code | 101 blank | 96 comment | 301 complexity | 44adcd7fcfc8e23e77d48d932689e4e5 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copylight (C) 2009, Shunichi Yamamoto, tkrworks.net
  3. *
  4. * This file is part of pic2osc.
  5. *
  6. * pic2osc is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option ) any later version.
  10. *
  11. * pic2osc is distributed in the hope that it will be useful,
  12. * but WITHIOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with PicnomeSerial. if not, see <http:/www.gnu.org/licenses/>.
  18. *
  19. * PicnomeSerial.java,v.1.6.03(149) 2012/02/15
  20. */
  21. import java.io.*;
  22. import java.awt.*;
  23. import java.awt.event.*;
  24. import javax.swing.*;
  25. import javax.swing.text.*;
  26. import javax.swing.border.*;
  27. import javax.swing.event.*;
  28. import org.jdesktop.swingx.*;
  29. import org.pushingpixels.substance.api.SubstanceLookAndFeel;
  30. //sy import org.pushingpixels.substance.api.skin.*;
  31. import org.pushingpixels.substance.api.skin.TwilightSkin;
  32. import org.pushingpixels.substance.api.skin.SubstanceTwilightLookAndFeel;
  33. //You have to comment out if you compile win version.
  34. //win import com.apple.eawt.*;//mac
  35. public class PicnomeSerial extends JFrame implements ActionListener, ChangeListener {
  36. final static int MENU_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
  37. PicnomeCommunication pserial = new PicnomeCommunication();
  38. private MidiDetailFrame mdf = new MidiDetailFrame();
  39. private JXTaskPaneContainer container;
  40. private JPanel psd_p;
  41. private CardLayout psd_cl;
  42. private File hex_f;
  43. private FileReader hex_fr;
  44. private Timer timer;
  45. private int ch;
  46. private int size;
  47. private int count;
  48. private int bar;
  49. private int prev_index;
  50. private boolean para_change_flag;
  51. public PicnomeSerial() {
  52. super("pic2osc ver. / f/w ver.");
  53. init();
  54. (new Thread(new AutoResizeThread())).start();
  55. }
  56. public static void main(String[] args) {
  57. PicnomeSerial psgui = new PicnomeSerial();
  58. for(int i = 0; i < psgui.pserial.getCurrentNum(); i++) {
  59. psgui.pserial.openSerialPort(i);
  60. try {
  61. Thread.sleep(100);
  62. } catch(InterruptedException ioe) {}
  63. psgui.pserial.setSerialPort(i);
  64. if(psgui.pserial.getCurrentMaxColumn(i) == 7)
  65. psgui.mdf.setHalfVisible();
  66. }
  67. int timeout_count = 0;
  68. while(!psgui.pserial.isFirmwareVersion()) {
  69. timeout_count++;
  70. if(timeout_count > 65536 * 20)
  71. break;
  72. }
  73. psgui.setTitle("pic2osc " + psgui.pserial.getAppVersion() + " / " + psgui.pserial.getFirmwareVersion());
  74. //for DORAnome
  75. //sy psgui.changeDORAnome();//dora
  76. //for PICratchBOX
  77. /*
  78. if(psgui.pserial.getIsPrB())
  79. psgui.pserial.enableAllAdcPorts();
  80. */
  81. }
  82. private void changeDORAnome() {
  83. pserial.protocol_cb.setSelectedItem("DORAnome");
  84. pserial.midioutput_cb.setSelectedItem("IAC BUS 2");
  85. for(int i = 0; i < 6; i++) {
  86. pserial.adc_ck[i].setSelected(false);
  87. pserial.adc_cmb0[i].setSelectedIndex(1);
  88. if(i < 2)
  89. pserial.adc_cmb1[i].setSelectedIndex(6);
  90. else
  91. pserial.adc_cmb1[i].setSelectedIndex(4);
  92. }
  93. }
  94. private void init() {
  95. SwingUtilities.invokeLater(new Runnable() {
  96. public void run() {
  97. JFrame.setDefaultLookAndFeelDecorated(true);
  98. JDialog.setDefaultLookAndFeelDecorated(true);
  99. SubstanceLookAndFeel.setSkin(new TwilightSkin());
  100. //sy SubstanceLookAndFeel.setSkin(new GraphiteGlassSkin());
  101. //sy SubstanceLookAndFeel.setSkin(new RavenSkin());
  102. if(System.getProperty("os.name").startsWith("Windows")) {
  103. ImageIcon icon;
  104. icon = new ImageIcon("icon\\pic2osc-16x16.png");
  105. setIconImage(icon.getImage());
  106. }
  107. SpringLayout sl = new SpringLayout();
  108. Container c = getContentPane();
  109. c.setLayout(sl);
  110. c.add(createTaskPane());
  111. if(System.getProperty("os.name").startsWith("Mac OS X")) {
  112. setSize(430, 625);
  113. //You have to comment out if you compile win version.
  114. //mac
  115. /*win
  116. Application app = Application.getApplication();
  117. app.addApplicationListener(new ApplicationAdapter() {
  118. public void handleQuit(ApplicationEvent arg0) {
  119. for(int i = 0; i < 6; i++) {
  120. String str =new String("ae " + i + " " + 0 + (char)0x0D);
  121. if(pserial.getCurrentNum() == 1) {
  122. pserial.setAdcEnable(0, i, false);
  123. pserial.sendDataToSerial(0, str);
  124. }
  125. if(pserial.getCurrentNum() == 2) {
  126. pserial.setAdcEnable(1, i, false);
  127. pserial.sendDataToSerial(1, str);
  128. }
  129. }
  130. System.exit(0);
  131. }
  132. });
  133. win*/
  134. //mac end
  135. }
  136. else if(System.getProperty("os.name").startsWith("Windows"))
  137. setSize(444, 680);
  138. addWindowListener(
  139. new WindowAdapter() {
  140. public void windowClosing(WindowEvent e) {
  141. for(int i = 0; i < 6; i++) {
  142. String str =new String("ae " + i + " " + 0 + (char)0x0D);
  143. if(pserial.getCurrentNum() == 1) {
  144. pserial.setAdcEnable(0, i, false);
  145. pserial.sendDataToSerial(0, str);
  146. }
  147. if(pserial.getCurrentNum() == 2) {
  148. pserial.setAdcEnable(1, i, false);
  149. pserial.sendDataToSerial(1, str);
  150. }
  151. }
  152. System.exit(0);
  153. }
  154. });
  155. mdf.init();
  156. if(System.getProperty("os.name").startsWith("Mac OS X"))
  157. mdf.setBounds(450, 0, 890, 620);// mac
  158. else if(System.getProperty("os.name").startsWith("Windows"))
  159. mdf.setBounds(470, 40, 990, 665);// win
  160. setVisible(true);
  161. }
  162. });
  163. }
  164. private JXTaskPaneContainer createTaskPane() {
  165. SpringLayout sl = new SpringLayout();
  166. container =new JXTaskPaneContainer();
  167. JXTaskPane pane1 = new JXTaskPane("Protocol Settings");
  168. container.add(pane1);
  169. pane1.setCollapsed(true);
  170. JPanel ps_p = new JPanel();
  171. SpringLayout ps_sl = new SpringLayout();
  172. ps_p.setLayout(ps_sl);
  173. SoftBevelBorder ps_inborder = new SoftBevelBorder(SoftBevelBorder.LOWERED);
  174. BevelBorder ps_outborder = new BevelBorder(BevelBorder.LOWERED);
  175. ps_p.setPreferredSize(new Dimension(385, 140));
  176. ps_p.setBorder(ps_outborder);
  177. sl.putConstraint(SpringLayout.NORTH, ps_p, 10, SpringLayout.NORTH, pane1);
  178. sl.putConstraint(SpringLayout.WEST, ps_p, 10, SpringLayout.WEST, pane1);
  179. pane1.add(ps_p);
  180. JLabel ioprotocol_l = new JLabel("I/O Protocol :");
  181. ps_sl.putConstraint(SpringLayout.NORTH, ioprotocol_l, 10, SpringLayout.NORTH, ps_p);
  182. ps_sl.putConstraint(SpringLayout.WEST, ioprotocol_l, 22, SpringLayout.WEST, ps_p);
  183. ps_p.add(ioprotocol_l);
  184. String[] protocol_str = {"Open Sound Control", "MIDI", "OSC/MIDI(ext.)", "DORAnome"};//dora
  185. pserial.protocol_cb = new JComboBox(protocol_str);
  186. pserial.protocol_cb.setActionCommand("ProtocolChanged");
  187. pserial.protocol_cb.addActionListener(this);
  188. ps_sl.putConstraint(SpringLayout.NORTH, pserial.protocol_cb, -4, SpringLayout.NORTH, ioprotocol_l);
  189. ps_sl.putConstraint(SpringLayout.WEST, pserial.protocol_cb, 10, SpringLayout.EAST, ioprotocol_l);
  190. ps_p.add(pserial.protocol_cb);
  191. psd_p = new JPanel();
  192. psd_cl = new CardLayout();
  193. psd_p.setLayout(psd_cl);
  194. psd_p.setPreferredSize(new Dimension(370, 85));
  195. ps_sl.putConstraint(SpringLayout.NORTH, psd_p, 40, SpringLayout.NORTH, ps_p);
  196. ps_sl.putConstraint(SpringLayout.WEST, psd_p, 10, SpringLayout.WEST, ps_p);
  197. ps_p.add(psd_p);
  198. //Open Sound Control Setting
  199. JPanel osc_p = new JPanel();
  200. SpringLayout osc_sl = new SpringLayout();
  201. osc_p.setLayout(osc_sl);
  202. osc_p.setPreferredSize(new Dimension(370, 85));
  203. psd_p.add(osc_p, "osc");
  204. JLabel hostaddress_l = new JLabel("Host Address :");
  205. osc_sl.putConstraint(SpringLayout.NORTH, hostaddress_l, 5, SpringLayout.NORTH, osc_p);
  206. if(System.getProperty("os.name").startsWith("Mac OS X"))
  207. osc_sl.putConstraint(SpringLayout.WEST, hostaddress_l, 4, SpringLayout.WEST, osc_p);
  208. else if(System.getProperty("os.name").startsWith("Windows"))
  209. osc_sl.putConstraint(SpringLayout.WEST, hostaddress_l, 1, SpringLayout.WEST, osc_p);
  210. osc_p.add(hostaddress_l);
  211. pserial.hostaddress_tf = new JTextField("127.0.0.1", 10);
  212. pserial.hostaddress_tf.addActionListener(this);
  213. if(System.getProperty("os.name").startsWith("Mac OS X"))
  214. osc_sl.putConstraint(SpringLayout.NORTH, pserial.hostaddress_tf, -6, SpringLayout.NORTH, hostaddress_l);
  215. else if(System.getProperty("os.name").startsWith("Windows"))
  216. osc_sl.putConstraint(SpringLayout.NORTH, pserial.hostaddress_tf, -1, SpringLayout.NORTH, hostaddress_l);
  217. osc_sl.putConstraint(SpringLayout.WEST, pserial.hostaddress_tf, 10, SpringLayout.EAST, hostaddress_l);
  218. osc_p.add(pserial.hostaddress_tf);
  219. JLabel hostport_l = new JLabel("Host Port :");
  220. osc_sl.putConstraint(SpringLayout.NORTH, hostport_l, 35, SpringLayout.NORTH, osc_p);
  221. if(System.getProperty("os.name").startsWith("Mac OS X"))
  222. osc_sl.putConstraint(SpringLayout.WEST, hostport_l, 30, SpringLayout.WEST, osc_p);
  223. else if(System.getProperty("os.name").startsWith("Windows"))
  224. osc_sl.putConstraint(SpringLayout.WEST, hostport_l, 25, SpringLayout.WEST, osc_p);
  225. osc_p.add(hostport_l);
  226. pserial.hostport_tf = new JTextField("8000", 3);
  227. //sy pserial.hostport_tf.addActionListener(this);
  228. ((AbstractDocument)pserial.hostport_tf.getDocument()).setDocumentFilter(new HostPortFilter());
  229. if(System.getProperty("os.name").startsWith("Mac OS X"))
  230. osc_sl.putConstraint(SpringLayout.NORTH, pserial.hostport_tf, -6, SpringLayout.NORTH, hostport_l);
  231. else if(System.getProperty("os.name").startsWith("Windows"))
  232. osc_sl.putConstraint(SpringLayout.NORTH, pserial.hostport_tf, -1, SpringLayout.NORTH, hostport_l);
  233. osc_sl.putConstraint(SpringLayout.WEST, pserial.hostport_tf, 10, SpringLayout.EAST, hostport_l);
  234. osc_p.add(pserial.hostport_tf);
  235. JLabel listenport_l = new JLabel("Listen Port :");
  236. osc_sl.putConstraint(SpringLayout.NORTH, listenport_l, 65, SpringLayout.NORTH, osc_p);
  237. if(System.getProperty("os.name").startsWith("Mac OS X"))
  238. osc_sl.putConstraint(SpringLayout.WEST, listenport_l, 22, SpringLayout.WEST, osc_p);
  239. else if(System.getProperty("os.name").startsWith("Windows"))
  240. osc_sl.putConstraint(SpringLayout.WEST, listenport_l, 16, SpringLayout.WEST, osc_p);
  241. osc_p.add(listenport_l);
  242. pserial.listenport_tf = new JTextField("8080", 3);
  243. //sy pserial.listenport_tf.addActionListener(this);
  244. ((AbstractDocument)pserial.listenport_tf.getDocument()).setDocumentFilter(new ListenPortFilter());
  245. if(System.getProperty("os.name").startsWith("Mac OS X"))
  246. osc_sl.putConstraint(SpringLayout.NORTH, pserial.listenport_tf, -6, SpringLayout.NORTH, listenport_l);
  247. else if(System.getProperty("os.name").startsWith("Windows"))
  248. osc_sl.putConstraint(SpringLayout.NORTH, pserial.listenport_tf, -1, SpringLayout.NORTH, listenport_l);
  249. osc_sl.putConstraint(SpringLayout.WEST, pserial.listenport_tf, 10, SpringLayout.EAST, listenport_l);
  250. osc_p.add(pserial.listenport_tf);
  251. //MIDI Setting
  252. JPanel midi_p = new JPanel();
  253. SpringLayout midi_sl = new SpringLayout();
  254. midi_p.setLayout(midi_sl);
  255. midi_p.setPreferredSize(new Dimension(370, 85));
  256. psd_p.add(midi_p, "midi");
  257. JLabel midiinput_l = new JLabel("MIDI Input :");
  258. midi_sl.putConstraint(SpringLayout.NORTH, midiinput_l, 5, SpringLayout.NORTH, midi_p);
  259. if(System.getProperty("os.name").startsWith("Mac OS X"))
  260. midi_sl.putConstraint(SpringLayout.WEST, midiinput_l, 23, SpringLayout.WEST, midi_p);
  261. else if(System.getProperty("os.name").startsWith("Windows"))
  262. midi_sl.putConstraint(SpringLayout.WEST, midiinput_l, 23, SpringLayout.WEST, midi_p);
  263. midi_p.add(midiinput_l);
  264. pserial.midiinput_cb = new JComboBox(pserial.getMidiInputList());
  265. pserial.midiinput_cb.setActionCommand("MidiInChanged");
  266. pserial.midiinput_cb.addActionListener(this);
  267. if(System.getProperty("os.name").startsWith("Mac OS X"))
  268. pserial.midiinput_cb.setPreferredSize(new Dimension(250, 30));
  269. midi_sl.putConstraint(SpringLayout.NORTH, pserial.midiinput_cb, -4, SpringLayout.NORTH, midiinput_l);
  270. midi_sl.putConstraint(SpringLayout.WEST, pserial.midiinput_cb, 10, SpringLayout.EAST, midiinput_l);
  271. midi_p.add(pserial.midiinput_cb);
  272. JLabel midioutput_l = new JLabel("MIDI Output :");
  273. midi_sl.putConstraint(SpringLayout.NORTH, midioutput_l, 35, SpringLayout.NORTH, midi_p);
  274. if(System.getProperty("os.name").startsWith("Mac OS X"))
  275. midi_sl.putConstraint(SpringLayout.WEST, midioutput_l, 12, SpringLayout.WEST, midi_p);
  276. else if(System.getProperty("os.name").startsWith("Windows"))
  277. midi_sl.putConstraint(SpringLayout.WEST, midioutput_l, 13, SpringLayout.WEST, midi_p);
  278. midi_p.add(midioutput_l);
  279. pserial.midioutput_cb = new JComboBox(pserial.getMidiOutputList());
  280. pserial.midioutput_cb.setActionCommand("MidiOutChanged");
  281. pserial.midioutput_cb.addActionListener(this);
  282. if(System.getProperty("os.name").startsWith("Mac OS X"))
  283. pserial.midioutput_cb.setPreferredSize(new Dimension(250, 30));
  284. midi_sl.putConstraint(SpringLayout.NORTH, pserial.midioutput_cb, -4, SpringLayout.NORTH, midioutput_l);
  285. midi_sl.putConstraint(SpringLayout.WEST, pserial.midioutput_cb, 10, SpringLayout.EAST, midioutput_l);
  286. midi_p.add(pserial.midioutput_cb);
  287. pserial.mididetail_b = new JButton("Detail...");
  288. pserial.mididetail_b.addActionListener(this);
  289. midi_sl.putConstraint(SpringLayout.NORTH, pserial.mididetail_b, 60, SpringLayout.NORTH, midi_p);
  290. midi_sl.putConstraint(SpringLayout.WEST, pserial.mididetail_b, 218, SpringLayout.WEST, midi_p);
  291. midi_p.add(pserial.mididetail_b);
  292. //OSC/MIDI(ext.) Setting
  293. JPanel osc_ext_midi_p = new JPanel();
  294. SpringLayout osc_ext_midi_sl = new SpringLayout();
  295. osc_ext_midi_p.setLayout(osc_ext_midi_sl);
  296. osc_ext_midi_p.setPreferredSize(new Dimension(370, 85));
  297. psd_p.add(osc_ext_midi_p, "osc-ext-midi");
  298. JLabel hostaddress_ext_midi_l = new JLabel("Host Address :");
  299. osc_ext_midi_sl.putConstraint(SpringLayout.NORTH, hostaddress_ext_midi_l, 5, SpringLayout.NORTH, osc_ext_midi_p);
  300. if(System.getProperty("os.name").startsWith("Mac OS X"))
  301. osc_ext_midi_sl.putConstraint(SpringLayout.WEST, hostaddress_ext_midi_l, 4, SpringLayout.WEST, osc_ext_midi_p);
  302. else if(System.getProperty("os.name").startsWith("Windows"))
  303. osc_ext_midi_sl.putConstraint(SpringLayout.WEST, hostaddress_ext_midi_l, 1, SpringLayout.WEST, osc_ext_midi_p);
  304. osc_ext_midi_p.add(hostaddress_ext_midi_l);
  305. pserial.hostaddress_tf = new JTextField("127.0.0.1", 10);
  306. pserial.hostaddress_tf.addActionListener(this);
  307. if(System.getProperty("os.name").startsWith("Mac OS X"))
  308. osc_ext_midi_sl.putConstraint(SpringLayout.NORTH, pserial.hostaddress_tf, -6, SpringLayout.NORTH, hostaddress_ext_midi_l);
  309. else if(System.getProperty("os.name").startsWith("Windows"))
  310. osc_ext_midi_sl.putConstraint(SpringLayout.NORTH, pserial.hostaddress_tf, -1, SpringLayout.NORTH, hostaddress_ext_midi_l);
  311. osc_ext_midi_sl.putConstraint(SpringLayout.WEST, pserial.hostaddress_tf, 10, SpringLayout.EAST, hostaddress_ext_midi_l);
  312. osc_ext_midi_p.add(pserial.hostaddress_tf);
  313. JLabel hostport_ext_midi_l = new JLabel("Host Port :");
  314. osc_ext_midi_sl.putConstraint(SpringLayout.NORTH, hostport_ext_midi_l, 35, SpringLayout.NORTH, osc_ext_midi_p);
  315. if(System.getProperty("os.name").startsWith("Mac OS X"))
  316. osc_ext_midi_sl.putConstraint(SpringLayout.WEST, hostport_ext_midi_l, 30, SpringLayout.WEST, osc_ext_midi_p);
  317. else if(System.getProperty("os.name").startsWith("Windows"))
  318. osc_ext_midi_sl.putConstraint(SpringLayout.WEST, hostport_ext_midi_l, 25, SpringLayout.WEST, osc_ext_midi_p);
  319. osc_ext_midi_p.add(hostport_ext_midi_l);
  320. pserial.hostport_tf = new JTextField("8000", 3);
  321. pserial.hostport_tf.addActionListener(this);
  322. if(System.getProperty("os.name").startsWith("Mac OS X"))
  323. osc_ext_midi_sl.putConstraint(SpringLayout.NORTH, pserial.hostport_tf, -6, SpringLayout.NORTH, hostport_ext_midi_l);
  324. else if(System.getProperty("os.name").startsWith("Windows"))
  325. osc_ext_midi_sl.putConstraint(SpringLayout.NORTH, pserial.hostport_tf, -1, SpringLayout.NORTH, hostport_ext_midi_l);
  326. osc_ext_midi_sl.putConstraint(SpringLayout.WEST, pserial.hostport_tf, 10, SpringLayout.EAST, hostport_ext_midi_l);
  327. osc_ext_midi_p.add(pserial.hostport_tf);
  328. JLabel listenport_ext_midi_l = new JLabel("Listen Port :");
  329. osc_ext_midi_sl.putConstraint(SpringLayout.NORTH, listenport_ext_midi_l, 65, SpringLayout.NORTH, osc_ext_midi_p);
  330. if(System.getProperty("os.name").startsWith("Mac OS X"))
  331. osc_ext_midi_sl.putConstraint(SpringLayout.WEST, listenport_ext_midi_l, 22, SpringLayout.WEST, osc_ext_midi_p);
  332. else if(System.getProperty("os.name").startsWith("Windows"))
  333. osc_ext_midi_sl.putConstraint(SpringLayout.WEST, listenport_ext_midi_l, 16, SpringLayout.WEST, osc_ext_midi_p);
  334. osc_ext_midi_p.add(listenport_ext_midi_l);
  335. pserial.listenport_tf = new JTextField("8080", 3);
  336. if(System.getProperty("os.name").startsWith("Mac OS X"))
  337. osc_ext_midi_sl.putConstraint(SpringLayout.NORTH, pserial.listenport_tf, -6, SpringLayout.NORTH, listenport_ext_midi_l);
  338. else if(System.getProperty("os.name").startsWith("Windows"))
  339. osc_ext_midi_sl.putConstraint(SpringLayout.NORTH, pserial.listenport_tf, -1, SpringLayout.NORTH, listenport_ext_midi_l);
  340. osc_ext_midi_sl.putConstraint(SpringLayout.WEST, pserial.listenport_tf, 10, SpringLayout.EAST, listenport_ext_midi_l);
  341. osc_ext_midi_p.add(pserial.listenport_tf);
  342. JLabel midioutput_ext_midi_l = new JLabel("MIDI Output :");
  343. osc_ext_midi_sl.putConstraint(SpringLayout.NORTH, midioutput_ext_midi_l, 35, SpringLayout.NORTH, osc_ext_midi_p);
  344. if(System.getProperty("os.name").startsWith("Mac OS X"))
  345. osc_ext_midi_sl.putConstraint(SpringLayout.WEST, midioutput_ext_midi_l, 170, SpringLayout.WEST, osc_ext_midi_p);
  346. else if(System.getProperty("os.name").startsWith("Windows"))
  347. osc_ext_midi_sl.putConstraint(SpringLayout.WEST, midioutput_ext_midi_l, 159, SpringLayout.WEST, osc_ext_midi_p);
  348. osc_ext_midi_p.add(midioutput_ext_midi_l);
  349. pserial.midioutput_cb = new JComboBox(pserial.getMidiOutputList());
  350. pserial.midioutput_cb.setActionCommand("MidiOutChanged");
  351. pserial.midioutput_cb.addActionListener(this);
  352. if(System.getProperty("os.name").startsWith("Mac OS X"))
  353. pserial.midioutput_cb.setPreferredSize(new Dimension(200, 30));
  354. osc_ext_midi_sl.putConstraint(SpringLayout.NORTH, pserial.midioutput_cb, 20, SpringLayout.NORTH, midioutput_ext_midi_l);
  355. if(System.getProperty("os.name").startsWith("Mac OS X"))
  356. osc_ext_midi_sl.putConstraint(SpringLayout.WEST, pserial.midioutput_cb, -90, SpringLayout.EAST, midioutput_ext_midi_l);
  357. else if(System.getProperty("os.name").startsWith("Windows"))
  358. osc_ext_midi_sl.putConstraint(SpringLayout.WEST, pserial.midioutput_cb, -70, SpringLayout.EAST, midioutput_ext_midi_l);
  359. osc_ext_midi_p.add(pserial.midioutput_cb);
  360. //Device Settings
  361. JXTaskPane pane2 = new JXTaskPane("Device Settings");
  362. container.add(pane2);
  363. pane2.setCollapsed(true);
  364. JPanel ds_p = new JPanel();
  365. SpringLayout ds_sl = new SpringLayout();
  366. ds_p.setLayout(ds_sl);
  367. SoftBevelBorder ds_inborder = new SoftBevelBorder(SoftBevelBorder.LOWERED);
  368. //test TitledBorder ds_outborder = new TitledBorder(ds_inborder, "Device Settings", TitledBorder.LEFT, TitledBorder.ABOVE_TOP);
  369. BevelBorder ds_outborder = new BevelBorder(BevelBorder.LOWERED);
  370. ds_p.setPreferredSize(new Dimension(385, 380));
  371. ds_p.setBorder(ds_outborder);
  372. sl.putConstraint(SpringLayout.NORTH, ds_p, 180, SpringLayout.NORTH, pane2);
  373. sl.putConstraint(SpringLayout.WEST, ds_p, 10, SpringLayout.WEST, pane2);
  374. pane2.add(ds_p);
  375. JLabel device_l = new JLabel("Device :");
  376. ds_sl.putConstraint(SpringLayout.NORTH, device_l, 10, SpringLayout.NORTH, ds_p);
  377. ds_sl.putConstraint(SpringLayout.WEST, device_l, 12, SpringLayout.WEST, ds_p);
  378. ds_p.add(device_l);
  379. pserial.device_cb = new JComboBox(pserial.getDeviceList());
  380. pserial.device_cb.setActionCommand("DeviceChanged");
  381. pserial.device_cb.addActionListener(this);
  382. ds_sl.putConstraint(SpringLayout.NORTH, pserial.device_cb, -4, SpringLayout.NORTH, device_l);
  383. ds_sl.putConstraint(SpringLayout.WEST, pserial.device_cb, 10, SpringLayout.EAST, device_l);
  384. ds_p.add(pserial.device_cb);
  385. JLabel cable_l = new JLabel("Cable Orientation :");
  386. ds_sl.putConstraint(SpringLayout.NORTH, cable_l, 40, SpringLayout.NORTH, ds_p);
  387. ds_sl.putConstraint(SpringLayout.WEST, cable_l, 12, SpringLayout.WEST, ds_p);
  388. ds_p.add(cable_l);
  389. String[] cable_str = {"left", "right", "up", "down"};
  390. pserial.cable_cb = new JComboBox(cable_str);
  391. pserial.cable_cb.setActionCommand("CableChanged");
  392. pserial.cable_cb.addActionListener(this);
  393. if(System.getProperty("os.name").startsWith("Mac OS X"))
  394. ds_sl.putConstraint(SpringLayout.NORTH, pserial.cable_cb, -4, SpringLayout.NORTH, cable_l);
  395. else if(System.getProperty("os.name").startsWith("Windows"))
  396. ds_sl.putConstraint(SpringLayout.NORTH, pserial.cable_cb, -3, SpringLayout.NORTH, cable_l);
  397. ds_sl.putConstraint(SpringLayout.WEST, pserial.cable_cb, 10, SpringLayout.EAST, cable_l);
  398. ds_p.add(pserial.cable_cb);
  399. JLabel intensity_l = new JLabel("Intensity :");
  400. ds_sl.putConstraint(SpringLayout.NORTH, intensity_l, 72, SpringLayout.NORTH, ds_p);
  401. ds_sl.putConstraint(SpringLayout.WEST, intensity_l, 12, SpringLayout.WEST, ds_p);
  402. ds_p.add(intensity_l);
  403. SpinnerNumberModel intensity_m = new SpinnerNumberModel(15, 0, 15, 1);
  404. pserial.intensity_s = new JSpinner(intensity_m);
  405. JSpinner.NumberEditor intensity_edit = new JSpinner.NumberEditor(pserial.intensity_s);
  406. pserial.intensity_s.setEditor(intensity_edit);
  407. JFormattedTextField intensity_text = intensity_edit.getTextField();
  408. intensity_text.setEditable(false);
  409. pserial.intensity_s.addChangeListener(this);
  410. if(System.getProperty("os.name").startsWith("Mac OS X"))
  411. pserial.intensity_s.setPreferredSize(new Dimension(50, 22));
  412. if(System.getProperty("os.name").startsWith("Windows"))
  413. pserial.intensity_s.setPreferredSize(new Dimension(50, 24));
  414. ds_sl.putConstraint(SpringLayout.NORTH, pserial.intensity_s, -2, SpringLayout.NORTH, intensity_l);
  415. ds_sl.putConstraint(SpringLayout.WEST, pserial.intensity_s, 10, SpringLayout.EAST, intensity_l);
  416. ds_p.add(pserial.intensity_s);
  417. pserial.led_clear_b = new JButton("LED Clear");
  418. pserial.led_clear_b.addActionListener(this);
  419. ds_sl.putConstraint(SpringLayout.NORTH, pserial.led_clear_b, -2, SpringLayout.NORTH, pserial.intensity_s);
  420. ds_sl.putConstraint(SpringLayout.WEST, pserial.led_clear_b, 3, SpringLayout.EAST, pserial.intensity_s);
  421. ds_p.add(pserial.led_clear_b);
  422. pserial.led_test_b = new JButton("LED Test On");
  423. pserial.led_test_b.addActionListener(this);
  424. ds_sl.putConstraint(SpringLayout.NORTH, pserial.led_test_b, 0, SpringLayout.NORTH, pserial.led_clear_b);
  425. ds_sl.putConstraint(SpringLayout.WEST, pserial.led_test_b, 10, SpringLayout.EAST, pserial.led_clear_b);
  426. ds_p.add(pserial.led_test_b);
  427. JPanel dsps_p = new JPanel();
  428. SpringLayout dsps_sl = new SpringLayout();
  429. dsps_p.setLayout(dsps_sl);
  430. SoftBevelBorder dsps_inborder = new SoftBevelBorder(SoftBevelBorder.LOWERED);
  431. TitledBorder dsps_outborder = new TitledBorder(dsps_inborder, "Device-Specific Protocol Settings", TitledBorder.LEFT, TitledBorder.ABOVE_TOP);
  432. dsps_p.setPreferredSize(new Dimension(370, 130));
  433. dsps_p.setBorder(dsps_outborder);
  434. ds_sl.putConstraint(SpringLayout.NORTH, dsps_p, 100, SpringLayout.NORTH, ds_p);
  435. ds_sl.putConstraint(SpringLayout.WEST, dsps_p, 5, SpringLayout.WEST, ds_p);
  436. ds_p.add(dsps_p);
  437. JLabel prefix_l = new JLabel("Address Pattern Prefix :");
  438. dsps_sl.putConstraint(SpringLayout.NORTH, prefix_l, 10, SpringLayout.NORTH, dsps_p);
  439. dsps_sl.putConstraint(SpringLayout.WEST, prefix_l, 45, SpringLayout.WEST, dsps_p);
  440. dsps_p.add(prefix_l);
  441. pserial.prefix_tf = new JTextField("/test", 5);
  442. pserial.prefix_tf.addActionListener(this);
  443. if(System.getProperty("os.name").startsWith("Mac OS X"))
  444. dsps_sl.putConstraint(SpringLayout.NORTH, pserial.prefix_tf, -4, SpringLayout.NORTH, prefix_l);
  445. if(System.getProperty("os.name").startsWith("Windows"))
  446. dsps_sl.putConstraint(SpringLayout.NORTH, pserial.prefix_tf, 0, SpringLayout.NORTH, prefix_l);
  447. dsps_sl.putConstraint(SpringLayout.WEST, pserial.prefix_tf, 10, SpringLayout.EAST, prefix_l);
  448. dsps_p.add(pserial.prefix_tf);
  449. JLabel startcolumn_l = new JLabel("Starting Column :");
  450. dsps_sl.putConstraint(SpringLayout.NORTH, startcolumn_l, 40, SpringLayout.NORTH, dsps_p);
  451. if(System.getProperty("os.name").startsWith("Mac OS X"))
  452. dsps_sl.putConstraint(SpringLayout.WEST, startcolumn_l, 102, SpringLayout.WEST, dsps_p);
  453. if(System.getProperty("os.name").startsWith("Windows"))
  454. dsps_sl.putConstraint(SpringLayout.WEST, startcolumn_l, 84, SpringLayout.WEST, dsps_p);
  455. dsps_p.add(startcolumn_l);
  456. SpinnerNumberModel startcolumn_m = new SpinnerNumberModel(0, 0, null, 1);
  457. pserial.startcolumn_s = new JSpinner(startcolumn_m);
  458. JSpinner.NumberEditor startcolumn_edit = new JSpinner.NumberEditor(pserial.startcolumn_s);
  459. pserial.startcolumn_s.setEditor(startcolumn_edit);
  460. JFormattedTextField startcolumn_text = startcolumn_edit.getTextField();
  461. startcolumn_text.setEditable(false);
  462. pserial.startcolumn_s.addChangeListener(new ChangeListener() {
  463. public void stateChanged(ChangeEvent e) {
  464. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0)))
  465. pserial.setCurrentStartingColumn(0, (Integer)pserial.startcolumn_s.getValue());
  466. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1)))
  467. pserial.setCurrentStartingColumn(1, (Integer)pserial.startcolumn_s.getValue());
  468. }
  469. });
  470. pserial.startcolumn_s.setPreferredSize(new Dimension(50, 22));
  471. if(System.getProperty("os.name").startsWith("Mac OS X"))
  472. dsps_sl.putConstraint(SpringLayout.NORTH, pserial.startcolumn_s, -4, SpringLayout.NORTH, startcolumn_l);
  473. if(System.getProperty("os.name").startsWith("Windows"))
  474. dsps_sl.putConstraint(SpringLayout.NORTH, pserial.startcolumn_s, 0, SpringLayout.NORTH, startcolumn_l);
  475. dsps_sl.putConstraint(SpringLayout.WEST, pserial.startcolumn_s, 10, SpringLayout.EAST, startcolumn_l);
  476. dsps_p.add(pserial.startcolumn_s);
  477. JLabel startrow_l = new JLabel("Starting Row :");
  478. if(System.getProperty("os.name").startsWith("Mac OS X")) {
  479. dsps_sl.putConstraint(SpringLayout.NORTH, startrow_l, 70, SpringLayout.NORTH, dsps_p);
  480. dsps_sl.putConstraint(SpringLayout.WEST, startrow_l, 125, SpringLayout.WEST, dsps_p);
  481. }
  482. if(System.getProperty("os.name").startsWith("Windows")) {
  483. dsps_sl.putConstraint(SpringLayout.NORTH, startrow_l, 72, SpringLayout.NORTH, dsps_p);
  484. dsps_sl.putConstraint(SpringLayout.WEST, startrow_l, 102, SpringLayout.WEST, dsps_p);
  485. }
  486. dsps_p.add(startrow_l);
  487. SpinnerNumberModel startrow_m = new SpinnerNumberModel(0, 0, null, 1);
  488. pserial.startrow_s = new JSpinner(startrow_m);
  489. JSpinner.NumberEditor startrow_edit = new JSpinner.NumberEditor(pserial.startrow_s);
  490. pserial.startrow_s.setEditor(startrow_edit);
  491. JFormattedTextField startrow_text = startrow_edit.getTextField();
  492. startrow_text.setEditable(false);
  493. pserial.startrow_s.addChangeListener(new ChangeListener() {
  494. public void stateChanged(ChangeEvent e) {
  495. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0)))
  496. pserial.setCurrentStartingRow(0, (Integer)pserial.startrow_s.getValue());
  497. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1)))
  498. pserial.setCurrentStartingRow(1, (Integer)pserial.startrow_s.getValue());
  499. }
  500. });
  501. pserial.startrow_s.setPreferredSize(new Dimension(50, 22));
  502. if(System.getProperty("os.name").startsWith("Mac OS X"))
  503. dsps_sl.putConstraint(SpringLayout.NORTH, pserial.startrow_s, -4, SpringLayout.NORTH, startrow_l);
  504. if(System.getProperty("os.name").startsWith("Windows"))
  505. dsps_sl.putConstraint(SpringLayout.NORTH, pserial.startrow_s, 0, SpringLayout.NORTH, startrow_l);
  506. dsps_sl.putConstraint(SpringLayout.WEST, pserial.startrow_s, 10, SpringLayout.EAST, startrow_l);
  507. dsps_p.add(pserial.startrow_s);
  508. JTabbedPane ais_tab = new JTabbedPane();
  509. if(System.getProperty("os.name").startsWith("Mac OS X")) {
  510. ais_tab.setPreferredSize(new Dimension(380, 145));
  511. ds_sl.putConstraint(SpringLayout.WEST, ais_tab, 1, SpringLayout.WEST, ds_p);
  512. }
  513. else if(System.getProperty("os.name").startsWith("Windows")) {
  514. ais_tab.setPreferredSize(new Dimension(362, 130));
  515. ds_sl.putConstraint(SpringLayout.WEST, ais_tab, 9, SpringLayout.WEST, ds_p);
  516. }
  517. ds_sl.putConstraint(SpringLayout.NORTH, ais_tab, 240, SpringLayout.NORTH, ds_p);
  518. ds_p.add(ais_tab);
  519. JPanel aie_p = new JPanel();
  520. SpringLayout aie_sl = new SpringLayout();
  521. aie_p.setLayout(aie_sl);
  522. aie_p.setPreferredSize(new Dimension(380, 60));
  523. aie_sl.putConstraint(SpringLayout.NORTH, aie_p, 0, SpringLayout.NORTH, ais_tab);
  524. aie_sl.putConstraint(SpringLayout.WEST, aie_p, 0, SpringLayout.WEST, ais_tab);
  525. for(int i = 0; i < pserial.getMaxAnalogNum(); i++) {
  526. pserial.adc_ck[i] = new JCheckBox(" adc " + i);
  527. pserial.adc_ck[i].addActionListener(this);
  528. if(i < 4) {
  529. aie_sl.putConstraint(SpringLayout.NORTH, pserial.adc_ck[i], 10, SpringLayout.NORTH, aie_p);
  530. aie_sl.putConstraint(SpringLayout.WEST, pserial.adc_ck[i], 10 + (90 * i), SpringLayout.WEST, aie_p);
  531. }
  532. else if(i < 8) {
  533. aie_sl.putConstraint(SpringLayout.NORTH, pserial.adc_ck[i], 40, SpringLayout.NORTH, aie_p);
  534. aie_sl.putConstraint(SpringLayout.WEST, pserial.adc_ck[i], 10 + (90 * (i - 4)), SpringLayout.WEST, aie_p);
  535. }
  536. else {
  537. aie_sl.putConstraint(SpringLayout.NORTH, pserial.adc_ck[i], 70, SpringLayout.NORTH, aie_p);
  538. aie_sl.putConstraint(SpringLayout.WEST, pserial.adc_ck[i], 10 + (90 * (i - 8)), SpringLayout.WEST, aie_p);
  539. }
  540. aie_p.add(pserial.adc_ck[i]);
  541. }
  542. ais_tab.addTab("Analog In. Enable", aie_p);
  543. JPanel ait_p = new JPanel();
  544. SpringLayout ait_sl = new SpringLayout();
  545. ait_p.setLayout(ait_sl);
  546. ait_p.setPreferredSize(new Dimension(395, 80));
  547. ait_sl.putConstraint(SpringLayout.NORTH, ait_p, 0, SpringLayout.NORTH, ais_tab);
  548. ait_sl.putConstraint(SpringLayout.WEST, ait_p, 0, SpringLayout.WEST, ais_tab);
  549. for(int i = 0; i < pserial.getMaxAnalogNum(); i++) {
  550. String[] type_name = {"I/F", "C/F", "M/A"};
  551. pserial.adc_cmb0[i] = new JComboBox(type_name);
  552. pserial.adc_cmb0[i].setActionCommand("InputType" + i);
  553. pserial.adc_cmb0[i].setEnabled(false);
  554. pserial.adc_cmb0[i].addActionListener(this);
  555. if(i < 4) {
  556. ait_sl.putConstraint(SpringLayout.NORTH, pserial.adc_cmb0[i], 10, SpringLayout.NORTH, ait_p);
  557. ait_sl.putConstraint(SpringLayout.WEST, pserial.adc_cmb0[i], 3 + (90 * i), SpringLayout.WEST, ait_p);
  558. }
  559. else if(i < 8) {
  560. ait_sl.putConstraint(SpringLayout.NORTH, pserial.adc_cmb0[i], 40, SpringLayout.NORTH, ait_p);
  561. ait_sl.putConstraint(SpringLayout.WEST, pserial.adc_cmb0[i], 3 + (90 * (i - 4)), SpringLayout.WEST, ait_p);
  562. }
  563. else {
  564. ait_sl.putConstraint(SpringLayout.NORTH, pserial.adc_cmb0[i], 70, SpringLayout.NORTH, ait_p);
  565. ait_sl.putConstraint(SpringLayout.WEST, pserial.adc_cmb0[i], 3 + (90 * (i - 8)), SpringLayout.WEST, ait_p);
  566. }
  567. ait_p.add(pserial.adc_cmb0[i]);
  568. }
  569. ais_tab.addTab("Input Type", ait_p);
  570. JPanel aic_p = new JPanel();
  571. SpringLayout aic_sl = new SpringLayout();
  572. aic_p.setLayout(aic_sl);
  573. aic_p.setPreferredSize(new Dimension(395, 80));
  574. aic_sl.putConstraint(SpringLayout.NORTH, aic_p, 0, SpringLayout.NORTH, ais_tab);
  575. aic_sl.putConstraint(SpringLayout.WEST, aic_p, 0, SpringLayout.WEST, ais_tab);
  576. for(int i = 0; i < pserial.getMaxAnalogNum(); i++) {
  577. String[] curve_name = {"C.1", "C.2", "C.3", "C.4", "C.5", "C.6", "C.7", "C.8"};
  578. pserial.adc_cmb1[i] = new JComboBox(curve_name);
  579. pserial.adc_cmb1[i].setEnabled(false);
  580. pserial.adc_cmb1[i].setSelectedIndex(2);
  581. pserial.adc_cmb1[i].addActionListener(this);
  582. if(i < 4) {
  583. aic_sl.putConstraint(SpringLayout.NORTH, pserial.adc_cmb1[i], 10, SpringLayout.NORTH, aic_p);
  584. aic_sl.putConstraint(SpringLayout.WEST, pserial.adc_cmb1[i], 5 + (90 * i), SpringLayout.WEST, aic_p);
  585. }
  586. else if(i < 8) {
  587. aic_sl.putConstraint(SpringLayout.NORTH, pserial.adc_cmb1[i], 40, SpringLayout.NORTH, aic_p);
  588. aic_sl.putConstraint(SpringLayout.WEST, pserial.adc_cmb1[i], 5 + (90 * (i - 4)), SpringLayout.WEST, aic_p);
  589. }
  590. else {
  591. aic_sl.putConstraint(SpringLayout.NORTH, pserial.adc_cmb1[i], 70, SpringLayout.NORTH, aic_p);
  592. aic_sl.putConstraint(SpringLayout.WEST, pserial.adc_cmb1[i], 5 + (90 * (i - 8)), SpringLayout.WEST, aic_p);
  593. }
  594. aic_p.add(pserial.adc_cmb1[i]);
  595. }
  596. ais_tab.addTab("Fader Curve", aic_p);
  597. // j[bNOɐݒ肷
  598. // pane2.setMnemonic(KeyEvent.VK_O);
  599. return container;
  600. }
  601. private class AutoResizeThread implements Runnable {
  602. int height_old;
  603. @Override
  604. public void run() {
  605. while(true) {
  606. try {
  607. Dimension dim = container.getPreferredScrollableViewportSize();
  608. double d = dim.getHeight();
  609. if((int)d != height_old) {
  610. if(System.getProperty("os.name").startsWith("Mac OS X"))
  611. setSize(402, (int)d + 10);
  612. else if(System.getProperty("os.name").startsWith("Windows"))
  613. setSize(418, (int)d + 25);
  614. }
  615. height_old = (int)d;
  616. Thread.sleep(10);
  617. } catch(Exception e) {
  618. }
  619. }
  620. }
  621. }
  622. public void actionPerformed(ActionEvent e) {
  623. String cmd = e.getActionCommand();
  624. if(cmd == null)
  625. cmd = "timer";
  626. else if(cmd.equals(pserial.prefix_tf.getText()))
  627. cmd = "Prefix";
  628. else if(cmd.equals(pserial.hostaddress_tf.getText()))
  629. cmd = "HostAddress";
  630. if(cmd.equals("DeviceChanged")) {
  631. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0)))
  632. pserial.changeDeviceSettings(0);
  633. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1)))
  634. pserial.changeDeviceSettings(1);
  635. }
  636. else if(cmd.equals("ProtocolChanged")) {
  637. if(((String)pserial.protocol_cb.getSelectedItem()).equals("Open Sound Control")) {
  638. psd_cl.show(psd_p, "osc");
  639. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0)))
  640. pserial.setCurrentProtocol(0, "Open Sound Control");
  641. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1)))
  642. pserial.setCurrentProtocol(1, "Open Sound Control");
  643. }
  644. else if(((String)pserial.protocol_cb.getSelectedItem()).equals("MIDI")) {
  645. psd_cl.show(psd_p, "midi");
  646. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0)))
  647. pserial.setCurrentProtocol(0, "MIDI");
  648. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1)))
  649. pserial.setCurrentProtocol(1, "MIDI");
  650. }
  651. else if(((String)pserial.protocol_cb.getSelectedItem()).equals("OSC/MIDI(ext.)")) {
  652. psd_cl.show(psd_p, "osc-ext-midi");
  653. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0)))
  654. pserial.setCurrentProtocol(0, "OSC/MIDI(ext.)");
  655. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1)))
  656. pserial.setCurrentProtocol(1, "OSC/MIDI(ext.)");
  657. }
  658. else if(((String)pserial.protocol_cb.getSelectedItem()).equals("DORAnome")) {
  659. psd_cl.show(psd_p, "osc-ext-midi");
  660. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0)))
  661. pserial.setCurrentProtocol(0, "DORAnome");
  662. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1)))
  663. pserial.setCurrentProtocol(1, "DORAnome");
  664. for(int i = 3; i < 6; i++) {
  665. String str =new String("ae " + i + " " + 1 + (char)0x0D);
  666. pserial.adc_ck[i].setSelected(true);
  667. pserial.adc_cmb0[i].setEnabled(true);
  668. if(pserial.adc_cmb0[i].getSelectedIndex() < 2)
  669. pserial.adc_cmb1[i].setEnabled(true);
  670. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0))) {
  671. pserial.setAdcEnable(0, i, true);
  672. pserial.sendDataToSerial(0, str);
  673. }
  674. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1))) {
  675. pserial.setAdcEnable(1, i, true);
  676. pserial.sendDataToSerial(1, str);
  677. }
  678. }
  679. }
  680. /*sy
  681. else if(((String)pserial.protocol_cb.getSelectedItem()).equals("OSC(LEDs)/MIDI(Pads)")) {
  682. psd_cl.show(psd_p, "midi");
  683. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0)))
  684. pserial.setCurrentProtocol(0, "OSC(LEDs)/MIDI(Pads)");
  685. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1)))
  686. pserial.setCurrentProtocol(1, "OSC(LEDs)/MIDI(Pads)");
  687. }
  688. */
  689. }
  690. else if(cmd.equals("MidiInChanged")) {
  691. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0))) {
  692. pserial.setCurrentMidiIn(0, pserial.midiinput_cb.getSelectedIndex());
  693. pserial.openMIDIPort(0);
  694. }
  695. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1))) {
  696. pserial.setCurrentMidiIn(1, pserial.midiinput_cb.getSelectedIndex());
  697. pserial.openMIDIPort(1);
  698. }
  699. }
  700. else if(cmd.equals("MidiOutChanged")) {
  701. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0))) {
  702. pserial.setCurrentMidiOut(0, pserial.midioutput_cb.getSelectedIndex());
  703. pserial.openMIDIPort(0);
  704. }
  705. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1))) {
  706. pserial.setCurrentMidiOut(1, pserial.midioutput_cb.getSelectedIndex());
  707. pserial.openMIDIPort(1);
  708. }
  709. }
  710. else if(cmd.equals("CableChanged")) {
  711. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0)))
  712. pserial.setCurrentCable(0, (String)pserial.cable_cb.getSelectedItem());
  713. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1)))
  714. pserial.setCurrentCable(1, (String)pserial.cable_cb.getSelectedItem());
  715. }
  716. else if(cmd.equals("LED Clear")) {
  717. int idx = pserial.device_cb.getSelectedIndex();
  718. for(int i = 0; i < 8; i++) {
  719. String str =new String("lr " + i + " " + 0 + (char)0x0D);
  720. if(pserial.checkPortState(idx))
  721. pserial.sendDataToSerial(idx, str);
  722. }
  723. }
  724. else if(cmd.equals("LED Test On")) {
  725. //sy int idx = pserial.device_cb.getSelectedIndex();
  726. String str =new String("test 1" + (char)0x0D);
  727. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0))) {
  728. if(pserial.checkPortState(0))
  729. pserial.sendDataToSerial(0, str);
  730. }
  731. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1))) {
  732. if(pserial.checkPortState(1))
  733. pserial.sendDataToSerial(1, str);
  734. }
  735. /*
  736. if(pserial.checkPortState(idx))
  737. pserial.sendDataToSerial(idx, str);
  738. */
  739. pserial.led_test_b.setText("LED Test Off");
  740. }
  741. else if(cmd.equals("LED Test Off")) {
  742. //sy int idx = pserial.device_cb.getSelectedIndex();
  743. String str =new String("test 0" + (char)0x0D);
  744. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0))) {
  745. if(pserial.checkPortState(0))
  746. pserial.sendDataToSerial(0, str);
  747. }
  748. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1))) {
  749. if(pserial.checkPortState(1))
  750. pserial.sendDataToSerial(1, str);
  751. }
  752. pserial.led_test_b.setText("LED Test On");
  753. }
  754. else if(cmd.equals("Detail..."))
  755. mdf.setVisible(true);
  756. else if(cmd.equals("Select")) {
  757. JFileChooser fc = new JFileChooser();
  758. int selected = fc.showOpenDialog(this);
  759. if (selected == JFileChooser.APPROVE_OPTION) {
  760. hex_f = fc.getSelectedFile();
  761. pserial.hex_tf.setText(hex_f.getName());
  762. pserial.update_b.setEnabled(true);
  763. }
  764. }
  765. else if(cmd.equals("Update")) {
  766. try
  767. {
  768. hex_fr = new FileReader(hex_f);
  769. size = 0;
  770. count = 0;
  771. bar = 0;
  772. while(hex_fr.read() != -1)
  773. size++;
  774. timer.start();
  775. hex_fr = new FileReader(hex_f);
  776. }
  777. catch(IOException ioe){}
  778. }
  779. else if(cmd.equals("Prefix"))
  780. pserial.initOSCListener();
  781. /*
  782. else if(cmd.equals("HostAddress") || cmd.equals("HostPort")) {
  783. pserial.setOSCHostInfo();
  784. }
  785. */
  786. else if(cmd.equals(" adc 0") || cmd.equals(" adc 1") || cmd.equals(" adc 2") || cmd.equals(" adc 3") ||
  787. cmd.equals(" adc 4") || cmd.equals(" adc 5") || cmd.equals(" adc 6") || cmd.equals(" adc 7") ||
  788. cmd.equals(" adc 8") || cmd.equals(" adc 9") || cmd.equals(" adc 10")) {
  789. int adc_id = -1;
  790. if(cmd.length() == 6)
  791. adc_id = Integer.parseInt(cmd.substring(5, 6));
  792. else
  793. adc_id = Integer.parseInt(cmd.substring(5, 7));
  794. boolean b = pserial.adc_ck[adc_id].isSelected();
  795. String str;
  796. if(b) {
  797. str =new String("ae " + adc_id + " " + 1 + (char)0x0D);
  798. pserial.adc_cmb0[adc_id].setEnabled(true);
  799. if(pserial.adc_cmb0[adc_id].getSelectedIndex() < 2)
  800. pserial.adc_cmb1[adc_id].setEnabled(true);
  801. }
  802. else {
  803. str =new String("ae " + adc_id + " " + 0 + (char)0x0D);
  804. pserial.adc_cmb0[adc_id].setEnabled(false);
  805. pserial.adc_cmb1[adc_id].setEnabled(false);
  806. }
  807. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0))) {
  808. pserial.setAdcEnable(0, adc_id, b);
  809. pserial.sendDataToSerial(0, str);
  810. }
  811. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1))) {
  812. pserial.setAdcEnable(1, adc_id, b);
  813. pserial.sendDataToSerial(1, str);
  814. }
  815. }
  816. else if(cmd.equals("InputType0") || cmd.equals("InputType1") || cmd.equals("InputType2") || cmd.equals("InputType3") ||
  817. cmd.equals("InputType4") || cmd.equals("InputType5") || cmd.equals("InputType6") || cmd.equals("InputType7") ||
  818. cmd.equals("InputType8") || cmd.equals("InputType9") || cmd.equals("InputType10")) {
  819. int adc_id = Integer.parseInt(cmd.substring(9, 10));
  820. int idx = pserial.adc_cmb0[adc_id].getSelectedIndex();
  821. if(idx < 2) {
  822. pserial.adc_cmb1[adc_id].setEnabled(true);
  823. }
  824. else {
  825. pserial.adc_cmb1[adc_id].setEnabled(false);
  826. }
  827. }
  828. else if(cmd.equals("timer")) {
  829. try {
  830. if((ch = hex_fr.read()) != -1) {
  831. bar = (int)(((double)count / (double)size) * 100);
  832. pserial.update_pb.setValue(bar);
  833. count++;
  834. pserial.sendDataToSerial(0, ch);
  835. }
  836. if(ch == -1 || ch == 59) {
  837. pserial.update_pb.setValue(0);
  838. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0)))
  839. pserial.closeSerialPort(0);
  840. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1)))
  841. pserial.closeSerialPort(1);
  842. hex_fr.close();
  843. timer.stop();
  844. }
  845. } catch(IOException ioe) {}
  846. }
  847. }
  848. public void stateChanged(ChangeEvent e) {
  849. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0))) {
  850. if((Integer)pserial.intensity_s.getValue() != pserial.getCurrentIntensity(0)) {
  851. pserial.setCurrentIntensity(0, (Integer)pserial.intensity_s.getValue());
  852. String str =new String("i " + pserial.getCurrentIntensity(0) + (char)0x0D);
  853. if(pserial.checkPortState(0))
  854. pserial.sendDataToSerial(0, str);
  855. }
  856. //sy pserial.starting_column[0] = (Integer)pserial.startcolumn_s.getValue();
  857. //sy pserial.starting_row[0] = (Integer)pserial.startrow_s.getValue();
  858. }
  859. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1))) {
  860. if((Integer)pserial.intensity_s.getValue() != pserial.getCurrentIntensity(1)) {
  861. pserial.setCurrentIntensity(1, (Integer)pserial.intensity_s.getValue());
  862. String str =new String("i " + pserial.getCurrentIntensity(1) + (char)0x0D);
  863. if(pserial.checkPortState(1))
  864. pserial.sendDataToSerial(1, str);
  865. }
  866. //sy pserial.starting_column[1] = (Integer)pserial.startcolumn_s.getValue();
  867. //sy pserial.starting_row[1] = (Integer)pserial.startrow_s.getValue();
  868. }
  869. }
  870. public void changedUpdate(DocumentEvent e) {
  871. System.out.println("text");
  872. }
  873. public class HostPortFilter extends DocumentFilter {
  874. @Override
  875. public void insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
  876. //debug System.out.println("insert");
  877. if(string == null)
  878. return;
  879. else
  880. replace(fb, offset, 0, string, attr);
  881. }
  882. @Override
  883. public void remove(DocumentFilter.FilterBypass fb, int offset, int length) throws BadLocationException {
  884. //debug System.out.println("remove");
  885. replace(fb, offset, length, "", null);
  886. }
  887. @Override
  888. public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
  889. //debug System.out.println("replace");
  890. Document doc = fb.getDocument();
  891. int currentLength = doc.getLength();
  892. String currentContent = doc.getText(0, currentLength);
  893. String before = currentContent.substring(0, offset);
  894. String after = currentContent.substring(length+offset, currentLength);
  895. String newValue = before + (text == null ? "" : text) + after;
  896. //currentValue =
  897. checkInput(newValue, offset);
  898. fb.replace(offset, length, text, attrs);
  899. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0))) {
  900. pserial.setOSCHostInfo(0, newValue, pserial.listenport_tf.getText());
  901. }
  902. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1))) {
  903. pserial.setOSCHostInfo(1, newValue, pserial.listenport_tf.getText());
  904. }
  905. }
  906. private int checkInput(String proposedValue, int offset) throws BadLocationException {
  907. int newValue = 0;
  908. if(proposedValue.length() > 0) {
  909. try {
  910. newValue = Integer.parseInt(proposedValue);
  911. }catch(NumberFormatException e) {
  912. throw new BadLocationException(proposedValue, offset);
  913. }
  914. }
  915. return newValue;
  916. }
  917. }
  918. public class ListenPortFilter extends DocumentFilter {
  919. @Override
  920. public void insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
  921. //debug System.out.println("insert");
  922. if(string == null)
  923. return;
  924. else
  925. replace(fb, offset, 0, string, attr);
  926. }
  927. @Override
  928. public void remove(DocumentFilter.FilterBypass fb, int offset, int length) throws BadLocationException {
  929. //debug System.out.println("remove");
  930. replace(fb, offset, length, "", null);
  931. }
  932. @Override
  933. public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
  934. //debug System.out.println("replace");
  935. Document doc = fb.getDocument();
  936. int currentLength = doc.getLength();
  937. String currentContent = doc.getText(0, currentLength);
  938. String before = currentContent.substring(0, offset);
  939. String after = currentContent.substring(length+offset, currentLength);
  940. String newValue = before + (text == null ? "" : text) + after;
  941. //currentValue =
  942. checkInput(newValue, offset);
  943. fb.replace(offset, length, text, attrs);
  944. System.out.println("listen replace");
  945. if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(0))) {
  946. pserial.setOSCHostInfo(0, pserial.hostport_tf.getText(), newValue);
  947. }
  948. else if(((String)pserial.device_cb.getSelectedItem()).equals(pserial.getCurrentDevice(1))) {
  949. pserial.setOSCHostInfo(1, pserial.hostport_tf.getText(), newValue);
  950. }
  951. }
  952. private int checkInput(String proposedValue, int offset) throws BadLoc

Large files files are truncated, but you can click here to view the full file