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

Added gray background text to authors field to assist newcomers #2147

Merged
merged 8 commits into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Improve language quality of the German translation of shared database
- Change "Recent files" to "Recent databases" to keep the file menu consistent
- Customized importer files need to be slightly changed since the class `ImportFormat` was renamed to `Importer`
- [koppor#61](https://github.com/koppor/jabref/issues/61) Display gray background text in authors field to assist newcomers

### Fixed
- Fixed [#2092](https://github.com/JabRef/jabref/issues/2092): "None"-button in date picker clears the date field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import net.sf.jabref.gui.keyboard.KeyBinding;
import net.sf.jabref.gui.util.GUIUtil;
import net.sf.jabref.logic.autocompleter.AutoCompleter;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.model.entry.FieldProperty;
import net.sf.jabref.model.entry.InternalBibtexFields;

Expand Down Expand Up @@ -151,7 +153,8 @@ private void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField
false);
defaultHeight = 0;
} else {
fieldEditor = new TextArea(field, null);
String prompt = (field.equals(FieldName.AUTHOR)) ? Localization.lang("Firstname Lastname and Firstname and Lastname and others") : "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong text

It should be Firstname Lastname and Firstname Lastname. and others must not be translated as it is a fixed bibtex term used to write et al. or something else as configured in the bibtex style.

The rendering of your example is
Lastname, F.; Firstname; Lastname & others
but it should be
Lastname, F.; Lastname, F. & others

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, as our "normalize to bibtex name format" formatter will produce "Last, First and Last, First and other", the text should be in this form.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to Localization.lang("Firstname Lastname and Firstname Lastname") + " and others"

fieldEditor = new TextArea(field, null, prompt);
bPanel.frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener((TextArea) fieldEditor);
defaultHeight = fieldEditor.getPane().getPreferredSize().height;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.regex.Pattern;

import javax.swing.AbstractAction;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
Expand All @@ -26,7 +25,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class JTextAreaWithHighlighting extends JTextArea implements SearchQueryHighlightListener {
public class JTextAreaWithHighlighting extends JTextAreaWithUnfocusedText implements SearchQueryHighlightListener {

private static final Log LOGGER = LogFactory.getLog(JTextAreaWithHighlighting.class);

Expand All @@ -35,13 +34,15 @@ public class JTextAreaWithHighlighting extends JTextArea implements SearchQueryH
private UndoManager undo;

public JTextAreaWithHighlighting() {
super();
setupUndoRedo();
setupPasteListener();
this(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not "" instead of null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

public JTextAreaWithHighlighting(String text) {
this(text, "");
}

JTextAreaWithHighlighting(String text) {
super(text);
public JTextAreaWithHighlighting(String text, String title) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add javadoc comments at least describing title. Isn't title the textWhenNotFocused

Please rename textWhenNotFocused to placeholder to be in line with HTML5 --> http://www.w3schools.com/tags/att_input_placeholder.asp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

super(text, title);
setupUndoRedo();
setupPasteListener();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package net.sf.jabref.gui.fieldeditors;

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

import javax.swing.JTextArea;
import javax.swing.UIManager;

import net.sf.jabref.gui.util.component.JTextFieldWithUnfocusedText;

/**
* A text area which displays a predefined text the same way as {@link JTextFieldWithUnfocusedText} does.
*/
public class JTextAreaWithUnfocusedText extends JTextArea implements FocusListener {

private final String textWhenNotFocused;

public JTextAreaWithUnfocusedText() {
this("");
}

public JTextAreaWithUnfocusedText(String content, String textWhenNotFocused) {
this(textWhenNotFocused);
setText(content);
}

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

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

if (!this.hasFocus() && this.getText().isEmpty()) {
Font prev = g.getFont();
Color prevColor = g.getColor();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could rename some variables here.
g- > graphic
h -> height

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

g.setColor(UIManager.getColor("textInactiveText"));
int h = g.getFontMetrics().getHeight();
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, h + this.getInsets().top);
g2d.setRenderingHints(hints);
g.setFont(prev);
g.setColor(prevColor);
}
}

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

@Override
public void focusLost(FocusEvent e) {
this.repaint();
}
}
6 changes: 5 additions & 1 deletion src/main/java/net/sf/jabref/gui/fieldeditors/TextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public class TextArea extends JTextAreaWithHighlighting implements FieldEditor {


public TextArea(String fieldName, String content) {
super(content);
this(fieldName, content, "");
}

public TextArea(String fieldName, String content, String title) {
super(content, title);


updateFont();
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/net/sf/jabref/gui/fieldeditors/TextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.text.Document;
import javax.swing.undo.CannotRedoException;
Expand All @@ -20,6 +19,7 @@
import net.sf.jabref.gui.actions.PasteAction;
import net.sf.jabref.gui.autocompleter.AutoCompleteListener;
import net.sf.jabref.gui.fieldeditors.contextmenu.FieldTextMenu;
import net.sf.jabref.gui.util.component.JTextFieldWithUnfocusedText;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand All @@ -28,7 +28,7 @@
* An implementation of the FieldEditor backed by a JTextField. Used for single-line input, only BibTex key at the
* moment?!
*/
public class TextField extends JTextField implements FieldEditor {
public class TextField extends JTextFieldWithUnfocusedText implements FieldEditor {

private static final Log LOGGER = LogFactory.getLog(TextField.class);

Expand All @@ -39,7 +39,11 @@ public class TextField extends JTextField implements FieldEditor {


public TextField(String fieldName, String content, boolean changeColorOnFocus) {
super(content);
this(fieldName, content, changeColorOnFocus, "");
}

public TextField(String fieldName, String content, boolean changeColorOnFocus, String title) {
super(content, title);

setupPasteListener();
setupUndoRedo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class JTextFieldWithUnfocusedText extends JTextField implements FocusList

private final String textWhenNotFocused;

public JTextFieldWithUnfocusedText(String content, String textWhenNotFocused) {
this(textWhenNotFocused);
setText(content);
}

public JTextFieldWithUnfocusedText(String textWhenNotFocused) {
super();
this.setEditable(true);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=
Copy_BibTeX_key_and_link=
empty_BibTeX_key=
BibLaTeX_field_only=
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=Die_übergebene_Such-ID_ist_leer.
Copy_BibTeX_key_and_link=BibTeX-Key_und_Link_kopieren
empty_BibTeX_key=Leerer_BibTeX-Key
BibLaTeX_field_only=Nur_ein_BibLaTeX-Feld
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=The_given_search_ID_was_empty.
Copy_BibTeX_key_and_link=Copy_BibTeX_key_and_link
empty_BibTeX_key=empty_BibTeX_key
BibLaTeX_field_only=BibLaTeX_field_only
Firstname_Lastname_and_Firstname_and_Lastname_and_others=Firstname_Lastname_and_Firstname_and_Lastname_and_others
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=
Copy_BibTeX_key_and_link=
empty_BibTeX_key=
BibLaTeX_field_only=
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=
Copy_BibTeX_key_and_link=
empty_BibTeX_key=
BibLaTeX_field_only=
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=L'Identifiant_de_recherche_entré_était_vide.
Copy_BibTeX_key_and_link=Copier_la_clef_BibTeX_et_le_lien
empty_BibTeX_key=Clef_BibTeX_vide
BibLaTeX_field_only=Champ_BibLaTeX_uniquement
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=
Copy_BibTeX_key_and_link=
empty_BibTeX_key=
BibLaTeX_field_only=
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=L'ID_della_ricerca_usato_era_vuoto.
Copy_BibTeX_key_and_link=Copia_la_chiave_e_il_link_BibTeX
empty_BibTeX_key=chiave_BibTeX_vuota
BibLaTeX_field_only=campo_solo_BibLaTeX
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=
Copy_BibTeX_key_and_link=
empty_BibTeX_key=
BibLaTeX_field_only=
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=
Copy_BibTeX_key_and_link=
empty_BibTeX_key=
BibLaTeX_field_only=
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=
Copy_BibTeX_key_and_link=
empty_BibTeX_key=
BibLaTeX_field_only=
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=
Copy_BibTeX_key_and_link=
empty_BibTeX_key=
BibLaTeX_field_only=
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=
Copy_BibTeX_key_and_link=
empty_BibTeX_key=
BibLaTeX_field_only=
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=
Copy_BibTeX_key_and_link=
empty_BibTeX_key=
BibLaTeX_field_only=
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=Verilen_arama_IDsi_boştu.
Copy_BibTeX_key_and_link=BibTeX_anahtarı_ve_bağlantısını_kopyala
empty_BibTeX_key=boş_BibTeX_anahtarı
BibLaTeX_field_only=Yalnızca_BibLaTeX_alanı
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_vi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=
Copy_BibTeX_key_and_link=
empty_BibTeX_key=
BibLaTeX_field_only=
Firstname_Lastname_and_Firstname_and_Lastname_and_others=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2299,3 +2299,4 @@ The_given_search_ID_was_empty.=
Copy_BibTeX_key_and_link=
empty_BibTeX_key=
BibLaTeX_field_only=
Firstname_Lastname_and_Firstname_and_Lastname_and_others=