Example usage for javax.swing JTextField getDocument

List of usage examples for javax.swing JTextField getDocument

Introduction

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

Prototype

public Document getDocument() 

Source Link

Document

Fetches the model associated with the editor.

Usage

From source file:com.aw.swing.mvp.cmp.RowSelectorMediator.java

public RowSelectorMediator(JTextField textField, JTable table, int columnIndex) {
    this.textField = textField;
    this.table = table;
    this.columnIndex = columnIndex;

    documentListener = new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            textFieldChanged(e);/*  w  ww. j  a v  a 2  s.  c om*/
        }

        public void insertUpdate(DocumentEvent e) {
            textFieldChanged(e);
        }

        public void removeUpdate(DocumentEvent e) {
            textFieldChanged(e);
        }
    };

    textField.getDocument().addDocumentListener(documentListener);

    //Add the keylistener to process the Up, Down, PgUp and PgDn keys events
    textField.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            textFieldKeyPressed(e);
        }

        public void keyReleased(KeyEvent e) {
        }
    });
}

From source file:edu.ku.brc.af.ui.weblink.WebLinkButton.java

/**
 * @return//from www.  ja v  a 2s  . c o m
 */
private CustomDialog createPromptDlg(final Hashtable<String, String> backupHash) {
    if (webLinkDef != null) {
        // Start by getting the data needed to build the URL
        // so first see if we need to prompt for data.

        int promptCnt = webLinkDef.getPromptCount();
        if (promptCnt > 0 || backupHash.size() > 0) {
            textFieldHash.clear();

            promptCnt += backupHash != null ? backupHash.size() : 0;

            String rowDef = createDuplicateJGoodiesDef("p", "4px", promptCnt); //$NON-NLS-1$ //$NON-NLS-2$
            PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,f:p:g", rowDef)); //$NON-NLS-1$
            CellConstraints cc = new CellConstraints();

            DocumentAdaptor dla = new DocumentAdaptor() {
                @Override
                protected void changed(DocumentEvent e) {
                    super.changed(e);
                    boolean enableOK = true;
                    for (JTextField tf : textFieldHash.values()) {
                        if (tf.getText().length() == 0) {
                            enableOK = false;
                            break;
                        }
                    }
                    promptDialog.getOkBtn().setEnabled(enableOK);
                }

            };

            int y = 1;
            for (WebLinkDefArg arg : webLinkDef.getArgs()) {
                if (arg.isPrompt() && valueHash.get(arg.getName()) == null) {
                    JTextField txtField = createTextField(15);
                    txtField.getDocument().addDocumentListener(dla);
                    textFieldHash.put(arg.getName(), txtField);
                    String label = arg.getTitle();
                    if (StringUtils.isEmpty(label)) {
                        label = arg.getName();
                    }
                    pb.add(createFormLabel(label), cc.xy(1, y));
                    pb.add(txtField, cc.xy(3, y));
                    y += 2;
                }
            }

            if (backupHash != null) {
                for (String name : backupHash.keySet()) {
                    JTextField txtField = createTextField(15);
                    txtField.getDocument().addDocumentListener(dla);
                    textFieldHash.put(name, txtField);
                    pb.add(createLabel(backupHash.get(name), SwingConstants.RIGHT), cc.xy(1, y));
                    pb.add(txtField, cc.xy(3, y));
                    y += 2;
                }
            }

            pb.setDefaultDialogBorder();

            return new CustomDialog((Frame) getTopWindow(), getResourceString("WBLK_PROMPT_DATA"), true,
                    CustomDialog.OKCANCELHELP, pb.getPanel());
        }
    }
    return null;
}

From source file:it.txt.access.capability.revocation.wizard.panel.PanelRevocationData.java

private void checkEditableTextBox(final javax.swing.JTextField textBox) {

    textBox.getDocument().addDocumentListener(new DocumentListener() {

        public void insertUpdate(DocumentEvent e) {
            sorroundIssuerDocumentChange(e);
        }// ww w.  ja va 2 s. co  m

        public void removeUpdate(DocumentEvent e) {
            sorroundIssuerDocumentChange(e);
        }

        public void changedUpdate(DocumentEvent e) {
            sorroundIssuerDocumentChange(e);
        }

        private void sorroundIssuerDocumentChange(DocumentEvent e) {
            if (textBox.getText().equals("")) {
                textBox.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
            } else {
                textBox.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));
            }
        }
    });
}

From source file:es.emergya.ui.plugins.admin.aux1.RecursoDialog.java

