Example usage for java.awt Rectangle setLocation

List of usage examples for java.awt Rectangle setLocation

Introduction

In this page you can find the example usage for java.awt Rectangle setLocation.

Prototype

public void setLocation(int x, int y) 

Source Link

Document

Moves this Rectangle to the specified location.

Usage

From source file:forge.itemmanager.views.ItemListView.java

@Override
protected void onScrollSelectionIntoView(final JViewport viewport) {
    // compute where we're going and where we are
    final Rectangle targetRect = this.table.getCellRect(this.getSelectedIndex(), 0, true);
    final Rectangle curViewRect = viewport.getViewRect();

    // if the target cell is not visible, attempt to jump to a location where it is
    // visible but not on the edge of the viewport
    if (targetRect.y + targetRect.height > curViewRect.y + curViewRect.height) {
        // target is below us, move to position 3 rows below target
        targetRect.setLocation(targetRect.x, targetRect.y + (targetRect.height * 3));
    } else if (targetRect.y < curViewRect.y) {
        // target is above is, move to position 3 rows above target
        targetRect.setLocation(targetRect.x, targetRect.y - (targetRect.height * 3));
    }/*w ww  .j av  a2s  .  c  o  m*/

    this.table.scrollRectToVisible(targetRect);
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

private void solveConflict() {
    if (this.investPoint == null || this.ROIPoint == null) {
        /* No conflict to be solved. */
        return;/*from  w  w  w .  ja va  2  s  .  c o m*/
    }

    /* Take border into consideration. */
    final Rectangle ROIRectWithBorder = new Rectangle((Rectangle) this.ROIRect);
    final Rectangle investRectWithBorder = new Rectangle((Rectangle) this.investRect);
    ROIRectWithBorder.setLocation((int) ROIRectWithBorder.getX() - 1, (int) ROIRectWithBorder.getY() - 1);
    ROIRectWithBorder.setSize((int) ROIRectWithBorder.getWidth() + 2, (int) ROIRectWithBorder.getHeight() + 2);
    investRectWithBorder.setLocation((int) investRectWithBorder.getX() - 1,
            (int) investRectWithBorder.getY() - 1);
    investRectWithBorder.setSize((int) investRectWithBorder.getWidth() + 2,
            (int) investRectWithBorder.getHeight() + 2);
    if (false == ROIRectWithBorder.intersects(investRectWithBorder)) {
        return;
    }

    final Rectangle oldROIRect = new Rectangle((Rectangle) this.ROIRect);
    final Rectangle oldInvestRect = new Rectangle((Rectangle) this.investRect);

    // Move to Down.
    if (this.ROIRect.getY() > this.investRect.getY()) {
        ((Rectangle) this.ROIRect).translate(0,
                (int) (this.investRect.getY() + this.investRect.getHeight() - this.ROIRect.getY() + 4));
    } else {
        ((Rectangle) this.investRect).translate(0,
                (int) (this.ROIRect.getY() + this.ROIRect.getHeight() - this.investRect.getY() + 4));
    }

    if ((this.drawArea.getY() + this.drawArea.getHeight()) > (this.ROIRect.getY() + this.ROIRect.getHeight())
            && (this.drawArea.getY() + this.drawArea.getHeight()) > (this.investRect.getY()
                    + this.investRect.getHeight())) {
        return;
    }

    this.ROIRect.setRect(oldROIRect);
    this.investRect.setRect(oldInvestRect);

    // Move to Up.
    if (this.ROIRect.getY() > this.investRect.getY()) {
        ((Rectangle) this.investRect).translate(0,
                -(int) (this.investRect.getY() + this.investRect.getHeight() - this.ROIRect.getY() + 4));
    } else {
        ((Rectangle) this.ROIRect).translate(0,
                -(int) (this.ROIRect.getY() + this.ROIRect.getHeight() - this.investRect.getY() + 4));
    }

    if ((this.drawArea.getY() < this.ROIRect.getY()) && (this.drawArea.getY() < this.investRect.getY())) {
        return;
    }

    this.ROIRect.setRect(oldROIRect);
    this.investRect.setRect(oldInvestRect);
}

From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java

private void drawSquares(Graphics squares, Point start, Rectangle bounds, Dataset dataset,
        boolean clusterColumns) {
    //        ColorFactory colors = ColorFactoryList.getInstance().getActiveColorFactory(dataset);
    colors = colorFactory.getActiveColorFactory(dataset);
    Rectangle view = getSquaresBounds(dataset);
    squares.translate(start.x, start.y);
    int rows = this.countgenes(this.rowNode);
    int counter = 0;
    double[] gengenscalevals = null;
    int[] upperArrangement = null;
    if (clusterColumns) {
        upperArrangement = upperTree.arrangement;
    } else {//from www .j  a v a 2s. c o  m
        upperArrangement = new int[dataset.getColumnIds().length];
        for (int x = 0; x < dataset.getColumnIds().length; x++)
            upperArrangement[x] = x;
    }
    double[][] dat = null;
    dat = dataset.getData();
    if (sideTree == null) {
        return;
    }
    for (int i = 0; i < sideTree.arrangement.length; i++) {
        double v = 0;
        Rectangle sqr = new Rectangle(0, 0, squareW, squareL);
        for (int j = 0; j < upperArrangement.length; j++) {
            if (bounds == null || bounds.intersects((j * squareW), (i * squareL), squareW, squareL)) {

                if (upperTree != null) {

                    sqr.setLocation((j * squareW), (i * squareL));
                    if (!view.intersects(sqr)) {
                        continue;
                    }

                    if (sideTree.arrangement[i] != -1 && upperArrangement[j] != -1) {

                        if (dataset.isMissing(sideTree.arrangement[i], upperArrangement[j])) {
                            squares.setColor(colors.getMissing());
                        } else {
                            if (!gengenscale) {
                                v = dat[sideTree.arrangement[i]][upperArrangement[j]];
                                squares.setColor(colors.getColor(v));
                            } else {
                                v = gengenscalevals[upperArrangement[j]];
                                squares.setColor(colors.getColor(v));
                            }
                        }
                        squares.fillRect((j * squareW), (i * squareL), squareW, squareL);
                    }
                } else {
                    sqr.setLocation((j * squareW), (i * squareL));
                    if (!view.intersects(sqr)) {
                        continue;
                    }

                    v = dat[sideTree.arrangement[i]][upperArrangement[j]];

                    if (dataset.isMissing(sideTree.arrangement[i], upperArrangement[j])) {
                        squares.setColor(colors.getMissing());
                    } else {
                        squares.setColor(colors.getColor(v));
                    }

                    squares.fillRect((j * squareW), (i * squareL), squareW, squareL);
                }
            }
        }
        counter++;
        if (counter == rows) {
            break;
        }
    }
    counter = 0;
    if (true) {
        squares.setColor(GridCol);
        for (int i = 0; i < sideTree.arrangement.length + 1; i++) {
            if (bounds == null
                    || bounds.intersects(0, i * squareL, upperArrangement.length * squareW, i * squareL)) {
                squares.drawLine(0, i * squareL, (upperArrangement.length * squareW) + 0, i * squareL);
            }
            counter++;
            if (counter > rows) {
                break;
            }
        }
        for (int j = 0; j < upperArrangement.length; j++) {
            if (bounds == null || bounds.intersects(j * squareW, 0, j * squareW, rows * squareL)) {
                squares.drawLine(j * squareW, 0, j * squareW, rows * squareL);
            }
        }

        if (bounds == null || bounds.intersects(upperArrangement.length * squareW, 0,
                upperArrangement.length * squareW, rows * squareL)) {
            squares.drawLine(upperArrangement.length * squareW, 0, upperArrangement.length * squareW,
                    rows * squareL);
        }

    }
    squares.translate(-start.x, -start.y);
}

From source file:knop.psfj.BeadImage.java

/**
 * Gets the enlarged frame./*from   www  .java  2s  .  c  om*/
 *
 * @param r the r
 * @param f the f
 * @return the enlarged frame
 */
public static Rectangle getEnlargedFrame(Rectangle r, int f) {
    Rectangle rn = new Rectangle();
    rn.setLocation(round(r.getCenterX() - f / 2), round(r.getCenterY() - f / 2));
    rn.setSize(f, f);

    return rn;
}

From source file:knop.psfj.BeadImage.java

/**
 * Gets the enlarged frame./*from  w  ww  .  j a v  a 2  s.  c o  m*/
 *
 * @param r the r
 * @return the enlarged frame
 */
public Rectangle getEnlargedFrame(Rectangle r) {
    Rectangle rn = new Rectangle();

    int f = frameSize;

    if (frameSize * frameSize >= imageWidth * imageHeight * 0.8) {
        rn.setLocation(0, 0);
        rn.setSize(imageWidth, imageHeight);
        return rn;
    }

    int x = MathUtils.round(r.getX() + r.getWidth() / 2 - f / 2);

    int y = MathUtils.round(r.getY() + r.getHeight() / 2 - f / 2);

    x -= 1;
    y -= 1;

    int w = f;
    int h = f;
    rn.setLocation(x, y);
    rn.setSize(w, h);

    return rn;
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

@Override
public void mouseWheelMoved(final MouseWheelEvent e) {
    if ((e.getModifiers() & MouseEvent.CTRL_MASK) != 0) {
        final int rotation = e.getWheelRotation();

        final Point point = e.getPoint();
        final Rectangle rect = this.hexMapPanel.getVisibleRect();

        final HexPosition focusedNumber = this.hexMapPanel.getHexPosition(e.getPoint());

        if (rotation < 0) {
            menuViewZoomInActionPerformed(null);
        } else {//from w  ww  .  j a v a  2 s.c om
            menuViewZoomOutActionPerformed(null);
        }

        final float cellx = this.hexMapPanel.getHexEngine().calculateX(focusedNumber.getColumn(),
                focusedNumber.getRow());
        final float celly = this.hexMapPanel.getHexEngine().calculateY(focusedNumber.getColumn(),
                focusedNumber.getRow());

        final float cellw = this.hexMapPanel.getHexEngine().getCellWidth()
                * this.hexMapPanel.getHexEngine().getScaleX();
        final float cellh = this.hexMapPanel.getHexEngine().getCellHeight()
                * this.hexMapPanel.getHexEngine().getScaleY();

        final float dx = cellx + cellw / 2 - point.x;
        final float dy = celly + cellh / 2 - point.y;

        rect.setLocation(Math.round(rect.x + dx), Math.round(rect.y + dy));

        this.hexMapPanel.scrollRectToVisible(rect);
    }
}

From source file:com.lfv.lanzius.server.LanziusServer.java

public void init() {

    log.info(Config.VERSION + "\n");

    docVersion = 0;//from  ww  w.  ja  v  a2s  . c  om

    frame = new JFrame(Config.TITLE + " - Server Control Panel");

    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            actionPerformed(new ActionEvent(itemExit, 0, null));
        }
    });

    // Create graphical terminal view
    panel = new WorkspacePanel(this);
    frame.getContentPane().add(panel);

    // Create a menu bar
    JMenuBar menuBar = new JMenuBar();

    // FILE
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    // Load configuration
    itemLoadConfig = new JMenuItem("Load configuration...");
    itemLoadConfig.addActionListener(this);
    fileMenu.add(itemLoadConfig);
    // Load terminal setup
    itemLoadExercise = new JMenuItem("Load exercise...");
    itemLoadExercise.addActionListener(this);
    fileMenu.add(itemLoadExercise);
    fileMenu.addSeparator();
    // Exit
    itemExit = new JMenuItem("Exit");
    itemExit.addActionListener(this);
    fileMenu.add(itemExit);
    menuBar.add(fileMenu);

    // SERVER
    JMenu serverMenu = new JMenu("Server");
    serverMenu.setMnemonic(KeyEvent.VK_S);
    // Start
    itemServerStart = new JMenuItem("Start");
    itemServerStart.addActionListener(this);
    serverMenu.add(itemServerStart);
    // Stop
    itemServerStop = new JMenuItem("Stop");
    itemServerStop.addActionListener(this);
    serverMenu.add(itemServerStop);
    // Restart
    itemServerRestart = new JMenuItem("Restart");
    itemServerRestart.addActionListener(this);
    itemServerRestart.setEnabled(false);
    serverMenu.add(itemServerRestart);
    // Monitor network connection
    itemServerMonitor = new JCheckBoxMenuItem("Monitor network");
    itemServerMonitor.addActionListener(this);
    itemServerMonitor.setState(false);
    serverMenu.add(itemServerMonitor);
    menuBar.add(serverMenu);

    // TERMINAL
    JMenu terminalMenu = new JMenu("Terminal");
    terminalMenu.setMnemonic(KeyEvent.VK_T);
    itemTerminalLink = new JMenuItem("Link...");
    itemTerminalLink.addActionListener(this);
    terminalMenu.add(itemTerminalLink);
    itemTerminalUnlink = new JMenuItem("Unlink...");
    itemTerminalUnlink.addActionListener(this);
    terminalMenu.add(itemTerminalUnlink);
    itemTerminalUnlinkAll = new JMenuItem("Unlink All");
    itemTerminalUnlinkAll.addActionListener(this);
    terminalMenu.add(itemTerminalUnlinkAll);
    itemTerminalSwap = new JMenuItem("Swap...");
    itemTerminalSwap.addActionListener(this);
    terminalMenu.add(itemTerminalSwap);
    menuBar.add(terminalMenu);

    // GROUP
    JMenu groupMenu = new JMenu("Group");
    groupMenu.setMnemonic(KeyEvent.VK_G);
    itemGroupStart = new JMenuItem("Start...");
    itemGroupStart.addActionListener(this);
    groupMenu.add(itemGroupStart);
    itemGroupPause = new JMenuItem("Pause...");
    itemGroupPause.addActionListener(this);
    groupMenu.add(itemGroupPause);
    itemGroupStop = new JMenuItem("Stop...");
    itemGroupStop.addActionListener(this);
    groupMenu.add(itemGroupStop);
    menuBar.add(groupMenu);

    frame.setJMenuBar(menuBar);

    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle maximumWindowBounds = graphicsEnvironment.getMaximumWindowBounds();

    if (Config.SERVER_SIZE_FULLSCREEN) {
        maximumWindowBounds.setLocation(0, 0);
        maximumWindowBounds.setSize(Toolkit.getDefaultToolkit().getScreenSize());
        frame.setResizable(false);
        frame.setUndecorated(true);
    } else if (Config.SERVER_SIZE_100P_WINDOW) {
        // Fixes a bug in linux using gnome. With the line below the upper and
        // lower bars are respected
        maximumWindowBounds.height -= 1;
    } else if (Config.SERVER_SIZE_75P_WINDOW) {
        maximumWindowBounds.width *= 0.75;
        maximumWindowBounds.height *= 0.75;
    } else if (Config.SERVER_SIZE_50P_WINDOW) {
        maximumWindowBounds.width /= 2;
        maximumWindowBounds.height /= 2;
    }

    frame.setBounds(maximumWindowBounds);
    frame.setVisible(true);

    log.info("Starting control panel");

    // Autostart for debugging
    if (Config.SERVER_AUTOLOAD_CONFIGURATION != null)
        actionPerformed(new ActionEvent(itemLoadConfig, 0, null));

    if (Config.SERVER_AUTOSTART_SERVER)
        actionPerformed(new ActionEvent(itemServerStart, 0, null));

    if (Config.SERVER_AUTOLOAD_EXERCISE != null)
        actionPerformed(new ActionEvent(itemLoadExercise, 0, null));

    if (Config.SERVER_AUTOSTART_GROUP > 0)
        actionPerformed(new ActionEvent(itemGroupStart, 0, null));

    try {
        // Read the property files
        serverProperties = new Properties();
        serverProperties.loadFromXML(new FileInputStream("data/properties/serverproperties.xml"));
        int rcPort = Integer.parseInt(serverProperties.getProperty("RemoteControlPort", "0"));
        if (rcPort > 0) {
            groupRemoteControlListener(rcPort);
        }
        isaPeriod = Integer.parseInt(serverProperties.getProperty("ISAPeriod", "60"));
        isaNumChoices = Integer.parseInt(serverProperties.getProperty("ISANumChoices", "6"));
        for (int i = 0; i < 9; i++) {
            String tag = "ISAKeyText" + Integer.toString(i);
            String def_val = Integer.toString(i + 1);
            isakeytext[i] = serverProperties.getProperty(tag, def_val);
        }
        isaExtendedMode = serverProperties.getProperty("ISAExtendedMode", "false").equalsIgnoreCase("true");
    } catch (Exception e) {
        log.error("Unable to start remote control listener");
        log.error(e.getMessage());
    }
    isaClients = new HashSet<Integer>();
}

