Example #1
0
  // Displays the users currently online in the usersOnlineWindow JTextArea
  private void showUsersOnline() throws JSONException {

    // F**k det här under. Det f*****g sög att skriva. JSONArrays är retarderade.

    for (int i = 0; i < ((JSONArray) obj.get("listOfUsernames")).length(); i++) {
      if (!((JSONArray) obj.get("listOfUsernames")).isNull(i)) {
        if (!doesArrayContain(
            arrayOfAddedUsernames, ((JSONArray) obj.get("listOfUsernames")).getString(i))) {
          usersOnlineWindow.append("\n" + ((JSONArray) obj.get("listOfUsernames")).getString(i));
          pushValueToArray(
              arrayOfAddedUsernames, ((JSONArray) obj.get("listOfUsernames")).getString(i));
        }
      }
    }

    if (!obj.getString("disconnectedUser").equals("")) {
      int offset = usersOnlineWindow.getText().indexOf(obj.getString("disconnectedUser"));

      if (offset != -1) {
        try {
          int line = usersOnlineWindow.getLineOfOffset(offset);
          int start = usersOnlineWindow.getLineStartOffset(line);
          int end = usersOnlineWindow.getLineEndOffset(line);

          usersOnlineWindow.replaceRange("", start, end);
        } catch (BadLocationException e) {
          e.printStackTrace();
        }
      }
      obj.put("disconnectedUser", "");
    }
  }
 @Override
 public synchronized void write(byte[] ba, int str, int len) {
   try {
     curLength += len;
     if (bytesEndWith(ba, str, len, LINE_SEP)) {
       lineLengths.addLast(new Integer(curLength));
       curLength = 0;
       if (lineLengths.size() > maxLines) {
         textArea.replaceRange(null, 0, lineLengths.removeFirst().intValue());
       }
     }
     for (int xa = 0; xa < 10; xa++) {
       try {
         textArea.append(new String(ba, str, len));
         break;
       } catch (
           Throwable
               thr) { // sometimes throws a java.lang.Error: Interrupted attempt to aquire write
                      // lock
         if (xa == 9) {
           thr.printStackTrace();
         }
       }
     }
     textArea.setCaretPosition(textArea.getText().length());
   } catch (Throwable thr) {
     CharArrayWriter caw = new CharArrayWriter();
     thr.printStackTrace(new PrintWriter(caw, true));
     textArea.append(System.getProperty("line.separator", "\n"));
     textArea.append(caw.toString());
   }
 }
