Example #1
0
 /*
  * Creates the JTextArea for the GUI with the ScrollPane.
  */
 private JScrollPane responseArea() {
   responseArea = new JTextArea();
   responseArea.setSize(10, 10);
   responseArea.setLineWrap(true);
   responseArea.setWrapStyleWord(true);
   scrollPane =
       new JScrollPane(
           responseArea,
           ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
           ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
   return scrollPane;
 }
Example #2
0
  public ReplyView(MikroEventModel e, EventViewManager m) {
    super();
    evm = m;
    textArea = new JTextArea("@" + evm.event.getAuthor() + " ", 4, 45);
    Font f = new Font("Nimbus Sans L Bold", Font.PLAIN, 15);
    textArea.setFont(f);
    textArea.setLineWrap(true);
    ((AbstractDocument) textArea.getDocument()).setDocumentFilter(new DocumentSizeFilter(140));
    buttonPanel = new JPanel();
    submitButton = new JButton("Post");
    cancelButton = new JButton("Cancel");

    submitButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            evm.reply(textArea.getText());
          }
        });
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            evm.setEventView();
          }
        });

    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
    buttonPanel.add(Box.createHorizontalGlue());
    buttonPanel.add(submitButton);
    buttonPanel.add(Box.createHorizontalStrut(5));
    buttonPanel.add(cancelButton);

    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(textArea);
    this.add(buttonPanel);
  }
Example #3
0
  // Initialize all the GUI components and display the frame
  private static void initGUI() {
    // Set up the status bar
    statusField = new JLabel();
    statusField.setText(statusMessages[DISCONNECTED]);
    statusColor = new JTextField(1);
    statusColor.setBackground(Color.red);
    statusColor.setEditable(false);
    statusBar = new JPanel(new BorderLayout());
    statusBar.add(statusColor, BorderLayout.WEST);
    statusBar.add(statusField, BorderLayout.CENTER);

    // Set up the options pane
    JPanel optionsPane = initOptionsPane();

    // Set up the chat pane
    JPanel chatPane = new JPanel(new BorderLayout());
    chatText = new JTextArea(10, 20);
    chatText.setLineWrap(true);
    chatText.setEditable(false);
    chatText.setForeground(Color.blue);
    JScrollPane chatTextPane =
        new JScrollPane(
            chatText,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    chatLine = new JTextField();
    chatLine.setEnabled(false);
    chatLine.addActionListener(
        new ActionAdapter() {
          public void actionPerformed(ActionEvent e) {
            String s = chatLine.getText();
            if (!s.equals("")) {
              appendToChatBox("OUTGOING: " + s + "\n");
              chatLine.selectAll();

              // Send the string
              sendString(s);
            }
          }
        });
    chatPane.add(chatLine, BorderLayout.SOUTH);
    chatPane.add(chatTextPane, BorderLayout.CENTER);
    chatPane.setPreferredSize(new Dimension(200, 200));

    // Set up the main pane
    JPanel mainPane = new JPanel(new BorderLayout());
    mainPane.add(statusBar, BorderLayout.SOUTH);
    mainPane.add(optionsPane, BorderLayout.WEST);
    mainPane.add(chatPane, BorderLayout.CENTER);

    // Set up the main frame
    mainFrame = new JFrame("Simple TCP Chat");
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.setContentPane(mainPane);
    mainFrame.setSize(mainFrame.getPreferredSize());
    mainFrame.setLocation(200, 200);
    mainFrame.pack();
    mainFrame.setVisible(true);
  }
Example #4
0
  public LicenseDialog(Component parent) {
    setTitle("Licensing information");

    pnlButtons.add(bttnOk);

    cbLang.addItem("English");
    cbLang.addItem("Eesti");

    FlowLayout fl = new FlowLayout();
    fl.setAlignment(FlowLayout.LEFT);

    pnlHeader.setLayout(fl);

    pnlHeader.add(lblLang);
    pnlHeader.add(cbLang);

    pnlMain.setLayout(new BorderLayout());
    pnlMain.add(pnlHeader, BorderLayout.NORTH);
    pnlMain.add(scrollPane, BorderLayout.CENTER);
    pnlMain.add(pnlButtons, BorderLayout.SOUTH);

    taLicenseText.setText(getLicenseText());
    taLicenseText.setCaretPosition(0);
    taLicenseText.setLineWrap(true);
    taLicenseText.setEditable(false);
    taLicenseText.setWrapStyleWord(true);

    getContentPane().add(pnlMain);
    setPreferredSize(new Dimension(500, 600));
    setLocationRelativeTo(parent);

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    bttnOk.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            if (evt.getSource() == bttnOk) {
              dispose();
            }
          } // end actionPerformed
        }); // end bttnOk Action Listener

    cbLang.addItemListener(
        new ItemListener() {
          public void itemStateChanged(final ItemEvent event) {
            if (event.getSource() == cbLang
                && event.getStateChange() == ItemEvent.SELECTED
                && cbLang.getItemCount() > 0) {
              taLicenseText.setText(getLicenseText());
              taLicenseText.setCaretPosition(0);
            }
          }
        }); // end cbLang item listener

    pack();
    setVisible(true);
  } // PortPropertiesDialog
    public MainFrame() {
      try {
        mainPanel.setLayout(new BorderLayout());
        mainPanel.setBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9));
        mainPanel.add(outputContainer, java.awt.BorderLayout.CENTER);
        outputArea.setLineWrap(true);
        outputContainer.add(new JScrollPane(outputArea), java.awt.BorderLayout.CENTER);
        outputContainer.setBorder(new javax.swing.border.TitledBorder("Results"));

        this.getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER);

        java.util.ArrayList<JButton> btns = new java.util.ArrayList<JButton>();
        {
          JPanel westPanel = new JPanel(new GridLayout(0, 1, 0, 10));
          westPanel.setBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9));
          JPanel opsPanel = new JPanel(new GridLayout(6, 1));
          opsPanel.setBorder(new javax.swing.border.TitledBorder("Operations"));

          for (Action action : operations) {
            JPanel p = new JPanel(new BorderLayout());
            JButton jb = new JButton(action);
            btns.add(jb);
            p.add(jb, BorderLayout.NORTH);
            opsPanel.add(p);
          }

          westPanel.add(opsPanel);
          controlContainer.add(westPanel, BorderLayout.CENTER);
        }

        this.getContentPane().add(controlContainer, BorderLayout.WEST);
        this.pack();

        Dimension dim = btns.get(0).getSize();
        for (JButton btn : btns) {
          btn.setPreferredSize(dim);
        }

        java.awt.Dimension prefSize = this.getPreferredSize();
        prefSize.setSize(prefSize.getWidth(), 1.1 * prefSize.getHeight());
        this.setSize(prefSize);

        java.awt.Dimension parentSize;
        java.awt.Point parentLocation = new java.awt.Point(0, 0);
        parentSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        int x = parentLocation.x + (parentSize.width - prefSize.width) / 2;
        int y = parentLocation.y + (parentSize.height - prefSize.height) / 2;
        this.setLocation(x, y);
        this.setResizable(true);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
 void addTextArea(JPanel panel, String key, String label) {
   JLabel lab = new JLabel(label);
   lab.setAlignmentX(LEFT_ALIGNMENT);
   panel.add(lab);
   JTextArea field = new JTextArea();
   field.setText(sketch.configFile.get(key));
   field.setLineWrap(true);
   field.setWrapStyleWord(true);
   fields.put(key, field);
   JScrollPane scroll = new JScrollPane(field);
   scroll.setAlignmentX(0.0f);
   panel.add(scroll);
 }
  public void init() {
    task_name = new String[1];
    task_name[0] = "当前没有任务";
    task_description = "";
    jl_taskname = new JList(task_name);
    scrollpane1 = new JScrollPane(jl_taskname);

    jta_taskdescription = new JTextArea("", 20, 20);
    jta_taskdescription.setLineWrap(true);
    jta_taskdescription.setWrapStyleWord(true);
    jta_taskdescription.setEditable(true);
    scrollpane2 = new JScrollPane(jta_taskdescription);
  }
  /**
   * @param shortcut dialog will be initialized with this <code>shortcut</code>. It can be <code>
   *     null</code> if dialog is used to create new mouse shortcut.
   */
  public MouseShortcutDialog(
      JComponent parentComponent,
      MouseShortcut shortcut,
      @NotNull Keymap keymap,
      @NotNull String actiondId,
      @NotNull Group mainGroup) {
    super(parentComponent, true);
    setTitle(KeyMapBundle.message("mouse.shortcut.dialog.title"));

    myKeymap = keymap;
    myActionId = actiondId;
    myMainGroup = mainGroup;

    myRbSingleClick =
        new JRadioButton(KeyMapBundle.message("mouse.shortcut.dialog.single.click.radio"));
    myRbDoubleClick =
        new JRadioButton(KeyMapBundle.message("mouse.shortcut.dialog.double.click.radio"));
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(myRbSingleClick);
    buttonGroup.add(myRbDoubleClick);

    myLblPreview = new JLabel(" ");

    myClickPad = new MyClickPad();

    myTarConflicts = new JTextArea();
    myTarConflicts.setFocusable(false);
    myTarConflicts.setEditable(false);
    myTarConflicts.setBackground(UIUtil.getPanelBackground());
    myTarConflicts.setLineWrap(true);
    myTarConflicts.setWrapStyleWord(true);

    if (shortcut != null) {
      if (shortcut.getClickCount() == 1) {
        myRbSingleClick.setSelected(true);
      } else {
        myRbDoubleClick.setSelected(true);
      }
      myButton = shortcut.getButton();
      myModifiers = shortcut.getModifiers();
    } else {
      myRbSingleClick.setSelected(true);
      myButton = -1;
      myModifiers = -1;
    }

    updatePreviewAndConflicts();

    init();
  }
Example #9
0
  public ButtonsRenderer(DefaultListModel<E> model) {
    super(new BorderLayout());
    this.model = model;
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0));
    setOpaque(true);
    label.setLineWrap(true);
    label.setOpaque(false);
    add(label);

    Box box = Box.createHorizontalBox();
    for (JButton b : Arrays.asList(deleteButton, copyButton)) {
      b.setFocusable(false);
      b.setRolloverEnabled(false);
      box.add(b);
      box.add(Box.createHorizontalStrut(5));
    }
    add(box, BorderLayout.EAST);
  }
  public ExecuteVisualizer() {
    // Set textarea properties
    jtaInstructions.setWrapStyleWord(true);
    jtaInstructions.setLineWrap(true);
    jtaInstructions.setEditable(false);

    // Set ExecuteVisualizer frame layout and add components to the frame
    setLayout(new BorderLayout(5, 10));
    add(jtaInstructions, BorderLayout.CENTER);
    add(jbtStart, BorderLayout.SOUTH);

    // Set Options frame attributes
    optionsFrame.setSize(250, 350);
    optionsFrame.setTitle("Options");
    optionsFrame.setResizable(false);
    optionsFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Set VisualizerFrame attributes
    vFrame.setSize(800, 475);
    vFrame.setTitle("Beats visualized");
    vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    vFrame.setLocationRelativeTo(null);

    // Set colorChoose frame attributes
    colorChooser.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ColorChooser newContentPane = new ColorChooser();
    newContentPane.setOpaque(true); // content panes must be opaque
    colorChooser.setContentPane(newContentPane);
    colorChooser.setResizable(false);

    // Add listener to button which will open Options, VisualizerFrame
    // and colorChoose frame, and close the current frame
    jbtStart.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            optionsFrame.setVisible(true);
            vFrame.setVisible(true);
            colorChooser.pack();
            colorChooser.setVisible(true);
            dispose();
          }
        });
  }
