Example usage for javax.swing JTextField getText

List of usage examples for javax.swing JTextField getText

Introduction

In this page you can find the example usage for javax.swing JTextField getText.

Prototype

public String getText() 

Source Link

Document

Returns the text contained in this TextComponent.

Usage

From source file:ca.sqlpower.architect.swingui.enterprise.SecurityPanel.java

private User createUserFromPrompter() {
    JTextField nameField = new JTextField(15);
    JTextField passField = new JPasswordField(15);
    JTextField confirmField = new JPasswordField(15);

    JPanel namePanel = new JPanel(new BorderLayout());
    namePanel.add(new JLabel("User Name"), BorderLayout.WEST);
    namePanel.add(nameField, BorderLayout.EAST);

    JPanel passPanel = new JPanel(new BorderLayout());
    passPanel.add(new JLabel("Password"), BorderLayout.WEST);
    passPanel.add(passField, BorderLayout.EAST);

    JPanel confirmPanel = new JPanel(new BorderLayout());
    confirmPanel.add(new JLabel("Confirm Password"), BorderLayout.WEST);
    confirmPanel.add(confirmField, BorderLayout.EAST);

    Object[] messages = new Object[] { "Specify the User's Name and Password.", namePanel, passPanel,
            confirmPanel };//from  w  w  w.  java  2s  . c  o m

    String[] options = { "OK", "Cancel", };
    int option = JOptionPane.showOptionDialog(getPanel(), messages, "Specify the User's Name and Password",
            JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);

    if (nameField.getText().equals("") || nameField.getText() == null || passField.getText().equals("")
            || passField.getText() == null) {
        return null;
    }

    if (!passField.getText().equals(confirmField.getText())) {
        JOptionPane.showMessageDialog(getPanel(), "The passwords you entered do not match.", "Error",
                JOptionPane.ERROR_MESSAGE);
        return null;
    }

    User user = null;
    if (option == 0) {
        String password;
        try {
            password = new String(Hex.encodeHex(digester.digest(passField.getText().getBytes("UTF-8"))));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Unable to encode password", e);
        }
        user = new User(nameField.getText(), password);
    }

    return user;
}

From source file:be.agiv.security.demo.Main.java

