password field and small fixes

This commit is contained in:
Konstantin Bulenkov
2012-10-19 02:58:53 +02:00
parent 0cd44e5f3b
commit f61be0864f
4 changed files with 87 additions and 68 deletions
@@ -29,8 +29,10 @@ Focus.color=ff0000
TextField.background=737373
TextFieldUI=com.intellij.ide.ui.laf.darcula.ui.DarculaTextFieldUI
TextField.border=com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder
PasswordField.background=737373
PasswordFieldUI=com.intellij.ide.ui.laf.darcula.ui.DarculaPasswordFieldUI
PasswordField.border=com.intellij.ide.ui.laf.darcula.ui.DarculaTextBorder
PasswordField.background=aaaaaa
CheckBoxUI=com.intellij.ide.ui.laf.darcula.ui.DarculaCheckBoxUI
ComboBoxUI=com.intellij.ide.ui.laf.darcula.ui.DarculaComboBoxUI
@@ -25,11 +25,8 @@ import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicComboBoxEditor;
import javax.swing.plaf.basic.BasicComboBoxUI;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.geom.Path2D;
/**
@@ -48,58 +45,7 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border {
return new DarculaComboBoxUI(((JComboBox)c));
}
@Override
protected ComboBoxEditor createEditor() {
final ComboBoxEditor ed = new BasicComboBoxEditor.UIResource(){
@Override
protected JTextField createEditorComponent() {
return super.createEditorComponent();
}
};
if (ed != null) {
ed.getEditorComponent().addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
myComboBox.repaint();
}
@Override
public void focusLost(FocusEvent e) {
myComboBox.repaint();
}
});
}
return ed;
}
@Override
public void paint(Graphics g, JComponent c) {
hasFocus = comboBox.hasFocus();
final GraphicsConfig config = new GraphicsConfig(g);
if ( !comboBox.isEditable() ) {
Rectangle r = rectangleForCurrentValue();
paintCurrentValueBackground(g,r,hasFocus);
paintCurrentValue(g,r,hasFocus);
g.setColor(ColorUtil.fromHex("939393").darker());
final int xxx = c.getWidth() - c.getBorder().getBorderInsets(c).right - arrowButton.getWidth();
g.drawLine(xxx, hasFocus ? 2 : 1, xxx, c.getHeight() - (hasFocus ? 3 : 0));
} else {
g.setColor(editor.getBackground());
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
g.fillRoundRect(1, 1, c.getWidth() - 2, c.getHeight() - 2, 5, 5);
g.setColor(ColorUtil.fromHex("939393"));
final int xxx = editor.getWidth() + c.getBorder().getBorderInsets(c).left;
g.drawLine(xxx, hasFocus ? 3 : 1, xxx, c.getHeight() - (hasFocus ? 2 : 0));
editor.repaint();
}
config.restore();
}
protected JButton createArrowButton() {
protected JButton createArrowButton() {
final Color bg = myComboBox.getBackground();
final Color fg = myComboBox.getForeground();
JButton button = new BasicArrowButton(SwingConstants.SOUTH, bg, fg, fg, fg) {
@@ -126,8 +72,8 @@ public class DarculaComboBoxUI extends BasicComboBoxUI implements Border {
path.lineTo(xU+1, yU + 2);
path.closePath();
g.fill(path);
g.setColor(ColorUtil.fromHex("939393").darker());
g.drawLine(0, -1, 0 , h);
g.setColor(ColorUtil.fromHex("939393"));
g.drawLine(0, 0, 0 , h);
//paintTriangle(g, w / 2, h / 2, 5, SOUTH, myComboBox.isEnabled());
//g.setColor(ColorUtil.fromHex("939393"));
//g.drawLine(0,0, 0,h);
@@ -0,0 +1,81 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ide.ui.laf.darcula.ui;
import com.intellij.openapi.ui.GraphicsConfig;
import com.intellij.util.ui.JBInsets;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicPasswordFieldUI;
import javax.swing.text.JTextComponent;
import java.awt.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
/**
* @author Konstantin Bulenkov
*/
public class DarculaPasswordFieldUI extends BasicPasswordFieldUI {
@SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"})
public static ComponentUI createUI(final JComponent c) {
c.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
c.repaint();
}
@Override
public void focusLost(FocusEvent e) {
c.repaint();
}
});
return new DarculaPasswordFieldUI();
}
@Override
protected void paintBackground(Graphics g) {
final JTextComponent c = getComponent();
final Container parent = c.getParent();
if (parent != null) {
g.setColor(parent.getBackground());
g.fillRect(0, 0, c.getWidth(), c.getHeight());
}
final Border border = c.getBorder();
if (border instanceof DarculaTextBorder) {
g.setColor(c.getBackground());
final int width = c.getWidth();
final int height = c.getHeight();
final JBInsets insets = ((DarculaTextBorder)border).getBorderInsets(c);
if (c.hasFocus()) {
final GraphicsConfig config = new GraphicsConfig(g);
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
((Graphics2D)g).setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
g.fillRoundRect(insets.left - 5, insets.top - 2, width - insets.width() + 10, height - insets.height() + 6, 5, 5);
config.restore();
}
else {
g.fillRect(insets.left - 5, insets.top - 2, width - insets.width() + 12, height - insets.height() + 6);
}
} else {
super.paintBackground(g);
}
}
}
@@ -48,16 +48,6 @@ public class DarculaTextFieldUI extends BasicTextFieldUI {
return new DarculaTextFieldUI();
}
@Override
protected void installDefaults() {
super.installDefaults();
}
@Override
protected void paintSafely(Graphics g) {
super.paintSafely(g);
}
@Override
protected void paintBackground(Graphics g) {
final JTextComponent c = getComponent();