Search in sources :

Example 51 with JDialog

use of javax.swing.JDialog in project JMRI by JMRI.

the class EcosTurnoutManager method checkTurnoutList.

/* This is used after an event update form the ecos informing us of a change in the 
     * turnout list, we have to determine if it is an addition or delete.
     * We should only ever do either a remove or an add in one go.
     */
void checkTurnoutList(String[] ecoslines) {
    final EcosPreferences p = adaptermemo.getPreferenceManager();
    String[] jmrilist = getEcosObjectArray();
    boolean nomatch = true;
    int intTurnout = 0;
    String strECOSTurnout = null;
    for (int i = 0; i < jmrilist.length; i++) {
        nomatch = true;
        String strJMRITurnout = jmrilist[i];
        intTurnout = Integer.parseInt(strJMRITurnout);
        for (String li : ecoslines) {
            strECOSTurnout = li.replaceAll("[\\n\\r]", "");
            if (strECOSTurnout.equals(strJMRITurnout)) {
                nomatch = false;
                break;
            }
        }
        if (nomatch) {
            final EcosTurnout et = (EcosTurnout) getByEcosObject(intTurnout);
            _tecos.remove(intTurnout);
            if (p.getRemoveTurnoutsFromJMRI() == 0x02) {
                //Remove turnout
                _tecos.remove(et.getObject());
                deregister(et);
            } else if (p.getRemoveTurnoutsFromJMRI() == 0x00) {
                final JDialog dialog = new JDialog();
                dialog.setTitle("Delete Turnout");
                dialog.setLocationRelativeTo(null);
                dialog.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
                JPanel container = new JPanel();
                container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
                container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
                JLabel question = new JLabel("A Turnout " + et.getDisplayName() + " has been deleted on the ECOS");
                question.setAlignmentX(Component.CENTER_ALIGNMENT);
                container.add(question);
                question = new JLabel("Do you want to remove this turnout from JMRI");
                question.setAlignmentX(Component.CENTER_ALIGNMENT);
                container.add(question);
                final JCheckBox remember = new JCheckBox("Remember this setting for next time?");
                remember.setFont(remember.getFont().deriveFont(10f));
                remember.setAlignmentX(Component.CENTER_ALIGNMENT);
                JButton yesButton = new JButton("Yes");
                JButton noButton = new JButton("No");
                JPanel button = new JPanel();
                button.setAlignmentX(Component.CENTER_ALIGNMENT);
                button.add(yesButton);
                button.add(noButton);
                container.add(button);
                noButton.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        if (remember.isSelected()) {
                            p.setRemoveTurnoutsFromJMRI(0x01);
                        }
                        dialog.dispose();
                    }
                });
                yesButton.addActionListener(new ActionListener() {

                    final ResourceBundle rb = ResourceBundle.getBundle("jmri.jmrit.beantable.BeanTableBundle");

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        if (remember.isSelected()) {
                            p.setRemoveTurnoutsFromJMRI(0x02);
                        }
                        // one is this table
                        int count = et.getNumPropertyChangeListeners() - 1;
                        if (log.isDebugEnabled()) {
                            log.debug("Delete with " + count);
                        }
                        if ((!noWarnDelete) && (count > 0)) {
                            String msg = java.text.MessageFormat.format(rb.getString("DeletePrompt") + "\n" + rb.getString("ReminderInUse"), new Object[] { et.getSystemName(), "" + count });
                            // verify deletion
                            int val = javax.swing.JOptionPane.showOptionDialog(null, msg, rb.getString("WarningTitle"), javax.swing.JOptionPane.YES_NO_CANCEL_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE, null, new Object[] { rb.getString("ButtonYes"), rb.getString("ButtonYesPlus"), rb.getString("ButtonNo") }, rb.getString("ButtonNo"));
                            if (val == 2) {
                                _tecos.remove(et.getObject());
                                deregister(et);
                                dialog.dispose();
                                // return without deleting
                                return;
                            }
                            if (val == 1) {
                                // suppress future warnings
                                noWarnDelete = true;
                            }
                        }
                        // finally OK, do the actual delete
                        deleteEcosTurnout(et);
                        dialog.dispose();
                    }
                });
                container.add(remember);
                container.setAlignmentX(Component.CENTER_ALIGNMENT);
                container.setAlignmentY(Component.CENTER_ALIGNMENT);
                dialog.getContentPane().add(container);
                dialog.pack();
                dialog.setModal(true);
                dialog.setVisible(true);
            } else {
                //We will need to remove the turnout from our list as it no longer exists on the ecos.
                _tecos.remove(et.getObject());
            }
        }
    }
    int turnout;
    for (String li : ecoslines) {
        String tmpturn = li.replaceAll("[\\n\\r]", "");
        turnout = Integer.parseInt(tmpturn);
        if (getByEcosObject(turnout) == null) {
            EcosMessage mout = new EcosMessage("get(" + turnout + ", addrext)");
            tc.sendEcosMessage(mout, this);
        }
    }
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) ResourceBundle(java.util.ResourceBundle) JDialog(javax.swing.JDialog)

