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;
* @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());
}
/**
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;
}