Example usage for javax.swing SwingUtilities convertPointToScreen

List of usage examples for javax.swing SwingUtilities convertPointToScreen

Introduction

In this page you can find the example usage for javax.swing SwingUtilities convertPointToScreen.

Prototype

@SuppressWarnings("deprecation")
public static void convertPointToScreen(Point p, Component c) 

Source Link

Document

Convert a point from a component's coordinate system to screen coordinates.

Usage

From source file:Main.java

public static void main(String[] argv) {

    JButton component = new JButton();
    Point pt = new Point(component.getLocation());
    SwingUtilities.convertPointToScreen(pt, component);
}

From source file:Main.java

public static void showPopupMenu(final JPopupMenu popup, final Component component, int x, int y) {
    final Point p = new Point(x, y);
    SwingUtilities.convertPointToScreen(p, component);
    final Dimension size = popup.getPreferredSize();
    final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    boolean horiz = false;
    boolean vert = false;

    final int origX = x;

    if ((p.x + size.width > screen.width) && (size.width < screen.width)) {
        x += (screen.width - p.x - size.width);
        horiz = true;// www.j a va  2 s  .c  o  m
    }

    if ((p.y + size.height > screen.height) && (size.height < screen.height)) {
        y += (screen.height - p.y - size.height);
        vert = true;
    }

    if (horiz && vert) {
        x = origX - size.width - 2;
    }
    popup.show(component, x, y);
}

From source file:com.hammurapi.jcapture.CaptureFrame.java

public CaptureFrame(final AbstractCaptureApplet applet) throws Exception {
    super("Screen capture");
    setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("camera.png")));

    setUndecorated(true);//from w  w w .j  a  va2s. c o  m

    Translucener.makeFrameTranslucent(this);

    setAlwaysOnTop(true);
    this.applet = applet;
    captureConfig = new CaptureConfig();
    captureConfig.load(applet.loadConfig());
    captureConfig.setBackgroundProcessor(applet.getBackgroundProcessor());

    //--- GUI construction ---

    capturePanel = new JPanel();

    final JLabel dimensionsLabel = new JLabel("");
    capturePanel.add(dimensionsLabel, BorderLayout.CENTER);

    capturePanel.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            super.componentResized(e);
            dimensionsLabel.setText(e.getComponent().getWidth() + " x " + e.getComponent().getHeight());
        }
    });

    JButton captureButton = new JButton(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Rectangle bounds = capturePanel.getBounds();
            Point loc = bounds.getLocation();
            SwingUtilities.convertPointToScreen(loc, capturePanel);
            bounds.setLocation(loc);
            Properties props = captureConfig.setRecordingRectangle(bounds);
            if (props != null) {
                getApplet().storeConfig(props);
            }
            capturing.set(true);
            setVisible(false);
        }

    });
    captureButton.setText("Capture");
    captureButton.setToolTipText("Create a snapshot of the screen");
    capturePanel.add(captureButton, BorderLayout.CENTER);

    recordButton = new JButton(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Rectangle bounds = capturePanel.getBounds();
            Point loc = bounds.getLocation();
            SwingUtilities.convertPointToScreen(loc, capturePanel);
            bounds.setLocation(loc);
            Properties props = captureConfig.setRecordingRectangle(bounds);
            if (props != null) {
                getApplet().storeConfig(props);
            }
            recording.set(true);
            setVisible(false);
        }

    });
    recordButton.setText("Record");
    setRecordButtonState();
    capturePanel.add(recordButton, BorderLayout.CENTER);

    JButton optionsButton = new JButton(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            new CaptureOptionsDialog(CaptureFrame.this).setVisible(true);
        }

    });
    optionsButton.setText("Options");
    capturePanel.add(optionsButton, BorderLayout.CENTER);

    JButton cancelButton = new JButton(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            CaptureFrame.this.setVisible(false);
        }

    });
    cancelButton.setText("Cancel");
    capturePanel.add(cancelButton, BorderLayout.CENTER);

    getContentPane().add(capturePanel, BorderLayout.CENTER);

    capturePanel.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false));

    if (captureConfig.getRecordingRectangle() == null) {
        setSize(400, 300);
        setLocationRelativeTo(null);
    } else {
        setBounds(captureConfig.getRecordingRectangle());
    }

    Insets dragInsets = new Insets(5, 5, 5, 5);
    new ComponentResizer(dragInsets, this);

    ComponentMover cm = new ComponentMover();
    cm.registerComponent(this);
    cm.setDragInsets(dragInsets);

    addComponentListener(new ComponentListener() {

        @Override
        public void componentShown(ComponentEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void componentResized(ComponentEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void componentMoved(ComponentEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void componentHidden(ComponentEvent e) {
            if (capturing.get()) {
                capturing.set(false);
                try {
                    capture();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            } else if (recording.get()) {
                recording.set(false);
                record();
            }
        }
    });

}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopPopupButton.java

protected void showPopup() {
    popup.removeAll();//  w w  w . j av  a  2  s  . c  o  m

    for (final Action action : actionList) {
        if (action.isVisible()) {
            final JMenuItem menuItem = new JMenuItem(action.getCaption());
            menuItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    action.actionPerform((Component) action.getOwner());
                }
            });
            menuItem.setEnabled(action.isEnabled());
            menuItem.setName(action.getId());

            initAction(action, menuItem);

            popup.add(menuItem);
        }
    }

    int popupHeight = popup.getComponentCount() * 25;

    Point pt = new Point();
    SwingUtilities.convertPointToScreen(pt, impl);

    int y;
    if (pt.getY() + impl.getHeight() + popupHeight < Toolkit.getDefaultToolkit().getScreenSize().getHeight()) {
        y = impl.getHeight();
    } else {
        y = -popupHeight;
    }

    // do not show ugly empty popup
    if (popup.getComponentCount() > 0) {
        popup.show(impl, 0, y);
    }
}