Example 52 with JDialog

use of javax.swing.JDialog in project JMRI by JMRI.

the class EcosTurnoutManager method propertyChange.

@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
    if ((e.getPropertyName().equals("length")) && (!addingTurnouts)) {
        final EcosPreferences p = adaptermemo.getPreferenceManager();
        EcosTurnout et;
        String[] ecoslist = this.getEcosObjectArray();
        String[] jmrilist = getSystemNameArray();
        for (int i = 0; i < jmrilist.length; i++) {
            if (jmrilist[i].startsWith(prefix + "T")) {
                et = (EcosTurnout) getBySystemName(jmrilist[i]);
                if (et.getObject() == 0) {
                //We do not support this yet at there are many parameters
                // when creating a turnout on the ecos.
                }
            }
        }
        for (int i = 0; i < ecoslist.length; i++) {
            et = (EcosTurnout) getByEcosObject(Integer.parseInt(ecoslist[i]));
            int address = et.getNumber();
            if (getBySystemName(prefix + "T" + address) == null) {
                if (p.getRemoveTurnoutsFromEcos() == 0x02) {
                    RemoveObjectFromEcos removeObjectFromEcos = new RemoveObjectFromEcos();
                    removeObjectFromEcos.removeObjectFromEcos("" + et.getObject(), tc);
                    deleteEcosTurnout(et);
                } else {
                    final EcosTurnout etd = et;
                    final JDialog dialog = new JDialog();
                    dialog.setTitle("Remove Turnout From ECoS?");
                    dialog.setLocation(300, 200);
                    dialog.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
                    JPanel container = new JPanel();
                    container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
                    container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
                    JLabel question = new JLabel("Do you also want to remove turnout " + etd.getSystemName() + " from the Ecos");
                    question.setAlignmentX(Component.CENTER_ALIGNMENT);
                    container.add(question);
                    final JCheckBox remember = new JCheckBox("Remember this setting for next time?");
                    remember.setFont(remember.getFont().deriveFont(10f));
                    remember.setAlignmentX(Component.CENTER_ALIGNMENT);
                    remember.setVisible(true);
                    JButton yesButton = new JButton("Yes");
                    JButton noButton = new JButton("No");
                    JPanel button = new JPanel();
                    button.setAlignmentX(Component.CENTER_ALIGNMENT);
                    button.add(yesButton);
                    button.add(noButton);
                    container.add(button);
                    noButton.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (remember.isSelected()) {
                                p.setRemoveTurnoutsFromEcos(0x01);
                            }
                            dialog.dispose();
                        }
                    });
                    yesButton.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (remember.isSelected()) {
                                p.setRemoveTurnoutsFromEcos(0x02);
                            }
                            RemoveObjectFromEcos removeObjectFromEcos = new RemoveObjectFromEcos();
                            removeObjectFromEcos.removeObjectFromEcos("" + etd.getObject(), tc);
                            deleteEcosTurnout(etd);
                            dialog.dispose();
                        }
                    });
                    container.add(remember);
                    container.setAlignmentX(Component.CENTER_ALIGNMENT);
                    container.setAlignmentY(Component.CENTER_ALIGNMENT);
                    dialog.getContentPane().add(container);
                    dialog.pack();
                    dialog.setModal(true);
                    dialog.setVisible(true);
                }
            }
        }
    }
    super.propertyChange(e);
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) JDialog(javax.swing.JDialog) RemoveObjectFromEcos(jmri.jmrix.ecos.utilities.RemoveObjectFromEcos)

Example 53 with JDialog

use of javax.swing.JDialog in project tika by apache.

the class TikaGUI method hyperlinkUpdate.

