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


Java JComponent.getVisibleRect方法代码示例

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


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

示例1: scroll

import javax.swing.JComponent; //导入方法依赖的package包/类
/**
 * Scroll to specified location. e.g.
 * <tt>scroll(component, LEFT, BOTTOM);</tt>.
 *
 * @param c
 *            JComponent to scroll.
 * @param horizontal
 *            Horizontal location. Should take the value: LEFT, HCENTER or
 *            RIGHT.
 * @param vertical
 *            Vertical location. Should take the value: TOP, VCENTER or
 *            BOTTOM.
 */
public static void scroll(JComponent c, int horizontal, int vertical){
	Rectangle visible=c.getVisibleRect();
	Rectangle bounds=c.getBounds();
	
	switch(vertical){
	case TOP:
		visible.y=0;
		break;
	case VCENTER:
		visible.y=(bounds.height-visible.height)/2;
		break;
	case BOTTOM:
		visible.y=bounds.height-visible.height+OFFSET;
		break;
	}
	
	switch(horizontal){
	case LEFT:
		visible.x=0;
		break;
	case HCENTER:
		visible.x=(bounds.width-visible.width)/2;
		break;
	case RIGHT:
		visible.x=bounds.width-visible.width+OFFSET;
		break;
	}
	
	// When scrolling to bottom or right of viewport, add an OFFSET value.
	// This is because without this certain components (e.g. JTable) would
	// not scroll right to the bottom (presumably the bounds calculation
	// doesn't take the table header into account.  It doesn't matter if
	// OFFSET is a huge value (e.g. 10000) - the scrollRectToVisible method
	// still works correctly.
	
	c.scrollRectToVisible(visible);
}
 
开发者ID:LapisSea,项目名称:OpenGL-Bullet-engine,代码行数:51,代码来源:ScrollUtil.java

