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:op.care.prescription.DlgRegular.java

private void tblDosisMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblDosisMousePressed
    if (!SwingUtilities.isRightMouseButton(evt)) {
        return;/* w  w  w  .  ja v  a2s. c o m*/
    }

    final TMDose tm = (TMDose) tblDosis.getModel();
    if (tm.getRowCount() == 0) {
        return;
    }
    Point p = evt.getPoint();
    Point p2 = evt.getPoint();
    // Convert a coordinate relative to a component's bounds to screen coordinates
    SwingUtilities.convertPointToScreen(p2, tblDosis);

    //        final Point screenposition = p2;
    final int row = tblDosis.rowAtPoint(p);

    ListSelectionModel lsm = tblDosis.getSelectionModel();
    lsm.setSelectionInterval(row, row);

    // Meneintrge
    SYSTools.unregisterListeners(menu);
    menu = new JPopupMenu();

    //-----------------------------------------
    JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.msg.delete"), SYSConst.icon22delete);
    itemPopupDelete.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            PrescriptionSchedule schedule = prescription.getPrescriptionSchedule().get(row);
            prescription.getPrescriptionSchedule().remove(schedule);
            schedules2delete.add(schedule);
            reloadTable();
        }
    });
    menu.add(itemPopupDelete);
    menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY());

}

From source file:op.care.sysfiles.PnlFiles.java

private void tblFilesMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblFilesMousePressed

    Point p = evt.getPoint();//w w  w . ja v  a  2  s  . co m
    ListSelectionModel lsm = tblFiles.getSelectionModel();
    Point p2 = evt.getPoint();
    SwingUtilities.convertPointToScreen(p2, tblFiles);
    final Point screenposition = p2;

    boolean singleRowSelected = lsm.getMaxSelectionIndex() == lsm.getMinSelectionIndex();

    final int row = tblFiles.rowAtPoint(p);
    final int col = tblFiles.columnAtPoint(p);

    if (singleRowSelected) {
        lsm.setSelectionInterval(row, row);
    }

    final TMSYSFiles tm = (TMSYSFiles) tblFiles.getModel();
    final SYSFiles sysfile = tm.getRow(tblFiles.convertRowIndexToModel(row));

    if (SwingUtilities.isRightMouseButton(evt)) {

        SYSTools.unregisterListeners(menu);
        menu = new JPopupMenu();

        // SELECT
        JMenuItem itemPopupShow = new JMenuItem(SYSTools.xx("misc.commands.show"), SYSConst.icon22magnify1);
        itemPopupShow.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SYSFilesTools.handleFile(sysfile, Desktop.Action.OPEN);
            }
        });
        menu.add(itemPopupShow);

        if (col == TMSYSFiles.COL_DESCRIPTION
                && OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) {

            final JMenuItem itemPopupEdit = new JMenuItem(SYSTools.xx("misc.commands.edit"),
                    SYSConst.icon22edit3);
            itemPopupEdit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {

                    final JidePopup popup = new JidePopup();
                    popup.setMovable(false);
                    popup.getContentPane()
                            .setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS));

                    final JComponent editor = new JTextArea(sysfile.getBeschreibung(), 10, 40);
                    ((JTextArea) editor).setLineWrap(true);
                    ((JTextArea) editor).setWrapStyleWord(true);
                    ((JTextArea) editor).setEditable(true);

                    popup.getContentPane().add(new JScrollPane(editor));
                    final JButton saveButton = new JButton(SYSConst.icon22apply);
                    saveButton.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent actionEvent) {
                            EntityManager em = OPDE.createEM();
                            try {
                                em.getTransaction().begin();
                                popup.hidePopup();
                                SYSFiles mySysfile = em.merge(sysfile);
                                mySysfile.setBeschreibung(((JTextArea) editor).getText().trim());
                                em.getTransaction().commit();
                                tm.setSYSFile(tblFiles.convertRowIndexToModel(row), mySysfile);
                            } catch (Exception e) {
                                em.getTransaction().rollback();
                                OPDE.fatal(e);
                            } finally {
                                em.close();
                            }

                        }
                    });

                    saveButton.setHorizontalAlignment(SwingConstants.RIGHT);
                    JPanel pnl = new JPanel(new BorderLayout(10, 10));
                    JScrollPane pnlEditor = new JScrollPane(editor);

                    pnl.add(pnlEditor, BorderLayout.CENTER);
                    JPanel buttonPanel = new JPanel();
                    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
                    buttonPanel.add(saveButton);
                    pnl.setBorder(new EmptyBorder(10, 10, 10, 10));
                    pnl.add(buttonPanel, BorderLayout.SOUTH);

                    popup.setOwner(tblFiles);
                    popup.removeExcludedComponent(tblFiles);
                    popup.getContentPane().add(pnl);
                    popup.setDefaultFocusComponent(editor);

                    popup.showPopup(screenposition.x, screenposition.y);

                }
            });
            menu.add(itemPopupEdit);
        }

        if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, internalClassID)) {
            JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.commands.delete"),
                    SYSConst.icon22delete);
            itemPopupDelete.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {

                    new DlgYesNo(
                            SYSTools.xx("misc.questions.delete1") + "<br/><b>" + sysfile.getFilename()
                                    + "</b><br/>" + SYSTools.xx("misc.questions.delete2"),
                            new ImageIcon(getClass().getResource("/artwork/48x48/bw/trashcan_empty.png")),
                            new Closure() {
                                @Override
                                public void execute(Object o) {
                                    if (o.equals(JOptionPane.YES_OPTION)) {
                                        SYSFilesTools.deleteFile(sysfile);
                                        reloadTable();
                                    }
                                }
                            });

                }
            });
            menu.add(itemPopupDelete);
            itemPopupDelete.setEnabled(singleRowSelected);
        }

        menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY());
    } else if (evt.getClickCount() == 2) {
        SYSFilesTools.handleFile(sysfile, Desktop.Action.OPEN);
    }

}

