本文整理汇总了Java中java.awt.Rectangle类的典型用法代码示例。如果您正苦于以下问题:Java Rectangle类的具体用法?Java Rectangle怎么用?Java Rectangle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Rectangle类属于java.awt包,在下文中一共展示了Rectangle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: synchronizeSelectedNodes
import java.awt.Rectangle; //导入依赖的package包/类
/** Synchronize the selected nodes from the manager of this Explorer.
*/
final void synchronizeSelectedNodes() {
Node[] arr = manager.getSelectedNodes ();
table.getSelectionModel().clearSelection();
NodeTableModel ntm = (NodeTableModel)table.getModel();
int size = ntm.getRowCount();
int firstSelection = -1;
for (int i = 0; i < size; i++) {
Node n = getNodeFromRow(i);
for (int j = 0; j < arr.length; j++) {
if (n.equals(arr[j])) {
table.getSelectionModel().addSelectionInterval(i, i);
if (firstSelection == -1) {
firstSelection = i;
}
}
}
}
if (firstSelection >= 0) {
Rectangle rect = table.getCellRect(firstSelection, 0, true);
if (!getViewport().getViewRect().contains(rect.getLocation())) {
rect.height = Math.max(rect.height, getHeight() - 30);
table.scrollRectToVisible(rect);
}
}
}
示例2: paint
import java.awt.Rectangle; //导入依赖的package包/类
@Override
public void paint(Graphics g, JComponent c) {
recalculateIfInsetsChanged();
recalculateIfOrientationChanged();
Rectangle clip = g.getClipBounds();
if (!clip.intersects(trackRect) && slider.getPaintTrack()) {
calculateGeometry();
}
if (slider.getPaintTrack() && clip.intersects(trackRect)) {
paintTrack(g);
}
if (slider.hasFocus() && clip.intersects(focusRect)) {
paintFocus(g);
}
// the ticks are now inside the track so they have to be painted each thumb movement
paintTicks(g);
// thumb is always painted due to value below thumb
paintThumb(g);
}
示例3: reSetBounds
import java.awt.Rectangle; //导入依赖的package包/类
@Override
public void reSetBounds() {
PontoElementar[] pontos = getPontos();
int espacoI = distSelecao;
int mW = pontos[0].getWidth() + espacoI;
int mH = pontos[0].getHeight() + espacoI;
int H = pontos[2].getTop() - pontos[0].getTop() - (mH + espacoI);
int W = pontos[2].getLeft() - pontos[0].getLeft() - (mW + espacoI);
int L = pontos[0].getLeft() + mW;
int T = pontos[0].getTop() + mH;
if ((W < 10) || (H < 10)) {
Reposicione();
return;
}
Rectangle ret = new Rectangle(getLeft() - L, getTop() - T, getWidth() - W, getHeight() - H);
DoFormaResize(ret);
}
示例4: getBoundsInRectangle
import java.awt.Rectangle; //导入依赖的package包/类
private Bounds[] getBoundsInRectangle(Rectangle rectangle) {
List<Bounds> list = new ArrayList<Bounds>();
double maxX = untranslate(rectangle.getMaxX());
double minX = untranslate(rectangle.getMinX());
double maxY = untranslate(rectangle.getMaxY());
double minY = untranslate(rectangle.getMinY());
for (Bounds bounds : diagram.getBounds()) {
if ((bounds.getLeft() <= maxX) && (bounds.getLeft() >= minX)
&& (bounds.getRight() <= maxX)
&& (bounds.getRight() >= minX)) {
if ((bounds.getTop() <= maxY) && (bounds.getTop() >= minY)
&& (bounds.getBottom() <= maxY)
&& (bounds.getBottom() >= minY)) {
list.add(bounds);
}
}
}
return list.toArray(new Bounds[list.size()]);
}
示例5: mousePressed
import java.awt.Rectangle; //导入依赖的package包/类
@Override
public void mousePressed(MouseEvent e) {
e.consume();
switch (mode) {
case LINES:
x1 = e.getX();
y1 = e.getY();
x2 = -1;
break;
case POINTS:
default:
colors.add(getForeground());
lines.add(new Rectangle(e.getX(), e.getY(), -1, -1));
x1 = e.getX();
y1 = e.getY();
repaint();
break;
}
}
示例6: paintChildren
import java.awt.Rectangle; //导入依赖的package包/类
void paintChildren(ParagraphView pView, Graphics2D g, Shape pAlloc, Rectangle clipBounds,
int startIndex, int endIndex)
{
while (startIndex < endIndex) {
EditorView view = get(startIndex);
Shape childAlloc = getChildAllocation(startIndex, pAlloc);
if (view.getClass() == NewlineView.class) {
// Extend till end of screen (docView's width)
Rectangle2D.Double childRect = ViewUtils.shape2Bounds(childAlloc);
DocumentView docView = pView.getDocumentView();
// Note that op.getVisibleRect() may be obsolete - it does not incorporate
// possible just performed horizontal scroll while clipBounds already does.
double maxX = Math.max(
Math.max(docView.op.getVisibleRect().getMaxX(), clipBounds.getMaxX()),
childRect.getMaxX()
);
childRect.width = (maxX - childRect.x);
childAlloc = childRect;
}
view.paint(g, childAlloc, clipBounds);
startIndex++;
}
}
示例7: fitWESN
import java.awt.Rectangle; //导入依赖的package包/类
public static double[] fitWESN(double[] wesn, int width, int height) {
Rectangle rect = new Rectangle(0, 0, width, height);
double scale = (wesn[1] - wesn[0]) / (double)width;
double scaleY = (wesn[3] - wesn[2]) / (double)height;
double x0, y0;
if(scaleY > scale) {
scale = scaleY;
x0 = .5d * (wesn[0] + wesn[1]);
wesn[0] = x0 - (double)width * .5d * scale;
wesn[1] = wesn[0] + (double)width * scale;
} else {
y0 = .5d * (wesn[2] + wesn[3]);
wesn[3] = y0 + (double)height * .5d * scale;
wesn[2] = wesn[3] - (double)height * scale;
}
return wesn;
}
示例8: LabelSeparator
import java.awt.Rectangle; //导入依赖的package包/类
public LabelSeparator(JLabel label)
{
JSeparator separator = new JSeparator();
final int height1 = label.getPreferredSize().height;
final int height2 = separator.getPreferredSize().height;
final int height3 = (height1 - height2) / 2;
final int width1 = label.getPreferredSize().width;
final int[] rows = {height3, height2, height3,};
final int[] cols = {width1, TableLayout.FILL,};
setLayout(new TableLayout(rows, cols));
add(label, new Rectangle(0, 0, 1, 3));
add(separator, new Rectangle(1, 1, 1, 1));
}
示例9: attach
import java.awt.Rectangle; //导入依赖的package包/类
@Attachment(type = "image/png", fileExtension = "png", value = "att")
public byte[] attach() {
try {
BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "png", baos);
baos.flush();
byte[] imageInByte = baos.toByteArray();
baos.close();
return imageInByte;
} catch (AWTException | IOException e) {
return null;
}
}
示例10: initScreenBounds
import java.awt.Rectangle; //导入依赖的package包/类
static void initScreenBounds() {
GraphicsDevice[] devices = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getScreenDevices();
screenBounds = new Rectangle[devices.length];
scales = new double[devices.length][2];
for (int i = 0; i < devices.length; i++) {
GraphicsConfiguration gc = devices[i].getDefaultConfiguration();
screenBounds[i] = gc.getBounds();
AffineTransform tx = gc.getDefaultTransform();
scales[i][0] = tx.getScaleX();
scales[i][1] = tx.getScaleY();
}
maxBounds = screenBounds[0];
for (int i = 0; i < screenBounds.length; i++) {
maxBounds = maxBounds.union(screenBounds[i]);
}
}
示例11: add
import java.awt.Rectangle; //导入依赖的package包/类
/**
* Adds a <code>Rectangle</code> to this <code>RepaintArea</code>.
* PAINT Rectangles are divided into mostly vertical and mostly horizontal.
* Each group is unioned together.
* UPDATE Rectangles are unioned.
*
* @param r the specified <code>Rectangle</code>
* @param id possible values PaintEvent.UPDATE or PaintEvent.PAINT
* @since 1.3
*/
public synchronized void add(Rectangle r, int id) {
// Make sure this new rectangle has positive dimensions
if (r.isEmpty()) {
return;
}
int addTo = UPDATE;
if (id == PaintEvent.PAINT) {
addTo = (r.width > r.height) ? HORIZONTAL : VERTICAL;
}
if (paintRects[addTo] != null) {
paintRects[addTo].add(r);
} else {
paintRects[addTo] = new Rectangle(r);
}
}
示例12: paintTitle
import java.awt.Rectangle; //导入依赖的package包/类
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
final View v = getTextViewForTab(tabIndex);
if (v != null) {
v.paint(g2d, textRect);
return;
}
if (title == null) return;
final Color color = tabPane.getForegroundAt(tabIndex);
if (color instanceof UIResource) {
g2d.setColor(getNonSelectedTabTitleColor());
if (tabPane.getSelectedIndex() == tabIndex) {
boolean pressed = isPressedAt(tabIndex);
boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
Color textColor = getSelectedTabTitleColor(enabled, pressed);
Color shadowColor = getSelectedTabTitleShadowColor(enabled);
AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
return;
}
} else {
g2d.setColor(color);
}
g2d.setFont(font);
SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
示例13: paintExpandControl
import java.awt.Rectangle; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void paintExpandControl(Graphics g, Rectangle clipBounds,
Insets insets, Rectangle bounds, TreePath path, int row,
boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) {
//modify the paintContext's state to match the state for the row
//this is a hack in that it requires knowledge of the subsequent
//method calls. The point is, the context used in drawCentered
//should reflect the state of the row, not of the tree.
boolean isSelected = tree.getSelectionModel().isPathSelected(path);
int state = paintContext.getComponentState();
if (isSelected) {
paintContext.setComponentState(state | SynthConstants.SELECTED);
}
super.paintExpandControl(g, clipBounds, insets, bounds, path, row,
isExpanded, hasBeenExpanded, isLeaf);
paintContext.setComponentState(state);
}
示例14: findImage
import java.awt.Rectangle; //导入依赖的package包/类
@Override
public ImageFinderResult findImage(Rectangle sourceScreenRect, BufferedImage templateImage, double desiredAccuracy) {
try {
BufferedImage capture = new Robot().createScreenCapture(sourceScreenRect);
Mat sourceMat = CvHelper.convertToMat(capture);
Mat templateMat = CvHelper.convertToMat(templateImage);
return this.findImage(sourceMat, templateMat, desiredAccuracy);
} catch (Exception ex) {
throw new RuntimeException(String.format(
"An error ocurred while trying to find an image on screen at (%s, %s, %s, %s)",
sourceScreenRect.x,
sourceScreenRect.y,
sourceScreenRect.width,
sourceScreenRect.height), ex);
}
}
示例15: setValue
import java.awt.Rectangle; //导入依赖的package包/类
public void setValue(String in) {
final StringTokenizer st = new StringTokenizer(in, ",");
try {
setValue(new Rectangle(Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken())));
}
catch (NumberFormatException e) {
// This can happen if a VisibilityOption has the same name
// as a PositionOption, either currently, or due to editing.
// Don't throw a bug, just log it.
if (in.indexOf('\t') > 0) {
ErrorDialog.dataError(new BadDataReport("Map or Chart window with same name as piece Palette", getKey(), e));
}
else {
ErrorDialog.bug(e);
}
}
}