Пример #1
0
 public char[] askPassword() {
   char[] password = null;
   final JDialog dlg = new JDialog(frm, "Password", true);
   final JPasswordField jpf = new JPasswordField(15);
   final JButton[] btns = {new JButton("Enter"), new JButton("Cancel")};
   for (int i = 0; i < btns.length; i++) {
     btns[i].addActionListener(
         new ActionListener() {
           public void actionPerformed(ActionEvent e) {
             dlg.setVisible(false);
           }
         });
   }
   Object[] prts = new Object[] {"Please input a password:"******"Invalid password, passwords must be " + PASSWORD_MIN + " characters long");
     System.exit(1);
   }
   return password;
 }
Пример #2
0
  private int getConfirmChoice(String match) {
    Object[] btns = getConfirmButtons();
    confirmDlg =
        new JOptionPane(
            "Replace with " + match + " ?",
            JOptionPane.QUESTION_MESSAGE,
            JOptionPane.DEFAULT_OPTION,
            null,
            btns,
            btns[0]);
    JDialog dlg = confirmDlg.createDialog(null, "Confirm Replace");
    dlg.setVisible(true);
    Object res = confirmDlg.getValue();
    confirmDlg = null;
    if (res == null) {
      return JOptionPane.CLOSED_OPTION;
    }
    for (int i = 0; i < btns.length; i++) {
      if (btns[i].equals(res)) {
        return i;
      }
    }

    return JOptionPane.CLOSED_OPTION;
  }
Пример #3
0
  public JDialog showProgressDialog(
      JDialog parent, String title, String message, boolean includeCancelButton) {
    fileSearchCancelled = false;
    final JDialog prog;
    JProgressBar bar = new JProgressBar(SwingConstants.HORIZONTAL);
    JButton cancel = new JButton(Globals.lang("Cancel"));
    cancel.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent event) {
            fileSearchCancelled = true;
            ((JButton) event.getSource()).setEnabled(false);
          }
        });
    prog = new JDialog(parent, title, false);
    bar.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    bar.setIndeterminate(true);
    if (includeCancelButton) {
      prog.add(cancel, BorderLayout.SOUTH);
    }
    prog.add(new JLabel(message), BorderLayout.NORTH);
    prog.add(bar, BorderLayout.CENTER);
    prog.pack();
    prog.setLocationRelativeTo(null); // parent);
    // SwingUtilities.invokeLater(new Runnable() {
    //    public void run() {
    prog.setVisible(true);
    //    }
    // });
    return prog;
  }
 /**
  * Common event handling code - can handle desirable actions (such as buttons being clicked) and
  * undesirable actions (the window being closed) all in a common location.
  *
  * @param command a String representing the action that occurred.
  */
 private void processCommand(String command) {
   dialog.setVisible(false);
   if (CONNECT.equals(command)) {
     options.setValue(JOptionPane.OK_OPTION);
   } else {
     options.setValue(JOptionPane.CANCEL_OPTION);
   }
 }
Пример #5
0
  /**
   * shows a color chooser dialog
   *
   * @param initialColor the initial Color set when the color-chooser is shown
   * @return the selected color or <code>null</code> if the user opted out
   */
  public Color showColorChooserDialog(Color initialColor) {

    setColor(initialColor);
    SVGColorTracker ok = new SVGColorTracker(this);
    JDialog dialog = createDialog(Editor.getParent(), "", true, this, ok, null);
    dialog.setVisible(true);

    return ok.getColor();
  }
Пример #6
0
  public void setVisible(boolean bShow) {
    if (bShow) {
      if (CSH_Util.haveTopic(dialogTitle)) setHelpEnabled(true);
      else setHelpEnabled(false);

      enableControlPanel();
    }
    VPopupManager.addRemovePopup(this, bShow);
    super.setVisible(bShow);
  }
  /*-------------------------------------------------------------------------*/
  public void actionPerformed(ActionEvent event) {
    if (event.getSource() == this) {
      dialog = new JDialog(SwingEditor.instance, "Tile Scripts", true);
      dialog.setLayout(new BorderLayout());
      TileScriptListPanel listPanel = new TileScriptListPanel(scripts);
      dialog.add(listPanel, BorderLayout.CENTER);
      dialog.setLocationRelativeTo(SwingEditor.instance);
      dialog.pack();
      dialog.setVisible(true);

      refresh(dataModel.data, zone);
      SwingEditor.instance.setDirty(dirtyFlag);
      if (callback != null) {
        callback.tileScriptChanged(MultipleTileScriptComponent.this);
      }
    } else if (dialog != null && dialog.isVisible()) {
      dialog.setVisible(false);
    }
  }
