    001package org.vishia.gral.widget;
    002
    003import org.vishia.gral.base.GralPos;
    004import org.vishia.gral.base.GralWidget;
    005import org.vishia.gral.ifc.GralCanvasStorage;
    006import org.vishia.gral.ifc.GralColor;
    007import org.vishia.gral.ifc.GralRectangle;
    008
    009/**A widget which is a canvas to plot something.
    010 * @author hartmut Schorrig
    011 *
    012 */
    013public class GralPlotArea extends GralWidget
    014{
    015  /**Version, history and license.
    016   * <ul>
    017   * <li>2015-09-26 Hartmut creation.
    018   * </ul>
    019   * <br><br>
    020   * <b>Copyright/Copyleft</b>:
    021   * For this source the LGPL Lesser General Public License,
    022   * published by the Free Software Foundation is valid.
    023   * It means:
    024   * <ol>
    025   * <li> You can use this source without any restriction for any desired purpose.
    026   * <li> You can redistribute copies of this source to everybody.
    027   * <li> Every user of this source, also the user of redistribute copies
    028   *    with or without payment, must accept this license for further using.
    029   * <li> But the LPGL is not appropriate for a whole software product,
    030   *    if this source is only a part of them. It means, the user
    031   *    must publish this part of source,
    032   *    but don't need to publish the whole source of the own product.
    033   * <li> You can study and modify (improve) this source
    034   *    for own using or for redistribution, but you have to license the
    035   *    modified sources likewise under this LGPL Lesser General Public License.
    036   *    You mustn't delete this Copyright/Copyleft inscription in this source file.
    037   * </ol>
    038   * If you are intent to use this sources without publishing its usage, you can get
    039   * a second license subscribing a special contract with the author.
    040   *
    041   * @author Hartmut Schorrig = hartmut@vishia.org
    042   *
    043   */
    044  public static final String sVersion = "2015-09-26";
    045
    046  protected final GralCanvasStorage canvasStore = new GralCanvasStorage();
    047
    048  public GralPlotArea(String posname) {
    049    super(posname, 'P' );
    050  }
    051
    052
    053  public UserUnits userUnitsPerGrid(float x0, float y0, float xSize, float ySize) {
    054    return new UserUnits(x0, y0, xSize, ySize, true);
    055  }
    056
    057
    058  public void drawLine(GralColor color, UserUnits userUnits, float[][] points, int iy) {
    059    canvasStore.drawLine(color, userUnits, points, iy);
    060  }
    061
    062
    063
    064
    065
    066  public class UserUnits{
    067    /**User units for this area to draw somewhat in user units. */
    068    final public float x0, y0, xmax, ymax, fx, fy;
    069
    070    /**Sets the user units
    071     * @param x0 origin, x-Coordinate, bottom left
    072     * @param y0 origin, y-Coordinate, bottom left
    073     * @param x1 x-Coordinate, right
    074     * @param y1 y-Coordinate top right
    075     */
    076    protected UserUnits(float x0, float y0, float x1, float y1, boolean perGridPos){
    077      this.x0 = x0; this.y0 = y0; this.xmax = x1; this.ymax = y1;
    078      GralPos pos = GralPlotArea.super.pos();
    079      float height, width;
    080      if(perGridPos){
    081        height= width = 1;
    082        fx = height / x1;
    083        fy = width  / y1;
    084      } else {
    085        height = pos.height();
    086        width = pos.width();
    087        fx = height / (x1 - x0);
    088        fy = width  / (y1 - y0);
    089      }
    090    }
    091  }
    092
    093
    094  /**This class contains the access to the GralWidget class. It is used only as super class for the implementation level.
    095   * Don't use this class from user applications! It is public only because it should be seen from the graphic implementation.
    096   */
    097  public abstract class _GraphicImplAccess_ extends GralWidget.ImplAccess {
    098
    099    protected _GraphicImplAccess_(GralWidget widgg)
    100    {
    101      super(widgg);
    102    }
    103
    104    protected GralCanvasStorage canvasStore(){ return GralPlotArea.this.canvasStore; }
    105
    106    @Override public boolean setFocusGThread()
    107    {
    108      // TODO Auto-generated method stub
    109      return false;
    110    }
    111
    112    @Override public void removeWidgetImplementation()
    113    {
    114      // TODO Auto-generated method stub
    115
    116    }
    117
    118    @Override public void repaintGthread()
    119    {
    120      // TODO Auto-generated method stub
    121
    122    }
    123
    124    @Override public Object getWidgetImplementation()
    125    {
    126      // TODO Auto-generated method stub
    127      return null;
    128    }
    129
    130    @Override public void setBoundsPixel(int x, int y, int dx, int dy)
    131    {
    132      // TODO Auto-generated method stub
    133
    134    }
    135
    136    @Override public GralRectangle getPixelPositionSize()
    137    {
    138      // TODO Auto-generated method stub
    139      return null;
    140    }
    141
    142  }
    143
    144}