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

📄 simplegroupexampler.java

📁 开源的关于SWT开发的图形应用库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

package com.swtplus.gallery;

import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Text;

import com.swtplus.utility.Styler;
import com.swtplus.widgets.PCombo;
import com.swtplus.widgets.PGroup;
import com.swtplus.widgets.combo.ColorComboStrategy;
import com.swtplus.widgets.combo.ListComboStrategy;
import com.swtplus.widgets.combo.NamedRGB;
import com.swtplus.widgets.group.SimpleGroupStrategy;
import com.swtplus.widgets.toggle.ChevronsToggleStrategy;
import com.swtplus.widgets.toggle.IToggleStrategy;
import com.swtplus.widgets.toggle.ImageToggleStrategy;
import com.swtplus.widgets.toggle.MinMaxToggleStrategy;
import com.swtplus.widgets.toggle.TreeNodeToggleStrategy;
import com.swtplus.widgets.toggle.TwisteToggleStrategy;


public class SimpleGroupExampler extends Composite implements IWidgetExampler {

	Composite exampleArea;
	private Styler colorStyler;
	private Styler borderStyler;
	private PCombo toggleCombo;
	private Text titleText;
	protected Font font;
	private PCombo groupImageCombo;
	
	PGroup pGroup;
	protected Image groupBrowsedImage;
	private Button buttonToggleLeft;
	private Button buttonImageRight;
	private Button buttonCenterVertically;
	private Button buttonLineMiddle;
	private Color foreground;
	private Color background;
	private Color colorBody;
	
	
	public static final String TWISTE = "TwisteToggleStrategy";
	public static final String TREENODE = "TreeNodeToggleStrategy";
	public static final String CHEVRONS = "ChevronsToggleStrategy";
	public static final String MINMAX = "MinMaxToggleStrategy";
	public static final String IMAGE = "ImageToggleStrategy (Using Slider Images)";
	
	boolean firstCreate = true;
	private ColorComboStrategy foregroundComboStrat;
	private PCombo foregroundCombo;
	private ColorComboStrategy backgroundComboStrat;
	private PCombo backgroundCombo;
	private ColorComboStrategy bodyComboStrat;
	private PCombo bodyCombo;
	
