当前位置: 首页>>代码示例>>Java>>正文


Java JViewport.getViewPosition方法代码示例

本文整理汇总了Java中javax.swing.JViewport.getViewPosition方法的典型用法代码示例。如果您正苦于以下问题:Java JViewport.getViewPosition方法的具体用法?Java JViewport.getViewPosition怎么用?Java JViewport.getViewPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JViewport的用法示例。


在下文中一共展示了JViewport.getViewPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getExtentBounds

import javax.swing.JViewport; //导入方法依赖的package包/类
/** Get position of the component extent. The (x, y) are set to (0, 0) if there's
* no viewport or (-x, -y) if there's one.
*/
public Rectangle getExtentBounds(Rectangle r) {
    if (r == null) {
        r = new Rectangle();
    }
    if (component != null) {
        JViewport port = getParentViewport();
        if (port != null) {
            Point p = port.getViewPosition();
            r.width = port.getWidth();
            r.height = port.getHeight();
            r.x = p.x;
            r.y = p.y;
        } else { // no viewport
            r.setBounds(component.getVisibleRect());
        }
    }
    return r;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:EditorUI.java

示例2: changed

import javax.swing.JViewport; //导入方法依赖的package包/类
private void changed() {
    JViewport viewport = sp.getViewport();
    Point viewPosition = viewport.getViewPosition();
    if (viewPosition.x > 0) {
        try {
            Rectangle textRect = editorPane.getUI().modelToView(editorPane, editorPane.getDocument().getLength());
            int textLength = textRect.x + textRect.width;
            int viewLength = viewport.getExtentSize().width;
            //System.out.println("Utilities.createSingleLineEditor(): spLength = "+sp.getSize().width+", viewLength = "+viewLength+", textLength = "+textLength+", viewPosition = "+viewPosition);
            if (textLength < (viewPosition.x + viewLength)) {
                viewPosition.x = Math.max(textLength - viewLength, 0);
                viewport.setViewPosition(viewPosition);
                //System.out.println("Utilities.createSingleLineEditor(): setting new view position = "+viewPosition);
            }
        } catch (BadLocationException blex) {
            Exceptions.printStackTrace(blex);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:Utilities.java

示例3: computeVisibleSpan

import javax.swing.JViewport; //导入方法依赖的package包/类
private int[] computeVisibleSpan() {
    Component parent = pane.getParent();
    
    if (parent instanceof JLayeredPane) {
        parent = parent.getParent();
    }

    if (parent instanceof JViewport) {
        JViewport vp = (JViewport) parent;

        Point start = vp.getViewPosition();
        Dimension size = vp.getExtentSize();
        Point end = new Point((int) (start.getX() + size.getWidth()), (int) (start.getY() + size.getHeight()));

        int startPosition = pane.viewToModel(start);
        int endPosition = pane.viewToModel(end);

        if (parentWithListener != vp) {
            vp.addChangeListener(WeakListeners.change(this, vp));
            parentWithListener = vp;
        }
        return new int[] {startPosition, endPosition};
    }

    return new int[] {0, pane.getDocument().getLength()};
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ComponentPeer.java

示例4: autoscroll

import javax.swing.JViewport; //导入方法依赖的package包/类
/** notify the Component to autoscroll */
public void autoscroll(Point cursorLoc) {
    JViewport viewport = getViewport();
    Point viewPos = viewport.getViewPosition();
    int viewHeight = viewport.getExtentSize().height;

    if ((cursorLoc.y - viewPos.y) <= realInsets.top) {
        // scroll up
        viewport.setViewPosition(new Point(viewPos.x, Math.max(viewPos.y - realInsets.top, 0)));
    } else if (((viewPos.y + viewHeight) - cursorLoc.y) <= realInsets.bottom) {
        // scroll down
        viewport.setViewPosition(
            new Point(viewPos.x, Math.min(viewPos.y + realInsets.bottom, this.getHeight() - viewHeight))
        );
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:IndexedCustomizer.java

示例5: actionPerformedImpl

import javax.swing.JViewport; //导入方法依赖的package包/类
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
	Container parent = textArea.getParent();
	if (parent instanceof JViewport) {
		JViewport viewport = (JViewport)parent;
		Point p = viewport.getViewPosition();
		p.y += delta*textArea.getLineHeight();
		if (p.y<0) {
			p.y = 0;
		}
		else {
			Rectangle viewRect = viewport.getViewRect();
			int visibleEnd = p.y + viewRect.height;
			if (visibleEnd>=textArea.getHeight()) {
				p.y = textArea.getHeight() - viewRect.height;
			}
		}
		viewport.setViewPosition(p);
	}
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:21,代码来源:RTextAreaEditorKit.java

示例6: validateThird

import javax.swing.JViewport; //导入方法依赖的package包/类
public void validateThird() {
    JViewport viewport = this.pane.getViewport();
    JScrollBar scroller = this.pane.getHorizontalScrollBar();
    if (!scroller.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
        throw new Error("unexpected component orientation");
    }
    int value = scroller.getValue();
    if (value != 0) {
        throw new Error("unexpected scroll value");
    }
    int extent = viewport.getExtentSize().width;
    if (extent != scroller.getVisibleAmount()) {
        throw new Error("unexpected visible amount");
    }
    int size = viewport.getViewSize().width;
    if (size != scroller.getMaximum()) {
        throw new Error("unexpected maximum");
    }
    int pos = size - extent - value;
    if (pos != viewport.getViewPosition().x) {
        throw new Error("unexpected position");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:Test6526631.java

示例7: autoscroll

import javax.swing.JViewport; //导入方法依赖的package包/类
/** Performs autoscroll operation.
*/
public void autoscroll(Point cursorLoc) {
    JViewport viewport = getViewport();

    if (viewport == null) {
        return;
    }

    Point viewPos = viewport.getViewPosition();
    int viewHeight = viewport.getExtentSize().height;
    int viewWidth = viewport.getExtentSize().width;

    // perform scrolling
    if ((cursorLoc.y - viewPos.y) < insets.top) {
        // scroll up
        viewport.setViewPosition(new Point(viewPos.x, Math.max(viewPos.y - scrollUnits.top, 0)));
    } else if (((viewPos.y + viewHeight) - cursorLoc.y) < insets.bottom) {
        // scroll down
        viewport.setViewPosition(
            new Point(viewPos.x, Math.min(viewPos.y + scrollUnits.bottom, comp.getHeight() - viewHeight))
        );
    } else if ((cursorLoc.x - viewPos.x) < insets.left) {
        // scroll left
        viewport.setViewPosition(new Point(Math.max(viewPos.x - scrollUnits.left, 0), viewPos.y));
    } else if (((viewPos.x + viewWidth) - cursorLoc.x) < insets.right) {
        // scroll right
        viewport.setViewPosition(
            new Point(Math.min(viewPos.x + scrollUnits.right, comp.getWidth() - viewWidth), viewPos.y)
        );
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:AutoscrollSupport.java

示例8: adjustTreeScrollBar

import javax.swing.JViewport; //导入方法依赖的package包/类
private void adjustTreeScrollBar(int treeViewWidth) {
    DebugTreeView tView = getTreeView();
    if (tView == null) {
        scrollBarPanel.setVisible(false);
        return;
    }
    JViewport viewport = tView.getViewport();
    Point point = viewport.getViewPosition();
    if (point.y < 0) {
        viewport.setViewPosition(new Point(point.x, 0));
    }
    Dimension viewSize = viewport.getExtentSize();
    Dimension treeSize = viewport.getViewSize();
    if (treeViewWidth < 0) {
        treeViewWidth = treeSize.width;
    }
    int unitHeight = tView.getUnitHeight();
    if (unitHeight > 0) {
        JScrollBar sbar = mainScrollPane.getVerticalScrollBar();
        if (sbar.getUnitIncrement() != unitHeight) {
            sbar.setUnitIncrement(unitHeight);
        }
    }
    if (treeViewWidth <= viewSize.width) {
        scrollBarPanel.setVisible(false);
    } else {
        treeScrollBar.setMaximum(treeViewWidth);
        treeScrollBar.setVisibleAmount(viewSize.width);
        if (unitHeight > 0) {
            treeScrollBar.setUnitIncrement(unitHeight / 2);
        }
        treeScrollBar.setBlockIncrement(viewSize.width);
        scrollBarPanel.setVisible(true);
    } // else
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:DebuggingViewComponent.java

示例9: adjustmentValueChanged

import javax.swing.JViewport; //导入方法依赖的package包/类
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
    DebugTreeView tView = getTreeView();
    if (tView == null) {
        return;
    }
    JViewport viewport = tView.getViewport();
    Point position = viewport.getViewPosition();
    viewport.setViewPosition(new Point(e.getValue(), position.y));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:DebuggingViewComponent.java

示例10: getTriangle

import javax.swing.JViewport; //导入方法依赖的package包/类
/**
 *
 * Generates a polygon like this :
 *
 *   /|
 *  / |
 * ----
 *
 * This triangle represents the triangle for the bottom right corner of the
 * viewport.
 *
 * @return the triangle
 */

private Polygon getTriangle() {
    JViewport viewport = getScrollPane().getViewport();
    //get bounds of viewport
    Rectangle bounds = viewport.getBounds();
    //position of viewport relative to text area.
    Point viewportPosition = viewport.getViewPosition();
    int w = viewportPosition.x + bounds.width;
    int h = viewportPosition.y + bounds.height;
    int[] xs = {w, w, w - triangleSize};
    int[] ys = {h - triangleSize, h, h};
    Polygon polygon = new Polygon(xs, ys, 3);
    return polygon;
}
 
开发者ID:Panzer1119,项目名称:JAddOn,代码行数:28,代码来源:JExpandableTextArea.java

示例11: toViewportChildLocalSpace

import javax.swing.JViewport; //导入方法依赖的package包/类
private static Point toViewportChildLocalSpace( JViewport v, Point inViewportParentSpace )
{
    Point l = toLocalSpace(v, inViewportParentSpace);
    Point p = v.getViewPosition();
    l.x += p.x;
    l.y += p.y;
    return l;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:XTextAreaPeer.java

示例12: showPanTip

import javax.swing.JViewport; //导入方法依赖的package包/类
/**
 * Shows a tool tip over the upper left corner of the viewport with the
 * contents of the pannable view's pannable tip text (typically a string
 * identifiying the corner point). Tip is removed after a short delay.
 */
public void showPanTip() {
    String tipText = null;
    Point upperLeft = new Point(0, 0);
    JViewport vp = getEnclosingViewport();
    if (!isPannableUnbounded() && vp != null)
        upperLeft = vp.getViewPosition();
    Location loc = locationForPoint(upperLeft);
    if (loc != null)
        tipText = getToolTipText(loc);

    showTip(tipText, getLocation());
}
 
开发者ID:CBSkarmory,项目名称:AWGW,代码行数:18,代码来源:GridPanel.java

示例13: resize

import javax.swing.JViewport; //导入方法依赖的package包/类
/**
 * Forces the table to resize given column.
 */
private void resize(int newWidth, JTable table) {
    int oldWidth = getWidth();
    JTableHeader header = table.getTableHeader();
    if (header == null) {
        return;
    }
    header.setResizingColumn(this);
    final int oldMin = getMinWidth();
    final int oldMax = getMaxWidth();
    setMinWidth(newWidth);
    setMaxWidth(newWidth);
    setWidth(newWidth);
    // The trick is to restore the original values
    // after the table has be layouted. During layout this column
    // has fixed width (by setting min==max==preffered)
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            setMinWidth(oldMin);
            setMaxWidth(oldMax);
        }
    });
    Container container;
    if ((header.getParent() == null) ||
            ((container = header.getParent().getParent()) == null) ||
            !(container instanceof JScrollPane)) {
        header.setResizingColumn(null);
        return;
    }
    
    if (!container.getComponentOrientation().isLeftToRight() &&
            ! header.getComponentOrientation().isLeftToRight()) {
        if (table != null) {
            JViewport viewport = ((JScrollPane)container).getViewport();
            int viewportWidth = viewport.getWidth();
            int diff = newWidth - oldWidth;
            int newHeaderWidth = table.getWidth() + diff;
            
            /* Resize a table */
            Dimension tableSize = table.getSize();
            tableSize.width += diff;
            table.setSize(tableSize);
            
            /* If this table is in AUTO_RESIZE_OFF mode and
             * has a horizontal scrollbar, we need to update
             * a view's position.
             */
            if ((newHeaderWidth >= viewportWidth) &&
                    (table.getAutoResizeMode() == JTable.AUTO_RESIZE_OFF)) {
                Point p = viewport.getViewPosition();
                p.x = Math.max(0, Math.min(newHeaderWidth - viewportWidth, p.x + diff));
                viewport.setViewPosition(p);
            }
        }
    }
    header.setResizingColumn(null);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:61,代码来源:ETableColumn.java

示例14: updateTextInAWT

import javax.swing.JViewport; //导入方法依赖的package包/类
private void updateTextInAWT(EditorCookie es, final String in) throws IOException, BadLocationException {
    StyledDocument tmpdoc = es.getDocument();
    if (tmpdoc == null)
        tmpdoc = es.openDocument();

    //sample editor position

    JEditorPane[] eps = es.getOpenedPanes();
    JEditorPane pane = null;
    JViewport port = null;
    int caretPosition = 0;
    Point viewPosition = null;
    if (eps != null) {
        pane = eps[0];
        caretPosition = pane.getCaretPosition();
        port = getParentViewport (pane);
        if (port != null)
            viewPosition = port.getViewPosition();
    }

    // prepare modification task

    final Exception[] taskEx = new Exception[] {null};
    final StyledDocument sdoc = tmpdoc;

    Runnable task = new Runnable() {
        public void run() {
            try {
                sdoc.remove (0, sdoc.getLength());  // right alternative

                // we are at Unicode level
                sdoc.insertString (0, in, null);
            } catch (Exception iex) {
                taskEx[0] = iex;
            }
        }
    };

    // perform document modification

    org.openide.text.NbDocument.runAtomicAsUser(sdoc, task);

    //??? setModified (true);  

    //restore editor position

    if (eps != null) {
        try {
            pane.setCaretPosition (caretPosition);
        } catch (IllegalArgumentException e) {
        }
        port.setViewPosition (viewPosition);
    }

    if (taskEx[0]!=null) {
        if (taskEx[0] instanceof IOException) {
            throw (IOException)taskEx[0];
        }
        throw new IOException(taskEx[0]);
    }
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:63,代码来源:XMLTextRepresentation.java

示例15: moveLocation

import javax.swing.JViewport; //导入方法依赖的package包/类
/**
 * Moves the current location by a given amount.
 *
 * @param dr the number of rows by which to move the location
 * @param dc the number of columns by which to move the location
 */
public void moveLocation(int dr, int dc) {
    Location newLocation = new Location(currentLocation.getRow() + dr,
            currentLocation.getCol() + dc);
    if (!grid.isValid(newLocation))
        return;

    currentLocation = newLocation;

    JViewport viewPort = getEnclosingViewport();
    if (isPannableUnbounded()) {
        if (originRow > currentLocation.getRow())
            originRow = currentLocation.getRow();
        if (originCol > currentLocation.getCol())
            originCol = currentLocation.getCol();
        Dimension dim = viewPort.getSize();
        int rows = dim.height / (cellSize + 1);
        int cols = dim.width / (cellSize + 1);
        if (originRow + rows - 1 < currentLocation.getRow())
            originRow = currentLocation.getRow() - rows + 1;
        if (originCol + rows - 1 < currentLocation.getCol())
            originCol = currentLocation.getCol() - cols + 1;
    } else if (viewPort != null) {
        int dx = 0;
        int dy = 0;
        Point p = pointForLocation(currentLocation);
        Rectangle locRect = new Rectangle(p.x - cellSize / 2, p.y
                - cellSize / 2, cellSize + 1, cellSize + 1);

        Rectangle viewRect = viewPort.getViewRect();
        if (!viewRect.contains(locRect)) {
            while (locRect.x < viewRect.x + dx)
                dx -= cellSize + 1;
            while (locRect.y < viewRect.y + dy)
                dy -= cellSize + 1;
            while (locRect.getMaxX() > viewRect.getMaxX() + dx)
                dx += cellSize + 1;
            while (locRect.getMaxY() > viewRect.getMaxY() + dy)
                dy += cellSize + 1;

            Point pt = viewPort.getViewPosition();
            pt.x += dx;
            pt.y += dy;
            viewPort.setViewPosition(pt);
        }
    }
    repaint();
    showTip(getToolTipText(currentLocation),
            pointForLocation(currentLocation));
}
 
开发者ID:CBSkarmory,项目名称:AWGW,代码行数:56,代码来源:GridPanel.java


注:本文中的javax.swing.JViewport.getViewPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。