/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
* Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Oracle Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package tweeter.view;
import javafx.scene.control.Button;
import javafx.scene.control.TextBox;
import javafx.scene.image.ImageView;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import tweeter.view.AbstractView;
import tweeter.view.TweeterView;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordBox;
import javafx.scene.layout.HBox;
import javafx.stage.Alert;
import javafx.scene.layout.LayoutInfo;
public class LoginView extends AbstractView {
def logo_layoutX= 20;
def logo_layoutY= 35;
def line_startX =5;
def line_startY =100;
def line_endtXpadding =5;
def line_endX =100;
def usrtext_layoutX = 20;
def usrtext_layoutY = 150;
def usrtextbox_layoutX = 100;
def usrtextbox_layoutY = 143;
def usrtextbox_widht = 115;
def psswrdtext_layoutX = 20;
def psswrdtext_layoutY = 180;
def labelsize = 11;
def passwrdtextbox_layoutX = 100;
def passwrdtextbox_layoutY = 173;
def passwrdtextbox_width = 115;
def startext_layoutXpadding = 5;
def startext_layoutYpadding = 9;
def startext_widthpadding = 15;
def starbgrect_xypadding = 2;
def starbgrect_widthheightpadding = 4;
def loginbtn_layoutX = 65;
def loginbtn_layoutY = 220;
def loginbtn_width = 70;
def cancelbtn_width = 70;
def _btnSpacing = 5;
override var show = true on replace {
if(visible) {
userTextBox.requestFocus();
}
};
var logo = ImageView {
layoutX: logo_layoutX
layoutY: logo_layoutY
image: TweeterView.theme.logoImage
};
var line = Line {
startX: line_startX
startY: line_startY
endX: bind TweeterView.width - line_endtXpadding
endY: line_endX
stroke: bind Color.web("#{TweeterView.theme.linkColor}")
};
var userText = Label {
layoutX: usrtext_layoutX
layoutY: usrtext_layoutY
font: Font { name: "Bitstream Vera Sans Bold" size: labelsize }
textFill: bind Color.web("#{TweeterView.theme.linkColor}")
text: "User Name:"
};
var userTextBox = TextBox {
layoutX: usrtextbox_layoutX
layoutY: usrtextbox_layoutY
width: usrtextbox_widht
blocksMouse: false
}
var passwdText = Label {
layoutX: psswrdtext_layoutX
layoutY: psswrdtext_layoutY
font:Font {
name: "Bitstream Vera Sans Bold"
size: labelsize
}
textFill: bind Color.web("#{TweeterView.theme.linkColor}")
text: "Password:"
};
var passwdTextBox : PasswordBox = PasswordBox {
layoutX: passwrdtextbox_layoutX
layoutY: passwrdtextbox_layoutY
width: passwrdtextbox_width
blocksMouse: false
action: function() {
login();
}
};
var starText:Label = Label {
layoutX: bind passwdTextBox.translateX + startext_layoutXpadding
layoutY: bind passwdTextBox.translateY + startext_layoutYpadding
font: Font { name: "Bitstream Vera Sans Bold" size: labelsize }
textFill: bind Color.web("#{TweeterView.theme.linkColor}")
clip: Rectangle {
x: bind starText.layoutX
y: bind starText.layoutY
layoutInfo:LayoutInfo{
width: passwdTextBox.layoutBounds.width - startext_widthpadding
height: bind passwdTextBox.boundsInLocal.height
}
}
};
var starBGRect = Rectangle {
x: bind passwdTextBox.translateX + starbgrect_xypadding
y: bind passwdTextBox.translateY + starbgrect_xypadding
width: bind passwdTextBox.width - starbgrect_widthheightpadding
height: bind passwdTextBox.height - starbgrect_widthheightpadding
fill: Color.WHITE
};
public var onLogin:function(user:String, passwd:String) = null;
var btnsBox : HBox = HBox {
layoutX: loginbtn_layoutX
layoutY: loginbtn_layoutY
spacing: _btnSpacing
content: [
Button {
text: "Login"
font:Font{ name:"Arial" size: 12}
layoutInfo:LayoutInfo {
width: loginbtn_width
}
blocksMouse: false
action: function() {
login();
}
},
Button {
text: "Cancel"
font:Font{ name:"Arial" size: 12}
layoutInfo: LayoutInfo {
width: cancelbtn_width
}
blocksMouse: false
action:function(){
passwdTextBox.text = "" ;
userTextBox.text = "";
}
}
]
};
function login():Void {
if(onLogin == null) {
return;
}
userTextBox.commit();
passwdTextBox.commit();
if((passwdTextBox.text!="") and (userTextBox.text != "")) {
onLogin(userTextBox.text, passwdTextBox.text);
passwdTextBox.clear();
}
else {
Alert.inform("Please Enter Username and Password.");
}
}
init{
children = [ logo, line, userText, userTextBox,
passwdText, passwdTextBox, starBGRect, starText,
btnsBox
]
}
}