Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package testSWT;
- import org.eclipse.jface.action.MenuManager;
- import org.eclipse.jface.action.StatusLineManager;
- import org.eclipse.jface.action.ToolBarManager;
- import org.eclipse.jface.dialogs.IDialogConstants;
- import org.eclipse.jface.dialogs.MessageDialog;
- import org.eclipse.jface.window.ApplicationWindow;
- import org.eclipse.swt.SWT;
- import org.eclipse.swt.graphics.Image;
- import org.eclipse.swt.graphics.Point;
- import org.eclipse.swt.widgets.Composite;
- import org.eclipse.swt.widgets.Control;
- import org.eclipse.swt.widgets.Display;
- import org.eclipse.swt.widgets.Shell;
- import org.eclipse.swt.widgets.Button;
- import org.eclipse.swt.events.KeyAdapter;
- import org.eclipse.swt.events.KeyEvent;
- import org.eclipse.swt.events.SelectionAdapter;
- import org.eclipse.swt.events.SelectionEvent;
- public class TestApplication extends ApplicationWindow {
- /**
- * Create the application window.
- */
- public TestApplication() {
- super(null);
- createActions();
- addToolBar(SWT.FLAT | SWT.WRAP);
- addMenuBar();
- addStatusLine();
- }
- /**
- * Create contents of the application window.
- * @param parent
- */
- @Override
- protected Control createContents(Composite parent) {
- Composite container = new Composite(parent, SWT.NONE);
- Button btnNewButton = new Button(container, SWT.NONE);
- btnNewButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- System.out.println("widget selected");
- openQuestion(TestApplication.this.getShell(), "Hello Testing", "11111111111\n11111111111\n\n11111"
- + "111111111111111\n1111111111111111\n"
- + "11111111111111111\n11111111111111\n"
- + "111111111111111111111\n11111111111\n"
- + "11111111\n1111111111111111\n11111111\n"
- + "1111111111\n11111111111111111\n111111\n"
- + "1111111\n11111111111111111111\n11111\n"
- + "22222222222\n22222222222222\n2222222\n"
- + "2222222\n2222222222222222\n222222222\n"
- + "22222222222222222222\n222222222222\n"
- + "22222222222222\n222222222222222222\n", 1);
- }
- });
- btnNewButton.setBounds(85, 10, 95, 28);
- btnNewButton.setText("New Button");
- return container;
- }
- /**
- * Create the actions.
- */
- private void createActions() {
- // Create the actions
- }
- /**
- * Create the menu manager.
- * @return the menu manager
- */
- @Override
- protected MenuManager createMenuManager() {
- MenuManager menuManager = new MenuManager("menu");
- return menuManager;
- }
- /**
- * Create the toolbar manager.
- * @return the toolbar manager
- */
- @Override
- protected ToolBarManager createToolBarManager(int style) {
- ToolBarManager toolBarManager = new ToolBarManager(style);
- return toolBarManager;
- }
- /**
- * Create the status line manager.
- * @return the status line manager
- */
- @Override
- protected StatusLineManager createStatusLineManager() {
- StatusLineManager statusLineManager = new StatusLineManager();
- return statusLineManager;
- }
- /**
- * Launch the application.
- * @param args
- */
- public static void main(String args[]) {
- try {
- TestApplication window = new TestApplication();
- window.setBlockOnOpen(true);
- window.open();
- Display.getCurrent().dispose();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Configure the shell.
- * @param newShell
- */
- @Override
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText("New Application");
- }
- /**
- * Return the initial size of the window.
- */
- @Override
- protected Point getInitialSize() {
- return new Point(450, 300);
- }
- public void openQuestion(Shell parentShell, String title, String question, final int iconStyle){
- MessageDialog dialog = new MessageDialog(
- parentShell,
- title,
- getTitleIcon(iconStyle),
- question,
- iconStyle,
- new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL },
- 0
- ) {
- @Override
- public Image getImage() {
- return null;
- }
- };
- dialog.open() ;
- }
- private Image getTitleIcon(int iconStyle) {
- // TODO Auto-generated method stub
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement