Java Code Examples for javax.swing.text.BadLocationException#getMessage()

The following examples show how to use javax.swing.text.BadLocationException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 *  Insert the Saas client call
 */
protected void insertSaasServiceAccessCode(boolean isInBlock) throws IOException {
    try {
        String code = "";
        if (isInBlock) {
            code = getCustomMethodBody();
        } else {
            code = "\nprivate String call" + getBean().getName() + "Service() {\n"; // NOI18n
            code += getCustomMethodBody() + "\n";
            code += "return "+getResultPattern()+";\n";
            code += "}\n";
        }
        insert(code, true);
    } catch (BadLocationException ex) {
        throw new IOException(ex.getMessage());
    }
}
 
Example 2
/**
 *  Insert the Saas client call
 */
protected void insertSaasServiceAccessCode(boolean isInBlock) throws IOException {
    try {
        String code = "";
        if (isInBlock) {
            code = getCustomMethodBody();
        } else {
            code = "\nprivate String call" + getBean().getName() + "Service() {\n";
            code += getCustomMethodBody() + "\n";
            code += "return " + getResultPattern() + ";\n";
            code += "}\n";
        }
        insert(code, true);
    } catch (BadLocationException ex) {
        throw new IOException(ex.getMessage());
    }
}
 
Example 3
/**
 *  Insert the Saas client call
 */
protected void insertSaasServiceAccessCode(boolean isInBlock) throws IOException {
    try {
        String code = "";
        if (isInBlock) {
            code = getCustomMethodBody();
        } else {
            code = "\nprivate String call" + getBean().getName() + "Service() {\n"; // NOI18n

            code += getCustomMethodBody() + "\n";
            code += "return "+getResultPattern()+";\n";
            code += "}\n";
        }
        insert(code, true);
    } catch (BadLocationException ex) {
        throw new IOException(ex.getMessage());
    }
}
 
Example 4
/**
 *  Create Saas Service
 */
public void createSaasServiceClass() throws IOException {
    DataObject d = Util.createDataObjectFromTemplate(
            getBean().getSaasServiceTemplate()+"."+Constants.PHP_EXT, 
                getSaasServiceFolder(), getBean().getSaasServiceName());
    if(d != null) {
        saasServiceFile = d.getPrimaryFile();
        try {
            Document doc = Util.getDocument(saasServiceFile);
            replaceDocument(doc, "__SAAS_FOLDER__", getSaasFolder().getName());
            replaceDocument(doc, "__CONSTRUCT__", "__construct");
        } catch (BadLocationException ex) {
            throw new IOException(ex.getMessage());
        }
    }
}
 
Example 5
@Override
public Object _makeVisible() {
    JEditorPane editor = (JEditorPane) parent.getComponent();
    try {
        Rectangle bounds = editor.modelToView(pos);
        if (bounds != null) {
            bounds.height = editor.getVisibleRect().height;
            editor.scrollRectToVisible(bounds);
        }
    } catch (BadLocationException e) {
        throw new InvalidElementStateException("Invalid position " + pos + "(" + e.getMessage() + ")", e);
    }
    return null;
}
 
Example 6
@Override
public Point _getMidpoint() {
    JEditorPane editor = (JEditorPane) parent.getComponent();
    try {
        Rectangle bounds = editor.modelToView(pos);
        return new Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
    } catch (BadLocationException e) {
        throw new InvalidElementStateException("Invalid position " + pos + "(" + e.getMessage() + ")", e);
    }
}
 
