Example usage for javax.swing.event DocumentListener DocumentListener

List of usage examples for javax.swing.event DocumentListener DocumentListener

Introduction

In this page you can find the example usage for javax.swing.event DocumentListener DocumentListener.

Prototype

DocumentListener

Source Link

Usage

From source file:se.trixon.toolbox.photokml.config.ModuleFoldersPanel.java

private void init() {
    rootNameTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override/*from   w  ww  .ja v a 2 s . c o m*/
        public void changedUpdate(DocumentEvent e) {
            saveOption();
        }

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

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

        private void saveOption() {
            mOptions.setFoldersRootName(rootNameTextField.getText());
        }
    });

    rootDescriptionTextArea.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveOption();
        }

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

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

        private void saveOption() {
            mOptions.setFoldersRootDescription(rootDescriptionTextArea.getText());
        }
    });

    dateFormatTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            previewDateFormat();
        }

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

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

        private void previewDateFormat() {
            String datePreview;

            try {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatTextField.getText());
                datePreview = simpleDateFormat.format(new Date(System.currentTimeMillis()));
                mInvalidDateFormat = false;
            } catch (IllegalArgumentException ex) {
                datePreview = Dict.ERROR.getString();
                mInvalidDateFormat = true;
            }

            String dateLabel = String.format("%s (%s)", Dict.DATE_PATTERN.getString(), datePreview);
            folderByDateRadioButton.setText(dateLabel);
            mOptions.setFoldersDatePattern(dateFormatTextField.getText());
        }
    });

    regexTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveOption();
        }

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

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

        private void saveOption() {
            try {
                mOptions.setFoldersRegex(regexTextField.getText());
            } catch (NumberFormatException e) {
            }
        }
    });

    defaultRegexTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveOption();
        }

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

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

        private void saveOption() {
            mOptions.setFoldersRegexDefault(defaultRegexTextField.getText());
        }
    });

}

From source file:se.trixon.toolbox.photokml.config.ModuleSourcePanel.java

private void init() {
    sourceChooserPanel.setDropMode(FileChooserPanel.DropMode.MULTI);
    sourceChooserPanel.setMode(JFileChooser.FILES_AND_DIRECTORIES);
    sourceChooserPanel.getFileChooser().setMultiSelectionEnabled(true);
    sourceChooserPanel.setButtonListener(this);
    sourceChooserPanel.getTextField().addFocusListener(new FocusAdapter() {
        @Override//from   w  w w . j av a 2s .c o  m
        public void focusLost(java.awt.event.FocusEvent evt) {
            saveSourcePath();
        }
    });

    sourceChooserPanel.getTextField().getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveSourcePath();
        }

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

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

    patternTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            saveOption();
        }

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

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

        private void saveOption() {
            mOptions.setSourcePattern(patternTextField.getText());
        }
    });
}

From source file:se.trixon.toolbox.relocator.RelocatorTopComponent.java

private void init() {
    mHelpId = "se.trixon.toolbox.relocator.about";

    startButton.setIcon(Pict.Actions.ARROW_RIGHT.get(ICON_SIZE));
    startButton.setToolTipText(Dict.START.getString());

    helpButton.setIcon(Pict.Actions.HELP_CONTENTS.get(ICON_SIZE));
    helpButton.setToolTipText(Dict.HELP.getString());

    opComboBox.setModel(new DefaultComboBoxModel(mBundle.getString("operations").split("\\|")));
    dateSourceComboBox.setModel(new DefaultComboBoxModel(mBundle.getString("dateSource").split("\\|")));
    followLinksCheckBox.setEnabled(!SystemUtils.IS_OS_WINDOWS);

    sourceChooserPanel.setDropMode(FileChooserPanel.DropMode.MULTI);
    sourceChooserPanel.setHeader(Dict.SOURCE.getString());
    sourceChooserPanel.setMode(JFileChooser.FILES_AND_DIRECTORIES);
    sourceChooserPanel.getFileChooser().setMultiSelectionEnabled(true);
    sourceChooserPanel.setButtonListener(this);

    previewDateFormat();/*from  w  ww .  j ava  2 s. c  o  m*/

    dateFormatTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
            previewDateFormat();
        }

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

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

    });

    loadOptions();
}