Example #11
0
  /**
   * Creates a new instance of ListInputPanel with initialized components.
   *
   * @param file_parser An object that can bring up a file chooser, parse selected files and append
   *     the extracted contents to this object's text area. The Load button is disabled if this is
   *     null.
   */
  public ListInputPanel(ListInputParser file_parser) {
    // Call superclass constructor
    super(new BorderLayout(4, 4));

    // Store the file parser
    this.file_parser = file_parser;

    // Initialize layout settings
    int horizontal_gap = 4;
    int vertical_gap = 4;

    // Set up the button panel and attach action listeners to the buttons
    JPanel button_panel = new JPanel(new GridLayout(1, 4));
    load_button = new JButton("Load");
    save_button = new JButton("Save");
    clear_button = new JButton("Clear");
    organize_button = new JButton("Organize");
    button_panel.add(load_button);
    button_panel.add(save_button);
    button_panel.add(clear_button);
    button_panel.add(organize_button);
    save_button.addActionListener(this);
    load_button.addActionListener(this);
    clear_button.addActionListener(this);
    organize_button.addActionListener(this);

    // Disable the load button if appropriate
    if (file_parser == null) load_button.setEnabled(false);

    // Prepare text_area
    text_area = new JTextArea();
    text_area.setLineWrap(false);
    text_area.setEditable(true);
    text_area.setText("");

    // Make scrollable
    JScrollPane scroll_pane = new JScrollPane(text_area);

    // Add contents to this JPanel
    add(button_panel, BorderLayout.NORTH);
    add(scroll_pane, BorderLayout.CENTER);
  }
Example #12
0
  public TestHTML() {
    int d = (Frame.getFrames().length == 0) ? JFrame.EXIT_ON_CLOSE : JFrame.DISPOSE_ON_CLOSE;

    JPanel pan = new JPanel();
    pan.setLayout(new BorderLayout(GAP, GAP - 4));
    pan.setBorder(new EmptyBorder(GAP, GAP, GAP, GAP));
    pan.setBackground(COL);
    pan.setFont(font);
    lab = new JLabel(MSG); // , SwingConstants.CENTER);
    lab.setName("title");
    lab.setFont(new Font("Serif", 3, 16));
    // lab.setForeground(Color.black);
    pan.add(lab, "North");

    text = new JTextArea("JTextArea\n");
    text.setName("area");
    text.setLineWrap(true);
    text.setFont(font);
    JScrollPane scr1 = new JScrollPane(text);
    scr1.setPreferredSize(new Dimension(300, 500));
    pan.add(scr1, "Center");

    html = new JEditorPane();
    html.setContentType("text/html");
    html.setEditable(false);
    html.addMouseListener(this);
    html.addMouseMotionListener(this);
    JScrollPane scr2 = new JScrollPane(html);
    scr2.setPreferredSize(new Dimension(350, 500));
    pan.add(scr2, "East");

    but = new JButton("Copy text from JTextArea to JEditorPane");
    but.addActionListener(this);
    pan.add(but, "South");

    frm = new JFrame(MSG);
    frm.setContentPane(pan);
    frm.setDefaultCloseOperation(d);
    frm.setLocation(100, 150);
    frm.pack();
    frm.setVisible(true);
  }
Example #13
0
  public GUI() {
    String[] keys = {"no Quotation found"};
    if (tryDir(".") || tryDir("BLM305") || tryDir("CSE470")) keys = Q.keySet().toArray(keys);
    menu = new JComboBox<String>(keys);
    if (Q.size() > 0) setMessage(0);

    JPanel pan = new JPanel();
    pan.setLayout(new BorderLayout(GAP, GAP - 4));
    pan.setBorder(new javax.swing.border.EmptyBorder(GAP, GAP, GAP, GAP));
    pan.setBackground(COLOR);

    pan.add(topPanel(), "North");

    txt.setFont(LARGE);
    txt.setEditable(false);
    txt.setRows(5);
    txt.setColumns(30);
    txt.setWrapStyleWord(true);
    txt.setLineWrap(true);
    txt.setDragEnabled(true);
    pan.add(new JScrollPane(txt), "Center");

    ref.setFont(SMALL);
    ref.setEditable(false);
    ref.setColumns(35);
    ref.setDragEnabled(true);
    pan.add(ref, "South");

    pan.setToolTipText("A project realized collectively by the class");
    menu.setToolTipText("Quotation classes");
    who.setToolTipText("author()+year()");
    txt.setToolTipText("text()");
    ref.setToolTipText("reference()");

    frm.setContentPane(pan);
    frm.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frm.setLocation(scaled(120), scaled(90));
    frm.pack();
    frm.setVisible(true);
  }
Example #14
0
  /** Populates the frame with UI controls. */
  private void buildUI() {
    Container cPane = getContentPane();
    cPane.setLayout(new BorderLayout());

    // Split pane for message text area and input text area
    mChatSplitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    mChatSplitter.setResizeWeight(1);
    mChatSplitter.setBorder(BorderFactory.createEmptyBorder());

    mLog = new ChatLogPanel(mColorMap);
    mChatSplitter.setTopComponent(mLog);

    mInputText = new JTextArea();
    mInputText.setLineWrap(true);
    mInputText.setWrapStyleWord(true);
    mInputText.setBorder(BorderFactory.createEmptyBorder(1, 4, 1, 4));
    mChatSplitter.setBottomComponent(new JScrollPane(mInputText));

    cPane.add(mChatSplitter, BorderLayout.CENTER);

    // Necessary for all windows, for Mac support
    AppMenuBar.applyPlatformMenuBar(this);
  }
Example #15
0
 public Converter(String title) {
   super(title);
   getContentPane().setLayout(new BorderLayout());
   initKeyPad();
   JPanel inputPanel = new JPanel();
   inputPanel.add(prompt);
   inputPanel.add(input);
   inputPanel.add(miUnit);
   inputPanel.add(kmUnit);
   unitsGroup.add(miUnit);
   unitsGroup.add(kmUnit);
   miUnit.setSelected(true);
   getContentPane().add(inputPanel, "North");
   JPanel controlPanel = new JPanel(new BorderLayout(0, 0));
   controlPanel.add(keypadPanel, "Center");
   controlPanel.add(convert, "South");
   getContentPane().add(controlPanel, "East");
   getContentPane().add(display, "Center");
   display.setLineWrap(true);
   display.setEditable(false);
   convert.addActionListener(this);
   input.addActionListener(this);
 }
Example #16
0
  public ProgressBarDemo() {
    jpb.setStringPainted(true); // Paint the percent in a string
    jpb.setValue(0);
    jpb.setMaximum(100);

    jtaResult.setWrapStyleWord(true);
    jtaResult.setLineWrap(true);

    JPanel panel = new JPanel();
    panel.add(new JLabel("Enter the prime number count"));
    panel.add(jtfPrimeCount);
    panel.add(jbtDisplayPrime);

    add(jpb, BorderLayout.NORTH);
    add(new JScrollPane(jtaResult), BorderLayout.CENTER);
    add(panel, BorderLayout.SOUTH);

    jbtDisplayPrime.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ComputePrime task =
                new ComputePrime(Integer.parseInt(jtfPrimeCount.getText()), jtaResult);

            task.addPropertyChangeListener(
                new PropertyChangeListener() {
                  public void propertyChange(PropertyChangeEvent e) {
                    if ("progress".equals(e.getPropertyName())) {
                      jpb.setValue((Integer) e.getNewValue());
                    }
                  }
                });

            task.execute(); // Execute SwingWorker
          }
        });
  }
