-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Changes from 1 commit
789bf72
6f35ff1
cf6afe5
1dc5249
cf41a69
f6f82d5
31a5612
24f2467
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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); | ||
|
||
|
@@ -35,13 +34,15 @@ public class JTextAreaWithHighlighting extends JTextArea implements SearchQueryH | |
private UndoManager undo; | ||
|
||
public JTextAreaWithHighlighting() { | ||
super(); | ||
setupUndoRedo(); | ||
setupPasteListener(); | ||
this(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add javadoc comments at least describing Please rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
super(text, title); | ||
setupUndoRedo(); | ||
setupPasteListener(); | ||
} | ||
|
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you could rename some variables here. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
} |
There was a problem hiding this comment.
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 writeet 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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"