@Override
 public void actionPerformed(ActionEvent e) {
   try {
     if (e.getSource() == ok_button) {
       if (mainFrame != null) {
         Client client =
             new Client(serverAddress.getText(), Integer.parseInt(serverPort.getText()), 0);
         if (client.getClientThread().getClientSocket().isConnected()) mainFrame.setClient(client);
       }
       this.setVisible(false);
       this.dispose();
     } else if (e.getSource() == cancel_button) {
       mainFrame.setClient(null);
       this.setVisible(false);
       this.dispose();
     }
   } catch (NumberFormatException exception) {
     JOptionPane.showMessageDialog(this, "Invalid value: " + exception.getMessage());
   }
 }
  public void doReplaceAll() {
    EditWindow currentWindow = editor.getActiveWindow();

    if (currentWindow == null || getFindTextField().getText().length() == 0) {
      // launch error dialog?
      return;
    }
    JEditorPane editorPane = currentWindow.getEditorPane();
    String text = editorPane.getText();

    String replacement = getReplaceTextField().getText();

    editorPane.setText(getCurrentPattern().matcher(text).replaceAll(replacement));
  }
Exemple #3
0
  void writeNetcdf(NetcdfOutputChooser.Data data) {
    // if (debugNcmlWrite) {
    //  System.out.printf("choices=%s%n", choice);
    // }

    String text = editor.getText();

    try {
      ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes(CDM.utf8Charset));
      NcMLReader.writeNcMLToFile(
          bis,
          data.outputFilename,
          data.version,
          Nc4ChunkingStrategy.factory(data.chunkerType, data.deflate, data.shuffle));
      JOptionPane.showMessageDialog(this, "File successfully written");

    } catch (Exception ioe) {
      JOptionPane.showMessageDialog(this, "ERROR: " + ioe.getMessage());
      ioe.printStackTrace();
    }
  }
 public void showResult(JEditorPane txt, String result) {
   try {
     if (txt.getText().length() == 0) {
       appendHTML(txt, result);
       txt.setSelectionStart(txt.getText().length());
       txt.setSelectionEnd(txt.getText().length() - 1);
     } else {
       if (txt.getText().length() > MAX_LOG_SIZE) {
         txt.setSelectionStart(0);
         txt.setSelectionStart(txt.getText().length() - MAX_LOG_SIZE);
         txt.replaceSelection("");
       }
       txt.setSelectionStart(txt.getText().length());
       appendHTML(txt, result);
       txt.setSelectionEnd(txt.getText().length());
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  public void findNext() {
    EditWindow currentWindow = editor.getActiveWindow();

    if (currentWindow == null || getFindTextField().getText().length() == 0) {
      // launch error dialog?
      return;
    }
    Pattern p = getCurrentPattern();
    JEditorPane editorPane = currentWindow.getEditorPane();

    // for some reason, getText() trims off \r but the indexes in
    // the editor pane don't.
    String text = editorPane.getText().replaceAll("\\r", "");
    Matcher m = p.matcher(text);
    int index = editorPane.getSelectionEnd();

    if (!(m.find(index) || m.find())) {
      return;
    }
    editorPane.setSelectionStart(m.start());
    editorPane.setSelectionEnd(m.end());
  }
 public String getParseText() {
   return editor.getText();
 }
 public String getTextString() {
   return editor.getText();
 }
Exemple #8
0
  /**
   * Builds the chat window by adding all fields and buttons as well as making the window visible.
   * It also adds listeners to all the buttons and a listener so that the default close operation
   * becomes a method call.
   */
  private void buildChatWindow() {
    Dimension chatWindowDimension = new Dimension(500, 400);
    Dimension writeAreDimensions = new Dimension(0, 83);
    JPanel mainPanel = new JPanel(new GridBagLayout());
    JPanel extrasPanel = new JPanel();
    JScrollPane scrollDisplayArea = new JScrollPane();
    displayArea = new JTextPane();
    JEditorPane writeMessageArea = new JEditorPane();
    JButton sendTextButton = new JButton("Send");
    JButton sendFileButton = new JButton("Send file");

    displayTextDocument = displayArea.getDocument();

    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(5, 5, 5, 5);
    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = 2;
    c.weightx = 1;
    c.weighty = 1;
    c.gridx = 0;
    c.gridy = 0;
    scrollDisplayArea.add(displayArea);
    scrollDisplayArea.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    scrollDisplayArea.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    mainPanel.add(scrollDisplayArea, c);

    c.gridwidth = 1;
    c.weightx = 0;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 1;
    extrasPanel.setBackground(new Color(96, 92, 95));
    mainPanel.add(extrasPanel, c);

    c.gridx = 1;
    c.gridy = 1;
    mainPanel.add(sendFileButton, c);

    c.weightx = 1;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 2;
    writeMessageArea.setPreferredSize(writeAreDimensions);
    mainPanel.add(writeMessageArea, c);

    c.weightx = 0;
    c.weighty = 0;
    c.gridx = 1;
    c.gridy = 2;
    mainPanel.add(sendTextButton, c);

    setPreferredSize(chatWindowDimension);
    add(mainPanel);
    pack();
    setVisible(true);

    sendTextButton.addActionListener(
        e -> {
          // TODO add XML colors and shit
          System.out.println("ChatGUI: Sending message: " + writeMessageArea.getText());
          chat.sendMessage(writeMessageArea.getText());
          writeMessageArea.setText("");
        });

    sendFileButton.addActionListener(
        e -> {
          // TODO send a file
          System.out.println("ChatGUI: Is supposed to send a file");
        });

    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            closeChatWindowOperation();
          }
        });
  }
 public String getToolTip() {
   return mouseHoverTextPanel.getText();
 }
Exemple #10
0
 public void save() throws Exception {
   U.saveString(file, text.getText());
   file_lastModified = file.lastModified();
   saved = true;
   sem.pushEvent("updateTitle", this, null);
 }