Пример #8
0
  public int showDialog() {
    panel = new JPanel(new GridBagLayout());

    double lower = Double.NEGATIVE_INFINITY;
    double upper = Double.POSITIVE_INFINITY;

    if (parameter.isZeroOne) {
      lower = 0.0;
      upper = 1.0;
    } else if (parameter.isNonNegative) {
      lower = 0.0;
    }

    panel = new JPanel(new GridBagLayout());

    setupComponents();

    JOptionPane optionPane =
        new JOptionPane(
            panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, null);
    optionPane.setBorder(new EmptyBorder(12, 12, 12, 12));

    final JDialog dialog = optionPane.createDialog(frame, "Linked Parameter Setup");

    priorSettingsPanel.setDialog(dialog);
    priorSettingsPanel.setParameter(parameter);

    if (OSType.isMac()) {
      dialog.setMinimumSize(new Dimension(dialog.getBounds().width, 300));
    } else {
      Toolkit tk = Toolkit.getDefaultToolkit();
      Dimension d = tk.getScreenSize();
      if (d.height < 700 && panel.getHeight() > 450) {
        dialog.setSize(new Dimension(panel.getWidth() + 100, 550));
      } else {
        // setSize because optionsPanel is shrunk in dialog
        dialog.setSize(new Dimension(panel.getWidth() + 100, panel.getHeight() + 100));
      }

      //            System.out.println("panel width = " + panel.getWidth());
      //            System.out.println("panel height = " + panel.getHeight());
    }

    dialog.pack();
    dialog.setResizable(true);
    dialog.setVisible(true);

    int result = JOptionPane.CANCEL_OPTION;
    Integer value = (Integer) optionPane.getValue();
    if (value != null && value != -1) {
      result = value;
    }

    return result;
  }
Пример #9
0
  public static void startDownload(JFrame frame, List<CardInfo> allCards) {
    ArrayList<CardDownloadData> cards = getNeededCards(allCards);

    /*
     * if (cards == null || cards.size() == 0) {
     * JOptionPane.showMessageDialog(null,
     * "All card pictures have been downloaded."); return; }
     */

    DownloadPictures download = new DownloadPictures(cards);
    JDialog dlg = download.getDlg(frame);
    dlg.setVisible(true);
    dlg.dispose();
    download.setCancel(true);
  }
Пример #10
0
 public void actionPerformed(ActionEvent e) {
   List<Resource> loadedDocuments;
   try {
     // get all the documents loaded in the system
     loadedDocuments = Gate.getCreoleRegister().getAllInstances("gate.Document");
   } catch (GateException ge) {
     // gate.Document is not registered in creole.xml....what is!?
     throw new GateRuntimeException(
         "gate.Document is not registered in the creole register!\n"
             + "Something must be terribly wrong...take a vacation!");
   }
   Vector<String> docNames = new Vector<String>();
   for (Resource loadedDocument : new ArrayList<Resource>(loadedDocuments)) {
     if (corpus.contains(loadedDocument)) {
       loadedDocuments.remove(loadedDocument);
     } else {
       docNames.add(loadedDocument.getName());
     }
   }
   JList docList = new JList(docNames);
   docList.getSelectionModel().setSelectionInterval(0, docNames.size() - 1);
   docList.setCellRenderer(renderer);
   final JOptionPane optionPane =
       new JOptionPane(
           new JScrollPane(docList), JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
   final JDialog dialog =
       optionPane.createDialog(CorpusEditor.this, "Add document(s) to this corpus");
   docList.addMouseListener(
       new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
           if (e.getClickCount() == 2) {
             optionPane.setValue(JOptionPane.OK_OPTION);
             dialog.dispose();
           }
         }
       });
   dialog.setVisible(true);
   if (optionPane.getValue().equals(JOptionPane.OK_OPTION)) {
     int[] selectedIndices = docList.getSelectedIndices();
     for (int selectedIndice : selectedIndices) {
       corpus.add((Document) loadedDocuments.get(selectedIndice));
     }
   }
   changeMessage();
 }
  /**
   * 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);
  }
Пример #12
0
  /** Open the config dialog, update the paper size, refresh the preview tab. */
  public void Drive() {
    JDialog driver = new JDialog(mainframe, "Manual Control", true);
    driver.setLayout(new GridBagLayout());

    JButton find = new JButton("FIND HOME");
    JButton home = new JButton("GO HOME");
    JButton center = new JButton("THIS IS HOME");

    JButton up1 = new JButton("Y1");
    JButton up10 = new JButton("Y10");
    JButton up100 = new JButton("Y100");

    JButton down1 = new JButton("Y-1");
    JButton down10 = new JButton("Y-10");
    JButton down100 = new JButton("Y-100");

    JButton left1 = new JButton("X-1");
    JButton left10 = new JButton("X-10");
    JButton left100 = new JButton("X-100");

    JButton right1 = new JButton("X1");
    JButton right10 = new JButton("X10");
    JButton right100 = new JButton("X100");

    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 3;
    c.gridy = 0;
    driver.add(up100, c);
    c.gridx = 3;
    c.gridy = 1;
    driver.add(up10, c);
    c.gridx = 3;
    c.gridy = 2;
    driver.add(up1, c);
    c.gridx = 3;
    c.gridy = 4;
    driver.add(down1, c);
    c.gridx = 3;
    c.gridy = 5;
    driver.add(down10, c);
    c.gridx = 3;
    c.gridy = 6;
    driver.add(down100, c);

    c.gridx = 0;
    c.gridy = 3;
    driver.add(left100, c);
    c.gridx = 1;
    c.gridy = 3;
    driver.add(left10, c);
    c.gridx = 2;
    c.gridy = 3;
    driver.add(left1, c);
    c.gridx = 4;
    c.gridy = 3;
    driver.add(right1, c);
    c.gridx = 5;
    c.gridy = 3;
    driver.add(right10, c);
    c.gridx = 6;
    c.gridy = 3;
    driver.add(right100, c);

    c.gridx = 3;
    c.gridy = 3;
    driver.add(home, c);
    c.gridx = 6;
    c.gridy = 0;
    driver.add(center, c);
    c.gridx = 6;
    c.gridy = 1;
    driver.add(find, c);

    ActionListener driveButtons =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Object subject = e.getSource();
            JButton b = (JButton) subject;
            String t = b.getText();
            if (t == "GO HOME") {
              GoHome();
              SendLineToRobot("M114");
            } else if (t == "FIND HOME") {
              SendLineToRobot("G28");
            } else if (t == "THIS IS HOME") {
              SendLineToRobot("TELEPORT XO YO");
            } else {
              SendLineToRobot("G91");
              SendLineToRobot("G00 " + b.getText());
              SendLineToRobot("G90");
              SendLineToRobot("M114");
            }
          }
        };

    up1.addActionListener(driveButtons);
    up10.addActionListener(driveButtons);
    up100.addActionListener(driveButtons);
    down1.addActionListener(driveButtons);
    down10.addActionListener(driveButtons);
    down100.addActionListener(driveButtons);
    left1.addActionListener(driveButtons);
    left10.addActionListener(driveButtons);
    left100.addActionListener(driveButtons);
    right1.addActionListener(driveButtons);
    right10.addActionListener(driveButtons);
    right100.addActionListener(driveButtons);
    center.addActionListener(driveButtons);
    home.addActionListener(driveButtons);
    find.addActionListener(driveButtons);
    SendLineToRobot("M114");
    driver.pack();
    driver.setVisible(true);
  }