public RecursoDialog(final Recurso rec, final AdminResources adminResources) {
    super();/*from  w  w  w .  ja  v a2  s  .c o  m*/
    setAlwaysOnTop(true);
    setSize(600, 400);

    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            if (cambios) {
                int res = JOptionPane.showConfirmDialog(RecursoDialog.this,
                        "Existen cambios sin guardar. Seguro que desea cerrar la ventana?",
                        "Cambios sin guardar", JOptionPane.OK_CANCEL_OPTION);
                if (res != JOptionPane.CANCEL_OPTION) {
                    e.getWindow().dispose();
                }
            } else {
                e.getWindow().dispose();
            }
        }
    });
    final Recurso r = (rec == null) ? null : RecursoConsultas.get(rec.getId());
    if (r != null) {
        setTitle(i18n.getString("Resources.summary.titleWindow") + " " + r.getIdentificador());
    } else {
        setTitle(i18n.getString("Resources.summary.titleWindow.new"));
    }
    setIconImage(getBasicWindow().getFrame().getIconImage());
    JPanel base = new JPanel();
    base.setBackground(Color.WHITE);
    base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

    // Icono del titulo
    JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING));
    title.setOpaque(false);
    JLabel labelTitulo = null;
    if (r != null) {
        labelTitulo = new JLabel(i18n.getString("Resources.summary"),
                LogicConstants.getIcon("tittleficha_icon_recurso"), JLabel.LEFT);

    } else {
        labelTitulo = new JLabel(i18n.getString("Resources.cabecera.nuevo"),
                LogicConstants.getIcon("tittleficha_icon_recurso"), JLabel.LEFT);

    }
    labelTitulo.setFont(LogicConstants.deriveBoldFont(12f));
    title.add(labelTitulo);
    base.add(title);

    // Nombre
    JPanel mid = new JPanel(new SpringLayout());
    mid.setOpaque(false);
    mid.add(new JLabel(i18n.getString("Resources.name"), JLabel.RIGHT));
    final JTextField name = new JTextField(25);
    if (r != null) {
        name.setText(r.getNombre());
    }

    name.getDocument().addDocumentListener(changeListener);
    name.setEditable(r == null);
    mid.add(name);

    // patrullas
    final JLabel labelSquads = new JLabel(i18n.getString("Resources.squad"), JLabel.RIGHT);
    mid.add(labelSquads);
    List<Patrulla> pl = PatrullaConsultas.getAll();
    pl.add(0, null);
    final JComboBox squads = new JComboBox(pl.toArray());
    squads.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXX");
    squads.addActionListener(changeSelectionListener);
    squads.setOpaque(false);
    labelSquads.setLabelFor(squads);
    if (r != null) {
        squads.setSelectedItem(r.getPatrullas());
    } else {
        squads.setSelectedItem(null);
    }
    squads.setEnabled((r != null && r.getHabilitado() != null) ? r.getHabilitado() : true);
    mid.add(squads);

    // // Identificador
    // mid.setOpaque(false);
    // mid.add(new JLabel(i18n.getString("Resources.identificador"),
    // JLabel.RIGHT));
    // final JTextField identificador = new JTextField("");
    // if (r != null) {
    // identificador.setText(r.getIdentificador());
    // }
    // identificador.getDocument().addDocumentListener(changeListener);
    // identificador.setEditable(r == null);
    // mid.add(identificador);
    // Espacio en blanco
    // mid.add(Box.createHorizontalGlue());
    // mid.add(Box.createHorizontalGlue());

    // Tipo
    final JLabel labelTipoRecursos = new JLabel(i18n.getString("Resources.type"), JLabel.RIGHT);
    mid.add(labelTipoRecursos);
    final JComboBox types = new JComboBox(RecursoConsultas.getTipos());
    labelTipoRecursos.setLabelFor(types);
    types.addActionListener(changeSelectionListener);
    if (r != null) {
        types.setSelectedItem(r.getTipo());
    } else {
        types.setSelectedItem(0);
    }
    // types.setEditable(true);
    types.setEnabled(true);
    mid.add(types);

    // Estado Eurocop
    mid.add(new JLabel(i18n.getString("Resources.status"), JLabel.RIGHT));
    final JTextField status = new JTextField();
    if (r != null && r.getEstadoEurocop() != null) {
        status.setText(r.getEstadoEurocop().getIdentificador());
    }
    status.setEditable(false);
    mid.add(status);

    // Subflota y patrulla
    mid.add(new JLabel(i18n.getString("Resources.subfleet"), JLabel.RIGHT));
    final JComboBox subfleets = new JComboBox(FlotaConsultas.getAllHabilitadas());
    subfleets.addActionListener(changeSelectionListener);
    if (r != null) {
        subfleets.setSelectedItem(r.getFlotas());
    } else {
        subfleets.setSelectedIndex(0);
    }
    subfleets.setEnabled(true);
    subfleets.setOpaque(false);
    mid.add(subfleets);

    // Referencia humana
    mid.add(new JLabel(i18n.getString("Resources.incidences"), JLabel.RIGHT));
    final JTextField rhumana = new JTextField();
    // if (r != null && r.getIncidencias() != null) {
    // rhumana.setText(r.getIncidencias().getReferenciaHumana());
    // }
    rhumana.setEditable(false);
    mid.add(rhumana);

    // dispositivo
    mid.add(new JLabel(i18n.getString("Resources.device"), JLabel.RIGHT));
    final PlainDocument plainDocument = new PlainDocument() {

        private static final long serialVersionUID = 4929271093724956016L;

        @Override
        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
            if (this.getLength() + str.length() <= LogicConstants.LONGITUD_ISSI) {
                super.insertString(offs, str, a);
            }
        }
    };
    final JTextField issi = new JTextField(plainDocument, "", LogicConstants.LONGITUD_ISSI);
    plainDocument.addDocumentListener(changeListener);
    issi.setEditable(true);
    mid.add(issi);
    mid.add(new JLabel(i18n.getString("Resources.enabled"), JLabel.RIGHT));
    final JCheckBox enabled = new JCheckBox("", true);
    enabled.addActionListener(changeSelectionListener);
    enabled.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            if (enabled.isSelected()) {
                squads.setSelectedIndex(0);
            }
            squads.setEnabled(enabled.isSelected());
        }
    });
    enabled.setEnabled(true);
    enabled.setOpaque(false);
    if (r != null) {
        enabled.setSelected(r.getHabilitado());
    } else {
        enabled.setSelected(true);
    }
    if (r != null && r.getDispositivo() != null) {
        issi.setText(
                StringUtils.leftPad(String.valueOf(r.getDispositivo()), LogicConstants.LONGITUD_ISSI, '0'));
    }

    mid.add(enabled);

    // Fecha ultimo gps
    mid.add(new JLabel(i18n.getString("Resources.lastPosition"), JLabel.RIGHT));
    JTextField lastGPS = new JTextField();
    final Date lastGPSDateForRecurso = HistoricoGPSConsultas.lastGPSDateForRecurso(r);
    if (lastGPSDateForRecurso != null) {
        lastGPS.setText(SimpleDateFormat.getDateTimeInstance().format(lastGPSDateForRecurso));
    }
    lastGPS.setEditable(false);
    mid.add(lastGPS);

    // Espacio en blanco
    mid.add(Box.createHorizontalGlue());
    mid.add(Box.createHorizontalGlue());

    // informacion adicional
    JPanel infoPanel = new JPanel(new SpringLayout());
    final JTextField info = new JTextField(25);
    info.getDocument().addDocumentListener(changeListener);
    infoPanel.add(new JLabel(i18n.getString("Resources.info")));
    infoPanel.add(info);
    infoPanel.setOpaque(false);
    info.setOpaque(false);
    SpringUtilities.makeCompactGrid(infoPanel, 1, 2, 6, 6, 6, 18);

    if (r != null) {
        info.setText(r.getInfoAdicional());
    } else {
        info.setText("");
    }
    info.setEditable(true);

    // Espacio en blanco
    mid.add(Box.createHorizontalGlue());
    mid.add(Box.createHorizontalGlue());

    SpringUtilities.makeCompactGrid(mid, 5, 4, 6, 6, 6, 18);
    base.add(mid);
    base.add(infoPanel);

    JPanel buttons = new JPanel();
    buttons.setOpaque(false);
    JButton accept = null;
    if (r == null) {
        accept = new JButton("Crear", LogicConstants.getIcon("button_crear"));
    } else {
        accept = new JButton("Guardar", LogicConstants.getIcon("button_save"));
    }
    accept.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                if (cambios || r == null || r.getId() == null) {
                    boolean shithappens = true;
                    if ((r == null || r.getId() == null)) { // Estamos
                        // creando
                        // uno nuevo
                        if (RecursoConsultas.alreadyExists(name.getText())) {
                            shithappens = false;
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.nombreUnico"));
                        } else if (issi.getText() != null && issi.getText().length() > 0 && StringUtils
                                .trimToEmpty(issi.getText()).length() != LogicConstants.LONGITUD_ISSI) {
                            JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString(Locale.ROOT,
                                    "admin.recursos.popup.error.faltanCifras", LogicConstants.LONGITUD_ISSI));
                            shithappens = false;
                        } else if (issi.getText() != null && issi.getText().length() > 0
                                && LogicConstants.isNumeric(issi.getText())
                                && RecursoConsultas.alreadyExists(new Integer(issi.getText()))) {
                            shithappens = false;
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.dispositivoUnico"));
                        }
                    }
                    if (shithappens) {
                        if (name.getText().isEmpty()) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.nombreNulo"));
                        } else if (issi.getText() != null && issi.getText().length() > 0 && StringUtils
                                .trimToEmpty(issi.getText()).length() != LogicConstants.LONGITUD_ISSI) {
                            JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString(Locale.ROOT,
                                    "admin.recursos.popup.error.faltanCifras", LogicConstants.LONGITUD_ISSI));
                        } else if (issi.getText() != null && issi.getText().length() > 0
                                && LogicConstants.isNumeric(issi.getText()) && r != null && r.getId() != null
                                && RecursoConsultas.alreadyExists(new Integer(issi.getText()), r.getId())) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.issiUnico"));
                        } else if (issi.getText() != null && issi.getText().length() > 0
                                && !LogicConstants.isNumeric(issi.getText())) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.noNumerico"));
                            // } else if (identificador.getText().isEmpty())
                            // {
                            // JOptionPane
                            // .showMessageDialog(
                            // RecursoDialog.this,
                            // i18n.getString("admin.recursos.popup.error.identificadorNulo"));
                        } else if (subfleets.getSelectedIndex() == -1) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.noSubflota"));
                        } else if (types.getSelectedItem() == null
                                || types.getSelectedItem().toString().trim().isEmpty()) {
                            JOptionPane.showMessageDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.error.noTipo"));
                        } else {
                            int i = JOptionPane.showConfirmDialog(RecursoDialog.this,
                                    i18n.getString("admin.recursos.popup.dialogo.guardar.titulo"),
                                    i18n.getString("admin.recursos.popup.dialogo.guardar.guardar"),
                                    JOptionPane.YES_NO_CANCEL_OPTION);

                            if (i == JOptionPane.YES_OPTION) {

                                Recurso recurso = r;

                                if (r == null) {
                                    recurso = new Recurso();
                                }

                                recurso.setInfoAdicional(info.getText());
                                if (issi.getText() != null && issi.getText().length() > 0) {
                                    recurso.setDispositivo(new Integer(issi.getText()));
                                } else {
                                    recurso.setDispositivo(null);
                                }
                                recurso.setFlotas(FlotaConsultas.find(subfleets.getSelectedItem().toString()));
                                if (squads.getSelectedItem() != null && enabled.isSelected()) {
                                    recurso.setPatrullas(
                                            PatrullaConsultas.find(squads.getSelectedItem().toString()));
                                } else {
                                    recurso.setPatrullas(null);
                                }
                                recurso.setNombre(name.getText());
                                recurso.setHabilitado(enabled.isSelected());
                                // recurso.setIdentificador(identificador
                                // .getText());
                                recurso.setTipo(types.getSelectedItem().toString());
                                dispose();

                                RecursoAdmin.saveOrUpdate(recurso);
                                adminResources.refresh(null);

                                PluginEventHandler.fireChange(adminResources);
                            } else if (i == JOptionPane.NO_OPTION) {
                                dispose();
                            }
                        }
                    }
                } else {
                    log.debug("No hay cambios");
                    dispose();
                }

            } catch (Throwable t) {
                log.error("Error guardando un recurso", t);
            }
        }
    });
    buttons.add(accept);

    JButton cancelar = new JButton("Cancelar", LogicConstants.getIcon("button_cancel"));

    cancelar.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (cambios) {
                if (JOptionPane.showConfirmDialog(RecursoDialog.this,
                        "Existen cambios sin guardar. Seguro que desea cerrar la ventana?",
                        "Cambios sin guardar", JOptionPane.OK_CANCEL_OPTION) != JOptionPane.CANCEL_OPTION) {
                    dispose();
                }
            } else {
                dispose();
            }
        }
    });

    buttons.add(cancelar);

    base.add(buttons);

    getContentPane().add(base);
    setLocationRelativeTo(null);
    cambios = false;
    if (r == null) {
        cambios = true;
    }

    pack();

    int x;
    int y;

    Container myParent = getBasicWindow().getPluginContainer().getDetachedTab(0);
    Point topLeft = myParent.getLocationOnScreen();
    Dimension parentSize = myParent.getSize();

    Dimension mySize = getSize();

    if (parentSize.width > mySize.width) {
        x = ((parentSize.width - mySize.width) / 2) + topLeft.x;
    } else {
        x = topLeft.x;
    }

    if (parentSize.height > mySize.height) {
        y = ((parentSize.height - mySize.height) / 2) + topLeft.y;
    } else {
        y = topLeft.y;
    }

    setLocation(x, y);
    cambios = false;
}