	public SimpleGroupExampler(Composite parent){
		super(parent,SWT.NONE);
		
		colorStyler = new Styler();
		colorStyler.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
		
		borderStyler = new Styler();
		borderStyler.setBorderColor(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
		
		colorStyler.add(this);
		this.setLayout(new GridLayout());
		
		SimpleGroupStrategy sgs = new SimpleGroupStrategy(SWT.NONE);
		PGroup sg = new PGroup(this,sgs);
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
		sg.setLayoutData(gd);
		sg.setBackground(parent.getBackground());
		sg.setText("Toggle Strategy");
		Composite c = sg.getBody();
		GridLayout gl = new GridLayout();
		gl.numColumns = 2;
		c.setLayout(gl);
		colorStyler.add(c);
		
		
		Label l = new Label(c,SWT.NONE);
		l.setText("Toggle Strategy:");
		colorStyler.add(l);
		
		ListComboStrategy toggleStrategy = new ListComboStrategy(SWT.NONE);
		toggleStrategy.setVisibleItemCount(6);
		toggleCombo = new PCombo (c,PCombo.FLAT | PCombo.READ_ONLY,toggleStrategy);
		borderStyler.add(toggleCombo);
		
		toggleStrategy.getList().setItems(new String[]{"(None)",TWISTE,TREENODE,CHEVRONS,MINMAX,IMAGE});

		gd = new GridData(GridData.FILL_HORIZONTAL);
		toggleCombo.setLayoutData(gd);
		toggleCombo.setValue(TREENODE);
		
		sgs = new SimpleGroupStrategy(SWT.NONE);
		sg = new PGroup(this,sgs);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		sg.setLayoutData(gd);
		sg.setBackground(parent.getBackground());
		sg.setText("Colors");
		c = sg.getBody();
		gl = new GridLayout();
		gl.numColumns = 2;
		c.setLayout(gl);
		c.setBackground(parent.getBackground());
		
		Label colorForegroundLabel = new Label(c,SWT.NONE);
		colorForegroundLabel.setText("Foreground Color:");
		colorStyler.add(colorForegroundLabel);
		
		foregroundComboStrat = new ColorComboStrategy(ColorComboStrategy.SHOW_DEFAULT | ColorComboStrategy.SHOW_SWTPALETTE);
		foregroundCombo = new PCombo(c,PCombo.READ_ONLY | PCombo.FLAT,foregroundComboStrat);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		foregroundCombo.setLayoutData(gd);
		borderStyler.add(foregroundCombo);
		
		Label backLabel = new Label(c,SWT.NONE);
		backLabel.setText("Background Color:");
		colorStyler.add(backLabel);
		
		backgroundComboStrat = new ColorComboStrategy(ColorComboStrategy.SHOW_DEFAULT | ColorComboStrategy.SHOW_SWTPALETTE);
		backgroundCombo = new PCombo(c,PCombo.READ_ONLY | PCombo.FLAT,backgroundComboStrat);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		backgroundCombo.setLayoutData(gd);
		borderStyler.add(backgroundCombo);
		
		Label colorBodyBackgroundLabel = new Label(c,SWT.NONE);
		colorBodyBackgroundLabel.setText("Body Color:");
		
		colorStyler.add(colorBodyBackgroundLabel);
		
		bodyComboStrat = new ColorComboStrategy(ColorComboStrategy.SHOW_DEFAULT | ColorComboStrategy.SHOW_SWTPALETTE);
		bodyCombo = new PCombo(c,PCombo.READ_ONLY | PCombo.FLAT,bodyComboStrat);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		bodyCombo.setLayoutData(gd);
		borderStyler.add(bodyCombo);
		
		
		sgs = new SimpleGroupStrategy(SWT.NONE);
		sg = new PGroup(this,sgs);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		sg.setLayoutData(gd);
		sg.setBackground(parent.getBackground());
		sg.setText("Text and Images");
		c = sg.getBody();
		gl = new GridLayout();
		gl.numColumns = 3;
		c.setLayout(gl);
		c.setBackground(parent.getBackground());
		
		Label titleLabel = new Label(c,SWT.NONE);
		titleLabel.setText("Title:");
		colorStyler.add(titleLabel);
		
		titleText = new Text(c, SWT.SINGLE);
		titleText.setText("Sample PGroup");
		gd = new GridData(GridData.FILL_HORIZONTAL);
		titleText.setLayoutData(gd);
		colorStyler.add(titleText);
		borderStyler.add(titleText);
		
		Button apply = new Button(c,SWT.PUSH | SWT.FLAT);
		apply.setText("Apply");
		apply.addSelectionListener(new SelectionListener(){

			public void widgetSelected(SelectionEvent arg0) {
				//title = titleText.getText();
				recreate();
			}

			public void widgetDefaultSelected(SelectionEvent arg0) {}
			
		});
		
		l = new Label(c,SWT.NONE);
		l.setText("Font:");
		colorStyler.add(l);
		
		Button fontButton = new Button(c,SWT.PUSH | SWT.FLAT);
		fontButton.setText("Change Font...");
		fontButton.addSelectionListener(new SelectionListener(){
			public void widgetDefaultSelected(SelectionEvent arg0) {
			}
			public void widgetSelected(SelectionEvent arg0) {
				FontDialog fd = new FontDialog(Display.getCurrent().getActiveShell());
				FontData fds = fd.open();
				if (fds != null){
					if (font != null)
						font.dispose();
					
					font = new Font(Display.getCurrent(),fds);
					recreate();
				}
			}});
		
		Label placeholder = new Label(c,SWT.NONE);
		colorStyler.add(placeholder);
		
		Label imageLabel = new Label(c,SWT.NONE);
		imageLabel.setText("Image:");
		colorStyler.add(imageLabel);
		
		ListComboStrategy imageStrategy = new ListComboStrategy(SWT.NONE);
		groupImageCombo = new PCombo(c,PCombo.READ_ONLY | PCombo.FLAT,imageStrategy);
		groupImageCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		borderStyler.add(groupImageCombo);
		
		imageStrategy.getList().add("(None)");
		imageStrategy.getList().add("Woman");
		imageStrategy.getList().add("Browse...");
		
		groupImageCombo.setValue("Woman");
		
		groupImageCombo.addSelectionListener(new SelectionListener(){
			public void widgetSelected(SelectionEvent arg0) {
				if (!groupImageCombo.getValue().equals("Browse...")){
					recreate();
					return;

⌨️ 快捷键说明

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