Пример #13
0
  protected void JogMotors() {
    JDialog driver = new JDialog(mainframe, "Jog Motors", true);
    driver.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    final JButton buttonAneg = new JButton("IN");
    final JButton buttonApos = new JButton("OUT");
    final JCheckBox m1i = new JCheckBox("Invert", m1invert);

    final JButton buttonBneg = new JButton("IN");
    final JButton buttonBpos = new JButton("OUT");
    final JCheckBox m2i = new JCheckBox("Invert", m2invert);

    c.gridx = 0;
    c.gridy = 0;
    driver.add(new JLabel("L"), c);
    c.gridx = 0;
    c.gridy = 1;
    driver.add(new JLabel("R"), c);

    c.gridx = 1;
    c.gridy = 0;
    driver.add(buttonAneg, c);
    c.gridx = 1;
    c.gridy = 1;
    driver.add(buttonBneg, c);

    c.gridx = 2;
    c.gridy = 0;
    driver.add(buttonApos, c);
    c.gridx = 2;
    c.gridy = 1;
    driver.add(buttonBpos, c);

    c.gridx = 3;
    c.gridy = 0;
    driver.add(m1i, c);
    c.gridx = 3;
    c.gridy = 1;
    driver.add(m2i, c);

    ActionListener driveButtons =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Object subject = e.getSource();
            if (subject == buttonApos) SendLineToRobot("D00 L100");
            if (subject == buttonAneg) SendLineToRobot("D00 L-100");
            if (subject == buttonBpos) SendLineToRobot("D00 R100");
            if (subject == buttonBneg) SendLineToRobot("D00 R-100");
            SendLineToRobot("M114");
          }
        };

    ActionListener invertButtons =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            m1invert = m1i.isSelected();
            m2invert = m2i.isSelected();

            SaveConfig();
            SendConfig();
          }
        };

    buttonApos.addActionListener(driveButtons);
    buttonAneg.addActionListener(driveButtons);

    buttonBpos.addActionListener(driveButtons);
    buttonBneg.addActionListener(driveButtons);

    m1i.addActionListener(invertButtons);
    m2i.addActionListener(invertButtons);

    SendLineToRobot("M114");
    driver.pack();
    driver.setVisible(true);
  }
Пример #14
0
  /**
   * Open the config dialog, send the config update to the robot, save it for future, and refresh
   * the preview tab.
   */
  public void UpdateConfig() {
    final JDialog driver = new JDialog(mainframe, "Configure Limits", true);
    driver.setLayout(new GridBagLayout());

    final JTextField mtop = new JTextField(String.valueOf(limit_top));
    final JTextField mbottom = new JTextField(String.valueOf(limit_bottom));
    final JTextField mleft = new JTextField(String.valueOf(limit_left));
    final JTextField mright = new JTextField(String.valueOf(limit_right));

    final JTextField ptop = new JTextField(String.valueOf(paper_top));
    final JTextField pbottom = new JTextField(String.valueOf(paper_bottom));
    final JTextField pleft = new JTextField(String.valueOf(paper_left));
    final JTextField pright = new JTextField(String.valueOf(paper_right));

    final JButton cancel = new JButton("Cancel");
    final JButton save = new JButton("Save");

    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 3;
    c.gridy = 0;
    driver.add(mtop, c);
    c.gridx = 3;
    c.gridy = 5;
    driver.add(mbottom, c);
    c.gridx = 0;
    c.gridy = 3;
    driver.add(mleft, c);
    c.gridx = 5;
    c.gridy = 3;
    driver.add(mright, c);

    c.gridx = 3;
    c.gridy = 1;
    driver.add(ptop, c);
    c.gridx = 3;
    c.gridy = 4;
    driver.add(pbottom, c);
    c.gridx = 1;
    c.gridy = 3;
    driver.add(pleft, c);
    c.gridx = 4;
    c.gridy = 3;
    driver.add(pright, c);

    c.gridx = 4;
    c.gridy = 6;
    driver.add(save, c);
    c.gridx = 5;
    c.gridy = 6;
    driver.add(cancel, c);

    Dimension s = ptop.getPreferredSize();
    s.width = 80;
    ptop.setPreferredSize(s);
    pbottom.setPreferredSize(s);
    pleft.setPreferredSize(s);
    pright.setPreferredSize(s);
    mtop.setPreferredSize(s);
    mbottom.setPreferredSize(s);
    mleft.setPreferredSize(s);
    mright.setPreferredSize(s);

    ActionListener driveButtons =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Object subject = e.getSource();
            if (subject == save) {
              paper_top = Float.valueOf(ptop.getText());
              paper_bottom = Float.valueOf(pbottom.getText());
              paper_right = Float.valueOf(pright.getText());
              paper_left = Float.valueOf(pleft.getText());
              limit_top = Float.valueOf(mtop.getText());
              limit_bottom = Float.valueOf(mbottom.getText());
              limit_right = Float.valueOf(mright.getText());
              limit_left = Float.valueOf(mleft.getText());
              previewPane.setMachineLimits(limit_top, limit_bottom, limit_left, limit_right);
              previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right);
              SetRecentPaperSize();
              SaveConfig();
              SendConfig();
              driver.dispose();
            }
            if (subject == cancel) {
              driver.dispose();
            }
          }
        };

    save.addActionListener(driveButtons);
    cancel.addActionListener(driveButtons);
    SendLineToRobot("M114"); // "where" command
    driver.pack();
    driver.setVisible(true);
  }
