code cleanup
authorNiki Roo <niki@nikiroo.be>
Mon, 27 Apr 2020 20:28:22 +0000 (22:28 +0200)
committerNiki Roo <niki@nikiroo.be>
Mon, 27 Apr 2020 20:28:22 +0000 (22:28 +0200)
src/be/nikiroo/fanfix_swing/gui/BrowserPanel.java
src/be/nikiroo/fanfix_swing/gui/BrowserTab.java

index 2e48398b470e01a9bb76ad1b89d975f0bc160921..f0e77c95031a7986d8ae1e97a1ba67b7315c91e9 100644 (file)
@@ -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<String> 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());
        }
 
        /**
index d453bdef25ef04cba470a29b7d7ede20adba8446..a55a2df8a41930612c81838f0d8dfae32cd99487 100644 (file)
@@ -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<String> selectedElements = this.selectedElements;
+               if (selectedElements != null && !selectedElements.isEmpty()) {
+                       return selectedElements.get(0);
+               }
+
+               return null;
+       }
+
        public int getTotalCount() {
                return totalCount;
        }