Skip to content

Commit

Permalink
Towards a easier to use search by removing incremental search, adding…
Browse files Browse the repository at this point in the history
… a toolbar using icons for the search options, adding a field stating the search results, search results are shown after each change of the search parameters
  • Loading branch information
simonharrer committed Nov 16, 2015
1 parent d736b42 commit a1b231e
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 342 deletions.
6 changes: 0 additions & 6 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public class JabRefPreferences {
public static final String USE_XMP_PRIVACY_FILTER = "useXmpPrivacyFilter";
public static final String SEARCH_AUTO_COMPLETE = "searchAutoComplete";
public static final String SEARCH_MODE_LIVE_FILTER = "searchModeLiveFilter";
public static final String SEARCH_MODE_INCREMENTAL = "incrementS";
public static final String SEARCH_CASE_SENSITIVE = "caseSensitiveSearch";
public static final String DEFAULT_AUTO_SORT = "defaultAutoSort";
public static final String DEFAULT_SHOW_SOURCE = "defaultShowSource";
Expand Down Expand Up @@ -165,7 +164,6 @@ public class JabRefPreferences {
public static final String SEARCH_PANE_POS_X = "searchPanePosX";
public static final String SEARCH_HIGHLIGHT_WORDS = "highLightWords";
public static final String SEARCH_REG_EXP = "regExpSearch";
public static final String SEARCH_SELECT_MATCHES = "selectS";
public static final String EDITOR_EMACS_KEYBINDINGS = "editorEMACSkeyBindings";
public static final String EDITOR_EMACS_KEYBINDINGS_REBIND_CA = "editorEMACSkeyBindingsRebindCA";
public static final String EDITOR_EMACS_KEYBINDINGS_REBIND_CF = "editorEMACSkeyBindingsRebindCF";
Expand Down Expand Up @@ -256,7 +254,6 @@ public class JabRefPreferences {
public static final String DEFAULT_LABEL_PATTERN = "defaultLabelPattern";

public static final String SEARCH_MODE_GLOBAL = "searchAllBases";
public static final String SEARCH_MODE_RESULTS_IN_DIALOG = "showSearchInDialog";
public static final String SEARCH_MODE_FLOAT = "floatSearch";
public static final String GRAY_OUT_NON_HITS = "grayOutNonHits";
public static final String CONFIRM_DELETE = "confirmDelete";
Expand Down Expand Up @@ -541,11 +538,9 @@ private JabRefPreferences() {
defaults.put(DEFAULT_SHOW_SOURCE, Boolean.FALSE);
defaults.put(DEFAULT_AUTO_SORT, Boolean.FALSE);
defaults.put(SEARCH_CASE_SENSITIVE, Boolean.FALSE);
defaults.put(SEARCH_MODE_INCREMENTAL, Boolean.FALSE);
defaults.put(SEARCH_MODE_LIVE_FILTER, Boolean.TRUE);
defaults.put(SEARCH_AUTO_COMPLETE, Boolean.TRUE);

defaults.put(SEARCH_SELECT_MATCHES, Boolean.FALSE);
defaults.put(SEARCH_REG_EXP, Boolean.TRUE);
defaults.put(SEARCH_HIGHLIGHT_WORDS, Boolean.TRUE);
defaults.put(SEARCH_PANE_POS_X, 0);
Expand Down Expand Up @@ -652,7 +647,6 @@ private JabRefPreferences() {
defaults.put(CONFIRM_DELETE, Boolean.TRUE);
defaults.put(GRAY_OUT_NON_HITS, Boolean.TRUE);
defaults.put(SEARCH_MODE_FLOAT, Boolean.TRUE);
defaults.put(SEARCH_MODE_RESULTS_IN_DIALOG, Boolean.FALSE);
defaults.put(SEARCH_MODE_GLOBAL, Boolean.FALSE);
defaults.put(DEFAULT_LABEL_PATTERN, "[authors3][year]");
defaults.put(PREVIEW_ENABLED, Boolean.TRUE);
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,6 @@ public void run() {
}
});

actions.put(Actions.INC_SEARCH, (BaseAction) () -> {
frame.setSearchBarVisible(true);
frame.getSearchBar().startIncrementalSearch();
});

// The action for copying the selected entry's key.
actions.put(Actions.COPY_KEY, (BaseAction) () -> {
BibtexEntry[] bes = mainTable.getSelectedEntries();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/sf/jabref/gui/IconTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ public enum JabRefIcon {
KEY_BINDINGS("\uf3ad"), /*css: keyboard */
FIND_DUPLICATES("\uf233"), /*css: code-equal */

REGEX("\uf4f0"), /*css: regex */
CASE_SENSITIVE("\uf127"), /*css: alphabetical */
OPEN_IN_NEW_WINDOW("\uf47b"), /*css: open-in-new */

// STILL MISSING:
GROUP_REGULAR("\uF4E6", Color.RED);

Expand Down
8 changes: 2 additions & 6 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,6 @@ void addJToogleButton(JToggleButton button) {
Localization.menuTitle("Manage content selectors"));
private final AbstractAction saveSessionAction = new SaveSessionAction();
public final AbstractAction loadSessionAction = new LoadSessionAction();
private final AbstractAction incrementalSearch = new GeneralAction(Actions.INC_SEARCH,
Localization.menuTitle("Incremental search"), Localization.lang("Start incremental search"),
prefs.getKey(KeyBinds.INCREMENTAL_SEARCH));
private final AbstractAction normalSearch = new GeneralAction(Actions.SEARCH, Localization.menuTitle("Search"),
Localization.lang("Search"), prefs.getKey(KeyBinds.SEARCH), IconTheme.JabRefIcon.SEARCH.getIcon());
private final AbstractAction toggleSearch = new GeneralAction(Actions.TOGGLE_SEARCH,
Expand Down Expand Up @@ -997,7 +994,7 @@ private void initLayout() {
searchBar = new SearchBar(this);
searchBar.setAlignmentX(1.0f);
searchBar.setAlignmentY(0.0f);
searchBar.setMaximumSize(new Dimension(200, 25));
searchBar.setMaximumSize(new Dimension(400, 25));
main.add(searchBar);
setSearchBarVisible(Globals.prefs.getBoolean(JabRefPreferences.SEARCH_BAR_VISIBLE));
tabbedPane.setAlignmentX(1.0f);
Expand Down Expand Up @@ -1291,7 +1288,6 @@ private void fillMenu() {
mb.add(edit);

search.add(normalSearch);
search.add(incrementalSearch);
search.add(replaceAll);
search.add(massSetField);
search.addSeparator();
Expand Down Expand Up @@ -1561,7 +1557,7 @@ private void initActions() {
redo, cut, delete, copy, paste, mark, unmark, unmarkAll, editEntry,
selectAll, copyKey, copyCiteKey, copyKeyAndTitle, editPreamble, editStrings, toggleGroups, toggleSearch,
makeKeyAction, normalSearch, mergeEntries, cleanupEntries, exportToClipboard,
incrementalSearch, replaceAll, sendAsEmail, downloadFullText, writeXmpAction,
replaceAll, sendAsEmail, downloadFullText, writeXmpAction,
findUnlinkedFiles, addToGroup, removeFromGroup, moveToGroup, autoLinkFile, resolveDuplicateKeys,
openPdf, openUrl, openFolder, openFile, openSpires, togglePreview, dupliCheck, autoSetFile,
newEntryAction, plainTextImport, massSetField, manageKeywords, pushExternalButton.getMenuAction(),
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/sf/jabref/gui/actions/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class Actions {
public static final String EXPORT_TO_CLIPBOARD = "exportToClipboard";
public static final String FOCUS_TABLE = "focusTable";
public static final String FORWARD = "forward";
public static final String INC_SEARCH = "incSearch";
public static final String MAKE_KEY = "makeKey";
public static final String MANAGE_SELECTORS = "manageSelectors";
public static final String MARK_ENTRIES = "markEntries";
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/net/sf/jabref/gui/keyboard/KeyBinds.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class KeyBinds {
public static final String IMPORT_INTO_CURRENT_DATABASE = "Import into current database";
public static final String IMPORT_INTO_NEW_DATABASE = "Import into new database";
public static final String INCREASE_TABLE_FONT_SIZE = "Increase table font size";
public static final String INCREMENTAL_SEARCH = "Incremental search";
public static final String LOAD_SESSION = "Load session";
public static final String MARK_ENTRIES = "Mark entries";
public static final String NEW_ARTICLE = "New article";
Expand All @@ -92,7 +91,6 @@ public class KeyBinds {
public static final String QUIT_JAB_REF = "Quit JabRef";
public static final String REDO = "Redo";
public static final String REFRESH_OO = "Refresh OO";
public static final String REPEAT_INCREMENTAL_SEARCH = "Repeat incremental search";
public static final String REPLACE_STRING = "Replace string";
public static final String RESOLVE_DUPLICATE_BIB_TE_X_KEYS = "Resolve duplicate BibTeX keys";
public static final String SAVE_ALL = "Save all";
Expand Down Expand Up @@ -150,8 +148,6 @@ public KeyBinds() {
keyBindMap.put(TOGGLE_GROUPS_INTERFACE, "ctrl shift G");
keyBindMap.put(AUTOGENERATE_BIB_TE_X_KEYS, "ctrl G");
keyBindMap.put(SEARCH, "ctrl F");
keyBindMap.put(INCREMENTAL_SEARCH, "ctrl shift F");
keyBindMap.put(REPEAT_INCREMENTAL_SEARCH, "ctrl shift F");
keyBindMap.put(CLOSE_DIALOG, "ESCAPE");
keyBindMap.put(CLOSE_ENTRY_EDITOR, "ESCAPE");
keyBindMap.put(CLOSE_PREAMBLE_EDITOR, "ESCAPE");
Expand Down
99 changes: 46 additions & 53 deletions src/main/java/net/sf/jabref/gui/search/JSearchTextField.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package net.sf.jabref.gui.search;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JTextField;
import javax.swing.UIManager;


/**
* A text field which displays a predefined text (e.g. "Search") if it has not the focus and no text is entered.
* Implementation based on https://gmigdos.wordpress.com/2010/03/30/java-a-custom-jtextfield-for-searching/
Expand All @@ -20,51 +13,51 @@ public class JSearchTextField extends JTextField implements FocusListener {

private String textWhenNotFocused;

public JSearchTextField() {
super();
this.setEditable(true);
this.setText("");
this.textWhenNotFocused = "Search...";
this.addFocusListener(this);
}

public String getTextWhenNotFocused() {
return this.textWhenNotFocused;
}

public void setTextWhenNotFocused(String newText) {
this.textWhenNotFocused = newText;
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);

if (!this.hasFocus() && this.getText().isEmpty()) {
int height = this.getHeight();
Font prev = g.getFont();
Color prevColor = g.getColor();
g.setColor(UIManager.getColor("textInactiveText"));
int h = g.getFontMetrics().getHeight();
int textBottom = (((height - h) / 2) + h) - 4;
int x = this.getInsets().left;
Graphics2D g2d = (Graphics2D) g;
RenderingHints hints = g2d.getRenderingHints();
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.drawString(textWhenNotFocused, x, textBottom);
g2d.setRenderingHints(hints);
g.setFont(prev);
g.setColor(prevColor);
}
}

@Override
public JSearchTextField() {
super();
this.setEditable(true);
this.setText("");
this.textWhenNotFocused = "Search...";
this.addFocusListener(this);
}

public String getTextWhenNotFocused() {
return this.textWhenNotFocused;
}

public void setTextWhenNotFocused(String newText) {
this.textWhenNotFocused = newText;
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);

if (!this.hasFocus() && this.getText().isEmpty()) {
int height = this.getHeight();
Font prev = g.getFont();
Color prevColor = g.getColor();
g.setColor(UIManager.getColor("textInactiveText"));
int h = g.getFontMetrics().getHeight();
int textBottom = (((height - h) / 2) + h) - 4;
int x = this.getInsets().left;
Graphics2D g2d = (Graphics2D) g;
RenderingHints hints = g2d.getRenderingHints();
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.drawString(textWhenNotFocused, x, textBottom);
g2d.setRenderingHints(hints);
g.setFont(prev);
g.setColor(prevColor);
}
}

@Override
public void focusGained(FocusEvent e) {
this.repaint();
}
this.repaint();
}

@Override
@Override
public void focusLost(FocusEvent e) {
this.repaint();
}
this.repaint();
}
}

0 comments on commit a1b231e

Please sign in to comment.