package com.vci.client.ui.swing.components;
|
|
|
import java.awt.Color;
|
import java.awt.Graphics;
|
import java.awt.event.FocusEvent;
|
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseListener;
|
|
import javax.swing.JTextArea;
|
import javax.swing.text.Document;
|
|
import com.vci.client.ui.swing.VCISwingUtil;
|
|
/**
|
*
|
* <p>Title: </p>
|
* <p>Description: </p>
|
* <p>Copyright: Copyright (c) 2012</p>
|
* <p>Company: VCI</p>
|
* @author xchao
|
* @time 2012-5-10
|
* @version 1.0
|
*/
|
public class VCIJTextArea extends JTextArea implements MouseListener{
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 2642791569725874464L;
|
public VCIJTextArea(boolean required) {
|
this("", required);
|
}
|
public VCIJTextArea(String text, boolean required) {
|
this(text);
|
setRequired(required);
|
}
|
|
public VCIJTextArea() {
|
this("");
|
}
|
|
public VCIJTextArea(String text) {
|
this(null, text, 0, 0);
|
}
|
|
public VCIJTextArea(Document doc) {
|
this(doc, null, 0, 0);
|
}
|
|
public VCIJTextArea(int rows, int columns) {
|
this(null, null, rows, columns);
|
}
|
|
public VCIJTextArea(String text, int rows, int columns) {
|
this(null, text, rows, columns);
|
}
|
|
public VCIJTextArea(Document doc, String text, int rows, int columns) {
|
super(doc, text, rows, columns);
|
customConstructor();
|
}
|
|
private void customConstructor(){
|
setFont(VCISwingUtil.FONT_DEFAULT);
|
addMouseListener(this);
|
VCIJTextContextMenu.register(this);
|
}
|
private boolean required = false;
|
|
public boolean isRequired() {
|
return required;
|
}
|
|
public void setRequired(boolean required) {
|
this.required = required;
|
}
|
@Override
|
public void paint(Graphics g){
|
super.paint(g);
|
if(isRequired()) {
|
drawRequiredFlag(g);
|
}
|
}
|
|
private void drawRequiredFlag(Graphics g){
|
int x = getWidth() - 9;
|
int y = 1;
|
g.setColor(Color.RED);
|
g.fillArc(x, y, 7, 7, 0, 360);
|
// int x = getWidth() - 10;
|
// int y = 10;
|
// g.setColor(Color.RED);
|
// g.drawString("*", x, y);
|
}
|
|
private Object obj = null;
|
public Object getObj() {
|
return obj;
|
}
|
public void setObj(Object obj) {
|
this.obj = obj;
|
}
|
|
private boolean hasFocus = false;
|
public void mouseClicked(MouseEvent e) {
|
hasFocus = true;
|
setBackground(VCISwingUtil.JTEXT_FIELD_MOUSE_CLICK_BACKGROUND_COLOR);
|
setBorder(VCISwingUtil.JTEXT_FIELD_BORDER_MOUSE_CLICKED);
|
}
|
|
public void mousePressed(MouseEvent e) {
|
// TODO Auto-generated method stub
|
|
}
|
|
public void mouseReleased(MouseEvent e) {
|
// TODO Auto-generated method stub
|
|
}
|
|
public void mouseEntered(MouseEvent e) {
|
setBorder(VCISwingUtil.JTEXT_FIELD_BORDER_MOUSE_ENTERED);
|
}
|
|
@Override
|
public void processFocusEvent(FocusEvent event){
|
super.processFocusEvent(event);
|
if(hasFocus) {
|
hasFocus = false;
|
setBorder(VCISwingUtil.JTEXT_FIELD_BORDER_MOUSE_EXITED);
|
setBackground(VCISwingUtil.JTEXT_FIELD_MOUSE_EXITED_BACKGROUND_COLOR);
|
}
|
}
|
|
public void mouseExited(MouseEvent e) {
|
if(hasFocus){
|
setBorder(VCISwingUtil.JTEXT_FIELD_BORDER_MOUSE_ENTERED);
|
}else{
|
setBorder(VCISwingUtil.JTEXT_FIELD_BORDER_MOUSE_EXITED);
|
}
|
}
|
|
}
|