protected void populateDialog(JDialog dlg) { dlg.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dlg.setResizable(false); dlg.setSize(new Dimension(350, 135)); dlg.setTitle("New TurboVNC Connection"); dlg.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { if (VncViewer.nViewers == 1) { if (cc.viewer instanceof VncViewer) { ((VncViewer) cc.viewer).exit(1); } } else { ret = false; endDialog(); } } }); dlg.getContentPane().setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.LINE_START; gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridheight = 1; gbc.insets = new Insets(0, 0, 0, 0); gbc.ipadx = 0; gbc.ipady = 0; gbc.weightx = 1; gbc.weighty = 1; dlg.getContentPane().add(topPanel, gbc); dlg.getContentPane().add(buttonPanel); dlg.pack(); }
/** * Creates a dialog where the user can specify the location of the database,including the type of * network connection (if this is a networked client)and IP address and port number; or search and * select the database on a local drive if this is a standalone client. * * @param parent Defines the Component that is to be the parent of this dialog box. For * information on how this is used, see <code>JOptionPane</code> * @param connectionMode Specifies the type of connection (standalone or networked) * @see JOptionPane */ public DatabaseLocationDialog(Frame parent, ApplicationMode connectionMode) { configOptions = (new ConfigOptions(connectionMode)); configOptions.getObservable().addObserver(this); // load saved configuration SavedConfiguration config = SavedConfiguration.getSavedConfiguration(); // the port and connection type are irrelevant in standalone mode if (connectionMode == ApplicationMode.STANDALONE_CLIENT) { validPort = true; validCnx = true; networkType = ConnectionType.DIRECT; location = config.getParameter(SavedConfiguration.DATABASE_LOCATION); } else { // there may not be a network connectivity type defined and, if // not, we do not set a default - force the user to make a choice // the at least for the first time they run this. String tmp = config.getParameter(SavedConfiguration.NETWORK_TYPE); if (tmp != null) { try { networkType = ConnectionType.valueOf(tmp); configOptions.setNetworkConnection(networkType); validCnx = true; } catch (IllegalArgumentException e) { log.warning("Unknown connection type: " + networkType); } } // there is always at least a default port number, so we don't have // to validate this. port = config.getParameter(SavedConfiguration.SERVER_PORT); configOptions.setPortNumberText(port); validPort = true; location = config.getParameter(SavedConfiguration.SERVER_ADDRESS); } // there may not be a default database location, so we had better // validate before using the returned value. if (location != null) { configOptions.setLocationFieldText(location); validDb = true; } options = new JOptionPane(configOptions, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); connectButton.setActionCommand(CONNECT); connectButton.addActionListener(this); boolean allValid = validDb && validPort && validCnx; connectButton.setEnabled(allValid); exitButton.setActionCommand(EXIT); exitButton.addActionListener(this); options.setOptions(new Object[] {connectButton, exitButton}); dialog = options.createDialog(parent, TITLE); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(this); dialog.setVisible(true); }
public void initComponents() { final Browser browser = new Browser(); BrowserView browserView = new BrowserView(browser); JFrame parent = new JFrame(); final JDialog dialog = new JDialog(parent, "QUIZ", true); browser.addLoadListener( new LoadAdapter() { @Override public void onFinishLoadingFrame(FinishLoadingEvent event) { if (event.isMainFrame()) { String videoUrl = "https://www.youtube.com/embed/" + url + "?rel=0&controls=0&showinfo=0"; DOMDocument document = event.getBrowser().getDocument(); DOMNode root = document.findElement(By.id("video")); DOMElement iframe = document.createElement("iframe"); iframe.setAttribute("src", videoUrl); iframe.setAttribute("frameborder", "0"); root.appendChild(iframe); DOMNode root2 = document.findElement(By.id("text")); DOMElement p = document.createElement("p"); p.setAttribute("class", "text"); DOMNode n = document.createTextNode(question.getText()); root2.appendChild(p); p.appendChild(n); DOMNode answers = document.findElement(By.id("answers")); if (question.getAnswerType().equals(AnswerType.MULTIPLE_CHOICE)) { DOMNode form = document.createElement("form"); AnswerManager am = new AnswerManager(session); List<String> answerList = am.getAnswerByQuestionId(question.getId()); for (String answer : answerList) { DOMElement trueBox = document.createElement("input"); trueBox.setAttribute("type", "radio"); trueBox.setAttribute("name", "tf"); DOMNode dataTrue = document.createTextNode(answer); DOMElement labeltrue = document.createElement("label"); labeltrue.appendChild(dataTrue); form.appendChild(trueBox); form.appendChild(labeltrue); DOMElement br = document.createElement("br"); form.appendChild(br); } answers.appendChild(form); } if (question.getAnswerType().equals(AnswerType.TRUE_FALSE)) { DOMNode form = document.createElement("form"); DOMElement trueBox = document.createElement("input"); trueBox.setAttribute("type", "radio"); trueBox.setAttribute("name", "tf"); DOMNode dataTrue = document.createTextNode("true"); DOMElement labeltrue = document.createElement("label"); labeltrue.appendChild(dataTrue); DOMElement falseBox = document.createElement("input"); DOMNode dataFalse = document.createTextNode("false"); DOMElement labelFalse = document.createElement("label"); labelFalse.appendChild(dataFalse); falseBox.setAttribute("type", "radio"); falseBox.setAttribute("name", "tf"); form.appendChild(labeltrue); form.appendChild(trueBox); DOMElement br = document.createElement("br"); form.appendChild(br); form.appendChild(labelFalse); form.appendChild(falseBox); // answers.appendChild(form); } } } }); browser.loadURL("http://dtprojecten.ehb.be/~PR-Ready/question/videoFrame.html?853954951951959"); dialog.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); } }); browser.registerFunction( "nextQuestion", new BrowserFunction() { public JSValue invoke(JSValue... jsValues) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); quizLauncher.setIncrement(quizLauncher.getIncrement() + 1); quizLauncher.windowChoice(); return JSValue.createUndefined(); } }); browser.registerFunction( "previousQuestion", new BrowserFunction() { public JSValue invoke(JSValue... jsValues) { browser.dispose(); dialog.setVisible(false); dialog.dispose(); quizLauncher.setIncrement(quizLauncher.getIncrement() - 1); quizLauncher.windowChoice(); return JSValue.createUndefined(); } }); dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); dialog.add(new BrowserView(browser), BorderLayout.CENTER); dialog.setResizable(false); dialog.setUndecorated(true); dialog.setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); dialog.setLocationRelativeTo(parent); dialog.setVisible(true); }