Example #17
0
  /** Creates the GUI. */
  public void majorLayout() {
    //
    // Setup Menu
    //
    JMenuBar menuBar = new JMenuBar();
    JMenu file = new JMenu(ResourceHandler.getMessage("menu.file"));
    file.setMnemonic(ResourceHandler.getAcceleratorKey("menu.file"));

    file.add(exitMenuItem = new JMenuItem(ResourceHandler.getMessage("menu.exit")));
    exitMenuItem.setMnemonic(ResourceHandler.getAcceleratorKey("menu.exit"));
    exitMenuItem.addActionListener(this);
    menuBar.add(file);

    JMenu edit = new JMenu(ResourceHandler.getMessage("menu.edit"));
    edit.setMnemonic(ResourceHandler.getAcceleratorKey("menu.edit"));

    edit.add(optionMenuItem = new JMenuItem(ResourceHandler.getMessage("menu.option")));
    optionMenuItem.setMnemonic(ResourceHandler.getAcceleratorKey("menu.option"));
    optionMenuItem.addActionListener(this);
    menuBar.add(edit);

    JMenu help = new JMenu(ResourceHandler.getMessage("menu.help"));
    help.setMnemonic(ResourceHandler.getAcceleratorKey("menu.help"));

    help.add(helpMenuItem = new JMenuItem(ResourceHandler.getMessage("menu.help")));
    helpMenuItem.setMnemonic(ResourceHandler.getAcceleratorKey("menu.help"));

    help.add(new JSeparator());
    help.add(aboutMenuItem = new JMenuItem(ResourceHandler.getMessage("menu.about")));
    aboutMenuItem.setMnemonic(ResourceHandler.getAcceleratorKey("menu.about"));
    helpMenuItem.addActionListener(this);
    aboutMenuItem.addActionListener(this);
    menuBar.add(help);

    setJMenuBar(menuBar);

    //
    // Setup main GUI
    //

    dirLabel = new JLabel(ResourceHandler.getMessage("converter_gui.lablel0"));
    dirTF = new JTextField();
    dirBttn = new JButton(ResourceHandler.getMessage("button.browse.dir"));
    dirBttn.setMnemonic(ResourceHandler.getAcceleratorKey("button.browse.dir"));

    matchingLabel = new JLabel(ResourceHandler.getMessage("converter_gui.lablel1"));
    matchingTF = new JTextField(ResourceHandler.getMessage("converter_gui.lablel2"));
    recursiveCheckBox = new JCheckBox(ResourceHandler.getMessage("converter_gui.lablel3"));
    recursiveCheckBox.setMnemonic(ResourceHandler.getAcceleratorKey("converter_gui.lablel3"));

    backupLabel = new JLabel(ResourceHandler.getMessage("converter_gui.lablel5"));
    backupTF = new JTextField();
    backupBttn = new JButton(ResourceHandler.getMessage("button.browse.backup"));
    backupBttn.setMnemonic(ResourceHandler.getAcceleratorKey("button.browse.backup"));

    templateLabel = new JLabel(ResourceHandler.getMessage("converter_gui.lablel7"));
    templateCh = new TemplateFileChoice();

    staticVersioningLabel = new JLabel(ResourceHandler.getMessage("static.versioning.label"));
    String version = System.getProperty("java.version");
    if (version.indexOf("-") > 0) {
      version = version.substring(0, version.indexOf("-"));
    }
    int dotIndex = version.indexOf(".");
    dotIndex = version.indexOf(".", dotIndex + 1);
    String familyVersion = version.substring(0, dotIndex);

    MessageFormat formatter =
        new MessageFormat(ResourceHandler.getMessage("static.versioning.radio.button"));
    staticVersioningRadioButton = new JRadioButton(formatter.format(new Object[] {version}));
    staticVersioningRadioButton.setMnemonic(
        ResourceHandler.getAcceleratorKey("static.versioning.radio.button"));

    formatter = new MessageFormat(ResourceHandler.getMessage("dynamic.versioning.radio.button"));
    dynamicVersioningRadioButton = new JRadioButton(formatter.format(new Object[] {familyVersion}));
    dynamicVersioningRadioButton.setMnemonic(
        ResourceHandler.getAcceleratorKey("dynamic.versioning.radio.button"));

    staticVersioningTextArea = new JTextArea(ResourceHandler.getMessage("static.versioning.text"));

    formatter = new MessageFormat(ResourceHandler.getMessage("dynamic.versioning.text"));
    dynamicVersioningTextArea = new JTextArea(formatter.format(new Object[] {familyVersion}));

    ButtonGroup versioningButtonGroup = new ButtonGroup();
    versioningButtonGroup.add(staticVersioningRadioButton);
    versioningButtonGroup.add(dynamicVersioningRadioButton);

    runBttn = new JButton(ResourceHandler.getMessage("button.convert"));
    runBttn.setMnemonic(ResourceHandler.getAcceleratorKey("button.convert"));

    recursiveCheckBox.setOpaque(false);
    staticVersioningRadioButton.setOpaque(false);
    dynamicVersioningRadioButton.setOpaque(false);

    staticVersioningTextArea.setEditable(false);
    staticVersioningTextArea.setLineWrap(true);
    staticVersioningTextArea.setWrapStyleWord(true);
    dynamicVersioningTextArea.setEditable(false);
    dynamicVersioningTextArea.setLineWrap(true);
    dynamicVersioningTextArea.setWrapStyleWord(true);

    staticVersioningPanel.setLayout(new BorderLayout());
    staticVersioningPanel.add(staticVersioningTextArea, "Center");
    staticVersioningPanel.setBorder(new LineBorder(Color.black));

    dynamicVersioningPanel.setLayout(new BorderLayout());
    dynamicVersioningPanel.add(dynamicVersioningTextArea, "Center");
    dynamicVersioningPanel.setBorder(new LineBorder(Color.black));

    if (converter.isStaticVersioning()) {
      staticVersioningRadioButton.setSelected(true);
    } else {
      dynamicVersioningRadioButton.setSelected(true);
    }

    addListeners();

    final int buf = 10, // Buffer (between components and form)
        sp = 10, // Space between components
        vsp = 5, // Vertical space
        indent = 20; // Indent between form (left edge) and component

    GridBagConstraints gbc = new GridBagConstraints();
    GridBagLayout gbl = new GridBagLayout();
    getContentPane().setLayout(gbl);

    //
    // Setup top panel
    //
    GridBagLayout topLayout = new GridBagLayout();
    JPanel topPanel = new JPanel();
    topPanel.setOpaque(false);
    topPanel.setLayout(topLayout);

    topLayout.setConstraints(
        dirLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(10, 0, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        dirTF,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            1,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(vsp, 2, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        dirBttn,
        new GridBagConstraints(
            2,
            0,
            1,
            1,
            0,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(10, sp, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        matchingLabel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(10, 0, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        matchingTF,
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            1,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(vsp, 2, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        recursiveCheckBox,
        new GridBagConstraints(
            2,
            1,
            GridBagConstraints.REMAINDER,
            1,
            1,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(vsp, 10, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        backupLabel,
        new GridBagConstraints(
            0,
            3,
            1,
            1,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(10, 0, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        backupTF,
        new GridBagConstraints(
            1,
            3,
            1,
            1,
            1,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(vsp, 2, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        backupBttn,
        new GridBagConstraints(
            2,
            3,
            1,
            1,
            0,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(10, sp, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        templateLabel,
        new GridBagConstraints(
            0,
            4,
            1,
            1,
            0,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(10, 0, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        templateCh,
        new GridBagConstraints(
            1,
            4,
            1,
            1,
            0,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(vsp, 2, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        sep1,
        new GridBagConstraints(
            0,
            5,
            GridBagConstraints.REMAINDER,
            1,
            1,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(10, 10, 10, 10),
            0,
            0));
    topLayout.setConstraints(
        staticVersioningLabel,
        new GridBagConstraints(
            0,
            6,
            1,
            1,
            0,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(10, 0, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        staticVersioningRadioButton,
        new GridBagConstraints(
            0,
            7,
            GridBagConstraints.REMAINDER,
            1,
            1,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(vsp, 10, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        staticVersioningPanel,
        new GridBagConstraints(
            0,
            8,
            GridBagConstraints.REMAINDER,
            1,
            0,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(vsp, 25, 10, 0),
            0,
            0));
    topLayout.setConstraints(
        dynamicVersioningRadioButton,
        new GridBagConstraints(
            0,
            9,
            GridBagConstraints.REMAINDER,
            1,
            1,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(vsp, 10, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        dynamicVersioningPanel,
        new GridBagConstraints(
            0,
            10,
            GridBagConstraints.REMAINDER,
            1,
            0,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(vsp, 25, 0, 0),
            0,
            0));
    topLayout.setConstraints(
        sep2,
        new GridBagConstraints(
            0,
            11,
            GridBagConstraints.REMAINDER,
            1,
            1,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(10, 10, 0, 10),
            0,
            0));

    invisibleBttn = new JButton();
    invisibleBttn.setVisible(false);
    topLayout.setConstraints(
        invisibleBttn,
        new GridBagConstraints(
            2,
            6,
            1,
            1,
            0,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.CENTER,
            new Insets(indent, sp, 0, 0),
            0,
            0));

    topPanel.add(dirLabel);
    topPanel.add(dirTF);
    topPanel.add(dirBttn);
    topPanel.add(matchingLabel);
    topPanel.add(matchingTF);
    topPanel.add(recursiveCheckBox);
    topPanel.add(backupLabel);
    topPanel.add(backupTF);
    topPanel.add(backupBttn);
    topPanel.add(templateLabel);
    topPanel.add(templateCh);
    topPanel.add(sep1);
    topPanel.add(staticVersioningLabel);
    topPanel.add(staticVersioningRadioButton);
    topPanel.add(staticVersioningPanel);
    topPanel.add(dynamicVersioningRadioButton);
    topPanel.add(dynamicVersioningPanel);
    topPanel.add(sep2);
    topPanel.add(invisibleBttn);

    //
    // Setup bottom panel
    //
    GridBagLayout buttomLayout = new GridBagLayout();
    JPanel buttomPanel = new JPanel();
    buttomPanel.setOpaque(false);
    buttomPanel.setLayout(buttomLayout);

    buttomLayout.setConstraints(
        runBttn,
        new GridBagConstraints(
            3,
            0,
            1,
            1,
            0,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(sp, 0, 0, 0),
            0,
            0));
    buttomPanel.add(runBttn);

    //
    // Setup main panel
    //
    GridBagLayout mainLayout = new GridBagLayout();
    JPanel mainPanel = new JPanel();

    mainPanel.setOpaque(false);
    mainPanel.setLayout(mainLayout);

    mainLayout.setConstraints(
        topPanel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(buf, buf, 0, buf),
            0,
            0));
    mainLayout.setConstraints(
        buttomPanel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1,
            1,
            GridBagConstraints.SOUTH,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, buf, buf, buf),
            0,
            0));
    mainPanel.add(topPanel);
    mainPanel.add(buttomPanel);

    Border border = BorderFactory.createEtchedBorder();
    mainPanel.setBorder(border);

    GridBagLayout layout = new GridBagLayout();
    getContentPane().setLayout(layout);

    layout.setConstraints(
        mainPanel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1,
            1,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));

    getContentPane().add(mainPanel);

    pack();
    setResizable(false);
  }
Example #18
0
  public PartitionModelPanel(final PartitionSubstitutionModel partitionModel) {

    super(12, (OSType.isMac() ? 6 : 24));

    this.model = partitionModel;

    initCodonPartitionComponents();

    PanelUtils.setupComponent(nucSubstCombo);
    nucSubstCombo.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            model.setNucSubstitutionModel((NucModelType) nucSubstCombo.getSelectedItem());
          }
        });
    nucSubstCombo.setToolTipText("<html>Select the type of nucleotide substitution model.</html>");

    PanelUtils.setupComponent(aaSubstCombo);
    aaSubstCombo.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            AminoAcidModelType type = (AminoAcidModelType) aaSubstCombo.getSelectedItem();
            model.setAaSubstitutionModel(type);
            citationText.setText(type.getCitation().toString());
          }
        });
    aaSubstCombo.setToolTipText("<html>Select the type of amino acid substitution model.</html>");

    PanelUtils.setupComponent(binarySubstCombo);
    binarySubstCombo.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            model.setBinarySubstitutionModel((BinaryModelType) binarySubstCombo.getSelectedItem());
            useAmbiguitiesTreeLikelihoodCheck.setSelected(
                binarySubstCombo.getSelectedItem() == BinaryModelType.BIN_COVARION);
            useAmbiguitiesTreeLikelihoodCheck.setEnabled(
                binarySubstCombo.getSelectedItem() != BinaryModelType.BIN_COVARION);
          }
        });
    binarySubstCombo.setToolTipText("<html>Select the type of binary substitution model.</html>");

    PanelUtils.setupComponent(useAmbiguitiesTreeLikelihoodCheck);
    useAmbiguitiesTreeLikelihoodCheck.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            model.setUseAmbiguitiesTreeLikelihood(useAmbiguitiesTreeLikelihoodCheck.isSelected());
          }
        });
    useAmbiguitiesTreeLikelihoodCheck.setToolTipText(
        "<html>Detemine useAmbiguities in &lt treeLikelihood &gt .</html>");

    PanelUtils.setupComponent(frequencyCombo);
    frequencyCombo.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            model.setFrequencyPolicy((FrequencyPolicyType) frequencyCombo.getSelectedItem());
          }
        });
    frequencyCombo.setToolTipText(
        "<html>Select the policy for determining the base frequencies.</html>");

    PanelUtils.setupComponent(heteroCombo);
    heteroCombo.setToolTipText(
        "<html>Select the type of site-specific rate<br>heterogeneity model.</html>");
    heteroCombo.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {

            boolean gammaHetero =
                heteroCombo.getSelectedIndex() == 1 || heteroCombo.getSelectedIndex() == 3;

            model.setGammaHetero(gammaHetero);
            model.setInvarHetero(
                heteroCombo.getSelectedIndex() == 2 || heteroCombo.getSelectedIndex() == 3);

            if (gammaHetero) {
              gammaCatLabel.setEnabled(true);
              gammaCatCombo.setEnabled(true);
            } else {
              gammaCatLabel.setEnabled(false);
              gammaCatCombo.setEnabled(false);
            }

            if (codingCombo.getSelectedIndex() != 0) {
              heteroUnlinkCheck.setEnabled(heteroCombo.getSelectedIndex() != 0);
              heteroUnlinkCheck.setSelected(heteroCombo.getSelectedIndex() != 0);
            }
          }
        });

    PanelUtils.setupComponent(gammaCatCombo);
    gammaCatCombo.setToolTipText(
        "<html>Select the number of categories to use for<br>the discrete gamma rate heterogeneity model.</html>");
    gammaCatCombo.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {

            model.setGammaCategories(gammaCatCombo.getSelectedIndex() + 4);
          }
        });

    setYang96Button = new JButton("Use Yang96 model");
    setYang96Button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ev) {
            setYang96Model();
          }
        });
    PanelUtils.setupComponent(setYang96Button);
    setYang96Button.setToolTipText(
        "<html>Sets a 3 codon-position model with independent GTR and Gamma as described in<br>"
            + "Yang (1996) <i>J Mol Evol</i> <b>42</b>: 587–596. This model is named 3' in this paper.</html>");

    setSRD06Button = new JButton("Use SRD06 model");
    setSRD06Button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ev) {
            setSRD06Model();
          }
        });
    PanelUtils.setupComponent(setSRD06Button);
    setSRD06Button.setToolTipText(
        "<html>Sets the SRD06 model as described in<br>"
            + "Shapiro, Rambaut & Drummond (2006) <i>MBE</i> <b>23</b>: 7-9.</html>");

    citationText = new JTextArea(1, 40);
    citationText.setLineWrap(true);
    citationText.setWrapStyleWord(true);
    citationText.setEditable(false);
    citationText.setFont(this.getFont());
    citationText.setOpaque(false);
    AminoAcidModelType type = (AminoAcidModelType) aaSubstCombo.getSelectedItem();
    citationText.setText(type.getCitation().toString());

    dolloCheck.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            if (dolloCheck.isSelected()) {
              binarySubstCombo.setSelectedIndex(0);
              binarySubstCombo.setEnabled(false);
              useAmbiguitiesTreeLikelihoodCheck.setSelected(true);
              useAmbiguitiesTreeLikelihoodCheck.setEnabled(false);
              frequencyCombo.setEnabled(false);
              frequencyCombo.setSelectedItem(FrequencyPolicyType.EMPIRICAL);
              heteroCombo.setSelectedIndex(0);
              heteroCombo.setEnabled(false);
              model.setBinarySubstitutionModel(BinaryModelType.BIN_DOLLO);
              model.setDolloModel(true);
              DolloComponentOptions comp =
                  (DolloComponentOptions)
                      model.getOptions().getComponentOptions(DolloComponentOptions.class);
              comp.createParameters(model.getOptions());
              comp.setActive(true);

            } else {
              binarySubstCombo.setEnabled(true);
              useAmbiguitiesTreeLikelihoodCheck.setEnabled(true);
              frequencyCombo.setEnabled(true);
              heteroCombo.setEnabled(true);
              model.setBinarySubstitutionModel(
                  (BinaryModelType) binarySubstCombo.getSelectedItem());
              model.setDolloModel(false);
            }
          }
        });

    PanelUtils.setupComponent(dolloCheck);
    //        dolloCheck.addChangeListener(new ChangeListener() {
    //            public void stateChanged(ChangeEvent e) {
    //                model.setDolloModel(true);
    //            }
    //        });
    dolloCheck.setEnabled(true);
    dolloCheck.setToolTipText(
        "<html>Activates a Stochastic Dollo model as described in<br>"
            + "Alekseyenko, Lee & Suchard (2008) <i>Syst Biol</i> <b>57</b>: 772-784.</html>");

    PanelUtils.setupComponent(discreteTraitSiteModelCombo);
    discreteTraitSiteModelCombo.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            model.setDiscreteSubstType(
                (DiscreteSubstModelType) discreteTraitSiteModelCombo.getSelectedItem());
          }
        });

    PanelUtils.setupComponent(continuousTraitSiteModelCombo);
    continuousTraitSiteModelCombo.setToolTipText(
        "<html>Select the model of continuous random walk, either homogenous<br>"
            + "or relaxed random walk (RRW) with a choice of distributions.</html>");
    continuousTraitSiteModelCombo.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            model.setContinuousSubstModelType(
                (ContinuousSubstModelType) continuousTraitSiteModelCombo.getSelectedItem());
          }
        });

    PanelUtils.setupComponent(latLongCheck);
    latLongCheck.setToolTipText(
        "<html>Specify whether this is a geographical trait representing <br>"
            + "latitude and longitude. Provides appropriate statistics to log file.</html>");

    latLongCheck.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            model.setIsLatitudeLongitude(latLongCheck.isSelected());
          }
        });
    latLongCheck.setEnabled(false);

    PanelUtils.setupComponent(useLambdaCheck);
    useLambdaCheck.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            ContinuousComponentOptions component =
                (ContinuousComponentOptions)
                    model.getOptions().getComponentOptions(ContinuousComponentOptions.class);
            component.setUseLambda(model, useLambdaCheck.isSelected());
          }
        });
    useLambdaCheck.setToolTipText(
        "<html>Estimate degree of phylogenetic correlation in continuous traits using <br>"
            + "a tree transform. Inspired by Pagel (1999), described in Lemey et al (2013) <i>in prep</i></html>");

    PanelUtils.setupComponent(activateBSSVS);
    activateBSSVS.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            model.setActivateBSSVS(activateBSSVS.isSelected());
          }
        });
    activateBSSVS.setToolTipText(
        "<html>Activates Bayesian stochastic search variable selection on the rates as described in<br>"
            + "Lemey, Rambaut, Drummond & Suchard (2009) <i>PLoS Computational Biology</i> <b>5</b>: e1000520</html>");

    // ============ micro-sat ================
    microsatName.setColumns(30);
    microsatName.addKeyListener(
        new java.awt.event.KeyListener() {
          public void keyTyped(KeyEvent e) {}

          public void keyPressed(KeyEvent e) {}

          public void keyReleased(KeyEvent e) {
            model.getMicrosatellite().setName(microsatName.getText());
          }
        });
    microsatMax.setColumns(10);
    microsatMax.addKeyListener(
        new java.awt.event.KeyListener() {
          public void keyTyped(KeyEvent e) {}

          public void keyPressed(KeyEvent e) {}

          public void keyReleased(KeyEvent e) {
            model.getMicrosatellite().setMax(Integer.parseInt(microsatMax.getText()));
          }
        });
    microsatMin.setColumns(10);
    microsatMin.addKeyListener(
        new java.awt.event.KeyListener() {
          public void keyTyped(KeyEvent e) {}

          public void keyPressed(KeyEvent e) {}

          public void keyReleased(KeyEvent e) {
            model.getMicrosatellite().setMin(Integer.parseInt(microsatMin.getText()));
          }
        });

    PanelUtils.setupComponent(shareMicroSatCheck);
    shareMicroSatCheck.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            model.getOptions().shareMicroSat = shareMicroSatCheck.isSelected();
            if (shareMicroSatCheck.isSelected()) {
              model.getOptions().shareMicroSat();
            } else {
              model.getOptions().unshareMicroSat();
            }
            setOptions();
          }
        });

    PanelUtils.setupComponent(rateProportionCombo);
    rateProportionCombo.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            model.setRatePorportion(
                (MicroSatModelType.RateProportionality) rateProportionCombo.getSelectedItem());
          }
        });
    // rateProportionCombo.setToolTipText("<html>Select the type of microsatellite substitution
    // model.</html>");
    PanelUtils.setupComponent(mutationBiasCombo);
    mutationBiasCombo.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            model.setMutationBias(
                (MicroSatModelType.MutationalBias) mutationBiasCombo.getSelectedItem());
          }
        });
    PanelUtils.setupComponent(phaseCombo);
    phaseCombo.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent ev) {
            model.setPhase((MicroSatModelType.Phase) phaseCombo.getSelectedItem());
          }
        });

    setupPanel();
    setOpaque(false);
  }
  private void jbInit() throws Exception {
    titledBorder1 = new TitledBorder("");
    this.setLayout(baseLayout);

    double[][] lower_size = {
      {TableLayout.PREFERRED, TableLayout.FILL, 25}, {25, 25, TableLayout.FILL}
    };
    mLowerPanelLayout = new TableLayout(lower_size);

    mLowerPanel.setLayout(mLowerPanelLayout);

    double[][] dir_size = {
      {TableLayout.FILL, TableLayout.PREFERRED}, {TableLayout.PREFERRED, TableLayout.FILL}
    };
    mDirectionsPanelLayout = new TableLayout(dir_size);
    mDirectionsPanel.setLayout(mDirectionsPanelLayout);

    // Try to get icons for the toolbar buttons
    try {
      ClassLoader loader = getClass().getClassLoader();
      mAddIcon = new ImageIcon(loader.getResource(COMMON_IMG_ROOT + "/add.gif"));
      mRemoveIcon = new ImageIcon(loader.getResource(COMMON_IMG_ROOT + "/remove.gif"));
      mDisabledRemoveIcon =
          new ImageIcon(loader.getResource(COMMON_IMG_ROOT + "/remove_disabled.gif"));

      mAddNodeBtn.setIcon(mAddIcon);
      mRemoveNodeBtn.setIcon(mRemoveIcon);
      mRemoveNodeBtn.setDisabledIcon(mDisabledRemoveIcon);
    } catch (Exception e) {
      // Ack! No icons. Use text labels instead
      mAddNodeBtn.setText("Add");
      mRemoveNodeBtn.setText("Remove");
    }

    /*
    mAddNodeBtn.setMaximumSize(new Dimension(130, 33));
    mAddNodeBtn.setMinimumSize(new Dimension(130, 33));
    mAddNodeBtn.setPreferredSize(new Dimension(130, 33));
    mAddNodeBtn.setText("Add Node");
    */
    mAddNodeBtn.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            mAddNodeBtn_actionPerformed(e);
          }
        });
    /*
    mRemoveNodeBtn.setMaximumSize(new Dimension(130, 33));
    mRemoveNodeBtn.setMinimumSize(new Dimension(130, 33));
    mRemoveNodeBtn.setPreferredSize(new Dimension(130, 33));
    mRemoveNodeBtn.setText("Remove Node");
    */
    mRemoveNodeBtn.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            mRemoveNode();
          }
        });
    mHostnameLabel.setHorizontalAlignment(SwingConstants.TRAILING);
    mHostnameLabel.setLabelFor(mHostnameField);
    mHostnameLabel.setText("Hostname:");

    mHostnameField.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            mAddNodeBtn_actionPerformed(e);
          }
        });
    mDirectionsPanel.setBorder(BorderFactory.createEtchedBorder());
    mTitleLabel.setFont(new java.awt.Font("Serif", 1, 20));
    mTitleLabel.setHorizontalAlignment(SwingConstants.CENTER);
    mTitleLabel.setText("Add Cluster Nodes");
    mDirectionsLabel.setText("Click on the add button to add nodes to your cluster configuration.");
    mDirectionsLabel.setLineWrap(true);
    mDirectionsLabel.setEditable(false);
    mDirectionsLabel.setBackground(mTitleLabel.getBackground());

    baseLayout.setHgap(5);
    baseLayout.setVgap(5);
    mLowerPanel.add(
        mHostnameLabel, new TableLayoutConstraints(0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL));
    mLowerPanel.add(
        mHostnameField, new TableLayoutConstraints(1, 0, 1, 0, TableLayout.FULL, TableLayout.FULL));
    mLowerPanel.add(
        mListScrollPane1,
        new TableLayoutConstraints(0, 1, 1, 2, TableLayout.FULL, TableLayout.FULL));
    mLowerPanel.add(
        mAddNodeBtn, new TableLayoutConstraints(2, 0, 2, 0, TableLayout.FULL, TableLayout.FULL));
    mLowerPanel.add(
        mRemoveNodeBtn, new TableLayoutConstraints(2, 1, 2, 1, TableLayout.FULL, TableLayout.FULL));
    this.add(mLowerPanel, BorderLayout.CENTER);
    mListScrollPane1.getViewport().add(lstNodes, null);
    mDirectionsPanel.add(
        mTitleLabel, new TableLayoutConstraints(0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL));
    mDirectionsPanel.add(
        mDirectionsLabel,
        new TableLayoutConstraints(0, 1, 0, 1, TableLayout.FULL, TableLayout.FULL));
    mDirectionsPanel.add(
        mIconLabel, new TableLayoutConstraints(1, 0, 1, 1, TableLayout.FULL, TableLayout.FULL));
    this.add(mDirectionsPanel, BorderLayout.NORTH);
  }
  /** Initializes the <tt>NewStatusMessageDialog</tt> by adding the buttons, fields, etc. */
  private void init() {
    JLabel messageLabel =
        new JLabel(GuiActivator.getResources().getI18NString("service.gui.NEW_STATUS_MESSAGE"));

    JPanel dataPanel = new TransparentPanel(new BorderLayout(5, 5));

    JTextArea infoArea =
        new JTextArea(GuiActivator.getResources().getI18NString("service.gui.STATUS_MESSAGE_INFO"));

    JLabel infoTitleLabel =
        new JLabel(GuiActivator.getResources().getI18NString("service.gui.NEW_STATUS_MESSAGE"));

    JPanel labelsPanel = new TransparentPanel(new GridLayout(0, 1));

    JButton okButton = new JButton(GuiActivator.getResources().getI18NString("service.gui.OK"));

    JPanel buttonsPanel = new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));

    this.setTitle(GuiActivator.getResources().getI18NString("service.gui.NEW_STATUS_MESSAGE"));

    this.getRootPane().setDefaultButton(okButton);

    this.setPreferredSize(new Dimension(500, 200));

    infoArea.setEditable(false);
    infoArea.setLineWrap(true);
    infoArea.setWrapStyleWord(true);
    infoArea.setOpaque(false);

    dataPanel.add(messageLabel, BorderLayout.WEST);

    messageTextField.setText(presenceOpSet.getCurrentStatusMessage());
    dataPanel.add(messageTextField, BorderLayout.CENTER);

    infoTitleLabel.setHorizontalAlignment(JLabel.CENTER);
    infoTitleLabel.setFont(infoTitleLabel.getFont().deriveFont(Font.BOLD, 18.0f));

    labelsPanel.add(infoTitleLabel);
    labelsPanel.add(infoArea);
    labelsPanel.add(dataPanel);

    messagePanel = new TransparentPanel(new GridBagLayout());
    GridBagConstraints messagePanelConstraints = new GridBagConstraints();
    messagePanelConstraints.anchor = GridBagConstraints.NORTHWEST;
    messagePanelConstraints.fill = GridBagConstraints.NONE;
    messagePanelConstraints.gridx = 0;
    messagePanelConstraints.gridy = 0;
    messagePanelConstraints.insets = new Insets(5, 0, 5, 10);
    messagePanelConstraints.weightx = 0;
    messagePanelConstraints.weighty = 0;
    messagePanel.add(
        new ImageCanvas(ImageLoader.getImage(ImageLoader.RENAME_DIALOG_ICON)),
        messagePanelConstraints);

    messagePanelConstraints.anchor = GridBagConstraints.NORTH;
    messagePanelConstraints.fill = GridBagConstraints.HORIZONTAL;
    messagePanelConstraints.gridx = 1;
    messagePanelConstraints.insets = new Insets(0, 0, 0, 0);
    messagePanelConstraints.weightx = 1;
    messagePanel.add(labelsPanel, messagePanelConstraints);

    okButton.setName("ok");
    cancelButton.setName("cancel");

    okButton.setMnemonic(GuiActivator.getResources().getI18nMnemonic("service.gui.OK"));
    cancelButton.setMnemonic(GuiActivator.getResources().getI18nMnemonic("service.gui.CANCEL"));

    okButton.addActionListener(this);
    cancelButton.addActionListener(this);

    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);

    JPanel mainPanel = new TransparentPanel(new GridBagLayout());
    mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 10));

    GridBagConstraints mainPanelConstraints = new GridBagConstraints();
    mainPanelConstraints.anchor = GridBagConstraints.NORTH;
    mainPanelConstraints.fill = GridBagConstraints.BOTH;
    mainPanelConstraints.gridx = 0;
    mainPanelConstraints.gridy = 0;
    mainPanelConstraints.weightx = 1;
    mainPanelConstraints.weighty = 1;
    mainPanel.add(messagePanel, mainPanelConstraints);

    mainPanelConstraints.anchor = GridBagConstraints.SOUTHEAST;
    mainPanelConstraints.fill = GridBagConstraints.NONE;
    mainPanelConstraints.gridy = 1;
    mainPanelConstraints.weightx = 0;
    mainPanelConstraints.weighty = 0;
    mainPanel.add(buttonsPanel, mainPanelConstraints);

    this.getContentPane().add(mainPanel);
  }
