From 0de22f15c0742ffeadf09007feb75c4bd3bc0251 Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Wed, 28 Sep 2016 13:47:03 +0200 Subject: [PATCH 1/7] enhance toggle behaviour --- .../net/sf/jabref/collab/FileUpdatePanel.java | 8 ++- .../java/net/sf/jabref/gui/BasePanel.java | 16 ++--- .../java/net/sf/jabref/gui/JabRefFrame.java | 51 +++++-------- .../net/sf/jabref/gui/SidePaneComponent.java | 51 ++++++++++++- .../net/sf/jabref/gui/SidePaneManager.java | 40 +++++++---- .../net/sf/jabref/gui/actions/Actions.java | 1 - .../gui/exporter/SaveDatabaseAction.java | 5 +- .../sf/jabref/gui/groups/GroupSelector.java | 29 +++++++- .../gui/importer/fetcher/GeneralFetcher.java | 56 +++++---------- .../gui/openoffice/OpenOfficePanel.java | 71 ++++++++----------- .../importer/fetcher/GeneralFetcherTest.java | 2 +- 11 files changed, 184 insertions(+), 146 deletions(-) diff --git a/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java b/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java index 2d2ce422f6f..69ffb30d1f7 100644 --- a/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java +++ b/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java @@ -17,8 +17,7 @@ import net.sf.jabref.gui.SidePaneManager; import net.sf.jabref.logic.l10n.Localization; -public class FileUpdatePanel extends SidePaneComponent implements ActionListener, - ChangeScanner.DisplayResultCallback { +public class FileUpdatePanel extends SidePaneComponent implements ActionListener, ChangeScanner.DisplayResultCallback { public static final String NAME = "fileUpdate"; @@ -68,6 +67,11 @@ public void componentClosing() { manager.unregisterComponent(FileUpdatePanel.NAME); } + @Override + public String getSidePaneName() { + return NAME; + } + @Override public int getRescalingWeight() { return 0; diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 0e5a7002d3a..eb5cf6fe430 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -397,12 +397,6 @@ 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")); - }); - actions.put(FindUnlinkedFilesDialog.ACTION_COMMAND, (BaseAction) () -> { final FindUnlinkedFilesDialog dialog = new FindUnlinkedFilesDialog(frame, frame, BasePanel.this); dialog.setLocationRelativeTo(frame); @@ -1217,7 +1211,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.getGroupSelector().getAction().isSelected()) { final List entries = Collections.singletonList(addedEntryEvent.getBibEntry()); final TreePath[] selection = frame.getGroupSelector().getGroupsTree().getSelectionPaths(); if (selection != null) { @@ -2160,7 +2154,7 @@ public void fileUpdated() { } FileUpdatePanel pan = new FileUpdatePanel(BasePanel.this, sidePaneManager, getBibDatabaseContext().getDatabaseFile().orElse(null), scanner); - sidePaneManager.register(FileUpdatePanel.NAME, pan); + sidePaneManager.register(pan); sidePaneManager.show(FileUpdatePanel.NAME); }; @@ -2185,10 +2179,10 @@ public void cleanUp() { } // Check if there is a FileUpdatePanel for this BasePanel being shown. If so, // remove it: - if (sidePaneManager.hasComponent("fileUpdate")) { - FileUpdatePanel fup = (FileUpdatePanel) sidePaneManager.getComponent("fileUpdate"); + if (sidePaneManager.hasComponent(FileUpdatePanel.NAME)) { + FileUpdatePanel fup = (FileUpdatePanel) sidePaneManager.getComponent(FileUpdatePanel.NAME); if (fup.getPanel() == this) { - sidePaneManager.hideComponent("fileUpdate"); + sidePaneManager.hideComponent(FileUpdatePanel.NAME); } } } diff --git a/src/main/java/net/sf/jabref/gui/JabRefFrame.java b/src/main/java/net/sf/jabref/gui/JabRefFrame.java index 79f16202ae3..375b20606d2 100644 --- a/src/main/java/net/sf/jabref/gui/JabRefFrame.java +++ b/src/main/java/net/sf/jabref/gui/JabRefFrame.java @@ -190,11 +190,7 @@ public class JabRefFrame extends JFrame implements OutputPrinter { // for the name and message strings. /* References to the toggle buttons in the toolbar */ - // the groups interface - public JToggleButton groupToggle; private JToggleButton previewToggle; - private JToggleButton fetcherToggle; - private final OpenDatabaseAction open = new OpenDatabaseAction(this, true); private final EditModeAction editModeAction = new EditModeAction(); @@ -351,11 +347,6 @@ public void actionPerformed(ActionEvent e) { } }); - private final Action toggleGroups = enableToggle(new GeneralAction(Actions.TOGGLE_GROUPS, - Localization.menuTitle("Toggle groups interface"), - Localization.lang("Toggle groups interface"), - Globals.getKeyPrefs().getKey(KeyBinding.TOGGLE_GROUPS_INTERFACE), - IconTheme.JabRefIcon.TOGGLE_GROUPS.getIcon())); private final AbstractAction addToGroup = new GeneralAction(Actions.ADD_TO_GROUP, Localization.lang("Add to group") + ELLIPSES); private final AbstractAction removeFromGroup = new GeneralAction(Actions.REMOVE_FROM_GROUP, Localization.lang("Remove from group") + ELLIPSES); @@ -394,8 +385,6 @@ public void actionPerformed(ActionEvent e) { Localization.lang("Will write XMP-metadata to the PDFs linked from selected entries."), Globals.getKeyPrefs().getKey(KeyBinding.WRITE_XMP)); - private JMenuItem optMenuItem; - private final AbstractAction openFolder = new GeneralAction(Actions.OPEN_FOLDER, Localization.menuTitle("Open folder"), Localization.lang("Open folder"), Globals.getKeyPrefs().getKey(KeyBinding.OPEN_FOLDER)); @@ -481,7 +470,7 @@ public void actionPerformed(ActionEvent e) { private PushToApplications pushApplications; private GeneralFetcher generalFetcher; - + private OpenOfficePanel openOfficePanel; private GroupSelector groupSelector; private int previousTabCount = -1; @@ -662,9 +651,10 @@ public void windowClosing(WindowEvent e) { currentBasePanel.getPreviewPanel().updateLayout(); - groupToggle.setSelected(sidePaneManager.isComponentVisible("groups")); + groupSelector.getAction().setSelected(sidePaneManager.isComponentVisible(GroupSelector.NAME)); previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); - fetcherToggle.setSelected(sidePaneManager.isComponentVisible(generalFetcher.getTitle())); + generalFetcher.getAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.NAME)); + openOfficePanel.getAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficePanel.NAME)); Globals.getFocusListener().setFocused(currentBasePanel.getMainTable()); setWindowTitle(); editModeAction.initName(); @@ -724,10 +714,10 @@ private void initSidePane() { sidePaneManager = new SidePaneManager(this); groupSelector = new GroupSelector(this, sidePaneManager); + openOfficePanel = new OpenOfficePanel(this, sidePaneManager); + generalFetcher = new GeneralFetcher(this, sidePaneManager); - generalFetcher = new GeneralFetcher(sidePaneManager, this); - - sidePaneManager.register("groups", groupSelector); + sidePaneManager.register(groupSelector); } /** @@ -1228,12 +1218,12 @@ private void fillMenu() { search.addSeparator(); search.add(new JCheckBoxMenuItem(generalFetcher.getAction())); if (prefs.getBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE)) { - sidePaneManager.register(generalFetcher.getTitle(), generalFetcher); - sidePaneManager.show(generalFetcher.getTitle()); + sidePaneManager.register(generalFetcher); + sidePaneManager.show(GeneralFetcher.NAME); } mb.add(search); - groups.add(new JCheckBoxMenuItem(toggleGroups)); + groups.add(new JCheckBoxMenuItem(groupSelector.getAction())); groups.addSeparator(); groups.add(addToGroup); groups.add(removeFromGroup); @@ -1273,7 +1263,7 @@ private void fillMenu() { view.addSeparator(); view.add(new JCheckBoxMenuItem(toggleToolbar)); view.add(new JCheckBoxMenuItem(enableToggle(generalFetcher.getAction()))); - view.add(new JCheckBoxMenuItem(toggleGroups)); + view.add(new JCheckBoxMenuItem(groupSelector.getAction())); view.add(new JCheckBoxMenuItem(togglePreview)); view.add(getNextPreviewStyleAction()); view.add(getPreviousPreviewStyleAction()); @@ -1314,10 +1304,7 @@ private void fillMenu() { tools.add(newSubDatabaseAction); tools.add(writeXmpAction); - OpenOfficePanel otp = OpenOfficePanel.getInstance(); - otp.init(this, sidePaneManager); - optMenuItem = otp.getMenuItem(); - tools.add(optMenuItem); + tools.add(new JCheckBoxMenuItem(openOfficePanel.getAction())); tools.add(pushExternalButton.getMenuAction()); tools.addSeparator(); tools.add(openFolder); @@ -1475,14 +1462,12 @@ private void createToolBar() { } tlb.addSeparator(); - fetcherToggle = new JToggleButton(generalFetcher.getAction()); - tlb.addJToggleButton(fetcherToggle); + tlb.addJToggleButton(new JToggleButton(generalFetcher.getAction())); previewToggle = new JToggleButton(togglePreview); tlb.addJToggleButton(previewToggle); - groupToggle = new JToggleButton(toggleGroups); - tlb.addJToggleButton(groupToggle); + tlb.addJToggleButton(new JToggleButton(groupSelector.getAction())); tlb.addSeparator(); @@ -1509,8 +1494,8 @@ private void initActions() { openDatabaseOnlyActions.addAll(Arrays.asList(mergeDatabaseAction, newSubDatabaseAction, save, globalSearch, saveAs, saveSelectedAs, saveSelectedAsPlain, editModeAction, undo, redo, cut, deleteEntry, copy, paste, mark, markSpecific, unmark, unmarkAll, rankSubMenu, editEntry, selectAll, copyKey, copyCiteKey, copyKeyAndTitle, copyKeyAndLink, editPreamble, editStrings, - toggleGroups, makeKeyAction, normalSearch, generalFetcher.getAction(), mergeEntries, cleanupEntries, exportToClipboard, replaceAll, - sendAsEmail, downloadFullText, writeXmpAction, optMenuItem, findUnlinkedFiles, addToGroup, removeFromGroup, + groupSelector.getAction(), makeKeyAction, normalSearch, generalFetcher.getAction(), mergeEntries, cleanupEntries, exportToClipboard, replaceAll, + sendAsEmail, downloadFullText, writeXmpAction, openOfficePanel.getAction(), findUnlinkedFiles, addToGroup, removeFromGroup, moveToGroup, autoLinkFile, resolveDuplicateKeys, openUrl, openFolder, openFile, togglePreview, dupliCheck, autoSetFile, newEntryAction, newSpec, customizeAction, plainTextImport, getMassSetField(), getManageKeywords(), pushExternalButton.getMenuAction(), closeDatabaseAction, getNextPreviewStyleAction(), getPreviousPreviewStyleAction(), checkIntegrity, @@ -2378,10 +2363,6 @@ public GroupSelector getGroupSelector() { return groupSelector; } - public void setFetcherToggle(boolean enabled) { - fetcherToggle.setSelected(enabled); - } - public void setPreviewToggle(boolean enabled) { previewToggle.setSelected(enabled); } diff --git a/src/main/java/net/sf/jabref/gui/SidePaneComponent.java b/src/main/java/net/sf/jabref/gui/SidePaneComponent.java index 3ed6190bde5..4b9a953b8d5 100644 --- a/src/main/java/net/sf/jabref/gui/SidePaneComponent.java +++ b/src/main/java/net/sf/jabref/gui/SidePaneComponent.java @@ -3,12 +3,17 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.InputEvent; +import javax.swing.AbstractAction; +import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JToolBar; +import javax.swing.KeyStroke; import org.jdesktop.swingx.JXTitledPanel; import org.jdesktop.swingx.painter.MattePainter; @@ -17,7 +22,7 @@ public abstract class SidePaneComponent extends JXTitledPanel { protected final JButton close = new JButton(IconTheme.JabRefIcon.CLOSE.getSmallIcon()); - private final SidePaneManager manager; + protected final SidePaneManager manager; protected BasePanel panel; @@ -95,9 +100,53 @@ public Dimension getMinimumSize() { return getPreferredSize(); } + public abstract String getSidePaneName(); + /** * Specifies how to distribute extra vertical space between side pane components. * 0: fixed height, 1: fill the remaining space */ public abstract int getRescalingWeight(); + + + public class ToggleAction extends AbstractAction { + + public ToggleAction(String text, String description, KeyStroke key, IconTheme.JabRefIcon icon){ + super(text, icon.getSmallIcon()); + putValue(Action.ACCELERATOR_KEY, key); + putValue(Action.LARGE_ICON_KEY, icon.getIcon()); + putValue(Action.SHORT_DESCRIPTION, description); + } + + public ToggleAction(String text, String description, KeyStroke key, Icon icon){ + super(text, icon); + putValue(Action.ACCELERATOR_KEY, key); + putValue(Action.SHORT_DESCRIPTION, description); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (!manager.hasComponent(getSidePaneName())) { + manager.register(SidePaneComponent.this); + } + + // if clicked by mouse just toggle + if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) { + manager.toggle(getSidePaneName()); + } else { + manager.toggleThreeWay(getSidePaneName()); + } + putValue(Action.SELECTED_KEY, manager.isComponentVisible(getSidePaneName())); + } + + public void setSelected(boolean selected){ + putValue(Action.SELECTED_KEY, selected); + } + + public boolean isSelected() { + return Boolean.TRUE.equals(getValue(Action.SELECTED_KEY)); + } + + } + } diff --git a/src/main/java/net/sf/jabref/gui/SidePaneManager.java b/src/main/java/net/sf/jabref/gui/SidePaneManager.java index 7e3febe55c4..eb4575f72ec 100644 --- a/src/main/java/net/sf/jabref/gui/SidePaneManager.java +++ b/src/main/java/net/sf/jabref/gui/SidePaneManager.java @@ -32,7 +32,6 @@ public class SidePaneManager { private final SidePane sidep; private final Map components = new LinkedHashMap<>(); - private final Map componentNames = new HashMap<>(); private final List visible = new LinkedList<>(); @@ -67,6 +66,11 @@ public synchronized boolean isComponentVisible(String name) { } } + /** + * if panel is visible it will be hidden and the other way around + * + * @param name name of the panel + */ public synchronized void toggle(String name) { if (isComponentVisible(name)) { hide(name); @@ -75,6 +79,21 @@ public synchronized void toggle(String name) { } } + /** + * if panel is hidden it will be shown and focused + * if panel is visible but not focused it will be focused + * ig panel is visible and focused it will be hidden + * + * @param name name of the panel + */ + public synchronized void toggleThreeWay(String name){ + if (isComponentVisible(name) && Globals.getFocusListener().getFocused() == components.get(name)) { + hide(name); + } else { + show(name); + } + } + public synchronized void show(String name) { SidePaneComponent sidePaneComponent = components.get(name); if (sidePaneComponent == null) { @@ -98,9 +117,8 @@ public synchronized void hide(String name) { } } - public synchronized void register(String name, SidePaneComponent comp) { - components.put(name, comp); - componentNames.put(comp, name); + public synchronized void register(SidePaneComponent comp) { + components.put(comp.getSidePaneName(), comp); } private synchronized void show(SidePaneComponent component) { @@ -114,16 +132,14 @@ private synchronized void show(SidePaneComponent component) { updateView(); component.componentOpening(); } + Globals.getFocusListener().setFocused(component); + component.grabFocus(); } public synchronized SidePaneComponent getComponent(String name) { return components.get(name); } - private synchronized String getComponentName(SidePaneComponent comp) { - return componentNames.get(comp); - } - public synchronized void hideComponent(SidePaneComponent comp) { if (visible.contains(comp)) { comp.componentClosing(); @@ -168,8 +184,7 @@ private void updatePreferredPositions() { // Update the preferred positions of all visible components int index = 0; for (SidePaneComponent comp : visible) { - String componentName = getComponentName(comp); - preferredPositions.put(componentName, index); + preferredPositions.put(comp.getSidePaneName(), index); index++; } @@ -195,8 +210,8 @@ public PreferredIndexSort() { @Override public int compare(SidePaneComponent comp1, SidePaneComponent comp2) { - int pos1 = preferredPositions.getOrDefault(getComponentName(comp1), 0); - int pos2 = preferredPositions.getOrDefault(getComponentName(comp2), 0); + int pos1 = preferredPositions.getOrDefault(comp1.getSidePaneName(), 0); + int pos2 = preferredPositions.getOrDefault(comp2.getSidePaneName(), 0); return Integer.valueOf(pos1).compareTo(pos2); } } @@ -231,7 +246,6 @@ public synchronized void moveDown(SidePaneComponent comp) { } public synchronized void unregisterComponent(String name) { - componentNames.remove(components.get(name)); components.remove(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 58c9e70a3f0..6013786b746 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/exporter/SaveDatabaseAction.java b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java index 4e9ae829442..3e90cbf1cfd 100644 --- a/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java @@ -14,6 +14,7 @@ import net.sf.jabref.Globals; import net.sf.jabref.JabRefExecutorService; import net.sf.jabref.collab.ChangeScanner; +import net.sf.jabref.collab.FileUpdatePanel; import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.FileDialog; import net.sf.jabref.gui.JabRefFrame; @@ -381,7 +382,7 @@ private boolean checkExternalModification() { scanner.displayResult(resolved -> { if (resolved) { panel.setUpdatedExternally(false); - SwingUtilities.invokeLater(() -> panel.getSidePaneManager().hide("fileUpdate")); + SwingUtilities.invokeLater(() -> panel.getSidePaneManager().hide(FileUpdatePanel.NAME)); } else { canceled = true; } @@ -399,7 +400,7 @@ private boolean checkExternalModification() { canceled = true; } else { panel.setUpdatedExternally(false); - panel.getSidePaneManager().hide("fileUpdate"); + panel.getSidePaneManager().hide(FileUpdatePanel.NAME); } } } 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 957d4c08e76..e6660af3ba3 100644 --- a/src/main/java/net/sf/jabref/gui/groups/GroupSelector.java +++ b/src/main/java/net/sf/jabref/gui/groups/GroupSelector.java @@ -50,6 +50,7 @@ import net.sf.jabref.gui.SidePaneComponent; import net.sf.jabref.gui.SidePaneManager; import net.sf.jabref.gui.help.HelpAction; +import net.sf.jabref.gui.keyboard.KeyBinding; import net.sf.jabref.gui.maintable.MainTableDataModel; import net.sf.jabref.gui.undo.NamedCompound; import net.sf.jabref.gui.worker.AbstractWorker; @@ -78,6 +79,8 @@ */ public class GroupSelector extends SidePaneComponent implements TreeSelectionListener { + public static final String NAME = "groups"; + private static final Log LOGGER = LogFactory.getLog(GroupSelector.class); private final GroupsTree groupsTree; @@ -125,6 +128,8 @@ public class GroupSelector extends SidePaneComponent implements TreeSelectionLis private final AddToGroupAction moveToGroup = new AddToGroupAction(true); private final RemoveFromGroupAction removeFromGroup = new RemoveFromGroupAction(); + private ToggleAction toggleAction; + /** * The first element for each group defines which field to use for the quicksearch. The next two define the name and @@ -133,6 +138,11 @@ public class GroupSelector extends SidePaneComponent implements TreeSelectionLis public GroupSelector(JabRefFrame frame, SidePaneManager manager) { super(manager, IconTheme.JabRefIcon.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups")); + toggleAction = new ToggleAction(Localization.menuTitle("Toggle groups interface"), + Localization.menuTitle("Toggle groups interface"), + Globals.getKeyPrefs().getKey(KeyBinding.TOGGLE_GROUPS_INTERFACE), + IconTheme.JabRefIcon.TOGGLE_GROUPS); + this.frame = frame; hideNonHits = new JRadioButtonMenuItem(Localization.lang("Hide non-hits"), !Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS)); @@ -701,6 +711,11 @@ public void componentOpening() { valueChanged(null); } + @Override + public String getSidePaneName() { + return NAME; + } + @Override public int getRescalingWeight() { return 1; @@ -711,7 +726,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); + getAction().setSelected(false); } private void setGroups(GroupTreeNode groupsRoot) { @@ -1212,7 +1227,7 @@ public Enumeration getExpandedPaths() { public void setActiveBasePanel(BasePanel panel) { super.setActiveBasePanel(panel); if (panel == null) { // hide groups - frame.getSidePaneManager().hide("groups"); + frame.getSidePaneManager().hide(NAME); return; } MetaData metaData = panel.getBibDatabaseContext().getMetaData(); @@ -1269,4 +1284,14 @@ public GroupsTree getGroupsTree() { public void listen(GroupUpdatedEvent updateEvent) { setGroups(updateEvent.getMetaData().getGroups().orElse(null)); } + + @Override + public void grabFocus() { + groupsTree.grabFocus(); + } + + public ToggleAction getAction() { + return toggleAction; + } + } 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 5d95de98926..2c92bc3351d 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 @@ -12,8 +12,6 @@ import java.util.Comparator; import java.util.List; -import javax.swing.AbstractAction; -import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComboBox; @@ -38,21 +36,21 @@ public class GeneralFetcher extends SidePaneComponent implements ActionListener { + public static final String NAME = "fetcher"; + private final JTextField tf = new JTextField(); private final CardLayout optionsCards = new CardLayout(); private final JPanel optionsPanel = new JPanel(optionsCards); private final JPanel optPanel = new JPanel(new BorderLayout()); - private final SidePaneManager sidePaneManager; - private final Action action; + private final ToggleAction action; private final JabRefFrame frame; private EntryFetcher activeFetcher; - public GeneralFetcher(SidePaneManager p0, JabRefFrame frame) { - super(p0, IconTheme.JabRefIcon.WWW.getSmallIcon(), Localization.lang("Web search")); - this.sidePaneManager = p0; + public GeneralFetcher(JabRefFrame frame, SidePaneManager sidePaneManager) { + super(sidePaneManager, IconTheme.JabRefIcon.WWW.getSmallIcon(), Localization.lang("Web search")); this.frame = frame; List fetchers = new EntryFetchers(Globals.journalAbbreviationLoader).getEntryFetchers(); EntryFetcher[] fetcherArray = fetchers.toArray(new EntryFetcher[fetchers.size()]); @@ -93,9 +91,10 @@ public GeneralFetcher(SidePaneManager p0, JabRefFrame frame) { revalidate(); }); - action = new FetcherAction(); - - + action = new ToggleAction(Localization.lang("Web search"), + Localization.lang("Toggle web search interface"), + Globals.getKeyPrefs().getKey(KeyBinding.WEB_SEARCH), + IconTheme.JabRefIcon.WWW); helpBut.setMargin(new Insets(0, 0, 0, 0)); tf.setPreferredSize(new Dimension(1, tf.getPreferredSize().height)); @@ -158,7 +157,7 @@ private JTextField getTextField() { return tf; } - public Action getAction() { + public ToggleAction getAction() { return action; } @@ -225,37 +224,15 @@ public void actionPerformed(ActionEvent e) { } } - - class FetcherAction extends AbstractAction { - - public FetcherAction() { - super(Localization.lang("Web search"), IconTheme.JabRefIcon.WWW.getSmallIcon()); - //if ((activeFetcher.getKeyName() != null) && (activeFetcher.getKeyName().length() > 0)) - putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.WEB_SEARCH)); - putValue(Action.LARGE_ICON_KEY, IconTheme.JabRefIcon.WWW.getIcon()); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Toggle web search interface")); - } - - @Override - public void actionPerformed(ActionEvent e) { - if (!sidePaneManager.hasComponent(GeneralFetcher.this.getTitle())) { - sidePaneManager.register(GeneralFetcher.this.getTitle(), GeneralFetcher.this); - } - - if (frame.getTabbedPane().getTabCount() > 0) { - sidePaneManager.toggle(GeneralFetcher.this.getTitle()); - if (sidePaneManager.isComponentVisible(GeneralFetcher.this.getTitle())) { - getTextField().requestFocus(); - } - } - } + @Override + public void grabFocus() { + getTextField().grabFocus(); } - @Override public void componentClosing() { super.componentClosing(); - frame.setFetcherToggle(false); + getAction().setSelected(false); Globals.prefs.putBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE, Boolean.FALSE); } @@ -265,6 +242,11 @@ public void componentOpening() { Globals.prefs.putBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE, Boolean.TRUE); } + @Override + public String getSidePaneName() { + return NAME; + } + @Override public int getRescalingWeight() { return 0; 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 30746dab9f9..ad5d4ee653a 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java @@ -80,9 +80,11 @@ */ public class OpenOfficePanel extends AbstractWorker { + public static final String NAME = "OpenOffice/LibreOffice"; + private static final Log LOGGER = LogFactory.getLog(OpenOfficePanel.class); - private OOPanel comp; + private OOPanel sidePane; private JDialog diag; private final JButton connect; private final JButton manualConnect; @@ -101,7 +103,6 @@ public class OpenOfficePanel extends AbstractWorker { HelpFile.OPENOFFICE_LIBREOFFICE).getHelpButton(); private OOBibBase ooBase; private JabRefFrame frame; - private SidePaneManager manager; private OOBibStyle style; private StyleSelectDialog styleDialog; private boolean dialogOkPressed; @@ -114,7 +115,7 @@ public class OpenOfficePanel extends AbstractWorker { private static OpenOfficePanel instance; - private OpenOfficePanel() { + public OpenOfficePanel(JabRefFrame jabRefFrame, SidePaneManager spManager) { Icon connectImage = IconTheme.JabRefIcon.CONNECT_OPEN_OFFICE.getSmallIcon(); connect = new JButton(connectImage); @@ -134,36 +135,11 @@ private OpenOfficePanel() { loader = new StyleLoader(preferences, Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader), Globals.prefs.getDefaultEncoding()); - } - - public static OpenOfficePanel getInstance() { - if (OpenOfficePanel.instance == null) { - OpenOfficePanel.instance = new OpenOfficePanel(); - } - return OpenOfficePanel.instance; - } - public SidePaneComponent getSidePaneComponent() { - return comp; - } - - public void init(JabRefFrame jabRefFrame, SidePaneManager spManager) { this.frame = jabRefFrame; - this.manager = spManager; - comp = new OOPanel(spManager, IconTheme.getImage("openoffice"), "OpenOffice/LibreOffice", this); + sidePane = new OOPanel(spManager, IconTheme.getImage("openoffice"), "OpenOffice/LibreOffice"); initPanel(); - spManager.register(getName(), comp); - } - - public JMenuItem getMenuItem() { - if (preferences.showPanel()) { - manager.show(getName()); - } - JMenuItem item = new JMenuItem(Localization.lang("OpenOffice/LibreOffice connection"), - IconTheme.getImage("openoffice")); - item.addActionListener(event -> manager.show(getName())); - item.setAccelerator(Globals.getKeyPrefs().getKey(KeyBinding.OPEN_OPEN_OFFICE_LIBRE_OFFICE_CONNECTION)); - return item; + spManager.register(sidePane); } private void initPanel() { @@ -326,7 +302,7 @@ public void actionPerformed(ActionEvent e) { mainBuilder.add(settingsB).xy(1, 10); JPanel content = new JPanel(); - comp.setContentContainer(content); + sidePane.setContentContainer(content); content.setLayout(new BorderLayout()); content.add(mainBuilder.getPanel(), BorderLayout.CENTER); @@ -804,24 +780,27 @@ private void showSettingsPopup() { menu.show(settingsB, 0, settingsB.getHeight()); } - public String getName() { - return "OpenOffice/LibreOffice"; + public SidePaneComponent.ToggleAction getAction() { + return sidePane.getToggleAction(); } private class OOPanel extends SidePaneComponent { - private final OpenOfficePanel openOfficePanel; + private final ToggleAction toggleAction; - public OOPanel(SidePaneManager sidePaneManager, Icon url, String s, OpenOfficePanel panel) { - super(sidePaneManager, url, s); - openOfficePanel = panel; - } + public OOPanel(SidePaneManager sidePaneManager, Icon icon, String title) { + super(sidePaneManager, icon, title); + sidePaneManager.register(this); + if (preferences.showPanel()) { + manager.show(NAME); + } - @Override - public String getName() { - return openOfficePanel.getName(); + toggleAction = new ToggleAction(Localization.lang("OpenOffice/LibreOffice connection"), + Localization.lang("OpenOffice/LibreOffice connection"), + Globals.getKeyPrefs().getKey(KeyBinding.OPEN_OPEN_OFFICE_LIBRE_OFFICE_CONNECTION), + icon); } @Override @@ -834,10 +813,20 @@ public void componentOpening() { preferences.setShowPanel(true); } + @Override + public String getSidePaneName() { + return NAME; + } + @Override public int getRescalingWeight() { return 0; } + + public ToggleAction getToggleAction() { + return toggleAction; + } + } } diff --git a/src/test/java/net/sf/jabref/gui/importer/fetcher/GeneralFetcherTest.java b/src/test/java/net/sf/jabref/gui/importer/fetcher/GeneralFetcherTest.java index 5bdb204928c..04860cf805a 100644 --- a/src/test/java/net/sf/jabref/gui/importer/fetcher/GeneralFetcherTest.java +++ b/src/test/java/net/sf/jabref/gui/importer/fetcher/GeneralFetcherTest.java @@ -61,7 +61,7 @@ public void setUp() { GeneralFetcherTest.acmpf = new ACMPortalFetcher(); ArrayList al = new ArrayList<>(); al.add(GeneralFetcherTest.acmpf); - GeneralFetcherTest.gf = new GeneralFetcher(GeneralFetcherTest.spm, GeneralFetcherTest.jrf); + GeneralFetcherTest.gf = new GeneralFetcher(GeneralFetcherTest.jrf, GeneralFetcherTest.spm); } @After From 8f454e71b1b1c90c323bf8e88952588d4ab25da7 Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Wed, 28 Sep 2016 16:50:12 +0200 Subject: [PATCH 2/7] fix issues --- src/main/java/net/sf/jabref/gui/SidePaneManager.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/SidePaneManager.java b/src/main/java/net/sf/jabref/gui/SidePaneManager.java index eb4575f72ec..abee4c961ba 100644 --- a/src/main/java/net/sf/jabref/gui/SidePaneManager.java +++ b/src/main/java/net/sf/jabref/gui/SidePaneManager.java @@ -67,7 +67,7 @@ public synchronized boolean isComponentVisible(String name) { } /** - * if panel is visible it will be hidden and the other way around + * If panel is visible it will be hidden and the other way around * * @param name name of the panel */ @@ -80,14 +80,15 @@ public synchronized void toggle(String name) { } /** - * if panel is hidden it will be shown and focused - * if panel is visible but not focused it will be focused - * ig panel is visible and focused it will be hidden + * If panel is hidden it will be shown and focused + * If panel is visible but not focused it will be focused + * If panel is visible and focused it will be hidden * * @param name name of the panel */ public synchronized void toggleThreeWay(String name){ - if (isComponentVisible(name) && Globals.getFocusListener().getFocused() == components.get(name)) { + boolean isPanelFocused = Globals.getFocusListener().getFocused() == components.get(name); + if (isComponentVisible(name) && isPanelFocused) { hide(name); } else { show(name); From 2317d85c8c8094a0eda29870d9e2daa44583607d Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Tue, 11 Oct 2016 11:26:12 +0200 Subject: [PATCH 3/7] make getToggleAction abstract --- .../net/sf/jabref/collab/FileUpdatePanel.java | 7 +++++++ src/main/java/net/sf/jabref/gui/BasePanel.java | 2 +- .../java/net/sf/jabref/gui/JabRefFrame.java | 18 +++++++++--------- .../net/sf/jabref/gui/SidePaneComponent.java | 5 +++++ .../sf/jabref/gui/groups/GroupSelector.java | 5 +++-- .../gui/importer/fetcher/GeneralFetcher.java | 5 +++-- .../jabref/gui/openoffice/OpenOfficePanel.java | 1 + 7 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java b/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java index 69ffb30d1f7..da6429caac9 100644 --- a/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java +++ b/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java @@ -17,6 +17,8 @@ import net.sf.jabref.gui.SidePaneManager; import net.sf.jabref.logic.l10n.Localization; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + public class FileUpdatePanel extends SidePaneComponent implements ActionListener, ChangeScanner.DisplayResultCallback { public static final String NAME = "fileUpdate"; @@ -77,6 +79,11 @@ public int getRescalingWeight() { return 0; } + @Override + public ToggleAction getToggleAction() { + throw new NotImplementedException(); + } + /** * actionPerformed * diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 4c4ebd641d4..231ec03b589 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -1211,7 +1211,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.getGroupSelector().getAction().isSelected()) { + if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP) && frame.getGroupSelector().getToggleAction().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 024fed923ca..ab7602cd1c9 100644 --- a/src/main/java/net/sf/jabref/gui/JabRefFrame.java +++ b/src/main/java/net/sf/jabref/gui/JabRefFrame.java @@ -650,9 +650,9 @@ public void windowClosing(WindowEvent e) { currentBasePanel.getPreviewPanel().updateLayout(); - groupSelector.getAction().setSelected(sidePaneManager.isComponentVisible(GroupSelector.NAME)); + groupSelector.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GroupSelector.NAME)); previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); - generalFetcher.getAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.NAME)); + generalFetcher.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.NAME)); openOfficePanel.getAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficePanel.NAME)); Globals.getFocusListener().setFocused(currentBasePanel.getMainTable()); setWindowTitle(); @@ -1225,14 +1225,14 @@ private void fillMenu() { search.add(normalSearch); search.add(replaceAll); search.addSeparator(); - search.add(new JCheckBoxMenuItem(generalFetcher.getAction())); + search.add(new JCheckBoxMenuItem(generalFetcher.getToggleAction())); if (prefs.getBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE)) { sidePaneManager.register(generalFetcher); sidePaneManager.show(GeneralFetcher.NAME); } mb.add(search); - groups.add(new JCheckBoxMenuItem(groupSelector.getAction())); + groups.add(new JCheckBoxMenuItem(groupSelector.getToggleAction())); groups.addSeparator(); groups.add(addToGroup); groups.add(removeFromGroup); @@ -1272,8 +1272,8 @@ private void fillMenu() { view.add(decreseFontSize); view.addSeparator(); view.add(new JCheckBoxMenuItem(toggleToolbar)); - view.add(new JCheckBoxMenuItem(enableToggle(generalFetcher.getAction()))); - view.add(new JCheckBoxMenuItem(groupSelector.getAction())); + view.add(new JCheckBoxMenuItem(enableToggle(generalFetcher.getToggleAction()))); + view.add(new JCheckBoxMenuItem(groupSelector.getToggleAction())); view.add(new JCheckBoxMenuItem(togglePreview)); view.add(getNextPreviewStyleAction()); view.add(getPreviousPreviewStyleAction()); @@ -1472,12 +1472,12 @@ private void createToolBar() { } tlb.addSeparator(); - tlb.addJToggleButton(new JToggleButton(generalFetcher.getAction())); + tlb.addJToggleButton(new JToggleButton(generalFetcher.getToggleAction())); previewToggle = new JToggleButton(togglePreview); tlb.addJToggleButton(previewToggle); - tlb.addJToggleButton(new JToggleButton(groupSelector.getAction())); + tlb.addJToggleButton(new JToggleButton(groupSelector.getToggleAction())); tlb.addSeparator(); @@ -1504,7 +1504,7 @@ private void initActions() { openDatabaseOnlyActions.addAll(Arrays.asList(mergeDatabaseAction, newSubDatabaseAction, save, globalSearch, saveAs, saveSelectedAs, saveSelectedAsPlain, editModeAction, undo, redo, cut, deleteEntry, copy, paste, mark, markSpecific, unmark, unmarkAll, rankSubMenu, editEntry, selectAll, copyKey, copyCiteKey, copyKeyAndTitle, copyKeyAndLink, editPreamble, editStrings, - groupSelector.getAction(), makeKeyAction, normalSearch, generalFetcher.getAction(), mergeEntries, cleanupEntries, exportToClipboard, replaceAll, + groupSelector.getToggleAction(), makeKeyAction, normalSearch, generalFetcher.getToggleAction(), mergeEntries, cleanupEntries, exportToClipboard, replaceAll, sendAsEmail, downloadFullText, writeXmpAction, openOfficePanel.getAction(), findUnlinkedFiles, addToGroup, removeFromGroup, moveToGroup, autoLinkFile, resolveDuplicateKeys, openUrl, openFolder, openFile, togglePreview, dupliCheck, autoSetFile, newEntryAction, newSpec, customizeAction, plainTextImport, getMassSetField(), getManageKeywords(), diff --git a/src/main/java/net/sf/jabref/gui/SidePaneComponent.java b/src/main/java/net/sf/jabref/gui/SidePaneComponent.java index 4b9a953b8d5..5e7b7bde3e0 100644 --- a/src/main/java/net/sf/jabref/gui/SidePaneComponent.java +++ b/src/main/java/net/sf/jabref/gui/SidePaneComponent.java @@ -108,6 +108,11 @@ public Dimension getMinimumSize() { */ public abstract int getRescalingWeight(); + /** + * @return the action which toggles this {@link SidePaneComponent} + */ + public abstract ToggleAction getToggleAction(); + public class ToggleAction extends AbstractAction { 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 ca11f272521..02db3910efd 100644 --- a/src/main/java/net/sf/jabref/gui/groups/GroupSelector.java +++ b/src/main/java/net/sf/jabref/gui/groups/GroupSelector.java @@ -725,7 +725,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); } - getAction().setSelected(false); + getToggleAction().setSelected(false); } private void setGroups(GroupTreeNode groupsRoot) { @@ -1282,7 +1282,8 @@ public void grabFocus() { groupsTree.grabFocus(); } - public ToggleAction getAction() { + @Override + public ToggleAction getToggleAction() { return toggleAction; } 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 2c92bc3351d..937590eeb62 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 @@ -157,7 +157,8 @@ private JTextField getTextField() { return tf; } - public ToggleAction getAction() { + @Override + public ToggleAction getToggleAction() { return action; } @@ -232,7 +233,7 @@ public void grabFocus() { @Override public void componentClosing() { super.componentClosing(); - getAction().setSelected(false); + getToggleAction().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 194d7f9fadc..6a72d0ddffe 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java @@ -825,6 +825,7 @@ public int getRescalingWeight() { return 0; } + @Override public ToggleAction getToggleAction() { return toggleAction; } From 7c5179a9d0121cfdb0f2d8b198e52781f0d92a56 Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Tue, 11 Oct 2016 13:10:11 +0200 Subject: [PATCH 4/7] make SideComponentManager generic --- .../net/sf/jabref/collab/FileUpdatePanel.java | 9 +- .../java/net/sf/jabref/gui/BasePanel.java | 14 +-- .../java/net/sf/jabref/gui/JabRefFrame.java | 8 +- .../net/sf/jabref/gui/SidePaneComponent.java | 10 +- .../net/sf/jabref/gui/SidePaneManager.java | 117 +++++++++--------- .../gui/exporter/SaveDatabaseAction.java | 4 +- .../sf/jabref/gui/groups/GroupSelector.java | 9 +- .../gui/importer/fetcher/GeneralFetcher.java | 7 -- .../gui/openoffice/OpenOfficePanel.java | 11 +- 9 files changed, 82 insertions(+), 107 deletions(-) diff --git a/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java b/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java index da6429caac9..fe7863dce20 100644 --- a/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java +++ b/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java @@ -21,8 +21,6 @@ public class FileUpdatePanel extends SidePaneComponent implements ActionListener, ChangeScanner.DisplayResultCallback { - public static final String NAME = "fileUpdate"; - private final SidePaneManager manager; private final ChangeScanner scanner; @@ -66,12 +64,7 @@ public BasePanel getPanel() { */ @Override public void componentClosing() { - manager.unregisterComponent(FileUpdatePanel.NAME); - } - - @Override - public String getSidePaneName() { - return NAME; + manager.unregisterComponent(FileUpdatePanel.class); } @Override diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 231ec03b589..84bb79e315d 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -2111,15 +2111,15 @@ public void fileUpdated() { // Check if there is already a notification about external // changes: - boolean hasAlready = sidePaneManager.hasComponent(FileUpdatePanel.NAME); + boolean hasAlready = sidePaneManager.hasComponent(FileUpdatePanel.class); if (hasAlready) { - sidePaneManager.hideComponent(FileUpdatePanel.NAME); - sidePaneManager.unregisterComponent(FileUpdatePanel.NAME); + sidePaneManager.hideComponent(FileUpdatePanel.class); + sidePaneManager.unregisterComponent(FileUpdatePanel.class); } FileUpdatePanel pan = new FileUpdatePanel(BasePanel.this, sidePaneManager, getBibDatabaseContext().getDatabaseFile().orElse(null), scanner); sidePaneManager.register(pan); - sidePaneManager.show(FileUpdatePanel.NAME); + sidePaneManager.show(FileUpdatePanel.class); }; if (scanner.changesFound()) { @@ -2143,10 +2143,10 @@ public void cleanUp() { } // Check if there is a FileUpdatePanel for this BasePanel being shown. If so, // remove it: - if (sidePaneManager.hasComponent(FileUpdatePanel.NAME)) { - FileUpdatePanel fup = (FileUpdatePanel) sidePaneManager.getComponent(FileUpdatePanel.NAME); + if (sidePaneManager.hasComponent(FileUpdatePanel.class)) { + FileUpdatePanel fup = (FileUpdatePanel) sidePaneManager.getComponent(FileUpdatePanel.class); if (fup.getPanel() == this) { - sidePaneManager.hideComponent(FileUpdatePanel.NAME); + sidePaneManager.hideComponent(FileUpdatePanel.class); } } } diff --git a/src/main/java/net/sf/jabref/gui/JabRefFrame.java b/src/main/java/net/sf/jabref/gui/JabRefFrame.java index ab7602cd1c9..3e727a4ffbc 100644 --- a/src/main/java/net/sf/jabref/gui/JabRefFrame.java +++ b/src/main/java/net/sf/jabref/gui/JabRefFrame.java @@ -650,10 +650,10 @@ public void windowClosing(WindowEvent e) { currentBasePanel.getPreviewPanel().updateLayout(); - groupSelector.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GroupSelector.NAME)); + groupSelector.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GroupSelector.class)); previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); - generalFetcher.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.NAME)); - openOfficePanel.getAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficePanel.NAME)); + generalFetcher.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.class)); + openOfficePanel.getAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficePanel.OOPanel.class)); Globals.getFocusListener().setFocused(currentBasePanel.getMainTable()); setWindowTitle(); editModeAction.initName(); @@ -1228,7 +1228,7 @@ private void fillMenu() { search.add(new JCheckBoxMenuItem(generalFetcher.getToggleAction())); if (prefs.getBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE)) { sidePaneManager.register(generalFetcher); - sidePaneManager.show(GeneralFetcher.NAME); + sidePaneManager.show(GeneralFetcher.class); } mb.add(search); diff --git a/src/main/java/net/sf/jabref/gui/SidePaneComponent.java b/src/main/java/net/sf/jabref/gui/SidePaneComponent.java index 5e7b7bde3e0..c3514399502 100644 --- a/src/main/java/net/sf/jabref/gui/SidePaneComponent.java +++ b/src/main/java/net/sf/jabref/gui/SidePaneComponent.java @@ -100,8 +100,6 @@ public Dimension getMinimumSize() { return getPreferredSize(); } - public abstract String getSidePaneName(); - /** * Specifies how to distribute extra vertical space between side pane components. * 0: fixed height, 1: fill the remaining space @@ -131,17 +129,17 @@ public ToggleAction(String text, String description, KeyStroke key, Icon icon){ @Override public void actionPerformed(ActionEvent e) { - if (!manager.hasComponent(getSidePaneName())) { + if (!manager.hasComponent(SidePaneComponent.this.getClass())) { manager.register(SidePaneComponent.this); } // if clicked by mouse just toggle if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) { - manager.toggle(getSidePaneName()); + manager.toggle(SidePaneComponent.this.getClass()); } else { - manager.toggleThreeWay(getSidePaneName()); + manager.toggleThreeWay(SidePaneComponent.this.getClass()); } - putValue(Action.SELECTED_KEY, manager.isComponentVisible(getSidePaneName())); + putValue(Action.SELECTED_KEY, manager.isComponentVisible(SidePaneComponent.this.getClass())); } public void setSelected(boolean selected){ diff --git a/src/main/java/net/sf/jabref/gui/SidePaneManager.java b/src/main/java/net/sf/jabref/gui/SidePaneManager.java index abee4c961ba..92df0599a86 100644 --- a/src/main/java/net/sf/jabref/gui/SidePaneManager.java +++ b/src/main/java/net/sf/jabref/gui/SidePaneManager.java @@ -1,6 +1,5 @@ package net.sf.jabref.gui; -import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -31,7 +30,7 @@ public class SidePaneManager { private final SidePane sidep; - private final Map components = new LinkedHashMap<>(); + private final Map, SidePaneComponent> components = new LinkedHashMap<>(); private final List visible = new LinkedList<>(); @@ -53,29 +52,27 @@ public SidePane getPanel() { return sidep; } - public synchronized boolean hasComponent(String name) { - return components.containsKey(name); + public synchronized boolean hasComponent(Class sidePaneComponent) { + return components.containsKey(sidePaneComponent); } - public synchronized boolean isComponentVisible(String name) { - SidePaneComponent sidePaneComponent = components.get(name); - if (sidePaneComponent == null) { + public synchronized boolean isComponentVisible(Class sidePaneComponent) { + SidePaneComponent component = components.get(sidePaneComponent); + if (component == null) { return false; } else { - return visible.contains(sidePaneComponent); + return visible.contains(component); } } /** * If panel is visible it will be hidden and the other way around - * - * @param name name of the panel */ - public synchronized void toggle(String name) { - if (isComponentVisible(name)) { - hide(name); + public synchronized void toggle(Class sidePaneComponent) { + if (isComponentVisible(sidePaneComponent)) { + hide(sidePaneComponent); } else { - show(name); + show(sidePaneComponent); } } @@ -83,33 +80,31 @@ public synchronized void toggle(String name) { * If panel is hidden it will be shown and focused * If panel is visible but not focused it will be focused * If panel is visible and focused it will be hidden - * - * @param name name of the panel */ - public synchronized void toggleThreeWay(String name){ - boolean isPanelFocused = Globals.getFocusListener().getFocused() == components.get(name); - if (isComponentVisible(name) && isPanelFocused) { - hide(name); + public synchronized void toggleThreeWay(Class sidePaneComponent) { + boolean isPanelFocused = Globals.getFocusListener().getFocused() == components.get(sidePaneComponent); + if (isComponentVisible(sidePaneComponent) && isPanelFocused) { + hide(sidePaneComponent); } else { - show(name); + show(sidePaneComponent); } } - public synchronized void show(String name) { - SidePaneComponent sidePaneComponent = components.get(name); - if (sidePaneComponent == null) { - LOGGER.warn("Side pane component '" + name + "' unknown."); + public synchronized void show(Class sidePaneComponent) { + SidePaneComponent component = components.get(sidePaneComponent); + if (component == null) { + LOGGER.warn("Side pane component '" + sidePaneComponent + "' unknown."); } else { - show(sidePaneComponent); + show(component); } } - public synchronized void hide(String name) { - SidePaneComponent sidePaneComponent = components.get(name); - if (sidePaneComponent == null) { - LOGGER.warn("Side pane component '" + name + "' unknown."); + public synchronized void hide(Class sidePaneComponent) { + SidePaneComponent component = components.get(sidePaneComponent); + if (component == null) { + LOGGER.warn("Side pane component '" + sidePaneComponent + "' unknown."); } else { - hideComponent(sidePaneComponent); + hideComponent(component); if (frame.getCurrentBasePanel() != null) { MainTable mainTable = frame.getCurrentBasePanel().getMainTable(); mainTable.setSelected(mainTable.getSelectedRow()); @@ -119,7 +114,7 @@ public synchronized void hide(String name) { } public synchronized void register(SidePaneComponent comp) { - components.put(comp.getSidePaneName(), comp); + components.put(comp.getClass(), comp); } private synchronized void show(SidePaneComponent component) { @@ -137,8 +132,8 @@ private synchronized void show(SidePaneComponent component) { component.grabFocus(); } - public synchronized SidePaneComponent getComponent(String name) { - return components.get(name); + public synchronized SidePaneComponent getComponent(Class sidePaneComponent) { + return components.get(sidePaneComponent); } public synchronized void hideComponent(SidePaneComponent comp) { @@ -149,30 +144,36 @@ public synchronized void hideComponent(SidePaneComponent comp) { } } - public synchronized void hideComponent(String name) { - SidePaneComponent comp = components.get(name); - if (comp == null) { + public synchronized void hideComponent(Class sidePaneComponent) { + SidePaneComponent component = components.get(sidePaneComponent); + if (component == null) { return; } - if (visible.contains(comp)) { - comp.componentClosing(); - visible.remove(comp); + if (visible.contains(component)) { + component.componentClosing(); + visible.remove(component); updateView(); } } - private static Map getPreferredPositions() { - Map preferredPositions = new HashMap<>(); + private static Map, Integer> getPreferredPositions() { + Map, Integer> preferredPositions = new HashMap<>(); List componentNames = Globals.prefs.getStringList(JabRefPreferences.SIDE_PANE_COMPONENT_NAMES); List componentPositions = Globals.prefs .getStringList(JabRefPreferences.SIDE_PANE_COMPONENT_PREFERRED_POSITIONS); for (int i = 0; i < componentNames.size(); ++i) { + String componentName = componentNames.get(i); try { - preferredPositions.put(componentNames.get(i), Integer.parseInt(componentPositions.get(i))); + Class componentClass = (Class) Class.forName(componentName); + preferredPositions.put(componentClass, Integer.parseInt(componentPositions.get(i))); + } catch (ClassNotFoundException e) { + LOGGER.error("Following side pane could not be found: " + componentName, e); + } catch (ClassCastException e) { + LOGGER.error("Following Class is no side pane: '" + componentName, e); } catch (NumberFormatException e) { - LOGGER.info("Invalid number format for side pane component '" + componentNames.get(i) + "'.", e); + LOGGER.info("Invalid number format for side pane component '" + componentName + "'.", e); } } @@ -180,17 +181,20 @@ private static Map getPreferredPositions() { } private void updatePreferredPositions() { - Map preferredPositions = getPreferredPositions(); + Map, Integer> preferredPositions = getPreferredPositions(); // Update the preferred positions of all visible components int index = 0; for (SidePaneComponent comp : visible) { - preferredPositions.put(comp.getSidePaneName(), index); + preferredPositions.put(comp.getClass(), index); index++; } // Split the map into a pair of parallel String lists suitable for storage - List tmpComponentNames = new ArrayList<>(preferredPositions.keySet()); + List tmpComponentNames = preferredPositions.keySet().parallelStream() + .map(Class::getName) + .collect(Collectors.toList()); + List componentPositions = preferredPositions.values().stream().map(Object::toString) .collect(Collectors.toList()); @@ -199,10 +203,12 @@ private void updatePreferredPositions() { } - // Helper class for sorting visible components based on their preferred position + /** + * Helper class for sorting visible components based on their preferred position + */ private class PreferredIndexSort implements Comparator { - private final Map preferredPositions; + private final Map, Integer> preferredPositions; public PreferredIndexSort() { @@ -211,8 +217,8 @@ public PreferredIndexSort() { @Override public int compare(SidePaneComponent comp1, SidePaneComponent comp2) { - int pos1 = preferredPositions.getOrDefault(comp1.getSidePaneName(), 0); - int pos2 = preferredPositions.getOrDefault(comp2.getSidePaneName(), 0); + int pos1 = preferredPositions.getOrDefault(comp1.getClass(), 0); + int pos2 = preferredPositions.getOrDefault(comp2.getClass(), 0); return Integer.valueOf(pos1).compareTo(pos2); } } @@ -246,8 +252,8 @@ public synchronized void moveDown(SidePaneComponent comp) { } } - public synchronized void unregisterComponent(String name) { - components.remove(name); + public synchronized void unregisterComponent(Class sidePaneComponent) { + components.remove(sidePaneComponent); } /** @@ -256,10 +262,9 @@ public synchronized void unregisterComponent(String name) { * * @param panel */ - private synchronized void setActiveBasePanel(BasePanel panel) { - for (Map.Entry stringSidePaneComponentEntry : components.entrySet()) { - stringSidePaneComponentEntry.getValue().setActiveBasePanel(panel); + for (SidePaneComponent component : components.values()) { + component.setActiveBasePanel(panel); } } diff --git a/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java index 3e90cbf1cfd..6aadc90727d 100644 --- a/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/net/sf/jabref/gui/exporter/SaveDatabaseAction.java @@ -382,7 +382,7 @@ private boolean checkExternalModification() { scanner.displayResult(resolved -> { if (resolved) { panel.setUpdatedExternally(false); - SwingUtilities.invokeLater(() -> panel.getSidePaneManager().hide(FileUpdatePanel.NAME)); + SwingUtilities.invokeLater(() -> panel.getSidePaneManager().hide(FileUpdatePanel.class)); } else { canceled = true; } @@ -400,7 +400,7 @@ private boolean checkExternalModification() { canceled = true; } else { panel.setUpdatedExternally(false); - panel.getSidePaneManager().hide(FileUpdatePanel.NAME); + panel.getSidePaneManager().hide(FileUpdatePanel.class); } } } 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 02db3910efd..dcfc5e83c06 100644 --- a/src/main/java/net/sf/jabref/gui/groups/GroupSelector.java +++ b/src/main/java/net/sf/jabref/gui/groups/GroupSelector.java @@ -79,8 +79,6 @@ */ public class GroupSelector extends SidePaneComponent implements TreeSelectionListener { - public static final String NAME = "groups"; - private static final Log LOGGER = LogFactory.getLog(GroupSelector.class); private final GroupsTree groupsTree; @@ -710,11 +708,6 @@ public void componentOpening() { valueChanged(null); } - @Override - public String getSidePaneName() { - return NAME; - } - @Override public int getRescalingWeight() { return 1; @@ -1219,7 +1212,7 @@ public Enumeration getExpandedPaths() { public void setActiveBasePanel(BasePanel panel) { super.setActiveBasePanel(panel); if (panel == null) { // hide groups - frame.getSidePaneManager().hide(NAME); + frame.getSidePaneManager().hide(GroupSelector.class); return; } MetaData metaData = panel.getBibDatabaseContext().getMetaData(); 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 937590eeb62..0897baad761 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 @@ -36,8 +36,6 @@ public class GeneralFetcher extends SidePaneComponent implements ActionListener { - public static final String NAME = "fetcher"; - private final JTextField tf = new JTextField(); private final CardLayout optionsCards = new CardLayout(); @@ -243,11 +241,6 @@ public void componentOpening() { Globals.prefs.putBoolean(JabRefPreferences.WEB_SEARCH_VISIBLE, Boolean.TRUE); } - @Override - public String getSidePaneName() { - return NAME; - } - @Override public int getRescalingWeight() { return 0; 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 6a72d0ddffe..b5196a297c3 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java @@ -80,8 +80,6 @@ */ public class OpenOfficePanel extends AbstractWorker { - public static final String NAME = "OpenOffice/LibreOffice"; - private static final Log LOGGER = LogFactory.getLog(OpenOfficePanel.class); private OOPanel sidePane; @@ -787,7 +785,7 @@ public SidePaneComponent.ToggleAction getAction() { } - private class OOPanel extends SidePaneComponent { + public class OOPanel extends SidePaneComponent { private final ToggleAction toggleAction; @@ -796,7 +794,7 @@ public OOPanel(SidePaneManager sidePaneManager, Icon icon, String title) { super(sidePaneManager, icon, title); sidePaneManager.register(this); if (preferences.showPanel()) { - manager.show(NAME); + manager.show(OOPanel.class); } toggleAction = new ToggleAction(Localization.lang("OpenOffice/LibreOffice connection"), @@ -815,11 +813,6 @@ public void componentOpening() { preferences.setShowPanel(true); } - @Override - public String getSidePaneName() { - return NAME; - } - @Override public int getRescalingWeight() { return 0; From b339cd10c4fc147744dcb437a2aebff811de05df Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Tue, 11 Oct 2016 13:14:38 +0200 Subject: [PATCH 5/7] extract OOPanel --- .../java/net/sf/jabref/gui/JabRefFrame.java | 6 +-- .../gui/openoffice/OpenOfficePanel.java | 49 ++--------------- .../gui/openoffice/OpenOfficeSidePanel.java | 52 +++++++++++++++++++ 3 files changed, 58 insertions(+), 49 deletions(-) create mode 100644 src/main/java/net/sf/jabref/gui/openoffice/OpenOfficeSidePanel.java diff --git a/src/main/java/net/sf/jabref/gui/JabRefFrame.java b/src/main/java/net/sf/jabref/gui/JabRefFrame.java index 3e727a4ffbc..282294b75a1 100644 --- a/src/main/java/net/sf/jabref/gui/JabRefFrame.java +++ b/src/main/java/net/sf/jabref/gui/JabRefFrame.java @@ -653,7 +653,7 @@ public void windowClosing(WindowEvent e) { groupSelector.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GroupSelector.class)); previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); generalFetcher.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.class)); - openOfficePanel.getAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficePanel.OOPanel.class)); + openOfficePanel.getToggleAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficePanel.OOPanel.class)); Globals.getFocusListener().setFocused(currentBasePanel.getMainTable()); setWindowTitle(); editModeAction.initName(); @@ -1314,7 +1314,7 @@ private void fillMenu() { tools.add(newSubDatabaseAction); tools.add(writeXmpAction); - tools.add(new JCheckBoxMenuItem(openOfficePanel.getAction())); + tools.add(new JCheckBoxMenuItem(openOfficePanel.getToggleAction())); tools.add(pushExternalButton.getMenuAction()); tools.addSeparator(); tools.add(openFolder); @@ -1505,7 +1505,7 @@ private void initActions() { saveAs, saveSelectedAs, saveSelectedAsPlain, editModeAction, undo, redo, cut, deleteEntry, copy, paste, mark, markSpecific, unmark, unmarkAll, rankSubMenu, editEntry, selectAll, copyKey, copyCiteKey, copyKeyAndTitle, copyKeyAndLink, editPreamble, editStrings, groupSelector.getToggleAction(), makeKeyAction, normalSearch, generalFetcher.getToggleAction(), mergeEntries, cleanupEntries, exportToClipboard, replaceAll, - sendAsEmail, downloadFullText, writeXmpAction, openOfficePanel.getAction(), findUnlinkedFiles, addToGroup, removeFromGroup, + sendAsEmail, downloadFullText, writeXmpAction, openOfficePanel.getToggleAction(), findUnlinkedFiles, addToGroup, removeFromGroup, moveToGroup, autoLinkFile, resolveDuplicateKeys, openUrl, openFolder, openFile, togglePreview, dupliCheck, autoSetFile, newEntryAction, newSpec, customizeAction, plainTextImport, getMassSetField(), getManageKeywords(), pushExternalButton.getMenuAction(), closeDatabaseAction, getNextPreviewStyleAction(), getPreviousPreviewStyleAction(), checkIntegrity, 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 b5196a297c3..afe95fe23b6 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java @@ -82,7 +82,7 @@ public class OpenOfficePanel extends AbstractWorker { private static final Log LOGGER = LogFactory.getLog(OpenOfficePanel.class); - private OOPanel sidePane; + private OpenOfficeSidePanel sidePane; private JDialog diag; private final JButton connect; private final JButton manualConnect; @@ -110,8 +110,6 @@ public class OpenOfficePanel extends AbstractWorker { private final OpenOfficePreferences preferences; private final StyleLoader loader; - private static OpenOfficePanel instance; - public OpenOfficePanel(JabRefFrame jabRefFrame, SidePaneManager spManager) { Icon connectImage = IconTheme.JabRefIcon.CONNECT_OPEN_OFFICE.getSmallIcon(); @@ -135,7 +133,7 @@ public OpenOfficePanel(JabRefFrame jabRefFrame, SidePaneManager spManager) { Globals.prefs.getDefaultEncoding()); this.frame = jabRefFrame; - sidePane = new OOPanel(spManager, IconTheme.getImage("openoffice"), "OpenOffice/LibreOffice"); + sidePane = new OpenOfficeSidePanel(spManager, IconTheme.getImage("openoffice"), "OpenOffice/LibreOffice", preferences); initPanel(); spManager.register(sidePane); } @@ -780,49 +778,8 @@ private void showSettingsPopup() { menu.show(settingsB, 0, settingsB.getHeight()); } - public SidePaneComponent.ToggleAction getAction() { + public SidePaneComponent.ToggleAction getToggleAction() { return sidePane.getToggleAction(); } - - public class OOPanel extends SidePaneComponent { - - private final ToggleAction toggleAction; - - - public OOPanel(SidePaneManager sidePaneManager, Icon icon, String title) { - super(sidePaneManager, icon, title); - sidePaneManager.register(this); - if (preferences.showPanel()) { - manager.show(OOPanel.class); - } - - toggleAction = new ToggleAction(Localization.lang("OpenOffice/LibreOffice connection"), - Localization.lang("OpenOffice/LibreOffice connection"), - Globals.getKeyPrefs().getKey(KeyBinding.OPEN_OPEN_OFFICE_LIBRE_OFFICE_CONNECTION), - icon); - } - - @Override - public void componentClosing() { - preferences.setShowPanel(false); - } - - @Override - public void componentOpening() { - preferences.setShowPanel(true); - } - - @Override - public int getRescalingWeight() { - return 0; - } - - @Override - public ToggleAction getToggleAction() { - return toggleAction; - } - - } - } diff --git a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficeSidePanel.java b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficeSidePanel.java new file mode 100644 index 00000000000..5c3797cfef2 --- /dev/null +++ b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficeSidePanel.java @@ -0,0 +1,52 @@ +package net.sf.jabref.gui.openoffice; + +import javax.swing.Icon; + +import net.sf.jabref.Globals; +import net.sf.jabref.gui.SidePaneComponent; +import net.sf.jabref.gui.SidePaneManager; +import net.sf.jabref.gui.keyboard.KeyBinding; +import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.openoffice.OpenOfficePreferences; + +public class OpenOfficeSidePanel extends SidePaneComponent { + + private OpenOfficePreferences preferences; + private final ToggleAction toggleAction; + + + public OpenOfficeSidePanel(SidePaneManager sidePaneManager, Icon icon, String title, OpenOfficePreferences preferences) { + super(sidePaneManager, icon, title); + this.preferences = preferences; + sidePaneManager.register(this); + if (preferences.showPanel()) { + manager.show(OpenOfficeSidePanel.class); + } + + toggleAction = new ToggleAction(Localization.lang("OpenOffice/LibreOffice connection"), + Localization.lang("OpenOffice/LibreOffice connection"), + Globals.getKeyPrefs().getKey(KeyBinding.OPEN_OPEN_OFFICE_LIBRE_OFFICE_CONNECTION), + icon); + } + + @Override + public void componentClosing() { + preferences.setShowPanel(false); + } + + @Override + public void componentOpening() { + preferences.setShowPanel(true); + } + + @Override + public int getRescalingWeight() { + return 0; + } + + @Override + public ToggleAction getToggleAction() { + return toggleAction; + } + +} From 00f255bc9edaf34529d611fe61a169619843b916 Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Tue, 11 Oct 2016 18:20:07 +0200 Subject: [PATCH 6/7] fix compile error --- src/main/java/net/sf/jabref/gui/JabRefFrame.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/sf/jabref/gui/JabRefFrame.java b/src/main/java/net/sf/jabref/gui/JabRefFrame.java index 282294b75a1..52a36e1cf92 100644 --- a/src/main/java/net/sf/jabref/gui/JabRefFrame.java +++ b/src/main/java/net/sf/jabref/gui/JabRefFrame.java @@ -99,6 +99,7 @@ import net.sf.jabref.gui.menus.FileHistoryMenu; import net.sf.jabref.gui.menus.RightClickMenu; import net.sf.jabref.gui.openoffice.OpenOfficePanel; +import net.sf.jabref.gui.openoffice.OpenOfficeSidePanel; import net.sf.jabref.gui.preftabs.PreferencesDialog; import net.sf.jabref.gui.protectedterms.ProtectedTermsDialog; import net.sf.jabref.gui.push.PushToApplicationButton; @@ -653,7 +654,7 @@ public void windowClosing(WindowEvent e) { groupSelector.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GroupSelector.class)); previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled()); generalFetcher.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.class)); - openOfficePanel.getToggleAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficePanel.OOPanel.class)); + openOfficePanel.getToggleAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class)); Globals.getFocusListener().setFocused(currentBasePanel.getMainTable()); setWindowTitle(); editModeAction.initName(); From f6564a8775e1a24bb58cf5f918348494354ce18b Mon Sep 17 00:00:00 2001 From: Christian Bartsch Date: Tue, 11 Oct 2016 19:44:49 +0200 Subject: [PATCH 7/7] change method not implemented exception --- src/main/java/net/sf/jabref/collab/FileUpdatePanel.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java b/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java index fe7863dce20..2694d3203df 100644 --- a/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java +++ b/src/main/java/net/sf/jabref/collab/FileUpdatePanel.java @@ -17,8 +17,6 @@ import net.sf.jabref.gui.SidePaneManager; import net.sf.jabref.logic.l10n.Localization; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; - public class FileUpdatePanel extends SidePaneComponent implements ActionListener, ChangeScanner.DisplayResultCallback { private final SidePaneManager manager; @@ -74,7 +72,7 @@ public int getRescalingWeight() { @Override public ToggleAction getToggleAction() { - throw new NotImplementedException(); + throw new UnsupportedOperationException(); } /**