/** * Returns the bounds of a child view as a rectangle, since * <code>View</code>s tend to use <code>Shape</code>. * * @param parent The parent view of the child whose bounds we're getting. * @param line The index of the child view. * @param editorRect Returned from the text area's * <code>getVisibleEditorRect</code> method. * @return The child view's bounds. */ protected static final Rectangle getChildViewBounds(View parent, int line, Rectangle editorRect) { Shape alloc = parent.getChildAllocation(line, editorRect); if (alloc==null) { // WrappedSyntaxView can have this when made so small it's // no longer visible return new Rectangle(); } return alloc instanceof Rectangle ? (Rectangle)alloc : alloc.getBounds(); }
/** * Returns the bounds of a child view as a rectangle, since * <code>View</code>s tend to use <code>Shape</code>. * * @param parent The parent view of the child whose bounds we're getting. * @param line The index of the child view. * @param editorRect Returned from the text area's * <code>getVisibleEditorRect</code> method. * @return The child view's bounds. */ protected static final Rectangle getChildViewBounds(View parent, int line, Rectangle editorRect) { Shape alloc = parent.getChildAllocation(line, editorRect); return alloc instanceof Rectangle ? (Rectangle)alloc : alloc.getBounds(); }
/** * Returns the bounds of a child view as a rectangle, since * <code>View</code>s tend to use <code>Shape</code>. * * @param parent The parent view of the child whose bounds we're getting. * @param line The index of the child view. * @param editorRect Returned from the text area's * <code>getVisibleEditorRect</code> method. * @return The child view's bounds. */ protected static final Rectangle getChildViewBounds(View parent, int line, Rectangle editorRect) { Shape alloc = parent.getChildAllocation(line, editorRect); return alloc instanceof Rectangle ? (Rectangle)alloc : alloc.getBounds(); }
/** * Returns the bounds of a child view as a rectangle, since * <code>View</code>s tend to use <code>Shape</code>. * * @param parent The parent view of the child whose bounds we're getting. * @param line The index of the child view. * @param editorRect Returned from the text area's * <code>getVisibleEditorRect</code> method. * @return The child view's bounds. */ protected static final Rectangle getChildViewBounds(View parent, int line, Rectangle editorRect) { Shape alloc = parent.getChildAllocation(line, editorRect); if (alloc==null) { // WrappedSyntaxView can have this when made so small it's // no longer visible return new Rectangle(); } return alloc instanceof Rectangle ? (Rectangle)alloc : alloc.getBounds(); }
protected static Shape getAllocation(View v, JEditorPane edit) { Insets ins = edit.getInsets(); View vParent = v.getParent(); int x = ins.left; int y = ins.top; while (vParent != null) { int i = vParent.getViewIndex(v.getStartOffset(), Position.Bias.Forward); Shape alloc = vParent.getChildAllocation(i, new Rectangle(0, 0, Short.MAX_VALUE, Short.MAX_VALUE)); x += alloc.getBounds().x; y += alloc.getBounds().y; vParent = vParent.getParent(); } return new Rectangle(x, y, (int) v.getPreferredSpan(View.X_AXIS), (int) v.getPreferredSpan(View.Y_AXIS)); } }
MouseListener sentenceCollapse = new MouseAdapter() { public void mouseClicked(MouseEvent e) { JEditorPane src = (JEditorPane)e.getSource(); View v = src.getUI().getRootView(src); Insets ins = src.getInsets(); int x = ins.left; int y = ins.top; Point p = e.getPoint(); p.translate(-x, -y); Rectangle alloc = new Rectangle(0,0,Short.MAX_VALUE,Short.MAX_VALUE); while (v != null && !(v instanceof SentenceView)) { View vChild = null; int n = v.getViewCount(); for (int i = 0; i < n; i++) { Rectangle r = v.getChildAllocation(i, alloc).getBounds(); if (r.contains(p)) { vChild = v.getView(i); alloc = (Rectangle) r.clone(); } } v = vChild; } if (v != null && v instanceof SentenceView) { <<< unfold or fold the Sentence View >>> src.repaint(); } };
childAllocation = view.getChildAllocation(i,allocation); if (childAllocation != null) { childView = view.getView(i);
childAllocation = view.getChildAllocation(i, allocation); if (childAllocation != null) { childView = view.getView(i);
childAllocation = view.getChildAllocation(i,allocation); if (childAllocation != null) { childView = view.getView(i);
Shape childBounds = v.getChildAllocation(childIndex, alloc); retValue = child.getNextVisualPositionFrom(pos, b, childBounds, direction, biasRet); childBounds = v.getChildAllocation(1, alloc); retValue = child.getNextVisualPositionFrom(-1, biasRet[0], childBounds, Shape childBounds = v.getChildAllocation(childIndex, alloc); retValue = child.getNextVisualPositionFrom(pos, b, childBounds, direction, biasRet); childIndex < v.getViewCount()) { child = v.getView(childIndex); childBounds = v.getChildAllocation(childIndex, alloc); retValue = child.getNextVisualPositionFrom( -1, b, childBounds, direction, biasRet); childBounds = v.getChildAllocation(childIndex, alloc); Position.Bias originalBias = biasRet[0]; int nextPos = child.getNextVisualPositionFrom(