Package es.iiia.shapegrammar.rule

Source Code of es.iiia.shapegrammar.rule.RuleShapePropertySource

package es.iiia.shapegrammar.rule;

import java.util.ArrayList;

import javax.swing.JOptionPane;

import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;

import es.iiia.shapegrammar.model.NodeModel;

public class RuleShapePropertySource implements IPropertySource {
  private static String scaleID = "scaleRuleDesignBlock";
    private static String rotateID = "rotateRuleDesignBlock";
    private static String flipHorizontal = "flipHorizontal";
    private static String flipVertical = "flipVertical";
   
    private static final String[] bool = {"No", "Yes"};
   
  protected RuleShapeModel node;
   
    public RuleShapePropertySource(RuleShapeModel node) {
            this.node = node;
    }
  public Object getEditableValue() {
    return null;
  }

  public IPropertyDescriptor[] getPropertyDescriptors() {
    ArrayList<IPropertyDescriptor> properties = new ArrayList<IPropertyDescriptor>();
         if (this.node instanceof RuleShapeModel) {
           TextPropertyDescriptor desc = new TextPropertyDescriptor(NodeModel.PROPERTY_RENAME, "Name");
             properties.add(desc);
             desc = new TextPropertyDescriptor(scaleID, "Scale");
             desc.setCategory("Geometry");
             properties.add(desc);
            
             desc = new TextPropertyDescriptor(rotateID, "Rotate");
             desc.setCategory("Geometry");
             properties.add(desc);
            
             ComboBoxPropertyDescriptor combo = new ComboBoxPropertyDescriptor(flipHorizontal, "Flip horizontal", bool);
             desc.setCategory("Geometry");
             properties.add(combo);
            
             combo = new ComboBoxPropertyDescriptor(flipVertical, "Flip vertical", bool);
             desc.setCategory("Geometry");
             properties.add(combo);
         }
         return properties.toArray(new IPropertyDescriptor[0]);

  }

  public Object getPropertyValue(Object id) {
    if (id.equals(NodeModel.PROPERTY_RENAME)) {
            return node.getName()
    } else if (id.equals(scaleID)) {
      return "1,1";
    } else if (id.equals(rotateID)) {
      return "0";
    } else if (id.equals(flipHorizontal)) {
      return 0;
    } else if (id.equals(flipVertical)) {
      return 0;
    }
    return null;
  }

  public boolean isPropertySet(Object id) {
    return false;
  }

  public void resetPropertyValue(Object id) {
   
  }

  public void setPropertyValue(Object id, Object value) {
    if (id.equals(NodeModel.PROPERTY_RENAME)) {
            node.setName((String)value);
    } else if (id.equals(flipHorizontal)) {
      node.flipHorizontal();
    } else if (id.equals(flipVertical)) {
      node.flipVertical();
    } else {
      // number values
      try {
     
        if (id.equals(scaleID)) {
          String[] scale = value.toString().split(",");
          double x = Double.parseDouble(scale[0]);
          double y = Double.parseDouble(scale.length == 2 ? scale[1] : scale[0]);
          node.scale(x, y, 0, 0);
        } else if (id.equals(rotateID)) {
          double number = Double.parseDouble(value.toString());
          node.rotate((number * Math.PI) / 180);
        }       
     
      } catch (NumberFormatException ex) {
        // TODO: Better show!
        // JOptionPane.showMessageDialog(null, "This is not a number!");
      }
    }
  }
}
TOP

Related Classes of es.iiia.shapegrammar.rule.RuleShapePropertySource

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.