private void secConvIssueToken() {
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    JPanel contentPanel = new JPanel(gridBagLayout);

    JLabel urlLabel = new JLabel("URL:");
    gridBagConstraints.gridx = 0;//  ww w.jav  a  2 s  .c  om
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    gridBagConstraints.ipadx = 5;
    gridBagLayout.setConstraints(urlLabel, gridBagConstraints);
    contentPanel.add(urlLabel);

    JTextField urlTextField = new JTextField(ClaimsAwareServiceFactory.SERVICE_SC_LOCATION, 60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(urlTextField, gridBagConstraints);
    contentPanel.add(urlTextField);

    JLabel warningLabel = new JLabel(
            "This operation can fail if the web service does not support WS-SecurityConversation.");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(warningLabel, gridBagConstraints);
    contentPanel.add(warningLabel);

    int result = JOptionPane.showConfirmDialog(this, contentPanel, "Secure Conversation Issue Token",
            JOptionPane.OK_CANCEL_OPTION);
    if (result == JOptionPane.CANCEL_OPTION) {
        return;
    }

    String location = urlTextField.getText();

    SecureConversationClient secConvClient = new SecureConversationClient(location);
    try {
        this.secConvSecurityToken = secConvClient.getSecureConversationToken(this.rStsSecurityToken);
        this.secConvViewMenuItem.setEnabled(true);
        this.secConvCancelMenuItem.setEnabled(true);
        secConvViewToken();
    } catch (Exception e) {
        showException(e);
    }
}

From source file:projects.wdlf47tuc.ProcessAllSwathcal.java

/**
 * Main entry point.//  ww  w. ja  va2  s.  c  o  m
 * 
 * @param args
 * 
 * @throws IOException 
 * 
 */
public ProcessAllSwathcal() {

    // Path to AllSwathcal.dat file
    File allSwathcal = new File(
            "/home/nrowell/Astronomy/Data/47_Tuc/Kalirai_2012/UVIS/www.stsci.edu/~jkalirai/47Tuc/AllSwathcal.dat");

    // Read file contents into the List
    try (BufferedReader in = new BufferedReader(new FileReader(allSwathcal))) {
        String sourceStr;
        while ((sourceStr = in.readLine()) != null) {
            Source source = Source.parseSource(sourceStr);
            if (source != null) {
                allSources.add(source);
            }
        }
    } catch (IOException e) {
    }

    logger.info("Parsed " + allSources.size() + " Sources from AllSwathcal.dat");

    // Initialise chart
    cmdPanel = new ChartPanel(updateDataAndPlotCmd(allSources));
    cmdPanel.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseClicked(ChartMouseEvent e) {
            // Capture mouse click location, transform to graph coordinates and add
            // a point to the polygonal selection box.
            Point2D p = cmdPanel.translateScreenToJava2D(e.getTrigger().getPoint());
            Rectangle2D plotArea = cmdPanel.getScreenDataArea();
            XYPlot plot = (XYPlot) cmdPanel.getChart().getPlot();
            double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
            double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());
            points.add(new double[] { chartX, chartY });
            cmdPanel.setChart(plotCmd());
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent arg0) {
        }
    });

    // Create colour combo boxes
    final JComboBox<Filter> magComboBox = new JComboBox<Filter>(filters);
    final JComboBox<Filter> col1ComboBox = new JComboBox<Filter>(filters);
    final JComboBox<Filter> col2ComboBox = new JComboBox<Filter>(filters);

    // Set initial values
    magComboBox.setSelectedItem(magFilter);
    col1ComboBox.setSelectedItem(col1Filter);
    col2ComboBox.setSelectedItem(col2Filter);

    // Create an action listener for these
    ActionListener al = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            if (evt.getSource() == magComboBox) {
                magFilter = (Filter) magComboBox.getSelectedItem();
            }
            if (evt.getSource() == col1ComboBox) {
                col1Filter = (Filter) col1ComboBox.getSelectedItem();
            }
            if (evt.getSource() == col2ComboBox) {
                col2Filter = (Filter) col2ComboBox.getSelectedItem();
            }
            // Changed colour(s), so reset selection box coordinates
            points.clear();
            cmdPanel.setChart(updateDataAndPlotCmd(allSources));
        }
    };
    magComboBox.addActionListener(al);
    col1ComboBox.addActionListener(al);
    col2ComboBox.addActionListener(al);
    // Add a bit of padding to space things out
    magComboBox.setBorder(new EmptyBorder(5, 5, 5, 5));
    col1ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5));
    col2ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Set up statistic sliders
    final JSlider magErrMaxSlider = GuiUtil.buildSlider(magErrorRangeMin, magErrorRangeMax, 3, "%3.3f");
    final JSlider chi2MaxSlider = GuiUtil.buildSlider(chi2RangeMin, chi2RangeMax, 3, "%3.3f");
    final JSlider sharpMinSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f");
    final JSlider sharpMaxSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f");

    // Set intial values
    magErrMaxSlider.setValue(
            (int) Math.rint(100.0 * (magErrMax - magErrorRangeMin) / (magErrorRangeMax - magErrorRangeMin)));
    chi2MaxSlider.setValue((int) Math.rint(100.0 * (chi2Max - chi2RangeMin) / (chi2RangeMax - chi2RangeMin)));
    sharpMinSlider
            .setValue((int) Math.rint(100.0 * (sharpMin - sharpRangeMin) / (sharpRangeMax - sharpRangeMin)));
    sharpMaxSlider
            .setValue((int) Math.rint(100.0 * (sharpMax - sharpRangeMin) / (sharpRangeMax - sharpRangeMin)));

    // Set labels & initial values
    final JLabel magErrMaxLabel = new JLabel(getMagErrMaxLabel());
    final JLabel chi2MaxLabel = new JLabel(getChi2MaxLabel());
    final JLabel sharpMinLabel = new JLabel(getSharpMinLabel());
    final JLabel sharpMaxLabel = new JLabel(getSharpMaxLabel());

    // Create a change listener fot these
    ChangeListener cl = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();

            if (source == magErrMaxSlider) {
                // Compute max mag error from slider position
                double newMagErrMax = magErrorRangeMin
                        + (magErrorRangeMax - magErrorRangeMin) * (source.getValue() / 100.0);
                magErrMax = newMagErrMax;
                magErrMaxLabel.setText(getMagErrMaxLabel());
            }
            if (source == chi2MaxSlider) {
                // Compute Chi2 max from slider position
                double newChi2Max = chi2RangeMin + (chi2RangeMax - chi2RangeMin) * (source.getValue() / 100.0);
                chi2Max = newChi2Max;
                chi2MaxLabel.setText(getChi2MaxLabel());
            }
            if (source == sharpMinSlider) {
                // Compute sharp min from slider position
                double newSharpMin = sharpRangeMin
                        + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0);
                sharpMin = newSharpMin;
                sharpMinLabel.setText(getSharpMinLabel());
            }
            if (source == sharpMaxSlider) {
                // Compute sharp max from slider position
                double newSharpMax = sharpRangeMin
                        + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0);
                sharpMax = newSharpMax;
                sharpMaxLabel.setText(getSharpMaxLabel());
            }
            cmdPanel.setChart(updateDataAndPlotCmd(allSources));
        }
    };
    magErrMaxSlider.addChangeListener(cl);
    chi2MaxSlider.addChangeListener(cl);
    sharpMinSlider.addChangeListener(cl);
    sharpMaxSlider.addChangeListener(cl);
    // Add a bit of padding to space things out
    magErrMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5));
    chi2MaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5));
    sharpMinSlider.setBorder(new EmptyBorder(5, 5, 5, 5));
    sharpMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Text field to store distance modulus
    final JTextField distanceModulusField = new JTextField(Double.toString(mu));
    distanceModulusField.setBorder(new EmptyBorder(5, 5, 5, 5));

    Border compound = BorderFactory.createCompoundBorder(new LineBorder(this.getBackground(), 5),
            BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));

    final JButton lfButton = new JButton("Luminosity function for selection");
    lfButton.setBorder(compound);
    lfButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            // Read distance modulus field
            try {
                double mu_new = Double.parseDouble(distanceModulusField.getText());
                mu = mu_new;
            } catch (NullPointerException | NumberFormatException ex) {
                JOptionPane.showMessageDialog(lfButton,
                        "Error parsing the distance modulus: " + ex.getMessage(), "Distance Modulus Error",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }

            if (boxedSources.isEmpty()) {
                JOptionPane.showMessageDialog(lfButton, "No sources are currently selected!", "Selection Error",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                computeAndPlotLuminosityFunction(boxedSources);
            }
        }
    });
    final JButton clearSelectionButton = new JButton("Clear selection");
    clearSelectionButton.setBorder(compound);
    clearSelectionButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            points.clear();
            cmdPanel.setChart(plotCmd());
        }
    });

    JPanel controls = new JPanel(new GridLayout(9, 2));
    controls.setBorder(new EmptyBorder(10, 10, 10, 10));
    controls.add(new JLabel("Magnitude = "));
    controls.add(magComboBox);
    controls.add(new JLabel("Colour 1 = "));
    controls.add(col1ComboBox);
    controls.add(new JLabel("Colour 2 = "));
    controls.add(col2ComboBox);
    controls.add(magErrMaxLabel);
    controls.add(magErrMaxSlider);
    controls.add(chi2MaxLabel);
    controls.add(chi2MaxSlider);
    controls.add(sharpMinLabel);
    controls.add(sharpMinSlider);
    controls.add(sharpMaxLabel);
    controls.add(sharpMaxSlider);
    controls.add(new JLabel("Adopted distance modulus = "));
    controls.add(distanceModulusField);
    controls.add(lfButton);
    controls.add(clearSelectionButton);

    this.setLayout(new BorderLayout());
    this.add(cmdPanel, BorderLayout.CENTER);
    this.add(controls, BorderLayout.SOUTH);

    this.validate();
}

