📄 rectanglegroupstrategy.java
字号:
}
}
/* (non-Javadoc)
* @see com.swtplus.widgets.IGroupStrategy#computeSize(int, int, boolean)
*/
public Point computeSize(int wHint, int hHint, boolean changed) {
Point size = new Point(0,0);
//figure out min width
int decorationsWidth = 0;
if (getGroup().getImage() != null){
decorationsWidth += hMargin + getGroup().getImage().getBounds().width + betweenSpacing;
} else {
decorationsWidth += hMargin;
}
decorationsWidth += hMargin;
if (getToggleStrategy() != null)
decorationsWidth += getToggleStrategy().getSize().x + hMargin + betweenSpacing;
//figure out the size of the body for use later
Point bodySize;
int body_wHint = SWT.DEFAULT,body_hHint = SWT.DEFAULT;
if (wHint != SWT.DEFAULT)
body_wHint = wHint - (2*margin);
if (hHint != SWT.DEFAULT){
if (rounded){
body_hHint = hHint - getTitleHeight() - 5;
} else {
body_hHint = hHint - getTitleHeight() - margin;
}
}
bodySize = getGroup().getBody().computeSize(body_wHint,body_hHint,changed);
if (wHint == SWT.DEFAULT){
int titleWidth = decorationsWidth + getTextWidth();
size.x = Math.max(titleWidth,bodySize.x + (2*margin));
} else {
int minWidth = decorationsWidth + 50;
size.x = Math.max(minWidth,bodySize.x + (2*margin));
size.x = Math.max(size.x,wHint);
}
if (getGroup().isExpanded()){
if (rounded){
size.y = getTitleHeight() + bodySize.y + 5;
} else {
size.y = getTitleHeight() + bodySize.y + margin;
}
} else {
size.y = getTitleHeight();
}
return size;
}
/* (non-Javadoc)
* @see com.swtplus.widgets.AbstractGroupStrategy#computeTitleHeight()
*/
public int computeTitleHeight(){
int h = 0;
int imageHeight = 0;
if (getGroup().getImage() != null)
imageHeight = getGroup().getImage().getBounds().height;
if (paintImageInBounds){
h = Math.max(getFontHeight() + (2*titleTextMargin),imageHeight);
h += (2*vMargin);
} else {
h = Math.max(getFontHeight() + (2*titleTextMargin) + (2*vMargin),imageHeight +1);
}
if (getToggleStrategy() != null){
int toggleHeight = getToggleStrategy().getSize().y;
h = Math.max(toggleHeight + (2*vMargin), h);
}
return h;
}
/* (non-Javadoc)
* @see com.swtplus.widgets.AbstractGroupStrategy#computeActiveBounds()
*/
public Rectangle computeActiveBounds() {
Point textPoint = new Point (0,0);
int textWidth = 0;
Image image = getGroup().getImage();
// Compute Title Area Height for later use
int titleAreaHeight = 0;
if (image != null && !paintImageInBounds){
titleAreaHeight = getFontHeight() + (2*titleTextMargin) + (2*vMargin);
if (getToggleStrategy() != null){
titleAreaHeight = Math.max(titleAreaHeight, getToggleStrategy().getSize().y + (2*vMargin));
}
}
// Paint Text
// First, compute the starting text point
// Part 1, Image
textPoint.x = hMargin;
if (image != null){
if (imageLeft){
textPoint.x += image.getBounds().width + betweenSpacing;
}
if (paintImageInBounds){
textPoint.y = (getTitleHeight() - getFontHeight()) /2;
} else {
textPoint.y = (getTitleHeight() - titleAreaHeight) + (titleAreaHeight - getFontHeight()) /2;
}
} else {
textPoint.y = (getTitleHeight() - getFontHeight()) /2;
}
// Part 2, Toggle
if (getToggleStrategy() != null){
if (toggleLeft){
textPoint.x += getToggleStrategy().getSize().x + betweenSpacing;
}
}
// Now calculate the width of the text
textWidth = getGroup().getSize().x - (hMargin *2);
// Part 1, Image
if (image != null){
textWidth -= (image.getBounds().width + betweenSpacing);
}
// Part 2, Toggle
if (getToggleStrategy() != null)
textWidth -= getToggleStrategy().getSize().x + betweenSpacing;
return new Rectangle(textPoint.x,textPoint.y,textWidth,getFontHeight());
}
/**
* Initialize colors.
*/
private void initializeColors() {
getGroup().getBody().setBackground(getGroup().getBody().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
RGB backRGB = GraphicUtils.blend(getGroup().getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT).getRGB(),getGroup().getDisplay().getSystemColor(SWT.COLOR_BLACK).getRGB(),90);
initialBackground = new Color(getGroup().getBody().getDisplay(),backRGB);
getGroup().setBackground(initialBackground);
getGroup().setForeground(getGroup().getDisplay().getSystemColor(SWT.COLOR_TITLE_FOREGROUND));
g1 = getGroup().getBody().getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT);
g2 = getGroup().getBody().getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND);
setBackground(new Color[]{g1,g2},new int[]{100},true);
setBorderColor(g2);
}
/* (non-Javadoc)
* @see com.swtplus.widgets.IGroupStrategy#dispose()
*/
public void dispose() {
initialBackground.dispose();
g1.dispose();
g2.dispose();
}
/**
* Specify a gradient of colours to be drawn in the background of the group.
* <p>For example, to draw a gradient that varies from dark blue to blue and then to
* white and stays white for the right half of the label, use the following call
* to setBackground:</p>
* <pre>
* setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE),
* display.getSystemColor(SWT.COLOR_BLUE),
* display.getSystemColor(SWT.COLOR_WHITE),
* display.getSystemColor(SWT.COLOR_WHITE)},
* new int[] {25, 50, 100});
* </pre>
*
* @param colors an array of Color that specifies the colors to appear in the gradient
* in order of appearance from left to right; The value <code>null</code>
* clears the background gradient; the value <code>null</code> can be used
* inside the array of Color to specify the background color.
* @param percents an array of integers between 0 and 100 specifying the percent of the width
* of the widget at which the color should change; the size of the percents
* array must be one less than the size of the colors array.
*
*/
public void setBackground(Color[] colors, int[] percents) {
setBackground(colors,percents,false);
}
/**
* Specify a gradient of colours to be drawn in the background of the group.
* <p>For example, to draw a gradient that varies from dark blue to white in the vertical,
* direction use the following call
* to setBackground:</p>
* <pre>
* setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE),
* display.getSystemColor(SWT.COLOR_WHITE)},
* new int[] {100}, true);
* </pre>
*
* @param colors an array of Color that specifies the colors to appear in the gradient
* in order of appearance from left/top to right/bottom; The value <code>null</code>
* clears the background gradient; the value <code>null</code> can be used
* inside the array of Color to specify the background color.
* @param percents an array of integers between 0 and 100 specifying the percent of the width/height
* of the widget at which the color should change; the size of the percents
* array must be one less than the size of the colors array.
* @param vertical indicate the direction of the gradient. True is vertical and false is horizontal.
*/
public void setBackground(Color[] colors, int[] percents, boolean vertical) {
if (colors != null) {
if (percents == null || percents.length != colors.length - 1) {
throw new RuntimeException("Percents array must be one item less than the colors array");
}
if (getGroup().getDisplay().getDepth() < 15) {
// Don't use gradients on low color displays
colors = new Color[] {colors[colors.length - 1]};
percents = new int[] { };
}
for (int i = 0; i < percents.length; i++) {
if (percents[i] < 0 || percents[i] > 100) {
throw new RuntimeException("Percent array item out of range");
}
if (i > 0 && percents[i] < percents[i-1]) {
//throw new RuntimeException("huh?");
}
}
}
// Are these settings the same as before?
final Color background = getGroup().getBackground();
if ((gradientColors != null) && (colors != null) &&
(gradientColors.length == colors.length)) {
boolean same = false;
for (int i = 0; i < gradientColors.length; i++) {
same = (gradientColors[i] == colors[i]) ||
((gradientColors[i] == null) && (colors[i] == background)) ||
((gradientColors[i] == background) && (colors[i] == null));
if (!same) break;
}
if (same) {
for (int i = 0; i < gradientPercents.length; i++) {
same = gradientPercents[i] == percents[i];
if (!same) break;
}
}
if (same && this.gradientVertical == vertical) return;
}
// Store the new settings
if (colors == null) {
gradientColors = null;
gradientPercents = null;
gradientVertical = false;
} else {
gradientColors = new Color[colors.length];
for (int i = 0; i < colors.length; ++i)
gradientColors[i] = (colors[i] != null) ? colors[i] : background;
gradientPercents = new int[percents.length];
for (int i = 0; i < percents.length; ++i)
gradientPercents[i] = percents[i];
gradientVertical = vertical;
}
// Refresh with the new settings
getGroup().redraw();
}
/**
* Returns the color of the one pixel border drawn around the body when the
* group is expanded.
*
* @return the border color
*/
public Color getBorderColor() {
return borderColor;
}
/**
* Sets the border color. The border is the one pixel border drawn around the
* body when the group is expanded.
*
* @param borderColor the border color, or null for no border
*/
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -