Package DisplayProject.controls

Source Code of DisplayProject.controls.ReadOnlyButtonModel

/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package DisplayProject.controls;

import java.awt.event.ActionListener;
import java.awt.event.ItemListener;

import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.JComponent;
import javax.swing.event.ChangeListener;
import javax.swing.table.TableCellEditor;

import DisplayProject.table.ArrayFieldCellHelper;

/**
* A read-only model that does not allow the user to alter the value of the selected state
* of the button. This model will delegate most of the model work to the real model
* and only override a few critical methods.
* @author Tim
*
*/
public class ReadOnlyButtonModel implements ButtonModel {
  private ButtonModel originalModel;
  private JComponent widget;
 
  public ReadOnlyButtonModel(JComponent widget, ButtonModel originalModel) {
    this.originalModel = originalModel;
  }

  public void addActionListener(ActionListener l) { originalModel.addActionListener(l); }
  public void addChangeListener(ChangeListener l) { originalModel.addChangeListener(l); }
  public void addItemListener(ItemListener l)    { originalModel.addItemListener(l); }
  public String getActionCommand() { return originalModel.getActionCommand(); }
  public int getMnemonic() { return originalModel.getMnemonic(); }
  public Object[] getSelectedObjects() { return originalModel.getSelectedObjects(); }
  public boolean isArmed() {return originalModel.isArmed();}
  public boolean isEnabled() { return originalModel.isEnabled(); }
  public boolean isRollover() {return originalModel.isRollover();}
  public boolean isSelected() {return originalModel.isSelected();}
  public void removeActionListener(ActionListener l) {originalModel.removeActionListener(l);}
  public void removeChangeListener(ChangeListener l) {originalModel.removeChangeListener(l);}
  public void removeItemListener(ItemListener l) {originalModel.removeItemListener(l);}
  public void setActionCommand(String s) {originalModel.setActionCommand(s);}
  public void setArmed(boolean b) {originalModel.setArmed(b);}
  public void setEnabled(boolean b) {originalModel.setEnabled(b);}
  public void setGroup(ButtonGroup group) {originalModel.setGroup(group);}
  public void setMnemonic(int key) {originalModel.setMnemonic(key);}
  public void setRollover(boolean b) {originalModel.setRollover(b);}
  public void setSelected(boolean b) {originalModel.setSelected(b);}

  public ButtonModel getOriginalModel() {
    return this.originalModel;
  }

  public boolean isPressed() {
    // A read-only model doesn't get pressed
    return false;
  }
  public void setPressed(boolean b) {
    // A read-only button cannot be pressed, however if we were going to be activated
    // and we're in an array field, we need to cancel the cell editing
    if (isArmed() && !b) {
      ArrayField af = ArrayFieldCellHelper.getArrayField(this.widget);
      if (af != null) {
        final TableCellEditor editor = af.getCellEditor();
        if (editor != null) {
          editor.cancelCellEditing();
        }
      }
    }
  }
}

TOP

Related Classes of DisplayProject.controls.ReadOnlyButtonModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.