public boolean editCellAt(int index, EventObject e) {
    if (editor != null && !editor.stopCellEditing()) return false;

    if (index < 0 || index >= getModel().getSize()) return false;

    if (!isCellEditable(index)) return false;

    if (editorRemover == null) {
      KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
      editorRemover = new CellEditorRemover(fm);
      fm.addPropertyChangeListener("permanentFocusOwner", editorRemover); // NOI18N
    }

    if (editor != null && editor.isCellEditable(e)) {
      editorComp = prepareEditor(index);
      if (editorComp == null) {
        removeEditor();
        return false;
      }
      editorComp.setBounds(getCellBounds(index, index));
      add(editorComp);
      editorComp.validate();

      editingIndex = index;
      editor.addCellEditorListener(this);

      return true;
    }
    return false;
  }
Пример #2
0
 public void resetDefaultFocusTraversalKeys() {
   KeyboardFocusManager m = KeyboardFocusManager.getCurrentKeyboardFocusManager();
   for (Integer each :
       Arrays.asList(
           KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
           KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
           KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS,
           KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS)) {
     setFocusTraversalKeys(each, m.getDefaultFocusTraversalKeys(each));
   }
 }
  /*
   *  Create using the specified focus policy
   */
  public TabFocusHandler(JTabbedPane tabbedPane, int focusPolicy) {
    if (focusPolicy != RESET_FOCUS && focusPolicy != RETAIN_FOCUS)
      throw new IllegalArgumentException("Invalid focus policy");

    this.tabbedPane = tabbedPane;
    this.focusPolicy = focusPolicy;

    //  Add listeners to manage a tab change

    tabbedPane.addChangeListener(this);
    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    focusManager.addPropertyChangeListener("permanentFocusOwner", this);
  }
Пример #4
0
 public void removeNotify() {
   final KeyboardFocusManager keyboardFocusManager =
       KeyboardFocusManager.getCurrentKeyboardFocusManager();
   //noinspection HardCodedStringLiteral
   keyboardFocusManager.removePropertyChangeListener("permanentFocusOwner", myEditorRemover);
   //noinspection HardCodedStringLiteral
   keyboardFocusManager.removePropertyChangeListener("focusOwner", myEditorRemover);
   super.removeNotify();
   if (myBusyIcon != null) {
     remove(myBusyIcon);
     Disposer.dispose(myBusyIcon);
     myBusyIcon = null;
   }
 }
Пример #5
0
  public boolean editCellAt(final int row, final int column, final EventObject e) {
    if (cellEditor != null && !cellEditor.stopCellEditing()) {
      return false;
    }

    if (row < 0 || row >= getRowCount() || column < 0 || column >= getColumnCount()) {
      return false;
    }

    if (!isCellEditable(row, column)) {
      return false;
    }

    if (myEditorRemover == null) {
      final KeyboardFocusManager keyboardFocusManager =
          KeyboardFocusManager.getCurrentKeyboardFocusManager();
      myEditorRemover = new MyCellEditorRemover();
      //noinspection HardCodedStringLiteral
      keyboardFocusManager.addPropertyChangeListener("focusOwner", myEditorRemover);
      //noinspection HardCodedStringLiteral
      keyboardFocusManager.addPropertyChangeListener("permanentFocusOwner", myEditorRemover);
    }

    final TableCellEditor editor = getCellEditor(row, column);
    if (editor != null && editor.isCellEditable(e)) {
      editorComp = prepareEditor(editor, row, column);
      // ((JComponent)editorComp).setBorder(null);
      if (editorComp == null) {
        removeEditor();
        return false;
      }
      editorComp.setBounds(getCellRect(row, column, false));
      add(editorComp);
      editorComp.validate();

      IdeFocusManager.findInstanceByComponent(this).requestFocus(editorComp, false);

      setCellEditor(editor);
      setEditingRow(row);
      setEditingColumn(column);
      editor.addCellEditorListener(this);
      if (isTypeAhead) {
        JTableCellEditorHelper.typeAhead(this, e, row, column);
      }
      return true;
    }
    return false;
  }
  public void removeEditor() {
    KeyboardFocusManager.getCurrentKeyboardFocusManager()
        .removePropertyChangeListener("permanentFocusOwner", editorRemover); // NOI18N
    editorRemover = null;

    if (editor != null) {
      editor.removeCellEditorListener(this);

      if (editorComp != null) {
        remove(editorComp);
      }

      Rectangle cellRect = getCellBounds(editingIndex, editingIndex);

      editingIndex = -1;
      editorComp = null;

      repaint(cellRect);
    }
  }
    public void propertyChange(PropertyChangeEvent ev) {
      if (!isEditing() || getClientProperty("terminateEditOnFocusLost") != Boolean.TRUE) { // NOI18N
        return;
      }

      Component c = focusManager.getPermanentFocusOwner();
      while (c != null) {
        if (c == JListMutable.this) {
          // focus remains inside the table
          return;
        } else if ((c instanceof Window) || (c instanceof Applet && c.getParent() == null)) {
          if (c == SwingUtilities.getRoot(JListMutable.this)) {
            if (!getListCellEditor().stopCellEditing()) {
              getListCellEditor().cancelCellEditing();
            }
          }
          break;
        }
        c = c.getParent();
      }
    }
 public void removeNotify() {
   KeyboardFocusManager.getCurrentKeyboardFocusManager()
       .removePropertyChangeListener("permanentFocusOwner", editorRemover); // NOI18N
   super.removeNotify();
 }