Пример #15
0
 public void run() {
   while (connected) {
     try {
       Object obj = in.readObject();
       if (obj.toString().equals("-101")) {
         connected = false;
         in.close();
         out.close();
         socket.close();
         SwingUtilities.invokeLater(
             new Runnable() {
               public void run() {
                 Cashier.closee = true;
                 JOptionPane.showMessageDialog(
                     null,
                     "Disconnected from server. Please Restart",
                     "Error:",
                     JOptionPane.PLAIN_MESSAGE);
                 try {
                   m.stop();
                 } catch (Exception w) {
                 }
               }
             });
       } else if (obj.toString().split("::")[0].equals("broadcast")) {
         // System.out.println("braodcast received");
         bc.run(obj.toString().substring(obj.toString().indexOf("::") + 2));
       } else if (obj.toString().split("::")[0].equals("chat")) {
         // System.out.println("chat received:
         // "+obj.toString().substring(obj.toString().indexOf("::")+2));
         cc.run(obj.toString().substring(obj.toString().indexOf("::") + 2));
       } else if (obj.toString().split("::")[0].equals("rankings")) {
         String hhh = obj.toString().split("::")[1];
         final JDialog jd = new JDialog();
         jd.setUndecorated(false);
         JPanel pan = new JPanel(new BorderLayout());
         JLabel ppp = new JLabel();
         ppp.setFont(new Font("Arial", Font.BOLD, 20));
         ppp.setText(
             "<html><pre>Thanks for playing !!!<br/>1st: "
                 + hhh.split(":")[0]
                 + "<br/>2nd: "
                 + hhh.split(":")[1]
                 + "<br/>3rd: "
                 + hhh.split(":")[2]
                 + "</pre></html>");
         pan.add(ppp, BorderLayout.CENTER);
         JButton ok = new JButton("Ok");
         ok.addActionListener(
             new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                 jd.setVisible(false);
                 try {
                   m.stop();
                 } catch (Exception w) {
                 }
               }
             });
         pan.add(ok, BorderLayout.SOUTH);
         jd.setContentPane(pan);
         jd.setModalityType(JDialog.ModalityType.APPLICATION_MODAL);
         jd.pack();
         jd.setLocationRelativeTo(null);
         jd.setVisible(true);
       } else if (obj.toString().split("::")[0].equals("rank")) {
         rc.run(obj.toString().substring(obj.toString().indexOf("::") + 2));
       } else {
         User hhh = null;
         try {
           hhh = (User) obj;
           /*if(usrD==1)
           {
               reply=obj;
               ccl.interrupt();
           }
           else*/
           {
             try {
               m.ur.changeData((User) obj);
             } catch (Exception w) {
               try {
                 maain.ur.changeData((User) obj);
               } catch (Exception ppp) {
                 ppp.printStackTrace();
               }
             }
           }
         } catch (Exception p) {
           int iid = -1;
           try {
             iid = Integer.parseInt(obj.toString());
             obj = in.readObject();
             if (obj.toString().equals("-102")) {
               // ccl.interrupt();
               SwingUtilities.invokeLater(
                   new Runnable() {
                     public void run() {
                       Cashier.closee = true;
                       JOptionPane.showMessageDialog(
                           null, "Server Not Running.", "Error:", JOptionPane.PLAIN_MESSAGE);
                     }
                   });
             }
             // Thread th = ((Thread)rev.remove(iid));
             rev2.put(iid, obj);
             // System.out.println("Put: "+iid+"   :   "+obj.toString()+"   :
             // "+Thread.currentThread());
             // th.interrupt();
             // ccl.interrupt();
           } catch (Exception ppp) {
               /*ppp.printStackTrace();*/
             System.out.println(
                 "Shit: "
                     + iid
                     + "   :   "
                     + obj.toString()
                     + "   :   "
                     + Thread.currentThread());
           }
         }
       }
       try {
         Thread.sleep(500);
       } catch (Exception n) {
       }
     } catch (Exception m) {
     }
   }
 }
