Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. package testSWT;
  2.  
  3. import org.eclipse.jface.action.MenuManager;
  4. import org.eclipse.jface.action.StatusLineManager;
  5. import org.eclipse.jface.action.ToolBarManager;
  6. import org.eclipse.jface.dialogs.IDialogConstants;
  7. import org.eclipse.jface.dialogs.MessageDialog;
  8. import org.eclipse.jface.window.ApplicationWindow;
  9. import org.eclipse.swt.SWT;
  10. import org.eclipse.swt.graphics.Image;
  11. import org.eclipse.swt.graphics.Point;
  12. import org.eclipse.swt.widgets.Composite;
  13. import org.eclipse.swt.widgets.Control;
  14. import org.eclipse.swt.widgets.Display;
  15. import org.eclipse.swt.widgets.Shell;
  16. import org.eclipse.swt.widgets.Button;
  17. import org.eclipse.swt.events.KeyAdapter;
  18. import org.eclipse.swt.events.KeyEvent;
  19. import org.eclipse.swt.events.SelectionAdapter;
  20. import org.eclipse.swt.events.SelectionEvent;
  21.  
  22. public class TestApplication extends ApplicationWindow {
  23.  
  24. /**
  25. * Create the application window.
  26. */
  27. public TestApplication() {
  28. super(null);
  29. createActions();
  30. addToolBar(SWT.FLAT | SWT.WRAP);
  31. addMenuBar();
  32. addStatusLine();
  33. }
  34.  
  35. /**
  36. * Create contents of the application window.
  37. * @param parent
  38. */
  39. @Override
  40. protected Control createContents(Composite parent) {
  41. Composite container = new Composite(parent, SWT.NONE);
  42.  
  43. Button btnNewButton = new Button(container, SWT.NONE);
  44. btnNewButton.addSelectionListener(new SelectionAdapter() {
  45. @Override
  46. public void widgetSelected(SelectionEvent e) {
  47. System.out.println("widget selected");
  48. openQuestion(TestApplication.this.getShell(), "Hello Testing", "11111111111\n11111111111\n\n11111"
  49. + "111111111111111\n1111111111111111\n"
  50. + "11111111111111111\n11111111111111\n"
  51. + "111111111111111111111\n11111111111\n"
  52. + "11111111\n1111111111111111\n11111111\n"
  53. + "1111111111\n11111111111111111\n111111\n"
  54. + "1111111\n11111111111111111111\n11111\n"
  55. + "22222222222\n22222222222222\n2222222\n"
  56. + "2222222\n2222222222222222\n222222222\n"
  57. + "22222222222222222222\n222222222222\n"
  58. + "22222222222222\n222222222222222222\n", 1);
  59. }
  60. });
  61.  
  62. btnNewButton.setBounds(85, 10, 95, 28);
  63. btnNewButton.setText("New Button");
  64.  
  65. return container;
  66. }
  67.  
  68. /**
  69. * Create the actions.
  70. */
  71. private void createActions() {
  72. // Create the actions
  73. }
  74.  
  75. /**
  76. * Create the menu manager.
  77. * @return the menu manager
  78. */
  79. @Override
  80. protected MenuManager createMenuManager() {
  81. MenuManager menuManager = new MenuManager("menu");
  82. return menuManager;
  83. }
  84.  
  85. /**
  86. * Create the toolbar manager.
  87. * @return the toolbar manager
  88. */
  89. @Override
  90. protected ToolBarManager createToolBarManager(int style) {
  91. ToolBarManager toolBarManager = new ToolBarManager(style);
  92. return toolBarManager;
  93. }
  94.  
  95. /**
  96. * Create the status line manager.
  97. * @return the status line manager
  98. */
  99. @Override
  100. protected StatusLineManager createStatusLineManager() {
  101. StatusLineManager statusLineManager = new StatusLineManager();
  102. return statusLineManager;
  103. }
  104.  
  105. /**
  106. * Launch the application.
  107. * @param args
  108. */
  109. public static void main(String args[]) {
  110. try {
  111. TestApplication window = new TestApplication();
  112. window.setBlockOnOpen(true);
  113. window.open();
  114. Display.getCurrent().dispose();
  115. } catch (Exception e) {
  116. e.printStackTrace();
  117. }
  118. }
  119.  
  120. /**
  121. * Configure the shell.
  122. * @param newShell
  123. */
  124. @Override
  125. protected void configureShell(Shell newShell) {
  126. super.configureShell(newShell);
  127. newShell.setText("New Application");
  128. }
  129.  
  130. /**
  131. * Return the initial size of the window.
  132. */
  133. @Override
  134. protected Point getInitialSize() {
  135. return new Point(450, 300);
  136. }
  137. public void openQuestion(Shell parentShell, String title, String question, final int iconStyle){
  138. MessageDialog dialog = new MessageDialog(
  139. parentShell,
  140. title,
  141. getTitleIcon(iconStyle),
  142. question,
  143. iconStyle,
  144. new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL },
  145. 0
  146. ) {
  147. @Override
  148. public Image getImage() {
  149. return null;
  150. }
  151. };
  152.  
  153. dialog.open() ;
  154. }
  155.  
  156. private Image getTitleIcon(int iconStyle) {
  157. // TODO Auto-generated method stub
  158. return null;
  159. }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement