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", "");
    }
  }
 /**
  * Will select the Mars Messages tab error message that matches the given specifications, if it is
  * found. Matching is done by constructing a string using the parameter values and searching the
  * text area for the last occurrance of that string.
  *
  * @param fileName A String containing the file path name.
  * @param line Line number for error message
  * @param column Column number for error message
  */
 public void selectErrorMessage(String fileName, int line, int column) {
   String errorReportSubstring =
       new java.io.File(fileName).getName()
           + ErrorList.LINE_PREFIX
           + line
           + ErrorList.POSITION_PREFIX
           + column;
   int textPosition = assemble.getText().lastIndexOf(errorReportSubstring);
   if (textPosition >= 0) {
     int textLine = 0;
     int lineStart = 0;
     int lineEnd = 0;
     try {
       textLine = assemble.getLineOfOffset(textPosition);
       lineStart = assemble.getLineStartOffset(textLine);
       lineEnd = assemble.getLineEndOffset(textLine);
       assemble.setSelectionColor(Color.YELLOW);
       assemble.select(lineStart, lineEnd);
       assemble.getCaret().setSelectionVisible(true);
       assemble.repaint();
     } catch (BadLocationException ble) {
       // If there is a problem, simply skip the selection
     }
   }
 }
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);
     }
   }
 }
 @Override
 public void highLight(JTextArea j) {
   try {
     int startIndex = j.getLineStartOffset(line - 1);
     int endIndex = j.getLineEndOffset(line - 1);
     Highlighter.HighlightPainter painter =
         new DefaultHighlighter.DefaultHighlightPainter(new Color(255, 240, 240));
     j.getHighlighter().addHighlight(startIndex, endIndex, painter);
     //    jTextArea1.geth
   } catch (BadLocationException ex) {
     Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
   }
 }
Example #6
0
  public void update() {
    memView.setText(machine.memToString());

    r0.setText(String.format("%04X", machine.readReg(0) & 0xFFFF));
    r1.setText(String.format("%04X", machine.readReg(1) & 0xFFFF));
    r2.setText(String.format("%04X", machine.readReg(2) & 0xFFFF));
    r3.setText(String.format("%04X", machine.readReg(3) & 0xFFFF));
    r4.setText(String.format("%04X", machine.readReg(4) & 0xFFFF));
    r5.setText(String.format("%04X", machine.readReg(5) & 0xFFFF));
    r6.setText(String.format("%04X", machine.readReg(6) & 0xFFFF));
    r7.setText(String.format("%04X", machine.readReg(7) & 0xFFFF));

    d0.setText(String.format("%d", machine.readReg(0)));
    d1.setText(String.format("%d", machine.readReg(1)));
    d2.setText(String.format("%d", machine.readReg(2)));
    d3.setText(String.format("%d", machine.readReg(3)));
    d4.setText(String.format("%d", machine.readReg(4)));
    d5.setText(String.format("%d", machine.readReg(5)));
    d6.setText(String.format("%d", machine.readReg(6)));
    d7.setText(String.format("%d", machine.readReg(7)));

    cbNeg.setSelected(machine.neg());
    cbZero.setSelected(machine.zero());
    cbPos.setSelected(machine.pos());

    status.setText(machine.status());

    int line = machine.pcLine();
    try {
      int start = memView.getLineStartOffset(line);
      int end = memView.getLineEndOffset(line);
      memView.setCaretPosition(start);
      memView.select(start, end);

      Rectangle viewRect = memView.modelToView(start);
      // Scroll to make the rectangle visible
      memView.scrollRectToVisible(viewRect);
    } catch (Exception e) {
    }

    btnStep.setEnabled(true);
    btnStepOver.setEnabled(true);
    btnRun.setEnabled(true);
    btnStop.setEnabled(false);
  }
Example #7
0
  void doCaretUpdate(int dot, int mark) {
    if (dot == mark) {
      mainFrame.cutItem.setEnabled(false);
      mainFrame.copyItem.setEnabled(false);
      mainFrame.deleteItem.setEnabled(false);
    } else {
      mainFrame.cutItem.setEnabled(true);
      mainFrame.copyItem.setEnabled(true);
      mainFrame.deleteItem.setEnabled(true);
    }

    int length = sourceArea.getText().length();
    if (length == 0 || abs(mark - dot) == length) {
      mainFrame.selectAllItem.setEnabled(false);
    } else {
      mainFrame.selectAllItem.setEnabled(true);
    }

    try {
      if (length == 0) {
        mainFrame.selectLineItem.setEnabled(false);
      } else {
        int lineNum = sourceArea.getLineOfOffset(dot);
        int startLine = sourceArea.getLineStartOffset(lineNum);
        int endLine = sourceArea.getLineEndOffset(lineNum);
        if (endLine - startLine <= 1) {
          mainFrame.selectLineItem.setEnabled(false);
        } else {
          mainFrame.selectLineItem.setEnabled(true);
        }
      }
    } catch (BadLocationException ex) {
      ex.printStackTrace();
    }

    try {
      int line = sourceArea.getLineOfOffset(dot);
      lineText.setText(Integer.toString(line + 1));
      int column = dot - sourceArea.getLineStartOffset(line);
      columnText.setText(Integer.toString(column + 1));
    } catch (BadLocationException ex) {
      ex.printStackTrace();
    }
  }
Example #8
0
  private void highlightError(int index) {
    String message = (String) messages.elementAt(index);
    int i = message.indexOf(":");

    if ((i != -1) && (i < 10)) {
      try {
        int lineNumber = Integer.parseInt(message.substring(0, i).trim()) - 1;
        if (lineNumber < sourceArea.getLineCount()) {
          int start = sourceArea.getLineStartOffset(lineNumber);
          int end = sourceArea.getLineEndOffset(lineNumber);

          sourceArea.requestFocus();
          sourceArea.setSelectionStart(start);
          sourceArea.setSelectionEnd(end - 1);
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }
  @Override
  public DataObject execute(ServiceInput serviceInput) {
    String warning_value =
        String.valueOf(serviceInput.getInput().getAttributeValue(WarningWidget.WARNING_FIRE));

    int last = warningTextArea.getLineCount() - 1;
    int start;
    int end;
    String lastLine = "";

    try {
      if (last > 0) {
        start = warningTextArea.getLineStartOffset(last - 1);
        end = warningTextArea.getLineEndOffset(last);
        lastLine = warningTextArea.getText().substring(start, end - 1);
      }
    } catch (BadLocationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    if (!warning_value.equals(lastLine)) warningTextArea.append(warning_value + "\n");

    return new DataObject(); // no particular info to return
  }