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

📄 snippet012dialogwithimagebuttons.java

📁 对于可视的桌面开发系统的一些详细的设计资料
💻 JAVA
字号:
/*******************************************************************************
 * Copyright (c) 2006 Tom Schindl and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Tom Schindl - initial API and implementation
 *******************************************************************************/
package org.eclipse.jface.snippets.dialogs;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
 * A snippet to demonstrate a dialog with image buttons.
 *
 */
public class Snippet012DialogWithImageButtons {
	private ImageRegistry registry;
	
	public Snippet012DialogWithImageButtons(final Shell shell) {
		
		Dialog dia = new Dialog(shell) {
			private ImageDescriptor getImageDescriptor(String path) {
				if( registry == null ) {
					registry = new ImageRegistry(shell.getDisplay());
				}
				
				ImageDescriptor desc = registry.getDescriptor(path);
				if( desc == null ) {
					desc = ImageDescriptor.createFromFile(Snippet012DialogWithImageButtons.class, path);
					registry.put(path, desc);
				}
				
				return desc;
			}
			
			protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
				Button b = super.createButton(parent, id, label, defaultButton);
				if( id == IDialogConstants.OK_ID ) {
					b.setImage(getImageDescriptor("filesave.png").createImage()); //$NON-NLS-1$
					// reset the button layout
					setButtonLayoutData(b);
				} else {
					b.setImage(getImageDescriptor("cancel.png").createImage()); //$NON-NLS-1$
					// reset the button layout
					setButtonLayoutData(b);
					return b;
				}
				
				return b;
			}
		};
		dia.open();
	}
	
	public static void main(String[] args) {
		Display display = new Display ();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		
		shell.open ();
		
		new Snippet012DialogWithImageButtons(shell);
		
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		
		display.dispose ();
	}
}

⌨️ 快捷键说明

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