From source file:com.sec.ose.osi.ui.frm.main.identification.common.JComboLicenseName.java

public JComboLicenseName() {
    final JTextField editor;
    this.initLicenseComboBox();

    this.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (isEnabled()) {
                if (e.getActionCommand().equals("comboBoxChanged")
                        || e.getActionCommand().equals("comboBoxEdited")) {
                    if (getSelectedIndex() > 0) {
                        setSelectedIndex(getSelectedIndex());
                        IdentifyMediator.getInstance()
                                .setSelectedLicenseName(String.valueOf(getSelectedItem()));
                        log.debug("selected license name : "
                                + IdentifyMediator.getInstance().getSelectedLicenseName());
                    } else {
                        IdentifyMediator.getInstance().setSelectedLicenseName("");
                    }//from   w  ww  .j  ava2s.  c o m
                }
            }
        }
    });
    editor = (JTextField) this.getEditor().getEditorComponent();
    editor.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            char ch = e.getKeyChar();

            if (ch != KeyEvent.VK_ENTER && ch != KeyEvent.VK_BACK_SPACE
                    && (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)))
                return;
            if (ch == KeyEvent.VK_ENTER) {
                hidePopup();
                return;
            }

            String str = editor.getText();

            if (getComponentCount() > 0) {
                removeAllItems();
            }

            addItem(str);
            try {
                String tmpLicense = null;
                ArrayList<String> AllLicenseList = new ArrayList<String>();
                AllLicenseList = LicenseAPIWrapper.getAllLicenseList();
                if (str.length() > 0) {
                    for (int i = 0; i < AllLicenseList.size(); i++) {
                        tmpLicense = AllLicenseList.get(i);
                        if (tmpLicense.toLowerCase().startsWith(str.toLowerCase()))
                            addItem(tmpLicense);
                    }
                } else {
                    for (int i = 0; i < AllLicenseList.size(); i++) {
                        addItem(AllLicenseList.get(i));
                    }
                }
            } catch (Exception e1) {
                log.warn(e1.getMessage());
            }

            hidePopup();
            if (str.length() > 0)
                showPopup();
        }
    });

    editor.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            if (editor.getText().length() > 0)
                showPopup();
        }

        public void focusLost(FocusEvent e) {
            hidePopup();
        }
    });
}

From source file:com.qframework.core.GameonApp.java

private void onTextInput(final String resptype, final String respdata) {

    Timer t = new javax.swing.Timer(50, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JTextField area = new JTextField(resptype);
            area.setFocusable(true);/*from   ww w .ja v a2  s  .  c  o  m*/
            area.requestFocus();
            Object options[] = new Object[] { area };
            Frame parent = null;
            if (mAppContext != null)
                parent = (Frame) SwingUtilities.getAncestorOfClass(java.awt.Frame.class, mAppContext);
            else
                parent = (Frame) SwingUtilities.getAncestorOfClass(java.awt.Frame.class, mAppletContext);

            int option = JOptionPane.showOptionDialog(parent, options, "", JOptionPane.YES_OPTION,
                    JOptionPane.INFORMATION_MESSAGE, null, null, null);
            if (option == JOptionPane.YES_OPTION) {
                String truncated = area.getText().replaceAll("[^A-Za-z0-9:.@ ]", "");
                String script = respdata + "('" + truncated + "' , 1);";
                mScript.execScript(script);
            } else {
                String script = respdata + "(undefined, 1);";
                mScript.execScript(script);

            }
        }
    });
    t.setRepeats(false);
    t.start();

}

From source file:edu.virginia.iath.oxygenplugins.juel.JUELPluginMenu.java

public JUELPluginMenu(StandalonePluginWorkspace spw, LocalOptions ops) {
    super(name, true);
    ws = spw;/*from   ww w. ja  v a2 s. c  om*/
    options = ops;

    // setup the options
    //options.readStorage();

    // Find names
    JMenuItem search = new JMenuItem("Find Name");
    search.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent selection) {
            String label = "Find Name";

            final JTextField lastName = new JTextField("", 30);
            lastName.setPreferredSize(new Dimension(350, 25));
            //JTextField projectName = new JTextField("", 30);

            final JComboBox possibleVals = new JComboBox();
            possibleVals.setEnabled(false);
            possibleVals.setPreferredSize(new Dimension(350, 25));

            JButton search = new JButton("Search");
            search.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent selection) {
                    // query the database
                    try {
                        String json = "";
                        String line;
                        URL url = new URL("http://juel.iath.virginia.edu/academical_db/people/find_people?term="
                                + lastName.getText());
                        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                        while ((line = in.readLine()) != null) {
                            json += line;
                        }
                        JSONArray obj = new JSONArray(json);

                        // Read the JSON and update possibleVals
                        possibleVals.removeAllItems();
                        possibleVals.setEnabled(false);

                        for (int i = 0; i < obj.length(); i++) {
                            JSONObject cur = obj.getJSONObject(i);
                            String name = cur.getString("label");
                            String id = String.format("P%05d", cur.getInt("value"));
                            possibleVals.addItem(new ComboBoxObject(name, id));
                            possibleVals.setEnabled(true);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        possibleVals.setEnabled(false);
                    }

                    return;
                }
            });
            search.setPreferredSize(new Dimension(100, 25));

            JButton insert = new JButton("Insert");
            insert.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent sel) {
                    // Insert into the page
                    // Get the selected value, grab the ID, then insert into the document

                    // Get the editor
                    WSTextEditorPage ed = null;
                    WSEditor editorAccess = ws
                            .getCurrentEditorAccess(StandalonePluginWorkspace.MAIN_EDITING_AREA);
                    if (editorAccess != null && editorAccess.getCurrentPage() instanceof WSTextEditorPage) {
                        ed = (WSTextEditorPage) editorAccess.getCurrentPage();
                    }

                    String result = "key=\"" + ((ComboBoxObject) possibleVals.getSelectedItem()).id + "\"";

                    // Update the text in the document
                    ed.beginCompoundUndoableEdit();
                    int selectionOffset = ed.getSelectionStart();
                    ed.deleteSelection();
                    javax.swing.text.Document doc = ed.getDocument();
                    try {
                        if (selectionOffset > 0 && !doc.getText(selectionOffset - 1, 1).equals(" "))
                            result = " " + result;
                        if (selectionOffset > 0 && !doc.getText(selectionOffset, 1).equals(" ")
                                && !doc.getText(selectionOffset, 1).equals(">"))
                            result = result + " ";
                        doc.insertString(selectionOffset, result, javax.swing.text.SimpleAttributeSet.EMPTY);
                    } catch (javax.swing.text.BadLocationException b) {
                        // Okay if it doesn't work
                    }
                    ed.endCompoundUndoableEdit();

                    return;
                }
            });
            insert.setPreferredSize(new Dimension(100, 25));

            java.awt.GridLayout layoutOuter = new java.awt.GridLayout(3, 1);
            java.awt.FlowLayout layout = new java.awt.FlowLayout(FlowLayout.RIGHT); // rows, columns

            JPanel addPanel = new JPanel();
            JPanel addPanelInner = new JPanel();
            addPanel.setLayout(layoutOuter);
            addPanel.add(new JLabel("Search for last name, then choose a full name from the list below"));
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Search Last Name: "));
            addPanelInner.add(lastName);
            addPanelInner.add(search);
            addPanel.add(addPanelInner);
            addPanelInner = new JPanel();
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Narrow Search: "));
            addPanelInner.add(possibleVals);
            addPanelInner.add(insert);
            addPanel.add(addPanelInner);

            JOptionPane.showMessageDialog((java.awt.Frame) ws.getParentFrame(), addPanel, label,
                    JOptionPane.PLAIN_MESSAGE);

        }
    });
    this.add(search);

    // Find places
    search = new JMenuItem("Find Place");
    search.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent selection) {
            String label = "Find Place";

            final JTextField searchText = new JTextField("", 30);
            searchText.setPreferredSize(new Dimension(350, 25));
            //JTextField projectName = new JTextField("", 30);

            final JComboBox possibleVals = new JComboBox();
            possibleVals.setEnabled(false);
            possibleVals.setPreferredSize(new Dimension(350, 25));

            JButton search = new JButton("Search");
            search.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent selection) {
                    // query the database
                    try {
                        String json = "";
                        String line;
                        URL url = new URL(
                                "http://academical.village.virginia.edu/academical_db/places/find_places?term="
                                        + searchText.getText());
                        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                        while ((line = in.readLine()) != null) {
                            json += line;
                        }
                        JSONArray obj = new JSONArray(json);

                        // Read the JSON and update possibleVals
                        possibleVals.removeAllItems();
                        possibleVals.setEnabled(false);

                        for (int i = 0; i < obj.length(); i++) {
                            JSONObject cur = obj.getJSONObject(i);
                            String id = String.format("PL%04d", cur.getInt("value"));
                            String name = cur.getString("label") + " (" + id + ")";
                            possibleVals.addItem(new ComboBoxObject(name, id));
                            possibleVals.setEnabled(true);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        possibleVals.setEnabled(false);
                    }

                    return;
                }
            });
            search.setPreferredSize(new Dimension(100, 25));

            JButton insert = new JButton("Insert");
            insert.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent sel) {
                    // Insert into the page
                    // Get the selected value, grab the ID, then insert into the document

                    // Get the editor
                    WSTextEditorPage ed = null;
                    WSEditor editorAccess = ws
                            .getCurrentEditorAccess(StandalonePluginWorkspace.MAIN_EDITING_AREA);
                    if (editorAccess != null && editorAccess.getCurrentPage() instanceof WSTextEditorPage) {
                        ed = (WSTextEditorPage) editorAccess.getCurrentPage();
                    }

                    String result = "key=\"" + ((ComboBoxObject) possibleVals.getSelectedItem()).id + "\"";

                    // Update the text in the document
                    ed.beginCompoundUndoableEdit();
                    int selectionOffset = ed.getSelectionStart();
                    ed.deleteSelection();
                    javax.swing.text.Document doc = ed.getDocument();
                    try {
                        if (selectionOffset > 0 && !doc.getText(selectionOffset - 1, 1).equals(" "))
                            result = " " + result;
                        if (selectionOffset > 0 && !doc.getText(selectionOffset, 1).equals(" ")
                                && !doc.getText(selectionOffset, 1).equals(">"))
                            result = result + " ";
                        doc.insertString(selectionOffset, result, javax.swing.text.SimpleAttributeSet.EMPTY);
                    } catch (javax.swing.text.BadLocationException b) {
                        // Okay if it doesn't work
                    }
                    ed.endCompoundUndoableEdit();

                    return;
                }
            });
            insert.setPreferredSize(new Dimension(100, 25));

            java.awt.GridLayout layoutOuter = new java.awt.GridLayout(3, 1);
            java.awt.FlowLayout layout = new java.awt.FlowLayout(FlowLayout.RIGHT); // rows, columns

            JPanel addPanel = new JPanel();
            JPanel addPanelInner = new JPanel();
            addPanel.setLayout(layoutOuter);
            addPanel.add(new JLabel("Search for a place name, then choose one from the list below"));
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Search Keyword: "));
            addPanelInner.add(searchText);
            addPanelInner.add(search);
            addPanel.add(addPanelInner);
            addPanelInner = new JPanel();
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Narrow Search: "));
            addPanelInner.add(possibleVals);
            addPanelInner.add(insert);
            addPanel.add(addPanelInner);

            JOptionPane.showMessageDialog((java.awt.Frame) ws.getParentFrame(), addPanel, label,
                    JOptionPane.PLAIN_MESSAGE);

        }
    });
    this.add(search);

    // Find corporate bodies
    search = new JMenuItem("Find Corporate Body");
    search.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent selection) {
            String label = "Find Corporate Body";

            final JTextField searchText = new JTextField("", 30);
            searchText.setPreferredSize(new Dimension(350, 25));
            //JTextField projectName = new JTextField("", 30);

            final JComboBox possibleVals = new JComboBox();
            possibleVals.setEnabled(false);
            possibleVals.setPreferredSize(new Dimension(350, 25));

            JButton search = new JButton("Search");
            search.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent selection) {
                    // query the database
                    try {
                        String json = "";
                        String line;
                        URL url = new URL(
                                "http://academical.village.virginia.edu/academical_db/corporate_bodies/find?term="
                                        + searchText.getText());
                        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                        while ((line = in.readLine()) != null) {
                            json += line;
                        }
                        JSONArray obj = new JSONArray(json);

                        // Read the JSON and update possibleVals
                        possibleVals.removeAllItems();
                        possibleVals.setEnabled(false);

                        for (int i = 0; i < obj.length(); i++) {
                            JSONObject cur = obj.getJSONObject(i);
                            String id = String.format("CB%04d", cur.getInt("value"));
                            String name = cur.getString("label") + " (" + id + ")";
                            possibleVals.addItem(new ComboBoxObject(name, id));
                            possibleVals.setEnabled(true);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        possibleVals.setEnabled(false);
                    }

                    return;
                }
            });
            search.setPreferredSize(new Dimension(100, 25));

            JButton insert = new JButton("Insert");
            insert.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent sel) {
                    // Insert into the page
                    // Get the selected value, grab the ID, then insert into the document

                    // Get the editor
                    WSTextEditorPage ed = null;
                    WSEditor editorAccess = ws
                            .getCurrentEditorAccess(StandalonePluginWorkspace.MAIN_EDITING_AREA);
                    if (editorAccess != null && editorAccess.getCurrentPage() instanceof WSTextEditorPage) {
                        ed = (WSTextEditorPage) editorAccess.getCurrentPage();
                    }

                    String result = "key=\"" + ((ComboBoxObject) possibleVals.getSelectedItem()).id + "\"";

                    // Update the text in the document
                    ed.beginCompoundUndoableEdit();
                    int selectionOffset = ed.getSelectionStart();
                    ed.deleteSelection();
                    javax.swing.text.Document doc = ed.getDocument();
                    try {
                        if (selectionOffset > 0 && !doc.getText(selectionOffset - 1, 1).equals(" "))
                            result = " " + result;
                        if (selectionOffset > 0 && !doc.getText(selectionOffset, 1).equals(" ")
                                && !doc.getText(selectionOffset, 1).equals(">"))
                            result = result + " ";
                        doc.insertString(selectionOffset, result, javax.swing.text.SimpleAttributeSet.EMPTY);
                    } catch (javax.swing.text.BadLocationException b) {
                        // Okay if it doesn't work
                    }
                    ed.endCompoundUndoableEdit();

                    return;
                }
            });
            insert.setPreferredSize(new Dimension(100, 25));

            java.awt.GridLayout layoutOuter = new java.awt.GridLayout(3, 1);
            java.awt.FlowLayout layout = new java.awt.FlowLayout(FlowLayout.RIGHT); // rows, columns

            JPanel addPanel = new JPanel();
            JPanel addPanelInner = new JPanel();
            addPanel.setLayout(layoutOuter);
            addPanel.add(new JLabel("Search for a corporate body, then one from the list below"));
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Search Keyword: "));
            addPanelInner.add(searchText);
            addPanelInner.add(search);
            addPanel.add(addPanelInner);
            addPanelInner = new JPanel();
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Narrow Search: "));
            addPanelInner.add(possibleVals);
            addPanelInner.add(insert);
            addPanel.add(addPanelInner);

            JOptionPane.showMessageDialog((java.awt.Frame) ws.getParentFrame(), addPanel, label,
                    JOptionPane.PLAIN_MESSAGE);

        }
    });
    this.add(search);

    // Find Courses
    search = new JMenuItem("Find Course");
    search.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent selection) {
            String label = "Find Course";

            final JTextField searchText = new JTextField("", 30);
            searchText.setPreferredSize(new Dimension(350, 25));
            //JTextField projectName = new JTextField("", 30);

            final JComboBox possibleVals = new JComboBox();
            possibleVals.setEnabled(false);
            possibleVals.setPreferredSize(new Dimension(350, 25));

            JButton search = new JButton("Search");
            search.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent selection) {
                    // query the database
                    try {
                        String json = "";
                        String line;
                        URL url = new URL(
                                "http://academical.village.virginia.edu/academical_db/courses/find?term="
                                        + searchText.getText());
                        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                        while ((line = in.readLine()) != null) {
                            json += line;
                        }
                        JSONArray obj = new JSONArray(json);

                        // Read the JSON and update possibleVals
                        possibleVals.removeAllItems();
                        possibleVals.setEnabled(false);

                        for (int i = 0; i < obj.length(); i++) {
                            JSONObject cur = obj.getJSONObject(i);
                            String id = String.format("C%04d", cur.getInt("value"));
                            String name = cur.getString("label") + " (" + id + ")";
                            possibleVals.addItem(new ComboBoxObject(name, id));
                            possibleVals.setEnabled(true);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        possibleVals.setEnabled(false);
                    }

                    return;
                }
            });
            search.setPreferredSize(new Dimension(100, 25));

            JButton insert = new JButton("Insert");
            insert.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent sel) {
                    // Insert into the page
                    // Get the selected value, grab the ID, then insert into the document

                    // Get the editor
                    WSTextEditorPage ed = null;
                    WSEditor editorAccess = ws
                            .getCurrentEditorAccess(StandalonePluginWorkspace.MAIN_EDITING_AREA);
                    if (editorAccess != null && editorAccess.getCurrentPage() instanceof WSTextEditorPage) {
                        ed = (WSTextEditorPage) editorAccess.getCurrentPage();
                    }

                    String result = "key=\"" + ((ComboBoxObject) possibleVals.getSelectedItem()).id + "\"";

                    // Update the text in the document
                    ed.beginCompoundUndoableEdit();
                    int selectionOffset = ed.getSelectionStart();
                    ed.deleteSelection();
                    javax.swing.text.Document doc = ed.getDocument();
                    try {
                        if (selectionOffset > 0 && !doc.getText(selectionOffset - 1, 1).equals(" "))
                            result = " " + result;
                        if (selectionOffset > 0 && !doc.getText(selectionOffset, 1).equals(" ")
                                && !doc.getText(selectionOffset, 1).equals(">"))
                            result = result + " ";
                        doc.insertString(selectionOffset, result, javax.swing.text.SimpleAttributeSet.EMPTY);
                    } catch (javax.swing.text.BadLocationException b) {
                        // Okay if it doesn't work
                    }
                    ed.endCompoundUndoableEdit();

                    return;
                }
            });
            insert.setPreferredSize(new Dimension(100, 25));

            java.awt.GridLayout layoutOuter = new java.awt.GridLayout(3, 1);
            java.awt.FlowLayout layout = new java.awt.FlowLayout(FlowLayout.RIGHT); // rows, columns

            JPanel addPanel = new JPanel();
            JPanel addPanelInner = new JPanel();
            addPanel.setLayout(layoutOuter);
            addPanel.add(new JLabel("Search for a course, then choose one from the list below"));
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Search Keyword: "));
            addPanelInner.add(searchText);
            addPanelInner.add(search);
            addPanel.add(addPanelInner);
            addPanelInner = new JPanel();
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Narrow Search: "));
            addPanelInner.add(possibleVals);
            addPanelInner.add(insert);
            addPanel.add(addPanelInner);

            JOptionPane.showMessageDialog((java.awt.Frame) ws.getParentFrame(), addPanel, label,
                    JOptionPane.PLAIN_MESSAGE);

        }
    });
    this.add(search);
}

