Example usage for java.awt.event MouseEvent getSource

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

Introduction

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

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java

@Override
public void mouseClicked(MouseEvent e) {
    if (e.getSource() == table) {
        if (e.getClickCount() == 2) {
            // Only react to double clicks
            final List<File> selection = getSelection();

            if (selection.size() == 1) {
                final File file = selection.iterator().next();

                if (file.isDirectory()) {
                    // Change to the clicked directory
                    setDirectory(file);//from  w w  w.  ja v a2  s. com
                } else {
                    try {
                        // View the selected file
                        new ProcessBuilder(preferences.getViewFileCommand(), file.getAbsolutePath()).start();
                    } catch (IOException e1) {
                        logger.error("Error when viewing file", e1);
                    }
                }
            }
        }
    } else if (e.getSource() == table.getTableHeader()) {
        final int columnIndex = table.convertColumnIndexToModel(table.columnAtPoint(e.getPoint()));

        if (columnIndex >= 0) {
            // React to clicks on column headers and sort the entries accordingly
            switch (columnIndex) {
            case 0:
                tableModel.setSortCriteria(SortCriteria.TYPE);
                break;
            case 1:
                tableModel.setSortCriteria(SortCriteria.NAME);
                break;
            case 2:
                tableModel.setSortCriteria(SortCriteria.SIZE);
                break;
            case 3:
                tableModel.setSortCriteria(SortCriteria.LAST_UPDATE);
                break;
            default:
                throw new UnsupportedOperationException("Unsupported column index: " + columnIndex);
            }
        }
    }
}

From source file:graph.eventhandlers.MyEditingGraphMousePlugin.java

/**
 * If startVertex is non-null, and the mouse is released over an existing
 * vertex, create an undirected edge from startVertex to the vertex under
 * the mouse pointer. If shift was also pressed, create a directed edge
 * instead.//from   w ww .j a va  2s . c om
 */
