Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez committed Sep 2, 2015
1 parent 4cfeb6d commit f93a350
Show file tree
Hide file tree
Showing 21 changed files with 71 additions and 319 deletions.
45 changes: 15 additions & 30 deletions src/main/java/net/sf/jabref/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@
import javax.swing.undo.CannotUndoException;

import net.sf.jabref.DatabaseChangeEvent.ChangeType;
import net.sf.jabref.autocompleter.AbstractAutoCompleter;
import net.sf.jabref.autocompleter.AutoCompleter;
import net.sf.jabref.autocompleter.AutoCompleterFactory;
import net.sf.jabref.autocompleter.ContentAutoCompleters;
import net.sf.jabref.autocompleter.NameFieldAutoCompleter;
import net.sf.jabref.collab.ChangeScanner;
import net.sf.jabref.collab.FileUpdateListener;
import net.sf.jabref.collab.FileUpdatePanel;
Expand All @@ -83,7 +81,6 @@
import net.sf.jabref.external.WriteXMPAction;
import net.sf.jabref.groups.GroupSelector;
import net.sf.jabref.groups.GroupTreeNode;
import net.sf.jabref.gui.AutoCompleteListener;
import net.sf.jabref.gui.CleanUpAction;
import net.sf.jabref.gui.FileDialogs;
import net.sf.jabref.gui.FileListEntry;
Expand Down Expand Up @@ -134,7 +131,6 @@

import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down Expand Up @@ -176,18 +172,8 @@ public class BasePanel extends JPanel implements ClipboardOwner, FileUpdateListe
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints con = new GridBagConstraints();

// Hashtable indexing the only search auto completer
// required for the SearchAutoCompleterUpdater
private AutoCompleter searchAutoCompleter;


private ContentAutoCompleters autoCompleters = null; //= new HashMap<String, AbstractAutoCompleter>();
// Hashtable that holds as keys the names of the fields where
// autocomplete is active, and references to the autocompleter objects.

private NameFieldAutoCompleter searchCompleter = null;

//private AutoCompleteListener searchCompleteListener = null;
// AutoCompleter used in the search bar
private AutoCompleter<String> searchAutoCompleter;

// The undo manager.
public final CountingUndoManager undoManager = new CountingUndoManager(this);
Expand Down Expand Up @@ -261,11 +247,12 @@ public class BasePanel extends JPanel implements ClipboardOwner, FileUpdateListe
private final HashMap<String, Object> actions = new HashMap<String, Object>();
private SidePaneManager sidePaneManager;

// Returns a collection of AutoCompleters, which are populated from the current database
public ContentAutoCompleters getAutoCompleters() {
return autoCompleters;
}

//private ContentAutoCompleters autoCompleters;
private ContentAutoCompleters autoCompleters;

public BasePanel(JabRefFrame frame, BibtexDatabase db, File file,
MetaData metaData, String encoding) {
Expand Down Expand Up @@ -982,6 +969,7 @@ public void action() {
});