Example #21
0
  private void createUI() {

    setTitle(strings.getString("window.title"));

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    mailBodyArea = new JTextArea(20, 70);
    mailBodyArea.setLineWrap(true);
    mailBodyArea.setWrapStyleWord(true);
    mailBodyArea.setFont(new Font("monospaced", Font.PLAIN, 12));

    scrollPane = new JScrollPane(mailBodyArea);

    mailSubjectField = new JTextField(20);
    mailToField = new JTextField(20);
    mailFromField = new JTextField(20);

    mailSubjectLabel = new JLabel(strings.getString("subject.label"));
    mailToLabel = new JLabel(strings.getString("to.label"));
    setToFieldEditable(false);

    toLabelListener =
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            mouseClicked_searchSource();
          }

          public void mouseEntered(MouseEvent e) {
            setCursor(new Cursor(Cursor.HAND_CURSOR));
          }

          public void mouseExited(MouseEvent e) {
            setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
          }
        };

    mailFromLabel = new JLabel(strings.getString("from.label"));

    sendMailButton = new JButton(strings.getString("sendmail.text"));
    sendMailButton.setIcon(
        new ImageIcon(getClass().getResource(strings.getString("sendmail.icon"))));
    sendMailButton.setToolTipText(strings.getString("sendmail.tooltip"));
    cancelButton = new JButton(strings.getString("cancel.text"));
    cancelButton.setIcon(new ImageIcon(getClass().getResource(strings.getString("cancel.icon"))));
    cancelButton.setToolTipText(strings.getString("cancel.tooltip"));

    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            actionPerformed_cancel();
          }
        });

    sendMailButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            actionPerformed_sendMail();
          }
        });

    Container pane = this.getContentPane();

    container.setLayout(gridbag);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(5, 5, 0, 5);
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.EAST;
    pane.add(mailFromLabel, c);
    c.gridx = 1;
    pane.add(mailFromField, c);

    c.gridx = 0;
    c.gridy = 1;
    pane.add(mailToLabel, c);
    c.gridx = 1;
    pane.add(mailToField, c);

    c.gridx = 0;
    c.gridy = 2;
    pane.add(mailSubjectLabel, c);
    c.gridx = 1;
    pane.add(mailSubjectField, c);

    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = 2;
    pane.add(scrollPane, c);

    JPanel bPane = new JPanel();
    bPane.add(sendMailButton);
    bPane.add(cancelButton);

    c.gridx = 0;
    c.gridy = 4;
    pane.add(bPane, c);

    mailToField.requestFocus();
  }
  /** Construct a new dialog. */
  public JExecDetailsDialog() {
    super("Execution Details");

    /* create dialog body components */
    {
      JPanel body = new JPanel();
      body.setLayout(new BoxLayout(body, BoxLayout.Y_AXIS));

      {
        JPanel panel = new JPanel();
        panel.setName("MainDialogPanel");
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

        /* working directory */
        {
          panel.add(UIFactory.createPanelLabel("Working Directory:"));

          panel.add(Box.createRigidArea(new Dimension(0, 4)));

          JTextField field = UIFactory.createTextField(null, 100, JLabel.LEFT);
          pWorkingDirField = field;

          panel.add(field);
        }

        body.add(panel);
      }

      {
        JPanel panel = new JPanel();
        panel.setName("HorizontalBar");

        Dimension size = new Dimension(100, 7);
        panel.setPreferredSize(size);
        panel.setMinimumSize(size);
        panel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 7));

        body.add(panel);
      }

      /* command line */
      JPanel above = new JPanel();
      {
        above.setName("MainDialogPanel");
        above.setLayout(new BoxLayout(above, BoxLayout.Y_AXIS));

        {
          Box hbox = new Box(BoxLayout.X_AXIS);

          hbox.add(Box.createRigidArea(new Dimension(4, 0)));

          {
            JLabel label = new JLabel("X");
            pCommandLineLabel = label;

            label.setName("PanelLabel");

            hbox.add(label);
          }

          hbox.add(Box.createHorizontalGlue());

          above.add(hbox);
        }

        above.add(Box.createRigidArea(new Dimension(0, 4)));

        {
          JTextArea area = new JTextArea(null, 5, 70);
          pCommandLineArea = area;

          area.setName("CodeTextArea");
          area.setLineWrap(true);
          area.setWrapStyleWord(true);
          area.setEditable(false);
        }

        {
          JScrollPane scroll =
              UIFactory.createScrollPane(
                  pCommandLineArea,
                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER,
                  ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                  new Dimension(100, 27),
                  null,
                  null);

          above.add(scroll);
        }
      }

      /* environment */
      JPanel below = new JPanel();
      {
        below.setName("MainDialogPanel");
        below.setLayout(new BoxLayout(below, BoxLayout.Y_AXIS));

        {
          Box hbox = new Box(BoxLayout.X_AXIS);

          hbox.add(Box.createRigidArea(new Dimension(4, 0)));

          {
            JLabel label = new JLabel("X");
            pEnvLabel = label;

            label.setName("PanelLabel");

            hbox.add(label);
          }

          hbox.add(Box.createHorizontalGlue());

          below.add(hbox);
        }

        below.add(Box.createRigidArea(new Dimension(0, 4)));

        Component comps[] = UIFactory.createTitledPanels();
        {
          JPanel tpanel = (JPanel) comps[0];
          JPanel vpanel = (JPanel) comps[1];

          tpanel.add(Box.createRigidArea(new Dimension(sTSize, 0)));
          vpanel.add(Box.createHorizontalGlue());
        }

        {
          pEnvScroll =
              UIFactory.createScrollPane(
                  comps[2],
                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER,
                  ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                  new Dimension(100, 50),
                  new Dimension(100, 300),
                  null);

          below.add(pEnvScroll);
        }
      }

      {
        JVertSplitPanel split = new JVertSplitPanel(above, below);
        split.setResizeWeight(0.0);
        split.setAlignmentX(0.5f);

        body.add(split);
      }

      super.initUI("X", body, null, null, null, "Close", null);
    }
  }
  /** Constructs the <tt>LoginWindow</tt>. */
  private void init() {
    String title;

    if (windowTitle != null) title = windowTitle;
    else
      title =
          DesktopUtilActivator.getResources()
              .getI18NString("service.gui.AUTHENTICATION_WINDOW_TITLE", new String[] {server});

    String text;
    if (windowText != null) text = windowText;
    else
      text =
          DesktopUtilActivator.getResources()
              .getI18NString("service.gui.AUTHENTICATION_REQUESTED_SERVER", new String[] {server});

    String uinText;
    if (usernameLabelText != null) uinText = usernameLabelText;
    else uinText = DesktopUtilActivator.getResources().getI18NString("service.gui.IDENTIFIER");

    String passText;
    if (passwordLabelText != null) passText = passwordLabelText;
    else passText = DesktopUtilActivator.getResources().getI18NString("service.gui.PASSWORD");

    setTitle(title);

    infoTextArea.setEditable(false);
    infoTextArea.setOpaque(false);
    infoTextArea.setLineWrap(true);
    infoTextArea.setWrapStyleWord(true);
    infoTextArea.setFont(infoTextArea.getFont().deriveFont(Font.BOLD));
    infoTextArea.setText(text);
    infoTextArea.setAlignmentX(0.5f);

    JLabel uinLabel = new JLabel(uinText);
    uinLabel.setFont(uinLabel.getFont().deriveFont(Font.BOLD));

    JLabel passwdLabel = new JLabel(passText);
    passwdLabel.setFont(passwdLabel.getFont().deriveFont(Font.BOLD));

    TransparentPanel labelsPanel = new TransparentPanel(new GridLayout(0, 1, 8, 8));

    labelsPanel.add(uinLabel);
    labelsPanel.add(passwdLabel);

    TransparentPanel textFieldsPanel = new TransparentPanel(new GridLayout(0, 1, 8, 8));

    textFieldsPanel.add(uinValue);
    textFieldsPanel.add(passwdField);

    JPanel southFieldsPanel = new TransparentPanel(new GridLayout(1, 2));

    this.rememberPassCheckBox.setOpaque(false);
    this.rememberPassCheckBox.setBorder(null);

    southFieldsPanel.add(rememberPassCheckBox);
    if (signupLink != null && signupLink.length() > 0)
      southFieldsPanel.add(
          createWebSignupLabel(
              DesktopUtilActivator.getResources().getI18NString("plugin.simpleaccregwizz.SIGNUP"),
              signupLink));
    else southFieldsPanel.add(new JLabel());

    boolean allowRememberPassword = true;

    String allowRemPassStr =
        DesktopUtilActivator.getResources().getSettingsString(PNAME_ALLOW_SAVE_PASSWORD);
    if (allowRemPassStr != null) {
      allowRememberPassword = Boolean.parseBoolean(allowRemPassStr);
    }
    allowRememberPassword =
        DesktopUtilActivator.getConfigurationService()
            .getBoolean(PNAME_ALLOW_SAVE_PASSWORD, allowRememberPassword);

    setAllowSavePassword(allowRememberPassword);

    JPanel buttonPanel = new TransparentPanel(new FlowLayout(FlowLayout.CENTER));

    buttonPanel.add(loginButton);
    buttonPanel.add(cancelButton);

    JPanel southEastPanel = new TransparentPanel(new BorderLayout());
    southEastPanel.add(buttonPanel, BorderLayout.EAST);

    TransparentPanel mainPanel = new TransparentPanel(new BorderLayout(10, 10));

    mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 20));

    JPanel mainFieldsPanel = new TransparentPanel(new BorderLayout(0, 10));
    mainFieldsPanel.add(labelsPanel, BorderLayout.WEST);
    mainFieldsPanel.add(textFieldsPanel, BorderLayout.CENTER);
    mainFieldsPanel.add(southFieldsPanel, BorderLayout.SOUTH);

    mainPanel.add(infoTextArea, BorderLayout.NORTH);
    mainPanel.add(mainFieldsPanel, BorderLayout.CENTER);
    mainPanel.add(southEastPanel, BorderLayout.SOUTH);

    this.getContentPane().add(mainPanel, BorderLayout.EAST);

    this.loginButton.setName("ok");
    this.cancelButton.setName("cancel");
    if (loginButton.getPreferredSize().width > cancelButton.getPreferredSize().width)
      cancelButton.setPreferredSize(loginButton.getPreferredSize());
    else loginButton.setPreferredSize(cancelButton.getPreferredSize());

    this.loginButton.setMnemonic(
        DesktopUtilActivator.getResources().getI18nMnemonic("service.gui.OK"));
    this.cancelButton.setMnemonic(
        DesktopUtilActivator.getResources().getI18nMnemonic("service.gui.CANCEL"));

    this.loginButton.addActionListener(this);
    this.cancelButton.addActionListener(this);

    this.getRootPane().setDefaultButton(loginButton);
  }
 // Create the JTextComponent subclass.
 protected JTextComponent createTextComponent() {
   JTextArea ta = new JTextArea();
   ta.setLineWrap(true);
   return ta;
 }