From source file:com.mirth.connect.client.ui.panels.connectors.PollingSettingsPanel.java

private void initComponents() {
    scheduleTypeLabel = new JLabel("Schedule Type:");
    scheduleTypeComboBox = new MirthComboBox();
    // @formatter:off
    scheduleTypeComboBox/* w  w  w  . j  ava 2  s  .  c o  m*/
            .setToolTipText("<html>This connector polls to determine when new messages have arrived.<br>"
                    + "Select \"Interval\" to poll each n units of time.<br>"
                    + "Select \"Time\" to poll once a day at the specified time.<br>"
                    + "Select \"Cron\" to poll at the specified cron expression(s).</html>");
    // @formatter:on
    scheduleTypeComboBox.addItem(PollingType.INTERVAL.getDisplayName());
    scheduleTypeComboBox.addItem(PollingType.TIME.getDisplayName());
    scheduleTypeComboBox.addItem(PollingType.CRON.getDisplayName());

    scheduleTypeActionListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            scheduleTypeActionPerformed();
            updateNextFireTime();
        }
    };

    nextPollLabel = new JLabel("Next poll at: ");

    yesStartPollRadioButton = new MirthRadioButton("Yes");
    yesStartPollRadioButton.setToolTipText(
            "<html>Select Yes to immediately poll once on start.<br/>All subsequent polling will follow the specified schedule.</html>");
    yesStartPollRadioButton.setBackground(UIConstants.BACKGROUND_COLOR);
    yesStartPollRadioButton.setFocusable(false);

    noStartPollRadioButton = new MirthRadioButton("No");
    noStartPollRadioButton.setToolTipText(
            "<html>Select Yes to immediately poll once on start.<br/>All subsequent polling will follow the specified schedule.</html>");
    noStartPollRadioButton.setBackground(UIConstants.BACKGROUND_COLOR);
    noStartPollRadioButton.setSelected(true);
    noStartPollRadioButton.setFocusable(false);

    pollOnStartButtonGroup = new ButtonGroup();
    pollOnStartButtonGroup.add(yesStartPollRadioButton);
    pollOnStartButtonGroup.add(noStartPollRadioButton);

    pollingTimePicker = new MirthTimePicker();
    pollingTimePicker.setToolTipText("The time of day to poll.");
    pollingTimePicker.setVisible(false);
    JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) pollingTimePicker.getEditor();
    JTextField textField = editor.getTextField();
    textField.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent event) {
            updateNextFireTime();
        }

        public void removeUpdate(DocumentEvent e) {
        }

        public void changedUpdate(DocumentEvent e) {
        }
    });

    pollingFrequencySettingsPanel = new JPanel();
    pollingFrequencySettingsPanel.setBackground(UIConstants.BACKGROUND_COLOR);
    pollingFrequencySettingsPanel.setVisible(true);

    pollingFrequencyField = new MirthTextField();
    pollingFrequencyField.setToolTipText(
            "<html>The specified repeating time interval.<br/>Units must be less than 24 hours of time<br/>when converted to milliseconds.</html>");
    pollingFrequencyField.setSize(new Dimension(200, 20));
    pollingFrequencyField.setDocument(new MirthFieldConstraints(0, false, false, true));
    pollingFrequencyField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateNextFireTime();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateNextFireTime();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });

    pollingFrequencyTypeComboBox = new MirthComboBox();
    pollingFrequencyTypeComboBox.setToolTipText("The interval's unit of time.");
    pollingFrequencyTypeComboBox.addItem(POLLING_FREQUENCY_MILLISECONDS);
    pollingFrequencyTypeComboBox.addItem(POLLING_FREQUENCY_SECONDS);
    pollingFrequencyTypeComboBox.addItem(POLLING_FREQUENCY_MINUTES);
    pollingFrequencyTypeComboBox.addItem(POLLING_FREQUENCY_HOURS);
    pollingFrequencyTypeComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateNextFireTime();
        }
    });

    pollingCronSettingsPanel = new JPanel();
    pollingCronSettingsPanel.setBackground(UIConstants.BACKGROUND_COLOR);
    pollingCronSettingsPanel.setVisible(false);

    cronJobsTable = new MirthTable();
    Object[][] tableData = new Object[0][1];
    cronJobsTable.setModel(new RefreshTableModel(tableData, new String[] { "Expression", "Description" }));
    cronJobsTable.setOpaque(true);
    cronJobsTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    cronJobsTable.getTableHeader().setReorderingAllowed(false);
    cronJobsTable.setSortable(false);
    cronJobsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    cronJobsTable.getColumnModel().getColumn(0).setResizable(false);
    cronJobsTable.getColumnModel().getColumn(0).setCellEditor(new CronTableCellEditor(true));
    cronJobsTable.getColumnModel().getColumn(1).setResizable(false);
    cronJobsTable.getColumnModel().getColumn(1).setCellEditor(new CronTableCellEditor(true));

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR);
        cronJobsTable.setHighlighters(highlighter);
    }

    HighlightPredicate errorHighlighterPredicate = new HighlightPredicate() {
        public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
            if (adapter.column == cronJobsTable.getColumnViewIndex("Expression")) {
                String cronExpression = (String) cronJobsTable.getValueAt(adapter.row, adapter.column);

                if (invalidExpressions.contains(cronExpression)) {
                    return true;
                }
            }
            return false;
        }
    };
    errorHighlighter = new ColorHighlighter(errorHighlighterPredicate, Color.PINK, Color.BLACK, Color.PINK,
            Color.BLACK);

    //@formatter:off
    String tooltip = "<html><head><style>td {text-align:center;}</style></head>"
            + "Cron expressions must be in Quartz format with at least 6 fields.<br/>" + "<br/>Format:"
            + "<table>" + "<tr><td>Field</td><td>Required</td><td>Values</td><td>Special Characters</td></tr>"
            + "<tr><td>Seconds</td><td>YES</td><td>0-59</td><td>, - * /</td></tr>"
            + "<tr><td>Minutes</td><td>YES</td><td>0-59</td><td>, - * /</td></tr>"
            + "<tr><td>Hours</td><td>YES</td><td>0-23</td><td>, - * /</td></tr>"
            + "<tr><td>Day of Month</td><td>YES</td><td>1-31</td><td>, - * ? / L W</td></tr>"
            + "<tr><td>Month</td><td>YES</td><td>1-12 or JAN-DEC</td><td>, - * /</td></tr>"
            + "<tr><td>Day of Week</td><td>YES</td><td>1-7 or SUN-SAT</td><td>, - * ? / L #</td></tr>"
            + "<tr><td>Year</td><td>NO</td><td>empty, 1970-2099</td><td>, - * /</td></tr>" + "</table>"
            + "<br/>Special Characters:" + "<br/> &nbsp <b>*</b> : all values"
            + "<br/> &nbsp <b>?</b> : no specific value" + "<br/> &nbsp <b>-</b> : used to specify ranges"
            + "<br/> &nbsp <b>,</b> : used to specify list of values"
            + "<br/> &nbsp <b>/</b> : used to specify increments"
            + "<br/> &nbsp <b>L</b> : used to specify the last of"
            + "<br/> &nbsp <b>W</b> : used to specify the nearest weekday"
            + "<br/> &nbsp <b>#</b> : used to specify the nth day of the month"
            + "<br/><br/>Example: 0 */5 8-17 * * ? means to fire every 5 minutes starting at 8am<br/>and ending at 5pm everyday"
            + "<br/><br/><b>Note:</b> Support for specifying both a day-of-week and day-of-month<br/>is not yet supported. A ? must be used in one of these fields.</html>";
    //@formatter:on
    cronJobsTable.setToolTipText(tooltip);
    cronJobsTable.getTableHeader().setToolTipText(tooltip);

    cronScrollPane = new JScrollPane();
    cronScrollPane.getViewport().add(cronJobsTable);

    addJobButton = new JButton("Add");
    addJobButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            ((DefaultTableModel) cronJobsTable.getModel()).addRow(new Vector<String>());

            int rowSelectionNumber = cronJobsTable.getRowCount() - 1;
            cronJobsTable.setRowSelectionInterval(rowSelectionNumber, rowSelectionNumber);
            PlatformUI.MIRTH_FRAME.setSaveEnabled(true);

            Boolean enabled = deleteJobButton.isEnabled();
            if (!enabled) {
                deleteJobButton.setEnabled(true);
            }
            updateNextFireTime();
        }
    });

    deleteJobButton = new JButton("Delete");
    deleteJobButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            int rowSelectionNumber = cronJobsTable.getSelectedRow();

            if (rowSelectionNumber > -1) {
                DefaultTableModel model = (DefaultTableModel) cronJobsTable.getModel();
                model.removeRow(rowSelectionNumber);

                rowSelectionNumber--;
                if (rowSelectionNumber > -1) {
                    cronJobsTable.setRowSelectionInterval(rowSelectionNumber, rowSelectionNumber);
                } else if (cronJobsTable.getRowCount() > 0) {
                    cronJobsTable.setRowSelectionInterval(0, 0);
                }

                if (cronJobsTable.getRowCount() == 0) {
                    deleteJobButton.setEnabled(false);
                }
            }

            updateNextFireTime();
            PlatformUI.MIRTH_FRAME.setSaveEnabled(true);
        }
    });
    deleteJobButton.setEnabled(false);

    advancedSettingsButton = new JButton(new ImageIcon(Frame.class.getResource("images/wrench.png")));
    advancedSettingsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            lastSelectedPollingType = StringUtils.isBlank(lastSelectedPollingType) ? "Interval"
                    : lastSelectedPollingType;
            new AdvancedPollingSettingsDialog(lastSelectedPollingType, cachedAdvancedConnectorProperties,
                    channelContext);
            updateNextFireTime();
        }
    });

    timeSettingsLabel = new JLabel("Interval:");
    timeSettingsLabel.setBackground(UIConstants.BACKGROUND_COLOR);

    scheduleSettingsPanel = new JPanel();
    scheduleSettingsPanel.setBackground(UIConstants.BACKGROUND_COLOR);

    if (!channelContext) {
        // @formatter:off
        scheduleTypeComboBox.setToolTipText("<html>Select the pruning schedule type.<br>"
                + "Select \"Interval\" to prune each n units of time.<br>"
                + "Select \"Time\" to prune once a day at the specified time.<br>"
                + "Select \"Cron\" to prune at the specified cron expression(s).</html>");
        // @formatter:on 
        pollingFrequencyField.setToolTipText(
                "<html>The specified repeating time interval.<br/>Units must be between 1 and 24 hours of time<br/>when converted to milliseconds.</html>");
    }
}

From source file:krasa.formatter.plugin.ProjectSettingsForm.java

public ProjectSettingsForm(final Project project) {
    DONATEButton.setBorder(BorderFactory.createEmptyBorder());
    DONATEButton.setContentAreaFilled(false);
    this.project = project;
    JToggleButton[] modifiableButtons = new JToggleButton[] { useDefaultFormatter, useEclipseFormatter,
            optimizeImportsCheckBox, enableJavaFormatting, doNotFormatOtherFilesRadioButton,
            formatOtherFilesWithExceptionsRadioButton, formatSelectedTextInAllFileTypes, enableJSFormatting,
            enableCppFormatting, importOrderConfigurationManualRadioButton,
            importOrderConfigurationFromFileRadioButton, enableGWTNativeMethodsCheckBox };
    for (JToggleButton button : modifiableButtons) {
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                updateComponents();/*  www.j a  v a2 s . c o  m*/
            }
        });
    }

    JTextField[] modifiableFields = new JTextField[] { pathToEclipsePreferenceFileJava,
            pathToEclipsePreferenceFileJS, pathToEclipsePreferenceFileCpp, disabledFileTypes, importOrder,
            pathToImportOrderPreferenceFile };
    for (JTextField field : modifiableFields) {
        field.getDocument().addDocumentListener(new DocumentAdapter() {
            protected void textChanged(DocumentEvent e) {
                updateComponents();
            }
        });
    }

    eclipsePreferenceFilePathJavaBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            browseForFile(pathToEclipsePreferenceFileJava);
        }
    });
    pathToImportOrderPreferenceFileBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            browseForFile(pathToImportOrderPreferenceFile);
        }
    });
    eclipsePreferenceFilePathJSBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            browseForFile(pathToEclipsePreferenceFileJS);
        }
    });
    eclipsePreferenceFilePathCppBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            browseForFile(pathToEclipsePreferenceFileCpp);
        }
    });

    rootComponent.addAncestorListener(new AncestorListener() {
        public void ancestorAdded(AncestorEvent event) {
            // Called when component becomes visible, to ensure that the
            // popups
            // are visible when the form is shown for the first time.
            updateComponents();
        }

        public void ancestorRemoved(AncestorEvent event) {
        }

        public void ancestorMoved(AncestorEvent event) {
        }
    });

    pathToEclipsePreferenceFileJava.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            setJavaFormatterProfileModel();
        }
    });

    pathToEclipsePreferenceFileJS.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            setJavaScriptFormatterProfileModel();
        }
    });

    pathToEclipsePreferenceFileCpp.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            setCppFormatterProfileModel();
        }
    });

    newProfile.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (isModified(displayedSettings)) {
                createConfirmation("Profile was modified, save changes to current profile?", "Yes", "No",
                        new Runnable() {
                            @Override
                            public void run() {
                                apply();
                                createProfile();
                            }
                        }, new Runnable() {
                            @Override
                            public void run() {
                                importFrom(displayedSettings);
                                createProfile();
                            }
                        }, 0).showInFocusCenter();
            } else {
                createProfile();
            }
        }

        private void createProfile() {
            Settings settings = GlobalSettings.getInstance().newSettings();
            refreshProfilesModel();
            profiles.setSelectedItem(settings);
        }
    });
    copyProfile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (isModified(displayedSettings)) {
                ListPopup confirmation = createConfirmation(
                        "Profile was modified, save changes to current profile?", "Yes", "No", new Runnable() {
                            @Override
                            public void run() {
                                apply();
                                copyProfile();
                            }
                        }, new Runnable() {
                            @Override
                            public void run() {
                                importFrom(displayedSettings);
                                copyProfile();
                            }
                        }, 0);

                confirmation.showInFocusCenter();
            } else {
                copyProfile();
            }
        }

        private void copyProfile() {
            Settings settings = GlobalSettings.getInstance().copySettings(displayedSettings);
            refreshProfilesModel();
            profiles.setSelectedItem(settings);

        }
    });
    setJavaFormatterProfileModel();
    setJavaScriptFormatterProfileModel();
    setCppFormatterProfileModel();

    profilesModel = createProfilesModel();
    profiles.setModel(profilesModel);
    profiles.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // && isSameId()
            if (displayedSettings != null && getSelectedItem() != null && isModified(displayedSettings)) {
                showConfirmationDialogOnProfileChange();
            } else if (displayedSettings != null && getSelectedItem() != null) {
                importFromInternal(getSelectedItem());
            }
        }

    });

    profiles.setRenderer(new ListCellRendererWrapper() {
        @Override
        public void customize(JList jList, Object value, int i, boolean b, boolean b1) {
            if (value != null) {
                setText(((Settings) value).getName());
            }
        }
    });
    rename.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final JTextField content = new JTextField();
            content.setText(displayedSettings.getName());
            JBPopup balloon = PopupFactoryImpl.getInstance().createComponentPopupBuilder(content, content)
                    .createPopup();
            balloon.setMinimumSize(new Dimension(200, 20));
            balloon.addListener(new JBPopupListener() {
                @Override
                public void beforeShown(LightweightWindowEvent event) {
                }

                @Override
                public void onClosed(LightweightWindowEvent event) {
                    displayedSettings.setName(content.getText());
                }
            });
            balloon.showUnderneathOf(rename);
        }
    });
    delete.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int selectedIndex = profiles.getSelectedIndex();
            GlobalSettings.getInstance().delete(getSelectedItem(), getProject());
            profiles.setModel(profilesModel = createProfilesModel());
            int itemCount = profiles.getItemCount();
            if (selectedIndex < itemCount && selectedIndex >= 0) {
                Object itemAt = profiles.getItemAt(selectedIndex);
                importFromInternal((Settings) itemAt);
                profiles.setSelectedIndex(selectedIndex);
            }
            if (selectedIndex == itemCount && selectedIndex - 1 >= 0) {
                Object itemAt = profiles.getItemAt(selectedIndex - 1);
                importFromInternal((Settings) itemAt);
                profiles.setSelectedIndex(selectedIndex - 1);
            } else {
                Settings defaultSettings = GlobalSettings.getInstance().getDefaultSettings();
                importFromInternal(defaultSettings);
                profiles.setSelectedItem(defaultSettings);
            }

        }
    });
    DONATEButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            BareBonesBrowserLaunch.openURL(
                    "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=75YN7U7H7D7XU&lc=CZ&item_name=Eclipse%20code%20formatter%20%2d%20IntelliJ%20plugin%20%2d%20Donation&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest");
        }
    });
    helpButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            BareBonesBrowserLaunch
                    .openURL("http://code.google.com/p/eclipse-code-formatter-intellij-plugin/wiki/HowTo");
        }
    });
    ;
    homepage.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            BareBonesBrowserLaunch.openURL("http://plugins.intellij.net/plugin/?idea&id=6546");
        }
    });
}