From source file:edu.ku.brc.specify.plugins.ipadexporter.iPadDBExporterPlugin.java

/**
 * //from  w  w w  .j av  a2  s. c om
 */
private void createAccount() {
    Institution inst = iPadDBExporter.getCurrentInstitution();
    if (StringUtils.isEmpty(inst.getGuid())) {
        UIRegistry.showError("Institution must have a GUID value.");
        return;
    }
    loadAndPushResourceBundle(RESOURCE_NAME);

    final JTextField userNameTF = createTextField(15);
    final JPasswordField passwordTF = createPasswordField();
    final JLabel statusLbl = createLabel(" ");
    ImageIcon imgIcon = IconManager.getImage("SpecifySmalliPad128x128", IconManager.STD_ICON_SIZE.NonStd);
    JPanel loginPanel = DatabaseLoginPanel.createLoginPanel("Username", userNameTF, "USRNM_EMAIL_HINT",
            "Password", passwordTF, statusLbl, imgIcon);

    final CustomDialog dlg = new CustomDialog((Frame) getMostRecentWindow(),
            getResourceString("CREATE_INST_IN_CLOUD"), true, CustomDialog.OKCANCEL, loginPanel) {
        @Override
        protected void okButtonPressed() {
            // NOTE: THis call should fail indicating is is not being used
            // so it if is OK then it is an error
            String uName = userNameTF.getText();
            if (iPadCloud.isUserNameOK(uName)) {
                setErrorMsg(statusLbl, getFormattedResStr("USRNM_IS_TAKEN", uName));
            } else {
                super.okButtonPressed();
            }
        }
    };
    KeyAdapter ka = new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            String pwd = new String(passwordTF.getPassword());
            boolean isOK = UIHelper.isValidEmailAddress(userNameTF.getText()) && pwd.length() > 4;
            dlg.getOkBtn().setEnabled(isOK);
        }
    };
    userNameTF.addKeyListener(ka);
    passwordTF.addKeyListener(ka);
    dlg.setOkLabel(getResourceString("NEW_ACCOUNT"));
    dlg.createUI();
    dlg.getOkBtn().setEnabled(false);
    centerAndShow(dlg);
    popResourceBundle();

    if (!dlg.isCancelled()) {
        cloudInstId = iPadCloud.createInstitution(inst.getName(), inst.getUri(), inst.getCode(),
                inst.getGuid());
        if (cloudInstId != null) {
            createAccountBtn.setEnabled(false);
            loginBtn.setEnabled(true);

            enableRemoveDatasetBtn();

            checkInstitutionInfo(false);

            String uName = userNameTF.getText();
            String pwd = new String(passwordTF.getPassword());
            if (iPadCloud.addNewUser(uName, pwd, inst.getGuid())) {
                if (iPadCloud.login(uName, pwd)) {
                    login(new Pair<String, String>(uName, pwd));
                }
            } else {
                setErrorMsg(statusLbl, kErrorCreatingAcctMsg);
            }

        } else {
            UIRegistry.showError(kErrorCreatingAcctMsg);
        }
    }
}

