Example usage for javax.swing.event DocumentEvent getDocument

List of usage examples for javax.swing.event DocumentEvent getDocument

Introduction

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

Prototype

public Document getDocument();

Source Link

Document

Gets the document that sourced the change event.

Usage

From source file:com.kenai.redminenb.repository.RedmineRepositoryController.java

private void validateErrorOff(DocumentEvent e) {
    if (e.getDocument() == panel.accessKeyTextField.getDocument()
            || e.getDocument() == panel.urlTextField.getDocument()
            || e.getDocument() == panel.userField.getDocument()
            || e.getDocument() == panel.pwdField.getDocument()) {
        connectError = false;// w w w . ja v a  2  s .co m
        panel.projectComboBox.setModel(new ListComboBoxModel<Project>());
        panel.projectComboBox.setEnabled(false);
    }
}

From source file:net.sf.maltcms.chromaui.project.spi.wizard.DBProjectVisualPanel1.java

/**
 * Handles changes in the Project name and project directory,
 *//*  ww  w .  j  a va2s  .co m*/
private void updateTexts(DocumentEvent e) {

    Document doc = e.getDocument();

    if (doc == projectNameTextField.getDocument() || doc == projectLocationTextField.getDocument()) {
        // Change in the project name

        String projectName = projectNameTextField.getText();
        String projectFolder = projectLocationTextField.getText();

        //if (projectFolder.trim().length() == 0 || projectFolder.equals(oldName)) {
        createdFolderTextField.setText(projectFolder + File.separatorChar + projectName);
        //}
        String otxt = outputFolderTextField.getText();
        //            if (.isEmpty()) {
        File outputDir = new File(new File(projectFolder, projectName), "output");
        outputFolderTextField.setText(FileUtil.normalizeFile(outputDir).getAbsolutePath());
        //            }

    }
    //        if (panel != null) {
    //            panel.fireChangeEvent(); // Notify that the panel changed
    //        }
}

From source file:com.mirth.connect.client.ui.codetemplate.BasicCodeTemplatePropertiesPanel.java

private void initComponents() {
    containerPanel = new JPanel();
    containerPanel.setBackground(UIConstants.BACKGROUND_COLOR);

    templateCodeLabel = new JLabel("Code:");
    templateCodeTextArea = new MirthRTextScrollPane(ContextType.GLOBAL_DEPLOY);
    templateCodeTextArea.getDocument().addDocumentListener(codeChangeListener);
    templateCodeTextArea.getDocument().addDocumentListener(new DocumentListener() {
        @Override/*  w w  w  .j a  va  2s  .c o m*/
        public void removeUpdate(DocumentEvent evt) {
            codeChanged(evt);
        }

        @Override
        public void insertUpdate(DocumentEvent evt) {
            codeChanged(evt);
        }

        @Override
        public void changedUpdate(DocumentEvent evt) {
            codeChanged(evt);
        }

        private void codeChanged(DocumentEvent evt) {
            try {
                if (evt.getDocument().getLength() >= 3
                        && StringUtils.equals(evt.getDocument().getText(0, 3), "/**")) {
                    templateAutoGenerateDocumentationButton.setText("Update JSDoc");
                } else {
                    templateAutoGenerateDocumentationButton.setText("Generate JSDoc");
                }
            } catch (BadLocationException e) {
            }
        }
    });

    templateAutoGenerateDocumentationButton = new JButton("Update JSDoc");
    templateAutoGenerateDocumentationButton.setToolTipText(
            "<html>Generates/updates a JSDoc at the beginning of your<br/>code, with parameter/return annotations as needed.</html>");
    templateAutoGenerateDocumentationButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            String currentText = templateCodeTextArea.getText();
            String newText = CodeTemplateUtil.updateCode(templateCodeTextArea.getText());
            templateCodeTextArea.setText(newText, false);
            if (!currentText.equals(newText)) {
                parent.setSaveEnabled(true);
            }
        }
    });
}

From source file:jeplus.gui.JPanel_TrnsysProjectFiles.java

/**
 * Creates new form JPanel_EPlusProjectFiles with parameters
 *///from   w  w  w  .  j  av a 2s.co m