From source file:sms.Form1Exams.java

/**
 * Creates new form Form1Exams/*from   w w w  .  ja  va  2s. com*/
 */
public Form1Exams() {

    this.table = new JTable(this.model);
    this.sid = new JTextField();
    final TableRowSorter<TableModel> rowSorter = new TableRowSorter(this.table.getModel());
    this.table.setRowSorter(rowSorter);
    sid.getDocument().addDocumentListener(new DocumentListener() {
        public void insertUpdate(DocumentEvent e) {
            String text = Form1Exams.this.sid.getText();
            if (text.trim().length() == 0) {
                rowSorter.setRowFilter(null);
            } else {
                rowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + text, new int[0]));
            }
        }

        public void removeUpdate(DocumentEvent e) {
            String text = Form1Exams.this.sid.getText();
            if (text.trim().length() == 0) {
                rowSorter.setRowFilter(null);
            } else {
                rowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + text, new int[0]));
            }
        }

        public void changedUpdate(DocumentEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    });

    initComponents();
    setSubjectsModel();
    setExamsModel();
    actionPerformed();
    // findUsers();
    //action and statechanged listner for term radio buttons 

    //title();
}

From source file:sms.ViewResults.java

/**
 * Creates new form ViewResults/*from w w w .  ja va2  s  .  c  om*/
 */
public ViewResults() {

    this.table = new JTable(model);
    this.sid = new JTextField();
    final TableRowSorter<TableModel> rowSorter = new TableRowSorter<>(table.getModel());
    table.setRowSorter(rowSorter);
    sid.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            String text = sid.getText();

            if (text.trim().length() == 0) {
                rowSorter.setRowFilter(null);
            } else {
                rowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
            }
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            String text = sid.getText();

            if (text.trim().length() == 0) {
                rowSorter.setRowFilter(null);
            } else {
                rowSorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
            }
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    initComponents();
    setExamsModel();
    setSubjectsModel();
    setStreamsModel();
    // findUsers();
    // sorter(2);
}

From source file:uk.chromis.pos.imports.JPanelCSVImport.java

/**
 * Constructs a new JPanelCSVImport object
 *
 * @param oApp AppView//from  ww w  .  j av  a 2 s.  c o  m
 */
public JPanelCSVImport(AppView app) {

    m_App = app;
    m_props = m_App.getProperties();

    initComponents();

    m_dlSales = (DataLogicSales) m_App.getBean("uk.chromis.pos.forms.DataLogicSales");
    m_dlSystem = (DataLogicSystem) m_App.getBean("uk.chromis.pos.forms.DataLogicSystem");

    spr = new SaveProvider(m_dlSales.getProductCatUpdate(), m_dlSales.getProductCatInsert(),
            m_dlSales.getProductCatDelete());

    // Save Last file for later use.
    last_folder = AppConfig.getInstance().getProperty("CSV.last_folder");
    // config_file = m_props.getConfigFile();

    documentListener = new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent documentEvent) {
            jHeaderRead.setEnabled(true);
        }

        @Override
        public void insertUpdate(DocumentEvent documentEvent) {
            if (!"".equals(jFileName.getText().trim())) {
                jHeaderRead.setEnabled(true);
            }
        }

        @Override
        public void removeUpdate(DocumentEvent documentEvent) {
            if (jFileName.getText().trim().equals("")) {
                jHeaderRead.setEnabled(false);
            }
        }
    };
    jFileName.getDocument().addDocumentListener(documentListener);

}

From source file:view.MainWindow.java

/**
 * Creates new form MainWindow/*  ww  w  .j  ava  2 s .  c o m*/
 */