Example #25
0
  /**
   * This method is used to display the window to interact with obix as well as colibri.
   *
   * @param chosenComponents The {@link ObixObject} which have been chosen in the previous windows.
   * @return The container which contains all elemtents that are used for interacting with obix as
   *     well as colibri.
   */
  private Container interactionWindow(List<ObixObject> chosenComponents) {
    Container pane = new Container();
    pane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

    pane.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridwidth = 10;
    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(30, 20, 0, 0);

    c.gridy++;
    pane.add(registeredColibriChannelCheckBox, c);

    JLabel label = new JLabel("OBIX Components");
    Font headerF = new Font("Courier", Font.BOLD, 25);
    label.setFont(headerF);
    c.gridy++;
    pane.add(label, c);

    /*
       Print lobby Data
    */
    for (ObixObject o : chosenComponents) {
      if (connector.getColibriChannel().getRegistered()) {
        connector.getColibriChannel().send(ColibriMessage.createAddServiceMessage(o));
      }

      c.gridy++;
      c.insets = new Insets(30, 10, 0, 0);

      JLabel uriLabel = new JLabel(o.getObixUri());
      uriLabel.setFont(new Font("Courier", Font.ITALIC, 15));
      c.gridx = 0;
      c.gridwidth = 10;
      pane.add(uriLabel, c);

      c.gridwidth = 1;
      c.insets = new Insets(5, 10, 0, 0);

      final JTextField textField = new JTextField("NOT OBSERVED", 20);
      Font tempF = new Font("Courier", Font.PLAIN, 15);
      textField.setFont(tempF);
      c.gridy++;
      pane.add(textField, c);

      JLabel unitLabel = new JLabel();
      if (o.hasUnit()) {
        String unitString = o.getUnit().symbol().get();
        int unitCode = unitString.codePointAt(0);
        if (unitCode == 65533) {
          unitString = "\u2103";
        }
        unitLabel.setText(unitString);
      }
      c.gridx++;
      pane.add(unitLabel, c);

      final JButton getObixButton = new JButton("GET from OBIX");
      c.gridx++;
      pane.add(getObixButton, c);

      final JButton getColibriButton = new JButton("GET from Colibri");
      c.gridx++;
      pane.add(getColibriButton, c);

      final JCheckBox writableCheckBox = new JCheckBox("Writable");
      writableCheckBox.setSelected(o.getObj().isWritable());
      writableCheckBox.setEnabled(false);
      c.gridx++;
      pane.add(writableCheckBox, c);

      final JCheckBox observeObixCheckBox = new JCheckBox("observe Obix Data");
      observeObixCheckBox.setMargin(new Insets(0, 20, 0, 20));
      c.gridx++;
      pane.add(observeObixCheckBox, c);

      final JCheckBox observedByColibriCheckBox = new JCheckBox("Colibri observes Data");
      observedByColibriCheckBox.setEnabled(false);
      commandFactory.addCommand(
          () -> observedByColibriCheckBox.setSelected(o.getObservedByColibri()));
      c.gridx++;
      pane.add(observedByColibriCheckBox, c);

      final JCheckBox addServiceCheckbox = new JCheckBox("Service Added to Colibri");
      commandFactory.addCommand(() -> addServiceCheckbox.setSelected(o.getAddedAsService()));
      commandFactory.addCommand(
          () -> addServiceCheckbox.setEnabled(connector.getColibriChannel().getRegistered()));
      c.gridx++;
      pane.add(addServiceCheckbox, c);

      final JCheckBox observeColibriActionsCheckbox = new JCheckBox("Observe Colibri Actions");
      if (o.getObj().isWritable()) {
        commandFactory.addCommand(
            () -> observeColibriActionsCheckbox.setEnabled(o.getAddedAsService()));
        commandFactory.addCommand(
            () -> observeColibriActionsCheckbox.setSelected(o.getObservesColibriActions()));
      } else {
        observeColibriActionsCheckbox.setEnabled(false);
      }
      c.gridx++;
      pane.add(observeColibriActionsCheckbox, c);

      representationRows.add(
          new RepresentationRow(
              uriLabel,
              observeObixCheckBox,
              textField,
              o,
              writableCheckBox,
              getObixButton,
              getColibriButton,
              addServiceCheckbox,
              observedByColibriCheckBox,
              observeColibriActionsCheckbox));
      PutToObixTask putToObixTask =
          new PutToObixTask(o, connector.getColibriChannel(), connector.getObixChannel(), null);
      connector.getColibriChannel().addPutToObixTask(o.getServiceUri(), putToObixTask);
      ObixObservationUpdates observationUpdates =
          new ObixObservationUpdates(observeObixCheckBox, textField, o, connector);

      /**
       * Listener for the checkbox which indicates, if an {@link ObixObject] is observed by the obix connector.
       */
      observeObixCheckBox.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              ObixObject object = new ObixObject("", o.getObixChannelPort());
              for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) {
                if (r.getObservedCheckBox().equals(observeObixCheckBox)) {
                  object = r.getObixObject();
                }
              }
              if (e.getStateChange() == ItemEvent.SELECTED) {
                obixChannel.observe(object);
                commandFactory.addCommand(
                    object.getObixUri() + "ObserveCommand", observationUpdates::run);
              } else {
                commandFactory.removeCommand(object.getObixUri() + "ObserveCommand");
                object.getRelation().proactiveCancel();
              }
            }
          });

      /**
       * Listener for the checkbox which indicates, if an {@link ObixObject] is writeable.
       */
      writableCheckBox.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              ObixObject object = new ObixObject("", o.getObixChannelPort());
              for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) {
                if (r.getWritableCheckbox().equals(writableCheckBox)) {
                  object = r.getObixObject();
                }
              }

              if (e.getStateChange() == ItemEvent.SELECTED) {

              } else {
                object.getObj().setWritable(false);
              }
              object = obixChannel.put(object);
              writableCheckBox.setSelected(object.getObj().isWritable());
            }
          });

      /**
       * Listener for the checkbox which indicates, if an {@link ObixObject] is added as a service at colibri.
       */
      addServiceCheckbox.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              ObixObject object = new ObixObject("", o.getObixChannelPort());
              for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) {
                if (r.getAddedAsServiceCheckBox().equals(addServiceCheckbox)) {
                  object = r.getObixObject();
                }
              }
              if (e.getStateChange() == ItemEvent.SELECTED) {
                if (!object.getAddedAsService()) {
                  connector
                      .getColibriChannel()
                      .send(ColibriMessage.createAddServiceMessage(object));
                }
              } else {
                if (object.getAddedAsService()) {
                  connector
                      .getColibriChannel()
                      .send(ColibriMessage.createRemoveServiceMessage(object));
                }
              }
            }
          });

      /**
       * Listener for the checkbox which indicates, if the connector observes the actions that the colibri
       * semantic core performs on an {@link ObixObject].
       */
      observeColibriActionsCheckbox.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              ObixObject object = new ObixObject("", o.getObixChannelPort());
              for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) {
                if (r.getObserveColibriActionsCheckbox().equals(observeColibriActionsCheckbox)) {
                  object = r.getObixObject();
                }
              }
              if (e.getStateChange() == ItemEvent.SELECTED) {
                if (!object.getObservesColibriActions()) {
                  connector
                      .getColibriChannel()
                      .send(ColibriMessage.createObserveServiceMessage(object));
                }
              } else {
                if (object.getObservesColibriActions()) {
                  connector
                      .getColibriChannel()
                      .send(ColibriMessage.createDetachServiceMessage(object));
                }
              }
            }
          });

      /** GET Obix button listener */
      Action getObixAction =
          new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
              ObixObject object = new ObixObject("", o.getObixChannelPort());
              JTextField textF = null;
              for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) {
                if (r.getGetObixButton().equals(getObixButton)) {
                  object = r.getObixObject();
                  textF = r.getValueTextField();
                }
              }
              textField.setText("");
              object = obixChannel.get(object.getObixUri());
              textF.setText(object.toString());
              if (o.getObservedByColibri()) {
                o.getPutMessageToColibriTask().execute(o);
              }
            }
          };
      getObixButton.addActionListener(getObixAction);

      /** GET Colibri button listener */
      Action getColibriAction =
          new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
              ObixObject object = new ObixObject("", o.getObixChannelPort());
              JTextField textF = null;
              for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) {
                if (r.getGetColibriButton().equals(getColibriButton)) {
                  object = r.getObixObject();
                  textF = r.getValueTextField();
                }
              }
              connector.getColibriChannel().send(ColibriMessage.createGetMessage(object));
            }
          };
      getColibriButton.addActionListener(getColibriAction);

      /**
       * Listener for the textfield connected with an {@link ObixObject}, to send PUT messages to
       * obix on <Enter>.
       */
      textField.addKeyListener(
          new KeyListener() {
            public void keyTyped(KeyEvent e) {
              // intentionally empty
            }

            public void keyPressed(KeyEvent e) {
              // intentionally empty
            }

            public void keyReleased(KeyEvent e) {
              if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                ObixObject object = new ObixObject("", o.getObixChannelPort());
                for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) {
                  if (r.getValueTextField().equals(textField)) {
                    object = r.getObixObject();
                  }
                }
                object.setValueParameter1(textField.getText());
                textField.setText("");
                object = obixChannel.put(object);
                textField.setText(object.toString());
              }
            }
          });
    }

    JTextArea receivedMessagesTextArea = new JTextArea("Received Messages");
    receivedMessagesTextArea.setLineWrap(true);
    receivedMessagesTextArea.setWrapStyleWord(true);
    c.gridy++;
    c.gridx = 0;
    c.insets = new Insets(50, 0, 0, 0);
    c.gridwidth = 10;
    pane.add(receivedMessagesTextArea, c);
    receivedMessagesTextArea.setEnabled(false);
    commandFactory.addCommand(
        () ->
            receivedMessagesTextArea.setText(
                connector.getColibriChannel().getLastMessageReceived()));

    c.gridy++;
    c.gridwidth = 1;

    JLabel sendMessageLabel = new JLabel("Send Message to Colibri Semantic Core:");
    pane.add(sendMessageLabel, c);

    c.gridy++;
    c.gridwidth = 10;
    JTextArea sendMessageArea = new JTextArea("");
    pane.add(sendMessageArea, c);

    c.gridy++;
    c.gridwidth = 2;
    JButton sendQueMessageButton = new JButton("Send Query Message");
    pane.add(sendQueMessageButton, c);
    c.gridx++;
    c.gridx++;
    c.gridwidth = 2;
    JButton sendUpdMessageButton = new JButton("Send Update Message");
    pane.add(sendUpdMessageButton, c);

    commandFactory.addCommand(
        () -> sendQueMessageButton.setEnabled(connector.getColibriChannel().getRegistered()));
    commandFactory.addCommand(
        () -> sendUpdMessageButton.setEnabled(connector.getColibriChannel().getRegistered()));

    /** QUE to Colibri button listener */
    Action sendQueMessageAction =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            connector
                .getColibriChannel()
                .send(
                    ColibriMessage.createQueryMessage(
                        sendMessageArea.getText(), new ArrayList<>()));
          }
        };
    sendQueMessageButton.addActionListener(sendQueMessageAction);

    /** UPD to Colibri button listener */
    Action sendUpdMessageAction =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            connector
                .getColibriChannel()
                .send(ColibriMessage.createUpdateMessage(sendMessageArea.getText()));
          }
        };
    sendUpdMessageButton.addActionListener(sendUpdMessageAction);
    return pane;
  }
  // CONSTRUCTOR
  public FACFrame() {

    // SET PROPERTIES OF THE MAIN FRAME
    setTitle("Fully Associative Cache");
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setIconImage(Toolkit.getDefaultToolkit().createImage(FACFrame.class.getResource("cam.gif")));

    // CREATE COMPONENTS AND SET THEIR PROPERTIES

    // NAVIGATION BUTTONS
    restart = new JButton("Restart");
    next = new JButton("Next");
    back = new JButton("Back");
    quit = new JButton("Quit");

    // CACHE HITS AND MISSES INFO.
    lCacheHits = new JLabel("Cache Hits");
    lCacheMisses = new JLabel("Cache Misses");
    tCacheHits = new JTextField(5);
    tCacheMisses = new JTextField(5);
    tCacheHits.setEditable(false);
    tCacheHits.setFont(new Font("Monospaced", Font.BOLD, 14));
    tCacheHits.setText("  0");
    tCacheMisses.setEditable(false);
    tCacheMisses.setFont(new Font("Monospaced", Font.BOLD, 14));
    tCacheMisses.setText("  0");

    // PROGRESS UPDATE AREA
    tProgress = new JTextArea(3, 45);
    tProgress.setEditable(false);
    tProgress.setLineWrap(true);
    tProgress.setWrapStyleWord(true);
    tProgress.setCaretPosition(0);
    tProgress.setFont(new Font("Serif", Font.BOLD + Font.ITALIC, 16));
    tProgress.setText(
        "Welcome to Fully Associative Cache!\nThe system specs are as follows -"
            + "\n  16 Blocks in Cache\n  32 Blocks in Main Memory\n  8 Words per Block"
            + "\n  The replacement algorithm shown is the Least-Recently-Used algorithm"
            + "\n  as it is the most commonly used one."
            + "\nPlease generate the Address Reference String."
            + "\nThen click on \"Next\" to continue.");
    progressScroll = new JScrollPane();
    progressScroll.getViewport().add(tProgress);
    progressScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    lProgress = new JLabel("PROGRESS UPDATE");

    // ADDRESS REFERENCE STRING
    addRefStrList = new JList();
    addRefStrList.setEnabled(false);
    addRefStrScroll = new JScrollPane();
    addRefStrScroll.getViewport().setView(addRefStrList);
    addRefStrScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    addRefStrScroll.setPreferredSize(new Dimension(140, 300));

    // BUTTONS USED TO ADDRESS GENERATION
    autoGen = new JButton("Auto Generate Add. Ref. Str.");
    selfGen = new JButton("Self Generate Add. Ref. Str.");

    // BITS IN MAIN MEMORY ADDRESS
    lBits = new JLabel("                   TAG                        WORD");

    tTag = new JTextField(9);
    tTag.setEditable(false);
    tWord = new JTextField(7);
    tWord.setEditable(false);

    // SET THE FONT STYLES FOR THE BITS IN MAIN MEMORY ADDRESS
    tTag.setFont(new Font("Monospaced", Font.BOLD, 14));
    tWord.setFont(new Font("Monospaced", Font.BOLD, 14));

    // REGISTER LISTENERS
    restart.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            reStart();
          }
        });

    next.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            nextClicked = true;
            step();
          }
        });

    back.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            nextClicked = false;
            step();
          }
        });

    quit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int confirmQuit =
                JOptionPane.showConfirmDialog(
                    null,
                    "Really Quit?",
                    "Quit Confirmation",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE);
            switch (confirmQuit) {
              case JOptionPane.YES_OPTION:
                removeInstance();
              case JOptionPane.NO_OPTION:
                break;
            }
          }
        });

    autoGen.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            autoGenerateString();
          }
        });

    selfGen.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            selfGenerateString();
          }
        });

    // DISABLE NAVIGATION BUTTONS FOR NOW
    next.setEnabled(false);
    back.setEnabled(false);

    // CREATE PANELS
    cachePanel = new FACachePanel();
    memoryPanel = new MemoryPanel();
    bottomPanel = new JPanel();
    cache = new JPanel();
    cacheHitsMisses = new JPanel();
    pAutoSelfGen = new JPanel();
    pAddRefStr = new JPanel();
    pEastPanel = new JPanel();
    pBitsInMM = new JPanel();

    // ADD COMPONENTS TO THE PANELS

    // PANEL WITH PROGRESS UPDATE TEXT AREA AND NAVIGATION BUTTONS
    bottomPanel.add(lProgress);
    bottomPanel.add(progressScroll);
    bottomPanel.add(restart);
    bottomPanel.add(next);
    bottomPanel.add(back);
    bottomPanel.add(quit);

    // PANEL WITH CACHE BLOCKS, HITS AND MISSES INFO.
    cacheHitsMisses.add(lCacheHits);
    cacheHitsMisses.add(tCacheHits);
    cacheHitsMisses.add(lCacheMisses);
    cacheHitsMisses.add(tCacheMisses);
    cacheHMBorder = BorderFactory.createEtchedBorder();
    cacheHitsMisses.setBorder(BorderFactory.createTitledBorder(cacheHMBorder, ""));

    cache.setLayout(new BorderLayout());
    cache.add(cachePanel, "Center");
    cache.add(cacheHitsMisses, "South");

    // PANEL WITH ADDRESS REFERENCE STRING AND STRING GENERATION BUTTONS
    pAutoSelfGen.setLayout(new GridLayout(2, 1));
    pAutoSelfGen.add(autoGen);
    pAutoSelfGen.add(selfGen);

    pAddRefStr.setLayout(new BorderLayout());
    pAddRefStr.setPreferredSize(new Dimension(160, 400));

    pAddRefStr.add(addRefStrScroll, "Center");
    pAddRefStr.add(pAutoSelfGen, "South");
    addRefStrBorder = BorderFactory.createEtchedBorder();
    pAddRefStr.setBorder(
        BorderFactory.createTitledBorder(addRefStrBorder, " Address Reference String "));

    // PANEL WITH THE MAIN MEMORY ADDRESS BITS INFO.
    pBitsInMM.setLayout(new BorderLayout());
    bitsInMMBorder = BorderFactory.createEtchedBorder();
    pBitsInMM.setBorder(BorderFactory.createTitledBorder(bitsInMMBorder, " Main Memory Address "));
    pBitsInMM.add(tTag, "Center");
    pBitsInMM.add(tWord, "East");
    pBitsInMM.add(lBits, "South");

    // PANEL CONTAINING THE ADDRESS REF. STRING PANEL AND BITS IN MM PANEL
    pEastPanel.setLayout(new BorderLayout());
    pEastPanel.setPreferredSize(new Dimension(310, 650));
    pEastPanel.add(pAddRefStr, "Center");
    pEastPanel.add(pBitsInMM, "South");

    // ADD COMPONENTS TO THE FRAME CONTAINER
    Container c = getContentPane();
    c.setLayout(new BorderLayout());
    c.add(cache, "West");
    c.add(memoryPanel, "Center");
    c.add(pEastPanel, "East");
    c.add(bottomPanel, "South");

    // INITIALIZE ARRAYS THAT HOLDS STATUS OF EMPTY AND LRU CACHE BLOCKS
    for (int i = 0; i < 16; i++) {
      statusCacheEmpty[i] = true;
      statusCacheLRU[i] = 0;
    }

    /*
     * CALL THE FUNCTION TO GENERATE THE ARRAY addresses, WHICH CONTAINS ALL THE POSSIBLE MEMORY ADDRESSES
     * THIS ARRAY WILL BE USEFUL IN THE AUTO GENERATION OF ADDRESSES AS WELL AS FOR VALIDATION OF
     * ADDRESS STRINGS INPUT BY THE USER IF HE/SHE CHOOSES SELF GENERATION.
     */
    createAddresses();

    pack();
  } // END CONSTRUCTOR
