java.util.EventObject Java Examples

The following examples show how to use java.util.EventObject. 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: ConfigurationsComboModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: XMBeanAttributes.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final boolean editCellAt(final int row, final int column, EventObject e) {
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.finer("editCellAt(row="+row+", col="+column+
                ", e="+e+")");
    }
    if (JConsole.isDebug()) {
        System.err.println("edit: "+getValueName(row)+"="+getValue(row));
    }
    boolean retVal = super.editCellAt(row, column, e);
    if (retVal) {
        final TableCellEditor tableCellEditor =
                getColumnModel().getColumn(column).getCellEditor();
        if (tableCellEditor == valueCellEditor) {
            ((JComponent) tableCellEditor).requestFocus();
        }
    }
    return retVal;
}
 
Example #3
Source File: LabeledLocationFigure.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
public void scaleModel(EventObject event) {
  Origin origin = get(FigureConstants.ORIGIN);

  if (origin != null) {
    LocationFigure lf = getPresentationFigure();

    Point2D exact
        = origin.calculatePixelPositionExactly(lf.getModel().getPropertyLayoutPositionX(),
                                               lf.getModel().getPropertyLayoutPositionY());
    Point2D.Double anchor = new Point2D.Double(exact.getX(), exact.getY());
    setBounds(anchor, anchor);
  }

  invalidate();
  // Auch das Label aktualisieren
  fireFigureChanged();
}
 
Example #4
Source File: ConfigTree.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #5
Source File: JTreeTable.java    From JsDroidCmd with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Overridden to return false, and if the event is a mouse event
 * it is forwarded to the tree.<p>
 * The behavior for this is debatable, and should really be offered
 * as a property. By returning false, all keyboard actions are
 * implemented in terms of the table. By returning true, the
 * tree would get a chance to do something with the keyboard
 * events. For the most part this is ok. But for certain keys,
 * such as left/right, the tree will expand/collapse where as
 * the table focus should really move to a different column. Page
 * up/down should also be implemented in terms of the table.
 * By returning false this also has the added benefit that clicking
 * outside of the bounds of the tree node, but still in the tree
 * column will select the row, whereas if this returned true
 * that wouldn't be the case.
 * <p>By returning false we are also enforcing the policy that
 * the tree will never be editable (at least by a key sequence).
 */
@Override
public boolean isCellEditable(EventObject e) {
    if (e instanceof MouseEvent) {
        for (int counter = getColumnCount() - 1; counter >= 0;
             counter--) {
            if (getColumnClass(counter) == TreeTableModel.class) {
                MouseEvent me = (MouseEvent)e;
                MouseEvent newME = new MouseEvent(tree, me.getID(),
                           me.getWhen(), me.getModifiers(),
                           me.getX() - getCellRect(0, counter, true).x,
                           me.getY(), me.getClickCount(),
                           me.isPopupTrigger());
                tree.dispatchEvent(newME);
                break;
            }
        }
    }
    return false;
}
 
Example #6
Source File: XMBeanAttributes.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final boolean editCellAt(final int row, final int column, EventObject e) {
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.finer("editCellAt(row="+row+", col="+column+
                ", e="+e+")");
    }
    if (JConsole.isDebug()) {
        System.err.println("edit: "+getValueName(row)+"="+getValue(row));
    }
    boolean retVal = super.editCellAt(row, column, e);
    if (retVal) {
        final TableCellEditor tableCellEditor =
                getColumnModel().getColumn(column).getCellEditor();
        if (tableCellEditor == valueCellEditor) {
            ((JComponent) tableCellEditor).requestFocus();
        }
    }
    return retVal;
}
 
Example #7
Source File: ConfigurationsComboModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 = configName==null ? 
            ConfigurationsManager.getDefault().duplicate(lastSelected, tf.getText(), tf.getText()):
            ConfigurationsManager.getDefault().create(tf.getText(), tf.getText());
    combo.setSelectedItem(config);
    combo.setEditable(false);
}
 
