Package periman

Source Code of periman.ExpQstnrRowSpinner

package periman;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.w3c.dom.Document;

public class ExpQstnrRowSpinner implements ExpQstnrRow {

  String labelCaption;
  int minValue;
  int maxValue;
  int stepSize;
  int defaultValue;
 

  SpinnerNumberModel spinnerModel;


  public ExpQstnrRowSpinner(Element rowElement) {
    labelCaption = rowElement.getAttribute("label");
    minValue = Integer.parseInt( rowElement.getAttribute("min") );
    maxValue = Integer.parseInt( rowElement.getAttribute("max") );
    stepSize = Integer.parseInt( rowElement.getAttribute("step") );
    defaultValue = Integer.parseInt( rowElement.getAttribute("default") );
  }

  @Override
  public Element resultToDom(Document dom) {
    Element newRowElement = null;
    try{
      newRowElement = dom.createElement( Util.xmlElementValidfy(labelCaption) );
    }
    catch(DOMException de)
    {
      newRowElement = dom.createElement( "spinner_"+labelCaption.hashCode() );
    }
   
   
    newRowElement.setAttribute("value", ""+spinnerModel.getNumber().intValue() );
    return newRowElement;
  }

  @Override
  public JPanel toPanel() {
    JPanel panel = new JPanel();
    GridBagLayout layout = new GridBagLayout();
    panel.setLayout(layout);
   
    JLabel lbl = new JLabel(labelCaption);
    GridBagConstraints lblC = new GridBagConstraints();
    lblC.gridx=0;
    lblC.gridy=0;

    panel.add(lbl, lblC);

    spinnerModel = new SpinnerNumberModel();
    spinnerModel.setValue( defaultValue );
    JSpinner spinner = new JSpinner( spinnerModel );
    GridBagConstraints fieldC = new GridBagConstraints();
    fieldC.gridx=1;
    fieldC.gridy=0;
    fieldC.fill = GridBagConstraints.HORIZONTAL;
    fieldC.weightx = 1.0;
    fieldC.gridwidth = GridBagConstraints.REMAINDER;
    panel.add(spinner, fieldC);

    return panel;
  }

  @Override
  public boolean shouldNextBeEnabled() {
    return false;
  }

}
TOP

Related Classes of periman.ExpQstnrRowSpinner

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.