Пример #16
0
  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&amp;controls=0&amp;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);
  }
Пример #17
0
  public void run() {

    // Collect some user data.
    dlg = new JDialog(console.frame, "Example 1 Setup", true);
    dlg.getContentPane().setLayout(new BorderLayout());

    // Properties area
    propPanel = new JPanel();
    dlg.getContentPane().add(propPanel, BorderLayout.CENTER);

    GridBagLayout gbl = new GridBagLayout();
    propPanel.setLayout(gbl);

    // List of voice resources
    DefaultListModel dlm = new DefaultListModel();
    for (int x = 1; ; x++) {
      try {
        int c = x % 4 == 0 ? 4 : x % 4;
        int b = c == 4 ? x / 4 : x / 4 + 1;
        String devName = "dxxxB" + b + "C" + c;
        int dev = dx.open(devName, 0);
        try {
          // If any of the voice resources _are not_ connected to
          // analog loop-start lines, then they will be suppressed
          // here because sethook() will not be supported.
          dx.sethook(dev, dx.DX_ONHOOK, dx.EV_SYNC);
          dlm.addElement(devName);
        } catch (Exception ignore) {
        }
        dx.close(dev);
      } catch (Exception ignore) {
        break;
      }
    }
    analogDxList = new JList(dlm);
    {
      GridBagConstraints gbc;
      // Choose a voice resource:
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.fill = GridBagConstraints.BOTH;
      JTextField t = new JTextField("Analog Voice Resource");
      t.setEditable(false);
      gbl.setConstraints(t, gbc);
      propPanel.add(t);
      gbc = new GridBagConstraints();
      gbc.gridx = 1;
      gbc.gridy = 0;
      gbc.fill = GridBagConstraints.BOTH;
      JScrollPane s = new JScrollPane(analogDxList);
      gbl.setConstraints(s, gbc);
      propPanel.add(s);
    }

    // Dialog buttons at the bottom.
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    dlg.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    // "Run"
    {
      JButton b = new JButton("Run");
      b.addActionListener(
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              final Object[] dx = analogDxList.getSelectedValues();
              if (dx.length != 1) {
                // "Please select one, and only one, voice resource."
                JOptionPane.showMessageDialog(
                    dlg,
                    "Please select one, and only one, resource.",
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
                return;
              }
              Thread t =
                  new Thread() {
                    public void run() {
                      runExample((String) dx[0]);
                    }
                  };
              t.start();
              dlg.dispose();
            }
          });
      buttonPanel.add(b);
    }
    // "Cancel"
    {
      JButton b = new JButton("Cancel");
      b.addActionListener(
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              dlg.dispose();
            }
          });
      buttonPanel.add(b);
    }

    // Pack and Show
    dlg.pack();
    dlg.setLocationRelativeTo(console.frame);
    dlg.setVisible(true);
  }