?? tpopupmenu.java
字號:
/* * This source code is part of TWaver 1.3.1 * * SERVA Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * Copyright 2000-2005 SERVA Software, Inc. All rights reserved. */package demo;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import javax.swing.JPopupMenu;
import twaver.TWaverUtil;
public class TPopupMenu extends JPopupMenu{
private String text = null;
private Color topColor = null;
private Color bottomColor = null;
private Color foreColor = null;
private Font font = TWaverUtil.getDefaultFont();
private int width;
public TPopupMenu(String text, Color foreColor, Color backgroundColor, int width){
super();
this.text = text;
this.foreColor = foreColor;
this.topColor = backgroundColor;
this.bottomColor = backgroundColor;
this.width = width;
}
public TPopupMenu(String text, Color foreColor, Color topColor, Color bottomColor, int width){
super();
this.text = text;
this.foreColor = foreColor;
this.topColor = topColor;
this.bottomColor = bottomColor;
this.width = width;
}
public Insets getInsets() {
Insets insets = (Insets)super.getInsets().clone();
insets.left += width;
return insets;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
// draw backgound
Dimension size = this.getSize();
Graphics2D g2 = (Graphics2D) g;
GradientPaint gp = new GradientPaint(0, 0, topColor, 0, size.height, bottomColor, false);
g2.setPaint(gp);
g2.fillRect(0, 0, width, size.height);
// draw text
if(this.text != null && this.font != null){
g2.setColor(this.foreColor);
g2.setFont(font);
Dimension textSize = TWaverUtil.getTextSize(text, font, g2);
int y = (size.height + textSize.width)/ 2;
int xOffset = TWaverUtil.getTextOffset(text, font, g2);
TWaverUtil.drawString(text, g2, (width - textSize.height)/2 + xOffset, y, -Math.PI * 0.5);
}
}
public Font getFont() {
return font;
}
public void setFont(Font textFont) {
this.font = textFont;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -