Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 package org.apache.cayenne.modeler.util;
 import java.awt.Color;
 import java.awt.Font;
Utility class to create standard Swing widgets following default look-and-feel of CayenneModeler.
 // TODO: (Andrus) investigate performance impact of substituting
 // constructors for all new widgets with cloning the prototype
 public class CayenneWidgetFactory {

Not intended for instantiation.
     protected CayenneWidgetFactory() {

Creates a new JComboBox with a collection of model objects.
     public static JComboBox createComboBox(Collection<Stringmodelboolean sort) {
         return createComboBox(model.toArray(), sort);

Creates a new JComboBox with an array of model objects.
     public static JComboBox createComboBox(Object[] modelboolean sort) {
         JComboBox comboBox = CayenneWidgetFactory.createComboBox();
         if (sort) {
         comboBox.setModel(new DefaultComboBoxModel(model));
         return comboBox;

Creates a new JComboBox.
     public static JComboBox createComboBox() {
         JComboBox comboBox = new JComboBox();
         return comboBox;

Creates undoable JComboBox.
    public static JComboBox createUndoableComboBox() {
        JComboBox comboBox = new JComboBox();
        comboBox.addItemListener(new JComboBoxUndoListener());
        return comboBox;

Creates undoable JTextField.
    public static JTextField createUndoableTextField() {
        return new JTextFieldUndoable();

Creates undoable JTextField.
    public static JTextField createUndoableTextField(int size) {
        return new JTextFieldUndoable(size);

Creates cell editor for text field
    public static DefaultCellEditor createCellEditor(JTextField textField) {
        return new CayenneCellEditor(textField);

Creates cell editor for a table with combo as editor component. Type of this editor depends on auto-completion behavior of JComboBox

combo JComboBox to be used as editor component
    public static TableCellEditor createCellEditor(JComboBox combo) {
        if (..equals(combo
                .getClientProperty(.))) {
            return new ComboBoxCellEditor(combo);
        DefaultCellEditor editor = new DefaultCellEditor(combo);
        return editor;

Creates a new JTextField with a default columns count of 20.
    public static JTextField createTextField() {
        return createTextField(20);

Creates a new JTextField with a specified columns count.
    public static JTextField createTextField(int columns) {
        final JTextField textField = new JTextField(columns);
        return textField;
    protected static void initTextField(final JTextField textField) {
        // config focus
        textField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // transfer focus

Initializes a "form" element with a standard font and height.
    protected static void initFormWidget(JComponent component) {
        component.setFont(component.getFont().deriveFont(., 12));
         * Dimension size = component.getPreferredSize(); if (size == null) { size = new
         * Dimension(); } size.setSize(size.getWidth(), 20);
         * component.setPreferredSize(size);

Creates a borderless button that can be used as a clickable label.
    public static JButton createLabelButton(String text) {
        JButton but = createButton(text);
        but.setMargin(new Insets(0, 0, 0, 0));
        return but;

Creates a normal button.
    public static JButton createButton(String text) {
        return new JButton(text);

Creates and returns a JEdit text component with syntax highlighing
    public static JEditTextArea createJEditTextArea() {
        JEditTextArea area = new JEditTextAreaUndoable();
        if (OperatingSystem.getOS() == .) {
            area.setInputHandler(new MacInputHandler());
        return area;
    // public static JSQLTextPane createJSQLTextPane() {
    // JSQLTextPane area = new JSQLTextPane();
    // return area;
    // }
    public static JCayenneTextPane createJEJBQLTextPane() {
        JCayenneTextPane area = new JCayenneTextPaneUndoable(new EJBQLSyntaxConstant());
        return area;

Class for enabling Mac OS X keys
    private static class MacInputHandler extends DefaultInputHandler {
        MacInputHandler() {

Sets up the default key bindings.
        public void addDefaultKeyBindings() {
            addKeyBinding("A+LEFT"); // option + left
            addKeyBinding("AS+LEFT"); // option + shift + left
            addKeyBinding("A+RIGHT"); // option + right
            addKeyBinding("AS+RIGHT"); // option + shift + right
            // Clipboard
            addKeyBinding("M+C"); // command + c
            addKeyBinding("M+V"); // command + v
            addKeyBinding("M+X"); // command + x
New to GrepCode? Check out our FAQ X