Java Code Examples for java.util.EventObject#getSource()
The following examples show how to use
java.util.EventObject#getSource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DarkTableCellEditorDelegate.java From darklaf with MIT License | 6 votes |
@Override public boolean isCellEditable(final EventObject anEvent) { if (anEvent == null) return super.isCellEditable(anEvent); JTable table = ((JTable) anEvent.getSource()); if (anEvent instanceof KeyEvent) { if (DarkTableUI.ignoreKeyCodeOnEdit((KeyEvent) anEvent, table)) return false; } if (anEvent instanceof MouseEvent && TableConstants.isBooleanRenderingEnabled(table)) { Point p = ((MouseEvent) anEvent).getPoint(); int row = table.rowAtPoint(p); int col = table.columnAtPoint(p); if (row >= 0 && row < table.getRowCount() && col >= 0 && col < table.getColumnCount()) { Object value = table.getValueAt(row, col); if (TableConstants.useBooleanEditorForValue(value, table)) { Rectangle rect = table.getCellRect(row, col, false); p.x -= rect.x; p.y -= rect.y; Component editor = getBooleanEditor(table).getTableCellEditorComponent(table, true, false, row, col); editor.setBounds(rect); return editor.contains(p); } } } return super.isCellEditable(anEvent); }
Example 2
Source File: ConfigurationsComboModel.java From netbeans with Apache License 2.0 | 6 votes |
public void confirm(EventObject fe) { JTextField tf = (JTextField) fe.getSource(); JComboBox combo = (JComboBox) tf.getParent(); if (combo==null) return; if (fe instanceof FocusEvent) { combo.getEditor().getEditorComponent().removeFocusListener(this); } else { combo.getEditor().getEditorComponent().removeKeyListener(this); } Configuration config = configName==null ? ConfigurationsManager.getDefault().duplicate(lastSelected, tf.getText(), tf.getText()): ConfigurationsManager.getDefault().create(tf.getText(), tf.getText()); combo.setSelectedItem(config); combo.setEditable(false); currentActiveItem = null; }
Example 3
Source File: ComboBoxTableCellEditor.java From netbeans with Apache License 2.0 | 6 votes |
/********************************************************************** * Is the cell editable? If the mouse was pressed at a margin * we don't want the cell to be editable. * * @param evt The event-object. * * @interfaceMethod javax.swing.table.TableCellEditor *********************************************************************/ public boolean isCellEditable (EventObject evt) { this.startEditingEvent = evt; if (evt instanceof MouseEvent && evt.getSource () instanceof JTable) { MouseEvent me = (MouseEvent) evt; JTable table = (JTable) me.getSource (); Point pt = new Point (me.getX (), me.getY ()); int row = table.rowAtPoint (pt); int col = table.columnAtPoint (pt); Rectangle rec = table.getCellRect (row, col, false); if (me.getY () >= rec.y + rec.height || me.getX () >= rec.x + rec.width) { return false; } } return super.isCellEditable (evt); }
Example 4
Source File: ConfigurationsComboModel.java From netbeans with Apache License 2.0 | 6 votes |
public void confirm(EventObject fe) { JTextField tf = (JTextField) fe.getSource(); JComboBox combo = (JComboBox) tf.getParent(); if (combo==null) return; if (fe instanceof FocusEvent) { combo.getEditor().getEditorComponent().removeFocusListener(this); } else { combo.getEditor().getEditorComponent().removeKeyListener(this); } Configuration config = lastSelected; config.setDisplayName(tf.getText()); combo.setSelectedItem(config); combo.setEditable(false); currentActiveItem = null; }
Example 5
Source File: TableRendererTest.java From netbeans with Apache License 2.0 | 6 votes |
@Override public boolean isCellEditable(EventObject anEvent) { if (anEvent.getSource() instanceof JTable) { JTable table = (JTable) anEvent.getSource(); if (anEvent instanceof MouseEvent) { MouseEvent event = (MouseEvent) anEvent; Point p = event.getPoint(); int row = table.rowAtPoint(p); int col = table.columnAtPoint(p); Rectangle rect = table.getCellRect(row, col, true); p.translate(-rect.x, -rect.y); System.out.println("isCellEditable("+anEvent+")"); System.out.println("Point "+p+"in rectangle "+rect); if (p.x > rect.width - 24) { // last 24 points not editable return false; } } } return true; }
Example 6
Source File: ConfigTree.java From rcrs-server with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public boolean isCellEditable(EventObject o) { if (o instanceof MouseEvent && o.getSource() instanceof JTree) { JTree tree = (JTree)o.getSource(); MouseEvent e = (MouseEvent)o; if (e.getClickCount() > 1) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); Object leaf = path.getLastPathComponent(); if (leaf instanceof DefaultMutableTreeNode) { Object content = ((DefaultMutableTreeNode)leaf).getUserObject(); return content instanceof ConfigEntryNode; } } } return false; }
Example 7
Source File: PeriodicTableDialog.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
@Override public void stateChanged(EventObject event) { if (event.getSource() == periodicTable) { try { IsotopeFactory isoFac = Isotopes.getInstance(); selectedIsotope = isoFac.getMajorIsotope(periodicTable.getElementSymbol()); } catch (Exception e) { e.printStackTrace(); } hide(); } }
Example 8
Source File: DefaultTreeCellEditor.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * If the <code>realEditor</code> returns true to this * message, <code>prepareForEditing</code> * is messaged and true is returned. */ public boolean isCellEditable(EventObject event) { boolean retValue = false; boolean editable = false; if (event != null) { if (event.getSource() instanceof JTree) { setTree((JTree)event.getSource()); if (event instanceof MouseEvent) { TreePath path = tree.getPathForLocation( ((MouseEvent)event).getX(), ((MouseEvent)event).getY()); editable = (lastPath != null && path != null && lastPath.equals(path)); if (path!=null) { lastRow = tree.getRowForPath(path); Object value = path.getLastPathComponent(); boolean isSelected = tree.isRowSelected(lastRow); boolean expanded = tree.isExpanded(path); TreeModel treeModel = tree.getModel(); boolean leaf = treeModel.isLeaf(value); determineOffset(tree, value, isSelected, expanded, leaf, lastRow); } } } } if(!realEditor.isCellEditable(event)) return false; if(canEditImmediately(event)) retValue = true; else if(editable && shouldStartEditingTimer(event)) { startEditingTimer(); } else if(timer != null && timer.isRunning()) timer.stop(); if(retValue) prepareForEditing(); return retValue; }
Example 9
Source File: DefaultTreeCellEditor.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * If the <code>realEditor</code> returns true to this * message, <code>prepareForEditing</code> * is messaged and true is returned. */ public boolean isCellEditable(EventObject event) { boolean retValue = false; boolean editable = false; if (event != null) { if (event.getSource() instanceof JTree) { setTree((JTree)event.getSource()); if (event instanceof MouseEvent) { TreePath path = tree.getPathForLocation( ((MouseEvent)event).getX(), ((MouseEvent)event).getY()); editable = (lastPath != null && path != null && lastPath.equals(path)); if (path!=null) { lastRow = tree.getRowForPath(path); Object value = path.getLastPathComponent(); boolean isSelected = tree.isRowSelected(lastRow); boolean expanded = tree.isExpanded(path); TreeModel treeModel = tree.getModel(); boolean leaf = treeModel.isLeaf(value); determineOffset(tree, value, isSelected, expanded, leaf, lastRow); } } } } if(!realEditor.isCellEditable(event)) return false; if(canEditImmediately(event)) retValue = true; else if(editable && shouldStartEditingTimer(event)) { startEditingTimer(); } else if(timer != null && timer.isRunning()) timer.stop(); if(retValue) prepareForEditing(); return retValue; }
Example 10
Source File: DefaultTreeCellEditor.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * If the <code>realEditor</code> returns true to this * message, <code>prepareForEditing</code> * is messaged and true is returned. */ public boolean isCellEditable(EventObject event) { boolean retValue = false; boolean editable = false; if (event != null) { if (event.getSource() instanceof JTree) { setTree((JTree)event.getSource()); if (event instanceof MouseEvent) { TreePath path = tree.getPathForLocation( ((MouseEvent)event).getX(), ((MouseEvent)event).getY()); editable = (lastPath != null && path != null && lastPath.equals(path)); if (path!=null) { lastRow = tree.getRowForPath(path); Object value = path.getLastPathComponent(); boolean isSelected = tree.isRowSelected(lastRow); boolean expanded = tree.isExpanded(path); TreeModel treeModel = tree.getModel(); boolean leaf = treeModel.isLeaf(value); determineOffset(tree, value, isSelected, expanded, leaf, lastRow); } } } } if(!realEditor.isCellEditable(event)) return false; if(canEditImmediately(event)) retValue = true; else if(editable && shouldStartEditingTimer(event)) { startEditingTimer(); } else if(timer != null && timer.isRunning()) timer.stop(); if(retValue) prepareForEditing(); return retValue; }
Example 11
Source File: DefaultTreeCellEditor.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * If the <code>realEditor</code> returns true to this * message, <code>prepareForEditing</code> * is messaged and true is returned. */ public boolean isCellEditable(EventObject event) { boolean retValue = false; boolean editable = false; if (event != null) { if (event.getSource() instanceof JTree) { setTree((JTree)event.getSource()); if (event instanceof MouseEvent) { TreePath path = tree.getPathForLocation( ((MouseEvent)event).getX(), ((MouseEvent)event).getY()); editable = (lastPath != null && path != null && lastPath.equals(path)); if (path!=null) { lastRow = tree.getRowForPath(path); Object value = path.getLastPathComponent(); boolean isSelected = tree.isRowSelected(lastRow); boolean expanded = tree.isExpanded(path); TreeModel treeModel = tree.getModel(); boolean leaf = treeModel.isLeaf(value); determineOffset(tree, value, isSelected, expanded, leaf, lastRow); } } } } if(!realEditor.isCellEditable(event)) return false; if(canEditImmediately(event)) retValue = true; else if(editable && shouldStartEditingTimer(event)) { startEditingTimer(); } else if(timer != null && timer.isRunning()) timer.stop(); if(retValue) prepareForEditing(); return retValue; }
Example 12
Source File: DefaultTreeCellEditor.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * If the <code>realEditor</code> returns true to this * message, <code>prepareForEditing</code> * is messaged and true is returned. */ public boolean isCellEditable(EventObject event) { boolean retValue = false; boolean editable = false; if (event != null) { if (event.getSource() instanceof JTree) { setTree((JTree)event.getSource()); if (event instanceof MouseEvent) { TreePath path = tree.getPathForLocation( ((MouseEvent)event).getX(), ((MouseEvent)event).getY()); editable = (lastPath != null && path != null && lastPath.equals(path)); if (path!=null) { lastRow = tree.getRowForPath(path); Object value = path.getLastPathComponent(); boolean isSelected = tree.isRowSelected(lastRow); boolean expanded = tree.isExpanded(path); TreeModel treeModel = tree.getModel(); boolean leaf = treeModel.isLeaf(value); determineOffset(tree, value, isSelected, expanded, leaf, lastRow); } } } } if(!realEditor.isCellEditable(event)) return false; if(canEditImmediately(event)) retValue = true; else if(editable && shouldStartEditingTimer(event)) { startEditingTimer(); } else if(timer != null && timer.isRunning()) timer.stop(); if(retValue) prepareForEditing(); return retValue; }
Example 13
Source File: DefaultTreeCellEditor.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * If the <code>realEditor</code> returns true to this * message, <code>prepareForEditing</code> * is messaged and true is returned. */ public boolean isCellEditable(EventObject event) { boolean retValue = false; boolean editable = false; if (event != null) { if (event.getSource() instanceof JTree) { setTree((JTree)event.getSource()); if (event instanceof MouseEvent) { TreePath path = tree.getPathForLocation( ((MouseEvent)event).getX(), ((MouseEvent)event).getY()); editable = (lastPath != null && path != null && lastPath.equals(path)); if (path!=null) { lastRow = tree.getRowForPath(path); Object value = path.getLastPathComponent(); boolean isSelected = tree.isRowSelected(lastRow); boolean expanded = tree.isExpanded(path); TreeModel treeModel = tree.getModel(); boolean leaf = treeModel.isLeaf(value); determineOffset(tree, value, isSelected, expanded, leaf, lastRow); } } } } if(!realEditor.isCellEditable(event)) return false; if(canEditImmediately(event)) retValue = true; else if(editable && shouldStartEditingTimer(event)) { startEditingTimer(); } else if(timer != null && timer.isRunning()) timer.stop(); if(retValue) prepareForEditing(); return retValue; }
Example 14
Source File: ConfigurationsComboModel.java From netbeans with Apache License 2.0 | 5 votes |
private void confirm(EventObject fe) { JTextField tf = (JTextField) fe.getSource(); JComboBox combo = (JComboBox) tf.getParent(); if (combo==null) return; if (fe instanceof FocusEvent) { combo.getEditor().getEditorComponent().removeFocusListener(this); } else { combo.getEditor().getEditorComponent().removeKeyListener(this); } Configuration config = lastSelected; config.setDisplayName(tf.getText()); combo.setSelectedItem(config); combo.setEditable(false); }
Example 15
Source File: DelegatingCellEditor.java From netbeans with Apache License 2.0 | 5 votes |
@Override public boolean shouldSelectCell(EventObject anEvent) { if (!(anEvent.getSource() instanceof Outline)) { return false; } Outline outline = (Outline) anEvent.getSource(); if (!(anEvent instanceof MouseEvent)) { return false; } MouseEvent event = (MouseEvent) anEvent; Point p = event.getPoint(); // Locate the editor under the event location //int column = outline.columnAtPoint(p); int row = outline.rowAtPoint(p); Node n = DelegatingCellRenderer.getNodeAt(outline, row); if (n instanceof TreeModelNode) { TreeModelNode tmn = (TreeModelNode) n; TableRendererModel trm = tmn.getModel(); try { if (trm.canEditCell(tmn.getObject(), columnID)) { TableCellEditor editor = trm.getCellEditor(tmn.getObject(), columnID); if (editor != null) { return editor.shouldSelectCell(anEvent); } } } catch (UnknownTypeException ex) { } } return defaultEditor.shouldSelectCell(anEvent); }
Example 16
Source File: BaseTable.java From netbeans with Apache License 2.0 | 5 votes |
private void trySendEnterToDialog(BaseTable bt) { // System.err.println("SendEnterToDialog"); EventObject ev = EventQueue.getCurrentEvent(); if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ENTER)) { if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) { return; } if ( ev.getSource() instanceof JTextComponent && ((JTextComponent) ev.getSource()).getParent() instanceof JComboBox && ((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible() ) { return; } JRootPane jrp = bt.getRootPane(); if (jrp != null) { JButton b = jrp.getDefaultButton(); if ((b != null) && b.isEnabled()) { b.doClick(); } } } }
Example 17
Source File: Ruler.java From openAGV with Apache License 2.0 | 5 votes |
@Override public void originScaleChanged(EventObject evt) { if (evt.getSource() instanceof Origin) { Origin origin = (Origin) evt.getSource(); SwingUtilities.invokeLater(() -> { horizontalRulerScale = origin.getScaleX(); repaint(); }); } }
Example 18
Source File: DefaultTreeCellEditor.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * If the <code>realEditor</code> returns true to this * message, <code>prepareForEditing</code> * is messaged and true is returned. */ public boolean isCellEditable(EventObject event) { boolean retValue = false; boolean editable = false; if (event != null) { if (event.getSource() instanceof JTree) { setTree((JTree)event.getSource()); if (event instanceof MouseEvent) { TreePath path = tree.getPathForLocation( ((MouseEvent)event).getX(), ((MouseEvent)event).getY()); editable = (lastPath != null && path != null && lastPath.equals(path)); if (path!=null) { lastRow = tree.getRowForPath(path); Object value = path.getLastPathComponent(); boolean isSelected = tree.isRowSelected(lastRow); boolean expanded = tree.isExpanded(path); TreeModel treeModel = tree.getModel(); boolean leaf = treeModel.isLeaf(value); determineOffset(tree, value, isSelected, expanded, leaf, lastRow); } } } } if(!realEditor.isCellEditable(event)) return false; if(canEditImmediately(event)) retValue = true; else if(editable && shouldStartEditingTimer(event)) { startEditingTimer(); } else if(timer != null && timer.isRunning()) timer.stop(); if(retValue) prepareForEditing(); return retValue; }
Example 19
Source File: EditablePropertyDisplayer.java From netbeans with Apache License 2.0 | 4 votes |
/** Transmits escape sequence to dialog */ private void trySendEscToDialog() { if (isTableUI()) { //let the table decide, don't be preemptive return; } // System.err.println("SendEscToDialog"); EventObject ev = EventQueue.getCurrentEvent(); if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ESCAPE)) { if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) { return; } if ( ev.getSource() instanceof JTextComponent && ((JTextComponent) ev.getSource()).getParent() instanceof JComboBox && ((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible() ) { return; } InputMap imp = getRootPane().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionMap am = getRootPane().getActionMap(); KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); Object key = imp.get(escape); if (key != null) { Action a = am.get(key); if (a != null) { if (Boolean.getBoolean("netbeans.proppanel.logDialogActions")) { //NOI18N System.err.println("Action bound to escape key is " + a); //NOI18N } String commandKey = (String) a.getValue(Action.ACTION_COMMAND_KEY); if (commandKey == null) { commandKey = "cancel"; //NOI18N } a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, commandKey)); //NOI18N } } } }
Example 20
Source File: BaseTable.java From netbeans with Apache License 2.0 | 4 votes |
private void trySendEscToDialog(JTable jt) { // System.err.println("SendEscToDialog"); EventObject ev = EventQueue.getCurrentEvent(); if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ESCAPE)) { if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) { return; } if ( ev.getSource() instanceof JTextComponent && ((JTextComponent) ev.getSource()).getParent() instanceof JComboBox && ((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible() ) { return; } InputMap imp = jt.getRootPane().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionMap am = jt.getRootPane().getActionMap(); KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); Object key = imp.get(escape); if (key != null) { Action a = am.get(key); if (a != null) { if (Boolean.getBoolean("netbeans.proppanel.logDialogActions")) { //NOI18N System.err.println("Action bound to escape key is " + a); //NOI18N } //Actions registered with deprecated registerKeyboardAction will //need this lookup of the action command String commandKey = (String) a.getValue(Action.ACTION_COMMAND_KEY); if (commandKey == null) { commandKey = "cancel"; //NOI18N } a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, commandKey)); //NOI18N } } } }