Example #3
0
 public void newPrompt(String prompt) {
   int lineCount = textArea.getLineCount();
   try {
     int end = textArea.getLineEndOffset(lineCount - 1);
     textArea.replaceRange(prompt, 0, end);
   } catch (BadLocationException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Example #4
0
 public void truncateTextArea() {
   int numLinesToRemove =
       console.getLineCount() - 1 - MAX_CONSOLE_LINES; // There's a blank at the end
   if (numLinesToRemove > 0) {
     try {
       int posOfLastLineToRemove = console.getLineEndOffset(numLinesToRemove - 1);
       console.replaceRange("", 0, posOfLastLineToRemove);
     } catch (javax.swing.text.BadLocationException ex) {
       log.error("trouble truncating SystemConsole window", ex);
     }
   }
 }
  public void openAst(DetailAST parseTree) {
    parseTreeModel.setParseTree(parseTree);
    reloadAction.setEnabled(true);

    // clear for each new file
    clearLinesToPosition();
    // starts line counting at 1
    addLineToPosition(0);
    // insert the contents of the file to the text area

    // clean the text area before inserting the lines of the new file
    if (!textArea.getText().isEmpty()) {
      textArea.replaceRange("", 0, textArea.getText().length());
    }

    // move back to the top of the file
    textArea.moveCaretPosition(0);
  }
Example #6
0
 // MUST BE THE ONLY METHOD THAT TOUCHES textArea!
 public synchronized void run() {
   if (clear) {
     textArea.setText("");
   }
   for (String val : values) {
     curLength += val.length();
     if (val.endsWith(EOL1) || val.endsWith(EOL2)) {
       if (lengths.size() >= maxLines) {
         textArea.replaceRange("", 0, lengths.removeFirst());
       }
       lengths.addLast(curLength);
       curLength = 0;
     }
     textArea.append(val);
   }
   values.clear();
   clear = false;
   queue = true;
 }
Example #7
0
  final void setTextByLocale(Locale locale) {
    changeLocale(locale);
    // remove all template item to re-add other locale-spec items
    // if (templateList.getModel().getSize() > 0) {
    // templateList.removeAllItems();
    // }
    initTemplates();

    mainFrame.setTitle(localeHelper.getLocaleString(UIConstants.MAIN_WINDOW_TITLE));
    optionsBorder.setTitle(localeHelper.getLocaleString(UIConstants.BORDER_OPTIONS_TITLE));
    templateLabel.setText(localeHelper.getLocaleString(UIConstants.LABEL_TEMPLATE));
    useTemplateCheckBox.setText(localeHelper.getLocaleString(UIConstants.CHECKBOX_USETEMPLATE));
    useNumberRadioButton.setText(localeHelper.getLocaleString(UIConstants.RADIO_NUMTOCHANGE));
    useAlphaBetaRadioButton.setText(localeHelper.getLocaleString(UIConstants.RADIO_ALPHATOCHANGE));
    startPositionLabel.setText(localeHelper.getLocaleString(UIConstants.LABEL_STARTPOSITION));
    previewButton.setText(localeHelper.getLocaleString(UIConstants.BUTTON_PREVIEW));
    beginButton.setText(localeHelper.getLocaleString(UIConstants.BUTTON_BEGIN));
    changeSuffixCheck.setText(localeHelper.getLocaleString(UIConstants.LABEL_CHANGESUFFIX));
    previewLabel.setText(localeHelper.getLocaleString(UIConstants.LABEL_PREVIEW));
    addButton.setText(localeHelper.getLocaleString(UIConstants.BUTTON_ADD));
    removeButton.setText(localeHelper.getLocaleString(UIConstants.BUTTON_REMOVE));
    upperLowerTransformLabel.setText(localeHelper.getLocaleString(UIConstants.LABEL_ULTRANSFORM));

    fileMenu.setText(localeHelper.getLocaleString(UIConstants.MENU_FILE));
    fileOpen.setText(localeHelper.getLocaleString(UIConstants.MENU_FILE_OPEN));
    fileClose.setText(localeHelper.getLocaleString(UIConstants.MENU_FILE_EXIT));

    // used for language selection, for future add-on
    /*
    languageMenu.setText(localHelper
    .getLocalString(UIConstants.MENU_LANGUAGE));
    eng.setText(localHelper.getLocalString(UIConstants.MENU_LANGUAGE_ENG));
    chn.setText(localHelper.getLocalString(UIConstants.MENU_LANGUAGE_CHN));
    */
    textArea.replaceRange(
        localeHelper.getLocaleString(UIConstants.TEMPLATE_README),
        0,
        textArea.getDocument().getLength());

    mainFrame.pack();
  }
  public void openFile(File file, final Component parent) {
    if (file != null) {
      try {
        Main.getFrame().setTitle("Checkstyle : " + file.getName());
        final FileText text = new FileText(file.getAbsoluteFile(), getEncoding());
        final DetailAST parseTree = parseFile(text);
        parseTreeModel.setParseTree(parseTree);
        currentFile = file;
        lastDirectory = file.getParentFile();
        reloadAction.setEnabled(true);

        final String[] sourceLines = text.toLinesArray();

        // clear for each new file
        clearLinesToPosition();
        // starts line counting at 1
        addLineToPosition(0);
        // insert the contents of the file to the text area
        for (String element : sourceLines) {
          addLineToPosition(textArea.getText().length());
          textArea.append(element + System.lineSeparator());
        }

        // clean the text area before inserting the lines of the new file
        if (!textArea.getText().isEmpty()) {
          textArea.replaceRange("", 0, textArea.getText().length());
        }

        // insert the contents of the file to the text area
        for (final String element : sourceLines) {
          textArea.append(element + System.lineSeparator());
        }

        // move back to the top of the file
        textArea.moveCaretPosition(0);
      } catch (final IOException | ANTLRException ex) {
        showErrorDialog(parent, "Could not parse" + file + ": " + ex.getMessage());
      }
    }
  }
Example #9
0
  /** Invoked when an action occurs. */
  public void actionPerformed(ActionEvent e) {
    /* file menu */
    if (e.getSource() == newFile) {
      if (isUnsavedFile()) {
        int choice = displayUnsavedWarning();
        if (choice == JOptionPane.YES_OPTION) {
          editor.setText(null);
          currentFile = null;
        }
      } else {
        editor.setText(null);
        currentFile = null;
      }
    }
    if (e.getSource() == open) {
      if (isUnsavedFile()) {
        int choice = displayUnsavedWarning();
        if (choice == JOptionPane.YES_OPTION) {
          fileOpen();
        }
      } else {
        fileOpen();
      }
    }
    if (e.getSource() == save) {
      if (currentFile != null && currentFile.exists()) {
        fileSave();
      } else {
        fileSaveAs();
      }
    }
    if (e.getSource() == saveAs) {
      fileSaveAs();
    }
    if (e.getSource() == close) {
      if (isUnsavedFile()) {
        int choice = displayUnsavedWarning();
        if (choice == JOptionPane.YES_OPTION) {
          System.exit(0);
        }
      } else {
        System.exit(0);
      }
    }

    /* edit menu */
    if (e.getSource() == cut) {
      String text = editor.getSelectedText();
      if (text != null) {
        setClipboardText(text);
        editor.replaceRange("", editor.getSelectionStart(), editor.getSelectionEnd());
      }
    }
    if (e.getSource() == copy) {
      String text = editor.getSelectedText();
      if (text != null) {
        setClipboardText(text);
      }
    }
    if (e.getSource() == paste) {
      String text = getClipboardText();
      if (text != null) {
        if (editor.getSelectedText() != null) {
          editor.replaceRange(text, editor.getSelectionStart(), editor.getSelectionEnd());
        } else {
          editor.insert(text, editor.getCaretPosition());
        }
      }
    }
    if (e.getSource() == deleteSelected) {
      if (editor.getSelectedText() != null) {
        editor.replaceRange("", editor.getSelectionStart(), editor.getSelectionEnd());
      }
    }

    /* help menu */
    if (e.getSource() == about) {
      String message =
          "About "
              + programName
              + "\n"
              + "Author: "
              + authorName
              + "\n"
              + "Last modified: "
              + lastModified
              + "\n"
              + "Description: "
              + programDesc;
      JOptionPane.showOptionDialog(
          mainFrame,
          message,
          "About " + programName,
          JOptionPane.DEFAULT_OPTION,
          JOptionPane.PLAIN_MESSAGE,
          null,
          null,
          null);
    }

    /* buttons */
    // fileChooserButton
    if (e.getSource() == buttonPanel.getComponent(0)) {
      fileOpen();
    }
    // sideButton
    if (e.getSource() == buttonPanel.getComponent(1)) {
      String copiedText = editor.getSelectedText();
      if (copiedText != null) {
        side.setText(copiedText);
      }
    }
  }