/**
  * 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 #2
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 #3
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();
      }
    }
  }