From source file:op.FrmMain.java

public Point getLocationForDialog(Dimension dimOfDialog) {
    Point point = new Point((getSize().width - dimOfDialog.width) / 2, pnlMainMessage.getHeight() + 10);
    SwingUtilities.convertPointToScreen(point, this);
    return point;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.DocComponent.java

/**
 * Displays information about the attachment.
 * /*from w ww  .  j ava 2s .  co m*/
 * @param invoker The component where the clicks occurred.
 * @param p The location of the mouse pressed.
 */
private void displayInformation(JComponent invoker, Point p) {
    String text = label.getToolTipText();
    if (text == null || text.trim().length() == 0)
        return;
    JComponent comp;
    if (preview != null) {
        comp = preview;
    } else {
        JLabel l = new JLabel();
        l.setText(text);
        comp = l;
    }

    TinyDialog d = new TinyDialog(null, comp, TinyDialog.CLOSE_ONLY);
    d.setModal(true);
    d.getContentPane().setBackground(UIUtilities.BACKGROUND_COLOUR_EVEN);
    SwingUtilities.convertPointToScreen(p, invoker);
    d.pack();
    d.setLocation(p);
    d.setVisible(true);
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.DocComponent.java

/** Adds or edits the description of the tag. */
private void editDescription() {
    if (!(data instanceof AnnotationData))
        return;/*w w w  .j ava  2 s . c  o m*/
    String text = model.getAnnotationDescription((AnnotationData) data);
    originalDescription = text;
    SwingUtilities.convertPointToScreen(popupPoint, this);
    JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
    int type = EditorDialog.EDIT_TYPE;
    if (isModulo)
        type = EditorDialog.VIEW_TYPE;
    EditorDialog d = new EditorDialog(f, (AnnotationData) data, false, type);
    if (isModulo)
        d.allowEdit(false);
    d.addPropertyChangeListener(this);
    d.setOriginalDescription(originalDescription);
    d.setSize(300, 250);
    UIUtilities.showOnScreen(d, popupPoint);
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.EditorUI.java

/**
 * Removes the tags.//from  ww  w .  j  a v  a2 s  .  c  o  m
 * 
 * @param src The mouse clicked location.
 * @param location The location of the mouse pressed.
 */
void removeTags(JComponent src, Point location) {
    if (!generalPane.hasTagsToUnlink())
        return;
    if (model.isGroupLeader() || model.isAdministrator()) {
        if (tagMenu == null) {
            tagMenu = new PermissionMenu(PermissionMenu.REMOVE, "Tags");
            tagMenu.addPropertyChangeListener(new PropertyChangeListener() {

                public void propertyChange(PropertyChangeEvent evt) {
                    String n = evt.getPropertyName();
                    if (PermissionMenu.SELECTED_LEVEL_PROPERTY.equals(n)) {
                        removeLinks((Integer) evt.getNewValue(), model.getAllTags());
                    }
                }
            });
        }
        tagMenu.show(src, location.x, location.y);
        return;
    }
    SwingUtilities.convertPointToScreen(location, src);
    MessageBox box = new MessageBox(model.getRefFrame(), "Remove All Your Tags",
            "Are you sure you want to remove all your Tags?");
    Dimension d = box.getPreferredSize();
    Point p = new Point(location.x - d.width / 2, location.y);
    if (box.showMsgBox(p) == MessageBox.YES_OPTION) {
        List<TagAnnotationData> list = generalPane.removeTags();
        if (list.size() > 0)
            saveData(true);
    }
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.EditorUI.java

/**
 * Removes the other annotations.//from  w w  w  .  j av  a2  s. c  o  m
 * 
 * @param src The mouse clicked location.
 * @param location The location of the mouse pressed.
 */
void removeOtherAnnotations(JComponent src, Point location) {
    if (!generalPane.hasOtherAnnotationsToUnlink())
        return;
    if (model.isGroupLeader() || model.isAdministrator()) {
        if (otherAnnotationMenu == null) {
            otherAnnotationMenu = new PermissionMenu(PermissionMenu.REMOVE, "Other annotations");
            otherAnnotationMenu.addPropertyChangeListener(new PropertyChangeListener() {

                public void propertyChange(PropertyChangeEvent evt) {
                    String n = evt.getPropertyName();
                    if (PermissionMenu.SELECTED_LEVEL_PROPERTY.equals(n)) {
                        removeLinks((Integer) evt.getNewValue(), model.getAllOtherAnnotations());
                    }
                }
            });
        }
        otherAnnotationMenu.show(src, location.x, location.y);
        return;
    }
    SwingUtilities.convertPointToScreen(location, src);
    MessageBox box = new MessageBox(model.getRefFrame(), "Remove All Your Other Annotations",
            "Are you sure you want to remove all your other annotations?");
    Dimension d = box.getPreferredSize();
    Point p = new Point(location.x - d.width / 2, location.y);
    if (box.showMsgBox(p) == MessageBox.YES_OPTION) {
        List<AnnotationData> list = generalPane.removeOtherAnnotations();
        if (list.size() > 0)
            saveData(true);
    }
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.EditorUI.java

/**
 * Returns the collection of attachments.
 * /*  w ww. j  a va2 s . co  m*/
 * @param src The source of the mouse pressed.
 * @param location The location of the mouse pressed.
 */
void removeAttachedFiles(Component src, Point location) {
    if (!generalPane.hasAttachmentsToUnlink())
        return;
    if (model.isAdministrator() || model.isGroupLeader()) {
        if (docMenu == null) {
            docMenu = new PermissionMenu(PermissionMenu.REMOVE, "Attachments");
            docMenu.addPropertyChangeListener(new PropertyChangeListener() {

                public void propertyChange(PropertyChangeEvent evt) {
                    String n = evt.getPropertyName();
                    if (PermissionMenu.SELECTED_LEVEL_PROPERTY.equals(n)) {
                        List<FileAnnotationData> toRemove = model
                                .getFileAnnotatationsByLevel((Integer) evt.getNewValue());
                        model.fireFileAnnotationRemoveCheck(toRemove);
                    }
                }
            });
        }
        docMenu.show(src, location.x, location.y);
        return;
    }
    SwingUtilities.convertPointToScreen(location, src);
    MessageBox box = new MessageBox(model.getRefFrame(), "Remove All Attachments",
            "Are you sure you want to remove all Attachments?");
    Dimension d = box.getPreferredSize();
    Point p = new Point(location.x - d.width / 2, location.y);
    if (box.showMsgBox(p) == MessageBox.YES_OPTION) {
        List<FileAnnotationData> list = generalPane.removeAttachedFiles();
        if (list.size() > 0)
            model.fireFileAnnotationRemoveCheck(list);
    }
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/** Displays the file set associated to the image. */
void displayFileset() {
    Point location = inplaceIcon.getLocation();
    SwingUtilities.convertPointToScreen(location, inplaceIcon.getParent());
    // as the inplaceIcon already is on the right edge of the window
    // move it a bit more to the left
    location.translate(-FilesetInfoDialog.DEFAULT_WIDTH + inplaceIcon.getWidth(), inplaceIcon.getHeight());
    FilesetInfoDialog d = new FilesetInfoDialog();
    d.setData(model.getFileset(), model.isInplaceImport());
    d.open(location);/*  w  w  w . j  a va  2s. c o m*/
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.ToolBar.java

/** Displays the file set associated to the image. */
void displayFileset() {
    SwingUtilities.convertPointToScreen(location, component);
    FilesetInfoDialog d = new FilesetInfoDialog();
    d.setData(model.getFileset(), model.isInplaceImport());
    d.open(location);// www.j  a v  a2 s.  c om
}