Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
public final class ChartInfo {

private final String exampleChartName;
private final ExampleChart exampleChart;
private final ExampleChart<?> exampleChart;

/**
* Constructor
*
* @param exampleChartName
* @param exampleChart
*/
public ChartInfo(String exampleChartName, ExampleChart exampleChart) {
public ChartInfo(String exampleChartName, ExampleChart<?> exampleChart) {

this.exampleChartName = exampleChartName;
this.exampleChart = exampleChart;
Expand All @@ -24,7 +24,7 @@ public String getExampleChartName() {
return exampleChartName;
}

public ExampleChart getExampleChart() {
public ExampleChart<?> getExampleChart() {

return exampleChart;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ public static final class EditableProperty {
ChartStylePanel csp;
Object additionalParameter;

static HashMap<Class, TableCellEditor> editorMap;
static Class[] assignableClasses = {
static HashMap<Class<?>, TableCellEditor> editorMap;
static Class<?>[] assignableClasses = {
Theme.class, BasicStroke.class, Marker.class, TimeZone.class
};

static {
editorMap = new HashMap<Class, TableCellEditor>();
editorMap = new HashMap<>();
{
JComboBox comboBox = new JComboBox(new Boolean[] {Boolean.TRUE, Boolean.FALSE});
JComboBox<Boolean> comboBox = new JComboBox<>(new Boolean[] {Boolean.TRUE, Boolean.FALSE});
TableCellEditor cellEditor = new DefaultCellEditor(comboBox);
editorMap.put(Boolean.class, cellEditor);
editorMap.put(Boolean.TYPE, cellEditor);
}

{
Class[][] clsArr = {
Class<?>[][] clsArr = {
{int.class, Integer.class},
{byte.class, Byte.class},
{short.class, Short.class},
Expand All @@ -103,17 +103,17 @@ public static final class EditableProperty {
{String.class, String.class}
};

for (Class[] classes : clsArr) {
for (Class<?>[] classes : clsArr) {
GenericEditorWithClass editor = new GenericEditorWithClass(classes[1]);
for (Class class1 : classes) {
for (Class<?> class1 : classes) {
editorMap.put(class1, editor);
}
}
}

{
JComboBox comboBox =
new JComboBox(new Theme[] {new XChartTheme(), new GGPlot2Theme(), new MatlabTheme()});
JComboBox<Theme> comboBox =
new JComboBox<>(new Theme[] {new XChartTheme(), new GGPlot2Theme(), new MatlabTheme()});
editorMap.put(Theme.class, new DefaultCellEditor(comboBox));
}

Expand All @@ -125,7 +125,7 @@ public static final class EditableProperty {
new LabelValue("DASH_DASH", SeriesLines.DASH_DASH),
new LabelValue("DASH_DOT", SeriesLines.DASH_DOT)
};
JComboBox comboBox = new JComboBox(values);
JComboBox<LabelValue> comboBox = new JComboBox<>(values);
editorMap.put(BasicStroke.class, new DefaultCellEditor(comboBox));
}
{
Expand Down Expand Up @@ -156,13 +156,13 @@ public static final class EditableProperty {
new LabelValue("GGPlot2 Tick Marks", new BasicStroke(1.5f)), //
new LabelValue("Matlab Tick Marks", new BasicStroke(.5f)), //
};
JComboBox comboBox = new JComboBox(values);
JComboBox<LabelValue> comboBox = new JComboBox<>(values);
editorMap.put(Stroke.class, new DefaultCellEditor(comboBox));
}

{
Marker[] seriesMarkers = new BaseSeriesMarkers().getSeriesMarkers();
JComboBox comboBox = new JComboBox(seriesMarkers);
JComboBox<Marker> comboBox = new JComboBox<>(seriesMarkers);
editorMap.put(Marker.class, new DefaultCellEditor(comboBox));
}

Expand All @@ -178,7 +178,7 @@ public static final class EditableProperty {
Locale.GERMAN,
Locale.forLanguageTag("tr-TR")
};
JComboBox comboBox = new JComboBox(values);
JComboBox<Locale> comboBox = new JComboBox<>(values);
editorMap.put(Locale.class, new DefaultCellEditor(comboBox));
}

Expand All @@ -188,7 +188,7 @@ public static final class EditableProperty {
for (int i = 0; i < values.length; i++) {
values[i] = TimeZone.getTimeZone(availableIDs[i]);
}
JComboBox comboBox = new JComboBox(values);
JComboBox<TimeZone> comboBox = new JComboBox<>(values);
editorMap.put(TimeZone.class, new DefaultCellEditor(comboBox));
}
}
Expand Down Expand Up @@ -220,19 +220,19 @@ private void initEditor() {

try {
Object val = getValue();
Class cls = val == null ? getValueClass() : val.getClass();
Class<?> cls = val == null ? getValueClass() : val.getClass();
cellEditor = editorMap.get(cls);
if (cellEditor != null) {
return;
}

if (cls.isEnum()) {
JComboBox comboBox = new JComboBox(cls.getEnumConstants());
JComboBox<Object> comboBox = new JComboBox<>(cls.getEnumConstants());
cellEditor = new DefaultCellEditor(comboBox);
return;
}

for (Class class1 : assignableClasses) {
for (Class<?> class1 : assignableClasses) {
if (class1.isAssignableFrom(cls)) {
cellEditor = editorMap.get(class1);
return;
Expand Down Expand Up @@ -316,7 +316,7 @@ public TableCellEditor getTableCellEditor() {
return cellEditor;
}

public Class getValueClass() {
public Class<?> getValueClass() {

if (readMethod == null) {
// obj is array
Expand Down Expand Up @@ -354,11 +354,11 @@ public Component getTableCellEditorComponent(

static class GenericEditorWithClass extends DefaultCellEditor {

Class[] argTypes = new Class[] {String.class};
java.lang.reflect.Constructor constructor;
Class<?>[] argTypes = new Class<?>[] {String.class};
java.lang.reflect.Constructor<?> constructor;
Object value;

public GenericEditorWithClass(Class cls) {
public GenericEditorWithClass(Class<?> cls) {
super(new JTextField());
getComponent().setName("Table.editor");
try {
Expand Down Expand Up @@ -409,19 +409,19 @@ public Object getCellEditorValue() {

public static class EditorTableModel extends DefaultTableModel {
ArrayList<EditableProperty> properties;
Chart chart;
Chart<?, ?> chart;
int rowCount;
ChartStylePanel csp;

public EditorTableModel(ChartStylePanel csp, Chart chart) {
public EditorTableModel(ChartStylePanel csp, Chart<?, ?> chart) {
this.csp = csp;
addColumn("Name");
addColumn("Type");
addColumn("Value");
changeChart(chart);
}

public void changeChart(Chart chart) {
public void changeChart(Chart<?, ?> chart) {

this.chart = chart;
properties = getProperties(csp, chart);
Expand Down Expand Up @@ -487,7 +487,7 @@ public int getRowCount() {
public static class EditorTable extends JTable {
EditorTableModel tableModel;

public EditorTable(ChartStylePanel csp, Chart chart) {
public EditorTable(ChartStylePanel csp, Chart<?, ?> chart) {
tableModel = new EditorTableModel(csp, chart);

setModel(tableModel);
Expand All @@ -503,7 +503,7 @@ public EditorTable(ChartStylePanel csp, Chart chart) {
setAutoCreateRowSorter(true);
}

public void changeChart(Chart chart) {
public void changeChart(Chart<?, ?> chart) {

tableModel.changeChart(chart);
}
Expand All @@ -517,7 +517,7 @@ public TableCellEditor getCellEditor(int row, int column) {
if (editor != null) {
return editor;
}
Class valueClass = se.getValueClass();
Class<?> valueClass = se.getValueClass();
TableCellEditor defaultEditor = getDefaultEditor(valueClass);

// System.out.println(valueClass + "=>" + defaultEditor);
Expand All @@ -526,9 +526,9 @@ public TableCellEditor getCellEditor(int row, int column) {
}

private EditorTable table;
private XChartPanel chartPanel;
private XChartPanel<?> chartPanel;

public ChartStylePanel(XChartPanel chartPanel) {
public ChartStylePanel(XChartPanel<?> chartPanel) {
this.chartPanel = chartPanel;
table = new EditorTable(this, chartPanel.getChart());
JScrollPane scrollpane = new JScrollPane(table);
Expand All @@ -538,7 +538,7 @@ public ChartStylePanel(XChartPanel chartPanel) {
setPreferredSize(new Dimension(800, 600));
}

public void changeChart(XChartPanel chartPanel) {
public void changeChart(XChartPanel<?> chartPanel) {

this.chartPanel = chartPanel;
table.changeChart(chartPanel.getChart());
Expand Down Expand Up @@ -575,7 +575,7 @@ protected void repaintChart() {
"YAxisAlignment",
"YAxisGroupPosition"));

public static ArrayList<EditableProperty> getProperties(ChartStylePanel csp, Chart chart) {
public static ArrayList<EditableProperty> getProperties(ChartStylePanel csp, Chart<?, ?> chart) {

if (chart == null) {
return new ArrayList<EditableProperty>();
Expand All @@ -585,10 +585,10 @@ public static ArrayList<EditableProperty> getProperties(ChartStylePanel csp, Cha
getObjectProperties(csp, chart.getStyler(), "styler.", skipSet);
list.addAll(list2);

Map<String, Series> seriesMap = chart.getSeriesMap();
Map<String, ? extends Series> seriesMap = chart.getSeriesMap();
int ind = 0;
TreeSet<Integer> seriesIndSet = new TreeSet<Integer>();
for (Entry<String, Series> e : seriesMap.entrySet()) {
for (Entry<String, ? extends Series> e : seriesMap.entrySet()) {
Series series = e.getValue();
list2 = getObjectProperties(csp, series, "series[" + e.getKey() + "].", skipSet);
list.addAll(list2);
Expand Down
21 changes: 15 additions & 6 deletions xchart-demo/src/main/java/org/knowm/xchart/demo/XChartDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class XChartDemo extends JPanel implements TreeSelectionListener {
private final JTree tree;

/** The panel for chart */
protected XChartPanel chartPanel;
protected XChartPanel<?> chartPanel;

Timer timer = new Timer();

Expand All @@ -57,7 +57,7 @@ public XChartDemo() {
JScrollPane treeView = new JScrollPane(tree);

// Create Chart Panel
chartPanel = new XChartPanel(new AreaChart01().getChart());
chartPanel = new XChartPanel<>(new AreaChart01().getChart());

// Add the scroll panes to a split pane.
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
Expand Down Expand Up @@ -86,9 +86,8 @@ public void valueChanged(TreeSelectionEvent e) {
if (node.isLeaf()) {
ChartInfo chartInfo = (ChartInfo) nodeInfo;
// displayURL(chartInfo.bookURL);
ExampleChart exampleChart = chartInfo.getExampleChart();
chartPanel = new XChartPanel(exampleChart.getChart());
exampleChart.customizePanel(chartPanel);
ExampleChart<?> exampleChart = chartInfo.getExampleChart();
updateChartPanel(exampleChart);
splitPane.setBottomComponent(chartPanel);

// start running a simulated data feed for the sample real-time plot
Expand All @@ -113,6 +112,16 @@ public void run() {
}
}

private void updateChartPanel(ExampleChart<?> exampleChart) {
doUpdateChartPanel(exampleChart);
}

private <C extends Chart<?, ?>> void doUpdateChartPanel(ExampleChart<C> exampleChart) {
XChartPanel<C> panel = new XChartPanel<>(exampleChart.getChart());
exampleChart.customizePanel(panel);
chartPanel = panel;
}

/**
* Create the tree
*
Expand All @@ -127,7 +136,7 @@ private void createNodes(DefaultMutableTreeNode top) {

List<ExampleChart<Chart<Styler, Series>>> exampleList = DemoChartsUtil.getAllDemoCharts();
String categoryName = "";
for (ExampleChart exampleChart : exampleList) {
for (ExampleChart<Chart<Styler, Series>> exampleChart : exampleList) {
String name = exampleChart.getClass().getSimpleName();
name = name.substring(0, name.indexOf("Chart"));
if (!categoryName.equals(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public XChartStyleDemo() {

@Override
public void valueChanged(TreeSelectionEvent e) {
XChartPanel oldChartPanel = chartPanel;
XChartPanel<?> oldChartPanel = chartPanel;
super.valueChanged(e);
if (chartPanel != oldChartPanel) {
stylePanel.changeChart(chartPanel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.knowm.xchart.ToolTipType;
import org.knowm.xchart.XChartPanel;
import org.knowm.xchart.demo.charts.ExampleChart;
import org.knowm.xchart.style.Styler;
import org.knowm.xchart.style.Styler.LegendPosition;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Random;
import org.knowm.xchart.CategoryChart;
import org.knowm.xchart.CategoryChartBuilder;
import org.knowm.xchart.CategorySeries;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.demo.charts.ExampleChart;

Expand Down Expand Up @@ -72,10 +71,8 @@ public CategoryChart getChart() {
chart.getStyler().setLabelsRotation(45);

// Series
CategorySeries series1 =
chart.addSeries("series1", getLinearValues(0, 200, 6), getRandomValues(10, 50, 6));
CategorySeries series2 =
chart.addSeries("series2", getLinearValues(0, 200, 6), getRandomValues(10, 50, 6));
chart.addSeries("series1", getLinearValues(0, 200, 6), getRandomValues(10, 50, 6));
chart.addSeries("series2", getLinearValues(0, 200, 6), getRandomValues(10, 50, 6));

return chart;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public CategoryChart getChart() {
}

// Series
CategorySeries staked1 = chart.addSeries("Period 1", months, period1Values);
CategorySeries staked2 = chart.addSeries("Period 2", months, period2Values);
CategorySeries staked3 = chart.addSeries("Period 3", months, period3Values);
chart.addSeries("Period 1", months, period1Values);
chart.addSeries("Period 2", months, period2Values);
chart.addSeries("Period 3", months, period3Values);
CategorySeries overlappedLine = chart.addSeries("Average", months, averageValues);
overlappedLine.setOverlapped(true);
overlappedLine.setChartCategorySeriesRenderStyle(CategorySeries.CategorySeriesRenderStyle.Line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.awt.Font;
import org.knowm.xchart.DialChart;
import org.knowm.xchart.DialChartBuilder;
import org.knowm.xchart.DialSeries;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.XChartPanel;
import org.knowm.xchart.demo.charts.ExampleChart;
Expand Down Expand Up @@ -46,7 +45,7 @@ public DialChart getChart() {
.build();

// Series
DialSeries series = chart.addSeries("Rate", 0.55, "55 %");
chart.addSeries("Rate", 0.55, "55 %");

chart.getStyler().setLegendVisible(true);
chart.getStyler().setArcAngle(330);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public XYChart getChart() {
// chart.getStyler().setXAxisLabelRotation(0);

// Series
XYSeries series = chart.addSeries("10^x", xData, yData);
chart.addSeries("10^x", xData, yData);

return chart;
}
Expand Down
Loading
Loading