private static int getNSVisualPosition(EditorPane txt, int pos, int direction) { Element root = txt.getDocument().getDefaultRootElement(); int numLines = root.getElementIndex(txt.getDocument().getLength() - 1) + 1; int line = root.getElementIndex(pos) + 1; int tarLine = direction == SwingConstants.NORTH ? line - 1 : line + 1; try { if (tarLine <= 0) { return 0; } if (tarLine > numLines) { return txt.getDocument().getLength(); } Rectangle curRect = txt.modelToView(pos); Rectangle tarEndRect; if (tarLine < numLines) { tarEndRect = txt.modelToView(txt.getLineStartOffset(tarLine) - 1); } else { tarEndRect = txt.modelToView(txt.getDocument().getLength() - 1); } Debug.log(9, "curRect: " + curRect + ", tarEnd: " + tarEndRect); if (curRect.x > tarEndRect.x) { pos = txt.viewToModel(new Point(tarEndRect.x, tarEndRect.y)); } else { pos = txt.viewToModel(new Point(curRect.x, tarEndRect.y)); } } catch (BadLocationException e) { Debug.error(me + "Problem getting next visual position\n%s", e.getMessage()); } return pos; }
@Override public boolean importData(JComponent comp, Transferable t) { DataFlavor htmlFlavor = DataFlavor.stringFlavor; if (canImport(comp, t.getTransferDataFlavors())) { try { String transferString = (String) t.getTransferData(htmlFlavor); EditorPane targetTextPane = (EditorPane) comp; for (Map.Entry<String, String> entry : _copiedImgs.entrySet()) { String imgName = entry.getKey(); String imgPath = entry.getValue(); File destFile = targetTextPane.copyFileToBundle(imgPath); String newName = destFile.getName(); if (!newName.equals(imgName)) { String ptnImgName = "\"" + imgName + "\""; newName = "\"" + newName + "\""; transferString = transferString.replaceAll(ptnImgName, newName); Debug.info(ptnImgName + " exists. Rename it to " + newName); } } targetTextPane.insertString(transferString); } catch (Exception e) { Debug.error(me + "importData: Problem pasting text\n%s", e.getMessage()); } return true; } return false; }
public void setPage(URL url) throws IOException { // If we haven't created a peer yet, force us to use a browser, since // setPage is really aimed at HTML. if (!SwingWTUtils.isSWTControlAvailable(editorPaneImpl.getSWTPeer())) { loadBrowserEditorPane(); } editorPaneImpl.setPage(url); }
public void setSelectionColor(Color color) { editorPaneImpl.setSelectionColor(color); }
public void setEditorKit(EditorKit k) { editorPaneImpl.setEditorKit(k); }
public EditorKit getEditorKit() { return editorPaneImpl.getEditorKit(); }
public boolean isEditable() { return editorPaneImpl.isEditable(); }
public void setText(String text) { editorPaneImpl.setText(text); }
/** * Once a parent component receives an "add" call for a child, this being the child, this should * be called to tell us to instantiate the peer and load in any cached properties. */ public void setSwingWTParent(swingwt.awt.Container parent) throws Exception { descendantHasPeer = true; editorPaneImpl.setSwingWTParent(parent); peer = editorPaneImpl.getSWTPeer(); }
public void removeHyperlinkListener(swingwtx.swing.event.HyperlinkListener l) { editorPaneImpl.removeHyperlinkListener(l); }
public void addHyperlinkListener(swingwtx.swing.event.HyperlinkListener l) { editorPaneImpl.addHyperlinkListener(l); }
public Document getDocument() { return editorPaneImpl.getDocument(); }
public void setDocument(Document newdoc) { editorPaneImpl.setDocument(newdoc); }
public void setEditable(boolean b) { editorPaneImpl.setEditable(b); }
public Color getSelectionColor() { return editorPaneImpl.getSelectionColor(); }
public void scrollToReference(String reference) { editorPaneImpl.scrollToReference(reference); }
public void setCaretPosition(int pos) { editorPaneImpl.setCaretPosition(pos); }
public String getText() { return editorPaneImpl.getText(); }
public int getCaretPosition() { return editorPaneImpl.getCaretPosition(); }
public String getContentType() { return editorPaneImpl.getContentType(); }
public int getSelectionStart() { return editorPaneImpl.getSelectionStart(); }
public int getSelectionEnd() { return editorPaneImpl.getSelectionEnd(); }
public void setContentType(String contentType) { editorPaneImpl.setContentType(contentType); }