Debian Codegraph @

src/java/org/astrogrid/samp/web/SwingOriginAuthorizer.java

raw
1 package org.astrogrid.samp.web;
2
3 import java.awt.Component;
4 import javax.swing.JOptionPane;
5
6 /**
7 * OriginAuthorizer which uses a popup dialogue to ask the user.
8 *
9 * @author Mark Taylor
10 * @since 2 Feb 2011
11 */
12 class SwingOriginAuthorizer implements OriginAuthorizer {
13
14 private final Component parent_;
15
16 /**
17 * Constructor.
18 *
19 * @param parent parent component
20 */
21 public SwingOriginAuthorizer( Component parent ) {
22 parent_ = parent;
23 }
24
25 public boolean authorize( String origin ) {
26 return getResponse( new String[] {
27 "Is the following origin authorized for cross-domain HTTP access?",
28 " " + origin,
29 } );
30 }
31
32 public boolean authorizeAll() {
33 return getResponse( new String[] {
34 "Are all origins authorized for cross-domain HTTP access?",
35 } );
36 }
37
38 /**
39 * Presents some lines of text to the user and solicits a yes/no
40 * response from them.
41 * This method does not need to be called from the AWT event dispatch
42 * thread.
43 *
44 * @param lines lines of formatted plain text
45 * (not too many; not too long)
46 * @return true/false for use yes/no response
47 */
48 protected boolean getResponse( String[] lines ) {
49 return JOptionPane
50 .showOptionDialog( parent_, lines, "Security",
51 JOptionPane.YES_NO_OPTION,
52 JOptionPane.QUESTION_MESSAGE, null,
53 new String[] { "Yes", "No" }, "No" )
54 == 0;
55 }
56 }