Example usage for java.awt.event MouseEvent getComponent

List of usage examples for java.awt.event MouseEvent getComponent

Introduction

In this page you can find the example usage for java.awt.event MouseEvent getComponent.

Prototype

public Component getComponent() 

Source Link

Document

Returns the originator of the event.

Usage

From source file:org.orbisgis.sif.components.fstree.FileTree.java

/**
 * Event on Tree, called by listener/*from w w w . jav a 2s .  co m*/
 * @param evt 
 */
public void onMouseEvent(MouseEvent evt) {
    if (evt.isPopupTrigger()) {
        //Update selection
        TreePath path = getPathForLocation(evt.getX(), evt.getY());
        TreePath[] selectionPaths = getSelectionPaths();
        if ((selectionPaths != null) && (path != null)) {
            if (!contains(selectionPaths, path)) {
                if (evt.isControlDown()) {
                    addSelectionPath(path);
                } else {
                    setSelectionPath(path);
                }
            }
        } else {
            setSelectionPath(path);
        }
        //Show popup
        makePopupMenu().show(evt.getComponent(), evt.getX(), evt.getY());
    }
}

From source file:org.pmedv.blackboard.components.PartView.java

private void handlePopupTrigger(MouseEvent e) {
    if (e.isPopupTrigger() && model.getParts().size() >= 1) {

        Point p = e.getPoint();//from w  w  w.  ja v a  2  s.c  o m
        // get the row index that contains that coordinate
        int rowNumber = partPanel.getPartTable().rowAtPoint(p);
        // Get the ListSelectionModel of the JTable
        ListSelectionModel model = partPanel.getPartTable().getSelectionModel();
        // set the selected interval of rows. Using the "rowNumber"
        // variable for the beginning and end selects only that one row.
        model.setSelectionInterval(rowNumber, rowNumber);
        tablePopupMenu.show(e.getComponent(), e.getX(), e.getY());
    }
}

From source file:org.kepler.gui.popups.LibraryPopupListener.java

/**
 * /*from  w  ww  .  j ava 2s . c om*/
 * @param selPath
 * @param e
 */
private void handlePopupOutsideKar(TreePath selPath, MouseEvent e) {

    Object ob = selPath.getLastPathComponent();
    if (isDebugging)
        log.debug(ob.getClass().getName());

    if (ob instanceof KAREntityLibrary) {
        // User clicked on a KAR
        if (isDebugging)
            log.debug("KAREntityLibrary selected");
        KARPopup kp = new KARPopup(selPath, _aptree.getParentComponent());
        kp.initialize();
        _aptree.add(kp);
        _aptree.setSelectionPath(selPath);
        kp.show(e.getComponent(), e.getX(), e.getY());
    } else if (ob instanceof DownloadableKAREntityLibrary) {
        DownloadableKARPopup kp = new DownloadableKARPopup(selPath, _aptree.getParentComponent());
        kp.initialize();
        _aptree.add(kp);
        _aptree.setSelectionPath(selPath);
        kp.show(e.getComponent(), e.getX(), e.getY());
    } else if (ob instanceof RemoteRepositoryEntityLibrary) {
        //         System.out.println("Context click on RREL");

    } else if (ob instanceof FolderEntityLibrary) {
        // User clicked on a Folder
        FolderPopup fp = new FolderPopup(selPath, _aptree.getParentComponent());
        fp.initialize();
        _aptree.add(fp);
        _aptree.setSelectionPath(selPath);
        fp.show(e.getComponent(), e.getX(), e.getY());

    } else if (ob instanceof OntologyEntityLibrary) {
        // User clicked on an ontology
        OntologyPopup op = new OntologyPopup(selPath, _aptree.getParentComponent());
        op.initialize();
        _aptree.add(op);
        _aptree.setSelectionPath(selPath);
        op.show(e.getComponent(), e.getX(), e.getY());

    } else if (ob instanceof KARErrorEntityLibrary) {
        KARErrorPopup kep = new KARErrorPopup(selPath, _aptree.getParentComponent());
        kep.initialize();
        _aptree.add(kep);
        _aptree.setSelectionPath(selPath);
        kep.show(e.getComponent(), e.getX(), e.getY());

    } else if (ob instanceof RemoteKARErrorEntityLibrary) {
        RemoteKARErrorPopup kep = new RemoteKARErrorPopup(selPath, _aptree.getParentComponent());
        kep.initialize();
        _aptree.add(kep);
        _aptree.setSelectionPath(selPath);
        kep.show(e.getComponent(), e.getX(), e.getY());

    } else if (!(ob instanceof ptolemy.moml.EntityLibrary)) {
        // User clicked on a Component
        if (!(ob instanceof NamedObj)) {
            // Shouldn't happen
            return;
        }
        NamedObj no = (NamedObj) ob;
        String alternateLibraryPopupClassName = _getAlternateLibraryPopupClassName(no);
        if (alternateLibraryPopupClassName == null) {
            //System.out.println("Using default context menu stuff for class: " + ob.getClass().getName());
            OntologyComponentPopup ocp = new OntologyComponentPopup(selPath, _aptree.getParentComponent());
            ocp.initialize();
            _aptree.add(ocp);
            _aptree.setSelectionPath(selPath);
            ocp.show(e.getComponent(), e.getX(), e.getY());
        } else {
            try {
                Class<?> libraryPopupClass = Class.forName(alternateLibraryPopupClassName);
                Object object = libraryPopupClass.newInstance();
                Method getPopupMethod = libraryPopupClass.getMethod("getPopup", JTree.class, MouseEvent.class,
                        TreePath.class, Component.class);
                getPopupMethod.invoke(object, _aptree, e, selPath, _aptree.getParentComponent());
            } catch (Exception w) {
                log.error("Error creating alternateGetLibraryPopup!", w);
            }
        }
    }
}

