From 482db824864b9c681f62e913db8f3aeb7164a857 Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Mon, 26 Sep 2016 20:35:01 +0200 Subject: [PATCH] enhance toggle behaviour --- src/main/java/net/sf/jabref/gui/BasePanel.java | 4 ++-- src/main/java/net/sf/jabref/gui/JabRefFrame.java | 10 +++++++--- src/main/java/net/sf/jabref/gui/SidePaneManager.java | 4 +++- src/main/java/net/sf/jabref/gui/actions/Actions.java | 1 - .../java/net/sf/jabref/gui/groups/GroupSelector.java | 8 +++++++- .../sf/jabref/gui/importer/fetcher/GeneralFetcher.java | 10 ++++++---- .../net/sf/jabref/gui/openoffice/OpenOfficePanel.java | 7 ++----- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 0e5a7002d3a8..77437ab2a92c 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -400,7 +400,7 @@ private void setupActions() { // The action for toggling the groups interface actions.put(Actions.TOGGLE_GROUPS, (BaseAction) () -> { sidePaneManager.toggle("groups"); - frame.groupToggle.setSelected(sidePaneManager.isComponentVisible("groups")); + frame.getGroupToggle().setSelected(sidePaneManager.isComponentVisible("groups")); }); actions.put(FindUnlinkedFilesDialog.ACTION_COMMAND, (BaseAction) () -> { @@ -1217,7 +1217,7 @@ public void listen(EntryAddedEvent addedEntryEvent) { } // Automatically add new entry to the selected group (or set of groups) - if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP) && frame.groupToggle.isSelected()) { + if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP) && frame.getGroupToggle().isSelected()) { final List entries = Collections.singletonList(addedEntryEvent.getBibEntry()); final TreePath[] selection = frame.getGroupSelector().getGroupsTree().getSelectionPaths(); if (selection != null) { diff --git a/src/main/java/net/sf/jabref/gui/JabRefFrame.java b/src/main/java/net/sf/jabref/gui/JabRefFrame.java index 79f16202ae32..8a4d6d5e58d4 100644 --- a/src/main/java/net/sf/jabref/gui/JabRefFrame.java +++ b/src/main/java/net/sf/jabref/gui/JabRefFrame.java @@ -191,7 +191,7 @@ public class JabRefFrame extends JFrame implements OutputPrinter { /* References to the toggle buttons in the toolbar */ // the groups interface - public JToggleButton groupToggle; + private JToggleButton groupToggle; private JToggleButton previewToggle; private JToggleButton fetcherToggle; @@ -2378,8 +2378,12 @@ public GroupSelector getGroupSelector() { return groupSelector; } - public void setFetcherToggle(boolean enabled) { - fetcherToggle.setSelected(enabled); + public JToggleButton getFetcherToggle() { + return fetcherToggle; + } + + public JToggleButton getGroupToggle() { + return groupToggle; } public void setPreviewToggle(boolean enabled) { diff --git a/src/main/java/net/sf/jabref/gui/SidePaneManager.java b/src/main/java/net/sf/jabref/gui/SidePaneManager.java index 7e3febe55c48..3af43e880d03 100644 --- a/src/main/java/net/sf/jabref/gui/SidePaneManager.java +++ b/src/main/java/net/sf/jabref/gui/SidePaneManager.java @@ -68,7 +68,7 @@ public synchronized boolean isComponentVisible(String name) { } public synchronized void toggle(String name) { - if (isComponentVisible(name)) { + if (isComponentVisible(name) && Globals.getFocusListener().getFocused() == components.get(name)) { hide(name); } else { show(name); @@ -114,6 +114,8 @@ private synchronized void show(SidePaneComponent component) { updateView(); component.componentOpening(); } + Globals.getFocusListener().setFocused(component); + component.grabFocus(); } public synchronized SidePaneComponent getComponent(String name) { diff --git a/src/main/java/net/sf/jabref/gui/actions/Actions.java b/src/main/java/net/sf/jabref/gui/actions/Actions.java index 58c9e70a3f07..6013786b746b 100644 --- a/src/main/java/net/sf/jabref/gui/actions/Actions.java +++ b/src/main/java/net/sf/jabref/gui/actions/Actions.java @@ -60,7 +60,6 @@ public class Actions { public static final String TOGGLE_HIGHLIGHTS_GROUPS_MATCHING_DISABLE = "toggleHighlightGroupsMatchingDisable"; public static final String TOGGLE_GROUPS = "toggleGroups"; public static final String TOGGLE_PREVIEW = "togglePreview"; - public static final String TOGGLE_TOOLBAR = "toggleToolbar"; public static final String UNABBREVIATE = "unabbreviate"; public static final String UNDO = "undo"; public static final String UNMARK_ALL = "unmarkAll"; diff --git a/src/main/java/net/sf/jabref/gui/groups/GroupSelector.java b/src/main/java/net/sf/jabref/gui/groups/GroupSelector.java index 957d4c08e767..1eed8341fe32 100644 --- a/src/main/java/net/sf/jabref/gui/groups/GroupSelector.java +++ b/src/main/java/net/sf/jabref/gui/groups/GroupSelector.java @@ -711,7 +711,7 @@ public void componentClosing() { if (panel != null) {// panel may be null if no file is open any more panel.getMainTable().getTableModel().updateGroupingState(MainTableDataModel.DisplayOption.DISABLED); } - frame.groupToggle.setSelected(false); + frame.getGroupToggle().setSelected(false); } private void setGroups(GroupTreeNode groupsRoot) { @@ -1269,4 +1269,10 @@ public GroupsTree getGroupsTree() { public void listen(GroupUpdatedEvent updateEvent) { setGroups(updateEvent.getMetaData().getGroups().orElse(null)); } + + @Override + public void grabFocus() { + groupsTree.grabFocus(); + } + } diff --git a/src/main/java/net/sf/jabref/gui/importer/fetcher/GeneralFetcher.java b/src/main/java/net/sf/jabref/gui/importer/fetcher/GeneralFetcher.java index 5d95de989268..581c9d146c6c 100644 --- a/src/main/java/net/sf/jabref/gui/importer/fetcher/GeneralFetcher.java +++ b/src/main/java/net/sf/jabref/gui/importer/fetcher/GeneralFetcher.java @@ -244,18 +244,20 @@ public void actionPerformed(ActionEvent e) { if (frame.getTabbedPane().getTabCount() > 0) { sidePaneManager.toggle(GeneralFetcher.this.getTitle()); - if (sidePaneManager.isComponentVisible(GeneralFetcher.this.getTitle())) { - getTextField().requestFocus(); - } + frame.getFetcherToggle().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.this.getTitle())); } } } + @Override + public void grabFocus() { + getTextField().grabFocus(); + } @Override public void componentClosing() { super.componentClosing(); - frame.setFetcherToggle(false); + frame.getFetcherToggle().setSelected(false); Globals.prefs.putBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE, Boolean.FALSE); } diff --git a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java index 30746dab9f95..76a9e1de8078 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java @@ -143,10 +143,6 @@ public static OpenOfficePanel getInstance() { return OpenOfficePanel.instance; } - public SidePaneComponent getSidePaneComponent() { - return comp; - } - public void init(JabRefFrame jabRefFrame, SidePaneManager spManager) { this.frame = jabRefFrame; this.manager = spManager; @@ -161,7 +157,7 @@ public JMenuItem getMenuItem() { } JMenuItem item = new JMenuItem(Localization.lang("OpenOffice/LibreOffice connection"), IconTheme.getImage("openoffice")); - item.addActionListener(event -> manager.show(getName())); + item.addActionListener(event -> manager.toggle(getName())); item.setAccelerator(Globals.getKeyPrefs().getKey(KeyBinding.OPEN_OPEN_OFFICE_LIBRE_OFFICE_CONNECTION)); return item; } @@ -817,6 +813,7 @@ private class OOPanel extends SidePaneComponent { public OOPanel(SidePaneManager sidePaneManager, Icon url, String s, OpenOfficePanel panel) { super(sidePaneManager, url, s); openOfficePanel = panel; + sidePaneManager.register(getName(), this); } @Override