⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplegroupexampler.java

📁 开源的关于SWT开发的图形应用库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				}
				
				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("SimpleGroupStrategy.TOGGLE_LEFT");
		colorStyler.add(buttonToggleLeft);
		
		buttonImageRight = new Button(c,SWT.CHECK | SWT.FLAT);
		buttonImageRight.setText("SimpleGroupStrategy.IMAGE_RIGHT");
		colorStyler.add(buttonImageRight);
		
		buttonCenterVertically = new Button(c,SWT.CHECK | SWT.FLAT);
		buttonCenterVertically.setText("SimpleGroupStrategy.CENTER_VERTICALLY");
		colorStyler.add(buttonCenterVertically);
		
		buttonLineMiddle = new Button(c,SWT.CHECK | SWT.FLAT);
		buttonLineMiddle.setText("SimpleGroupStrategy.LINE_MIDDLE");
		colorStyler.add(buttonLineMiddle);
		
		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 | SimpleGroupStrategy.TOGGLE_LEFT;
		if (buttonImageRight.getSelection())
			style = style | SimpleGroupStrategy.IMAGE_RIGHT;
		if (buttonCenterVertically.getSelection())
			style = style | SimpleGroupStrategy.CENTER_VERTICALLY;
		if (buttonLineMiddle.getSelection())
			style = style | SimpleGroupStrategy.LINE_MIDDLE;
		
		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"));
		}
		
		SimpleGroupStrategy strategy;
		
		if (toggleCombo.getValue().equals("(None)")){
			strategy = new SimpleGroupStrategy(style);
		}else{
			strategy = new SimpleGroupStrategy(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.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);
			
			background = new Color(Display.getCurrent(), ((NamedRGB)backgroundCombo.getValue()).getRGB());
			pGroup.setBackground(background);
			
			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();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -