2 Copyright (C) 2003 Morten O. Alver, Nizar N. Batada
4 All programs in this directory and
5 subdirectories are published under the GNU General Public License as
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 Further information about the GNU GPL is available at:
24 http://www.gnu.org/copyleft/gpl.ja.html
27 package net.sf.jabref;
29 import java.awt.Color;
31 import javax.swing.JComponent;
32 import javax.swing.JLabel;
33 import javax.swing.JTextField;
35 public class FieldTextField extends JTextField implements FieldEditor {
37 protected String fieldName;
39 protected JLabel label;
41 public FieldTextField(String fieldName_, String content, boolean changeColorOnFocus) {
46 // Add the global focus listener, so a menu item can see if this field
48 // an action was called.
49 addFocusListener(Globals.focusListener);
50 if (changeColorOnFocus)
51 addFocusListener(new FieldEditorFocusListener());
52 fieldName = fieldName_;
53 label = new FieldNameLabel(" " + Util.nCase(fieldName) + " ");
54 // label = new JLabel(" "+Util.nCase(fieldName)+" ", JLabel.CENTER);
55 // label.setBorder(BorderFactory.createEtchedBorder());
56 setBackground(GUIGlobals.validFieldBackground);
57 // label.setOpaque(true);
58 // if ((content != null) && (content.length() > 0))
59 // label.setForeground(GUIGlobals.validFieldColor);
60 // At construction time, the field can never have an invalid value.
61 // else label.setForeground(GUIGlobals.nullFieldColor);
63 FieldTextMenu popMenu = new FieldTextMenu(this);
64 this.addMouseListener(popMenu);
65 label.addMouseListener(popMenu);
68 public void append(String text) {
69 setText(getText() + text);
72 public String getFieldName() {
76 public JLabel getLabel() {
80 public void setLabelColor(Color c) {
81 label.setForeground(c);
82 throw new NullPointerException("ok");
85 public JComponent getPane() {
89 public JComponent getTextComponent() {
94 public void updateFont() {
95 setFont(GUIGlobals.CURRENTFONT);
98 /*public void paint(Graphics g) {
99 Graphics2D g2 = (Graphics2D) g;
101 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
105 public void paste(String textToInsert) {
106 int sel = getSelectionEnd() - getSelectionStart();
108 int cPos = getCaretPosition();
111 replaceSelection(textToInsert);