Example 7
@Override
public void _moveto() {
    JEditorPane editor = (JEditorPane) parent.getComponent();
    try {
        Rectangle bounds = editor.modelToView(pos);
        getDriver().getDevices().moveto(parent.getComponent(), bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
    } catch (BadLocationException e) {
        throw new InvalidElementStateException("Invalid position " + pos + "(" + e.getMessage() + ")", e);
    }
}
 
Example 8
/**
 *  Insert the Saas client call
 */
@Override
protected void insertSaasServiceAccessCode(boolean isInBlock) throws IOException {
    clearVariablePatterns();
    addVariablePattern(J2eeUtil.JSP_NAMES_PAGE, 1);
    try {
        String code = "";
        code += J2eeUtil.getJspImports(getTargetDocument(), getStartPosition(), 
                getBean().getSaasServicePackageName());
        code += J2eeUtil.wrapWithTag(getCustomMethodBody(), getTargetDocument(), getStartPosition()) + "\n";
        insert(code, true);
    } catch (BadLocationException ex) {
        throw new IOException(ex.getMessage());
    }
}
 
Example 9
/**
 *  Insert the Saas client call
 */
@Override
protected void insertSaasServiceAccessCode(boolean isInBlock) throws IOException {
    clearVariablePatterns();
    addVariablePattern(J2eeUtil.JSP_NAMES_PAGE, 1);
    try {
        String code = "";
        code += J2eeUtil.getJspImports(getTargetDocument(), getStartPosition(), 
                getBean().getSaasServicePackageName());
        code += J2eeUtil.wrapWithTag(getCustomMethodBody(), getTargetDocument(), getStartPosition()) + "\n";
        insert(code, true);
    } catch (BadLocationException ex) {
        throw new IOException(ex.getMessage());
    }
}
 
Example 10
/**
 *  Insert the Saas client call
 */
@Override
protected void insertSaasServiceAccessCode(boolean isInBlock) throws IOException {
    addVariablePattern(J2eeUtil.JSP_NAMES_PAGE, 1);
    try {
        String code = "";
        code += J2eeUtil.getJspImports(getTargetDocument(), getStartPosition(), 
                getBean().getSaasServicePackageName());
        code += J2eeUtil.wrapWithTag(getCustomMethodBody(), getTargetDocument(), getStartPosition()) + "\n";
        insert(code, true);
    } catch (BadLocationException ex) {
        throw new IOException(ex.getMessage());
    }
}
 
Example 11
@Override
public Set<FileObject> generate() throws IOException {
    try {
        insert(PhpUtil.wrapWithTag(getCustomMethodBody(), getTargetDocument(), getStartPosition()), true);

    } catch (BadLocationException ex) {
        throw new IOException(ex.getMessage());
    }
    return super.generate();
}
 
Example 12
/**
 *  Insert the Saas client call
 */
protected void insertSaasServiceAccessCode(boolean isInBlock) throws IOException {
    try {
        String inclStr = "\ninclude_once \"" + getSaasServiceFolder().getName() + "/" + 
                getBean().getSaasServiceName() + ".php\";\n";
        String code = PhpUtil.wrapWithTag(inclStr+getCustomMethodBody(), getTargetDocument(), getStartPosition()) + "\n";
        insert(code, true);
    } catch (BadLocationException ex) {
        throw new IOException(ex.getMessage());
    }
}
 
Example 13
/**
 *  Return target and generated file objects
 */
protected void addSaasServiceMethod() throws IOException {
    String indent = "        ";
    List<ParameterInfo> filterParams = getServiceMethodParameters();
    final String[] parameters = getGetParamNames(filterParams);
    final Object[] paramTypes = getGetParamTypes(filterParams);
    String paramUse = getHeaderOrParameterUsage(filterParams);

    if (isContainsMethod(saasServiceFile,
            getBean().getSaasServiceMethodName(), parameters, paramTypes)) {
        return;
    }

    String type = REST_RESPONSE;
    String bodyText = "{ \n" + getServiceMethodBody() + "\n"+indent+"}";


    String comment = "\n";// NOI18N

    for (String param : parameters) {
        comment += indent+"@param $PARAM$ resource URI parameter\n".replace("$PARAM$", param);// NOI18N

    }
    comment += indent+"@return an instance of " + type;// NOI18N
    comment = "/*"+comment+"*/";
    
    String code = "\n" + indent + comment + 
            "\n" + indent + "public static function "+
            getBean().getSaasServiceMethodName()+"("+paramUse+")"+
            bodyText+"\n";
    try {
        Document saasServiceDoc = Util.getDocument(saasServiceFile);
        int start = PhpUtil.findText(saasServiceDoc, "}", false);
        int end = start;
        insert(code, start, end, saasServiceDoc, true);
    } catch (BadLocationException ex) {
        throw new IOException(ex.getMessage());
    }
}
 
Example 14
private boolean isContainsMethod(FileObject saasServiceFile, 
        String saasServiceMethodName, String[] parameters, Object[] paramTypes) throws IOException {
    try {
        return PhpUtil.findText(Util.getDocument(saasServiceFile), 
                "public static function "+saasServiceMethodName, true) != -1;
    } catch (BadLocationException ex) {
        throw new IOException(ex.getMessage());
    }
}
 
Example 15
/**
 *  Insert the Saas client call
 */
protected void insertSaasServiceAccessCode(boolean isInBlock) throws IOException {
    try {
        String inclStr = "\ninclude_once \"" + getSaasServiceFolder().getName() + "/" + 
                getBean().getSaasServiceName() + ".php\";\n";
        String code = PhpUtil.wrapWithTag(inclStr+getCustomMethodBody(), getTargetDocument(), getStartPosition()) + "\n";
        insert(code, true);
    } catch (BadLocationException ex) {
        throw new IOException(ex.getMessage());
    }
}
 
Example 16
Source Project: netbeans   File: EditorCaret.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the selected text contained for this
 * <code>Caret</code>.  If the selection is
 * <code>null</code> or the document empty, returns <code>null</code>.
 *
 * @param caret
 * @return the text
 * @exception IllegalArgumentException if the selection doesn't
 *  have a valid mapping into the document for some reason
 */
private String getSelectedText(CaretItem caret) {
    String txt = null;
    int p0 = Math.min(caret.getDot(), caret.getMark());
    int p1 = Math.max(caret.getDot(), caret.getMark());
    if (p0 != p1) {
        try {
            Document doc = component.getDocument();
            txt = doc.getText(p0, p1 - p0);
        } catch (BadLocationException e) {
            throw new IllegalArgumentException(e.getMessage());
        }
    }
    return txt;
}
 
Example 17
public InputStream getCatalogAsStream() throws IOException{
    try {
        String docContent = backendCatalogSwingDocument.getText(0, backendCatalogSwingDocument.getLength());
        InputStream bis = new ByteArrayInputStream(docContent.getBytes());
        logger.finer("In getCatalogAsStream gona return:"+docContent);
        return bis;
    } catch (BadLocationException ex) {
        throw new IOException(ex.getMessage());
    }
}
 
Example 18
Source Project: netbeans   File: DemoTokenUpdater.java    License: Apache License 2.0 5 votes vote down vote up
private String getDocumentText(int offset, int length) {
    try {
        return doc.getText(offset, length);
    } catch (BadLocationException e) {
        throw new IllegalStateException(e.getMessage());
    }
}
 
Example 19
Source Project: netbeans   File: DocumentUtilities.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized char charAt(int index) {
    try {
        doc.getText(index, 1, segment);
    } catch (BadLocationException e) {
        IndexOutOfBoundsException ioobe = new IndexOutOfBoundsException(e.getMessage()
            + " at offset=" + e.offsetRequested()); // NOI18N
        ioobe.initCause(e);
        throw ioobe;
    }
    char ch = segment.array[segment.offset];
    segment.array = null; // Allow GC of large char arrays
    return ch;
}
 
Example 20
Source Project: netbeans   File: Tag.java    License: Apache License 2.0 4 votes vote down vote up
public final void setAttribute(String name, String value) {
        NamedNodeMap attributes = getAttributes();
        Node attr = attributes.getNamedItem(name);
        if (attr != null) {
            attr.setNodeValue(value);
        } else {
            String stringToInsert = " " + name + "=" + '"' + value + '"';
            
            // Get the document and lock it
            BaseDocument doc = (BaseDocument)support.getDocument();
            doc.atomicLock();
            try {            
                // An attribute with the name was not found for the element
                // Let's add it to the end
                int insertStart = offset + length - 1;

                SCAN_LOOP:
                    for (TokenItem next = first().getNext(); next != null; next = next.getNext()) {
                        TokenID id = next.getTokenID();
                        if (id == ARGUMENT) {
                            while (next.getTokenID() != VALUE) {
                                next = next.getNext();
                                if (next == null) break SCAN_LOOP;
                            }

                            if (next == null) break SCAN_LOOP;

                            String image = next.getImage();
                            char test = image.charAt(0);

                            while (next.getTokenID() == VALUE || next.getTokenID() == CHARACTER) {
                                String actualValue = Util.actualAttributeValue(image);
                                if (!actualValue.equals(image)) {
                                    insertStart = next.getOffset() + actualValue.length();
                                    break SCAN_LOOP;
                                }
                                next = next.getNext();
                                if (next == null) break SCAN_LOOP;

                                // Check if this is the last token in the element and set the
                                // insertStart if it is
                                image = next.getImage();
                                insertStart = next.getOffset();
                                if (image.length() > 0 && image.charAt(image.length() - 1) == '>') {
                                    // The element is closing
                                    insertStart += image.length() - 1;
                                    if (image.length() > 1 && image.charAt(image.length() - 2) == '/') {
                                        // We have a closed element at the form <blu/>
                                        insertStart--;
                                    }
                                }
                            }

                            if (next == null) break SCAN_LOOP;
                        } else if (id == WS) {
                            // just skip
                        } else {
                            break; // end of element markup
                        }
                    }
                
                    doc.insertString(insertStart, stringToInsert, null);
                    doc.invalidateSyntaxMarks();
                } catch( BadLocationException e ) {
                    throw new DOMException(DOMException.INVALID_STATE_ERR , e.getMessage());
                } finally {
                    doc.atomicUnlock();
                }
        }
        
        // Update this object's member variables
//        retokenizeObject();
    }