Guest User

Untitled

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