diff --git a/build/darcula.jar b/build/darcula.jar index 70761db..e4ccf49 100644 Binary files a/build/darcula.jar and b/build/darcula.jar differ diff --git a/src/com/bulenkov/darcula/ui/DarculaPasswordFieldUI.java b/src/com/bulenkov/darcula/ui/DarculaPasswordFieldUI.java index 4e16d3f..d61967d 100755 --- a/src/com/bulenkov/darcula/ui/DarculaPasswordFieldUI.java +++ b/src/com/bulenkov/darcula/ui/DarculaPasswordFieldUI.java @@ -25,27 +25,40 @@ import javax.swing.text.JTextComponent; import java.awt.*; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; /** * @author Konstantin Bulenkov */ public class DarculaPasswordFieldUI extends BasicPasswordFieldUI { + private FocusListener myFocusListener = new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + getComponent().repaint(); + } + + @Override + public void focusLost(FocusEvent e) { + getComponent().repaint(); + } + }; + @SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"}) public static ComponentUI createUI(final JComponent c) { - c.addFocusListener(new FocusAdapter() { - @Override - public void focusGained(FocusEvent e) { - c.repaint(); - } + return new DarculaPasswordFieldUI(); + } - @Override - public void focusLost(FocusEvent e) { - c.repaint(); - } - }); + @Override + protected void installListeners() { + super.installListeners(); + getComponent().addFocusListener(myFocusListener); + } - return new DarculaPasswordFieldUI(); + @Override + protected void uninstallListeners() { + getComponent().removeFocusListener(myFocusListener); + super.uninstallListeners(); } @Override diff --git a/src/com/bulenkov/darcula/ui/DarculaTextFieldUI.java b/src/com/bulenkov/darcula/ui/DarculaTextFieldUI.java index 6e51f47..31b4ae0 100755 --- a/src/com/bulenkov/darcula/ui/DarculaTextFieldUI.java +++ b/src/com/bulenkov/darcula/ui/DarculaTextFieldUI.java @@ -32,62 +32,78 @@ import java.awt.event.*; * @author Konstantin Bulenkov */ public class DarculaTextFieldUI extends BasicTextFieldUI { + + private final FocusListener myFocusListener = new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + getComponent().repaint(); + } + + @Override + public void focusLost(FocusEvent e) { + getComponent().repaint(); + } + }; + + private final MouseMotionListener myMouseMotionListener = new MouseMotionAdapter() { + @Override + public void mouseMoved(MouseEvent e) { + if (getComponent() != null && isSearchField(getComponent())) { + if (getActionUnder(e) != null) { + getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + } else { + getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); + } + } + } + }; + + private final MouseListener myMouseListener = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (isSearchField(getComponent())) { + final SearchAction action = getActionUnder(e); + if (action != null) { + switch (action) { + case POPUP: + showSearchPopup(); + break; + case CLEAR: + getComponent().setText(""); + break; + } + e.consume(); + } + } + } + }; + private enum SearchAction {POPUP, CLEAR} - private final JTextField myTextField; protected JLabel myClearIcon; protected JLabel myRecentIcon; - public DarculaTextFieldUI(JTextField textField) { - myTextField = textField; - } - @SuppressWarnings("MethodOverridesStaticMethodOfSuperclass") public static ComponentUI createUI(final JComponent c) { - final DarculaTextFieldUI ui = new DarculaTextFieldUI((JTextField)c); - c.addFocusListener(new FocusAdapter() { - @Override - public void focusGained(FocusEvent e) { - c.repaint(); - } + return new DarculaTextFieldUI(); + } - @Override - public void focusLost(FocusEvent e) { - c.repaint(); - } - }); - c.addMouseMotionListener(new MouseMotionAdapter() { - @Override - public void mouseMoved(MouseEvent e) { - if (ui.getComponent() != null && isSearchField(c)) { - if (ui.getActionUnder(e) != null) { - c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - } else { - c.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); - } - } - } - }); - c.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - if (isSearchField(c)) { - final SearchAction action = ui.getActionUnder(e); - if (action != null) { - switch (action) { - case POPUP: - ui.showSearchPopup(); - break; - case CLEAR: - ((JTextField)c).setText(""); - break; - } - e.consume(); - } - } - } - }); - return ui; + @Override + protected void installListeners() { + super.installListeners(); + final JTextComponent c = getComponent(); + c.addFocusListener(myFocusListener); + c.addMouseMotionListener(myMouseMotionListener); + c.addMouseListener(myMouseListener); + } + + @Override + protected void uninstallListeners() { + final JTextComponent c = getComponent(); + c.removeMouseListener(myMouseListener); + c.removeMouseMotionListener(myMouseMotionListener); + c.removeFocusListener(myFocusListener); + super.uninstallListeners(); } protected void showSearchPopup() { @@ -110,7 +126,7 @@ public class DarculaTextFieldUI extends BasicTextFieldUI { } protected Rectangle getDrawingRect() { - final JTextComponent c = myTextField; + final JTextComponent c = getComponent(); final Insets i = c.getInsets(); final int x = i.right - 4 - 16; final int y = i.top - 3;