+ setJMenuBar(bar);
+ }
+
+ // "" = [unknown]
+ private void populateMenuSA(JMenu menu,
+ Map<String, List<String>> groupedValues, boolean type) {
+
+ // "All" and "Listing" special items first
+ JMenuItem item = new JMenuItem(
+ GuiReader.trans(StringIdGui.MENU_XXX_ALL_GROUPED));
+ item.addActionListener(getActionOpenList(type, false));
+ menu.add(item);
+ item = new JMenuItem(GuiReader.trans(StringIdGui.MENU_XXX_ALL_LISTING));
+ item.addActionListener(getActionOpenList(type, true));
+ menu.add(item);
+
+ menu.addSeparator();
+
+ for (final String value : groupedValues.keySet()) {
+ List<String> list = groupedValues.get(value);
+ if (type && list.size() == 1 && list.get(0).isEmpty()) {
+ // leaf item source/type
+ item = new JMenuItem(
+ value.isEmpty() ? GuiReader
+ .trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
+ : value);
+ item.addActionListener(getActionOpen(value, type));
+ menu.add(item);
+ } else {
+ JMenu dir;
+ if (!type && groupedValues.size() == 1) {
+ // only one group of authors
+ dir = menu;
+ } else {
+ dir = new JMenu(
+ value.isEmpty() ? GuiReader
+ .trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
+ : value);
+ }
+
+ for (String sub : list) {
+ // " " instead of "" for the visual height
+ String itemName = sub;
+ if (itemName.isEmpty()) {
+ itemName = type ? " " : GuiReader
+ .trans(StringIdGui.MENU_AUTHORS_UNKNOWN);
+ }
+
+ String actualValue = value;
+ if (type) {
+ if (!sub.isEmpty()) {
+ actualValue += "/" + sub;
+ }
+ } else {
+ actualValue = sub;
+ }
+
+ item = new JMenuItem(itemName);
+ item.addActionListener(getActionOpen(actualValue, type));
+ dir.add(item);
+ }
+
+ if (menu != dir) {
+ menu.add(dir);
+ }
+ }
+ }
+ }
+
+ /**
+ * Return an {@link ActionListener} that will set the given source (type) as
+ * the selected/displayed one.
+ *
+ * @param type
+ * the type (source) to select, cannot be NULL
+ *
+ * @return the {@link ActionListener}
+ */
+ private ActionListener getActionOpen(final String source, final boolean type) {
+ return new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ mainPanel.removeBookPanes();
+ mainPanel.addBookPane(source, type);
+ mainPanel.refreshBooks();
+ }
+ };
+ }
+
+ private ActionListener getActionOpenList(final boolean type,
+ final boolean listMode) {
+ return new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent ae) {
+ mainPanel.removeBookPanes();
+ try {
+ mainPanel.addBookPane(type, listMode);
+ } catch (IOException e) {
+ error(e.getLocalizedMessage(), "IOException", e);
+ }
+ mainPanel.refreshBooks();
+ }
+ };