From source file:burlov.ultracipher.swing.MainPanel.java

public MainPanel(Translator translator) {
    editDataPanel = new EditDataPanel(translator);
    translator.addToComponent(searchField);
    listPopup.add(getNewEntryAction());/*from  w w w .ja  va  2  s  . c  o  m*/
    listPopup.add(getDeleteEntryAction());

    setLayout(new BorderLayout());
    add(splitPane);

    /*
       * Suchpanel initialisieren
     */
    JPanel panel = new JPanel(new BorderLayout());
    JPanel searchPanel = new JPanel(new BorderLayout());
    searchPanel.add(new JLabel(new ImageIcon(getClass().getResource("find.png"))), BorderLayout.WEST);
    searchPanel.add(searchField, BorderLayout.CENTER);
    searchField.setToolTipText("Search");
    panel.add(searchPanel, BorderLayout.NORTH);
    panel.add(new JScrollPane(searchResults), BorderLayout.CENTER);
    splitPane.setLeftComponent(panel);

    /*
       * Anzeigepanel initialisieren
     */
    panel = new JPanel(new BorderLayout());
    panel.add(editDataPanel, BorderLayout.CENTER);
    panel.add(new PassGeneratorPanel(), BorderLayout.SOUTH);
    splitPane.setRightComponent(panel);

    searchResults.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            showDeletePopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            showDeletePopup(e);
        }

        private void showDeletePopup(MouseEvent e) {
            if (!e.isPopupTrigger()) {
                return;
            }
            int index = searchResults.locationToIndex(e.getPoint());
            if (index > -1) {
                searchResults.setSelectedIndex(index);
            }
            listPopup.show(e.getComponent(), e.getX(), e.getY());
        }
    });
    searchResults.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            editDataPanel.editData((DataEntry) searchResults.getSelectedValue(), false);
        }
    });
    searchField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            initResultList();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            initResultList();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            initResultList();
        }
    });

    editDataPanel.addNameChangeListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            int index = searchResultModel.indexOf(editDataPanel.getData());
            if (index >= 0) {
                searchResultModel.set(index, editDataPanel.getData());
            }
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            int index = searchResultModel.indexOf(editDataPanel.getData());
            if (index >= 0) {
                searchResultModel.set(index, editDataPanel.getData());
            }
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            int index = searchResultModel.indexOf(editDataPanel.getData());
            if (index >= 0) {
                searchResultModel.set(index, editDataPanel.getData());
            }
        }
    });
    searchField.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showTextPopup(e);
            } else {
                //               searchField.selectAll();
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            showTextPopup(e);
        }
    });
    //      searchField.addFocusListener(new FocusListener() {
    //         @Override
    //         public void focusLost(FocusEvent e) {
    //            System.out.println("MainPanel.MainPanel().new FocusListener() {...}.focusLost()");
    //         }
    //         
    //         @Override
    //         public void focusGained(FocusEvent e) {
    //            System.out.println("MainPanel.MainPanel().new FocusListener() {...}.focusGained()");
    //            //searchField.selectAll();
    //         }
    //      });
}

