Skip to content

Commit ca95412

Browse files
committed
Keystore credentials UI mockup (actual code)
1 parent ef28a44 commit ca95412

File tree

2 files changed

+200
-19
lines changed

2 files changed

+200
-19
lines changed

src/processing/mode/android/AndroidEditor.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ public void handleExportPackage() {
374374
// Need to implement an entire signing setup first
375375
// http://dev.processing.org/bugs/show_bug.cgi?id=1430
376376
deactivateExport();
377+
new KeyStoreCredentials(sketch);
378+
/*
377379
378380
if(handleExportCheckModified()) {
379381
new Thread() {
@@ -401,17 +403,6 @@ public void run() {
401403
stopIndeterminate();
402404
}
403405
}.start();
404-
}
405-
406-
// TODO now sign it... lots of fun signing code mess to go here. yay!
407-
408-
// maybe even send it to the device? mmm?
409-
// try {
410-
// runSketchOnDevice(AndroidEnvironment.getInstance().getHardware(), "release");
411-
// } catch (final MonitorCanceled ok) {
412-
// editor.statusNotice("Canceled.");
413-
// } finally {
414-
// editor.deactivateExport();
415-
// }
406+
} */
416407
}
417408
}
Lines changed: 197 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,200 @@
11
package processing.mode.android;
22