public void mouseReleased(MouseEvent e) {
    pw = graphInstance.getPathway();
    if (checkModifiers(e)) {
        final VisualizationViewer<BiologicalNodeAbstract, BiologicalEdgeAbstract> vv = (VisualizationViewer) e
                .getSource();
        //final Point2D p = vv.getRenderContext().getMultiLayerTransformer()
        //      .inverseTransform(e.getPoint());
        //int v = vv.getPickedVertexState().getPicked().size();
        //int edge = vv.getPickedEdgeState().getPicked().size();
        GraphElementAccessor<BiologicalNodeAbstract, BiologicalEdgeAbstract> pickSupport = vv.getPickSupport();
        // if (v > 0) {
        // System.out.println("release");
        final BiologicalNodeAbstract vertex = (BiologicalNodeAbstract) pickSupport
                .getVertex(vv.getGraphLayout(), e.getPoint().getX(), e.getPoint().getY());
        if (vertex != null && startVertex != null) {

            // Pathway pw = graphInstance.getPathway();

            BiologicalNodeAbstract start = startVertex;// (BiologicalNodeAbstract)
            // pw
            // .getNodeByVertexID(startVertex.toString());
            BiologicalNodeAbstract end = vertex;// (BiologicalNodeAbstract)
            // pw
            // .getNodeByVertexID(vertex.toString());

            if (pw.isPetriNet() && !((start instanceof Place && end instanceof Transition)
                    || (start instanceof Transition && end instanceof Place)))
                JOptionPane.showMessageDialog(MainWindowSingleton.getInstance(),
                        "In a petri net only Transition->Place and Place->Transition Relations are allowed!",
                        "Unallowed Operation...", JOptionPane.ERROR_MESSAGE);

            else if ((start instanceof ContinuousTransition && end instanceof Place
                    && ((Place) end).isDiscrete())
                    || (end instanceof ContinuousTransition && start instanceof Place
                            && ((Place) start).isDiscrete()))
                JOptionPane.showMessageDialog(MainWindowSingleton.getInstance(),
                        "Relations between discrete Places and Continoues Transitions are not possible!",
                        "Unallowed Operation...", JOptionPane.ERROR_MESSAGE);
            else {
                // Graph graph = vv.getGraphLayout().getGraph();
                EdgeDialog dialog = new EdgeDialog(startVertex, vertex);
                Pair<String[], BiologicalNodeAbstract[]> answer = dialog.getAnswer();
                String[] answers = answer.getLeft();
                BiologicalNodeAbstract[] nodes = answer.getRight();

                if (answers != null) {
                    if (answers[2] != null && answers[2].toLowerCase().contains("inhibi")
                            && !(startVertex instanceof Place && vertex instanceof Transition))
                        JOptionPane.showMessageDialog(MainWindowSingleton.getInstance(),
                                "Inhibitory Edges are only possible from Place to Transition!",
                                "Unallowed Operation...", JOptionPane.ERROR_MESSAGE);
                    else {
                        String name = answers[0];
                        String label = answers[0];
                        String element = answers[2];
                        if (answers[2].toLowerCase().contains("inhibi")) {
                            element = Elementdeclerations.pnInhibitionEdge;
                        }
                        boolean directed = false;
                        if (answers[1].equals("directed_edge")) {
                            directed = true;
                        }

                        Set<BiologicalNodeAbstract> parentBNAs = new HashSet<BiologicalNodeAbstract>();
                        parentBNAs.addAll(nodes[0].getAllParentNodes());
                        parentBNAs.addAll(nodes[1].getAllParentNodes());
                        BiologicalEdgeAbstract bea = pw.addEdge(label, name, nodes[0], nodes[1], element,
                                directed);
                        if (nodes[0] == startVertex && nodes[1] == vertex) {
                            pw.addEdgeToView(bea, false);
                        } else {
                            BiologicalEdgeAbstract clone = bea.clone();
                            clone.setFrom(startVertex);
                            clone.setTo(vertex);
                            pw.addEdgeToView(clone, false);
                        }
                    }
                }
            }
        }
        vv.repaint();
        startVertex = null;
        down = null;
        edgeIsDirected = false;
        vv.removePostRenderPaintable(edgePaintable);
        vv.removePostRenderPaintable(arrowPaintable);
    }
}

From source file:ca.phon.app.session.editor.view.session_information.SessionInfoEditorView.java