Example #27
0
  // initializes the internal component of the translator
  protected void jbInit() {
    this.getContentPane().setLayout(new GridBagLayout());

    loadButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            loadButton_actionPerformed(e);
          }
        });
    loadButton.setMaximumSize(new Dimension(39, 39));
    loadButton.setMinimumSize(new Dimension(39, 39));
    loadButton.setPreferredSize(new Dimension(39, 39));
    loadButton.setSize(new Dimension(39, 39));
    loadButton.setToolTipText("Load Source File");
    loadButton.setIcon(loadIcon);

    saveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            saveButton_actionPerformed(e);
          }
        });
    saveButton.setMaximumSize(new Dimension(39, 39));
    saveButton.setMinimumSize(new Dimension(39, 39));
    saveButton.setPreferredSize(new Dimension(39, 39));
    saveButton.setSize(new Dimension(39, 39));
    saveButton.setToolTipText("Save Destination File");
    saveButton.setIcon(saveIcon);

    singleStepButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            singleStepButton_actionPerformed(e);
          }
        });
    singleStepButton.setMaximumSize(new Dimension(39, 39));
    singleStepButton.setMinimumSize(new Dimension(39, 39));
    singleStepButton.setPreferredSize(new Dimension(39, 39));
    singleStepButton.setSize(new Dimension(39, 39));
    singleStepButton.setToolTipText("Single Step");
    singleStepButton.setIcon(singleStepIcon);

    ffwdButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ffwdButton_actionPerformed(e);
          }
        });
    ffwdButton.setMaximumSize(new Dimension(39, 39));
    ffwdButton.setMinimumSize(new Dimension(39, 39));
    ffwdButton.setPreferredSize(new Dimension(39, 39));
    ffwdButton.setSize(new Dimension(39, 39));
    ffwdButton.setToolTipText("Fast Forward");
    ffwdButton.setIcon(ffwdIcon);

    rewindButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            rewindButton_actionPerformed(e);
          }
        });
    rewindButton.setMaximumSize(new Dimension(39, 39));
    rewindButton.setMinimumSize(new Dimension(39, 39));
    rewindButton.setPreferredSize(new Dimension(39, 39));
    rewindButton.setSize(new Dimension(39, 39));
    rewindButton.setToolTipText("Rewind");
    rewindButton.setIcon(rewindIcon);

    stopButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            stopButton_actionPerformed(e);
          }
        });
    stopButton.setMaximumSize(new Dimension(39, 39));
    stopButton.setMinimumSize(new Dimension(39, 39));
    stopButton.setPreferredSize(new Dimension(39, 39));
    stopButton.setSize(new Dimension(39, 39));
    stopButton.setToolTipText("Stop");
    stopButton.setIcon(stopIcon);

    fullTranslationButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            fullTranslationButton_actionPerformed(e);
          }
        });
    fullTranslationButton.setMaximumSize(new Dimension(39, 39));
    fullTranslationButton.setMinimumSize(new Dimension(39, 39));
    fullTranslationButton.setPreferredSize(new Dimension(39, 39));
    fullTranslationButton.setSize(new Dimension(39, 39));
    fullTranslationButton.setToolTipText("Fast Translation");
    fullTranslationButton.setIcon(fullTranslationIcon);

    messageLbl.setFont(Utilities.statusLineFont);
    messageLbl.setLineWrap(true);
    messageLbl.setEditable(false);
    messageLbl.setCursor(null);
    messageLbl.setOpaque(false);
    messageLbl.setFocusable(false);
    messageLblPane.setBorder(BorderFactory.createLoweredBevelBorder());
    // messageLblPane.setBounds(new Rectangle(0, 672, TRANSLATOR_WIDTH - 8, 20));
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.ipadx = 0;
    c.ipady = 0;
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 3;
    c.anchor = GridBagConstraints.CENTER;
    c.gridx = 0;
    c.gridy = 2;
    this.getContentPane().add(messageLblPane, c);

    // arrowLabel.setBounds(new Rectangle(290, 324, 88, 71));
    arrowLabel.setIcon(arrowIcon);

    // source.setVisibleRows(31);
    // destination.setVisibleRows(31);
    // source.setBounds(new Rectangle(35,100,source.getWidth(),source.getHeight()));
    // destination.setBounds(new Rectangle(375,100,destination.getWidth(),destination.getHeight()));

    c.fill = GridBagConstraints.BOTH;
    c.ipadx = 0;
    c.ipady = 0;
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.CENTER;
    c.gridx = 0;
    c.gridy = 1;
    this.getContentPane().add(source, c);

    c.fill = GridBagConstraints.NONE;
    c.ipadx = 0;
    c.ipady = 0;
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.CENTER;
    c.gridx = 1;
    c.gridy = 1;
    this.getContentPane().add(arrowLabel, c);

    c.fill = GridBagConstraints.BOTH;
    c.ipadx = 0;
    c.ipady = 0;
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.CENTER;
    c.gridx = 2;
    c.gridy = 1;
    this.getContentPane().add(destination, c);

    // Adding the tool bar to this container.
    toolBar.setFloatable(false);
    toolBar.setLocation(0, 0);
    toolBar.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 0));
    toolBar.setBorder(BorderFactory.createEtchedBorder());
    arrangeToolBar();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.ipadx = 0;
    c.ipady = 0;
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 3;
    c.anchor = GridBagConstraints.CENTER;
    c.gridx = 0;
    c.gridy = 0;
    this.getContentPane().add(toolBar, c);
    toolBar.revalidate();
    toolBar.repaint();
    repaint();

    // Creating the menu bar
    arrangeMenu();
    setJMenuBar(menuBar);

    // initializing the window size and visibility
    setDefaultCloseOperation(3);
    setSize(new Dimension(TRANSLATOR_WIDTH, TRANSLATOR_HEIGHT));
    setVisible(true);
  }
