kylecordes / rsta

Rhino Swing Test App

This URL has Read+Write access

rsta / js / login.js
100644 75 lines (57 sloc) 2.04 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Rhino Swing Test Application
// Copyright 2008 Kyle Cordes
// http://kylecordes.com
 
 
function login() {
var layeredPane = new JLayeredPane();
var dialog = new JDialog();
var loggedIn = false;
 
importClass(com.kylecordes.rhinohack.RhinoAction);
 
var okAction = new JavaAdapter(RhinoAction, {
act : function(e) {
loggedIn = true;
dialog.dispose();
}
});
 
importClass(java.lang.Integer);
 
okAction.putValue(Action.NAME, "Log In");
okAction.putValue(Action.SHORT_DESCRIPTION, "This is a button to login");
okAction.putValue(Action.MNEMONIC_KEY, Integer.valueOf(KeyEvent.VK_O));
 
var picHeight = 260;
var picWidth = 450;
 
layeredPane.setPreferredSize(new Dimension(picWidth, picHeight));
layeredPane.setBorder(BorderFactory.createEmptyBorder());
 
function createImageIcon(path) {
var loader = java.lang.Thread.currentThread().getContextClassLoader();
var imgURL = loader.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
intf.print("Couldn't find file: " + path);
return new ImageIcon();
}
}
 
var image = createImageIcon("logo.jpg");
var picture = new JLabel(image);
picture.setBounds(0, 0, picWidth, 260);
layeredPane.add(picture);
 
var userName = new JTextField(15);
layeredPane.add(userName, Integer.valueOf(10));
userName.setBounds(320, 40, 100, 20);
 
userName.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "go");
userName.getActionMap().put("go", okAction);
 
var password = new JTextField();
password.setBounds(320, 100, 100, 20);
layeredPane.add(password, Integer.valueOf(10));
 
var loginButton = new JButton();
loginButton.setBounds(320, 150, 90, 28);
loginButton.setAction(okAction);
 
layeredPane.add(loginButton, Integer.valueOf(10));
 
layeredPane.setOpaque(true); // content panes must be opaque
dialog.setTitle("Rhino Swing Test Application - Login with any name/pw");
dialog.setContentPane(layeredPane);
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setModal(true);
 
dialog.setVisible(true);
return loggedIn;
}