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

📄 redmondshelfexampler.java

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

import org.eclipse.swt.SWT;
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.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.FontDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

import com.swtplus.utility.Styler;
import com.swtplus.widgets.PCombo;
import com.swtplus.widgets.PGroup;
import com.swtplus.widgets.PList;
import com.swtplus.widgets.PListItem;
import com.swtplus.widgets.PShelf;
import com.swtplus.widgets.PShelfItem;
import com.swtplus.widgets.combo.ColorComboStrategy;
import com.swtplus.widgets.combo.NamedRGB;
import com.swtplus.widgets.group.SimpleGroupStrategy;
import com.swtplus.widgets.list.ListBarListStrategy;
import com.swtplus.widgets.shelf.RedmondShelfStrategy;

public class RedmondShelfExampler extends Composite implements IWidgetExampler {

	private ColorComboStrategy foregroundComboStrat;
	private PCombo foregroundCombo;
	protected Font font;
	private Composite exampleArea;
	private boolean firstCreate = true;
	
	private PShelf pShelf;
	private Color foreground;
	private Label l;
	private Button border;
	private Label l1;
	private Label l2;
	private Styler borderStyler  = new Styler();
	private ColorComboStrategy selforegroundComboStrat;
	private PCombo selforegroundCombo;
	private Color selforeground;
	private ColorComboStrategy g1ComboStrat;
	private PCombo g1Combo;
	private ColorComboStrategy g2ComboStrat;
	private PCombo g2Combo;
	private Color g1;
	private Color g2;
	private ColorComboStrategy s1ComboStrat;
	private PCombo s1Combo;
	private ColorComboStrategy s2ComboStrat;
	private PCombo s2Combo;
	private Color s1;
	private Color s2;
	private ColorComboStrategy h1ComboStrat;
	private PCombo h1Combo;
	private ColorComboStrategy h2ComboStrat;
	private PCombo h2Combo;
	private Color h1;
	private Color h2;
	private ColorComboStrategy lComboStrat;
	private PCombo lCombo;
	private Color li;
	protected Font sfont;;

