-
complexity issue!!
this method has an overtly high cyclomatic complexity
could you suggest an alternative way of writng dis method?
Code:
public void actionPerformed(ActionEvent actionEvent) {
if ("Refresh".equals(actionEvent.getActionCommand())) {
}
if ("ZoomIn".equals(actionEvent.getActionCommand())) {
//new oom(1.8f);
double zoomInFactor = 1.2f;
zoom(zoomInFactor);
}
if ("ZoomOut".equals(actionEvent.getActionCommand())) {
double zoomOutFactor = 0.8f;
zoom(zoomOutFactor);
}
if ("ZoomFit".equals(actionEvent.getActionCommand())) {
view.fitContent(true);
view.updateView();
}
if ("Zoom100".equals(actionEvent.getActionCommand())) {
// view.focusView(0.1f, new Point(0, 0), true);
double zoomFactor = 1.0f;
view.setZoom(zoomFactor);
view.updateView();
}
if ("Print".equals(actionEvent.getActionCommand())) {
//view.print();
printGraph();
}
if ("Save".equals(actionEvent.getActionCommand())) {
saveGraph();
}
if ("Expand".equals(actionEvent.getActionCommand())) {
isExpanded = true;
isCollapsed = false;
alteringGraphSize();
}
if ("Collapse".equals(actionEvent.getActionCommand())) {
isCollapsed = true;
isExpanded = false;
alteringGraphSize();
}
if ("FullScreen".equals(actionEvent.getActionCommand())) {
graphOnFullScreen();
}
if ("Restore".equals(actionEvent.getActionCommand())) {
restoreScreen();
}
if ("Magnify".equals(actionEvent.getActionCommand())) {
magnifyGraph();
}
if ("Find".equals(actionEvent.getActionCommand())) {
if (searchToolBar.isVisible()) {
searchToolBar.setVisible(false);
} else {
searchToolBar.setVisible(true);
}
}
if ("Advanced Layout".equals(actionEvent.getActionCommand())) {
if (popupAdvancedLayout == null) {
popupAdvancedLayout = new JPopupMenu();
YPackage yPackage = new YPackage(ResourceResolver.getFileResource("layout-modules.xml"));
System.out.println("yPackage = " + yPackage.getName());
createAdvancedLayoutMenu(yPackage, null, popupAdvancedLayout);
// popAdvancedLayout.add(createAdvancedLayoutMenu(yPackage, null, popAdvancedLayout));
}
popupAdvancedLayout.show(view, btnAdvancedLayout.getLocation().x, btnAdvancedLayout.getLocation().y);
}
}
-
Just looking at your code, seems to me you can use switch-case to in this case. No need to lookup actionEvent.getActionCommand() multiple times. At the same time, I didn't see any common task doing in each event.
So the best thing I can recommended for you is take a piece of paper and re-design your logic here. Try to keep it as much as simple and common goals in the same level.
-
This is one reason many recommend that you don't add the same ActionListener to multiple buttons -- to avoid a "switch-board" type actionPerformed method. Better perhaps is to create different ActionListener objects each tailored to its own unique group of actions. I've also seen the Mediator design pattern used here.
-
-
Quote:
Originally Posted by
deepa8400
ok....wud try.
Ya give a try and if you can show it here. We can comment on that.
At the same time, please not that Fubarable edit your code, actually formated, in very first post. Formatted codes are easy to read actually. So please try to use code tags next time.