From source file:ec.ui.view.RevisionSaSeriesView.java

private void showSelectionPopup(Rectangle2D rectangle) {
    XYPlot plot = chartpanel_.getChart().getXYPlot();
    Rectangle2D dataArea = chartpanel_.getScreenDataArea();
    DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
    double minX = domainAxis.java2DToValue(rectangle.getMinX(), dataArea, plot.getDomainAxisEdge());
    double maxX = domainAxis.java2DToValue(rectangle.getMaxX(), dataArea, plot.getDomainAxisEdge());

    Date startDate = new Date((long) minX);
    Date endDate = new Date((long) maxX);
    TsPeriod start = new TsPeriod(firstPeriod.getFrequency(), startDate);
    TsPeriod end = new TsPeriod(firstPeriod.getFrequency(), endDate);

    if (end.minus(start) == 0) {
        return;/* ww  w .  j  a va2 s .  co m*/
    }

    TsPeriodSelector sel = new TsPeriodSelector();
    sel.between(start.firstday(), end.lastday());
    List<TsData> listSeries = history_.Select(info_, startDate, endDate);
    List<TsData> revSeries = new ArrayList<>();

    for (TsData t : listSeries) {
        revSeries.add(t.select(sel));
    }

    Point pt = new Point((int) rectangle.getX(), (int) rectangle.getY());
    pt.translate(3, 3);
    SwingUtilities.convertPointToScreen(pt, chartpanel_);
    popup.setLocation(pt);
    popup.setChartTitle(info_.toUpperCase() + " First estimations");
    popup.setTsData(sRef.select(sel), revSeries);
    popup.setVisible(true);
    chartpanel_.repaint();
}

From source file:edu.ku.brc.specify.ui.containers.ContainerTreeRenderer.java

/**
 * @param g2d//w ww .  j a v  a  2s .c o m
 * @param xc
 * @param yc
 * @param imgIcon
 * @param hitsInx
 * @return
 */
private int drawIcon(final Graphics2D g2d, final int xc, final int yc, final ImageIcon imgIcon,
        final int hitsInx) {
    g2d.drawImage(imgIcon.getImage(), xc, yc, null);
    hitRects[hitsInx].setBounds(xc, yc, imgIcon.getIconWidth(), imgIcon.getIconHeight());
    Point p = hitRects[hitsInx].getLocation();
    SwingUtilities.convertPointToScreen(p, this);
    hitRects[hitsInx].setLocation(p);
    return imgIcon.getIconWidth() + iconSep;
}

