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

📄 redmondshelfexampler.java

📁 开源的关于SWT开发的图形应用库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		firstCreate = false;		
	}
	
	public void recreate(){
		
		borderStyler.remove(pShelf);
		
		if (pShelf != null){
			pShelf.dispose();
		}
		if (l != null){
			l.dispose();
		}	
		if (l2 != null){
			l2.dispose();
		}	
		if (l1 != null){
			l1.dispose();
		}	
		
		
		
		
		
		l1 = new Label(exampleArea,SWT.NONE);
		GridData gd = new GridData();
		gd.widthHint = 100;
		l1.setLayoutData(gd);
		
		
		
		
		
		int style = 0;
		
		
		RedmondShelfStrategy strategy = new RedmondShelfStrategy(style);
		
		
		if (foreground != null)
			foreground.dispose();
		if (selforeground != null)
			selforeground.dispose();
		if (g1 != null)
			g1.dispose();
		if (g2 != null)
			g2.dispose();
		if (s1 != null)
			s1.dispose();
		if (s2 != null)
			s2.dispose();
		if (h1 != null)
			h1.dispose();
		if (h2 != null)
			h2.dispose();		
		if (li != null)
			li.dispose();	
		
		style = SWT.NONE;
		if (border.getSelection())
			style = style | PShelf.BORDER;
		
		pShelf = new PShelf(exampleArea,style,strategy);

		borderStyler.setBorderColor(strategy.getLineColor());
		
		if (!border.getSelection()){
			getDisplay().asyncExec(new Runnable() {
				public void run() {
					borderStyler.add(pShelf);		
					borderStyler.style();
					pShelf.getParent().redraw();
				}		
			});
		}
		
		l2 = new Label(exampleArea,SWT.NONE);
		gd = new GridData();
		gd.widthHint = 100;
		l2.setLayoutData(gd);
		
		
		if (firstCreate){
			foregroundComboStrat.setDefaultRGB(pShelf.getForeground().getRGB());
			foregroundCombo.setValue(new NamedRGB("Default",pShelf.getForeground().getRGB()));

			selforegroundComboStrat.setDefaultRGB(strategy.getSelectedForeground().getRGB());
			selforegroundCombo.setValue(new NamedRGB("Default",strategy.getSelectedForeground().getRGB()));

			g1ComboStrat.setDefaultRGB(strategy.getGradient1().getRGB());
			g1Combo.setValue(new NamedRGB("Default",strategy.getGradient1().getRGB()));

			g2ComboStrat.setDefaultRGB(strategy.getGradient2().getRGB());
			g2Combo.setValue(new NamedRGB("Default",strategy.getGradient2().getRGB()));

			s1ComboStrat.setDefaultRGB(strategy.getSelectedGradient1().getRGB());
			s1Combo.setValue(new NamedRGB("Default",strategy.getSelectedGradient1().getRGB()));

			s2ComboStrat.setDefaultRGB(strategy.getSelectedGradient2().getRGB());
			s2Combo.setValue(new NamedRGB("Default",strategy.getSelectedGradient2().getRGB()));

			h1ComboStrat.setDefaultRGB(strategy.getHoverGradient1().getRGB());
			h1Combo.setValue(new NamedRGB("Default",strategy.getHoverGradient1().getRGB()));

			h2ComboStrat.setDefaultRGB(strategy.getHoverGradient1().getRGB());
			h2Combo.setValue(new NamedRGB("Default",strategy.getHoverGradient2().getRGB()));
			
			lComboStrat.setDefaultRGB(strategy.getLineColor().getRGB());
			lCombo.setValue(new NamedRGB("Default",strategy.getLineColor().getRGB()));

			font = null;
			sfont = null;
		} else {
			foreground = new Color(Display.getCurrent(), ((NamedRGB)foregroundCombo.getValue()).getRGB());
			pShelf.setForeground(foreground);

			selforeground = new Color(Display.getCurrent(), ((NamedRGB)selforegroundCombo.getValue()).getRGB());
			strategy.setSelectedForeground(selforeground);
			
			g1 = new Color(Display.getCurrent(), ((NamedRGB)g1Combo.getValue()).getRGB());
			strategy.setGradient1(g1);
			
			g2 = new Color(Display.getCurrent(), ((NamedRGB)g2Combo.getValue()).getRGB());
			strategy.setGradient2(g2);

			s1 = new Color(Display.getCurrent(), ((NamedRGB)s1Combo.getValue()).getRGB());
			strategy.setSelectedGradient1(s1);
			
			s2 = new Color(Display.getCurrent(), ((NamedRGB)s2Combo.getValue()).getRGB());
			strategy.setSelectedGradient2(s2);
			
			h1 = new Color(Display.getCurrent(), ((NamedRGB)h1Combo.getValue()).getRGB());
			strategy.setHoverGradient1(h1);
			
			h2 = new Color(Display.getCurrent(), ((NamedRGB)h2Combo.getValue()).getRGB());
			strategy.setHoverGradient2(h2);
			
			li = new Color(Display.getCurrent(), ((NamedRGB)lCombo.getValue()).getRGB());
			strategy.setLineColor(li);	

			if (font != null)
				strategy.setFont(font);
			
			if (sfont != null)
				strategy.setSelectedFont(sfont);
		}
		
		
		gd = new GridData(GridData.FILL_BOTH);
		gd.verticalIndent = 100;
		pShelf.setLayoutData(gd);
		
		l = new Label(exampleArea,SWT.NONE);
		gd = new GridData(SWT.CENTER,SWT.TOP,true,false);
		gd.horizontalSpan =3;
		gd.heightHint = 70;
		l.setLayoutData(gd);
		
		
		PShelfItem si = new PShelfItem(pShelf,SWT.NONE);
		si.setText("Inbox");
		si.setImage(GalleryImageRegistry.getImage(this.getClass(),"list4_24.png"));
		
		si.getBody().setLayout(new GridLayout());
		Label label = new Label(si.getBody(),SWT.WRAP);
		label.setLayoutData(new GridData(GridData.FILL_BOTH));
		label.setText("This area is a just a regular SWT Composite.  You can access this Composite via ShelfItem.getBody() and add your contents.");
		
		si = new PShelfItem(pShelf,SWT.NONE);
		si.setText("Outgoing Mail");
		si.setImage(GalleryImageRegistry.getImage(this.getClass(),"list2_24.png"));
		
		GridLayout gl = new GridLayout();
		gl.marginHeight = 0;
		gl.marginWidth = 0;
		si.getBody().setLayout(gl);
		List list = new List(si.getBody(),SWT.WRAP);
		list.setLayoutData(new GridData(GridData.FILL_BOTH));
		list.setItems(new String[]{"List item 1","List Item 2","More sample data","Sample data...","Blah blah"});
		
		si = new PShelfItem(pShelf,SWT.NONE);
		si.setText("Notes");
		si.setImage(GalleryImageRegistry.getImage(this.getClass(),"list3_24.png"));
		
		si.getBody().setLayout(new GridLayout());
		Text t = new Text(si.getBody(),SWT.BORDER | SWT.MULTI | SWT.WRAP);
		t.setLayoutData(new GridData(GridData.FILL_BOTH));
		t.setText("The quick brown fox jumps over the lazy dog.  One Two Three");
		
		si = new PShelfItem(pShelf,SWT.NONE);
		si.setText("To-Do List");
		si.setImage(GalleryImageRegistry.getImage(this.getClass(),"list5_24.png"));
		
		gl = new GridLayout();
		gl.marginHeight = 0;
		gl.marginWidth = 0;
		si.getBody().setLayout(gl);
		ListBarListStrategy listStrategy = new ListBarListStrategy(ListBarListStrategy.HOVER);
		PList pList = new PList(si.getBody(),PList.SINGLE,listStrategy);
		pList.setLayoutData(new GridData(GridData.FILL_BOTH));
		
		PListItem li = new PListItem(pList,SWT.NONE);
		li.setText("Example 1");
		li.setImage(GalleryImageRegistry.getImage(this.getClass(),"list1.png"));

		
		si = new PShelfItem(pShelf,SWT.NONE);
		si.setText("Photos");
		si.setImage(GalleryImageRegistry.getImage(this.getClass(),"list1_24.png"));
		gl = new GridLayout();
		gl.marginHeight = 0;
		gl.marginWidth = 0;
		si.getBody().setLayout(gl);
		

		final Tree tree = new Tree (si.getBody(), SWT.V_SCROLL);

		tree.setLayoutData(new GridData(GridData.FILL_BOTH));

		for (int i=0; i<4; i++) {
			TreeItem iItem = new TreeItem (tree, 0);
			iItem.setText ("TreeItem (0) -" + i);
			for (int j=0; j<4; j++) {
				TreeItem jItem = new TreeItem (iItem, 0);
				jItem.setText ("TreeItem (1) -" + j);
				for (int k=0; k<4; k++) {
					TreeItem kItem = new TreeItem (jItem, 0);
					kItem.setText ("TreeItem (2) -" + k);
					for (int l=0; l<4; l++) {
						TreeItem lItem = new TreeItem (kItem, 0);
						lItem.setText ("TreeItem (3) -" + l);
					}
				}
			}
		}


		exampleArea.redraw();
		exampleArea.layout();
	}

	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() {
		Composite p = pShelf.getParent();
		
		if (pShelf != null){
			pShelf.dispose();
		}
				
		if (l != null){
			l.dispose();
		}		
		if (l2 != null){
			l2.dispose();
		}	
		if (l1 != null){
			l1.dispose();
		}	
		super.dispose();
		
		p.redraw();
	}
}

⌨️ 快捷键说明

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