package com.vci.client.uif.engine.client.tableArea;
|
|
import java.awt.Color;
|
import java.awt.Dimension;
|
import java.awt.FontMetrics;
|
import java.awt.Graphics;
|
import java.awt.Graphics2D;
|
import java.awt.Image;
|
import java.awt.LinearGradientPaint;
|
import java.awt.Point;
|
import java.awt.Rectangle;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import javax.swing.AbstractButton;
|
import javax.swing.ButtonModel;
|
import javax.swing.Icon;
|
import javax.swing.JComponent;
|
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.metal.MetalButtonUI;
|
|
import com.vci.client.ui.swing.VCISwingUtil;
|
|
import sun.swing.SwingUtilities2;
|
|
/**
|
* 查询区域标题按钮ButtonUI
|
* @author VCI-STGK006
|
*
|
*/
|
public class JXToggleButtonUI extends MetalButtonUI {
|
|
protected static JXToggleButtonUI tbui = new JXToggleButtonUI();
|
|
public static ComponentUI createUI(JComponent c) {
|
return tbui;
|
}
|
|
@Override
|
protected void paintText(Graphics g, JComponent c, Rectangle textRect,
|
String text) {
|
AbstractButton b = (AbstractButton) c;
|
|
/* recount the letter position */
|
int width = b.getWidth();
|
textRect.x = textRect.x + (width - textRect.x - textRect.width) - 10;
|
|
int textWidth = 0;
|
ButtonModel model = b.getModel();
|
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
|
int mnemIndex = b.getDisplayedMnemonicIndex();
|
|
/* Draw the Text */
|
if (model.isEnabled()) {
|
/*** paint the text normally */
|
g.setColor(b.getForeground());
|
} else {
|
/*** paint the text disabled ***/
|
g.setColor(getDisabledTextColor());
|
}
|
SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemIndex,
|
textRect.x, textRect.y + fm.getAscent());
|
}
|
|
@Override
|
protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
|
/* draw the background*/
|
drawBackground(g, c);
|
|
AbstractButton b = (AbstractButton) c;
|
|
/* recount the icon position */
|
iconRect.x = iconRect.x + iconRect.x - 10;
|
|
ButtonModel model = b.getModel();
|
Icon icon = b.getIcon();
|
Icon tmpIcon = null;
|
|
if (icon == null) {
|
return;
|
}
|
|
Icon selectedIcon = null;
|
|
/* the fallback icon should be based on the selected state */
|
if (model.isSelected()) {
|
selectedIcon = (Icon) b.getSelectedIcon();
|
if (selectedIcon != null) {
|
icon = selectedIcon;
|
}
|
}
|
|
if (!model.isEnabled()) {
|
if (model.isSelected()) {
|
tmpIcon = (Icon) b.getDisabledSelectedIcon();
|
if (tmpIcon == null) {
|
tmpIcon = selectedIcon;
|
}
|
}
|
|
if (tmpIcon == null) {
|
tmpIcon = (Icon) b.getDisabledIcon();
|
}
|
} else if (model.isPressed() && model.isArmed()) {
|
tmpIcon = (Icon) b.getPressedIcon();
|
if (tmpIcon != null) {
|
// revert back to 0 offset
|
clearTextShiftOffset();
|
}
|
} else if (b.isRolloverEnabled() && model.isRollover()) {
|
if (model.isSelected()) {
|
tmpIcon = (Icon) b.getRolloverSelectedIcon();
|
if (tmpIcon == null) {
|
tmpIcon = selectedIcon;
|
}
|
}
|
|
if (tmpIcon == null) {
|
tmpIcon = (Icon) b.getRolloverIcon();
|
}
|
}
|
|
if (tmpIcon != null) {
|
icon = tmpIcon;
|
}
|
|
if (model.isPressed() && model.isArmed()) {
|
icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y
|
+ getTextShiftOffset());
|
} else {
|
icon.paintIcon(c, g, iconRect.x, iconRect.y);
|
}
|
}
|
|
/* Do nothing */
|
@Override
|
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect,
|
Rectangle textRect, Rectangle iconRect) {
|
// Rectangle focusRect = new Rectangle();
|
// String text = b.getText();
|
// boolean isIcon = b.getIcon() != null;
|
//
|
// // If there is text
|
// if (text != null && !text.equals("")) {
|
// if (!isIcon) {
|
// focusRect.setBounds(textRect);
|
// } else {
|
// focusRect.setBounds(iconRect.union(textRect));
|
// }
|
// }
|
// // If there is an icon and no text
|
// else if (isIcon) {
|
// focusRect.setBounds(iconRect);
|
// }
|
// /* r=245,g=165,b=16 */
|
// g.setColor(getFocusColor());
|
// g.drawRect((focusRect.x - 1), (focusRect.y - 1), focusRect.width + 1,
|
// focusRect.height + 1);
|
}
|
|
@Override
|
protected void paintButtonPressed(Graphics g, AbstractButton b) {
|
if (b.isContentAreaFilled()) {
|
Dimension size = b.getSize();
|
/* r=189,g=190,b=176 */
|
g.setColor(getSelectColor());
|
g.fillRect(0, 0, size.width, size.height);
|
}
|
}
|
|
private void drawBackground(Graphics g, JComponent c) {
|
JXToggleButton b = (JXToggleButton) c;
|
String title = b.getTitle();
|
String iconUrl = b.getIconUrl();
|
|
Graphics2D g2 = (Graphics2D)g;
|
Point start = new Point(0, 0);
|
Point end = new Point(0, c.getHeight());
|
float[] dist = { 0.0F, 0.45F, 0.5F, 1.0F };
|
Color[] colors = { VCISwingUtil.TBC1, VCISwingUtil.TBC2, VCISwingUtil.TBC3, VCISwingUtil.TBC4 };
|
LinearGradientPaint lgp = new LinearGradientPaint(start, end, dist,
|
colors);
|
g2.setPaint(lgp);
|
g2.fillRect(0, 0, c.getWidth(), c.getHeight());
|
g2.setColor(VCISwingUtil.FRAMECOLOR);
|
g2.drawRect(0, 0, c.getWidth() - 1, c.getHeight() - 1);
|
if (iconUrl != null && !iconUrl.equals("")) {
|
Image img = VCISwingUtil.createImageIcon(iconUrl).getImage();
|
if (img != null) {
|
g2.drawImage(img, 8, 4, 16, 16, null);
|
}
|
}
|
g2.setColor(VCISwingUtil.TEXTCOLOR);
|
g2.setFont(VCISwingUtil.Font12B);
|
g2.drawString(title, 30, 17);
|
}
|
}
|