binding-2.0.1

16:33:15.602 INFO  jd.cli.Main - Decompiling binding-2.0.1.jar
package com.jgoodies.binding.adapter;

class AbstractTableAdapter$1 {}

/* Location:
 * Qualified Name:     com.jgoodies.binding.adapter.AbstractTableAdapter.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.binding.adapter;

import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;

final class AbstractTableAdapter$ListDataChangeHandler
  implements ListDataListener
{
  private AbstractTableAdapter$ListDataChangeHandler(AbstractTableAdapter paramAbstractTableAdapter) {}
  
  public void intervalAdded(ListDataEvent evt)
  {
    this$0.fireTableRowsInserted(evt.getIndex0(), evt.getIndex1());
  }
  
  public void intervalRemoved(ListDataEvent evt)
  {
    this$0.fireTableRowsDeleted(evt.getIndex0(), evt.getIndex1());
  }
  
  public void contentsChanged(ListDataEvent evt)
  {
    int firstRow = evt.getIndex0();
    int lastRow = evt.getIndex1();
    this$0.fireTableRowsUpdated(firstRow, lastRow);
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.binding.adapter.AbstractTableAdapter.ListDataChangeHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.binding.adapter;

import javax.swing.ListModel;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.table.AbstractTableModel;

public abstract class AbstractTableAdapter<E>
  extends AbstractTableModel
{
  private final ListModel listModel;
  private final String[] columnNames;
  
  public AbstractTableAdapter(ListModel listModel)
  {
    this(listModel, (String[])null);
  }
  
  public AbstractTableAdapter(ListModel listModel, String... columnNames)
  {
    this.listModel = listModel;
    if (listModel == null) {
      throw new NullPointerException("The list model must not be null.");
    }
    if ((columnNames == null) || (columnNames.length == 0))
    {
      this.columnNames = null;
    }
    else
    {
      this.columnNames = new String[columnNames.length];
      System.arraycopy(columnNames, 0, this.columnNames, 0, columnNames.length);
    }
    listModel.addListDataListener(createChangeHandler());
  }
  
  public int getColumnCount()
  {
    return columnNames.length;
  }
  
  public String getColumnName(int columnIndex)
  {
    return columnNames[columnIndex];
  }
  
  public final int getRowCount()
  {
    return listModel.getSize();
  }
  
  public final E getRow(int index)
  {
    return (E)listModel.getElementAt(index);
  }
  
  protected ListDataListener createChangeHandler()
  {
    return new ListDataChangeHandler(null);
  }
  
  private final class ListDataChangeHandler
    implements ListDataListener
  {
    private ListDataChangeHandler() {}
    
    public void intervalAdded(ListDataEvent evt)
    {
      fireTableRowsInserted(evt.getIndex0(), evt.getIndex1());
    }
    
    public void intervalRemoved(ListDataEvent evt)
    {
      fireTableRowsDeleted(evt.getIndex0(), evt.getIndex1());
    }
    
    public void contentsChanged(ListDataEvent evt)
    {
      int firstRow = evt.getIndex0();
      int lastRow = evt.getIndex1();
      fireTableRowsUpdated(firstRow, lastRow);
    }
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.binding.adapter.AbstractTableAdapter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.binding.adapter;

import com.jgoodies.binding.formatter.EmptyDateFormatter;
import com.jgoodies.binding.formatter.EmptyNumberFormatter;
import com.jgoodies.binding.list.SelectionInList;
import com.jgoodies.binding.value.ConverterFactory;
import com.jgoodies.binding.value.ValueModel;
import java.awt.Color;
import java.text.DateFormat;
import java.text.Format;
import java.text.NumberFormat;
import java.text.ParseException;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JFormattedTextField.AbstractFormatter;
import javax.swing.JFormattedTextField.AbstractFormatterFactory;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.text.DefaultFormatterFactory;
import javax.swing.text.MaskFormatter;
import javax.swing.text.NumberFormatter;

public class BasicComponentFactory
{
  public static JCheckBox createCheckBox(ValueModel valueModel, String text)
  {
    JCheckBox checkBox = new JCheckBox(text);
    Bindings.bind(checkBox, valueModel);
    return checkBox;
  }
  
  public static JColorChooser createColorChooser(ValueModel valueModel)
  {
    if (valueModel.getValue() == null) {
      throw new NullPointerException("The initial value must not be null.");
    }
    JColorChooser colorChooser = new JColorChooser(new ColorSelectionAdapter(valueModel));
    
    return colorChooser;
  }
  
  public static JColorChooser createColorChooser(ValueModel valueModel, Color defaultColor)
  {
    if (defaultColor == null) {
      throw new NullPointerException("The default color must not be null.");
    }
    JColorChooser colorChooser = new JColorChooser(new ColorSelectionAdapter(valueModel, defaultColor));
    
    return colorChooser;
  }
  
  public static <E> JComboBox createComboBox(SelectionInList<E> selectionInList)
  {
    return createComboBox(selectionInList, null);
  }
  
  public static <E> JComboBox createComboBox(SelectionInList<E> selectionInList, ListCellRenderer cellRenderer)
  {
    JComboBox comboBox = new JComboBox();
    Bindings.bind(comboBox, selectionInList);
    if (cellRenderer != null) {
      comboBox.setRenderer(cellRenderer);
    }
    return comboBox;
  }
  
  public static JFormattedTextField createDateField(ValueModel valueModel)
  {
    DateFormat shortFormat = DateFormat.getDateInstance(3);
    shortFormat.setLenient(false);
    
    JFormattedTextField.AbstractFormatter defaultFormatter = new EmptyDateFormatter(shortFormat);
    
    JFormattedTextField.AbstractFormatter displayFormatter = new EmptyDateFormatter();
    
    DefaultFormatterFactory formatterFactory = new DefaultFormatterFactory(defaultFormatter, displayFormatter);
    
    return createFormattedTextField(valueModel, formatterFactory);
  }
  
  public static JFormattedTextField createFormattedTextField(ValueModel valueModel, Format format)
  {
    JFormattedTextField textField = new JFormattedTextField(format);
    Bindings.bind(textField, valueModel);
    return textField;
  }
  
  public static JFormattedTextField createFormattedTextField(ValueModel valueModel, JFormattedTextField.AbstractFormatter formatter)
  {
    JFormattedTextField textField = new JFormattedTextField(formatter);
    Bindings.bind(textField, valueModel);
    return textField;
  }
  
  public static JFormattedTextField createFormattedTextField(ValueModel valueModel, JFormattedTextField.AbstractFormatterFactory formatterFactory)
  {
    JFormattedTextField textField = new JFormattedTextField(formatterFactory);
    Bindings.bind(textField, valueModel);
    return textField;
  }
  
  public static JFormattedTextField createFormattedTextField(ValueModel valueModel, String mask)
  {
    MaskFormatter formatter = null;
    try
    {
      formatter = new MaskFormatter(mask);
    }
    catch (ParseException e)
    {
      throw new IllegalArgumentException("Invalid mask '" + mask + "'.");
    }
    JFormattedTextField textField = new JFormattedTextField(formatter);
    Bindings.bind(textField, valueModel);
    return textField;
  }
  
  public static JFormattedTextField createIntegerField(ValueModel valueModel)
  {
    return createIntegerField(valueModel, NumberFormat.getIntegerInstance(), null);
  }
  
  public static JFormattedTextField createIntegerField(ValueModel valueModel, int emptyNumber)
  {
    return createIntegerField(valueModel, NumberFormat.getIntegerInstance(), emptyNumber);
  }
  
  public static JFormattedTextField createIntegerField(ValueModel valueModel, NumberFormat numberFormat)
  {
    return createIntegerField(valueModel, numberFormat, null);
  }
  
  public static JFormattedTextField createIntegerField(ValueModel valueModel, NumberFormat numberFormat, int emptyNumber)
  {
    return createIntegerField(valueModel, numberFormat, Integer.valueOf(emptyNumber));
  }
  
  public static JFormattedTextField createIntegerField(ValueModel valueModel, NumberFormat numberFormat, Integer emptyNumber)
  {
    NumberFormatter numberFormatter = new EmptyNumberFormatter(numberFormat, emptyNumber);
    
    numberFormatter.setValueClass(Integer.class);
    
    return createFormattedTextField(valueModel, numberFormatter);
  }
  
  public static JFormattedTextField createLongField(ValueModel valueModel)
  {
    return createLongField(valueModel, NumberFormat.getIntegerInstance(), null);
  }
  
  public static JFormattedTextField createLongField(ValueModel valueModel, long emptyNumber)
  {
    return createLongField(valueModel, NumberFormat.getIntegerInstance(), emptyNumber);
  }
  
  public static JFormattedTextField createLongField(ValueModel valueModel, NumberFormat numberFormat)
  {
    return createLongField(valueModel, numberFormat, null);
  }
  
  public static JFormattedTextField createLongField(ValueModel valueModel, NumberFormat numberFormat, long emptyNumber)
  {
    return createLongField(valueModel, numberFormat, Long.valueOf(emptyNumber));
  }
  
  public static JFormattedTextField createLongField(ValueModel valueModel, NumberFormat numberFormat, Long emptyNumber)
  {
    NumberFormatter numberFormatter = new EmptyNumberFormatter(numberFormat, emptyNumber);
    
    numberFormatter.setValueClass(Long.class);
    
    return createFormattedTextField(valueModel, numberFormatter);
  }
  
  public static JLabel createLabel(ValueModel valueModel)
  {
    JLabel label = new JLabel();
    Bindings.bind(label, valueModel);
    return label;
  }
  
  public static JLabel createLabel(ValueModel valueModel, Format format)
  {
    return createLabel(ConverterFactory.createStringConverter(valueModel, format));
  }
  
  public static <E> JList createList(SelectionInList<E> selectionInList)
  {
    return createList(selectionInList, null);
  }
  
  public static <E> JList createList(SelectionInList<E> selectionInList, ListCellRenderer cellRenderer)
  {
    JList list = new JList();
    Bindings.bind(list, selectionInList);
    if (cellRenderer != null) {
      list.setCellRenderer(cellRenderer);
    }
    return list;
  }
  
  public static JPasswordField createPasswordField(ValueModel valueModel)
  {
    return createPasswordField(valueModel, true);
  }
  
  public static JPasswordField createPasswordField(ValueModel valueModel, boolean commitOnFocusLost)
  {
    JPasswordField textField = new JPasswordField();
    Bindings.bind(textField, valueModel, commitOnFocusLost);
    return textField;
  }
  
  public static JRadioButton createRadioButton(ValueModel model, Object choice, String text)
  {
    JRadioButton radioButton = new JRadioButton(text);
    Bindings.bind(radioButton, model, choice);
    return radioButton;
  }
  
  public static JTextArea createTextArea(ValueModel valueModel)
  {
    return createTextArea(valueModel, true);
  }
  
  public static JTextArea createTextArea(ValueModel valueModel, boolean commitOnFocusLost)
  {
    JTextArea textArea = new JTextArea();
    Bindings.bind(textArea, valueModel, commitOnFocusLost);
    return textArea;
  }
  
  public static JTextField createTextField(ValueModel valueModel)
  {
    return createTextField(valueModel, true);
  }
  
  public static JTextField createTextField(ValueModel valueModel, boolean commitOnFocusLost)
  {
    JTextField textField = new JTextField();
    Bindings.bind(textField, valueModel, commitOnFocusLost);
    return textField;
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.binding.adapter.BasicComponentFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.binding.adapter;

class Bindings$1 {}

/* Location:
 * Qualified Name:     com.jgoodies.binding.adapter.Bindings.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.binding.adapter;

import com.jgoodies.binding.value.ComponentValueModel;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
import javax.swing.text.JTextComponent;

final class Bindings$ComponentPropertyHandler
  implements PropertyChangeListener
{
  private final JComponent component;
  
  private Bindings$ComponentPropertyHandler(JComponent component)
  {
    this.component = component;
  }
  
  public void propertyChange(PropertyChangeEvent evt)
  {
    String propertyName = evt.getPropertyName();
    ComponentValueModel model = (ComponentValueModel)evt.getSource();
    if ("enabled".equals(propertyName)) {
      component.setEnabled(model.isEnabled());
    } else if ("visible".equals(propertyName)) {
      component.setVisible(model.isVisible());
    } else if (("editable".equals(propertyName)) && 
      ((component instanceof JTextComponent))) {
      ((JTextComponent)component).setEditable(model.isEditable());
    }
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.binding.adapter.Bindings.ComponentPropertyHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.binding.adapter;

import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;

final class Bindings$FocusLostHandler
  extends FocusAdapter
{
  public void focusLost(FocusEvent evt)
  {
    if (!evt.isTemporary()) {
      Bindings.FOCUS_LOST_TRIGGER.triggerCommit();
    }
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.binding.adapter.Bindings.FocusLostHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.binding.adapter;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.ref.WeakReference;

final class Bindings$WeakPropertyChangeSupport$WeakPropertyChangeListener
  extends WeakReference<PropertyChangeListener>
  implements PropertyChangeListener
{
  final String propertyName;
  
  private Bindings$WeakPropertyChangeSupport$WeakPropertyChangeListener(Bindings.WeakPropertyChangeSupport paramWeakPropertyChangeSupport, PropertyChangeListener delegate)
  {
    this(paramWeakPropertyChangeSupport, null, delegate);
  }
  
  private Bindings$WeakPropertyChangeSupport$WeakPropertyChangeListener(Bindings.WeakPropertyChangeSupport paramWeakPropertyChangeSupport, String propertyName, PropertyChangeListener delegate)
  {
    super(delegate, Bindings.WeakPropertyChangeSupport.QUEUE);
    this.propertyName = propertyName;
  }
  
  public void propertyChange(PropertyChangeEvent evt)
  {
    PropertyChangeListener delegate = (PropertyChangeListener)get();
    if (delegate != null) {
      delegate.propertyChange(evt);
    }
  }
  
  void removeListener()
  {
    this$0.removeWeakPropertyChangeListener(this);
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.binding.adapter.Bindings.WeakPropertyChangeSupport.WeakPropertyChangeListener
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.binding.adapter;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeListenerProxy;
import java.beans.PropertyChangeSupport;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;

final class Bindings$WeakPropertyChangeSupport
  extends PropertyChangeSupport
{
  Bindings$WeakPropertyChangeSupport(Object sourceBean)
  {
    super(sourceBean);
  }
  
  public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
  {
    if (listener == null) {
      return;
    }
    if ((listener instanceof PropertyChangeListenerProxy))
    {
      PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy)listener;
      
      addPropertyChangeListener(proxy.getPropertyName(), (PropertyChangeListener)proxy.getListener());
    }
    else
    {
      super.addPropertyChangeListener(new WeakPropertyChangeListener(listener, null));
    }
  }
  
  public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
  {
    if (listener == null) {
      return;
    }
    super.addPropertyChangeListener(propertyName, new WeakPropertyChangeListener(propertyName, listener, null));
  }
  
  public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
  {
    if (listener == null) {
      return;
    }
    if ((listener instanceof PropertyChangeListenerProxy))
    {
      PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy)listener;
      
      removePropertyChangeListener(proxy.getPropertyName(), (PropertyChangeListener)proxy.getListener());
      
      return;
    }
    PropertyChangeListener[] listeners = getPropertyChangeListeners();
    for (int i = listeners.length - 1; i >= 0; i--) {
      if (!(listeners[i] instanceof PropertyChangeListenerProxy))
      {
        WeakPropertyChangeListener wpcl = (WeakPropertyChangeListener)listeners[i];
        if (wpcl.get() == listener)
        {
          super.removePropertyChangeListener(wpcl);
          break;
        }
      }
    }
  }
  
  public synchronized void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
  {
    if (listener == null) {
      return;
    }
    PropertyChangeListener[] listeners = getPropertyChangeListeners(propertyName);
    for (int i = listeners.length - 1; i >= 0; i--)
    {
      WeakPropertyChangeListener wpcl = (WeakPropertyChangeListener)listeners[i];
      if (wpcl.get() == listener)
      {
        super.removePropertyChangeListener(propertyName, wpcl);
        break;
      }
    }
  }
  
  public void firePropertyChange(PropertyChangeEvent evt)
  {
    cleanUp();
    super.firePropertyChange(evt);
  }
  
  public void firePropertyChange(String propertyName, Object oldValue, Object newValue)
  {
    cleanUp();
    super.firePropertyChange(propertyName, oldValue, newValue);
  }
  
  static final ReferenceQueue<PropertyChangeListener> QUEUE = new ReferenceQueue();
  
  private static void cleanUp()
  {
    WeakPropertyChangeListener wpcl;
    while ((wpcl = (WeakPropertyChangeListener)QUEUE.poll()) != null) {
      wpcl.removeListener();
    }
  }
  
  void removeWeakPropertyChangeListener(WeakPropertyChangeListener l)
  {
    if (propertyName == null) {
      super.removePropertyChangeListener(l);
    } else {
      super.removePropertyChangeListener(propertyName, l);
    }
  }
  
  private final class WeakPropertyChangeListener
    extends WeakReference<PropertyChangeListener>
    implements PropertyChangeListener
  {
    final String propertyName;
    
    private WeakPropertyChangeListener(PropertyChangeListener delegate)
    {
      this(null, delegate);
    }
    
    private WeakPropertyChangeListener(String propertyName, PropertyChangeListener delegate)
    {
      super(Bindings.WeakPropertyChangeSupport.QUEUE);
      this.propertyName = propertyName;
    }
    
    public void propertyChange(PropertyChangeEvent evt)
    {
      PropertyChangeListener delegate = (PropertyChangeListener)get();
      if (delegate != null) {
        delegate.propertyChange(evt);
      }
    }
    
    void removeListener()
    {
      removeWeakPropertyChangeListener(this);
    }
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.binding.adapter.Bindings.WeakPropertyChangeSupport
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.binding.adapter;

import com.jgoodies.binding.value.ValueModel;
import java.beans.PropertyChangeListener;

final class Bindings$WeakTrigger
  implements ValueModel
{
  private final transient Bindings.WeakPropertyChangeSupport changeSupport;
  private Boolean value;
  
  Bindings$WeakTrigger()
  {
    value = null;
    changeSupport = new Bindings.WeakPropertyChangeSupport(this);
  }
  
  public Object getValue()
  {
    return value;
  }
  
  public void setValue(Object newValue)
  {
    if ((newValue != null) && (!(newValue instanceof Boolean))) {
      throw new IllegalArgumentException("Trigger values must be of type Boolean.");
    }
    Object oldValue = value;
    value = ((Boolean)newValue);
    fireValueChange(oldValue, newValue);
  }
  
  public void addValueChangeListener(PropertyChangeListener listener)
  {
    if (listener == null) {
      return;
    }
    changeSupport.addPropertyChangeListener("value", listener);
  }
  
  public void removeValueChangeListener(PropertyChangeListener listener)
  {
    if (listener == null) {
      return;
    }
    changeSupport.removePropertyChangeListener("value", listener);
  }
  
  private void fireValueChange(Object oldValue, Object newValue)
  {
    changeSupport.firePropertyChange("value", oldValue, newValue);
  }
  
  void triggerCommit()
  {
    if (Boolean.TRUE.equals(getValue())) {
      setValue(null);
    }
    setValue(Boolean.TRUE);
  }
  
  void triggerFlush()
  {
    if (Boolean.FALSE.equals(getValue())) {
      setValue(null);
    }
    setValue(Boolean.FALSE);
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.binding.adapter.Bindings.WeakTrigger
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.binding.adapter;

import com.jgoodies.binding.beans.PropertyConnector;
import com.jgoodies.binding.list.SelectionInList;
import com.jgoodies.binding.value.BufferedValueModel;
import com.jgoodies.binding.value.ComponentValueModel;
import com.jgoodies.binding.value.ValueModel;
import java.awt.Color;
import java.awt.Component;
import java.awt.KeyboardFocusManager;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeListenerProxy;
import java.beans.PropertyChangeSupport;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import javax.swing.ButtonModel;
import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JRadioButton;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;

public final class Bindings
{
  private static final String COMMIT_ON_FOCUS_LOST_MODEL_KEY = "commitOnFocusListModel";
  private static final String COMPONENT_VALUE_MODEL_KEY = "componentValueModel";
  private static final String COMPONENT_PROPERTY_HANDLER_KEY = "componentPropertyHandler";
  static final FocusLostHandler FOCUS_LOST_HANDLER = new FocusLostHandler(null);
  static final WeakTrigger FOCUS_LOST_TRIGGER = new WeakTrigger();
  
  public static void bind(JCheckBox checkBox, ValueModel valueModel)
  {
    boolean enabled = checkBox.getModel().isEnabled();
    checkBox.setModel(new ToggleButtonAdapter(valueModel));
    checkBox.setEnabled(enabled);
    
    addComponentPropertyHandler(checkBox, valueModel);
  }
  
  public static void bind(JCheckBoxMenuItem checkBoxMenuItem, ValueModel valueModel)
  {
    boolean enabled = checkBoxMenuItem.getModel().isEnabled();
    checkBoxMenuItem.setModel(new ToggleButtonAdapter(valueModel));
    checkBoxMenuItem.setEnabled(enabled);
    
    addComponentPropertyHandler(checkBoxMenuItem, valueModel);
  }
  
  public static void bind(JColorChooser colorChooser, ValueModel valueModel)
  {
    colorChooser.setSelectionModel(new ColorSelectionAdapter(valueModel));
  }
  
  public static void bind(JColorChooser colorChooser, ValueModel valueModel, Color defaultColor)
  {
    if (defaultColor == null) {
      throw new NullPointerException("The default color must not be null.");
    }
    colorChooser.setSelectionModel(new ColorSelectionAdapter(valueModel, defaultColor));
  }
  
  public static <E> void bind(JComboBox comboBox, SelectionInList<E> selectionInList)
  {
    if (selectionInList == null) {
      throw new NullPointerException("The SelectionInList must not be null.");
    }
    comboBox.setModel(new ComboBoxAdapter(selectionInList));
    
    addComponentPropertyHandler(comboBox, selectionInList.getSelectionHolder());
  }
  
  public static void bind(JFormattedTextField textField, ValueModel valueModel)
  {
    bind(textField, "value", valueModel);
  }
  
  public static void bind(JLabel label, ValueModel valueModel)
  {
    bind(label, "text", valueModel);
  }
  
  public static <E> void bind(JList list, SelectionInList<E> selectionInList)
  {
    if (selectionInList == null) {
      throw new NullPointerException("The SelectionInList must not be null.");
    }
    list.setModel(selectionInList);
    list.setSelectionModel(new SingleListSelectionAdapter(selectionInList.getSelectionIndexHolder()));
    
    addComponentPropertyHandler(list, selectionInList.getSelectionHolder());
  }
  
  public static void bind(JRadioButton radioButton, ValueModel model, Object choice)
  {
    boolean enabled = radioButton.getModel().isEnabled();
    radioButton.setModel(new RadioButtonAdapter(model, choice));
    radioButton.setEnabled(enabled);
    
    addComponentPropertyHandler(radioButton, model);
  }
  
  public static void bind(JRadioButtonMenuItem radioButtonMenuItem, ValueModel model, Object choice)
  {
    boolean enabled = radioButtonMenuItem.getModel().isEnabled();
    radioButtonMenuItem.setModel(new RadioButtonAdapter(model, choice));
    radioButtonMenuItem.setEnabled(enabled);
    
    addComponentPropertyHandler(radioButtonMenuItem, model);
  }
  
  public static void bind(JTextArea textArea, ValueModel valueModel)
  {
    bind(textArea, valueModel, false);
  }
  
  public static void bind(JTextArea textArea, ValueModel valueModel, boolean commitOnFocusLost)
  {
    if (valueModel == null) {
      throw new NullPointerException("The value model must not be null.");
    }
    ValueModel textModel;
    if (commitOnFocusLost)
    {
      ValueModel textModel = createCommitOnFocusLostModel(valueModel, textArea);
      textArea.putClientProperty("commitOnFocusListModel", textModel);
    }
    else
    {
      textModel = valueModel;
    }
    TextComponentConnector connector = new TextComponentConnector(textModel, textArea);
    connector.updateTextComponent();
    addComponentPropertyHandler(textArea, valueModel);
  }
  
  public static void bind(JTextField textField, ValueModel valueModel)
  {
    bind(textField, valueModel, false);
  }
  
  public static void bind(JTextField textField, ValueModel valueModel, boolean commitOnFocusLost)
  {
    if (valueModel == null) {
      throw new NullPointerException("The value model must not be null.");
    }
    ValueModel textModel;
    if (commitOnFocusLost)
    {
      ValueModel textModel = createCommitOnFocusLostModel(valueModel, textField);
      textField.putClientProperty("commitOnFocusListModel", textModel);
    }
    else
    {
      textModel = valueModel;
    }
    TextComponentConnector connector = new TextComponentConnector(textModel, textField);
    connector.updateTextComponent();
    addComponentPropertyHandler(textField, valueModel);
  }
  
  public static void bind(JComponent component, String propertyName, ValueModel valueModel)
  {
    if (component == null) {
      throw new NullPointerException("The component must not be null.");
    }
    if (valueModel == null) {
      throw new NullPointerException("The value model must not be null.");
    }
    if (propertyName == null) {
      throw new NullPointerException("The property name must not be null.");
    }
    PropertyConnector.connectAndUpdate(valueModel, component, propertyName);
    
    addComponentPropertyHandler(component, valueModel);
  }
  
  public static void addComponentPropertyHandler(JComponent component, ValueModel valueModel)
  {
    if (!(valueModel instanceof ComponentValueModel)) {
      return;
    }
    ComponentValueModel cvm = (ComponentValueModel)valueModel;
    PropertyChangeListener componentHandler = new ComponentPropertyHandler(component, null);
    cvm.addPropertyChangeListener(componentHandler);
    component.putClientProperty("componentValueModel", cvm);
    component.putClientProperty("componentPropertyHandler", componentHandler);
    
    component.setEnabled(cvm.isEnabled());
    component.setVisible(cvm.isVisible());
    if ((component instanceof JTextComponent)) {
      ((JTextComponent)component).setEditable(cvm.isEditable());
    }
  }
  
  public static void removeComponentPropertyHandler(JComponent component)
  {
    ComponentValueModel componentValueModel = (ComponentValueModel)component.getClientProperty("componentValueModel");
    
    PropertyChangeListener componentHandler = (PropertyChangeListener)component.getClientProperty("componentPropertyHandler");
    if ((componentValueModel != null) && (componentHandler != null))
    {
      componentValueModel.removePropertyChangeListener(componentHandler);
      component.putClientProperty("componentValueModel", null);
      component.putClientProperty("componentPropertyHandler", null);
    }
    else
    {
      if ((componentValueModel == null) && (componentHandler == null)) {
        return;
      }
      if (componentValueModel != null) {
        throw new IllegalStateException("The component has a ComponentValueModel stored, but lacks the ComponentPropertyHandler.");
      }
      throw new IllegalStateException("The component has a ComponentPropertyHandler stored, but lacks the ComponentValueModel.");
    }
  }
  
  public static void commitImmediately()
  {
    FOCUS_LOST_TRIGGER.triggerCommit();
  }
  
  public static boolean flushImmediately()
  {
    boolean buffering = isFocusOwnerBuffering();
    if (buffering) {
      FOCUS_LOST_TRIGGER.triggerFlush();
    }
    return buffering;
  }
  
  public static boolean isFocusOwnerBuffering()
  {
    Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    if (!(focusOwner instanceof JComponent)) {
      return false;
    }
    Object value = ((JComponent)focusOwner).getClientProperty("commitOnFocusListModel");
    if (!(value instanceof BufferedValueModel)) {
      return false;
    }
    BufferedValueModel commitOnFocusLostModel = (BufferedValueModel)value;
    
    return commitOnFocusLostModel.isBuffering();
  }
  
  private static ValueModel createCommitOnFocusLostModel(ValueModel valueModel, Component component)
  {
    if (valueModel == null) {
      throw new NullPointerException("The value model must not be null.");
    }
    ValueModel model = new BufferedValueModel(valueModel, FOCUS_LOST_TRIGGER);
    component.addFocusListener(FOCUS_LOST_HANDLER);
    return model;
  }
  
  private static final class FocusLostHandler
    extends FocusAdapter
  {
    public void focusLost(FocusEvent evt)
    {
      if (!evt.isTemporary()) {
        Bindings.FOCUS_LOST_TRIGGER.triggerCommit();
      }
    }
  }
  
  private static final class ComponentPropertyHandler
    implements PropertyChangeListener
  {
    private final JComponent component;
    
    private ComponentPropertyHandler(JComponent component)
    {
      this.component = component;
    }
    
    public void propertyChange(PropertyChangeEvent evt)
    {
      String propertyName = evt.getPropertyName();
      ComponentValueModel model = (ComponentValueModel)evt.getSource();
      if ("enabled".equals(propertyName)) {
        component.setEnabled(model.isEnabled());
      } else if ("visible".equals(propertyName)) {
        component.setVisible(model.isVisible());
      } else if (("editable".equals(propertyName)) && 
        ((component instanceof JTextComponent))) {
        ((JTextComponent)component).setEditable(model.isEditable());
      }
    }
  }
  
  private static final class WeakTrigger
    implements ValueModel
  {
    private final transient Bindings.WeakPropertyChangeSupport changeSupport;
    private Boolean value;
    
    WeakTrigger()
    {
      value = null;
      changeSupport = new Bindings.WeakPropertyChangeSupport(this);
    }
    
    public Object getValue()
    {
      return value;
    }
    
    public void setValue(Object newValue)
    {
      if ((newValue != null) && (!(newValue instanceof Boolean))) {
        throw new IllegalArgumentException("Trigger values must be of type Boolean.");
      }
      Object oldValue = value;
      value = ((Boolean)newValue);
      fireValueChange(oldValue, newValue);
    }
    
    public void addValueChangeListener(PropertyChangeListener listener)
    {
      if (listener == null) {
        return;
      }
      changeSupport.addPropertyChangeListener("value", listener);
    }
    
    public void removeValueChangeListener(PropertyChangeListener listener)
    {
      if (listener == null) {
        return;
      }
      changeSupport.removePropertyChangeListener("value", listener);
    }
    
    private void fireValueChange(Object oldValue, Object newValue)
    {
      changeSupport.firePropertyChange("value", oldValue, newValue);
    }
    
    void triggerCommit()
    {
      if (Boolean.TRUE.equals(getValue())) {
        setValue(null);
      }
      setValue(Boolean.TRUE);
    }
    
    void triggerFlush()
    {
      if (Boolean.FALSE.equals(getValue())) {
        setValue(null);
      }
      setValue(Boolean.FALSE);
    }
  }
  
  private static final class WeakPropertyChangeSupport
    extends PropertyChangeSupport
  {
    WeakPropertyChangeSupport(Object sourceBean)
    {
      super();
    }
    
    public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
    {
      if (listener == null) {
        return;
      }
      if ((listener instanceof PropertyChangeListenerProxy))
      {
        PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy)listener;
        
        addPropertyChangeListener(proxy.getPropertyName(), (PropertyChangeListener)proxy.getListener());
      }
      else
      {
        super.addPropertyChangeListener(new WeakPropertyChangeListener(listener, null));
      }
    }
    
    public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
    {
      if (listener == null) {
        return;
      }
      super.addPropertyChangeListener(propertyName, new WeakPropertyChangeListener(propertyName, listener, null));
    }
    
    public synchronized void removePropertyChangeListener(PropertyChangeListener listener)
    {
      if (listener == null) {
        return;
      }
      if ((listener instanceof PropertyChangeListenerProxy))
      {
        PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy)listener;
        
        removePropertyChangeListener(proxy.getPropertyName(), (PropertyChangeListener)proxy.getListener());
        
        return;
      }
      PropertyChangeListener[] listeners = getPropertyChangeListeners();
      for (int i = listeners.length - 1; i >= 0; i--) {
        if (!(listeners[i] instanceof PropertyChangeListenerProxy))
        {
          WeakPropertyChangeListener wpcl = (WeakPropertyChangeListener)listeners[i];
          if (wpcl.get() == listener)
          {
            super.removePropertyChangeListener(wpcl);
            break;
          }
        }
      }
    }
    
    public synchronized void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
    {
      if (listener == null) {
        return;
      }
      PropertyChangeListener[] listeners = getPropertyChangeListeners(propertyName);
      for (int i = listeners.length - 1; i >= 0; i--)
      {
        WeakPropertyChangeListener wpcl = (WeakPropertyChangeListener)listeners[i];
        if (wpcl.get() == listener)
        {
          super.removePropertyChangeListener(propertyName, wpcl);
          break;
        }
      }
    }
    
    public void firePropertyChange(PropertyChangeEvent evt)
    {
      cleanUp();
      super.firePropertyChange(evt);
    }
    
    public void firePropertyChange(String propertyName, Object oldValue, Object newValue)
    {
      cleanUp();
      super.firePropertyChange(propertyName, oldValue, newValue);
    }
    
    static final ReferenceQueue<PropertyChangeListener> QUEUE = new ReferenceQueue();
    
    private static void cleanUp()
    {
      WeakPropertyChangeListener wpcl;
      while ((wpcl = (WeakPropertyChangeListener)QUEUE.poll()) != null) {
        wpcl.removeListener();
      }
    }
    
    void removeWeakPropertyChangeListener(WeakPropertyChangeListener l)
    {
      if (propertyName == null) {
        super.removePropertyChangeListener(l);
      } else {
        super.removePropertyChangeListener(propertyName, l);
      }
    }
    
    private final class WeakPropertyChangeListener
      extends WeakReference<PropertyChangeListener>
      implements PropertyChangeListener
    {
      final String propertyName;
      
      private WeakPropertyChangeListener(PropertyChangeListener delegate)
      {
        this(null, delegate);
      }
      
      private WeakPropertyChangeListener(String propertyName, PropertyChangeListener delegate)
      {
        super(Bindings.WeakPropertyChangeSupport.QUEUE);
        this.propertyName = propertyName;
      }
      
      public void propertyChange(PropertyChangeEvent evt)
      {
        PropertyChangeListener delegate = (PropertyChangeListener)get();
        if (delegate != null) {
          delegate.propertyChange(evt);
        }
      }
      
      void removeListener()
      {
        removeWeakPropertyChangeListener(this);
      }
    }
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.binding.adapter.Bindings
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.binding.adapter;

class BoundedRangeAdapter$1 {}

/* Location:
 * Qualified Name:     com.jgoodies.binding.adapter.BoundedRangeAdapter.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.binding.adapter;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

final class BoundedRangeAdapter$SubjectValueChangeHandler
  implements PropertyChangeListener
{
  private BoundedRangeAdapter$SubjectValueChangeHandler(BoundedRangeAdapter paramBoundedRangeAdapter) {}
  
  public void propertyChange(PropertyChangeEvent evt)
  {
    this$0.fireStateChanged();
  }
}

/* Location:
 * Qualified Name:     com.jgoodies.binding.adapter.BoundedRangeAdapter.SubjectValueChangeHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package com.jgoodies.binding.adapter;

import com.jgoodies.binding.value.ValueModel;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.Serializable;
import javax.swing.BoundedRangeModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;

public final class BoundedRangeAdapter
  implements BoundedRangeModel, Serializable
{
  private transient ChangeEvent changeEvent = null;
  private final EventListenerList listenerList = new EventListenerList();
  private final ValueModel subject;
  private int theExtent = 0;
  private int min = 0;
  private int max = 100;
  private boolean isAdjusting = false;
  
  public BoundedRangeAdapter(ValueModel subject, int extent, int min, int max)
  {
    this.subject = subject;
    Object subjectValue = subject.getValue();
    int initialValue = subjectValue == null ? min : ((Integer)subjectValue).intValue();
    
    initialize(initialValue, extent, min, max);
    subject.addValueChangeListener(new SubjectValueChangeHandler(null));
  }
  
  public int getExtent()
  {
    return theExtent;
  }
  
  public int get
1 2 3 4 5 6 7

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd