jfreechart
jfreechart copied to clipboard
ChartPanel createPopupMenu and actionPerformed update
Can these methods be updated, combined to use anonymous method creation so the whole chart object isn't passed into each action of the popup menu? This would also help remove the need of having to keep track of the actionCommand as a string lookup. If not then the action performed if-else could be replaced with a switch look-up. The switch would give direct access to the action and save some resource management.
Update for switch
switch (command) {
case PROPERTIES_COMMAND:
doEditChartProperties();
break;
case COPY_COMMAND:
doCopy();
break;
case SAVE_AS_PNG_COMMAND:
try {
doSaveAs();
}
catch (IOException e) {
JOptionPane.showMessageDialog(this, "I/O error occurred.",
localizationResources.getString("Save_as_PNG"),
JOptionPane.WARNING_MESSAGE);
} break;
case SAVE_AS_PNG_SIZE_COMMAND:
try{
final Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
doSaveAs(ss.width, ss.height);
}
catch (IOException e){
JOptionPane.showMessageDialog(ChartPanel.this, "I/O error occurred.",
localizationResources.getString("Save_as_PNG"),
JOptionPane.WARNING_MESSAGE);
} break;
case SAVE_AS_SVG_COMMAND:
try {
saveAsSVG(null);
} catch (IOException e) {
JOptionPane.showMessageDialog(this, "I/O error occurred.",
localizationResources.getString("Save_as_SVG"),
JOptionPane.WARNING_MESSAGE);
} break;
case SAVE_AS_PDF_COMMAND:
saveAsPDF(null);
break;
case PRINT_COMMAND:
createChartPrintJob();
break;
case ZOOM_IN_BOTH_COMMAND:
zoomInBoth(screenX, screenY);
break;
case ZOOM_IN_DOMAIN_COMMAND:
zoomInDomain(screenX, screenY);
break;
case ZOOM_IN_RANGE_COMMAND:
zoomInRange(screenX, screenY);
break;
case ZOOM_OUT_BOTH_COMMAND:
zoomOutBoth(screenX, screenY);
break;
case ZOOM_OUT_DOMAIN_COMMAND:
zoomOutDomain(screenX, screenY);
break;
case ZOOM_OUT_RANGE_COMMAND:
zoomOutRange(screenX, screenY);
break;
case ZOOM_RESET_BOTH_COMMAND:
restoreAutoBounds();
break;
case ZOOM_RESET_DOMAIN_COMMAND:
restoreAutoDomainBounds();
break;
case ZOOM_RESET_RANGE_COMMAND:
restoreAutoRangeBounds();
break;
default:
break;
}
This replacement does compile and pass all current tests.