本文整理汇总了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();
}
示例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();
}
示例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));
}