3-
/**
4-
* Created with IntelliJ IDEA.
5-
* User: imilka
6-
* Date: 24.05.14
7-
* Time: 0:06
8-
*/
9-
public class KeystoreCredentials {
3+
import processing.app.Base;
4+
import processing.app.Preferences;
5+
import processing.app.Sketch;
6+
7+
import javax.swing.*;
8+
import javax.swing.border.EmptyBorder;
9+
import javax.swing.border.MatteBorder;
10+
import javax.swing.border.TitledBorder;
11+
import java.awt.*;
12+
import java.awt.event.ActionEvent;
13+
import java.awt.event.ActionListener;
14+
import java.awt.event.MouseAdapter;
15+
import java.awt.event.MouseEvent;
16+
17+
18+
public class KeyStoreCredentials extends JFrame {
19+
static final String GUIDE_URL =
20+
"http://developer.android.com/tools/publishing/app-signing.html#cert";
21+
22+
Sketch sketch;
23+
24+
public KeyStoreCredentials(Sketch sketch) {
25+
this.sketch = sketch;
26+
27+
Container outer = getContentPane();
28+
Box pain = Box.createVerticalBox();
29+
pain.setBorder(new EmptyBorder(13, 13, 13, 13));
30+
outer.add(pain);
31+
32+
String labelText =
33+
"<html>" +
34+
"Please enter the information below so we can generate a private key for you.<br/>" +
35+
"Fields marked <b>bold</b> are required, " +
36+
"though you may consider to fill some of optional fields below those to avoid potential problems.<br/>" +
37+
"More about private keys can be found " +
38+
"<a href=\"" + GUIDE_URL + "\">here</a>.</body></html>";
39+
JLabel textarea = new JLabel(labelText);
40+
textarea.setPreferredSize(new Dimension(400, 100));
41+
textarea.addMouseListener(new MouseAdapter() {
42+
public void mouseClicked(MouseEvent e) {
43+
Base.openURL(GUIDE_URL);
44+
}
45+
});
46+
textarea.setAlignmentX(LEFT_ALIGNMENT);
47+
pain.add(textarea);
48+
49+
// password field
50+
JPasswordField passwordField = new JPasswordField(15);
51+
JLabel passwordLabel = new JLabel("<html><body><b>Keystore password: </b></body></html>");
52+
passwordLabel.setLabelFor(passwordField);
53+
54+
JPanel textPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
55+
textPane.add(passwordLabel);
56+
textPane.add(passwordField);
57+
textPane.setAlignmentX(LEFT_ALIGNMENT);
58+
pain.add(textPane);
59+
60+
// repeat password field
61+
JPasswordField repeatPasswordField = new JPasswordField(15);
62+
JLabel repeatPasswordLabel = new JLabel("<html><body><b>Repeat keystore password: </b></body></html>");
63+
repeatPasswordLabel.setLabelFor(passwordField);
64+
65+
textPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
66+
textPane.add(repeatPasswordLabel);
67+
textPane.add(repeatPasswordField);
68+
textPane.setAlignmentX(LEFT_ALIGNMENT);
69+
textPane.setBorder(new EmptyBorder(0, 0, 15, 0));
70+
pain.add(textPane);
71+
72+
MatteBorder mb = new MatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY);
73+
TitledBorder tb = new TitledBorder(mb, "Keystore issuer credentials", TitledBorder.LEFT, TitledBorder.DEFAULT_POSITION);
74+
JPanel separatorPanel = new JPanel();
75+
separatorPanel.setBorder(tb);
76+
pain.add(separatorPanel);
77+
78+
// common name (CN)
79+
JTextField commonName = new JTextField(15);
80+
JLabel commonNameLabel = new JLabel("First and last name: ");
81+
commonNameLabel.setLabelFor(commonName);
82+
83+
textPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
84+
textPane.add(commonNameLabel);
85+
textPane.add(commonName);
86+
textPane.setAlignmentX(LEFT_ALIGNMENT);
87+
pain.add(textPane);
88+
89+
// organizational unit (OU)
90+
JTextField organizationalUnit = new JTextField(15);
91+
JLabel organizationalUnitLabel = new JLabel("Organizational unit: ");
92+
organizationalUnitLabel.setLabelFor(organizationalUnit);
93+
94+
textPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
95+
textPane.add(organizationalUnitLabel);
96+
textPane.add(organizationalUnit);
97+
textPane.setAlignmentX(LEFT_ALIGNMENT);
98+
pain.add(textPane);
99+
100+
// organization name (O)
101+
JTextField organizationName = new JTextField(15);
102+
JLabel organizationNameLabel = new JLabel("Organization name: ");
103+
organizationNameLabel.setLabelFor(organizationName);
104+
105+
textPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
106+
textPane.add(organizationNameLabel);
107+
textPane.add(organizationName);
108+
textPane.setAlignmentX(LEFT_ALIGNMENT);
109+
pain.add(textPane);
110+
111+
// locality name (L)
112+
JTextField localityName = new JTextField(15);
113+
JLabel localityNameLabel = new JLabel("City or locality: ");
114+
localityNameLabel.setLabelFor(localityName);
115+
116+
textPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
117+
textPane.add(localityName);
118+
textPane.add(localityNameLabel);
119+
textPane.setAlignmentX(LEFT_ALIGNMENT);
120+
pain.add(textPane);
121+
122+
// state name (S)
123+
JTextField stateName = new JTextField(15);
124+
JLabel stateNameLabel = new JLabel("State name: ");
125+
stateNameLabel.setLabelFor(stateName);
126+
127+
textPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
128+
textPane.add(stateName);
129+
textPane.add(stateNameLabel);
130+
textPane.setAlignmentX(LEFT_ALIGNMENT);
131+
pain.add(textPane);
132+
133+
// country (C)
134+
JTextField country = new JTextField(15);
135+
JLabel countryLabel = new JLabel("Country code (XX): ");
136+
countryLabel.setLabelFor(country);
137+
138+
textPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
139+
textPane.add(country);
140+
textPane.add(countryLabel);
141+
textPane.setAlignmentX(LEFT_ALIGNMENT);
142+
pain.add(textPane);
143+
144+
// buttons
145+
JPanel buttons = new JPanel();
146+
buttons.setAlignmentX(LEFT_ALIGNMENT);
147+
JButton okButton = new JButton("OK");
148+
Dimension dim = new Dimension(Preferences.BUTTON_WIDTH,
149+
okButton.getPreferredSize().height);
150+
okButton.setPreferredSize(dim);
151+
okButton.addActionListener(new ActionListener() {
152+
public void actionPerformed(ActionEvent e) {
153+
setVisible(false);
154+
}
155+
});
156+
okButton.setEnabled(true);
157+
158+
JButton cancelButton = new JButton("Cancel");
159+
cancelButton.setPreferredSize(dim);
160+
cancelButton.addActionListener(new ActionListener() {
161+
public void actionPerformed(ActionEvent e) {
162+
setVisible(false);
163+
}
164+
});
165+
cancelButton.setEnabled(true);
166+
167+
// think different, biznatchios!
168+
if (Base.isMacOS()) {
169+
buttons.add(cancelButton);
170+
// buttons.add(Box.createHorizontalStrut(8));
171+
buttons.add(okButton);
172+
} else {
173+
buttons.add(okButton);
174+
// buttons.add(Box.createHorizontalStrut(8));
175+
buttons.add(cancelButton);
176+
}
177+
// buttons.setMaximumSize(new Dimension(300, buttons.getPreferredSize().height));
178+
pain.add(buttons);
179+
180+
JRootPane root = getRootPane();
181+
root.setDefaultButton(okButton);
182+
ActionListener disposer = new ActionListener() {
183+
public void actionPerformed(ActionEvent actionEvent) {
184+
setVisible(false);
185+
}
186+
};
187+
processing.app.Toolkit.registerWindowCloseKeys(root, disposer);
188+
processing.app.Toolkit.setIcon(this);
189+
190+
pack();
191+
192+
Dimension screen = processing.app.Toolkit.getScreenSize();
193+
Dimension windowSize = getSize();
194+
195+
setLocation((screen.width - windowSize.width) / 2,
196+
(screen.height - windowSize.height) / 2);
197+
198+
setVisible(true);
199+
}
10200
}

0 commit comments

Comments
 (0)