From source file:edu.ku.brc.af.ui.forms.formatters.UIFormatterEditorDlg.java

/**
 * @param txtFld/*from   w w w.ja  v  a2s.c  om*/
 */
private void hookTextChangeListener(final JTextField txtFld, final String errMsgKey, final int maxLen) {
    txtFld.getDocument().addDocumentListener(new DocumentAdaptor() {
        @Override
        protected void changed(DocumentEvent e) {
            if (StringUtils.isEmpty(txtFld.getText())) {
                setError(getResourceString(errMsgKey), false);
                updateUIEnabled();

            } else if (selectedFormat == null) {
                setError(fmtErrMsg, true);

            } else {
                updateUIEnabled();

                if (checkFieldLen(txtFld.getDocument().getLength(), maxLen)) {
                    sampleLabel.setText("");
                    updateSample();
                }
            }
            hasChanged = true;
        }
    });
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.FormPane.java

@Override
public void swapTextFieldType(final InputPanel inputPanel, final short fieldLen) {
    JTextComponent oldComp;//from  www. j  av  a2s .c o m
    short fieldType;
    short rows;
    if (inputPanel.getComp() instanceof JTextField) {
        JTextField tf = (JTextField) inputPanel.getComp();
        tf.getDocument().removeDocumentListener(docListener);
        fieldType = WorkbenchTemplateMappingItem.TEXTAREA;
        oldComp = tf;
        rows = DEFAULT_TEXTAREA_ROWS;
    } else {
        JTextArea ta = (JTextArea) inputPanel.getComp();
        ta.getDocument().removeDocumentListener(docListener);
        fieldType = WorkbenchTemplateMappingItem.TEXTFIELD;
        oldComp = ta;
        rows = DEFAULT_TEXTFIELD_ROWS;
    }

    WorkbenchTemplateMappingItem wbtmi = inputPanel.getWbtmi();
    inputPanel.setComp(createUIComp(WorkbenchTask.getDataType(wbtmi), wbtmi.getCaption(), wbtmi.getFieldName(),
            fieldType, wbtmi.getDataFieldLength(), fieldLen, rows, wbtmi));

    ignoreChanges = true;
    ((JTextComponent) inputPanel.getComp()).setText(oldComp.getText());
    ignoreChanges = false;

    hasChanged = true;
    workbenchPane.setChanged(true);
}

From source file:cz.alej.michalik.totp.client.AddDialog.java

public AddDialog(final Properties prop) {
    System.out.println("Pridat novy zaznam");
    this.setTitle("Pidat");
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.setMinimumSize(new Dimension(600, 150));
    this.setLocationByPlatform(true);
    // Panel pro vytvoen okraj
    JPanel panel = new JPanel();
    panel.setBorder(new EmptyBorder(10, 10, 10, 10));
    panel.setLayout(new GridBagLayout());
    // Vlastnosti pro popisky
    GridBagConstraints label = new GridBagConstraints();
    label.insets = new Insets(2, 2, 2, 2);
    label.fill = GridBagConstraints.NONE;
    label.weightx = 1;//ww  w. j a  va2s .  co m
    // Vlastnosti pro pole
    GridBagConstraints field = new GridBagConstraints();
    field.insets = new Insets(2, 2, 2, 2);
    field.fill = GridBagConstraints.HORIZONTAL;
    field.weightx = 10;

    this.add(panel);

    // Nastavm ikonu okna
    try {
        String path = "/material-design-icons/content/drawable-xhdpi/ic_create_black_48dp.png";
        this.setIconImage(Toolkit.getDefaultToolkit().getImage(App.class.getResource(path)));
    } catch (NullPointerException ex) {
        System.out.println("Icon not found");
    }

    // Pole pro pojmenovn zznamu
    // Ikona
    ImageIcon icon = null;
    try {
        String path = "/material-design-icons/editor/drawable-xhdpi/ic_format_color_text_black_18dp.png";
        icon = new ImageIcon(App.class.getResource(path));
    } catch (NullPointerException ex) {
        System.out.println("Icon not found");
    }
    // Pidn labelu s ikonou a nastavm velikost psma
    label.gridy = 0;
    field.gridy = 0;
    JLabel nameLabel = new JLabel("Nzev: ", icon, JLabel.CENTER);
    nameLabel.setFont(nameLabel.getFont().deriveFont(App.FONT_SIZE * 2 / 3));
    panel.add(nameLabel, label);
    // Pole pro jmno
    final JTextField name = new JTextField();
    name.setMaximumSize(new Dimension(Integer.MAX_VALUE, 50));
    name.setFont(name.getFont().deriveFont(App.FONT_SIZE * 2 / 3));
    panel.add(name, field);

    // Pole pro zadn sdlenho hesla
    // Ikona
    icon = null;
    try {
        String path = "/material-design-icons/hardware/drawable-xhdpi/ic_security_black_18dp.png";
        icon = new ImageIcon(App.class.getResource(path));
    } catch (NullPointerException ex) {
        System.out.println("Icon not found");
    }
    // Pidn labelu s ikonou
    label.gridy = 1;
    field.gridy = 1;
    JLabel secretLabel = new JLabel("Heslo: ", icon, JLabel.CENTER);
    secretLabel.setFont(secretLabel.getFont().deriveFont(App.FONT_SIZE * 2 / 3));
    panel.add(secretLabel, label);
    // Pole pro heslo
    final JTextField secret = new JTextField();
    secret.setMaximumSize(new Dimension(Integer.MAX_VALUE, 50));
    secret.setFont(secret.getFont().deriveFont(App.FONT_SIZE * 2 / 3));
    panel.add(secret, field);

    this.setVisible(true);

    // Akce pro odesln formule
    ActionListener submit = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            submit(prop, name, secret, false);
        }
    };

    // Pi stisku klvesy Enter odele formul
    name.addActionListener(submit);
    secret.addActionListener(submit);
    // Pi zmn pole pro heslo se vstup okamit zformtuje
    final Runnable sanitizer = new Runnable() {
        @Override
        public void run() {
            sanitize(secret);

        }
    };
    secret.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            SwingUtilities.invokeLater(sanitizer);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });

    // Pi zaven okna odele formul
    this.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(WindowEvent e) {
            // Ignorovat

        }

        @Override
        public void windowIconified(WindowEvent e) {
            // Ignorovat

        }

        @Override
        public void windowDeiconified(WindowEvent e) {
            // Ignorovat

        }

        @Override
        public void windowDeactivated(WindowEvent e) {
            // Ignorovat

        }

        @Override
        public void windowClosing(WindowEvent e) {
            // Odeslat
            submit(prop, name, secret, true);

        }

        @Override
        public void windowClosed(WindowEvent e) {
            // Ignorovat

        }

        @Override
        public void windowActivated(WindowEvent e) {
            // Ignorovat

        }
    });
}

From source file:edu.ku.brc.af.ui.PasswordStrengthUI.java

/**
 * Hooks up a Password field to the Strength UI
 * @param pwdTF the password text field to be be hooked up to this
 * @param btn optional button that will be enabled when the PasswordText is not empty
 *//*from   w  w w  . j a  va2 s  .  c  om*/
public void setPasswordField(final JTextField pwdTF, final JButton btn) {
    DocumentListener listener = new DocumentAdaptor() {
        @Override
        protected void changed(DocumentEvent e) {
            String txt = ((JTextField) pwdTF).getText();

            if (StringUtils.isEmpty(txt)) {
                initialSet = true;
                doPainting = false;
                for (JCheckBox cbx : cbxs) {
                    cbx.setSelected(false);
                }

            } else if (initialSet) {
                initialSet = false;
            } else {
                doPainting = true;
            }

            if (btn != null) {
                btn.setEnabled(!txt.isEmpty());
            }

            if (doPainting) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        checkStrength(pwdTF.getText()); // ignore return boolean
                        colorPanel.repaint();
                    }
                });
            }
        }
    };

    pwdTF.getDocument().addDocumentListener(listener);
}