From: Niki Roo Date: Mon, 27 Apr 2020 20:28:22 +0000 (+0200) Subject: code cleanup X-Git-Tag: fanfix-swing-1.0.0~3 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=bceea0a693c2551dc1efc7307df80977a50ed8dd;p=fanfix-swing.git code cleanup --- diff --git a/src/be/nikiroo/fanfix_swing/gui/BrowserPanel.java b/src/be/nikiroo/fanfix_swing/gui/BrowserPanel.java index 2e48398b..f0e77c95 100644 --- a/src/be/nikiroo/fanfix_swing/gui/BrowserPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/BrowserPanel.java @@ -1,7 +1,6 @@ package be.nikiroo.fanfix_swing.gui; import java.awt.BorderLayout; -import java.awt.Component; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -164,28 +163,19 @@ public class BrowserPanel extends ListenerPanel { * @return the {@link BookInfo} to highlight, cannot be NULL */ public BookInfo getHighlight() { - String selected1 = null; - Component selectedTab = tabs.getSelectedComponent(); - if (selectedTab instanceof BrowserTab) { - @SuppressWarnings({ "unchecked", "rawtypes" }) - List selectedAll = ((BrowserTab) selectedTab) - .getSelectedElements(); - if (!selectedAll.isEmpty()) { - selected1 = selectedAll.get(0); - } - } - BasicLibrary lib = Instance.getInstance().getLibrary(); if (tabs.getSelectedComponent() == sourceTab) { - return BookInfo.fromSource(lib, selected1); + return BookInfo.fromSource(lib, + sourceTab.getFirstSelectedElement()); } else if (tabs.getSelectedComponent() == authorTab) { - return BookInfo.fromAuthor(lib, selected1); + return BookInfo.fromAuthor(lib, + authorTab.getFirstSelectedElement()); } else if (tabs.getSelectedComponent() == tagsTab) { - return BookInfo.fromTag(lib, selected1); + return BookInfo.fromTag(lib, tagsTab.getFirstSelectedElement()); } // ...what? - return BookInfo.fromSource(lib, selected1); + return BookInfo.fromSource(lib, sourceTab.getFirstSelectedElement()); } /** diff --git a/src/be/nikiroo/fanfix_swing/gui/BrowserTab.java b/src/be/nikiroo/fanfix_swing/gui/BrowserTab.java index d453bdef..a55a2df8 100644 --- a/src/be/nikiroo/fanfix_swing/gui/BrowserTab.java +++ b/src/be/nikiroo/fanfix_swing/gui/BrowserTab.java @@ -168,6 +168,21 @@ public class BrowserTab extends ListenerPanel { return selectedElements; } + /** + * The first selected element if some are selected, NULL if none is + * selected. + * + * @return the first selected element or NULL + */ + public String getFirstSelectedElement() { + List selectedElements = this.selectedElements; + if (selectedElements != null && !selectedElements.isEmpty()) { + return selectedElements.get(0); + } + + return null; + } + public int getTotalCount() { return totalCount; }