Example #28
0
  public void launchChess() {

    mainWindow = new JFrame("网络黑白棋	作者:张炀");
    jpWest = new JPanel();
    jpEast = new JPanel();
    jpNorth = new JPanel();
    jpSouth = new JPanel();
    jpCenter = new JPanel();

    turnLabel = new JLabel();
    blackNumberLabel = new JLabel("黑棋:\n" + black + "		");
    whiteNumberLabel = new JLabel("白棋:\n" + white + "		");
    timeLabel = new JLabel("时间:  " + time + "		s");
    noticeLabel = new JLabel();

    noticeLabel = new JLabel("请选择:");
    numberPane = new JPanel();
    readyPane = new JPanel();
    jt1 = new JTextField(18); // 发送信息框
    jt2 = new JTextArea(3, 30); // 显示信息框
    js = new JScrollPane(jt2);
    jt2.setLineWrap(true);
    jt2.setEditable(false);
    //		jt1.setLineWrap(true);

    send = new JButton("发送");
    cancel = new JButton("取消");
    regret = new JButton("悔棋");
    submit = new JButton("退出");
    begin = new JButton("开始");
    save = new JButton("存盘");

    save.setEnabled(true);
    begin.setEnabled(true);

    fighter = new JRadioButton("下棋");
    audience = new JRadioButton("观看");
    group = new ButtonGroup();
    group.add(audience);
    group.add(fighter);
    group.add(AIPlayer);

    submit.addActionListener(this);
    begin.addActionListener(this);
    save.addActionListener(this);
    send.addActionListener(this);
    cancel.addActionListener(this);
    regret.addActionListener(this);
    fighter.addActionListener(this);
    audience.addActionListener(this);

    jpNorth.setLayout(new BorderLayout());
    jpNorth.add(turnLabel, BorderLayout.NORTH);
    jpNorth.add(jpCenter, BorderLayout.CENTER);
    jpSouth.add(js);
    jpSouth.add(jt1);
    jpSouth.add(send);
    jpSouth.add(cancel);
    jpEast.setLayout(new GridLayout(3, 1));
    submit.setBackground(new Color(130, 251, 241));
    panel x = new panel();
    jpEast.add(x);
    jpEast.add(numberPane);
    jpEast.add(readyPane);

    numberPane.add(blackNumberLabel);
    numberPane.add(whiteNumberLabel);
    numberPane.add(timeLabel);
    numberPane.add(submit);
    numberPane.add(begin);
    numberPane.add(save);
    numberPane.add(regret);

    readyPane.add(noticeLabel);
    readyPane.add(fighter);
    readyPane.add(audience);
    //		readyPane.add(save);
    //		readyPane.add(regret);

    jpCenter.setSize(400, 400);
    jmb = new JMenuBar();
    document = new JMenu("游戏		");
    edit = new JMenu("设置		");
    insert = new JMenu("棋盘			");
    help = new JMenu("帮助		");
    jmb.add(document);
    jmb.add(edit);
    jmb.add(insert);
    jmb.add(help);
    // mainWindow.setJMenuBar(jmb);

    mainWindow.setBounds(80, 80, 600, 600);
    mainWindow.setResizable(false);

    jsLeft = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, jpNorth, jpSouth);
    jsBase = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, jsLeft, jpEast);

    mainWindow.add(jsBase);
    mainWindow.setVisible(true);
    mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    jsBase.setDividerLocation(0.7);
    jsLeft.setDividerLocation(0.78);

    jpCenter.setLayout(new GridLayout(8, 8, 0, 0));
    ImageIcon key = new ImageIcon("chess1.jpg");
    for (int i = 0; i < cell.length; i++)
      for (int j = 0; j < cell.length; j++) {
        cell[i][j] = new ChessBoard(i, j);
        cell[i][j].addMouseListener(this);
        jpCenter.add(cell[i][j]);
      }

    cell[3][3].state = cell[4][4].state = '黑';
    cell[4][3].state = cell[3][4].state = '白';
    cell[3][3].taken = cell[4][4].taken = true;
    cell[4][3].taken = cell[3][4].taken = true;

    RememberState();

    new Thread(new TurnLabel(this)).start();

    file = new File("D:/" + myRole);
    try {
      fout = new FileOutputStream(file);
      out = new ObjectOutputStream(fout);
    } catch (IOException e1) {
      e1.printStackTrace();
    }

    Connect();

    try {
      out99 = new ObjectOutputStream(socket99.getOutputStream());
      in99 = new ObjectInputStream(socket99.getInputStream());

      out66 = new ObjectOutputStream(socket66.getOutputStream());
      in66 = new ObjectInputStream(socket66.getInputStream());

      out88 = new DataOutputStream(socket88.getOutputStream());
    } catch (IOException e) {
      e.printStackTrace();
    }

    new Thread(new Client9999(this)).start();
    new Thread(new Client6666(this)).start();
  }
  public void go() {
    // build gui

    frame = new JFrame("Quiz Card Buider");
    JPanel mainPanel = new JPanel();
    Font bigFont = new Font("sanserif", Font.BOLD, 24);
    question = new JTextArea(6, 20);
    question.setLineWrap(true);
    question.setWrapStyleWord(true);
    question.setFont(bigFont);

    JScrollPane qScroller = new JScrollPane(question);
    qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

    answer = new JTextArea(6, 20);
    answer.setLineWrap(true);
    answer.setWrapStyleWord(true);
    answer.setFont(bigFont);

    JScrollPane aScroller = new JScrollPane(question);
    aScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    aScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

    JButton nextButton = new JButton("Next Card");

    cardList = new ArrayList<QuizCard>();

    JLabel qLabel = new JLabel("Question");
    JLabel aLabel = new JLabel("Answer");

    mainPanel.add(qLabel);
    mainPanel.add(qScroller);
    mainPanel.add(aLabel);
    mainPanel.add(aScroller);
    mainPanel.add(nextButton);

    nextButton.addActionListener(new NextCardListener());

    JMenuBar menuBar = new JMenuBar();

    JMenu fileMenu = new JMenu("File");

    JMenuItem newMenuItem = new JMenuItem("New");
    JMenuItem saveMenuItem = new JMenuItem("Save");
    newMenuItem.addActionListener(new NewMenuListener());
    saveMenuItem.addActionListener(new SaveMenuListener());

    fileMenu.add(newMenuItem);
    fileMenu.add(saveMenuItem);
    menuBar.add(fileMenu);
    frame.setJMenuBar(menuBar);
    frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
    frame.setSize(500, 600);
    frame.setVisible(true);
    // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  }
  public void go() {
    frame = new JFrame("Quiz Card Player");
    JPanel mainPanel = new JPanel();
    Font bigFont = new Font("sanserif", Font.BOLD, 24);

    display = new JTextArea(10, 20);
    display.setFont(bigFont);
    display.setLineWrap(true);
    display.setEditable(false);

    JScrollPane qScroller = new JScrollPane(display);
    qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    nextButton = new JButton("Show Questions");
    nextButton.addActionListener(new NextCardListener());

    mainPanel.add(qScroller);
    mainPanel.add(nextButton);

    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    JMenuItem loadMenuItem = new JMenuItem("Load Card Set");
    loadMenuItem.addActionListener(new OpenMenuListener());
    fileMenu.add(loadMenuItem);
    menuBar.add(fileMenu);

    frame.setJMenuBar(menuBar);
    frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
    frame.setSize(640, 500);
    frame.setVisible(true);
  }