Skip to content

Commit e7c7bf2

Browse files
authored
Merge pull request #944 from knowm/timmolter/investigate-ide-warnings
Fix IDE warnings across xchart, xchart-demo, and xchart-site
2 parents ab019d3 + ff2b250 commit e7c7bf2

63 files changed

Lines changed: 216 additions & 235 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

xchart-demo/src/main/java/org/knowm/xchart/demo/ChartInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
public final class ChartInfo {
66

77
private final String exampleChartName;
8-
private final ExampleChart exampleChart;
8+
private final ExampleChart<?> exampleChart;
99

1010
/**
1111
* Constructor
1212
*
1313
* @param exampleChartName
1414
* @param exampleChart
1515
*/
16-
public ChartInfo(String exampleChartName, ExampleChart exampleChart) {
16+
public ChartInfo(String exampleChartName, ExampleChart<?> exampleChart) {
1717

1818
this.exampleChartName = exampleChartName;
1919
this.exampleChart = exampleChart;
@@ -24,7 +24,7 @@ public String getExampleChartName() {
2424
return exampleChartName;
2525
}
2626

27-
public ExampleChart getExampleChart() {
27+
public ExampleChart<?> getExampleChart() {
2828

2929
return exampleChart;
3030
}

xchart-demo/src/main/java/org/knowm/xchart/demo/ChartStylePanel.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,22 @@ public static final class EditableProperty {
7878
ChartStylePanel csp;
7979
Object additionalParameter;
8080

81-
static HashMap<Class, TableCellEditor> editorMap;
82-
static Class[] assignableClasses = {
81+
static HashMap<Class<?>, TableCellEditor> editorMap;
82+
static Class<?>[] assignableClasses = {
8383
Theme.class, BasicStroke.class, Marker.class, TimeZone.class
8484
};
8585

8686
static {
87-
editorMap = new HashMap<Class, TableCellEditor>();
87+
editorMap = new HashMap<>();
8888
{
89-
JComboBox comboBox = new JComboBox(new Boolean[] {Boolean.TRUE, Boolean.FALSE});
89+
JComboBox<Boolean> comboBox = new JComboBox<>(new Boolean[] {Boolean.TRUE, Boolean.FALSE});
9090
TableCellEditor cellEditor = new DefaultCellEditor(comboBox);
9191
editorMap.put(Boolean.class, cellEditor);
9292
editorMap.put(Boolean.TYPE, cellEditor);
9393
}
9494

9595
{
96-
Class[][] clsArr = {
96+
Class<?>[][] clsArr = {
9797
{int.class, Integer.class},
9898
{byte.class, Byte.class},
9999
{short.class, Short.class},
@@ -103,17 +103,17 @@ public static final class EditableProperty {
103103
{String.class, String.class}
104104
};
105105

106-
for (Class[] classes : clsArr) {
106+
for (Class<?>[] classes : clsArr) {
107107
GenericEditorWithClass editor = new GenericEditorWithClass(classes[1]);
108-
for (Class class1 : classes) {
108+
for (Class<?> class1 : classes) {
109109
editorMap.put(class1, editor);
110110
}
111111
}
112112
}
113113

114114
{
115-
JComboBox comboBox =
116-
new JComboBox(new Theme[] {new XChartTheme(), new GGPlot2Theme(), new MatlabTheme()});
115+
JComboBox<Theme> comboBox =
116+
new JComboBox<>(new Theme[] {new XChartTheme(), new GGPlot2Theme(), new MatlabTheme()});
117117
editorMap.put(Theme.class, new DefaultCellEditor(comboBox));
118118
}
119119

@@ -125,7 +125,7 @@ public static final class EditableProperty {
125125
new LabelValue("DASH_DASH", SeriesLines.DASH_DASH),
126126
new LabelValue("DASH_DOT", SeriesLines.DASH_DOT)
127127
};
128-
JComboBox comboBox = new JComboBox(values);
128+
JComboBox<LabelValue> comboBox = new JComboBox<>(values);
129129
editorMap.put(BasicStroke.class, new DefaultCellEditor(comboBox));
130130
}
131131
{
@@ -156,13 +156,13 @@ public static final class EditableProperty {
156156
new LabelValue("GGPlot2 Tick Marks", new BasicStroke(1.5f)), //
157157
new LabelValue("Matlab Tick Marks", new BasicStroke(.5f)), //
158158
};
159-
JComboBox comboBox = new JComboBox(values);
159+
JComboBox<LabelValue> comboBox = new JComboBox<>(values);
160160
editorMap.put(Stroke.class, new DefaultCellEditor(comboBox));
161161
}
162162

163163
{
164164
Marker[] seriesMarkers = new BaseSeriesMarkers().getSeriesMarkers();
165-
JComboBox comboBox = new JComboBox(seriesMarkers);
165+
JComboBox<Marker> comboBox = new JComboBox<>(seriesMarkers);
166166
editorMap.put(Marker.class, new DefaultCellEditor(comboBox));
167167
}
168168

@@ -178,7 +178,7 @@ public static final class EditableProperty {
178178
Locale.GERMAN,
179179
Locale.forLanguageTag("tr-TR")
180180
};
181-
JComboBox comboBox = new JComboBox(values);
181+
JComboBox<Locale> comboBox = new JComboBox<>(values);
182182
editorMap.put(Locale.class, new DefaultCellEditor(comboBox));
183183
}
184184

@@ -188,7 +188,7 @@ public static final class EditableProperty {
188188
for (int i = 0; i < values.length; i++) {
189189
values[i] = TimeZone.getTimeZone(availableIDs[i]);
190190
}
191-
JComboBox comboBox = new JComboBox(values);
191+
JComboBox<TimeZone> comboBox = new JComboBox<>(values);
192192
editorMap.put(TimeZone.class, new DefaultCellEditor(comboBox));
193193
}
194194
}
@@ -220,19 +220,19 @@ private void initEditor() {
220220

221221
try {
222222
Object val = getValue();
223-
Class cls = val == null ? getValueClass() : val.getClass();
223+
Class<?> cls = val == null ? getValueClass() : val.getClass();
224224
cellEditor = editorMap.get(cls);
225225
if (cellEditor != null) {
226226
return;
227227
}
228228

229229
if (cls.isEnum()) {
230-
JComboBox comboBox = new JComboBox(cls.getEnumConstants());
230+
JComboBox<Object> comboBox = new JComboBox<>(cls.getEnumConstants());
231231
cellEditor = new DefaultCellEditor(comboBox);
232232
return;
233233
}
234234

235-
for (Class class1 : assignableClasses) {
235+
for (Class<?> class1 : assignableClasses) {
236236
if (class1.isAssignableFrom(cls)) {
237237
cellEditor = editorMap.get(class1);
238238
return;
@@ -316,7 +316,7 @@ public TableCellEditor getTableCellEditor() {
316316
return cellEditor;
317317
}
318318

319-
public Class getValueClass() {
319+
public Class<?> getValueClass() {
320320

321321
if (readMethod == null) {
322322
// obj is array
@@ -354,11 +354,11 @@ public Component getTableCellEditorComponent(
354354

355355
static class GenericEditorWithClass extends DefaultCellEditor {
356356

357-
Class[] argTypes = new Class[] {String.class};
358-
java.lang.reflect.Constructor constructor;
357+
Class<?>[] argTypes = new Class<?>[] {String.class};
358+
java.lang.reflect.Constructor<?> constructor;
359359
Object value;
360360

361-
public GenericEditorWithClass(Class cls) {
361+
public GenericEditorWithClass(Class<?> cls) {
362362
super(new JTextField());
363363
getComponent().setName("Table.editor");
364364
try {
@@ -409,19 +409,19 @@ public Object getCellEditorValue() {
409409

410410
public static class EditorTableModel extends DefaultTableModel {
411411
ArrayList<EditableProperty> properties;
412-
Chart chart;
412+
Chart<?, ?> chart;
413413
int rowCount;
414414
ChartStylePanel csp;
415415

416-
public EditorTableModel(ChartStylePanel csp, Chart chart) {
416+
public EditorTableModel(ChartStylePanel csp, Chart<?, ?> chart) {
417417
this.csp = csp;
418418
addColumn("Name");
419419
addColumn("Type");
420420
addColumn("Value");
421421
changeChart(chart);
422422
}
423423

424-
public void changeChart(Chart chart) {
424+
public void changeChart(Chart<?, ?> chart) {
425425

426426
this.chart = chart;
427427
properties = getProperties(csp, chart);
@@ -487,7 +487,7 @@ public int getRowCount() {
487487
public static class EditorTable extends JTable {
488488
EditorTableModel tableModel;
489489

490-
public EditorTable(ChartStylePanel csp, Chart chart) {
490+
public EditorTable(ChartStylePanel csp, Chart<?, ?> chart) {
491491
tableModel = new EditorTableModel(csp, chart);
492492

493493
setModel(tableModel);
@@ -503,7 +503,7 @@ public EditorTable(ChartStylePanel csp, Chart chart) {
503503
setAutoCreateRowSorter(true);
504504
}
505505

506-
public void changeChart(Chart chart) {
506+
public void changeChart(Chart<?, ?> chart) {
507507

508508
tableModel.changeChart(chart);
509509
}
@@ -517,7 +517,7 @@ public TableCellEditor getCellEditor(int row, int column) {
517517
if (editor != null) {
518518
return editor;
519519
}
520-
Class valueClass = se.getValueClass();
520+
Class<?> valueClass = se.getValueClass();
521521
TableCellEditor defaultEditor = getDefaultEditor(valueClass);
522522

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

528528
private EditorTable table;
529-
private XChartPanel chartPanel;
529+
private XChartPanel<?> chartPanel;
530530

531-
public ChartStylePanel(XChartPanel chartPanel) {
531+
public ChartStylePanel(XChartPanel<?> chartPanel) {
532532
this.chartPanel = chartPanel;
533533
table = new EditorTable(this, chartPanel.getChart());
534534
JScrollPane scrollpane = new JScrollPane(table);
@@ -538,7 +538,7 @@ public ChartStylePanel(XChartPanel chartPanel) {
538538
setPreferredSize(new Dimension(800, 600));
539539
}
540540

541-
public void changeChart(XChartPanel chartPanel) {
541+
public void changeChart(XChartPanel<?> chartPanel) {
542542

543543
this.chartPanel = chartPanel;
544544
table.changeChart(chartPanel.getChart());
@@ -575,7 +575,7 @@ protected void repaintChart() {
575575
"YAxisAlignment",
576576
"YAxisGroupPosition"));
577577

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

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

588-
Map<String, Series> seriesMap = chart.getSeriesMap();
588+
Map<String, ? extends Series> seriesMap = chart.getSeriesMap();
589589
int ind = 0;
590590
TreeSet<Integer> seriesIndSet = new TreeSet<Integer>();
591-
for (Entry<String, Series> e : seriesMap.entrySet()) {
591+
for (Entry<String, ? extends Series> e : seriesMap.entrySet()) {
592592
Series series = e.getValue();
593593
list2 = getObjectProperties(csp, series, "series[" + e.getKey() + "].", skipSet);
594594
list.addAll(list2);

xchart-demo/src/main/java/org/knowm/xchart/demo/XChartDemo.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class XChartDemo extends JPanel implements TreeSelectionListener {
3333
private final JTree tree;
3434

3535
/** The panel for chart */
36-
protected XChartPanel chartPanel;
36+
protected XChartPanel<?> chartPanel;
3737

3838
Timer timer = new Timer();
3939

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

5959
// Create Chart Panel
60-
chartPanel = new XChartPanel(new AreaChart01().getChart());
60+
chartPanel = new XChartPanel<>(new AreaChart01().getChart());
6161

6262
// Add the scroll panes to a split pane.
6363
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
@@ -86,9 +86,8 @@ public void valueChanged(TreeSelectionEvent e) {
8686
if (node.isLeaf()) {
8787
ChartInfo chartInfo = (ChartInfo) nodeInfo;
8888
// displayURL(chartInfo.bookURL);
89-
ExampleChart exampleChart = chartInfo.getExampleChart();
90-
chartPanel = new XChartPanel(exampleChart.getChart());
91-
exampleChart.customizePanel(chartPanel);
89+
ExampleChart<?> exampleChart = chartInfo.getExampleChart();
90+
updateChartPanel(exampleChart);
9291
splitPane.setBottomComponent(chartPanel);
9392

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

115+
private void updateChartPanel(ExampleChart<?> exampleChart) {
116+
doUpdateChartPanel(exampleChart);
117+
}
118+
119+
private <C extends Chart<?, ?>> void doUpdateChartPanel(ExampleChart<C> exampleChart) {
120+
XChartPanel<C> panel = new XChartPanel<>(exampleChart.getChart());
121+
exampleChart.customizePanel(panel);
122+
chartPanel = panel;
123+
}
124+
116125
/**
117126
* Create the tree
118127
*
@@ -127,7 +136,7 @@ private void createNodes(DefaultMutableTreeNode top) {
127136

128137
List<ExampleChart<Chart<Styler, Series>>> exampleList = DemoChartsUtil.getAllDemoCharts();
129138
String categoryName = "";
130-
for (ExampleChart exampleChart : exampleList) {
139+
for (ExampleChart<Chart<Styler, Series>> exampleChart : exampleList) {
131140
String name = exampleChart.getClass().getSimpleName();
132141
name = name.substring(0, name.indexOf("Chart"));
133142
if (!categoryName.equals(name)) {

xchart-demo/src/main/java/org/knowm/xchart/demo/XChartStyleDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public XChartStyleDemo() {
2121

2222
@Override
2323
public void valueChanged(TreeSelectionEvent e) {
24-
XChartPanel oldChartPanel = chartPanel;
24+
XChartPanel<?> oldChartPanel = chartPanel;
2525
super.valueChanged(e);
2626
if (chartPanel != oldChartPanel) {
2727
stylePanel.changeChart(chartPanel);

xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart07.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.knowm.xchart.ToolTipType;
1111
import org.knowm.xchart.XChartPanel;
1212
import org.knowm.xchart.demo.charts.ExampleChart;
13-
import org.knowm.xchart.style.Styler;
1413
import org.knowm.xchart.style.Styler.LegendPosition;
1514

1615
/**

xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart11.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.Random;
66
import org.knowm.xchart.CategoryChart;
77
import org.knowm.xchart.CategoryChartBuilder;
8-
import org.knowm.xchart.CategorySeries;
98
import org.knowm.xchart.SwingWrapper;
109
import org.knowm.xchart.demo.charts.ExampleChart;
1110

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

7473
// Series
75-
CategorySeries series1 =
76-
chart.addSeries("series1", getLinearValues(0, 200, 6), getRandomValues(10, 50, 6));
77-
CategorySeries series2 =
78-
chart.addSeries("series2", getLinearValues(0, 200, 6), getRandomValues(10, 50, 6));
74+
chart.addSeries("series1", getLinearValues(0, 200, 6), getRandomValues(10, 50, 6));
75+
chart.addSeries("series2", getLinearValues(0, 200, 6), getRandomValues(10, 50, 6));
7976

8077
return chart;
8178
}

xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart12.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public CategoryChart getChart() {
8585
}
8686

8787
// Series
88-
CategorySeries staked1 = chart.addSeries("Period 1", months, period1Values);
89-
CategorySeries staked2 = chart.addSeries("Period 2", months, period2Values);
90-
CategorySeries staked3 = chart.addSeries("Period 3", months, period3Values);
88+
chart.addSeries("Period 1", months, period1Values);
89+
chart.addSeries("Period 2", months, period2Values);
90+
chart.addSeries("Period 3", months, period3Values);
9191
CategorySeries overlappedLine = chart.addSeries("Average", months, averageValues);
9292
overlappedLine.setOverlapped(true);
9393
overlappedLine.setChartCategorySeriesRenderStyle(CategorySeries.CategorySeriesRenderStyle.Line);

xchart-demo/src/main/java/org/knowm/xchart/demo/charts/dial/DialChart02.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.awt.Font;
66
import org.knowm.xchart.DialChart;
77
import org.knowm.xchart.DialChartBuilder;
8-
import org.knowm.xchart.DialSeries;
98
import org.knowm.xchart.SwingWrapper;
109
import org.knowm.xchart.XChartPanel;
1110
import org.knowm.xchart.demo.charts.ExampleChart;
@@ -46,7 +45,7 @@ public DialChart getChart() {
4645
.build();
4746

4847
// Series
49-
DialSeries series = chart.addSeries("Rate", 0.55, "55 %");
48+
chart.addSeries("Rate", 0.55, "55 %");
5049

5150
chart.getStyler().setLegendVisible(true);
5251
chart.getStyler().setArcAngle(330);

xchart-demo/src/main/java/org/knowm/xchart/demo/charts/line/LineChart08.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public XYChart getChart() {
6262
// chart.getStyler().setXAxisLabelRotation(0);
6363

6464
// Series
65-
XYSeries series = chart.addSeries("10^x", xData, yData);
65+
chart.addSeries("10^x", xData, yData);
6666

6767
return chart;
6868
}

0 commit comments

Comments
 (0)