From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java

private JDialog createAddChildDialog() {
    final JDialog dlg = new JDialog();
    dlg.setModal(true);//from   w w w.j av  a  2s.co m

    // Content
    final JPanel content = new JPanel();
    content.setLayout(new BorderLayout());
    content.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    // child name
    AlignmentGridPanel pathPanel = new AlignmentGridPanel();

    final JTextField childNameText = new JTextField();
    final RSyntaxTextArea childDataArea = new RSyntaxTextArea();

    final JMenuBar bar = new JMenuBar();
    final JMenu menu = new JMenu("Syntax Highlight");
    bar.add(menu);

    setMenuItem(menu, childDataArea, SyntaxConstants.SYNTAX_STYLE_XML);
    setMenuItem(menu, childDataArea, SyntaxConstants.SYNTAX_STYLE_JAVA);
    setMenuItem(menu, childDataArea, SyntaxConstants.SYNTAX_STYLE_PROPERTIES_FILE);

    pathPanel.addLine(new Component[] { new JLabel("Select:"), bar });
    pathPanel.addLine(new Component[] { new JLabel("Name: "), childNameText });
    pathPanel.addLine(new Component[] { new JLabel("Data: ") });

    content.add(pathPanel, BorderLayout.NORTH);
    content.add(new RTextScrollPane(childDataArea), BorderLayout.CENTER);

    childDataArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PROPERTIES_FILE);
    // Buttons.
    final CButtonPane btnPanel = new CButtonPane(CButtonPane.TAIL);
    final JButton btnOk = new JButton("Ok");
    btnOk.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String name = childNameText.getText();
            String data = childDataArea.getText();

            if ((name == null || name.isEmpty()) || (data == null || data.isEmpty())) {
                JOptionPane.showMessageDialog(null, "Name or Data is empty", "Error",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }
            childName = name;
            childText = data;
            dlg.setVisible(false);
            dlg.dispose();
        }
    });

    final JButton btnCancel = new JButton("Cancel");
    btnCancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            childName = "";
            childText = "";
            dlg.setVisible(false);
            dlg.dispose();
        }
    });
    btnPanel.add(btnCancel);
    btnPanel.add(btnOk);
    btnPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    Container con = dlg.getContentPane();
    con.setLayout(new BorderLayout());

    con.add(content, BorderLayout.CENTER);
    con.add(btnPanel, BorderLayout.SOUTH);

    return dlg;
}