public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == EventType.ACTIVATED) {
        try {
            URL url = e.getURL();
            try (InputStream stream = url.openStream()) {
                JEditorPane editor = new JEditorPane("text/plain", IOUtils.toString(stream, UTF_8));
                editor.setEditable(false);
                editor.setBackground(Color.WHITE);
                editor.setCaretPosition(0);
                editor.setPreferredSize(new Dimension(600, 400));
                String name = url.toString();
                name = name.substring(name.lastIndexOf('/') + 1);
                JDialog dialog = new JDialog(this, "Apache Tika: " + name);
                dialog.add(new JScrollPane(editor));
                dialog.pack();
                dialog.setVisible(true);
            }
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) ProgressMonitorInputStream(javax.swing.ProgressMonitorInputStream) TikaInputStream(org.apache.tika.io.TikaInputStream) InputStream(java.io.InputStream) JEditorPane(javax.swing.JEditorPane) Dimension(java.awt.Dimension) IOException(java.io.IOException) URL(java.net.URL) JDialog(javax.swing.JDialog)

Example 54 with JDialog

use of javax.swing.JDialog in project processdash by dtuma.

the class ScheduleBalancingDialog method buildAndShowGUI.

private void buildAndShowGUI() {
    chartData = null;
    int numScheduleRows = scheduleRows.size();
    sumUpTotalTime();
    originalTotalTime = totalRow.time;
    if (originalTotalTime == 0)
        // if the rows added up to zero, choose a nominal target total time
        // corresponding to 10 hours per included schedule
        originalTotalTime = numScheduleRows * 60 * 10;
    JPanel panel = new JPanel(new GridBagLayout());
    if (numScheduleRows == 1) {
        totalRow.rowLabel = scheduleRows.get(0).rowLabel;
    } else {
        for (int i = 0; i < numScheduleRows; i++) scheduleRows.get(i).addToPanel(panel, i);
        scheduleRows.get(numScheduleRows - 1).showPercentageTickMarks();
        addChartToPanel(panel, numScheduleRows + 1);
    }
    totalRow.addToPanel(panel, numScheduleRows);
    if (rowsAreEditable == false) {
        String title = TaskScheduleDialog.resources.getString("Balance.Read_Only_Title");
        JOptionPane.showMessageDialog(parent.frame, panel, title, JOptionPane.PLAIN_MESSAGE);
    } else {
        String title = TaskScheduleDialog.resources.getString("Balance.Editable_Title");
        JDialog dialog = new JDialog(parent.frame, title, true);
        addButtons(dialog, panel, numScheduleRows + 2);
        panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        dialog.getContentPane().add(panel);
        dialog.pack();
        dialog.setLocationRelativeTo(parent.frame);
        dialog.setResizable(true);
        dialog.setVisible(true);
    }
}
Also used : JPanel(javax.swing.JPanel) GridBagLayout(java.awt.GridBagLayout) Paint(java.awt.Paint) JDialog(javax.swing.JDialog)

Example 55 with JDialog

use of javax.swing.JDialog in project processdash by dtuma.

the class JOptionPaneTweaker method addNotify.

public void addNotify() {
    super.addNotify();
    Window window = SwingUtilities.getWindowAncestor(this);
    if (window instanceof JDialog) {
        final JDialog dialog = (JDialog) window;
        if (delay <= 0) {
            doTweak(dialog);
        } else {
            Timer t = new Timer(delay, new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    doTweak(dialog);
                }
            });
            t.setRepeats(false);
            t.start();
        }
    }
}
Also used : Window(java.awt.Window) Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JDialog(javax.swing.JDialog)

Aggregations

JDialog (javax.swing.JDialog)181 JButton (javax.swing.JButton)70 JPanel (javax.swing.JPanel)61 ActionEvent (java.awt.event.ActionEvent)51 ActionListener (java.awt.event.ActionListener)39 JLabel (javax.swing.JLabel)39 JOptionPane (javax.swing.JOptionPane)34 BorderLayout (java.awt.BorderLayout)30 Dimension (java.awt.Dimension)27 JScrollPane (javax.swing.JScrollPane)27 JFrame (javax.swing.JFrame)23 BoxLayout (javax.swing.BoxLayout)21 FlowLayout (java.awt.FlowLayout)19 JCheckBox (javax.swing.JCheckBox)15 AbstractAction (javax.swing.AbstractAction)14 WindowEvent (java.awt.event.WindowEvent)13 JComponent (javax.swing.JComponent)12 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)11 WindowAdapter (java.awt.event.WindowAdapter)11 IOException (java.io.IOException)10