?? rectanglegroupexampler.java
字號(hào):
groupImageCombo.setValue("Woman");
groupImageCombo.addSelectionListener(new SelectionListener(){
public void widgetSelected(SelectionEvent arg0) {
if (!groupImageCombo.getValue().equals("Browse...")){
recreate();
return;
}
if (groupBrowsedImage != null){
groupBrowsedImage.dispose();
groupBrowsedImage = null;
}
FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(),SWT.OPEN);
String file = fd.open();
if (file != null){
try {
groupBrowsedImage = new Image(Display.getCurrent(),file);
} catch (SWTException e) {
MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell());
mb.setText("Error");
mb.setMessage(e.toString());
mb.open();
}
}
recreate();
}
public void widgetDefaultSelected(SelectionEvent arg0) {
}});
sg = new PGroup(this, new SimpleGroupStrategy(SWT.NONE));
sg.setText("Styles");
sg.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
gd = new GridData(GridData.FILL_BOTH);
sg.setLayoutData(gd);
c = sg.getBody();
c.setBackground(parent.getBackground());
gl = new GridLayout();
c.setLayout(gl);
buttonToggleLeft = new Button(c,SWT.CHECK | SWT.FLAT);
buttonToggleLeft.setText("RectangleGroupStrategy.TOGGLE_LEFT");
colorStyler.add(buttonToggleLeft);
buttonImageRight = new Button(c,SWT.CHECK | SWT.FLAT);
buttonImageRight.setText("RectangleGroupStrategy.IMAGE_RIGHT");
colorStyler.add(buttonImageRight);
buttonRounded = new Button(c,SWT.CHECK | SWT.FLAT);
buttonRounded.setText("RectangleGroupStrategy.ROUNDED");
buttonRounded.setSelection(true);
colorStyler.add(buttonRounded);
buttonPaintImageOutOfBounds = new Button(c,SWT.CHECK |SWT.FLAT);
buttonPaintImageOutOfBounds.setText("RectangleGroupStrategy.PAINTIMAGEOUTOFBOUNDS");
colorStyler.add(buttonPaintImageOutOfBounds);
buttonPaintImageOutOfBounds.setSelection(true);
colorStyler.style();
borderStyler.style();
colorStyler.style();
borderStyler.style();
registerListeners(this);
}
public void recreate(){
if (pGroup != null){
pGroup.dispose();
}
int style = 0;
if (buttonToggleLeft.getSelection())
style = style | RectangleGroupStrategy.TOGGLE_LEFT;
if (buttonImageRight.getSelection())
style = style | RectangleGroupStrategy.IMAGE_RIGHT;
if (buttonRounded.getSelection())
style = style | RectangleGroupStrategy.ROUNDED;
if (buttonPaintImageOutOfBounds.getSelection())
style = style | RectangleGroupStrategy.PAINTIMAGEOUTOFBOUNDS;
IToggleStrategy toggle = null;
if (toggleCombo.getValue().equals(CHEVRONS)){
toggle = new ChevronsToggleStrategy();
}else if (toggleCombo.getValue().equals(TWISTE)){
toggle = new TwisteToggleStrategy();
}else if (toggleCombo.getValue().equals(TREENODE)){
toggle = new TreeNodeToggleStrategy();
}else if (toggleCombo.getValue().equals(MINMAX)){
toggle = new MinMaxToggleStrategy();
}else if (toggleCombo.getValue().equals(IMAGE)){
toggle = new ImageToggleStrategy(
GalleryImageRegistry.getImage(this.getClass(),"slider_up.GIF"),
GalleryImageRegistry.getImage(this.getClass(),"slider_down.GIF"),
GalleryImageRegistry.getImage(this.getClass(),"slider_up_hover.GIF"),
GalleryImageRegistry.getImage(this.getClass(),"slider_down_hover.GIF"));
}
RectangleGroupStrategy strategy;
if (toggleCombo.getValue().equals(NONE)){
strategy = new RectangleGroupStrategy(style);
}else{
strategy = new RectangleGroupStrategy(toggle,style);
}
if (foreground != null)
foreground.dispose();
if (background != null)
background.dispose();
if (colorBody != null)
colorBody.dispose();
pGroup = new PGroup(exampleArea,strategy);
if (firstCreate){
foregroundComboStrat.setDefaultRGB(pGroup.getForeground().getRGB());
foregroundCombo.setValue(new NamedRGB("Default",pGroup.getForeground().getRGB()));
backgroundComboStrat.setDefaultRGB(pGroup.getBackground().getRGB());
backgroundCombo.setValue(new NamedRGB("Default",pGroup.getBackground().getRGB()));
bodyComboStrat.setDefaultRGB(pGroup.getBody().getBackground().getRGB());
bodyCombo.setValue(new NamedRGB("Default",pGroup.getBody().getBackground().getRGB()));
font = null;
} else {
foreground = new Color(Display.getCurrent(), ((NamedRGB)foregroundCombo.getValue()).getRGB());
pGroup.setForeground(foreground);
if (backgroundSingle.getSelection()){
strategy.setBackground(null,null);
background = new Color(Display.getCurrent(), ((NamedRGB)backgroundCombo.getValue()).getRGB());
strategy.setBorderColor(background);
pGroup.setBackground(background);
} else {
}
colorBody = new Color(Display.getCurrent(), ((NamedRGB)bodyCombo.getValue()).getRGB());
pGroup.getBody().setBackground(colorBody);
if (font != null)
pGroup.setFont(font);
}
if (groupImageCombo.getValue().equals("Woman")){
pGroup.setImage(GalleryImageRegistry.getImage(this.getClass(),"woman3.png"));
}else if (groupImageCombo.getValue().equals("Browse...")){
if (groupBrowsedImage != null)
pGroup.setImage(groupBrowsedImage);
}
pGroup.setText(titleText.getText());
Styler styler = new Styler();
styler.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
GridData gd = new GridData(SWT.CENTER,SWT.TOP,true,false);
gd.verticalIndent = 100;
gd.widthHint = 200;
pGroup.setLayoutData(gd);
Composite body = pGroup.getBody();
FillLayout fl = new FillLayout();
fl.marginHeight = 5;
fl.marginWidth = 5;
body.setLayout(fl);
Label codeText = new Label(body,SWT.WRAP);
codeText.setText("This is the PGroup created by the options selected to the right.\n\n" +
"The area this text appears in is a normal SWT composite, which can be accessed simply " +
"by using the getBody() method call on the PGroup.");
codeText.setBackground(pGroup.getBody().getBackground());
styler.add(codeText);
exampleArea.layout();
}
public void setExampleArea(Composite area) {
exampleArea = area;
area.setLayout(new GridLayout());
recreate();
firstCreate = false;
}
public void registerListeners (Composite master){
Control [] children = master.getChildren();
for (int i = 0; i < children.length; i++) {
Control child = children[i];
if (child instanceof Composite){
if (child instanceof Combo){
Combo combo = (Combo) child;
combo.addSelectionListener(new SelectionListener(){
public void widgetSelected(SelectionEvent arg0) {
//recreate();
}
public void widgetDefaultSelected(SelectionEvent arg0) {}
});
} else if (child instanceof PCombo){
PCombo pCombo = (PCombo) child;
pCombo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
recreate();
}
});
} else {
registerListeners ((Composite) child);
}
}else if (child instanceof Button){
Button button = (Button) child;
button.addSelectionListener(new SelectionListener(){
public void widgetSelected(SelectionEvent arg0) {
recreate();
}
public void widgetDefaultSelected(SelectionEvent arg0) {}
});
}
}
}
public void dispose() {
super.dispose();
if (pGroup != null){
pGroup.dispose();
}
if (foreground != null)
foreground.dispose();
if (background != null)
background.dispose();
if (colorBody != null)
colorBody.dispose();
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -