Java Code Examples for java.beans.PropertyEditor#getCustomEditor()

The following examples show how to use java.beans.PropertyEditor#getCustomEditor() . 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: OutputSettingsPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void btnSelectFontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectFontActionPerformed
    PropertyEditor pe = PropertyEditorManager.findEditor(Font.class);
    if (pe != null) {
        pe.setValue(outputOptions.getFont());
        DialogDescriptor dd = new DialogDescriptor(pe.getCustomEditor(),
                NbBundle.getMessage(Controller.class,
                "LBL_Font_Chooser_Title"));                         //NOI18N
        String defaultFont = NbBundle.getMessage(Controller.class,
                "BTN_Defaul_Font");                                 //NOI18N
        dd.setOptions(new Object[]{DialogDescriptor.OK_OPTION,
                    defaultFont, DialogDescriptor.CANCEL_OPTION});  //NOI18N
        DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
        if (dd.getValue() == DialogDescriptor.OK_OPTION) {
            Font f = (Font) pe.getValue();
            outputOptions.setFont(f);
        } else if (dd.getValue() == defaultFont) {
            outputOptions.setFont(null);
        }
        updateFontField();
    }
}
 
Example 2
Source File: TermOptionsPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void fontButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontButtonActionPerformed
PropertyEditor pe = PropertyEditorManager.findEditor(Font.class);
if (pe != null) {
    pe.setValue(termOptions.getFont());
    DialogDescriptor dd = new DialogDescriptor(pe.getCustomEditor(), FontChooser_title());

    String defaultFontString = FontChooser_defaultFont_label();
    dd.setOptions(new Object[]{DialogDescriptor.OK_OPTION,
	defaultFontString, DialogDescriptor.CANCEL_OPTION});  //NOI18N
    DialogDisplayer.getDefault().createDialog(dd).setVisible(true);
    if (dd.getValue() == DialogDescriptor.OK_OPTION) {
	Font f = (Font) pe.getValue();
	termOptions.setFont(f);
	applyTermOptions();
    } else if (dd.getValue() == defaultFontString) {
	Font controlFont = UIManager.getFont("controlFont");			//NOI18N
	int fontSize = (controlFont == null) ? 12 : controlFont.getSize();
	termOptions.setFont(new Font("monospaced", Font.PLAIN, fontSize));	//NOI18N
    }
}
   }
 
Example 3
Source File: CellEditorAdapter.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
public CellEditorAdapter(PropertyEditor editor) {
  this.editor = editor;
  Component component = editor.getCustomEditor();
  if (component instanceof JTextField) {
    JTextField field = (JTextField)component;
    field.addFocusListener(new SelectOnFocus());
    field.addActionListener(new CommitEditing());
    field.registerKeyboardAction(
      new CancelEditing(),
      KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
      JComponent.WHEN_FOCUSED);
  }

  // when the editor notifies a change, commit the changes
  editor.addPropertyChangeListener(new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent evt) {       
      stopCellEditing();
    }
  });
}
 
Example 4
Source File: GenericObjectEditor.java    From meka with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tries to determine a view for the editor.
 *
 * @param editor	the editor to get the view for
 * @return		the view, null if failed to determine one
 */
public static JComponent findView(PropertyEditor editor) {
	JComponent	result;

	result = null;

	if (editor.supportsCustomEditor() && editor.isPaintable()) {
		result = new PropertyPanel(editor);
	}
	else if (editor.supportsCustomEditor() && (editor.getCustomEditor() instanceof JComponent)) {
		result = (JComponent) editor.getCustomEditor();
	}
	else if (editor.getTags() != null) {
		result = new PropertyValueSelector(editor);
	}
	else if (editor.getAsText() != null) {
		result = new PropertyText(editor);
	}

	return result;
}
 
Example 5
Source File: MMDCfgPanel.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
private void buttonFontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFontActionPerformed
  final PropertyEditor editor = PropertyEditorManager.findEditor(Font.class);
  if (editor == null) {
    LOGGER.error("Can't find any font editor");
    NbUtils.msgError(null, "Can't find editor! Unexpected state! Contact developer!");
    return;
  }
  editor.setValue(this.config.getFont());

  final DialogDescriptor descriptor = new DialogDescriptor(
          editor.getCustomEditor(),
          "Mind map font"
  );

  DialogDisplayer.getDefault().createDialog(descriptor).setVisible(true);
  if (descriptor.getValue() == DialogDescriptor.OK_OPTION) {
    this.config.setFont((Font) editor.getValue());
    updateFontButton(this.config);
    if (changeNotificationAllowed) {
      this.controller.changed();
    }
  }
}
 
Example 6
Source File: CellEditorAdapter.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public CellEditorAdapter(PropertyEditor editor) {
  this.editor = editor;
  Component component = editor.getCustomEditor();
  if (component instanceof JTextField) {
    JTextField field = (JTextField)component;
    field.addFocusListener(new SelectOnFocus());
    field.addActionListener(new CommitEditing());
    field.registerKeyboardAction(
      new CancelEditing(),
      KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
      JComponent.WHEN_FOCUSED);
  }

  // when the editor notifies a change, commit the changes
  editor.addPropertyChangeListener(new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent evt) {       
      stopCellEditing();
    }
  });
}
 
Example 7
Source File: CustomPropertyEditorDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public boolean performEdit( final PropertyEditor editor ) {
  if ( editor == null ) {
    throw new NullPointerException();
  }

  final Object originalValue = editor.getValue();
  final Component view = editor.getCustomEditor();
  if ( view instanceof ValidatingPropertyEditorComponent ) {
    validatingView = (ValidatingPropertyEditorComponent) view;
    validatingView.addPropertyChangeListener( validationHandler );
  } else {
    validatingView = null;
  }

  contentPane.removeAll();
  contentPane.add( new JScrollPane( view ), BorderLayout.CENTER );

  if ( super.performEdit() == false ) {
    try {
      editor.setValue( originalValue );
    } catch ( Exception ex ) {
      // ignore ..
    }
  }
  if ( validatingView != null ) {
    validatingView.removePropertyChangeListener( validationHandler );
  }
  return isConfirmed();
}