From source file:Filter3dTest.java

/**
 * Uses the Robot class to try to postion the mouse in the center of the
 * screen./*from   w ww . j a  va2 s  . co m*/
 * <p>
 * Note that use of the Robot class may not be available on all platforms.
 */
private synchronized void recenterMouse() {
    if (robot != null && comp.isShowing()) {
        centerLocation.x = comp.getWidth() / 2;
        centerLocation.y = comp.getHeight() / 2;
        SwingUtilities.convertPointToScreen(centerLocation, comp);
        isRecentering = true;
        robot.mouseMove(centerLocation.x, centerLocation.y);
    }
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java

/**
 * Opens the <tt>WritePanelRightButtonMenu</tt> when user clicks with the
 * right mouse button on the editor area.
 *
 * @param e the <tt>MouseEvent</tt> that notified us
 *//* ww w.  j  a v a  2 s. c  o m*/
public void mouseClicked(MouseEvent e) {
    if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 || (e.isControlDown() && !e.isMetaDown())) {
        Point p = e.getPoint();
        SwingUtilities.convertPointToScreen(p, e.getComponent());

        //SPELLCHECK
        ArrayList<JMenuItem> contributedMenuEntries = new ArrayList<JMenuItem>();

        for (ChatMenuListener listener : this.menuListeners) {
            contributedMenuEntries.addAll(listener.getMenuElements(this.chatPanel, e));
        }

        for (JMenuItem item : contributedMenuEntries) {
            rightButtonMenu.add(item);
        }

        JPopupMenu rightMenu = rightButtonMenu.makeMenu(contributedMenuEntries);
        rightMenu.setInvoker(editorPane);
        rightMenu.setLocation(p.x, p.y);
        rightMenu.setVisible(true);
    }
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatConversationPanel.java

/**
 * When a right button click is performed in the editor pane, a popup menu
 * is opened./*from w ww.j  ava2 s  .c o  m*/
 * In case of the Scheme being internal, it won't open the Browser but
 * instead it will trigger the forwarded action.
 *
 * @param e The MouseEvent.
 */
public void mouseClicked(MouseEvent e) {
    Point p = e.getPoint();
    SwingUtilities.convertPointToScreen(p, e.getComponent());

    if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 || (e.isControlDown() && !e.isMetaDown())) {
        openContextMenu(p);
    } else if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0 && currentHref != null
            && currentHref.length() != 0) {
        URI uri;
        try {
            uri = new URI(currentHref);
        } catch (URISyntaxException e1) {
            logger.error(
                    "Failed to open hyperlink in chat window. " + "Error was: Invalid URL - " + currentHref);
            return;
        }
        if ("jitsi".equals(uri.getScheme())) {
            for (ChatLinkClickedListener l : chatLinkClickedListeners) {
                l.chatLinkClicked(uri);
            }
        } else
            GuiActivator.getBrowserLauncher().openURL(currentHref);

        // after opening the link remove the currentHref to avoid
        // clicking on the window to gain focus to open the link again
        this.currentHref = "";
    }
}

From source file:au.org.ala.delta.intkey.Intkey.java

/**
 * Get the bounds of the main window/*from   ww  w . ja  v  a 2 s  .  co m*/
 * 
 * @return the bounds of the main window
 */
public Rectangle getClientBounds() {
    Rectangle r = _rootSplitPane.getBounds();
    // Rectangle outer = getMainFrame().getBounds();
    // r.x = r.x + outer.x;
    // r.y = r.y + _pnlAvailableCharactersHeader.getHeight();
    Point p1 = new Point(0, 0);
    SwingUtilities.convertPointToScreen(p1, _rootSplitPane);
    r.x = p1.x;
    r.y = p1.y + _pnlAvailableCharactersHeader.getHeight();
    r.height = r.height - _pnlAvailableCharactersHeader.getHeight();

    return r;
}