下面列出了java.util.EventObject#getSource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
@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;
}
@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;
}
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;
}
/**********************************************************************
* 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);
}
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;
}
/**
* 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;
}
@Override
public void originScaleChanged(EventObject evt) {
if (evt.getSource() instanceof Origin) {
Origin origin = (Origin) evt.getSource();
SwingUtilities.invokeLater(() -> {
horizontalRulerScale = origin.getScaleX();
repaint();
});
}
}
/**
* 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;
}
@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();
}
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
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);
}
@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);
}
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();
}
}
}
}
/** 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
}
}
}
}
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
}
}
}
}