From source file:org.apache.fop.render.pcl.PCLPainter.java

private Rectangle getTextBoundingBox(int x, int y, int letterSpacing, int wordSpacing, int[] dx, String text,
        Font font, FontMetricsMapper metrics) {
    int maxAscent = metrics.getMaxAscent(font.getFontSize()) / 1000;
    int descent = metrics.getDescender(font.getFontSize()) / 1000; //is negative
    int safetyMargin = (int) (SAFETY_MARGIN_FACTOR * font.getFontSize());
    Rectangle boundingRect = new Rectangle(x, y - maxAscent - safetyMargin, 0,
            maxAscent - descent + 2 * safetyMargin);

    int l = text.length();
    int dxl = (dx != null ? dx.length : 0);

    if (dx != null && dxl > 0 && dx[0] != 0) {
        boundingRect.setLocation(boundingRect.x - (int) Math.ceil(dx[0] / 10f), boundingRect.y);
    }/*from  www. j  a  va2 s  .co  m*/
    float width = 0.0f;
    for (int i = 0; i < l; i++) {
        char orgChar = text.charAt(i);
        float glyphAdjust = 0;
        int cw = font.getCharWidth(orgChar);

        if ((wordSpacing != 0) && CharUtilities.isAdjustableSpace(orgChar)) {
            glyphAdjust += wordSpacing;
        }
        glyphAdjust += letterSpacing;
        if (dx != null && i < dxl - 1) {
            glyphAdjust += dx[i + 1];
        }

        width += cw + glyphAdjust;
    }
    int extraWidth = font.getFontSize() / 3;
    boundingRect.setSize((int) Math.ceil(width) + extraWidth, boundingRect.height);
    return boundingRect;
}