public JPanel_TrnsysProjectFiles(JEPlusFrameMain frame, JEPlusProject project) {
    initComponents();
    MainGUI = frame;
    Project = project;

    this.txtGroupID.setText(Project.getProjectID());
    this.txtGroupNotes.setText(Project.getProjectNotes());
    txtDCKDir.setText(Project.getDCKDir());
    if (Project.getDCKTemplate() != null) {
        cboTemplateFile.setModel(new DefaultComboBoxModel(Project.getDCKTemplate().split("\\s*;\\s*")));
    } else {
        cboTemplateFile.setModel(new DefaultComboBoxModel(new String[] { "Select files..." }));
    }
    txtOutputFileNames.setText(Project.getOutputFileNames());
    txtRviDir.setText(Project.getRVIDir());
    if (Project.getRVIFile() != null) {
        cboRviFile.setModel(new DefaultComboBoxModel(new String[] { Project.getRVIFile() }));
    } else {
        cboRviFile.setModel(new DefaultComboBoxModel(new String[] { "Select a file..." }));
    }

    // Set listeners to text fields
    DL = new DocumentListener() {
        Document DocProjID = txtGroupID.getDocument();
        Document DocProjNotes = txtGroupNotes.getDocument();
        Document DocDCKDir = txtDCKDir.getDocument();
        Document DocOutputFiles = txtOutputFileNames.getDocument();
        Document DocRviDir = txtRviDir.getDocument();

        @Override
        public void insertUpdate(DocumentEvent e) {
            Document src = e.getDocument();
            if (src == DocProjID) {
                Project.setProjectID(txtGroupID.getText());
            } else if (src == DocProjNotes) {
                Project.setProjectNotes(txtGroupNotes.getText());
            } else if (src == DocDCKDir) {
                Project.setDCKDir(txtDCKDir.getText());
            } else if (src == DocOutputFiles) {
                Project.setOutputFileNames(txtOutputFileNames.getText());
            } else if (src == DocRviDir) {
                Project.setRVIDir(txtRviDir.getText());
            }
        }

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

        @Override
        public void changedUpdate(DocumentEvent e) {
            // not applicable
        }
    };
    txtGroupID.getDocument().addDocumentListener(DL);
    txtGroupNotes.getDocument().addDocumentListener(DL);
    txtDCKDir.getDocument().addDocumentListener(DL);
    txtOutputFileNames.getDocument().addDocumentListener(DL);
    txtRviDir.getDocument().addDocumentListener(DL);
}

From source file:net.sf.maltcms.chromaui.project.spi.wizard.DBProjectVisualPanel1.java

@Override
public void changedUpdate(DocumentEvent e) {
    updateTexts(e);/*from w w  w  . j a v a2  s.co  m*/
    if (this.projectNameTextField.getDocument() == e.getDocument()) {
        firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
    }
}

From source file:net.sf.maltcms.chromaui.project.spi.wizard.DBProjectVisualPanel1.java

@Override
public void insertUpdate(DocumentEvent e) {
    updateTexts(e);/*from  ww  w.  j a v  a  2 s  . c o  m*/
    if (this.projectNameTextField.getDocument() == e.getDocument()) {
        firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
    }
}

From source file:net.sf.maltcms.chromaui.project.spi.wizard.DBProjectVisualPanel1.java

@Override
public void removeUpdate(DocumentEvent e) {
    updateTexts(e);//from   w ww.jav a  2 s .  c  o  m
    if (this.projectNameTextField.getDocument() == e.getDocument()) {
        firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
    }
}

From source file:ListenerSample.java

public void printInfo(DocumentEvent documentEvent) {
    System.out.println("Offset: " + documentEvent.getOffset());
    System.out.println("Length: " + documentEvent.getLength());
    DocumentEvent.EventType type = documentEvent.getType();
    String typeString = null;//  ww w. ja  va2 s .  com
    if (type.equals(DocumentEvent.EventType.CHANGE)) {
        typeString = "Change";
    } else if (type.equals(DocumentEvent.EventType.INSERT)) {
        typeString = "Insert";
    } else if (type.equals(DocumentEvent.EventType.REMOVE)) {
        typeString = "Remove";
    }
    System.out.println("Type  : " + typeString);
    Document documentSource = documentEvent.getDocument();
    Element rootElement = documentSource.getDefaultRootElement();
    DocumentEvent.ElementChange change = documentEvent.getChange(rootElement);
    System.out.println("Change: " + change);
}

From source file:com.smart.aqimonitor.client.AqiMonitor.java

/**
 * Create the frame.//from www.  ja v  a  2 s . c om
 */
