@@ -44,15 +44,21 @@ public class Permissions extends JFrame {
44
44
static final String GUIDE_URL =
45
45
"https://developer.android.com/training/articles/security-tips.html#Permissions" ;
46
46
47
- static final int BORDER_HORIZ = 5 ;
48
- static final int BORDER_VERT = 3 ;
49
-
47
+ static final int BORDER_HORIZ = Toolkit .zoom (5 );
48
+ static final int BORDER_VERT = Toolkit .zoom (3 );
49
+ static final int CELL_HEIGHT = Toolkit .zoom (20 );
50
+ static final int BORDER = Toolkit .zoom (13 );
51
+ static final int TEXT_WIDTH = Toolkit .zoom (400 );
52
+ static final int TEXT_HEIGHT = Toolkit .zoom (80 );
53
+ static final int URL_WIDTH = Toolkit .zoom (400 );
54
+ static final int URL_HEIGHT = Toolkit .zoom (30 );
55
+ static final int DESC_WIDTH = Toolkit .zoom (400 );
56
+ static final int DESC_HEIGHT = Toolkit .zoom (50 );
57
+ static final int GAP = Toolkit .zoom (8 );
58
+
50
59
JScrollPane permissionScroller ;
51
60
JList <JCheckBox > permissionList ;
52
61
JLabel descriptionLabel ;
53
- // JTextArea descriptionLabel;
54
-
55
- // Editor editor;
56
62
Sketch sketch ;
57
63
58
64
int appComp ;
@@ -61,43 +67,12 @@ public class Permissions extends JFrame {
61
67
62
68
63
69
public Permissions (Sketch sketch , int appComp , File modeFolder ) {
64
- //public Permissions(Editor editor) {
65
70
super ("Android Permissions Selector" );
66
71
this .appComp = appComp ;
67
72
this .sketch = sketch ;
68
73
this .modeFolder = modeFolder ;
69
- // this.editor = editor;
70
-
71
- // XMLElement xml =
72
74
73
75
permissionList = new CheckBoxList ();
74
- // permissionList.addMouseListener(new MouseAdapter() {
75
- // public void mousePressed(MouseEvent e) {
76
- // if (isEnabled()) {
77
- // int index = permissionList.locationToIndex(e.getPoint());
78
- // if (index == -1) {
79
- // descriptionLabel.setText("");
80
- // } else {
81
- //// descriptionLabel.setText("<html>" + description[index] + "</html>");
82
- // descriptionLabel.setText(description[index]);
83
- // }
84
- // }
85
- // }
86
- // });
87
-
88
- // ListSelectionModel lsm = permissionList.getSelectionModel();
89
- // lsm.addListSelectionListener(new ListSelectionListener() {
90
- // public void valueChanged(ListSelectionEvent e) {
91
- //// ListSelectionModel lsm = (ListSelectionModel) e.getSource();
92
- // int index = e.getFirstIndex();
93
- // if (index == -1) {
94
- // descriptionLabel.setText("");
95
- // } else {
96
- // descriptionLabel.setText("<html>" + description[index] + "</html>");
97
- //// descriptionLabel.setText(description[index]);
98
- // }
99
- // }
100
- // });
101
76
permissionList .addListSelectionListener (new ListSelectionListener () {
102
77
public void valueChanged (ListSelectionEvent e ) {
103
78
if (e .getValueIsAdjusting () == false ) {
@@ -106,16 +81,11 @@ public void valueChanged(ListSelectionEvent e) {
106
81
descriptionLabel .setText ("" );
107
82
} else {
108
83
descriptionLabel .setText ("<html>" + description [index ] + "</html>" );
109
- //descriptionLabel.setText(description[index]);
110
84
}
111
85
}
112
86
}
113
87
});
114
- // permissionList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
115
- // permissionList.setFixedCellWidth(300);
116
- // int h = permissionList.getFixedCellHeight();
117
- // permissionList.setFixedCellHeight(h + 8);
118
- permissionList .setFixedCellHeight (20 );
88
+ permissionList .setFixedCellHeight (CELL_HEIGHT );
119
89
permissionList .setBorder (new EmptyBorder (BORDER_VERT , BORDER_HORIZ ,
120
90
BORDER_VERT , BORDER_HORIZ ));
121
91
@@ -129,10 +99,7 @@ public void valueChanged(ListSelectionEvent e) {
129
99
new JScrollPane (permissionList ,
130
100
ScrollPaneConstants .VERTICAL_SCROLLBAR_ALWAYS ,
131
101
ScrollPaneConstants .HORIZONTAL_SCROLLBAR_NEVER );
132
- // permissionList.setVisibleRowCount(20);
133
102
permissionList .setVisibleRowCount (12 );
134
- // permissionList.setPreferredSize(new Dimension(400, 300));
135
- // permissionsScroller.setPreferredSize(new Dimension(400, 300));
136
103
permissionList .addKeyListener (new KeyAdapter () {
137
104
public void keyTyped (KeyEvent e ) {
138
105
if (e .getKeyChar () == ' ' ) {
@@ -146,14 +113,9 @@ public void keyTyped(KeyEvent e) {
146
113
});
147
114
148
115
Container outer = getContentPane ();
149
- // outer.setLayout(new BorderLayout());
150
-
151
- // JPanel pain = new JPanel();
152
- Box pain = Box .createVerticalBox ();
153
- pain .setBorder (new EmptyBorder (13 , 13 , 13 , 13 ));
154
- // outer.add(pain, BorderLayout.CENTER);
155
- outer .add (pain );
156
- // pain.setLayout(new BoxLayout(pain, BoxLayout.Y_AXIS));
116
+ Box vbox = Box .createVerticalBox ();
117
+ vbox .setBorder (new EmptyBorder (BORDER , BORDER , BORDER , BORDER ));
118
+ outer .add (vbox );
157
119
158
120
String labelText =
159
121
"<html>" +
@@ -162,104 +124,41 @@ public void keyTyped(KeyEvent e) {
162
124
"or make phone calls. When installing your application,\n " +
163
125
"users will be asked whether they want to allow such access.</html>" ;
164
126
String urlText = "<html>More about permissions can be found " +
165
- "<a href=\" " + GUIDE_URL + "\" >here</a>.</html>" ;
166
-
167
- // "<html>" +
168
- // "Android applications must specifically ask for permission\n" +
169
- // "to do things like connect to the internet, write a file,\n" +
170
- // "or make phone calls. When installing your application,\n" +
171
- // "users will be asked whether they want to allow such access.\n" +
172
- // "More about permissions can be found " +
173
- // "<a href=\"" + GUIDE_URL + "\">here</a>.</body></html>";
174
- // JTextArea textarea = new JTextArea(labelText);
175
- // JTextArea textarea = new JTextArea(5, 40);
176
- // textarea.setText(labelText);
127
+ "<a href=\" " + GUIDE_URL + "\" >here</a>.</html>" ;
177
128
JLabel textarea = new JLabel (labelText );
178
129
JLabel urlarea = new JLabel (urlText );
179
- // JLabel textarea = new JLabel(labelText) {
180
- // public Dimension getPreferredSize() {
181
- // return new Dimension(400, 100);
182
- // }
183
- // public Dimension getMinimumSize() {
184
- // return getPreferredSize();
185
- // }
186
- // public Dimension getMaximumSize() {
187
- // return getPreferredSize();
188
- // }
189
- // };
190
- textarea .setPreferredSize (new Dimension (400 , 80 ));
191
- urlarea .setPreferredSize (new Dimension (400 , 30 ));
130
+ textarea .setPreferredSize (new Dimension (TEXT_WIDTH , TEXT_HEIGHT ));
131
+ urlarea .setPreferredSize (new Dimension (URL_WIDTH , URL_HEIGHT ));
192
132
urlarea .addMouseListener (new MouseAdapter () {
193
133
public void mouseClicked (MouseEvent e ) {
194
134
Platform .openURL (GUIDE_URL );
195
135
}
196
136
});
197
137
urlarea .setCursor (new java .awt .Cursor (java .awt .Cursor .HAND_CURSOR ));
198
- //textarea.setHorizontalAlignment(SwingConstants.LEFT);
199
138
textarea .setAlignmentX (LEFT_ALIGNMENT );
200
139
urlarea .setAlignmentX (LEFT_ALIGNMENT );
201
-
202
- // textarea.setBorder(new EmptyBorder(13, 8, 13, 8));
203
-
204
- // textarea.setBackground(null);
205
- // textarea.setBackground(Color.RED);
206
- // textarea.setEditable(false);
207
- // textarea.setHighlighter(null);
208
- // textarea.setFont(new Font("Dialog", Font.PLAIN, 12));
209
- pain .add (textarea );
210
- pain .add (urlarea );
211
- // textarea.setForeground(Color.RED);
212
- // pain.setBackground(Color.GREEN);
213
-
214
- // permissionList.setEnabled(false);
140
+ vbox .add (textarea );
141
+ vbox .add (urlarea );
215
142
216
143
permissionScroller .setAlignmentX (LEFT_ALIGNMENT );
217
- pain .add (permissionScroller );
218
- // pain.add(permissionList);
219
- pain .add (Box .createVerticalStrut (8 ));
144
+ vbox .add (permissionScroller );
145
+ vbox .add (Box .createVerticalStrut (GAP ));
220
146
221
- // descriptionLabel = new JTextArea(4, 10);
222
147
descriptionLabel = new JLabel ();
223
- // descriptionLabel = new JLabel() {
224
- // public Dimension getPreferredSize() {
225
- // return new Dimension(400, 100);
226
- // }
227
- // public Dimension getMinimumSize() {
228
- // return new Dimension(400, 100);
229
- // }
230
- // public Dimension getMaximumSize() {
231
- // return new Dimension(400, 100);
232
- // }
233
- // };
234
- descriptionLabel .setPreferredSize (new Dimension (400 , 50 ));
148
+ descriptionLabel .setPreferredSize (new Dimension (DESC_WIDTH , DESC_HEIGHT ));
235
149
descriptionLabel .setVerticalAlignment (SwingConstants .TOP );
236
150
descriptionLabel .setAlignmentX (LEFT_ALIGNMENT );
237
- pain .add (descriptionLabel );
238
- pain .add (Box .createVerticalStrut (8 ));
151
+ vbox .add (descriptionLabel );
152
+ vbox .add (Box .createVerticalStrut (GAP ));
239
153
240
154
JPanel buttons = new JPanel ();
241
- // buttons.setPreferredSize(new Dimension(400, 35));
242
- // JPanel buttons = new JPanel() {
243
- // public Dimension getPreferredSize() {
244
- // return new Dimension(400, 35);
245
- // }
246
- // public Dimension getMinimumSize() {
247
- // return new Dimension(400, 35);
248
- // }
249
- // public Dimension getMaximumSize() {
250
- // return new Dimension(400, 35);
251
- // }
252
- // };
253
-
254
- // Box buttons = Box.createHorizontalBox();
255
155
buttons .setAlignmentX (LEFT_ALIGNMENT );
256
156
JButton okButton = new JButton ("OK" );
257
157
Dimension dim = new Dimension (Toolkit .getButtonWidth (),
258
- okButton .getPreferredSize ().height );
158
+ Toolkit . zoom ( okButton .getPreferredSize ().height ) );
259
159
okButton .setPreferredSize (dim );
260
160
okButton .addActionListener (new ActionListener () {
261
161
public void actionPerformed (ActionEvent e ) {
262
- //PApplet.println(getSelections());
263
162
saveSelections ();
264
163
setVisible (false );
265
164
}
@@ -278,15 +177,12 @@ public void actionPerformed(ActionEvent e) {
278
177
// think different, biznatchios!
279
178
if (Platform .isMacOS ()) {
280
179
buttons .add (cancelButton );
281
- // buttons.add(Box.createHorizontalStrut(8));
282
180
buttons .add (okButton );
283
181
} else {
284
182
buttons .add (okButton );
285
- // buttons.add(Box.createHorizontalStrut(8));
286
183
buttons .add (cancelButton );
287
184
}
288
- // buttons.setMaximumSize(new Dimension(300, buttons.getPreferredSize().height));
289
- pain .add (buttons );
185
+ vbox .add (buttons );
290
186
291
187
JRootPane root = getRootPane ();
292
188
root .setDefaultButton (okButton );
@@ -356,21 +252,6 @@ public String getMenuTitle() {
356
252
}
357
253
358
254
359
- // public void init(Editor editor) {
360
- // this.editor = editor;
361
- // }
362
-
363
-
364
- // public void run() {
365
- // // parse the manifest file here and figure out what permissions are set
366
- // Manifest mf = new Manifest(editor);
367
- // setSelections(mf.getPermissions());
368
- //
369
- // // show the window and get to work
370
- // setVisible(true);
371
- // }
372
-
373
-
374
255
/**
375
256
* Created by running the parse.py script on a saved copy
376
257
* https://developer.android.com/reference/android/Manifest.permission.html
@@ -590,25 +471,14 @@ public Component getListCellRendererComponent(JList<? extends JCheckBox> list,
590
471
JCheckBox checkbox ,
591
472
int index , boolean isSelected ,
592
473
boolean cellHasFocus ) {
593
- // checkbox.setBorder(new EmptyBorder(13, 5, 3, 5)); // trying again
594
474
checkbox .setBackground (isSelected ? getSelectionBackground () : getBackground ());
595
475
checkbox .setForeground (isSelected ? getSelectionForeground () : getForeground ());
596
- //checkbox.setEnabled(isEnabled());
597
476
checkbox .setEnabled (list .isEnabled ());
598
477
checkbox .setFont (getFont ());
599
478
checkbox .setFocusPainted (false );
600
479
checkbox .setBorderPainted (true );
601
480
checkbox .setBorder (isSelected ? UIManager .getBorder ("List.focusCellHighlightBorder" ) : noFocusBorder );
602
481
return checkbox ;
603
482
}
604
-
605
- // @Override
606
- // public Component getListCellRendererComponent(JList<? extends JCheckBox> list,
607
- // JCheckBox value, int index,
608
- // boolean isSelected,
609
- // boolean cellHasFocus) {
610
- // // TODO Auto-generated method stub
611
- // return null;
612
- // }
613
483
}
614
484
}
0 commit comments