TickSpacingEdit.java :  » Graphic-Library » mjograph » mjo » undo » Java Open Source

Java Open Source » Graphic Library » mjograph 
mjograph » mjo » undo » TickSpacingEdit.java
package mjo.undo;

import mjo.core.*;
import mjo.core.data.*;
import mjo.core.plot.*;
import mjo.components.*;

import javax.swing.undo.*;
import javax.swing.*;
import java.awt.*;

import org.jfree.chart.*;
import org.jfree.chart.axis.*;
import org.jfree.chart.plot.*;

/***/
public class TickSpacingEdit extends OnceDoEdit{
    final private NumberAxis xa, ya;
    final private double newX, newY, oldX, oldY;

    /***/
    public TickSpacingEdit(NumberAxis xAxis, NumberAxis yAxis, double targetX, double targetY){
  xa = xAxis;
  ya = yAxis;

  //
  if(xa.isAutoTickUnitSelection())
      oldX = -1;//-1auto
  else
      oldX = xa.getTickUnit().getSize();
  
      if(ya.isAutoTickUnitSelection())
      oldY = -1;//-1auto
  else
      oldY = ya.getTickUnit().getSize();

  newX = targetX;
  newY = targetY;

    }

    public void onceDo(){
  if(newX <= 0)
      xa.setAutoTickUnitSelection(true);
  else{
      xa.setTickUnit(new NumberTickUnit(newX));
  }

  if(newY <= 0)
      ya.setAutoTickUnitSelection(true);
  else{
      ya.setTickUnit(new NumberTickUnit(newY));
  }

    }

    public void onceUndo(){
  if(oldX <= 0)
      xa.setAutoTickUnitSelection(true);
  else{
      xa.setTickUnit(new NumberTickUnit(oldX));
  }

  if(oldY <= 0)
      ya.setAutoTickUnitSelection(true);
  else{
      ya.setTickUnit(new NumberTickUnit(oldY));
  }

    }

    public String getPresentationName(){
  return "change tick spacings";
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.