📄 basictaskpanegroupui.java
字号:
public int getIconWidth() {
return 6;
}
public void paintIcon(Component c, Graphics g, int x, int y) {
if (up) {
g.drawLine(x + 3, y, x, y + 3);
g.drawLine(x + 3, y, x + 6, y + 3);
} else {
g.drawLine(x, y, x + 3, y + 3);
g.drawLine(x + 3, y + 3, x + 6, y);
}
}
}
/**
* The border around the content pane
*/
protected static class ContentPaneBorder implements Border {
Color color;
public ContentPaneBorder(Color color) {
this.color = color;
}
public Insets getBorderInsets(Component c) {
return new Insets(0, 1, 1, 1);
}
public boolean isBorderOpaque() {
return true;
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
g.setColor(color);
g.drawLine(x, y, x, y + height - 1);
g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
g.drawLine(x + width - 1, y, x + width - 1, y + height - 1);
}
}
/**
* The border of the taskpane group paints the "text", the "icon", the
* "expanded" status and the "special" type.
*
*/
protected class PaneBorder implements Border {
protected Color borderColor;
protected Color titleForeground;
protected Color specialTitleBackground;
protected Color specialTitleForeground;
protected Color titleBackgroundGradientStart;
protected Color titleBackgroundGradientEnd;
protected Color titleOver;
protected Color specialTitleOver;
protected JLabel label;
public PaneBorder() {
borderColor = UIManager.getColor("TaskPaneGroup.borderColor");
titleForeground = UIManager.getColor("TaskPaneGroup.titleForeground");
specialTitleBackground = UIManager
.getColor("TaskPaneGroup.specialTitleBackground");
specialTitleForeground = UIManager
.getColor("TaskPaneGroup.specialTitleForeground");
titleBackgroundGradientStart = UIManager
.getColor("TaskPaneGroup.titleBackgroundGradientStart");
titleBackgroundGradientEnd = UIManager
.getColor("TaskPaneGroup.titleBackgroundGradientEnd");
titleOver = UIManager.getColor("TaskPaneGroup.titleOver");
if (titleOver == null) {
titleOver = specialTitleBackground.brighter();
}
specialTitleOver = UIManager.getColor("TaskPaneGroup.specialTitleOver");
if (specialTitleOver == null) {
specialTitleOver = specialTitleBackground.brighter();
}
label = new JLabel();
label.setOpaque(false);
label.setIconTextGap(8);
}
public Insets getBorderInsets(Component c) {
return new Insets(getTitleHeight(), 0, 0, 0);
}
public boolean isBorderOpaque() {
return true;
}
/**
* Calculates the preferred border size, its size so all its content fits.
*/
public Dimension getPreferredSize(JTaskPaneGroup group) {
// calculate the title width so it is fully visible
// it starts with the title width
configureLabel(group);
Dimension dim = label.getPreferredSize();
// add the title left offset
dim.width += 3;
// add the controls width
dim.width += TITLE_HEIGHT;
// and some space between label and controls
dim.width += 3;
dim.height = getTitleHeight();
return dim;
}
protected void paintTitleBackground(JTaskPaneGroup group, Graphics g) {
if (group.isSpecial()) {
g.setColor(specialTitleBackground);
} else {
g.setColor(titleBackgroundGradientStart);
}
g.fillRect(0, 0, group.getWidth(), getTitleHeight() - 1);
}
protected void paintTitle(
JTaskPaneGroup group,
Graphics g,
Color textColor,
int x,
int y,
int width,
int height) {
configureLabel(group);
label.setForeground(textColor);
g.translate(x, y);
label.setBounds(0, 0, width, height);
label.paint(g);
g.translate(-x, -y);
}
protected void configureLabel(JTaskPaneGroup group) {
label.applyComponentOrientation(group.getComponentOrientation());
label.setFont(group.getFont());
label.setText(group.getTitle());
label.setIcon(
group.getIcon() == null ? new EmptyIcon() : group.getIcon());
}
protected void paintExpandedControls(JTaskPaneGroup group, Graphics g, int x,
int y, int width, int height) {}
protected Color getPaintColor(JTaskPaneGroup group) {
Color paintColor;
if (isMouseOverBorder()) {
if (mouseOver) {
if (group.isSpecial()) {
paintColor = specialTitleOver;
} else {
paintColor = titleOver;
}
} else {
if (group.isSpecial()) {
paintColor = specialTitleForeground;
} else {
paintColor = titleForeground;
}
}
} else {
if (group.isSpecial()) {
paintColor = specialTitleForeground;
} else {
paintColor = titleForeground;
}
}
return paintColor;
}
public void paintBorder(
Component c,
Graphics g,
int x,
int y,
int width,
int height) {
JTaskPaneGroup group = (JTaskPaneGroup)c;
// calculate position of title and toggle controls
int controlWidth = TITLE_HEIGHT - 2 * ROUND_HEIGHT;
int controlX = group.getWidth() - TITLE_HEIGHT;
int controlY = ROUND_HEIGHT - 1;
int titleX = 3;
int titleY = 0;
int titleWidth = group.getWidth() - getTitleHeight() - 3;
int titleHeight = getTitleHeight();
if (!group.getComponentOrientation().isLeftToRight()) {
controlX = group.getWidth() - controlX - controlWidth;
titleX = group.getWidth() - titleX - titleWidth;
}
// paint the title background
paintTitleBackground(group, g);
// paint the the toggles
paintExpandedControls(group, g, controlX, controlY, controlWidth,
controlWidth);
// paint the title text and icon
Color paintColor = getPaintColor(group);
// focus painted same color as text
if (group.hasFocus()) {
g.setColor(paintColor);
BasicGraphicsUtils.drawDashedRect(
g,
3,
3,
width - 6,
getTitleHeight() - 6);
}
paintTitle(
group,
g,
paintColor,
titleX,
titleY,
titleWidth,
titleHeight);
}
protected void paintRectAroundControls(JTaskPaneGroup group, Graphics g, int x,
int y, int width, int height, Color highColor, Color lowColor) {
if (mouseOver) {
int x2 = x + width;
int y2 = y + height;
g.setColor(highColor);
g.drawLine(x, y, x2, y);
g.drawLine(x, y, x, y2);
g.setColor(lowColor);
g.drawLine(x2, y, x2, y2);
g.drawLine(x, y2, x2, y2);
}
}
protected void paintOvalAroundControls(JTaskPaneGroup group, Graphics g, int x,
int y, int width, int height) {
if (group.isSpecial()) {
g.setColor(specialTitleBackground.brighter());
g.drawOval(
x,
y,
width,
height);
} else {
g.setColor(titleBackgroundGradientStart);
g.fillOval(
x,
y,
width,
height);
g.setColor(titleBackgroundGradientEnd.darker());
g.drawOval(
x,
y,
width,
height);
}
}
protected void paintChevronControls(JTaskPaneGroup group, Graphics g, int x,
int y, int width, int height) {
ChevronIcon chevron;
if (group.isExpanded()) {
chevron = new ChevronIcon(true);
} else {
chevron = new ChevronIcon(false);
}
int chevronX = x + width / 2 - chevron.getIconWidth() / 2;
int chevronY = y + (height / 2 - chevron.getIconHeight());
chevron.paintIcon(group, g, chevronX, chevronY);
chevron.paintIcon(
group,
g,
chevronX,
chevronY + chevron.getIconHeight() + 1);
}
/**
* Default implementation returns false.
*
* @return true if this border wants to display things differently when the
* mouse is over it
*/
protected boolean isMouseOverBorder() {
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -