Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance side pane toggle #1605

Merged
merged 8 commits into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/main/java/net/sf/jabref/collab/FileUpdatePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
import net.sf.jabref.gui.SidePaneManager;
import net.sf.jabref.logic.l10n.Localization;

public class FileUpdatePanel extends SidePaneComponent implements ActionListener,
ChangeScanner.DisplayResultCallback {
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

public static final String NAME = "fileUpdate";
public class FileUpdatePanel extends SidePaneComponent implements ActionListener, ChangeScanner.DisplayResultCallback {

private final SidePaneManager manager;

Expand Down Expand Up @@ -65,14 +64,19 @@ public BasePanel getPanel() {
*/
@Override
public void componentClosing() {
manager.unregisterComponent(FileUpdatePanel.NAME);
manager.unregisterComponent(FileUpdatePanel.class);
}

@Override
public int getRescalingWeight() {
return 0;
}

@Override
public ToggleAction getToggleAction() {
throw new NotImplementedException();
}

/**
* actionPerformed
*
Expand Down
24 changes: 9 additions & 15 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,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);
Expand Down Expand Up @@ -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().getToggleAction().isSelected()) {
final List<BibEntry> entries = Collections.singletonList(addedEntryEvent.getBibEntry());
final TreePath[] selection = frame.getGroupSelector().getGroupsTree().getSelectionPaths();
if (selection != null) {
Expand Down Expand Up @@ -2117,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(FileUpdatePanel.NAME, pan);
sidePaneManager.show(FileUpdatePanel.NAME);
sidePaneManager.register(pan);
sidePaneManager.show(FileUpdatePanel.class);
};

if (scanner.changesFound()) {
Expand All @@ -2149,10 +2143,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.class)) {
FileUpdatePanel fup = (FileUpdatePanel) sidePaneManager.getComponent(FileUpdatePanel.class);
if (fup.getPanel() == this) {
sidePaneManager.hideComponent("fileUpdate");
sidePaneManager.hideComponent(FileUpdatePanel.class);
}
}
}
Expand Down
56 changes: 19 additions & 37 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -190,11 +191,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();
Expand Down Expand Up @@ -351,11 +348,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);
Expand Down Expand Up @@ -394,8 +386,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));
Expand Down Expand Up @@ -481,7 +471,7 @@ public void actionPerformed(ActionEvent e) {
private PushToApplications pushApplications;

private GeneralFetcher generalFetcher;

private OpenOfficePanel openOfficePanel;
private GroupSelector groupSelector;

private int previousTabCount = -1;
Expand Down Expand Up @@ -661,9 +651,10 @@ public void windowClosing(WindowEvent e) {

currentBasePanel.getPreviewPanel().updateLayout();

groupToggle.setSelected(sidePaneManager.isComponentVisible("groups"));
groupSelector.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GroupSelector.class));
previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled());
fetcherToggle.setSelected(sidePaneManager.isComponentVisible(generalFetcher.getTitle()));
generalFetcher.getToggleAction().setSelected(sidePaneManager.isComponentVisible(GeneralFetcher.class));
openOfficePanel.getToggleAction().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class));
Globals.getFocusListener().setFocused(currentBasePanel.getMainTable());
setWindowTitle();
editModeAction.initName();
Expand Down Expand Up @@ -723,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);
}

/**
Expand Down Expand Up @@ -1235,14 +1226,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.getTitle(), generalFetcher);
sidePaneManager.show(generalFetcher.getTitle());
sidePaneManager.register(generalFetcher);
sidePaneManager.show(GeneralFetcher.class);
}
mb.add(search);

groups.add(new JCheckBoxMenuItem(toggleGroups));
groups.add(new JCheckBoxMenuItem(groupSelector.getToggleAction()));
groups.addSeparator();
groups.add(addToGroup);
groups.add(removeFromGroup);
Expand Down Expand Up @@ -1282,8 +1273,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(toggleGroups));
view.add(new JCheckBoxMenuItem(enableToggle(generalFetcher.getToggleAction())));
view.add(new JCheckBoxMenuItem(groupSelector.getToggleAction()));
view.add(new JCheckBoxMenuItem(togglePreview));
view.add(getNextPreviewStyleAction());
view.add(getPreviousPreviewStyleAction());
Expand Down Expand Up @@ -1324,10 +1315,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.getToggleAction()));
tools.add(pushExternalButton.getMenuAction());
tools.addSeparator();
tools.add(openFolder);
Expand Down Expand Up @@ -1485,14 +1473,12 @@ private void createToolBar() {
}
tlb.addSeparator();

fetcherToggle = new JToggleButton(generalFetcher.getAction());
tlb.addJToggleButton(fetcherToggle);
tlb.addJToggleButton(new JToggleButton(generalFetcher.getToggleAction()));

previewToggle = new JToggleButton(togglePreview);
tlb.addJToggleButton(previewToggle);

groupToggle = new JToggleButton(toggleGroups);
tlb.addJToggleButton(groupToggle);
tlb.addJToggleButton(new JToggleButton(groupSelector.getToggleAction()));

tlb.addSeparator();

Expand All @@ -1519,8 +1505,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.getToggleAction(), makeKeyAction, normalSearch, generalFetcher.getToggleAction(), mergeEntries, cleanupEntries, exportToClipboard, replaceAll,
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,
Expand Down Expand Up @@ -2381,10 +2367,6 @@ public GroupSelector getGroupSelector() {
return groupSelector;
}

public void setFetcherToggle(boolean enabled) {
fetcherToggle.setSelected(enabled);
}

public void setPreviewToggle(boolean enabled) {
previewToggle.setSelected(enabled);
}
Expand Down
54 changes: 53 additions & 1 deletion src/main/java/net/sf/jabref/gui/SidePaneComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -100,4 +105,51 @@ public Dimension getMinimumSize() {
* 0: fixed height, 1: fill the remaining space
*/
public abstract int getRescalingWeight();

/**
* @return the action which toggles this {@link SidePaneComponent}
*/
public abstract ToggleAction getToggleAction();


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(SidePaneComponent.this.getClass())) {
manager.register(SidePaneComponent.this);
}

// if clicked by mouse just toggle
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) {
manager.toggle(SidePaneComponent.this.getClass());
} else {
manager.toggleThreeWay(SidePaneComponent.this.getClass());
}
putValue(Action.SELECTED_KEY, manager.isComponentVisible(SidePaneComponent.this.getClass()));
}

public void setSelected(boolean selected){
putValue(Action.SELECTED_KEY, selected);
}

public boolean isSelected() {
return Boolean.TRUE.equals(getValue(Action.SELECTED_KEY));
}

}

}
Loading