Example #8
Source File: XMBeanAttributes.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final boolean editCellAt(final int row, final int column, EventObject e) {
    if (LOGGER.isLoggable(Level.FINER)) {
        LOGGER.finer("editCellAt(row="+row+", col="+column+
                ", e="+e+")");
    }
    if (JConsole.isDebug()) {
        System.err.println("edit: "+getValueName(row)+"="+getValue(row));
    }
    boolean retVal = super.editCellAt(row, column, e);
    if (retVal) {
        final TableCellEditor tableCellEditor =
                getColumnModel().getColumn(column).getCellEditor();
        if (tableCellEditor == valueCellEditor) {
            ((JComponent) tableCellEditor).requestFocus();
        }
    }
    return retVal;
}
 
Example #9
Source File: EventSupport.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add the event and vector of listeners to the queue to be delivered.
 * An event dispatcher thread dequeues events from the queue and dispatches
 * them to the registered listeners.
 * Package private; used by NamingEventNotifier to fire events
 */
synchronized void queueEvent(EventObject event,
                             Vector<? extends NamingListener> vector) {
    if (eventQueue == null)
        eventQueue = new EventQueue();

    /*
     * Copy the vector in order to freeze the state of the set
     * of EventListeners the event should be delivered to prior
     * to delivery.  This ensures that any changes made to the
     * Vector from a target listener's method during the delivery
     * of this event will not take effect until after the event is
     * delivered.
     */
    @SuppressWarnings("unchecked") // clone()
    Vector<NamingListener> v =
            (Vector<NamingListener>)vector.clone();
    eventQueue.enqueue(event, v);
}
 
Example #10
Source File: SheetTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Toggle the expanded state of a property set if either the event
 *  was a double click in the title area, a single click in the spinner
 *  area, or a keyboard event. */
private void maybeToggleExpanded(int row, EventObject e) {
    boolean doExpand = true;

    //If it's a mouse event, we need to check if it's a double click.
    if (e instanceof MouseEvent) {
        MouseEvent me = (MouseEvent) e;
        doExpand = me.getClickCount() > 1;

        //If not a double click, allow single click in the spinner margin
        if (!doExpand) {
            //marginWidth will definitely be initialized, you can't
            //click something that isn't on the screen
            doExpand = me.getPoint().x <= PropUtils.getMarginWidth();
        }
    }

    if (doExpand) {
        toggleExpanded(row);
    }
}
 
Example #11
Source File: BlobFieldTableCellEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isCellEditable(EventObject anEvent) {
    if (anEvent instanceof MouseEvent) {
        return ((MouseEvent) anEvent).getClickCount() >= 2;
    }
    return super.isCellEditable(anEvent);
}
 
Example #12
Source File: DefaultTreeCellEditor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This is invoked if a <code>TreeCellEditor</code>
 * is not supplied in the constructor.
 * It returns a <code>TextField</code> editor.
 * @return a new <code>TextField</code> editor
 */
protected TreeCellEditor createTreeCellEditor() {
    Border              aBorder = UIManager.getBorder("Tree.editorBorder");
    DefaultCellEditor   editor = new DefaultCellEditor
        (new DefaultTextField(aBorder)) {
        public boolean shouldSelectCell(EventObject event) {
            boolean retValue = super.shouldSelectCell(event);
            return retValue;
        }
    };

    // One click to edit.
    editor.setClickCountToStart(1);
    return editor;
}
 
Example #13
Source File: DefaultTreeCellEditor.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if <code>event</code> is <code>null</code>,
 * or it is a <code>MouseEvent</code> with a click count &gt; 2
 * and <code>inHitRegion</code> returns true.
 *
 * @param event the event being studied
 * @return whether editing can be started for the given {@code event}
 */
protected boolean canEditImmediately(EventObject event) {
    if((event instanceof MouseEvent) &&
       SwingUtilities.isLeftMouseButton((MouseEvent)event)) {
        MouseEvent       me = (MouseEvent)event;

        return ((me.getClickCount() > 2) &&
                inHitRegion(me.getX(), me.getY()));
    }
    return (event == null);
}
 
Example #14
Source File: DefaultTreeCellEditor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if <code>event</code> is <code>null</code>,
 * or it is a <code>MouseEvent</code> with a click count &gt; 2
 * and <code>inHitRegion</code> returns true.
 *
 * @param event the event being studied
 * @return whether editing can be started for the given {@code event}
 */
protected boolean canEditImmediately(EventObject event) {
    if((event instanceof MouseEvent) &&
       SwingUtilities.isLeftMouseButton((MouseEvent)event)) {
        MouseEvent       me = (MouseEvent)event;

        return ((me.getClickCount() > 2) &&
                inHitRegion(me.getX(), me.getY()));
    }
    return (event == null);
}
 
