Skip to content

Commit 4dcc42e

Browse files
committed
hi-dpi handling for key manager dialogs
1 parent 1ae97df commit 4dcc42e

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

src/processing/mode/android/KeyStoreManager.java

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141

4242
@SuppressWarnings("serial")
4343
public class KeyStoreManager extends JFrame {
44+
final static private int BOX_BORDER = Toolkit.zoom(13);
45+
final static private int PASS_BORDER = Toolkit.zoom(15);
46+
final static private int LABEL_WIDTH = Toolkit.zoom(400);
47+
final static private int LABEL_HEIGHT = Toolkit.zoom(100);
48+
final static private int GAP = Toolkit.zoom(13);
49+
4450
static final String GUIDE_URL =
4551
"https://developer.android.com/studio/publish/app-signing.html";
4652

@@ -68,23 +74,25 @@ private void createLayout() {
6874
Container outer = getContentPane();
6975
outer.removeAll();
7076

71-
Box pain = Box.createVerticalBox();
72-
pain.setBorder(new EmptyBorder(13, 13, 13, 13));
73-
outer.add(pain);
77+
Box vbox = Box.createVerticalBox();
78+
vbox.setBorder(new EmptyBorder(BOX_BORDER, BOX_BORDER, BOX_BORDER, BOX_BORDER));
79+
outer.add(vbox);
7480

7581
keyStore = AndroidKeyStore.getKeyStore();
7682
if (keyStore != null) {
77-
showKeystorePasswordLayout(pain);
83+
showKeystorePasswordLayout(vbox);
7884
} else {
79-
showKeystoreCredentialsLayout(pain);
85+
showKeystoreCredentialsLayout(vbox);
8086
}
8187

88+
vbox.add(Box.createVerticalStrut(GAP));
89+
8290
// buttons
8391
JPanel buttons = new JPanel();
8492
buttons.setAlignmentX(LEFT_ALIGNMENT);
8593
JButton okButton = new JButton("OK");
8694
Dimension dim = new Dimension(Toolkit.getButtonWidth(),
87-
okButton.getPreferredSize().height);
95+
Toolkit.zoom(okButton.getPreferredSize().height));
8896
okButton.setPreferredSize(dim);
8997
okButton.addActionListener(new ActionListener() {
9098
public void actionPerformed(ActionEvent e) {
@@ -120,14 +128,16 @@ public void actionPerformed(ActionEvent e) {
120128

121129
JButton resetKeystoreButton = new JButton("Reset password");
122130
dim = new Dimension(Toolkit.getButtonWidth()*2,
123-
okButton.getPreferredSize().height);
131+
Toolkit.zoom(resetKeystoreButton.getPreferredSize().height));
124132
resetKeystoreButton.setPreferredSize(dim);
125133
resetKeystoreButton.addActionListener(new ActionListener() {
126134
public void actionPerformed(ActionEvent e) {
127135
setVisible(false);
128136
int result = Messages.showYesNoQuestion(editor, "Android keystore",
129-
"Are you sure you want to reset the password?", "We will have to reset the keystore to do this, " +
130-
"which means you won't be able to upload an update for your app signed with the new keystore to Google Play.\n\n" +
137+
"Are you sure you want to reset the password?",
138+
"We will have to reset the keystore to do this, which means \n" +
139+
"you won't be able to upload an update for your app signed with\n" +
140+
"the new keystore to Google Play.\n\n" +
131141
"We will make a backup for the old keystore.");
132142

133143
if (result == JOptionPane.NO_OPTION) {
@@ -160,7 +170,7 @@ public void actionPerformed(ActionEvent e) {
160170
buttons.add(cancelButton);
161171
}
162172
// buttons.setMaximumSize(new Dimension(300, buttons.getPreferredSize().height));
163-
pain.add(buttons);
173+
vbox.add(buttons);
164174

165175
JRootPane root = getRootPane();
166176
root.setDefaultButton(okButton);
@@ -211,7 +221,7 @@ private boolean checkRequiredFields() {
211221
}
212222
}
213223

214-
private void showKeystoreCredentialsLayout(Box pain) {
224+
private void showKeystoreCredentialsLayout(Box box) {
215225
String labelText =
216226
"<html>" +
217227
"Please enter the information below so we can generate a private key for you.<br/>" +
@@ -220,14 +230,14 @@ private void showKeystoreCredentialsLayout(Box pain) {
220230
"More about private keys can be found " +
221231
"<a href=\"" + GUIDE_URL + "\">here</a>.</body></html>";
222232
JLabel textarea = new JLabel(labelText);
223-
textarea.setPreferredSize(new Dimension(400, 100));
233+
textarea.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT));
224234
textarea.addMouseListener(new MouseAdapter() {
225235
public void mouseClicked(MouseEvent e) {
226236
Platform.openURL(GUIDE_URL);
227237
}
228238
});
229239
textarea.setAlignmentX(LEFT_ALIGNMENT);
230-
pain.add(textarea);
240+
box.add(textarea);
231241

232242
// password field
233243
passwordField = new JPasswordField(15);
@@ -238,7 +248,7 @@ public void mouseClicked(MouseEvent e) {
238248
textPane.add(passwordLabel);
239249
textPane.add(passwordField);
240250
textPane.setAlignmentX(LEFT_ALIGNMENT);
241-
pain.add(textPane);
251+
box.add(textPane);
242252

243253
// repeat password field
244254
repeatPasswordField = new JPasswordField(15);
@@ -249,14 +259,14 @@ public void mouseClicked(MouseEvent e) {
249259
textPane.add(repeatPasswordLabel);
250260
textPane.add(repeatPasswordField);
251261
textPane.setAlignmentX(LEFT_ALIGNMENT);
252-
textPane.setBorder(new EmptyBorder(0, 0, 15, 0));
253-
pain.add(textPane);
262+
textPane.setBorder(new EmptyBorder(0, 0, PASS_BORDER, 0));
263+
box.add(textPane);
254264

255265
MatteBorder mb = new MatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY);
256266
TitledBorder tb = new TitledBorder(mb, "Keystore issuer credentials", TitledBorder.LEFT, TitledBorder.DEFAULT_POSITION);
257267
JPanel separatorPanel = new JPanel();
258268
separatorPanel.setBorder(tb);
259-
pain.add(separatorPanel);
269+
box.add(separatorPanel);
260270

261271
// common name (CN)
262272
commonName = new JTextField(15);
@@ -267,7 +277,7 @@ public void mouseClicked(MouseEvent e) {
267277
textPane.add(commonNameLabel);
268278
textPane.add(commonName);
269279
textPane.setAlignmentX(LEFT_ALIGNMENT);
270-
pain.add(textPane);
280+
box.add(textPane);
271281

272282
// organizational unit (OU)
273283
organizationalUnit = new JTextField(15);
@@ -278,7 +288,7 @@ public void mouseClicked(MouseEvent e) {
278288
textPane.add(organizationalUnitLabel);
279289
textPane.add(organizationalUnit);
280290
textPane.setAlignmentX(LEFT_ALIGNMENT);
281-
pain.add(textPane);
291+
box.add(textPane);
282292

283293
// organization name (O)
284294
organizationName = new JTextField(15);
@@ -289,7 +299,7 @@ public void mouseClicked(MouseEvent e) {
289299
textPane.add(organizationNameLabel);
290300
textPane.add(organizationName);
291301
textPane.setAlignmentX(LEFT_ALIGNMENT);
292-
pain.add(textPane);
302+
box.add(textPane);
293303

294304
// locality name (L)
295305
localityName = new JTextField(15);
@@ -300,7 +310,7 @@ public void mouseClicked(MouseEvent e) {
300310
textPane.add(localityNameLabel);
301311
textPane.add(localityName);
302312
textPane.setAlignmentX(LEFT_ALIGNMENT);
303-
pain.add(textPane);
313+
box.add(textPane);
304314

305315
// state name (S)
306316
stateName = new JTextField(15);
@@ -311,7 +321,7 @@ public void mouseClicked(MouseEvent e) {
311321
textPane.add(stateNameLabel);
312322
textPane.add(stateName);
313323
textPane.setAlignmentX(LEFT_ALIGNMENT);
314-
pain.add(textPane);
324+
box.add(textPane);
315325

316326
// country (C)
317327
country = new JTextField(15);
@@ -322,6 +332,6 @@ public void mouseClicked(MouseEvent e) {
322332
textPane.add(countryLabel);
323333
textPane.add(country);
324334
textPane.setAlignmentX(LEFT_ALIGNMENT);
325-
pain.add(textPane);
335+
box.add(textPane);
326336
}
327337
}

0 commit comments

Comments
 (0)