Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configuration properties package with tests #368

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2022, by David Gilbert and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* 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 library 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.]
*
* ----------------------
* DefaultAxisConfiguration.java
* ----------------------
* (C) Copyright 2005-2022, by David Gilbert and Contributors.
*
* Original Author: David Gilbert;
* Contributor(s): Andrzej Porebski;
* Arnaud Lelievre;
* Dimitry Polivaev
*
*/

package org.jfree.chart.swing.configuration;

import java.awt.Color;
import java.awt.Font;
import java.util.Map;

import org.jfree.chart.axis.Axis;
import org.jfree.chart.axis.LogAxis;
import org.jfree.chart.axis.NumberAxis;

/**
* A panel for editing the properties of an axis.
*/
class DefaultAxisConfiguration {


public static boolean isContainedIn(Map<String, String> properties, String name) {
return properties.get(name + "." + "areTickLabelsVisible") != null;
}
protected final String name;

private final String label;

private Font labelFont;

private final Color labelColor;

private Font tickLabelFont;


private final Color tickLabelColor;

private final boolean areTickLabelsVisible;

private final boolean areTickMarksVisible;


private final RectangleInsetsConfiguration tickLabelInsets;

private final RectangleInsetsConfiguration labelInsets;

/**
* A static method that returns a configuration that is appropriate for the axis
* type.
*
* @param axis the axis whose properties are to be displayed/edited in
* the panel.
*
* @return A panel or {@code null} if axis is {@code null}.
*/
static DefaultAxisConfiguration getInstance(Axis axis, String name) {

if (axis != null) {
// figure out what type of axis we have and instantiate the
// appropriate panel
if (axis instanceof NumberAxis) {
return new DefaultNumberAxisConfiguration((NumberAxis) axis, name);
}
if (axis instanceof LogAxis) {
return new DefaultLogAxisConfiguration((LogAxis) axis, name);
}
else {
return new DefaultAxisConfiguration(axis, name);
}
}
else {
return null;
}

}

public static DefaultAxisConfiguration getInstance(Map<String, String> properties, String name) {
if(DefaultNumberAxisConfiguration.isContainedIn(properties, name))
return new DefaultNumberAxisConfiguration(properties, name);
if(DefaultLogAxisConfiguration.isContainedIn(properties, name))
return new DefaultLogAxisConfiguration(properties, name);
if(DefaultValueAxisConfiguration.isContainedIn(properties, name))
return new DefaultValueAxisConfiguration(properties, name);
if(DefaultAxisConfiguration.isContainedIn(properties, name))
return new DefaultAxisConfiguration(properties, name);
return null;

}


/**
* Standard constructor: builds a panel for displaying/editing the
* properties of the specified axis.
*
* @param axis the axis whose properties are to be displayed/edited in
* the panel.
*/
DefaultAxisConfiguration(Axis axis, String name) {
this.name = name;
this.label = axis.getLabel();
this.labelFont = axis.getLabelFont();
this.labelColor = (Color) axis.getLabelPaint();
this.tickLabelFont = axis.getTickLabelFont();
this.tickLabelColor = (Color) axis.getTickLabelPaint();

// Insets values
this.tickLabelInsets = new RectangleInsetsConfiguration(axis.getTickLabelInsets(), name + "." + "tickLabelInsets");
this.labelInsets = new RectangleInsetsConfiguration(axis.getLabelInsets(), name + "." + "labelInsets");

this.areTickLabelsVisible =axis.isTickLabelsVisible();
this.areTickMarksVisible =axis.isTickMarksVisible();
}


DefaultAxisConfiguration(Map<String, String> properties, String name) {
this.name = name;
this.label = properties.get(name + "." + "label");
this.labelFont = StringMapper.stringToFont(properties.get(name + "." + "labelFont"));
this.labelColor = StringMapper.stringToColor(properties.get(name + "." + "labelColor"));
this.tickLabelFont = StringMapper.stringToFont(properties.get(name + "." + "tickLabelFont"));
this.tickLabelColor = StringMapper.stringToColor(properties.get(name + "." + "tickLabelColor"));
this.tickLabelInsets = new RectangleInsetsConfiguration(properties, name + "." + "tickLabelInsets");
this.labelInsets = new RectangleInsetsConfiguration(properties, name + "." + "labelInsets");
this.areTickLabelsVisible = Boolean.valueOf(properties.get(name + "." + "areTickLabelsVisible"));
this.areTickMarksVisible = Boolean.valueOf(properties.get(name + "." + "areTickMarksVisible"));
}

void fillProperties(Map<String, String> properties) {
if(label != null)
properties.put(name + "." + "label", label);
properties.put(name + "." + "labelFont", StringMapper.fontToString(labelFont));
properties.put(name + "." + "labelColor", StringMapper.colorToString(labelColor));
properties.put(name + "." + "tickLabelFont", StringMapper.fontToString(tickLabelFont));
properties.put(name + "." + "tickLabelColor", StringMapper.colorToString(tickLabelColor));
tickLabelInsets.fillProperties(properties);
labelInsets.fillProperties(properties);
properties.put(name + "." + "areTickLabelsVisible", Boolean.toString(areTickLabelsVisible));
properties.put(name + "." + "areTickMarksVisible", Boolean.toString(areTickMarksVisible));
}

void setAxisProperties(Axis axis) {
axis.setLabel(label);
axis.setLabelFont(labelFont);
axis.setLabelPaint(labelColor);
axis.setTickMarksVisible(areTickMarksVisible);
axis.setTickLabelsVisible(areTickLabelsVisible);
axis.setTickLabelFont(tickLabelFont);
axis.setTickLabelPaint(tickLabelColor);
axis.setTickLabelInsets(tickLabelInsets.getRectangleInsets());
axis.setLabelInsets(labelInsets.getRectangleInsets());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2022, by David Gilbert and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* 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 library 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.]
*
* -----------------------
* DefaultChartConfiguration.java
* -----------------------
* (C) Copyright 2000-2022, by David Gilbert.
*
* Original Author: David Gilbert;
* Contributor(s): Arnaud Lelievre;
* Daniel Gredler;
* Dimitry Polivaev
*
*/

package org.jfree.chart.swing.configuration;

import java.awt.Color;
import java.util.HashMap;
import java.util.Map;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PolarPlot;
import org.jfree.chart.title.Title;

/**
* A panel for editing chart properties (includes subpanels for the title,
* legend and plot).
*/
public class DefaultChartConfiguration {

private final DefaultTitleConfiguration titleConfiguration;

private final DefaultPlotConfiguration plotConfiguration;

private final boolean antialias;

private final Color background;

DefaultChartConfiguration(JFreeChart chart) {
this.antialias = chart.getAntiAlias();
this.background = (Color) chart.getBackgroundPaint();

Title title = chart.getTitle();
Plot plot = chart.getPlot();
this.titleConfiguration = new DefaultTitleConfiguration(title, "title");
if (plot instanceof PolarPlot) {
this.plotConfiguration = new DefaultPolarPlotConfiguration((PolarPlot) plot, "plot");
}
else {
this.plotConfiguration = new DefaultPlotConfiguration(plot, "plot");
}
}

DefaultChartConfiguration(Map<String, String> properties) {
antialias = Boolean.parseBoolean(properties.getOrDefault("antialias", "true"));
String x = properties.get("background");
background = StringMapper.stringToColor(x);
this.titleConfiguration = new DefaultTitleConfiguration(properties, "title");
if(Boolean.valueOf(properties.get("polarPlot"))) {
this.plotConfiguration = new DefaultPolarPlotConfiguration(properties, "plot");
}
else {
this.plotConfiguration = new DefaultPlotConfiguration(properties, "plot");
}
}

public Map<String, String> getProperties() {
Map<String, String> properties = new HashMap<String, String>();
fillProperties(properties);
return properties;
}

public void fillProperties(Map<String, String> properties) {
properties.put("antialias", Boolean.toString(antialias));
properties.put("background", StringMapper.colorToString(background));
properties.put("polarPlot", Boolean.toString(plotConfiguration instanceof DefaultPolarPlotConfiguration));
titleConfiguration.fillProperties(properties);
plotConfiguration.fillProperties(properties);
}

public void updateChart(JFreeChart chart) {
this.titleConfiguration.setTitleProperties(chart);
this.plotConfiguration.updatePlotProperties(chart.getPlot());
chart.setAntiAlias(antialias);
chart.setBackgroundPaint(background);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2022, by David Gilbert and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* 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 library 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.]
*
* -------------------------
* DefaultLogAxisConfiguration.java
* -------------------------
* (C) Copyright 2005-2022, by David Gilbert and Contributors.
*
* Original Author: Martin Hoeller;
* Contributor(s): Dimitry Polivaev;
*
*/

package org.jfree.chart.swing.configuration;



import java.util.Map;

import org.jfree.chart.axis.Axis;
import org.jfree.chart.axis.LogAxis;
import org.jfree.chart.axis.NumberTickUnit;

/**
* A panel for editing properties of a {@link LogAxis}.
*/
class DefaultLogAxisConfiguration extends DefaultValueAxisConfiguration {

private static final String MANUAL_TICK_UNIT = "logAxisManualTickUnit";

public static boolean isContainedIn(Map<String, String> properties, String name) {
return properties.get(name + "." + MANUAL_TICK_UNIT) != null;
}


private final double manualTickUnit;

/**
* Standard constructor: builds a property panel for the specified axis.
*
* @param axis the axis, which should be changed.
*/
DefaultLogAxisConfiguration(LogAxis axis, String name) {
super(axis, name);
this.manualTickUnit = axis.getTickUnit().getSize();
}

DefaultLogAxisConfiguration(Map<String, String> properties, String name) {
super(properties, name); // calling the constructor of the superclass with the Map<String, String> and name parameters
this.manualTickUnit = Double.valueOf(properties.get(name + "." + MANUAL_TICK_UNIT));
}

@Override
void fillProperties(Map<String, String> properties) {
super.fillProperties(properties); // calling the fillProperties method of the superclass
properties.put(name + "." + MANUAL_TICK_UNIT, Double.toString(manualTickUnit));
}

@Override
void setAxisProperties(Axis axis) {
super.setAxisProperties(axis);
LogAxis logAxis = (LogAxis) axis;
if (! isAutoTickUnitSelection) {
logAxis.setTickUnit(new NumberTickUnit(manualTickUnit));
}
}
}
Loading