5677 attempts to reduce cyclomatic complexity

This commit is contained in:
William Schaefer 2019-11-06 12:00:01 -05:00
parent 495682ca79
commit 5efe34235c
2 changed files with 11 additions and 12 deletions

View File

@ -175,9 +175,9 @@ public class ImageThumbnailPanel extends javax.swing.JPanel implements ListCellR
public String getToolTipText(MouseEvent event) { public String getToolTipText(MouseEvent event) {
if (event != null) { if (event != null) {
//gets tooltip of internal panel item mouse is over //gets tooltip of internal panel item mouse is over
Point p = event.getPoint(); Point point = event.getPoint();
for (Component comp : getComponents()) { for (Component comp : getComponents()) {
if (comp instanceof JComponent && p.x >= comp.getX() && p.x <= comp.getX() + ICON_SIZE && p.y >= comp.getY() && p.y <= comp.getY() + ICON_SIZE) { if (isPointInComponent(comp, point)) {
String toolTip = ((JComponent) comp).getToolTipText(); String toolTip = ((JComponent) comp).getToolTipText();
if (toolTip == null || toolTip.isEmpty()) { if (toolTip == null || toolTip.isEmpty()) {
return null; return null;
@ -190,4 +190,8 @@ public class ImageThumbnailPanel extends javax.swing.JPanel implements ListCellR
return null; return null;
} }
private boolean isPointInComponent(Component comp, Point point) {
return comp instanceof JComponent && point.x >= comp.getX() && point.x <= comp.getX() + ICON_SIZE && point.y >= comp.getY() && point.y <= comp.getY() + ICON_SIZE;
}
} }

View File

@ -209,13 +209,8 @@ final class VideoThumbnailPanel extends javax.swing.JPanel implements ListCellRe
//gets tooltip of internal panel item mouse is over //gets tooltip of internal panel item mouse is over
Point p = event.getPoint(); Point p = event.getPoint();
for (Component comp : getComponents()) { for (Component comp : getComponents()) {
if (comp instanceof JComponent && p.x >= comp.getX() && p.x <= comp.getX() + ICON_SIZE && p.y >= comp.getY() && p.y <= comp.getY() + ICON_SIZE) { if (comp instanceof JComponent && p.x >= comp.getX() && p.x <= comp.getX() + ICON_SIZE && p.y >= comp.getY() && p.y <= comp.getY() + ICON_SIZE && ((JComponent) comp).getToolTipText() != null && !((JComponent) comp).getToolTipText().isEmpty()) {
String toolTip = ((JComponent) comp).getToolTipText(); return ((JComponent) comp).getToolTipText();
if (toolTip == null || toolTip.isEmpty()) {
return null;
} else {
return toolTip;
}
} }
} }
} }