當前位置: 首頁>>代碼示例>>Java>>正文


Java JViewport.getSize方法代碼示例

本文整理匯總了Java中javax.swing.JViewport.getSize方法的典型用法代碼示例。如果您正苦於以下問題:Java JViewport.getSize方法的具體用法?Java JViewport.getSize怎麽用?Java JViewport.getSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JViewport的用法示例。


在下文中一共展示了JViewport.getSize方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: showPopup

import javax.swing.JViewport; //導入方法依賴的package包/類
private void showPopup(Set<AppearancePort> portObjects) {
	dragStart = null;
	CircuitState circuitState = canvas.getCircuitState();
	if (circuitState == null)
		return;
	ArrayList<Instance> ports = new ArrayList<Instance>(portObjects.size());
	for (AppearancePort portObject : portObjects) {
		ports.add(portObject.getPin());
	}

	hideCurrentPopup();
	LayoutThumbnail layout = new LayoutThumbnail();
	layout.setCircuit(circuitState, ports);
	JViewport owner = canvasPane.getViewport();
	Point ownerLoc = owner.getLocationOnScreen();
	Dimension ownerDim = owner.getSize();
	Dimension layoutDim = layout.getPreferredSize();
	int x = ownerLoc.x + Math.max(0, ownerDim.width - layoutDim.width - 5);
	int y = ownerLoc.y + Math.max(0, ownerDim.height - layoutDim.height - 5);
	PopupFactory factory = PopupFactory.getSharedInstance();
	Popup popup = factory.getPopup(canvasPane.getViewport(), layout, x, y);
	popup.show();
	curPopup = popup;
	curPopupTime = System.currentTimeMillis();
}
 
開發者ID:LogisimIt,項目名稱:Logisim,代碼行數:26,代碼來源:LayoutPopupManager.java

示例2: recalculateCellSize

import javax.swing.JViewport; //導入方法依賴的package包/類
/**
 * Calculate the cell size to use given the current viewable region and the
 * the number of rows and columns in the grid. We use the largest
 * cellSize that will fit in the viewable region, bounded to be at least the
 * parameter minSize.
 */
private void recalculateCellSize(int minSize) {
    if (numRows == 0 || numCols == 0) {
        cellSize = 0;
    } else {
        JViewport vp = getEnclosingViewport();
        Dimension viewableSize = (vp != null) ? vp.getSize() : getSize();
        int desiredCellSize = Math.min(
                (viewableSize.height - extraHeight()) / numRows,
                (viewableSize.width - extraWidth()) / numCols) - 1;
        // now we want to approximate this with
        // DEFAULT_CELL_SIZE * Math.pow(2, k)
        cellSize = DEFAULT_CELL_SIZE;
        if (cellSize <= desiredCellSize)
            while (2 * cellSize <= desiredCellSize)
                cellSize *= 2;
        else
            while (cellSize / 2 >= Math.max(desiredCellSize, MIN_CELL_SIZE))
                cellSize /= 2;
    }
    revalidate();
}
 
開發者ID:CBSkarmory,項目名稱:AWGW,代碼行數:28,代碼來源:GridPanel.java

示例3: 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.getSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。