forked from fanruan/design
hzzz
7 years ago
3 changed files with 38 additions and 50 deletions
@ -1,56 +1,43 @@ |
|||||||
package com.fr.design.gui.itextarea; |
package com.fr.design.gui.itextarea; |
||||||
|
|
||||||
import java.awt.Color; |
|
||||||
import java.awt.Graphics; |
|
||||||
import java.awt.Graphics2D; |
|
||||||
import java.awt.Shape; |
|
||||||
import java.awt.event.MouseAdapter; |
|
||||||
import java.awt.event.MouseEvent; |
|
||||||
import java.awt.geom.RoundRectangle2D; |
|
||||||
|
|
||||||
import javax.swing.JComponent; |
|
||||||
import javax.swing.plaf.basic.BasicTextAreaUI; |
|
||||||
import javax.swing.text.JTextComponent; |
|
||||||
|
|
||||||
import com.fr.design.constants.UIConstants; |
import com.fr.design.constants.UIConstants; |
||||||
import com.fr.design.utils.gui.GUIPaintUtils; |
import com.fr.design.utils.gui.GUIPaintUtils; |
||||||
|
|
||||||
public class UITextAreaUI extends BasicTextAreaUI { |
import javax.swing.*; |
||||||
protected boolean isRollOver; |
import javax.swing.plaf.basic.BasicTextAreaUI; |
||||||
private JComponent textField; |
import java.awt.*; |
||||||
|
import java.awt.event.MouseAdapter; |
||||||
public UITextAreaUI(final JComponent textField) { |
import java.awt.event.MouseEvent; |
||||||
super(); |
|
||||||
this.textField = textField; |
|
||||||
this.textField.addMouseListener(new MouseAdapter() { |
|
||||||
@Override |
|
||||||
public void mouseEntered(MouseEvent e) { |
|
||||||
isRollOver = true; |
|
||||||
textField.repaint(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void mouseExited(MouseEvent e) { |
|
||||||
isRollOver = false; |
|
||||||
textField.repaint(); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
public class UITextAreaUI extends BasicTextAreaUI { |
||||||
protected void paintBackground(Graphics g) { |
protected boolean isRollOver; |
||||||
JTextComponent editor = getComponent(); |
private JComponent textField; |
||||||
int width = editor.getWidth(); |
|
||||||
int height = editor.getHeight(); |
public UITextAreaUI(final JComponent textField) { |
||||||
Graphics2D g2d = (Graphics2D)g; |
super(); |
||||||
g2d.clearRect(0, 0, width, height); |
this.textField = textField; |
||||||
if(isRollOver && textField.isEnabled() && ((UITextArea)textField).isEditable()) { |
this.textField.addMouseListener(new MouseAdapter() { |
||||||
Shape shape = new RoundRectangle2D.Double(1, 1, width - 3, height - 3, UIConstants.ARC, UIConstants.ARC); |
@Override |
||||||
GUIPaintUtils.paintBorderShadow(g2d, 3, shape, UIConstants.HOVER_BLUE, Color.WHITE); |
public void mouseEntered(MouseEvent e) { |
||||||
} else { |
isRollOver = true; |
||||||
g2d.setColor(UIConstants.LINE_COLOR); |
textField.repaint(); |
||||||
g2d.drawRoundRect(1, 1, width - 2, height - 2, UIConstants.ARC, UIConstants.ARC); |
} |
||||||
} |
|
||||||
} |
@Override |
||||||
|
public void mouseExited(MouseEvent e) { |
||||||
|
isRollOver = false; |
||||||
|
textField.repaint(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
public void paintBorder(Graphics2D g2d, int width, int height, boolean isRound, int rectDirection) { |
||||||
|
if (isRollOver && textField.isEnabled()) { |
||||||
|
g2d.setColor(UIConstants.TEXT_FILED_BORDER_SELECTED); |
||||||
|
g2d.drawRect(0, 0, width - 1, height - 1); |
||||||
|
} else { |
||||||
|
GUIPaintUtils.drawBorder(g2d, 0, 0, width, height, isRound, rectDirection); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
} |
} |
Loading…
Reference in new issue