Example usage for javax.swing JTextArea getName

List of usage examples for javax.swing JTextArea getName

Introduction

In this page you can find the example usage for javax.swing JTextArea getName.

Prototype

public String getName() 

Source Link

Document

Gets the name of the component.

Usage

From source file:com.att.aro.ui.view.menu.tools.RegexWizard.java

@Override
public void focusLost(FocusEvent e) {
    JTextArea field = (JTextArea) e.getSource();
    if (field.getName().equals(requestField.getName())) {
        setRequestHighlightedText(field.getSelectedText());
        updateFocus(true, false, false);
    } else if (field.getName().equals(headerField.getName())) {
        setHeaderHighlightedText(field.getSelectedText());
        updateFocus(false, false, true);
    } else if (field.getName().equals(responseField.getName())) {
        setResponseHighlightedText(field.getSelectedText());
        updateFocus(false, true, false);
    } else {// if(field.getName().equals(regexRequestField.getName()) || field.getName().equals(regexResponseField.getName()) ||
            // field.getName().equals(regexHeaderField.getName())){
        clearHighlightedTexts();/*w w  w.j  a v a2 s .  c o  m*/
        if (field.getName().equals(regexRequestField.getName())) {
            updateFocus(true, false, false);
        } else if (field.getName().equals(regexResponseField.getName())) {
            updateFocus(false, true, false);
        } else {
            updateFocus(false, false, true);

        }
    }
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Creates the status message for the error, alerts the user with a popup. If
 * the issue is a recognized syntax error and the line and column numbers can
 * be found int he exception message, the cursor will be moved to that
 * position.//from w  w w .  j  a  v  a  2  s  . c o  m
 * 
 * @param throwable
 *          The error that occurred
 * @param operationDetailMessage
 *          A message specific to the operation that was running. This may be
 *          null
 * 
 * @return The message to be presented on the status line
 */
private String errorAlert(Throwable throwable, String operationDetailMessage) {
    String statusMessage;
    String alertMessage;
    String httpStatusMessage = null;
    String causeClass;
    String causeMessage;
    QueryExceptionHTTP httpExc = null;
    int[] lineAndColumn = new int[2];
    int whichSelectedTab = -1;
    JTextArea whichFocusJTextArea = null;

    if (throwable.getCause() != null) {
        causeClass = throwable.getCause().getClass().getName();
        causeMessage = throwable.getCause().getMessage();
    } else {
        causeClass = throwable.getClass().getName();
        causeMessage = throwable.getMessage();
    }

    if (operationDetailMessage != null) {
        alertMessage = operationDetailMessage + "\n\n";
    } else {
        alertMessage = "Error:";
    }

    alertMessage += causeClass + "\n" + causeMessage;

    statusMessage = causeMessage.trim().length() > 0 ? causeMessage : causeClass;

    if (throwable instanceof QueryExceptionHTTP) {
        httpExc = (QueryExceptionHTTP) throwable;

        httpStatusMessage = httpExc.getResponseMessage();
        if (httpStatusMessage == null || httpStatusMessage.trim().length() == 0) {
            try {
                httpStatusMessage = HttpStatus.getStatusText(httpExc.getResponseCode());
            } catch (Throwable lookupExc) {
                LOGGER.info("Cannot find message for returned HTTP code of " + httpExc.getResponseCode());
            }
        }
    }

    if (httpExc != null) {
        statusMessage += ": " + "Response Code: " + httpExc.getResponseCode()
                + (httpStatusMessage != null && httpStatusMessage.trim().length() > 0
                        ? " (" + httpStatusMessage + ")"
                        : "");

        JOptionPane.showMessageDialog(this,
                alertMessage + "\n\n" + "Response Code: " + httpExc.getResponseCode() + "\n"
                        + (httpStatusMessage != null ? httpStatusMessage : ""),
                "Error", JOptionPane.ERROR_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(this, alertMessage, "Error", JOptionPane.ERROR_MESSAGE);
    }

    // Attempt to deal with a syntax error and positioning the cursor
    if (runningOperation == Operation.CREATE_MODEL) {
        // Assertions processing issue
        RiotException riotExc = null;
        Throwable nextThrowable = throwable;
        while (riotExc == null && nextThrowable != null) {
            if (nextThrowable instanceof RiotException) {
                riotExc = (RiotException) nextThrowable;
            } else {
                LOGGER.trace("Not a riot exception, another? " + throwable.getClass().toString() + "->"
                        + throwable.getCause());
                nextThrowable = nextThrowable.getCause();
            }
        }
        if (riotExc != null) {
            lineAndColumn = getSyntaxErrorLineColLocation(riotExc.getMessage().toLowerCase(), "line: ", ",",
                    "col: ", "]");
            whichSelectedTab = TAB_NUMBER_ASSERTIONS;
            whichFocusJTextArea = assertionsInput;
        } else {
            LOGGER.debug("No riot exception found so the caret cannot be positioned");
        }
    }
    if (runningOperation == Operation.EXECUTE_SPARQL) {
        // SPARQL processing issue
        QueryParseException queryParseExc = null;
        Throwable nextThrowable = throwable;
        while (queryParseExc == null && nextThrowable != null) {
            if (nextThrowable instanceof QueryParseException) {
                queryParseExc = (QueryParseException) nextThrowable;
            } else {
                LOGGER.trace("Not a query parse exception, another? " + throwable.getClass().toString() + "->"
                        + throwable.getCause());
                nextThrowable = nextThrowable.getCause();
            }
        }
        if (queryParseExc != null) {
            lineAndColumn = getSyntaxErrorLineColLocation(queryParseExc.getMessage().toLowerCase(), "at line ",
                    ",", ", column ", ".");
            whichSelectedTab = TAB_NUMBER_SPARQL;
            whichFocusJTextArea = sparqlInput;
        } else {
            LOGGER.debug("No query parse exception found so the caret cannot be positioned");
        }
    }

    if (lineAndColumn[0] > 0 && lineAndColumn[1] > 0) {
        LOGGER.debug("Attempt to set assertions caret to position (" + lineAndColumn[0] + "," + lineAndColumn[1]
                + ")");
        final int finalLineNumber = lineAndColumn[0] - 1;
        final int finalColumnNumber = lineAndColumn[1] - 1;
        final int finalWhichSelectedTab = whichSelectedTab;
        final JTextArea finalWhichFocusJTextArea = whichFocusJTextArea;
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                tabbedPane.setSelectedIndex(finalWhichSelectedTab);
                try {
                    finalWhichFocusJTextArea.setCaretPosition(
                            finalWhichFocusJTextArea.getLineStartOffset(finalLineNumber) + finalColumnNumber);
                    finalWhichFocusJTextArea.requestFocusInWindow();
                } catch (Throwable throwable) {
                    LOGGER.warn("Cannot set " + finalWhichFocusJTextArea.getName() + " carat position to ("
                            + finalLineNumber + "," + finalColumnNumber + ") on tab " + finalWhichSelectedTab,
                            throwable);
                }
            }
        });
    }

    return statusMessage;
}