private void init() {
    setLayout(new BorderLayout());

    contentPanel = new TierDataLayoutPanel();

    dateField = createDateField();/*from w  ww .j ava2 s .  c o m*/
    dateField.getTextField().setColumns(10);
    dateField.setBackground(Color.white);

    mediaLocationField = new MediaSelectionField(getEditor().getProject());
    mediaLocationField.setEditor(getEditor());
    mediaLocationField.getTextField().setColumns(10);
    mediaLocationField.addPropertyChangeListener(FileSelectionField.FILE_PROP, mediaLocationListener);

    participantTable = new JXTable();
    participantTable.setVisibleRowCount(3);

    ComponentInputMap participantTableInputMap = new ComponentInputMap(participantTable);
    ActionMap participantTableActionMap = new ActionMap();

    ImageIcon deleteIcon = IconManager.getInstance().getIcon("actions/delete_user", IconSize.SMALL);
    final PhonUIAction deleteAction = new PhonUIAction(this, "deleteParticipant");
    deleteAction.putValue(PhonUIAction.SHORT_DESCRIPTION, "Delete selected participant");
    deleteAction.putValue(PhonUIAction.SMALL_ICON, deleteIcon);
    participantTableActionMap.put("DELETE_PARTICIPANT", deleteAction);
    participantTableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "DELETE_PARTICIPANT");
    participantTableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "DELETE_PARTICIPANT");

    removeParticipantButton = new JButton(deleteAction);

    participantTable.setInputMap(WHEN_FOCUSED, participantTableInputMap);
    participantTable.setActionMap(participantTableActionMap);

    addParticipantButton = new JButton(new NewParticipantAction(getEditor(), this));
    addParticipantButton.setFocusable(false);

    ImageIcon editIcon = IconManager.getInstance().getIcon("actions/edit_user", IconSize.SMALL);
    final PhonUIAction editParticipantAct = new PhonUIAction(this, "editParticipant");
    editParticipantAct.putValue(PhonUIAction.NAME, "Edit participant...");
    editParticipantAct.putValue(PhonUIAction.SHORT_DESCRIPTION, "Edit selected participant...");
    editParticipantAct.putValue(PhonUIAction.SMALL_ICON, editIcon);
    editParticipantButton = new JButton(editParticipantAct);
    editParticipantButton.setFocusable(false);

    final CellConstraints cc = new CellConstraints();
    FormLayout participantLayout = new FormLayout("fill:pref:grow, pref, pref, pref", "pref, pref, pref:grow");
    JPanel participantPanel = new JPanel(participantLayout);
    participantPanel.setBackground(Color.white);
    participantPanel.add(new JScrollPane(participantTable), cc.xywh(1, 2, 3, 2));
    participantPanel.add(addParticipantButton, cc.xy(2, 1));
    participantPanel.add(editParticipantButton, cc.xy(3, 1));
    participantPanel.add(removeParticipantButton, cc.xy(4, 2));
    participantTable.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent arg0) {
            if (arg0.getClickCount() == 2 && arg0.getButton() == MouseEvent.BUTTON1) {
                editParticipantAct.actionPerformed(new ActionEvent(arg0.getSource(), arg0.getID(), "edit"));
            }
        }

    });

    languageField = new LanguageField();
    languageField.getDocument().addDocumentListener(languageFieldListener);

    int rowIdx = 0;
    final JLabel dateLbl = new JLabel("Session Date");
    dateLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(dateLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(dateField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    final JLabel mediaLbl = new JLabel("Media");
    mediaLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(mediaLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(mediaLocationField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    final JLabel partLbl = new JLabel("Participants");
    partLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(partLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(participantPanel, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    final JLabel langLbl = new JLabel("Language");
    langLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(langLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(languageField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    add(new JScrollPane(contentPanel), BorderLayout.CENTER);

    update();
}

From source file:edu.harvard.i2b2.query.QueryTopPanel.java

private void jAndOrLabelMouseClicked(java.awt.event.MouseEvent evt) {
    JLabel label = (JLabel) evt.getSource();
    if (label.getText().equalsIgnoreCase("and")) {
        label.setText("or");
    } else if (label.getText().equalsIgnoreCase("or")) {
        label.setText("and");
    }//ww w.jav a  2 s.c  o  m
}

From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewer.java

private void setupTable() {
    tableModel = new ElementListTableModel();
    table = new JXTable(tableModel);

    tableSorter = new ElementListTableSorter(tableModel, table);
    table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(true);//from www  .  j a  v a 2s  . c om

    // set our column widths
    ElementListTableModel.setupColumnWidths(table);

    table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false));
    table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false));

    // hide irrelevent columns
    TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel();
    table.setColumnControlVisible(true);
    colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false);
    colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false);

    // popup menu
    table.addMouseListener(new PopupListener() {
        @Override
        public void showPopup(MouseEvent e) {
            // only clicks on tables
            if (!(e.getSource() instanceof JTable))
                return;

            JTable table = (JTable) e.getSource();
            ElementListTableModel model = (ElementListTableModel) table.getModel();

            // get the row and sanity check
            int row = table.rowAtPoint(e.getPoint());
            if (row < 0 || row >= model.getRowCount())
                return;

            // select it?
            table.setRowSelectionInterval(row, row);

            // get the element
            Element element = model.getElementAt(row);

            // create and show the menu
            JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewer.this);
            popup.show(table, e.getX(), e.getY());
        }
    });
}

From source file:com.openbravo.pos.sales.JTicketLines.java

/** Creates new form JLinesTicket */
public JTicketLines(AppView app, String propertyRowHeight, String propertyFontsize, String ticketline) {
    this.m_App = app;
    initComponents();//from   w  w w . j a  v a 2  s .  co  m

    m_jTicketTable.m_App = app;
    m_jTicketTable.propertyRowHeight = propertyRowHeight;

    ColumnTicket[] acolumns = new ColumnTicket[0];

    if (ticketline != null) {
        try {
            if (m_sp == null) {
                SAXParserFactory spf = SAXParserFactory.newInstance();
                m_sp = spf.newSAXParser();
            }
            ColumnsHandler columnshandler = new ColumnsHandler();
            m_sp.parse(new InputSource(new StringReader(ticketline)), columnshandler);
            acolumns = columnshandler.getColumns();

        } catch (ParserConfigurationException ePC) {
            logger.log(Level.WARNING, LocalRes.getIntString("exception.parserconfig"), ePC);
        } catch (SAXException eSAX) {
            logger.log(Level.WARNING, LocalRes.getIntString("exception.xmlfile"), eSAX);
        } catch (IOException eIO) {
            logger.log(Level.WARNING, LocalRes.getIntString("exception.iofile"), eIO);
        }
    }

    Map<String, Integer> widths = PropertyUtil.getTicketLineWidths(m_App);
    for (ColumnTicket acolumn : acolumns) {
        Integer width = widths.get(acolumn.name);
        if (width == null) {
            continue;
        }
        acolumn.width = width;
    }

    m_jTableModel = new TicketTableModel(acolumns);
    m_jTicketTable.setModel(m_jTableModel);

    m_jTicketTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
    TableColumnModel jColumns = m_jTicketTable.getColumnModel();
    for (int i = 0; i < acolumns.length; i++) {
        jColumns.getColumn(i).setPreferredWidth(acolumns[i].width);
        jColumns.getColumn(i).setResizable(true);
    }

    PropertyUtil.ScaleScrollbar(m_App, m_jScrollTableTicket);

    m_jTicketTable.getTableHeader().setReorderingAllowed(false);
    // m_jTicketTable.setDefaultRenderer(Object.class, new
    // TicketCellRenderer(app, acolumns, propertyFontsize));
    m_jTicketTable.setDefaultRenderer(Object.class,
            new RowHeightCellRenderer(app, acolumns, propertyFontsize, propertyRowHeight));

    PropertyUtil.ScaleTableColumnFontsize(m_App, m_jTicketTable, "sales-tablecolumn-fontsize", "14");

    m_jTicketTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    m_jTicketTable.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent me) {
            JTable table = (JTable) me.getSource();
            Point p = me.getPoint();
            int row = table.rowAtPoint(p);
            if (me.getClickCount() == 2) {
                // your valueChanged overridden method
                listDoubleClickListener.valueChanged(new ListSelectionEvent(m_jTicketTable, row, row, false));
            }
        }
    });
    // reseteo la tabla...
    m_jTableModel.clear();
}

From source file:org.tmpotter.ui.ActionHandler.java

public void onTableClicked(MouseEvent evt) {
    javax.swing.JTable table = (javax.swing.JTable) evt.getSource();
    Point point = evt.getPoint();
    int row = table.rowAtPoint(point);
    int col = table.columnAtPoint(point);

    table.setRowSelectionInterval(row, row);
    table.setColumnSelectionInterval(col, col);

    tmData.setPositionTextArea(0);// w  w w  .ja  v a  2s. c o  m
    if (tmData.getIndexPrevious() < tmData.getDocumentOriginalSize()) {
        tmData.setOriginalDocumentAnt(restoreText(modelMediator.getLeftEdit()));
        tmData.setTranslationDocumentAnt(restoreText(modelMediator.getRightEdit()));
    }
    modelMediator.setLeftEdit(formatText(modelMediator.getLeftSegment(modelMediator.getTmViewSelectedRow())));
    modelMediator.setRightEdit(formatText(modelMediator.getRightSegment(modelMediator.getTmViewSelectedRow())));
    tmData.setBothIndex(modelMediator.getTmViewSelectedRow());
    if (tmData.isIdentTop()) {
        modelMediator.setJoinEnabled(false);
    } else {
        modelMediator.setJoinEnabled(true);
    }
    modelMediator.updateTmView();
}

From source file:com.hp.alm.ali.idea.content.taskboard.TaskBoardPanel.java

private <T extends Component> T locateContainer(MouseEvent event, Class<T> clazz) {
    Point p = SwingUtilities.convertPoint((Component) event.getSource(), event.getPoint(), TaskBoardPanel.this);
    Component comp = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
    return (T) SwingUtilities.getAncestorOfClass(clazz, comp);
}

From source file:gui.InboxPanel.java

public void generate() {
    Message[] arrMsg = GmailAPI.Inbox.toArray(new Message[GmailAPI.Inbox.size()]);
    InboxList = new JList(arrMsg);
    InboxList.setCellRenderer(new DefaultListCellRenderer() { // Setting the DefaultListCellRenderer
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            Message message = (Message) value; // Using value we are getting the object in JList
            Map<String, String> map = null;
            try {
                map = GmailAPI.getMessageDetails(message.getId());
            } catch (MessagingException ex) {
                Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
            }//from  w w  w  .ja  v a  2 s  . co m
            String sub = map.get("subject");
            if (map.get("subject").length() > 22) {
                sub = map.get("subject").substring(0, 20) + "...";
            }
            setText(sub); // Setting the text
            //setIcon( shape.getImage() ); // Setting the Image Icon
            return this;
        }
    });
    InboxList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    InboxList.setLayoutOrientation(JList.VERTICAL);
    InboxList.setVisibleRowCount(-1);
    jScrollPane1.setViewportView(InboxList);

    InboxList.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            try {
                JList list = (JList) evt.getSource();
                int index = list.locationToIndex(evt.getPoint());
                String id = arrMsg[index].getId();
                curId = id;
                Map<String, String> map = GmailAPI.getMessageDetails(id);
                jTextField1.setText(map.get("from"));
                jTextField2.setText(map.get("subject"));
                dateTextField.setText(map.get("senddate"));
                BodyTextPane.setText(map.get("body"));
                //BodyTextPane.setContentType("text/html");
                //BodyTextArea.setCo
            } catch (IOException ex) {
                Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
            } catch (MessagingException ex) {
                Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}

From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java

@Override
public void setSortable(boolean enable) {
    super.setSortable(enable);

    JTableHeader header = getTableHeader();
    if (enable) {
        if (treeTableSortAdapter == null) {
            treeTableSortAdapter = new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    if (SwingUtilities.isLeftMouseButton(e)) {
                        JTableHeader h = (JTableHeader) e.getSource();
                        TableColumnModel columnModel = getColumnModel();

                        int viewColumn = h.columnAtPoint(e.getPoint());
                        int column = columnModel.getColumn(viewColumn).getModelIndex();

                        if (column != -1) {
                            beforeSort();

                            // Toggle sort order (ascending <-> descending)
                            SortableTreeTableModel model = (SortableTreeTableModel) getTreeTableModel();
                            model.setColumnAndToggleSortOrder(column);

                            // Set sorting icon and current column index
                            ((SortableHeaderCellRenderer) getTableHeader().getDefaultRenderer())
                                    .setSortingIcon(model.getSortOrder());
                            ((SortableHeaderCellRenderer) getTableHeader().getDefaultRenderer())
                                    .setColumnIndex(column);

                            saveSortPreferences(column);

                            afterSort();
                        }//w  w w .jav a  2 s.  com
                    }
                }
            };
            header.addMouseListener(treeTableSortAdapter);
        }
    } else {
        if (treeTableSortAdapter != null) {
            header.removeMouseListener(treeTableSortAdapter);
            treeTableSortAdapter = null;
        }
    }
}