Example #15
Source File: VarnodeTypeCellEditor.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isCellEditable(EventObject e) {
	if (e instanceof MouseEvent) {
		return ((MouseEvent) e).getClickCount() > 1;
	}
	return true;
}
 
Example #16
Source File: DefaultTreeCellEditor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if <code>event</code> is a <code>MouseEvent</code>
 * and the click count is 1.
 * @param event  the event being studied
 */
protected boolean shouldStartEditingTimer(EventObject event) {
    if((event instanceof MouseEvent) &&
        SwingUtilities.isLeftMouseButton((MouseEvent)event)) {
        MouseEvent        me = (MouseEvent)event;

        return (me.getClickCount() == 1 &&
                inHitRegion(me.getX(), me.getY()));
    }
    return false;
}
 
Example #17
Source File: VarnodeSizeCellEditor.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isCellEditable(EventObject e) {
	if (e instanceof MouseEvent) {
		return ((MouseEvent) e).getClickCount() > 1;
	}
	return true;
}
 
Example #18
Source File: DefaultTreeCellEditor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This is invoked if a <code>TreeCellEditor</code>
 * is not supplied in the constructor.
 * It returns a <code>TextField</code> editor.
 * @return a new <code>TextField</code> editor
 */
protected TreeCellEditor createTreeCellEditor() {
    Border              aBorder = UIManager.getBorder("Tree.editorBorder");
    DefaultCellEditor   editor = new DefaultCellEditor
        (new DefaultTextField(aBorder)) {
        public boolean shouldSelectCell(EventObject event) {
            boolean retValue = super.shouldSelectCell(event);
            return retValue;
        }
    };

    // One click to edit.
    editor.setClickCountToStart(1);
    return editor;
}
 
Example #19
Source File: ResultSetTableCellEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ResultSetTableCellEditor(final JCheckBox checkBox) {
    super(checkBox);
    delegate = new EditorDelegate() {

        @Override
        public void setValue(Object value) {
            val = value;
            checkBox.setSelected((value instanceof Boolean) ? ((Boolean) value) : false);
        }

        @Override
        public boolean isCellEditable(EventObject evt) {
            if (evt instanceof MouseEvent) {
                return ((MouseEvent) evt).getClickCount() >= 2;
            }
            return true;
        }

        @Override
        public Object getCellEditorValue() {
            Boolean bolVal = checkBox.isSelected();
            if (val == null && !checkBox.isSelected()) {
                return null;
            } else {
                return bolVal;
            }
        }
    };

    checkBox.addActionListener(delegate);
}
 
Example #20
Source File: DefaultTreeCellEditor.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #21
Source File: JTreeTable.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This is overriden to forward the event to the tree. This will
 * return true if the click count >= 3, or the event is null.
 */
public boolean isCellEditable(EventObject e) {
    if (e instanceof MouseEvent) {
        MouseEvent me = (MouseEvent)e;
        // If the modifiers are not 0 (or the left mouse button),
        // tree may try and toggle the selection, and table
        // will then try and toggle, resulting in the
        // selection remaining the same. To avoid this, we
        // only dispatch when the modifiers are 0 (or the left mouse
        // button).
        if (me.getModifiers() == 0 ||
            me.getModifiers() == InputEvent.BUTTON1_MASK) {
            for (int counter = getColumnCount() - 1; counter >= 0;
                 counter--) {
                if (getColumnClass(counter) == TreeTableModel.class) {
                    MouseEvent newME = new MouseEvent
                          (JTreeTable.this.tree, me.getID(),
                           me.getWhen(), me.getModifiers(),
                           me.getX() - getCellRect(0, counter, true).x,
                           me.getY(), me.getClickCount(),
                           me.isPopupTrigger());
                    JTreeTable.this.tree.dispatchEvent(newME);
                    break;
                }
            }
        }
        if (me.getClickCount() >= 3) {
            return treeEditable;
        }
        return false;
    }
    if (e == null) {
        return treeEditable;
    }
    return false;
}
 