From source file:com.entertailion.java.fling.FlingFrame.java

public FlingFrame(String appId) {
    super();/*from ww  w. j  ava2 s .  co m*/
    this.appId = appId;
    rampClient = new RampClient(this);

    addWindowListener(this);

    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    Locale locale = Locale.getDefault();
    resourceBundle = ResourceBundle.getBundle("com/entertailion/java/fling/resources/resources", locale);
    setTitle(MessageFormat.format(resourceBundle.getString("fling.title"), Fling.VERSION));

    JPanel listPane = new JPanel();
    // show list of ChromeCast devices detected on the local network
    listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
    JPanel devicePane = new JPanel();
    devicePane.setLayout(new BoxLayout(devicePane, BoxLayout.LINE_AXIS));
    deviceList = new JComboBox();
    deviceList.addActionListener(this);
    devicePane.add(deviceList);
    URL url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/refresh.png");
    ImageIcon icon = new ImageIcon(url, resourceBundle.getString("button.refresh"));
    refreshButton = new JButton(icon);
    refreshButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // refresh the list of devices
            if (deviceList.getItemCount() > 0) {
                deviceList.setSelectedIndex(0);
            }
            discoverDevices();
        }
    });
    refreshButton.setToolTipText(resourceBundle.getString("button.refresh"));
    devicePane.add(refreshButton);
    url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/settings.png");
    icon = new ImageIcon(url, resourceBundle.getString("settings.title"));
    settingsButton = new JButton(icon);
    settingsButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JTextField transcodingExtensions = new JTextField(50);
            transcodingExtensions.setText(transcodingExtensionValues);
            JTextField transcodingParameters = new JTextField(50);
            transcodingParameters.setText(transcodingParameterValues);

            JPanel myPanel = new JPanel(new BorderLayout());
            JPanel labelPanel = new JPanel(new GridLayout(3, 1));
            JPanel fieldPanel = new JPanel(new GridLayout(3, 1));
            myPanel.add(labelPanel, BorderLayout.WEST);
            myPanel.add(fieldPanel, BorderLayout.CENTER);
            labelPanel.add(new JLabel(resourceBundle.getString("transcoding.extensions"), JLabel.RIGHT));
            fieldPanel.add(transcodingExtensions);
            labelPanel.add(new JLabel(resourceBundle.getString("transcoding.parameters"), JLabel.RIGHT));
            fieldPanel.add(transcodingParameters);
            labelPanel.add(new JLabel(resourceBundle.getString("device.manual"), JLabel.RIGHT));
            JPanel devicePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
            final JComboBox manualDeviceList = new JComboBox();
            if (manualServers.size() == 0) {
                manualDeviceList.setVisible(false);
            } else {
                for (DialServer dialServer : manualServers) {
                    manualDeviceList.addItem(dialServer);
                }
            }
            devicePanel.add(manualDeviceList);
            JButton addButton = new JButton(resourceBundle.getString("device.manual.add"));
            addButton.setToolTipText(resourceBundle.getString("device.manual.add.tooltip"));
            addButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    JTextField name = new JTextField();
                    JTextField ipAddress = new JTextField();
                    Object[] message = { resourceBundle.getString("device.manual.name") + ":", name,
                            resourceBundle.getString("device.manual.ipaddress") + ":", ipAddress };

                    int option = JOptionPane.showConfirmDialog(null, message,
                            resourceBundle.getString("device.manual"), JOptionPane.OK_CANCEL_OPTION);
                    if (option == JOptionPane.OK_OPTION) {
                        try {
                            manualServers.add(
                                    new DialServer(name.getText(), InetAddress.getByName(ipAddress.getText())));

                            Object selected = deviceList.getSelectedItem();
                            int selectedIndex = deviceList.getSelectedIndex();
                            deviceList.removeAllItems();
                            deviceList.addItem(resourceBundle.getString("devices.select"));
                            for (DialServer dialServer : servers) {
                                deviceList.addItem(dialServer);
                            }
                            for (DialServer dialServer : manualServers) {
                                deviceList.addItem(dialServer);
                            }
                            deviceList.invalidate();
                            if (selectedIndex > 0) {
                                deviceList.setSelectedItem(selected);
                            } else {
                                if (deviceList.getItemCount() == 2) {
                                    // Automatically select single device
                                    deviceList.setSelectedIndex(1);
                                }
                            }

                            manualDeviceList.removeAllItems();
                            for (DialServer dialServer : manualServers) {
                                manualDeviceList.addItem(dialServer);
                            }
                            manualDeviceList.setVisible(true);
                            storeProperties();
                        } catch (UnknownHostException e1) {
                            Log.e(LOG_TAG, "manual IP address", e1);

                            JOptionPane.showMessageDialog(FlingFrame.this,
                                    resourceBundle.getString("device.manual.invalidip"));
                        }
                    }
                }
            });
            devicePanel.add(addButton);
            JButton removeButton = new JButton(resourceBundle.getString("device.manual.remove"));
            removeButton.setToolTipText(resourceBundle.getString("device.manual.remove.tooltip"));
            removeButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    Object selected = manualDeviceList.getSelectedItem();
                    manualDeviceList.removeItem(selected);
                    if (manualDeviceList.getItemCount() == 0) {
                        manualDeviceList.setVisible(false);
                    }
                    deviceList.removeItem(selected);
                    deviceList.invalidate();
                    manualServers.remove(selected);
                    storeProperties();
                }
            });
            devicePanel.add(removeButton);
            fieldPanel.add(devicePanel);
            int result = JOptionPane.showConfirmDialog(FlingFrame.this, myPanel,
                    resourceBundle.getString("settings.title"), JOptionPane.OK_CANCEL_OPTION);
            if (result == JOptionPane.OK_OPTION) {
                transcodingParameterValues = transcodingParameters.getText();
                transcodingExtensionValues = transcodingExtensions.getText();
                storeProperties();
            }
        }
    });
    settingsButton.setToolTipText(resourceBundle.getString("settings.title"));
    devicePane.add(settingsButton);
    listPane.add(devicePane);

    // TODO
    volume = new JSlider(JSlider.VERTICAL, 0, 100, 0);
    volume.setUI(new MySliderUI(volume));
    volume.setMajorTickSpacing(25);
    // volume.setMinorTickSpacing(5);
    volume.setPaintTicks(true);
    volume.setEnabled(true);
    volume.setValue(100);
    volume.setToolTipText(resourceBundle.getString("volume.title"));
    volume.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            if (!source.getValueIsAdjusting()) {
                int position = (int) source.getValue();
                rampClient.volume(position / 100.0f);
            }
        }

    });
    JPanel centerPanel = new JPanel(new BorderLayout());
    // centerPanel.add(volume, BorderLayout.WEST);

    centerPanel.add(DragHereIcon.makeUI(this), BorderLayout.CENTER);
    listPane.add(centerPanel);

    scrubber = new JSlider(JSlider.HORIZONTAL, 0, 100, 0);
    scrubber.addChangeListener(this);
    scrubber.setMajorTickSpacing(25);
    scrubber.setMinorTickSpacing(5);
    scrubber.setPaintTicks(true);
    scrubber.setEnabled(false);
    listPane.add(scrubber);

    // panel of playback buttons
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    label = new JLabel("00:00:00");
    buttonPane.add(label);
    url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/play.png");
    icon = new ImageIcon(url, resourceBundle.getString("button.play"));
    playButton = new JButton(icon);
    playButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            rampClient.play();
        }
    });
    buttonPane.add(playButton);
    url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/pause.png");
    icon = new ImageIcon(url, resourceBundle.getString("button.pause"));
    pauseButton = new JButton(icon);
    pauseButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            rampClient.pause();
        }
    });
    buttonPane.add(pauseButton);
    url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/stop.png");
    icon = new ImageIcon(url, resourceBundle.getString("button.stop"));
    stopButton = new JButton(icon);
    stopButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            rampClient.stop();
            setDuration(0);
            scrubber.setValue(0);
            scrubber.setEnabled(false);
        }
    });
    buttonPane.add(stopButton);
    listPane.add(buttonPane);
    getContentPane().add(listPane);

    createProgressDialog();
    startWebserver();
    discoverDevices();
}