示例2: tick

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override public void tick(double progress) {
    double nextZoom = progress >= 1.0 ? targetZoom :
        (sourceZoom + progress * (targetZoom - sourceZoom));

    Scene scene = getScene();
    JComponent view = scene.getView ();

    if (view != null) {
        Point viewLocation = view.getVisibleRect ().getLocation();
        Dimension viewSize = view.getVisibleRect ().getSize();
        Point oldCenter = scene.convertSceneToView (center);

        ((DependencyGraphScene)scene).setMyZoomFactor (nextZoom);
        scene.validate (); // HINT - forcing to change preferred size of the JComponent view

        Point newCenter = scene.convertSceneToView (center);
        Rectangle viewBounds = view.getVisibleRect();
        Point visibleCenter = new Point((int)viewBounds.getCenterX(), (int)viewBounds.getCenterY());
        newCenter.x += Math.round((newCenter.x - visibleCenter.x) * progress);
        newCenter.y += Math.round((newCenter.y - visibleCenter.y) * progress);

        view.scrollRectToVisible (new Rectangle (
                newCenter.x - oldCenter.x + viewLocation.x,
                newCenter.y - oldCenter.y + viewLocation.y,
                viewSize.width,
                viewSize.height
        ));
    } else {
        ((DependencyGraphScene)scene).setMyZoomFactor (nextZoom);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:CenteredZoomAnimator.java

示例3: moveVisibleRect

import javax.swing.JComponent; //导入方法依赖的package包/类
private void moveVisibleRect(Point center) {
    JComponent component = scene.getView();
    if (component == null) {
        return;
    }
    double zoomFactor = scene.getZoomFactor();
    Rectangle bounds = scene.getBounds();
    Dimension size = getSize();

    double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0;
    double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0;
    double scale = Math.min(sx, sy);

    int vw = (int) (scale * bounds.width);
    int vh = (int) (scale * bounds.height);
    int vx = (size.width - vw) / 2;
    int vy = (size.height - vh) / 2;

    int cx = (int) ((double) (center.x - vx) / scale * zoomFactor);
    int cy = (int) ((double) (center.y - vy) / scale * zoomFactor);

    Rectangle visibleRect = component.getVisibleRect();
    visibleRect.x = cx - visibleRect.width / 2;
    visibleRect.y = cy - visibleRect.height / 2;
    component.scrollRectToVisible(visibleRect);

    this.repaint();
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:29,代码来源:ExtendedSatelliteComponent.java

示例4: pan

import javax.swing.JComponent; //导入方法依赖的package包/类
private boolean pan (Widget widget, Point newLocation) {
    if (scrollPane == null  ||  scene != widget.getScene ())
        return false;
    newLocation = scene.convertSceneToView (widget.convertLocalToScene (newLocation));
    SwingUtilities.convertPointToScreen (newLocation, scene.getView ());
    JComponent view = scene.getView ();
    Rectangle rectangle = view.getVisibleRect ();
    rectangle.x += lastLocation.x - newLocation.x;
    rectangle.y += lastLocation.y - newLocation.y;
    view.scrollRectToVisible (rectangle);
    lastLocation = newLocation;
    return true;
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:14,代码来源:CustomizablePanAction.java

示例5: moveVisibleRect

import javax.swing.JComponent; //导入方法依赖的package包/类
private void moveVisibleRect(Point center) {
    JComponent component = scene.getView();
    if (component == null) {
        return;
    }
    double zoomFactor = scene.getZoomFactor();
    Rectangle bounds = scene.getBounds();
    Dimension size = getSize();

    double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0;
    double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0;
    double scale = Math.min(sx, sy);

    int vw = (int) (scale * bounds.width);
    int vh = (int) (scale * bounds.height);
    int vx = (size.width - vw) / 2;
    int vy = (size.height - vh) / 2;

    int cx = (int) ((double) (center.x - vx) / scale * zoomFactor);
    int cy = (int) ((double) (center.y - vy) / scale * zoomFactor);

    Rectangle visibleRect = component.getVisibleRect();
    visibleRect.x = cx - visibleRect.width / 2;
    visibleRect.y = cy - visibleRect.height / 2;
    component.scrollRectToVisible(visibleRect);

}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:28,代码来源:ExtendedSatelliteComponent.java

示例6: centerSelection

import javax.swing.JComponent; //导入方法依赖的package包/类
private void centerSelection() {
    Point sceneCenter = null;
    Collection<CfgNode> nodes = this.selectedNodes;
    if (nodes.size() == 0) {
        nodes = this.getNodes();
    }

    for (CfgNode n : nodes) {
        if (sceneCenter == null) {
            sceneCenter = this.findWidget(n).getLocation();
            continue;
        }
        Point location = this.findWidget(n).getLocation();
        sceneCenter.x = (location.x + sceneCenter.x) / 2;
        sceneCenter.y = (location.y + sceneCenter.y) / 2;
    }

    JComponent view = this.getView();
    if (view != null) {
        Rectangle viewBounds = view.getVisibleRect();

        Point viewCenter = this.convertSceneToView(sceneCenter);

        view.scrollRectToVisible(new Rectangle(
                viewCenter.x - viewBounds.width / 2,
                viewCenter.y - viewBounds.height / 2,
                viewBounds.width,
                viewBounds.height));
    }
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:31,代码来源:CfgScene.java

示例7: paint

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
    Graphics2D gr = (Graphics2D) g;
    super.paint(g);
    Rectangle bounds = scene.getBounds();
    Dimension size = getSize();

    double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0;
    double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0;
    double scale = Math.min(sx, sy);

    int vw = (int) (scale * bounds.width);
    int vh = (int) (scale * bounds.height);
    int vx = (size.width - vw) / 2;
    int vy = (size.height - vh) / 2;


    if (image == null || vw != imageWidth || vh != imageHeight) {

        imageWidth = vw;
        imageHeight = vh;
        image = this.createImage(imageWidth, imageHeight);
        Graphics2D ig = (Graphics2D) image.getGraphics();
        ig.scale(scale, scale);
 double oldFactor = scene.getZoomFactor();
 scene.setZoomFactor(scale);
        scene.paint(ig);
 scene.setZoomFactor(oldFactor);
    }

    gr.drawImage(image, vx, vy, this);

    JComponent component = scene.getView();
    double zoomFactor = scene.getZoomFactor();
    Rectangle viewRectangle = component != null ? component.getVisibleRect() : null;
    if (viewRectangle != null) {
        Rectangle window = new Rectangle(
                (int) ((double) viewRectangle.x * scale / zoomFactor),
                (int) ((double) viewRectangle.y * scale / zoomFactor),
                (int) ((double) viewRectangle.width * scale / zoomFactor),
                (int) ((double) viewRectangle.height * scale / zoomFactor));
        window.translate(vx, vy);
        gr.setColor(new Color(200, 200, 200, 128));
        gr.fill(window);
        gr.setColor(Color.BLACK);
        gr.drawRect(window.x, window.y, window.width - 1, window.height - 1);
    }
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:49,代码来源:ExtendedSatelliteComponent.java

示例8: paint

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
    Graphics2D gr = (Graphics2D) g;
    super.paint(g);
    Rectangle bounds = scene.getBounds();
    Dimension size = getSize();

    double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0;
    double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0;
    double scale = Math.min(sx, sy);

    int vw = (int) (scale * bounds.width);
    int vh = (int) (scale * bounds.height);
    int vx = (size.width - vw) / 2;
    int vy = (size.height - vh) / 2;


    if (image == null || vw != imageWidth || vh != imageHeight) {

        imageWidth = vw;
        imageHeight = vh;
        image = this.createImage(imageWidth, imageHeight);
        Graphics2D ig = (Graphics2D) image.getGraphics();
        ig.scale(scale, scale);
        scene.paint(ig);
    }

    gr.drawImage(image, vx, vy, this);

    JComponent component = scene.getView();
    double zoomFactor = scene.getZoomFactor();
    Rectangle viewRectangle = component != null ? component.getVisibleRect() : null;
    if (viewRectangle != null) {
        Rectangle window = new Rectangle(
                (int) ((double) viewRectangle.x * scale / zoomFactor),
                (int) ((double) viewRectangle.y * scale / zoomFactor),
                (int) ((double) viewRectangle.width * scale / zoomFactor),
                (int) ((double) viewRectangle.height * scale / zoomFactor));
        window.translate(vx, vy);
        gr.setColor(new Color(200, 200, 200, 128));
        gr.fill(window);
        gr.setColor(Color.BLACK);
        gr.drawRect(window.x, window.y, window.width - 1, window.height - 1);
    }
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:46,代码来源:ExtendedSatelliteComponent.java

示例9: paint

import javax.swing.JComponent; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
    Graphics2D gr = (Graphics2D) g;
    super.paint(g);
    Rectangle bounds = scene.getBounds();
    Dimension size = getSize();

    double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0;
    double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0;
    double scale = Math.min(sx, sy);

    int vw = (int) (scale * bounds.width);
    int vh = (int) (scale * bounds.height);
    int vx = (size.width - vw) / 2;
    int vy = (size.height - vh) / 2;


    if (image == null || vw != imageWidth || vh != imageHeight) {
        imageWidth = vw;
        imageHeight = vh;
        image = this.createImage(imageWidth, imageHeight);
        Graphics2D ig = (Graphics2D) image.getGraphics();
        ig.scale(scale, scale);
        double oldFactor = scene.getZoomFactor();
        scene.setZoomFactor(scale);
        scene.paint(ig);
        scene.setZoomFactor(oldFactor);
    }

    gr.drawImage(image, vx, vy, this);

    JComponent component = scene.getView();
    double zoomFactor = scene.getZoomFactor();
    Rectangle viewRectangle = component != null ? component.getVisibleRect() : null;
    if (viewRectangle != null) {
        Rectangle window = new Rectangle(
                (int) ((double) viewRectangle.x * scale / zoomFactor),
                (int) ((double) viewRectangle.y * scale / zoomFactor),
                (int) ((double) viewRectangle.width * scale / zoomFactor),
                (int) ((double) viewRectangle.height * scale / zoomFactor));
        window.translate(vx, vy);
        gr.setColor(new Color(200, 200, 200, 128));
        gr.fill(window);
        gr.setColor(Color.BLACK);
        gr.drawRect(window.x, window.y, window.width - 1, window.height - 1);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:ExtendedSatelliteComponent.java


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