	public RedmondShelfExampler(Composite c) {
		super(c, SWT.NONE);
		

		Styler colorStyler = new Styler();
		colorStyler.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
		
		Styler borderStyler = new Styler();
		borderStyler.setBorderColor(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
		
		SelectionListener sListener = new SelectionListener(){
			public void widgetSelected(SelectionEvent arg0) {
				recreate();
			}
			public void widgetDefaultSelected(SelectionEvent arg0) {
			}};
		
//		ModifyListener mListener = new ModifyListener() {
//			public void modifyText(ModifyEvent e) {
//				getDisplay().asyncExec(new Runnable(){
//					public void run() {
//						recreate();
//					}				
//				});
//			}		
//		};
	
        this.setLayout(new FillLayout());
		final Composite container = new Composite (this,SWT.NONE);
		container.setBackground(c.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
		
		container.setLayout(new GridLayout());
		
		
		SimpleGroupStrategy sgs = new SimpleGroupStrategy(SWT.NONE);
		PGroup sgStyles = new PGroup(container,sgs);
		sgStyles.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		sgStyles.setText("Styles");
		colorStyler.add(sgStyles);
		colorStyler.add(sgStyles.getBody());
		
		sgStyles.getBody().setLayout(new GridLayout());
		
		border = new Button(sgStyles.getBody(),SWT.CHECK | SWT.FLAT);
		border.setText("PCombo.BORDER");
		colorStyler.add(border);
		border.setSelection(true);
		border.addSelectionListener(sListener);


		sgs = new SimpleGroupStrategy(SWT.NONE);
		PGroup sg = new PGroup(container,sgs);
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
		sg.setLayoutData(gd);
		sg.setText("Colors and Font");
		c = sg.getBody();
		GridLayout gl = new GridLayout();
		gl.numColumns = 2;
		c.setLayout(gl);
		colorStyler.add(sg);
		colorStyler.add(sg.getBody());
		
		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 sfLabel = new Label(c,SWT.NONE);
		sfLabel.setText("Selected Foreground Color:");
		colorStyler.add(sfLabel);
		
		selforegroundComboStrat = new ColorComboStrategy(ColorComboStrategy.SHOW_DEFAULT | ColorComboStrategy.SHOW_SWTPALETTE);
		selforegroundCombo = new PCombo(c,PCombo.READ_ONLY | PCombo.FLAT,selforegroundComboStrat);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		selforegroundCombo.setLayoutData(gd);
		borderStyler.add(selforegroundCombo);
		
		
		Label g1 = new Label(c,SWT.NONE);
		g1.setText("Background Gradient 1:");
		colorStyler.add(g1);
		
		g1ComboStrat = new ColorComboStrategy(ColorComboStrategy.SHOW_DEFAULT | ColorComboStrategy.SHOW_SWTPALETTE);
		g1Combo = new PCombo(c,PCombo.READ_ONLY | PCombo.FLAT,g1ComboStrat);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		g1Combo.setLayoutData(gd);
		borderStyler.add(g1Combo);
		

		Label g2 = new Label(c,SWT.NONE);
		g2.setText("Background Gradient 2:");
		colorStyler.add(g2);
		
		g2ComboStrat = new ColorComboStrategy(ColorComboStrategy.SHOW_DEFAULT | ColorComboStrategy.SHOW_SWTPALETTE);
		g2Combo = new PCombo(c,PCombo.READ_ONLY | PCombo.FLAT,g2ComboStrat);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		g2Combo.setLayoutData(gd);
		borderStyler.add(g2Combo);

		
		Label s1 = new Label(c,SWT.NONE);
		s1.setText("Selected Gradient 1:");
		colorStyler.add(s1);
		
		s1ComboStrat = new ColorComboStrategy(ColorComboStrategy.SHOW_DEFAULT | ColorComboStrategy.SHOW_SWTPALETTE);
		s1Combo = new PCombo(c,PCombo.READ_ONLY | PCombo.FLAT,s1ComboStrat);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		s1Combo.setLayoutData(gd);
		borderStyler.add(s1Combo);

		
		Label s2 = new Label(c,SWT.NONE);
		s2.setText("Selected Gradient 2:");
		colorStyler.add(s2);
		
		s2ComboStrat = new ColorComboStrategy(ColorComboStrategy.SHOW_DEFAULT | ColorComboStrategy.SHOW_SWTPALETTE);
		s2Combo = new PCombo(c,PCombo.READ_ONLY | PCombo.FLAT,s2ComboStrat);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		s2Combo.setLayoutData(gd);
		borderStyler.add(s2Combo);
		
		
		Label h1 = new Label(c,SWT.NONE);
		h1.setText("Hover Gradient 1:");
		colorStyler.add(h1);
		
		h1ComboStrat = new ColorComboStrategy(ColorComboStrategy.SHOW_DEFAULT | ColorComboStrategy.SHOW_SWTPALETTE);
		h1Combo = new PCombo(c,PCombo.READ_ONLY | PCombo.FLAT,h1ComboStrat);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		h1Combo.setLayoutData(gd);
		borderStyler.add(h1Combo);

		
		Label h2 = new Label(c,SWT.NONE);
		h2.setText("Hover Gradient 2:");
		colorStyler.add(h2);
		
		h2ComboStrat = new ColorComboStrategy(ColorComboStrategy.SHOW_DEFAULT | ColorComboStrategy.SHOW_SWTPALETTE);
		h2Combo = new PCombo(c,PCombo.READ_ONLY | PCombo.FLAT,h2ComboStrat);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		h2Combo.setLayoutData(gd);
		borderStyler.add(h2Combo);

		Label li = new Label(c,SWT.NONE);
		li.setText("Line Color:");
		colorStyler.add(li);
		
		lComboStrat = new ColorComboStrategy(ColorComboStrategy.SHOW_DEFAULT | ColorComboStrategy.SHOW_SWTPALETTE);
		lCombo = new PCombo(c,PCombo.READ_ONLY | PCombo.FLAT,lComboStrat);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		lCombo.setLayoutData(gd);
		borderStyler.add(lCombo);
		
		
		Label 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();
				}
			}});

		
		l = new Label(c,SWT.NONE);
		l.setText("Selected Font:");
		colorStyler.add(l);
		
		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 (sfont != null)
						sfont.dispose();
					
					sfont = new Font(Display.getCurrent(),fds);
					recreate();
				}
			}});
		
//		
//		SimpleGroupStrategy sgs2 = new SimpleGroupStrategy(SWT.NONE);
//		PGroup sgColors = new PGroup(container,sgs2);
//		sgColors.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
//		sgColors.setText("Other Options");
//		colorStyler.add(sgColors);
//		colorStyler.add(sgColors.getBody());
//		
//		sgColors.getBody().setLayout(new GridLayout(2,false));
		
		
		colorStyler.style();
		borderStyler.style();
		
		registerListeners(this);
	}

	public void setExampleArea(Composite area) {
		exampleArea = area;
		
		GridLayout gl = new GridLayout(3,false);
		area.setLayout(gl);
		recreate();
		

⌨️ 快捷键说明

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