From source file:SortableTable.java

/**
 * If the user is dragging or resizing, then we clear the sort column.
 *
 * @param e  the mouse event.//from ww  w  . ja  v  a2  s .  c om
 */
public void mouseDragged(final MouseEvent e) {

    final JTableHeader header = (JTableHeader) e.getComponent();

    if ((header.getDraggedDistance() > 0) || (header.getResizingColumn() != null)) {
        this.renderer.setPressedColumn(-1);
        this.sortColumnIndex = -1;
    }
}

From source file:SortableTable.java

/**
 * When the user releases the mouse button, we attempt to sort the table.
 *
 * @param e  the mouse event./*from   w  w w.ja  va  2s  .c  o  m*/
 */
public void mouseReleased(final MouseEvent e) {

    final JTableHeader header = (JTableHeader) e.getComponent();

    if (header.getResizingColumn() == null) { // resizing takes precedence over sorting
        if (this.sortColumnIndex != -1) {
            final SortableTableModel model = (SortableTableModel) header.getTable().getModel();
            final boolean ascending = !model.isAscending();
            model.setAscending(ascending);
            model.sortByColumn(this.sortColumnIndex, ascending);

            this.renderer.setPressedColumn(-1); // clear
            header.repaint();
        }
    }
}

From source file:SortableTable.java

/**
 * Handle a mouse press event - if the user is NOT resizing a column and NOT dragging a column
 * then give visual feedback that the column header has been pressed.
 *
 * @param e  the mouse event./*from   w  w  w .  ja  va2  s  .c om*/
 */
public void mousePressed(final MouseEvent e) {

    final JTableHeader header = (JTableHeader) e.getComponent();

    if (header.getResizingColumn() == null) { // resizing takes precedence over sorting
        if (header.getDraggedDistance() < 1) { // dragging also takes precedence over sorting
            final int columnIndex = header.columnAtPoint(e.getPoint());
            final int modelColumnIndex = header.getTable().convertColumnIndexToModel(columnIndex);
            if (this.model.isSortable(modelColumnIndex)) {
                this.sortColumnIndex = header.getTable().convertColumnIndexToModel(columnIndex);
                this.renderer.setPressedColumn(this.sortColumnIndex);
                header.repaint();
                if (header.getTable().isEditing()) {
                    header.getTable().getCellEditor().stopCellEditing();
                }
            } else {
                this.sortColumnIndex = -1;
            }
        }
    }

}

From source file:de.tntinteractive.portalsammler.gui.DocumentTable.java

private void showPopup(final MouseEvent ev) {
    final JMenuItem open = new JMenuItem("Anzeigen");
    open.addActionListener(new ActionListener() {
        @Override/*from ww w  .j  av  a 2 s. c  o  m*/
        public void actionPerformed(final ActionEvent e) {
            DocumentTable.this.openSelectedRows();
        }
    });

    final JMenuItem export = new JMenuItem("Exportieren");
    export.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            DocumentTable.this.exportSelectedRows();
        }
    });

    final JPopupMenu menu = new JPopupMenu();
    menu.add(open);
    menu.add(export);
    menu.show(ev.getComponent(), ev.getX(), ev.getY());
}

From source file:org.pmedv.blackboard.dialogs.PartDialog.java

private void handlePopupTrigger(MouseEvent e) {
    if (e.isPopupTrigger() && model.getParts().size() >= 1) {
        Point p = e.getPoint();//from w  ww .ja  v  a  2 s .  co  m
        // get the row index that contains that coordinate
        int rowNumber = partPanel.getPartTable().rowAtPoint(p);
        // Get the ListSelectionModel of the JTable
        ListSelectionModel model = partPanel.getPartTable().getSelectionModel();
        // set the selected interval of rows. Using the "rowNumber"
        // variable for the beginning and end selects only that one row.
        model.setSelectionInterval(rowNumber, rowNumber);
        tablePopupMenu.show(e.getComponent(), e.getX(), e.getY());
    }
}

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

private void processEvent(MouseEvent e, JXLayer layer) {
    if (MouseEvent.MOUSE_DRAGGED == e.getID()) {
        return;/*from   w  w w .j a v a 2s . c o  m*/
    }

    final Point mousePoint = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), layer);
    if (this.updateMainTraceInfo(mousePoint)) {
        this.updateIndicatorTraceInfos(this.mainTraceInfo.getDataIndex());
        this.setDirty(true);
    }
}