public AqiMonitor() {
    refSelf = this;
    setPreferredSize(new Dimension(640, 480));
    setTitle("\u7A7A\u6C14\u8D28\u91CF\u76D1\u6D4B");
    setIconImage(Toolkit.getDefaultToolkit()
            .getImage(AqiMonitor.class.getResource("/lombok/installer/eclipse/STS.png")));
    setMinimumSize(new Dimension(640, 480));
    setMaximumSize(new Dimension(1024, 768));
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 636, 412);
    contentPane = new JPanel();
    contentPane.setPreferredSize(new Dimension(640, 480));
    contentPane.setMinimumSize(new Dimension(640, 480));
    contentPane.setMaximumSize(new Dimension(1024, 768));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);

    JPanel mainPanel = new JPanel();
    contentPane.add(mainPanel, BorderLayout.CENTER);
    mainPanel.setLayout(new BorderLayout(0, 0));

    JPanel contentPanel = new JPanel();
    mainPanel.add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));

    JScrollPane scrollPane = new JScrollPane();
    scrollPane
            .setViewportBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    contentPanel.add(scrollPane, BorderLayout.CENTER);

    textPane = new AqiTextPane();
    textPane.addInputMethodListener(new InputMethodListener() {

        public void caretPositionChanged(InputMethodEvent event) {

        }

        public void inputMethodTextChanged(InputMethodEvent event) {
            textPane.setCaretPosition(document.getLength() + 1);
        }
    });
    textPane.setEditable(false);
    textPane.setOpaque(false);
    textPane.setForeground(Color.BLACK);
    scrollPane.setViewportView(textPane);
    document = textPane.getStyledDocument();

    document.addDocumentListener(new DocumentListener() {

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

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

        @Override
        public void changedUpdate(DocumentEvent e) {
            if (e.getDocument() == document) {
                textPane.setCaretPosition(document.getLength());
            }
        }
    });

    JPanel buttonPanel = new JPanel();
    contentPane.add(buttonPanel, BorderLayout.SOUTH);
    buttonPanel.setLayout(new BorderLayout(0, 0));

    JLabel lblTipsLabel = new JLabel(
            "Tips\uFF1A\u6587\u4EF6\u4FDD\u5B58\u683C\u5F0Fcsv\u53EF\u7528Excel\u6253\u5F00");
    lblTipsLabel.setForeground(Color.BLUE);
    buttonPanel.add(lblTipsLabel, BorderLayout.WEST);

    JPanel panel = new JPanel();
    buttonPanel.add(panel, BorderLayout.CENTER);
    panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

    JButton btnRetrieve = new JButton("\u624B\u52A8\u83B7\u53D6\u6570\u636E");
    panel.add(btnRetrieve);
    btnRetrieve.setVerticalAlignment(SwingConstants.BOTTOM);

    JButton btnNewButton = new JButton("\u5173\u4E8E");
    btnNewButton.setToolTipText("\u5173\u4E8E");
    btnNewButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JTextArea textArea = new JTextArea(
                    "\n        csv\n\n        smartstudio@foxmail.com");
            textArea.setColumns(35);
            textArea.setRows(6);
            textArea.setLineWrap(true);// 
            textArea.setEditable(false);// 
            textArea.setOpaque(false);
            JOptionPane.showMessageDialog(contentPane, textArea, "", JOptionPane.PLAIN_MESSAGE);
        }
    });

    JButton btnSetting = new JButton("\u8BBE\u7F6E");
    btnSetting.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            Point parentPos = refSelf.getLocation();

            AqiSettingDialog settingDialog = new AqiSettingDialog(refSelf, pm25InDetailJob.getAqiParser());
            settingDialog.setModal(true);
            settingDialog.setLocation(parentPos.x + 100, parentPos.y + 150);
            settingDialog.init();
            settingDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            settingDialog.setVisible(true);
        }
    });

    JButton btnExportDir = new JButton("\u67E5\u770B\u6570\u636E");
    btnExportDir.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {

                String[] cmd = new String[5];

                String filePath = pm25InDetailJob.getAqiParser().getFilePath();
                File file = new File(filePath);
                if (!file.exists()) {
                    FileUtil.makeDir(file);
                }
                if (!file.isDirectory()) {
                    JOptionPane.showMessageDialog(contentPane, "", "",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }

                cmd[0] = "cmd";
                cmd[1] = "/c";
                cmd[2] = "start";
                cmd[3] = " ";
                cmd[4] = pm25InDetailJob.getAqiParser().getFilePath();

                Runtime.getRuntime().exec(cmd);

            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });
    panel.add(btnExportDir);
    panel.add(btnSetting);
    panel.add(btnNewButton);
    btnRetrieve.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (!isRetrieving) {
                isRetrieving = true;
                Thread firstRun = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        pm25InDetailJob.refresh();
                        isRetrieving = false;
                    }
                });

                firstRun.start();
            }
        }
    });

    init();
}

From source file:com.mirth.connect.plugins.mllpmode.MLLPModeSettingsDialog.java

private void changeAbbreviation(DocumentEvent evt) {
    String text = "";

    try {//from www .  ja  v  a  2s. co  m
        text = evt.getDocument().getText(0, evt.getDocument().getLength()).trim();
    } catch (BadLocationException e) {
    }

    if (evt.getDocument().equals(startOfMessageBytesField.getDocument())) {
        startOfMessageAbbreviation = TcpUtil.convertHexToAbbreviation(text);
        actionListener.actionPerformed(new ActionEvent(startOfMessageBytesField, ActionEvent.ACTION_PERFORMED,
                MLLPModeClientProvider.CHANGE_START_BYTES_COMMAND));
    } else if (evt.getDocument().equals(endOfMessageBytesField.getDocument())) {
        endOfMessageAbbreviation = TcpUtil.convertHexToAbbreviation(text);
        actionListener.actionPerformed(new ActionEvent(endOfMessageBytesField, ActionEvent.ACTION_PERFORMED,
                MLLPModeClientProvider.CHANGE_END_BYTES_COMMAND));
    } else if (evt.getDocument().equals(ackBytesField.getDocument())) {
        ackAbbreviation = TcpUtil.convertHexToAbbreviation(text);
    } else {
        nackAbbreviation = TcpUtil.convertHexToAbbreviation(text);
    }

    changeAbbreviation();
}