actions.put("search", new BaseAction() {

@Override
public void action() {
frame.setSearchBarVisible(true);
Expand All @@ -990,24 +978,25 @@ public void action() {
});

actions.put("toggleSearch", new BaseAction() {

@Override
public void action() {
frame.setSearchBarVisible(! frame.searchBar.isVisible());
boolean on = frame.searchBar.isVisible();
if (on)
frame.getSearchBar().startSearch();
frame.setSearchBarVisible(! frame.searchBar.isVisible());
if (frame.searchBar.isVisible()) {
frame.getSearchBar().startSearch();
}
}
});

actions.put("incSearch", new BaseAction() {
@Override

@Override
public void action() {
frame.setSearchBarVisible(true);
frame.getSearchBar().startIncrementalSearch();
frame.setSearchBarVisible(true);
frame.getSearchBar().startIncrementalSearch();
}
});


// The action for copying the selected entry's key.
actions.put("copyKey", new BaseAction() {

Expand Down Expand Up @@ -2239,18 +2228,14 @@ else if (mode == BasePanel.SHOWING_EDITOR) {
}

public void updateSearchManager() {
//frame.getSearchManager().setAutoCompleteListener(searchCompleteListener);
frame.getSearchBar().setAutoCompleter(searchCompleter);
frame.getSearchBar().setAutoCompleter(searchAutoCompleter);
}

private void instantiateSearchAutoCompleter() {
searchAutoCompleter = AutoCompleterFactory.getFor("author", "editor");
for (BibtexEntry entry : database.getEntries()) {
searchAutoCompleter.addBibtexEntry(entry);
}

//searchCompleteListener = new AutoCompleteListener(searchAutoCompleter);
//searchCompleteListener.setConsumeEnterKey(false); // So you don't have to press Enter twice
}

/*
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/net/sf/jabref/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import javax.swing.event.ChangeListener;
import javax.swing.text.JTextComponent;

import net.sf.jabref.autocompleter.AbstractAutoCompleter;
import net.sf.jabref.autocompleter.AutoCompleter;
import net.sf.jabref.export.LatexFieldFormatter;
import net.sf.jabref.external.ExternalFilePanel;
Expand All @@ -68,7 +67,6 @@
import net.sf.jabref.undo.UndoableKeyChange;
import net.sf.jabref.undo.UndoableRemoveEntry;
import net.sf.jabref.util.Util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down Expand Up @@ -566,8 +564,7 @@ public void actionPerformed(ActionEvent actionEvent) {
private void setupSourcePanel() {
source = new JTextAreaWithHighlighting();
frame.getSearchBar().addSearchListener((SearchTextListener)source);
//frame.getSearchManager().addSearchListener((SearchTextListener) source);


/* {
private boolean antialias = Globals.prefs.getBoolean("antialias");
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/net/sf/jabref/EntryEditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import javax.swing.*;

import net.sf.jabref.autocompleter.AbstractAutoCompleter;
import net.sf.jabref.autocompleter.AutoCompleter;
import net.sf.jabref.gui.AutoCompleteListener;
import net.sf.jabref.gui.FileListEditor;
Expand Down Expand Up @@ -141,8 +140,7 @@ private void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField
}
else {
ta = new FieldTextArea(fields[i], null);
frame.getSearchBar().addSearchListener((FieldTextArea)ta);
//frame.getSearchManager().addSearchListener((FieldTextArea) ta);
frame.getSearchBar().addSearchListener((FieldTextArea) ta);
defaultHeight = ta.getPane().getPreferredSize().height;
}
//ta.addUndoableEditListener(bPanel.undoListener);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/FieldTextMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
import javax.swing.text.JTextComponent;

import net.sf.jabref.util.CaseChangeMenu;
import net.sf.jabref.util.GoogleUrlCleaner;
import net.sf.jabref.util.NameListNormalizer;
import net.sf.jabref.util.GoogleUrlCleaner;

public class FieldTextMenu implements MouseListener
{
Expand Down
54 changes: 15 additions & 39 deletions src/main/java/net/sf/jabref/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,6 @@ public void windowClosing(WindowEvent e) {

tabbedPane.setBorder(null);
tabbedPane.setForeground(GUIGlobals.inActiveTabbed);



//JLabel label = new JLabel ( "Close X" );
//add ( label, , 0 );

/*
* The following state listener makes sure focus is registered with the
Expand All @@ -636,7 +631,7 @@ public void stateChanged(ChangeEvent e) {
BasePanel bp = basePanel();
if (bp != null) {
groupToggle.setSelected(sidePaneManager.isComponentVisible("groups"));
searchToggle.setSelected(searchBar.isVisible());
searchToggle.setSelected(searchBar.isVisible());
previewToggle.setSelected(Globals.prefs.getBoolean(JabRefPreferences.PREVIEW_ENABLED));
highlightAny
.setSelected(Globals.prefs.getBoolean(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING_ANY));
Expand Down Expand Up @@ -834,7 +829,6 @@ private void tearDownJabRef(Vector<String> filenames) {
prefs.putBoolean(JabRefPreferences.WINDOW_MAXIMISED, (getExtendedState() == Frame.MAXIMIZED_BOTH));

prefs.putBoolean(JabRefPreferences.TOOLBAR_VISIBLE, tlb.isVisible());
//prefs.putBoolean(JabRefPreferences.SEARCH_PANEL_VISIBLE, sidePaneManager.isComponentVisible("search"));
// Store divider location for side pane:
int width = contentPane.getDividerLocation();
if (width > 0) {
Expand Down Expand Up @@ -867,6 +861,11 @@ private void tearDownJabRef(Vector<String> filenames) {
Globals.autoSaveManager.clearAutoSaves();
}

// Let the search interface store changes to prefs.
searchBar.updatePrefs();

prefs.flush();

// hide systray because the JVM can only shut down when no systray icon is shown
if(sysTray != null) {
sysTray.hide();
Expand Down Expand Up @@ -941,12 +940,7 @@ public boolean quit() {
}
}

// Let the search interface store changes to prefs.
searchBar.updatePrefs();

prefs.flush();

if (close) {
if (close) {
for (int i = 0; i < tabbedPane.getTabCount(); i++) {
if (baseAt(i).isSaving()) {
// There is a database still being saved, so we need to wait.
Expand Down Expand Up @@ -1034,27 +1028,8 @@ private void initLayout() {
tabbedPane.setAlignmentY(0.0f);
main.add(tabbedPane);

//UIManager.put("TabbedPane.tabAreaInsets", new Insets(2, 20, 0, 6) );
UIManager.put("TabbedPane.contentBorderInsets", new Insets(0,0,0,0));

/* tabbedPane.setUI(new BasicTabbedPaneUI() {
@Override
protected int calculateTabAreaHeight(int tab_placement, int run_count, int max_tab_height) {
//if (tabbedPane.getTabCount() > 1)
return super.calculateTabAreaHeight(tab_placement, run_count, max_tab_height);
//else
// return 0;
}
@Override
protected int calculateTabAreaWidth(int tabPlacement, int vertRunCount, int maxTabWidth) {
//if (tabbedPane.getTabCount() > 1)
// return super.calculateTabAreaWidth(tabPlacement, vertRunCount, maxTabWidth) + 2000;
//else
// return 0;
}
});
*/

contentPane.setRightComponent(main);
contentPane.setLeftComponent(sidePaneManager.getPanel());
sidePaneManager.updateView();
Expand Down Expand Up @@ -1103,7 +1078,7 @@ public BasePanel baseAt(int i) {
public void showBaseAt(int i) {
tabbedPane.setSelectedIndex(i);
}

public void showBasePanel(BasePanel bp) {
tabbedPane.setSelectedComponent(bp);
}
Expand Down Expand Up @@ -1894,15 +1869,16 @@ public void addTab(BasePanel bp, File file, boolean raisePanel) {
// the database came from an import and has to be treated somehow
// -> mark as changed
// This also happens internally at basepanel to ensure consistency
title = title + '*';
title = title + '*';
}
} else {
title = file.getName();
}
// idea: "<html><div style='padding:2px 5px;'>" + title + "</div></html>" instead of "title" to get some space around.
// However, this causes https://sourceforge.net/p/jabref/bugs/1293/
// Therefore, plain "title" is used
tabbedPane.add(title, bp);

// We use html here to get some padding around the title
// There are no closing tags since we would otherwise run in a bug
// see https://sourceforge.net/p/jabref/bugs/1293/
tabbedPane.add("<html><div style='padding:2px 5px;'>" + title, bp);
tabbedPane.setToolTipTextAt(tabbedPane.getTabCount() - 1,
file != null ? file.getAbsolutePath() : null);
if (raisePanel) {
Expand Down Expand Up @@ -2901,7 +2877,7 @@ public void setSearchBarVisible(boolean visible) {

// Copied from org.pushingpixels.lafwidget.LafWidgetSupport
// http://jarvis.cs.ucdavis.edu/code_essence/functions/5829321
// We need to use reflection to change the tabAreaInsets since a TappedPaneUI does not a support a setter for this
// We need to use reflection to change the tabAreaInsets since a TappedPaneUI does not provide an easier way to set this
private void setTabAreaInsets(JTabbedPane tabbedPane, Insets tabAreaInsets) {
TabbedPaneUI ui = tabbedPane.getUI();
if (ui instanceof BasicTabbedPaneUI) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@

import javax.swing.JTable;
import javax.swing.KeyStroke;
import javax.swing.text.StyledEditorKit.BoldAction;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/sf/jabref/SearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import javax.swing.event.CaretListener;

import net.sf.jabref.autocompleter.AbstractAutoCompleter;
import net.sf.jabref.autocompleter.AutoCompleter;
import net.sf.jabref.autocompleter.FuzzyTextSearchStrategy;
import net.sf.jabref.gui.AutoCompleteListener;
import net.sf.jabref.gui.SearchResultsDialog;
Expand Down Expand Up @@ -909,7 +910,7 @@ public JSearchTextField() {
// popup.add(list);
}

public void setAutoCompleter(AbstractAutoCompleter searchCompleter) {
public void setAutoCompleter(AutoCompleter<String> searchCompleter) {
autoCompleteSupport.setAutoCompleter(searchCompleter);
}

Expand Down Expand Up @@ -984,7 +985,7 @@ public void focusLost(FocusEvent e) {

}

public void setAutoCompleter(AbstractAutoCompleter searchCompleter) {
public void setAutoCompleter(AutoCompleter<String> searchCompleter) {
this.searchField.setAutoCompleter(searchCompleter);
updateKeyListeners(); // Should I really call this here?
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
/* Copyright (C) 2003-2012 JabRef contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.autocompleter;

import java.util.ArrayList;

import java.util.HashMap;
import java.util.SortedSet;
import java.util.TreeSet;

import net.sf.jabref.BibtexEntry;
import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;

/**
* An autocompleter delivers possible completions for a given string. There are
* different types of autocompleters for different use cases.
*
* Example: {@link NameFieldAutoCompleter}, {@link EntireFieldAutoCompleter}
*
* @author kahlert, cordes, olly98
* @see AutoCompleterFactory
*/
public abstract class AbstractAutoCompleter implements AutoCompleter<String> {

private static final int SHORTEST_WORD = 4;
Expand Down Expand Up @@ -96,8 +117,9 @@ public void addWordToIndex(String word) {
public boolean indexContainsWord(String word) {
return indexCaseInsensitive.contains(word.toLowerCase());
}

public String getPrefix() {
return "";
}

}
Loading

0 comments on commit f93a350

Please sign in to comment.