Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.eclipse.swt.SWT;
- import org.eclipse.swt.custom.CLabel;
- import org.eclipse.swt.layout.FillLayout;
- import org.eclipse.swt.layout.FormAttachment;
- import org.eclipse.swt.layout.FormData;
- import org.eclipse.swt.layout.FormLayout;
- import org.eclipse.swt.layout.GridData;
- import org.eclipse.swt.layout.GridLayout;
- import org.eclipse.swt.layout.RowData;
- import org.eclipse.swt.layout.RowLayout;
- #import com.swtdesigner.SWTResourceManager;
- class LoginDialog
- include_package org.eclipse.swt.graphics;
- include_package org.eclipse.swt.widgets;
- def initialize(display)
- @display = display
- end
- def createContents
- #Shell must be created with style SWT::NO_TRIM
- shell = Shell.new(@display, SWT::NO_TRIM | SWT::ON_TOP)
- fillLayout = FillLayout.new;
- fillLayout.marginHeight = 1;
- shell.setLayout(fillLayout);
- #Create a composite with grid layout.
- composite = Composite.new(shell, SWT::NONE);
- gridLayout = GridLayout.new();
- gridLayout.numColumns = 2;
- gridLayout.marginHeight = 0;
- gridLayout.verticalSpacing = 0;
- gridLayout.marginWidth = 0;
- gridLayout.horizontalSpacing = 0;
- composite.setLayout(gridLayout);
- #Setting the background of the composite
- #with the image background for login dialog
- # img_Label = Label.new(composite, SWT::NONE)
- # img_Label.setLayoutData(GridData.new(195, 181));
- # img = Image.new(@display, "login.png");
- # img_Label.setImage(img);
- #Creating the composite which will contain
- #the login related widgets
- cmp_Login = Composite.new(composite, SWT::NONE);
- rowLayout = RowLayout.new();
- rowLayout.fill = true;
- cmp_Login.setLayout(rowLayout);
- gridData = GridData.new(GridData::FILL, GridData::FILL, false, false);
- gridData.widthHint = 196;
- cmp_Login.setLayoutData(gridData);
- #Label for the heading
- clbl_UserLogin = CLabel.new(cmp_Login, SWT::NONE);
- rowData = RowData.new();
- rowData.width = 180;
- clbl_UserLogin.setLayoutData(rowData);
- clbl_UserLogin.setText("User Login");
- #Label for the username
- clbl_Username = CLabel.new(cmp_Login, SWT::NONE);
- rowData_1 = RowData.new();
- rowData_1.width = 180;
- clbl_Username.setLayoutData(rowData_1);
- clbl_Username.setText("Username");
- #Textfield for the username
- txt_Username = Text.new(cmp_Login, SWT::BORDER);
- rowData_2 = RowData.new();
- rowData_2.width = 170;
- txt_Username.setLayoutData(rowData_2);
- #Label for the password
- clbl_Password = CLabel.new(cmp_Login, SWT::NONE);
- rowData_3 = RowData.new();
- rowData_3.width = 180;
- clbl_Password.setLayoutData(rowData_3);
- clbl_Password.setText("Password");
- #Textfield for the password
- txt_Password = Text.new(cmp_Login, SWT::BORDER);
- rowData_4 = RowData.new();
- rowData_4.width = 170;
- txt_Password.setLayoutData(rowData_4);
- txt_Password.setEchoChar('*'[0]);
- #Composite to hold button as I want the
- #button to be positioned to my choice.
- cmp_ButtonBar = Composite.new(cmp_Login, SWT::NONE);
- rowData_5 = RowData.new();
- rowData_5.height = 38;
- rowData_5.width = 185;
- cmp_ButtonBar.setLayoutData(rowData_5);
- cmp_ButtonBar.setLayout(FormLayout.new());
- #Button for login
- # btn_login = Button.new(cmp_ButtonBar, SWT::FLAT);
- # formData = FormData.new();
- # formData.bottom = FormAttachment.new(0, 28);
- # formData.top = FormAttachment.new(0, 5);
- # formData.right = FormAttachment.new(100, -3);
- # formData.left = FormAttachment.new(100, -40);
- # btn_login.setLayoutData(formData);
- # btn_login.setText("Login");
- #Adding CLOSE action to this button.
- # btn_login.addListener(SWT::Selection) do
- # shell.close();
- # #In your case, you might wish
- # #to call the authentication method.
- # end
- #Label for copyright info
- clbl_Message = CLabel.new(cmp_Login, SWT::NONE);
- clbl_Message.setAlignment(SWT::RIGHT);
- rowData_6 = RowData.new();
- rowData_6.width = 188;
- clbl_Message.setLayoutData(rowData_6);
- clbl_Message.setText("My Custom Login Screen");
- #Drawing a region which will
- #form the base of the login
- # region = Region.new();
- # pixel = Rectangle.new(1, 1, 388, 180);
- # region.add(pixel);
- # shell.setRegion(region);
- #Adding ability to move shell around
- l = Proc.new do |e|
- case e.type
- when SWT::MouseDown
- origin = Point.new(e.x, e.y);
- when SWT::MouseUp
- origin = null;
- when SWT::MouseMove
- if (origin != nil)
- p = @display.map(shell, nil, e.x, e.y);
- shell.setLocation(p.x - origin.x, p.y - origin.y);
- end
- end
- end;
- #Adding the listeners
- #to all visible components
- composite.addListener(SWT::MouseDown, l);
- composite.addListener(SWT::MouseUp, l);
- composite.addListener(SWT::MouseMove, l);
- # img_Label.addListener(SWT::MouseDown, l);
- # img_Label.addListener(SWT::MouseUp, l);
- # img_Label.addListener(SWT::MouseMove, l);
- #Positioning in the center of the screen.
- #This for the 1024 resolution only. Later,
- #I plan to make generic so, that it takes
- #the resolution and finds the center of
- #the screen.
- shell.setLocation(320,290);
- shell.open();
- while (!shell.isDisposed())
- if (!@display.read_and_dispatch())
- @display.sleep();
- end
- end
- # region.dispose();
- end # create contents
- end # class
Add Comment
Please, Sign In to add comment