public MainWindow() {
    initComponents();

    updateText();

    List<Image> icons = new ArrayList<>();
    icons.add(new ImageIcon(getClass().getResource("/image/aCCinaPDF_logo_icon32.png")).getImage());
    this.setIconImages(icons);

    setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
    workspacePanel.setParent((MainWindow) this);
    populateDriveComboBox();

    dmtn = new DefaultMutableTreeNode("0 " + Bundle.getBundle().getString("tn.documentsLoaded"));
    TreeModel tm = new DefaultTreeModel(dmtn);
    jtOpenedDocuments.setModel(tm);
    setupTreePopups();
    setupDropListener();

    DefaultTreeCellRenderer renderer1 = (DefaultTreeCellRenderer) jtOpenedDocuments.getCellRenderer();
    Icon closedIcon = new ImageIcon(MainWindow.class.getResource("/image/pdf_ico.jpg"));
    renderer1.setLeafIcon(closedIcon);
    DefaultTreeCellRenderer renderer2 = (DefaultTreeCellRenderer) jtExplorer.getCellRenderer();
    renderer2.setLeafIcon(closedIcon);
    tfProcurar.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            refreshTree(tfProcurar.getText());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            refreshTree(tfProcurar.getText());
        }

        @Override
        public void changedUpdate(DocumentEvent e) {

        }
    });

    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher((MainWindow) this);
    refreshTree(null);

    ctrl.setPrintMenuItem(menuItemPrint);
}

From source file:volker.streaming.music.gui.FormatPanel.java

private void initComponents() {
    formatLabel = new JLabel("How should your track info be displayed:");
    formatArea = new JTextArea(config.getFormat());
    formatLighter = new DefaultHighlighter();
    // TODO allow configuration of this color
    formatPainter = new DefaultHighlighter.DefaultHighlightPainter(new Color(200, 200, 255));
    formatArea.setHighlighter(formatLighter);
    formatArea.getDocument().addDocumentListener(new DocumentListener() {
        @Override/*w w  w . j  av a2  s .  c o  m*/
        public void removeUpdate(DocumentEvent e) {
            formatUpdated();
        }

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

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

    ImageIcon infoIcon = null;
    try {
        InputStream is = getClass().getResourceAsStream("info.png");
        if (is == null) {
            LOG.error("Couldn't find the info image.");
        } else {
            infoIcon = new ImageIcon(ImageIO.read(is));
            is.close();
        }
    } catch (IOException e1) {
        LOG.error("Couldn't find the info image.", e1);
    }
    if (infoIcon == null) {
        formatInfoButton = new JButton("?");
    } else {
        formatInfoButton = new JButton(infoIcon);
        formatInfoButton.setBorder(BorderFactory.createEmptyBorder());
    }

    formatInfoButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            showFormatHelp();
        }
    });

    templateLabel = new JLabel("Your template:");

    tagLabel = new JLabel("Available tags:");
    tagList = new JList<String>(new AbstractListModel<String>() {
        private static final long serialVersionUID = -8886588605378873151L;

        @Override
        public int getSize() {
            return properTags.size();
        }

        @Override
        public String getElementAt(int index) {
            return properTags.get(index);
        }
    });
    tagScrollPane = new JScrollPane(tagList);

    previewLabel = new JLabel("Preview:");
    previewField = new JTextField();
    previewField.setEditable(false);
    previewField.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
    previewField.setBackground(new Color(255, 255, 150));

    formatUpdated();
    highlightTags();

    nullMessageLabel = new JLabel("Message to display when no song is found:");
    nullMessageField = new JTextField(config.getNoTrackMessage() == null ? "" : config.getNoTrackMessage());
    nullMessageField.getDocument().addDocumentListener(new DocumentListener() {
        public void action() {
            config.setNoTrackMessage(nullMessageField.getText());
        }

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

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

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

    hline = new JSeparator(SwingConstants.HORIZONTAL);
    fileLabel = new JLabel("Location of text file:");
    fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fileField = new JTextField(15);
    if (config.getOutputFile() != null) {
        fileField.setText(config.getOutputFile().getAbsolutePath());
    }
    fileField.getDocument().addDocumentListener(new DocumentListener() {
        public void action() {
            config.setOutputFile(new File(fileField.getText()));
        }

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

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

        @Override
        public void changedUpdate(DocumentEvent e) {
            action();
        }
    });
    fileButton = new JButton("Browse");
    fileButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            browseFile();
        }
    });
}