Guest User

Untitled

a guest
Apr 30th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.46 KB | None | 0 0
  1. ## Offending code
  2. import org.eclipse.swt.SWT;
  3. import org.eclipse.swt.custom.CLabel;
  4. import org.eclipse.swt.layout.FillLayout;
  5. import org.eclipse.swt.layout.FormAttachment;
  6. import org.eclipse.swt.layout.FormData;
  7. import org.eclipse.swt.layout.FormLayout;
  8. import org.eclipse.swt.layout.GridData;
  9. import org.eclipse.swt.layout.GridLayout;
  10. import org.eclipse.swt.layout.RowData;
  11. import org.eclipse.swt.layout.RowLayout;
  12.  
  13. class LoginDialog
  14. include_package org.eclipse.swt.graphics;
  15. include_package org.eclipse.swt.widgets;
  16.  
  17. def initialize(display)
  18. @display = display
  19. end
  20.  
  21. def createContents
  22. #Shell must be created with style SWT::NO_TRIM
  23. shell = Shell.new(@display, SWT::NO_TRIM | SWT::ON_TOP)
  24. fillLayout = FillLayout.new;
  25. fillLayout.marginHeight = 1;
  26. shell.setLayout(fillLayout);
  27.  
  28. #Create a composite with grid layout.
  29. composite = Composite.new(shell, SWT::NONE);
  30. gridLayout = GridLayout.new();
  31. gridLayout.numColumns = 2;
  32. gridLayout.marginHeight = 0;
  33. gridLayout.verticalSpacing = 0;
  34. gridLayout.marginWidth = 0;
  35. gridLayout.horizontalSpacing = 0;
  36. composite.setLayout(gridLayout);
  37.  
  38. #Setting the background of the composite
  39. #with the image background for login dialog
  40. # img_Label = Label.new(composite, SWT::NONE)
  41. # img_Label.setLayoutData(GridData.new(195, 181));
  42. # img = Image.new(@display, "login.png");
  43. # img_Label.setImage(img);
  44.  
  45. #Creating the composite which will contain
  46. #the login related widgets
  47. cmp_Login = Composite.new(composite, SWT::NONE);
  48. rowLayout = RowLayout.new();
  49. rowLayout.fill = true;
  50. cmp_Login.setLayout(rowLayout);
  51. gridData = GridData.new(GridData::FILL, GridData::FILL, false, false);
  52. gridData.widthHint = 196;
  53. cmp_Login.setLayoutData(gridData);
  54.  
  55. #Label for the heading
  56. clbl_UserLogin = CLabel.new(cmp_Login, SWT::NONE);
  57. rowData = RowData.new();
  58. rowData.width = 180;
  59. clbl_UserLogin.setLayoutData(rowData);
  60. clbl_UserLogin.setText("User Login");
  61.  
  62. #Label for the username
  63. clbl_Username = CLabel.new(cmp_Login, SWT::NONE);
  64. rowData_1 = RowData.new();
  65. rowData_1.width = 180;
  66. clbl_Username.setLayoutData(rowData_1);
  67. clbl_Username.setText("Username");
  68.  
  69. #Textfield for the username
  70. txt_Username = Text.new(cmp_Login, SWT::BORDER);
  71. rowData_2 = RowData.new();
  72. rowData_2.width = 170;
  73. txt_Username.setLayoutData(rowData_2);
  74.  
  75. #Label for the password
  76. clbl_Password = CLabel.new(cmp_Login, SWT::NONE);
  77. rowData_3 = RowData.new();
  78. rowData_3.width = 180;
  79. clbl_Password.setLayoutData(rowData_3);
  80. clbl_Password.setText("Password");
  81.  
  82. #Textfield for the password
  83. txt_Password = Text.new(cmp_Login, SWT::BORDER);
  84. rowData_4 = RowData.new();
  85. rowData_4.width = 170;
  86. txt_Password.setLayoutData(rowData_4);
  87. txt_Password.setEchoChar('*'[0]);
  88.  
  89. #Composite to hold button as I want the
  90. #button to be positioned to my choice.
  91. cmp_ButtonBar = Composite.new(cmp_Login, SWT::NONE);
  92. rowData_5 = RowData.new();
  93. rowData_5.height = 38;
  94. rowData_5.width = 185;
  95. cmp_ButtonBar.setLayoutData(rowData_5);
  96. cmp_ButtonBar.setLayout(FormLayout.new());
  97.  
  98. #Button for login
  99. # btn_login = Button.new(cmp_ButtonBar, SWT::FLAT);
  100. # formData = FormData.new();
  101. # formData.bottom = FormAttachment.new(0, 28);
  102. # formData.top = FormAttachment.new(0, 5);
  103. # formData.right = FormAttachment.new(100, -3);
  104. # formData.left = FormAttachment.new(100, -40);
  105. # btn_login.setLayoutData(formData);
  106. # btn_login.setText("Login");
  107.  
  108. #Adding CLOSE action to this button.
  109. # btn_login.addListener(SWT::Selection) do
  110. # shell.close();
  111. # #In your case, you might wish
  112. # #to call the authentication method.
  113. # end
  114.  
  115. #Label for copyright info
  116. clbl_Message = CLabel.new(cmp_Login, SWT::NONE);
  117. clbl_Message.setAlignment(SWT::RIGHT);
  118. rowData_6 = RowData.new();
  119. rowData_6.width = 188;
  120. clbl_Message.setLayoutData(rowData_6);
  121. clbl_Message.setText("My Custom Login Screen");
  122.  
  123. #Drawing a region which will
  124. #form the base of the login
  125. # region = Region.new();
  126. # pixel = Rectangle.new(1, 1, 388, 180);
  127. # region.add(pixel);
  128. # shell.setRegion(region);
  129.  
  130. #Adding ability to move shell around
  131. l = Proc.new do |e|
  132. case e.type
  133. when SWT::MouseDown
  134. origin = Point.new(e.x, e.y);
  135. when SWT::MouseUp
  136. origin = null;
  137. when SWT::MouseMove
  138. if (origin != nil)
  139. p = @display.map(shell, nil, e.x, e.y);
  140. shell.setLocation(p.x - origin.x, p.y - origin.y);
  141. end
  142. end
  143. end;
  144.  
  145. #Adding the listeners
  146. #to all visible components
  147. composite.addListener(SWT::MouseDown, l);
  148. composite.addListener(SWT::MouseUp, l);
  149. composite.addListener(SWT::MouseMove, l);
  150.  
  151. # img_Label.addListener(SWT::MouseDown, l);
  152. # img_Label.addListener(SWT::MouseUp, l);
  153. # img_Label.addListener(SWT::MouseMove, l);
  154.  
  155. #Positioning in the center of the screen.
  156. #This for the 1024 resolution only. Later,
  157. #I plan to make generic so, that it takes
  158. #the resolution and finds the center of
  159. #the screen.
  160. shell.setLocation(320,290);
  161. shell.open();
  162.  
  163. while (!shell.isDisposed())
  164. if (!@display.read_and_dispatch())
  165. @display.sleep();
  166. end
  167. end
  168. # region.dispose();
  169. end # create contents
  170.  
  171. end # class
  172.  
  173. ## Output
  174. /home/uwe/workspace/aifudis/aifudis.operator/jruby-trunk/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:31 warning: already initialized constant SWT
  175. /home/uwe/workspace/aifudis/aifudis.operator/jruby-trunk/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:31 warning: already initialized constant GridData
  176. /home/uwe/workspace/aifudis/aifudis.operator/jruby-trunk/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:31 warning: already initialized constant GridLayout
  177. /home/uwe/workspace/aifudis/aifudis.operator/jruby-trunk/lib/ruby/site_ruby/1.8/builtin/javasupport/java.rb:42:in `method_missing': wrong number of arguments (1 for 0) (ArgumentError)
  178. from /home/uwe/workspace/aifudis/aifudis.operator/jruby-trunk/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/module.rb:25:in `const_missing'
  179. from /home/uwe/workspace/aifudis/aifudis.operator/jruby-trunk/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/module.rb:24:in `each'
  180. from /home/uwe/workspace/aifudis/aifudis.operator/jruby-trunk/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/module.rb:24:in `detect'
  181. from /home/uwe/workspace/aifudis/aifudis.operator/jruby-trunk/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/module.rb:24:in `const_missing'
  182. from /home/uwe/workspace/aifudis/aifudis.operator/././src/login_dialog.rb:133:in `createContents'
  183. from /home/uwe/workspace/aifudis/aifudis.operator/jruby-trunk/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/proc.rb:6:in `call'
  184. from /home/uwe/workspace/aifudis/aifudis.operator/jruby-trunk/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/proc.rb:6:in `method_missing'
  185. from /home/uwe/workspace/aifudis/aifudis.operator/jruby-trunk/lib/ruby/site_ruby/1.8/builtin/javasupport/proxy/interface.rb:174:in `__jcreate_proxy!'
  186. from /home/uwe/workspace/aifudis/aifudis.operator/././src/login_dialog.rb:163:in `createContents'
  187. from aifudis.operator.rb:28
  188. [uwe@pippin aifudis.operator]$
Add Comment
Please, Sign In to add comment