List of usage examples for java.awt.event MouseEvent getPoint
public Point getPoint()
From source file:com.intuit.tank.proxy.ProxyApp.java
private JPanel getTransactionTable() { JPanel frame = new JPanel(new BorderLayout()); model = new TransactionTableModel(); final JTable table = new TransactionTable(model); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter);/*w w w.j av a 2 s. co m*/ final JPopupMenu pm = new JPopupMenu(); JMenuItem item = new JMenuItem("Delete Selected"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { int response = JOptionPane.showConfirmDialog(ProxyApp.this, "Are you sure you want to delete " + selectedRows.length + " Transactions?", "Confirm Delete", JOptionPane.YES_NO_OPTION); if (response == JOptionPane.YES_OPTION) { int[] correctedRows = new int[selectedRows.length]; for (int i = selectedRows.length; --i >= 0;) { int row = selectedRows[i]; int index = (Integer) table.getValueAt(row, 0) - 1; correctedRows[i] = index; } Arrays.sort(correctedRows); for (int i = correctedRows.length; --i >= 0;) { int row = correctedRows[i]; Transaction transaction = model.getTransactionForIndex(row); if (transaction != null) { model.removeTransaction(transaction, row); isDirty = true; saveAction.setEnabled(isDirty && !stopAction.isEnabled()); } } } } } }); pm.add(item); table.add(pm); table.addMouseListener(new MouseAdapter() { boolean pressed = false; public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { Point p = e.getPoint(); int row = table.rowAtPoint(p); int index = (Integer) table.getValueAt(row, 0) - 1; Transaction transaction = model.getTransactionForIndex(index); if (transaction != null) { detailsTF.setText(transaction.toString()); detailsTF.setCaretPosition(0); detailsDialog.setVisible(true); } } } /** * @{inheritDoc */ @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { pressed = true; int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { pm.show(e.getComponent(), e.getX(), e.getY()); } } } /** * @{inheritDoc */ @Override public void mouseReleased(MouseEvent e) { if (!pressed && e.isPopupTrigger()) { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { pm.show(e.getComponent(), e.getX(), e.getY()); } } } }); JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Filter: "); panel.add(label, BorderLayout.WEST); final JLabel countLabel = new JLabel(" Count: 0 "); panel.add(countLabel, BorderLayout.EAST); final JTextField filterText = new JTextField(""); filterText.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { String text = filterText.getText(); if (text.length() == 0) { sorter.setRowFilter(null); } else { try { sorter.setRowFilter(RowFilter.regexFilter(text)); countLabel.setText(" Count: " + sorter.getViewRowCount() + " "); } catch (PatternSyntaxException pse) { System.err.println("Bad regex pattern"); } } } }); panel.add(filterText, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); return frame; }
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 ww w . j a v a 2 s.c o 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:net.sf.jabref.gui.MainTableSelectionListener.java
/** * Process general right-click events on the table. Show the table context menu at * the position where the user right-clicked. * @param e The mouse event defining the popup trigger. * @param row The row where the event occured. *///from ww w . ja v a2 s. co m private void processPopupTrigger(MouseEvent e, int row) { int selRow = table.getSelectedRow(); if ((selRow == -1) || // (getSelectedRowCount() == 0)) !table.isRowSelected(table.rowAtPoint(e.getPoint()))) { table.setRowSelectionInterval(row, row); //panel.updateViewToSelected(); } RightClickMenu rightClickMenu = new RightClickMenu(panel, panel.metaData()); rightClickMenu.show(table, e.getX(), e.getY()); }
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. j ava 2 s . com 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:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationCalibrationPanel.java
private void onMouseDragged(MouseEvent e) { if (mouse_start_point != null) { if (is_moving) { // moving double mz_delta = screenToDataX(mouse_start_point.getX() - e.getPoint().getX()); double acc_delta = screenToDataY(e.getPoint().getY() - mouse_start_point.getY()); // update mz if (mz_delta > 0.) { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_upper_bound = old_upper_bound + mz_delta; double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } else { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_lower_bound = old_lower_bound + mz_delta; double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); }/* w w w.j a v a 2 s .co m*/ // update acc if (acc_delta > 0.) { double old_upper_bound = thePlot.getRangeAxis().getUpperBound(); double old_lower_bound = thePlot.getRangeAxis().getLowerBound(); double new_upper_bound = old_upper_bound + acc_delta; double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound; thePlot.getRangeAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } else { double old_upper_bound = thePlot.getRangeAxis().getUpperBound(); double old_lower_bound = thePlot.getRangeAxis().getLowerBound(); double new_lower_bound = old_lower_bound + acc_delta; double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound; thePlot.getRangeAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } mouse_start_point = e.getPoint(); } } }
From source file:burlov.ultracipher.swing.MainPanel.java
public MainPanel(Translator translator) { editDataPanel = new EditDataPanel(translator); translator.addToComponent(searchField); listPopup.add(getNewEntryAction());/* w ww . j a v a 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: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:net.sf.jabref.gui.maintable.MainTable.java
@Override public String getToolTipText(MouseEvent e) { // Set tooltip text for all columns which are not fully displayed String toolTipText = null;//from w w w . ja va 2 s . c o m Point p = e.getPoint(); int col = columnAtPoint(p); int row = rowAtPoint(p); Component comp = prepareRenderer(getCellRenderer(row, col), row, col); Rectangle bounds = getCellRect(row, col, false); Dimension d = comp.getPreferredSize(); if ((d != null) && (d.width > bounds.width) && (getValueAt(row, col) != null)) { toolTipText = getValueAt(row, col).toString(); } return toolTipText; }
From source file:org.nuclos.client.ui.resplan.header.JHeaderGrid.java
@Override public String getToolTipText(MouseEvent event) { int index = stripAtPoint(event.getPoint()); if (index != -1) { JComponent renderer = setupCellRenderer(model.getElementAt(index), false); return renderer.getToolTipText(); } else {//from ww w . ja v a 2s . c o m return getToolTipText(); } }
From source file:Main.java
@Override public boolean isCellEditable(final EventObject event) { Object source = event.getSource(); if (!(source instanceof JTree) || !(event instanceof MouseEvent)) { return false; }/*from w w w . ja v a2s.co m*/ JTree tree = (JTree) source; MouseEvent mouseEvent = (MouseEvent) event; TreePath path = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY()); if (path == null) { return false; } Object node = path.getLastPathComponent(); if (node == null || !(node instanceof DefaultMutableTreeNode)) { return false; } Rectangle r = tree.getPathBounds(path); if (r == null) { return false; } Dimension d = panel.getPreferredSize(); r.setSize(new Dimension(d.width, r.height)); if (r.contains(mouseEvent.getX(), mouseEvent.getY())) { Point pt = SwingUtilities.convertPoint(tree, mouseEvent.getPoint(), panel); Object o = SwingUtilities.getDeepestComponentAt(panel, pt.x, pt.y); if (o instanceof JComboBox) { comboBox.showPopup(); } else if (o instanceof Component) { Object oo = SwingUtilities.getAncestorOfClass(JComboBox.class, (Component) o); if (oo instanceof JComboBox) { comboBox.showPopup(); } } return true; } return delegate.isCellEditable(event); }