本文整理匯總了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;
}
示例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);
}
}
}
示例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()};
}
示例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))
);
}
}
示例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);
}
}
示例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");
}
}
示例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)
);
}
}
示例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
}
示例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));
}
示例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;
}
示例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;
}
示例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());
}
示例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);
}
示例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]);
}
}
示例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));
}