Example #22
Source File: DefaultTreeCellEditor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #23
Source File: BatchImportDialog.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private TableCellEditor createFilesColumnCellEditor() {
	JComboBox<Object> comboBox = new GComboBox<>();
	DefaultCellEditor cellEditor = new DefaultCellEditor(comboBox) {
		@Override
		public boolean shouldSelectCell(EventObject anEvent) {
			return true;
		}

		@Override
		public Component getTableCellEditorComponent(JTable jtable, Object value,
				boolean isSelected, int row, int column) {
			comboBox.setSelectedItem("");
			comboBox.removeAllItems();

			BatchGroup rowVal = tableModel.getRowObject(row);
			comboBox.addItem("" + rowVal.size() + " files...");

			for (BatchLoadConfig batchLoadConfig : rowVal.getBatchLoadConfig()) {
				comboBox.addItem(batchLoadConfig.getPreferredFileName());
			}

			return super.getTableCellEditorComponent(table, value, isSelected, row, column);
		}
	};
	cellEditor.setClickCountToStart(2);
	return cellEditor;
}
 
Example #24
Source File: DefaultCellEditor.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a <code>DefaultCellEditor</code> object that uses a
 * combo box.
 *
 * @param comboBox  a <code>JComboBox</code> object
 */
public DefaultCellEditor(final JComboBox<?> comboBox) {
    editorComponent = comboBox;
    comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
    delegate = new EditorDelegate() {
        public void setValue(Object value) {
            comboBox.setSelectedItem(value);
        }

        public Object getCellEditorValue() {
            return comboBox.getSelectedItem();
        }

        public boolean shouldSelectCell(EventObject anEvent) {
            if (anEvent instanceof MouseEvent) {
                MouseEvent e = (MouseEvent)anEvent;
                return e.getID() != MouseEvent.MOUSE_DRAGGED;
            }
            return true;
        }
        public boolean stopCellEditing() {
            if (comboBox.isEditable()) {
                // Commit edited value.
                comboBox.actionPerformed(new ActionEvent(
                                 DefaultCellEditor.this, 0, ""));
            }
            return super.stopCellEditing();
        }
    };
    comboBox.addActionListener(delegate);
}
 
Example #25
Source File: JTreeTable.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Overriden to invoke repaint for the particular location if
 * the column contains the tree. This is done as the tree editor does
 * not fill the bounds of the cell, we need the renderer to paint
 * the tree in the background, and then draw the editor over it.
 */
public boolean editCellAt(int row, int column, EventObject e){
    boolean retValue = super.editCellAt(row, column, e);
    if (retValue && getColumnClass(column) == TreeTableModel.class) {
        repaint(getCellRect(row, column, false));
    }
    return retValue;
}
 
Example #26
Source File: RowTreeTable.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean editCellAt(int row, int column, EventObject e) {
    if ((e != null) && (!isEditIfNullEvent())) {
        return false;
    }
    boolean res = super.editCellAt(row, column, e);
    if ((res) && (cellEditor instanceof DefaultCellEditor)) {
        ((DefaultCellEditor) cellEditor).getComponent().requestFocus();
    }
    return res;
}
 
Example #27
Source File: DefaultTreeCellEditor.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns true if <code>event</code> is a <code>MouseEvent</code>
 * and the click count is 1.
 * @param event  the event being studied
 */
protected boolean shouldStartEditingTimer(EventObject event) {
    if((event instanceof MouseEvent) &&
        SwingUtilities.isLeftMouseButton((MouseEvent)event)) {
        MouseEvent        me = (MouseEvent)event;

        return (me.getClickCount() == 1 &&
                inHitRegion(me.getX(), me.getY()));
    }
    return false;
}
 
Example #28
Source File: WeakListenerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Getter for the target listener.
* @param ev the event the we want to distribute
* @return null if there is no listener because it has been finalized
*/
protected final java.util.EventListener get(java.util.EventObject ev) {
    Object l = ref.get(); // get the consumer

    // if the event consumer is gone, unregister us from the event producer
    if (l == null) {
        ref.requestCleanUp((ev == null) ? null : ev.getSource());
    }

    return (EventListener) l;
}
 
Example #29
Source File: XTextFieldEditor.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public boolean shouldSelectCell(EventObject event) {
    return true;
}
 
Example #30
Source File: JTreeFocusTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public boolean shouldSelectCell(EventObject anEvent) {
    //return super.shouldSelectCell(anEvent);
    return true;
}