From source file:org.nuclos.client.ui.collect.result.SearchResultStrategy.java

private void adjustVerticalScrollBarForSearch(boolean bRefreshOnly) {
    final CollectController<Clct> cc = getCollectController();
    final JViewport viewport = cc.getResultPanel().getResultTableScrollPane().getViewport();
    if (bRefreshOnly) {
        final Rectangle rect = cc.getResultTable().getCellRect(0, 0, true);
        final Rectangle viewRect = viewport.getViewRect();
        // There seem to be different opinions about what scrollRectToVisible has to do at SUN and everywhere else...
        rect.setLocation(viewRect.x, viewRect.y);//rect.x - viewRect.x, rect.y - viewRect.y);
        viewport.scrollRectToVisible(rect);
    } else {/* w  ww  .  j  a  va 2 s  .  c  o m*/
        Point viewPosition = viewport.getViewPosition();
        viewport.setViewPosition(new Point(viewPosition.x, 0));
    }
    final JScrollBar scrlbarVertical = cc.getResultPanel().getResultTableScrollPane().getVerticalScrollBar();
    scrlbarVertical.setValue(scrlbarVertical.getMinimum());
}

From source file:org.yccheok.jstock.gui.JTableUtilities.java

public static void scrollToVisible(JTable table, int rowIndex, int vColIndex) {
    if (!(table.getParent() instanceof JViewport)) {
        return;//from  ww w  .  j  a v  a  2s .c  o  m
    }

    JViewport viewport = (JViewport) table.getParent();

    // This rectangle is relative to the table where the
    // northwest corner of cell (0,0) is always (0,0).
    Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);

    // The location of the viewport relative to the table
    Point pt = viewport.getViewPosition();

    // Translate the cell location so that it is relative
    // to the view, assuming the northwest corner of the
    // view is (0,0)
    rect.setLocation(rect.x - pt.x, rect.y - pt.y);

    // Scroll the area into view
    viewport.scrollRectToVisible(rect);
}