jcckit.plot.PlotCanvas Maven / Gradle / Ivy
Show all versions of plantuml Show documentation
/*
* Copyright 2003-2004, Franz-Josef Elmer, All rights reserved
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details
* (http://www.gnu.org/copyleft/lesser.html).
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package jcckit.plot;
import jcckit.data.DataPlot;
import jcckit.graphic.Anchor;
import jcckit.graphic.ClippingRectangle;
import jcckit.util.ConfigParameters;
/**
* An abstract canvas containg a single {@link Plot}. The canvas is specified
* by a {@link ClippingRectangle}, called paper. A horizontal and
* vertical {@link Anchor} determine the position of the paper on the actual
* device.
*
* @author Franz-Josef Elmer
*/
public class PlotCanvas implements PlotListener {
/** Configuration parameter key. */
public static final String PAPER_KEY = "paper", HORIZONTAL_ANCHOR_KEY = "horizontalAnchor",
VERTICAL_ANCHOR_KEY = "verticalAnchor", PLOT_KEY = "plot";
private final ClippingRectangle _paper;
private final Anchor _horizontalAnchor;
private final Anchor _verticalAnchor;
private final Plot _plot;
/**
* Creates an instance from the specified configuration parameters.
*
* Key & Default Value
* Type
* Mandatory
* Description
*
*
* horizontalAnchor = center
* String
* no
* Horizontal position of the paper relative to the device border.
* Possible values are left, center, and
* right.
*
*
* paper = 0, 0, 1, 0.6
* double[]
* no
* Rectangle defining the paper. The first two values determine the x-
* and y- coordinates (in device-independent units) of the lower-left
* corner. The last two values determine the upper-right corner.
*
*
* plot = default values of {@link Plot}
* ConfigParameters
* no
* Definition of the {@link Plot}.
*
*
* verticalAnchor = center
* String
* no
* Vertical position of the paper relative to the device border.
* Possible values are top, center, and
* bottom.
*
*
*
* Note, that this instance registers itself at the wrapped {@link Plot}
* instance.
*/
public PlotCanvas(ConfigParameters config) {
double[] paper = config.getDoubleArray(PAPER_KEY, new double[] { 0, 0, 1, 0.6 });
_paper = new ClippingRectangle(paper[0], paper[1], paper[2], paper[3]);
_horizontalAnchor = Anchor.getHorizontalAnchor(config, HORIZONTAL_ANCHOR_KEY, Anchor.CENTER);
_verticalAnchor = Anchor.getVerticalAnchor(config, VERTICAL_ANCHOR_KEY, Anchor.CENTER);
_plot = new Plot(config.getNode(PLOT_KEY));
_plot.addPlotListener(this);
}
/** Returns the paper definition. */
public ClippingRectangle getPaper() {
return _paper;
}
/** Returns the horizontal anchor. */
public Anchor getHorizontalAnchor() {
return _horizontalAnchor;
}
/** Returns the vertical anchor. */
public Anchor getVerticalAnchor() {
return _verticalAnchor;
}
/** Returns the plot. */
public Plot getPlot() {
return _plot;
}
/**
* Connects the wrapped {@link Plot} instance with the specified
* {@link DataPlot}.
*
* @param dataPlot
* Data to be connected with this plot canvas. Can be
* null in order to disconnect this instance from a
* DataPlot.
*/
public void connect(DataPlot dataPlot) {
_plot.connect(dataPlot);
}
/**
* Handles the spcified event. Here nothing is done. But subclass may
* override this method.
*/
public void plotChanged(PlotEvent event) {
}
}