001    /* ======================================================
002     * Orson : a free chart beans library based on JFreeChart
003     * ======================================================
004     *
005     * (C) Copyright 2007, by Object Refinery Limited.
006     *
007     * Project Info:  not-yet-released
008     *
009     * This library is free software; you can redistribute it and/or modify it 
010     * under the terms of the GNU Lesser General Public License as published by 
011     * the Free Software Foundation; either version 2.1 of the License, or 
012     * (at your option) any later version.
013     *
014     * This library is distributed in the hope that it will be useful, but 
015     * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016     * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017     * License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this library; if not, write to the Free Software
021     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022     * USA.  
023     *
024     * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025     * in the United States and other countries.]
026     * 
027     */
028    
029    package org.jfree.beans;
030    
031    import java.beans.PropertyChangeEvent;
032    
033    import org.jfree.chart.axis.NumberAxis;
034    import org.jfree.chart.axis.ValueAxis;
035    import org.jfree.chart.plot.XYPlot;
036    
037    /**
038     * An XY chart where both the x and y-axes are numerical.
039     */
040    public abstract class NumericalXYChart extends AbstractXYChart {
041    
042        /**
043         * The x-axis scale type.  Note that a property editor for this type is 
044         * already registered by the {@link AbstractXYChart} class.
045         */
046        private AxisScale xAxisScale;
047    
048        /**
049         * Default constructor.
050         */
051        public NumericalXYChart() {
052            super();
053            this.xAxisScale = AxisScale.FLOAT;
054        }
055        
056        /**
057         * Returns the flag that controls whether or not the auto range calculation
058         * is forced to include zero.
059         * 
060         * @return A boolean.
061         * 
062         * @see #setXAxisAutoRangeIncludesZero(boolean)
063         */
064        public boolean getXAxisAutoRangeIncludesZero() {
065            XYPlot plot = (XYPlot) this.chart.getPlot();
066            if (plot == null) {
067                return false;
068            }
069            NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
070            return xAxis.getAutoRangeIncludesZero();
071        }
072        
073        /**
074         * Sets the flag that controls whether or not the auto range calculation
075         * is forced to include zero and sends a {@link PropertyChangeEvent} for
076         * the <code>xAxisAutoRangeIncludesZero</code> property to all registered
077         * listeners.
078         * 
079         * @param include  the new flag value.
080         * 
081         * @see #getXAxisAutoRangeIncludesZero()
082         */
083        public void setXAxisAutoRangeIncludesZero(boolean include) {
084            XYPlot plot = (XYPlot) this.chart.getPlot();
085            if (plot == null) {
086                return;
087            }
088            NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
089            boolean old = xAxis.getAutoRangeIncludesZero();
090            xAxis.setAutoRangeIncludesZero(include);
091            firePropertyChange("xAxisAutoRangeIncludesZero", old, include);
092        }
093        
094        /**
095         * Returns the scale type for the x-axis.
096         * 
097         * @return The scale type for the x-axis.
098         * 
099         * @see #setXAxisScale(AxisScale)
100         */
101        public AxisScale getXAxisScale() {
102            return this.xAxisScale;
103        }
104    
105        /**
106         * Sets the scale type for the x-axis and sends a 
107         * {@link PropertyChangeEvent} for the <code>xAxisScale</code> property to
108         * all registered listeners.
109         * 
110         * @param scale  the scale type (<code>null</code> not permitted).
111         * 
112         * @see #getXAxisScale()
113         */
114        public void setXAxisScale(AxisScale scale) {
115            if (scale == null) {
116                throw new IllegalArgumentException("Null 'scale' argument.");
117            }
118            XYPlot plot = (XYPlot) this.chart.getPlot();
119            if (plot != null) {
120                AxisScale old = this.xAxisScale;
121                ValueAxis axis = plot.getDomainAxis();
122                if (AxisScale.INTEGER.equals(scale)) {
123                    axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
124                }
125                else if (AxisScale.FLOAT.equals(scale)) {
126                    axis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
127                }
128                firePropertyChange("xAxisScsale", old, scale);
129            }
130        }
131    
132    }