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

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