From source file:be.agiv.security.demo.Main.java

private void rStsIssueToken() {
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    JPanel contentPanel = new JPanel(gridBagLayout);

    JLabel urlLabel = new JLabel("URL:");
    gridBagConstraints.gridx = 0;//  ww w  . j  ava  2  s .c o  m
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    gridBagConstraints.ipadx = 5;
    gridBagLayout.setConstraints(urlLabel, gridBagConstraints);
    contentPanel.add(urlLabel);

    JTextField urlTextField = new JTextField(
            "https://auth.beta.agiv.be/sts/Services/SalvadorSecurityTokenServiceConfiguration.svc/IWSTrust13",
            60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(urlTextField, gridBagConstraints);
    contentPanel.add(urlTextField);

    JLabel appliesToLabel = new JLabel("Applies to:");
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    gridBagLayout.setConstraints(appliesToLabel, gridBagConstraints);
    contentPanel.add(appliesToLabel);

    JTextField appliesToTextField = new JTextField(ClaimsAwareServiceFactory.SERVICE_REALM, 60);
    gridBagConstraints.gridx++;
    gridBagLayout.setConstraints(appliesToTextField, gridBagConstraints);
    contentPanel.add(appliesToTextField);

    int result = JOptionPane.showConfirmDialog(this, contentPanel, "R-STS Issue Token",
            JOptionPane.OK_CANCEL_OPTION);
    if (result == JOptionPane.CANCEL_OPTION) {
        return;
    }

    String location = urlTextField.getText();
    String appliesTo = appliesToTextField.getText();

    RSTSClient rStsClient = new RSTSClient(location);
    try {
        this.rStsSecurityToken = rStsClient.getSecurityToken(this.ipStsSecurityToken, appliesTo);
        this.rStsViewMenuItem.setEnabled(true);
        this.secConvIssueMenuItem.setEnabled(true);
        rStsViewToken();
    } catch (Exception e) {
        showException(e);
    }
}