Example usage for javax.swing.event ChangeEvent ChangeEvent

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

Introduction

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

Prototype

public ChangeEvent(Object source) 

Source Link

Document

Constructs a ChangeEvent object.

Usage

From source file:edu.ku.brc.specify.plugins.CollectionRelOneToManyPlugin.java

/**
 * /*from  ww w. j  a  va 2 s .  c om*/
 */
private void removeCollectionObject() {
    int rowInx = table.getSelectedRow();
    if (rowInx > -1) {
        CollectionRelationship colRel = colObjs.get(rowInx);
        if (colRel != null) {
            CollectionRelPlugin.removeFromCollectionRel(currentColObj.getLeftSideRels(), colRel);
            if (colRel.getId() != null) {
                colRel.setLeftSide(null);
                colRel.setRightSide(null);
                fvo.getMVParent().getTopLevel().addDeletedItem(colRel);
            }
            colObjs.remove(rowInx);
            model.fireTableDataChanged();
            notifyChangeListeners(new ChangeEvent(CollectionRelOneToManyPlugin.this));
        }
    }
}

From source file:Converter.java

protected void fireStateChanged() {
    Object[] listeners = listenerList.getListenerList();
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == ChangeListener.class) {
            if (changeEvent == null) {
                changeEvent = new ChangeEvent(this);
            }/*w w w .j  a  va 2  s  .c o m*/
            ((ChangeListener) listeners[i + 1]).stateChanged(changeEvent);
        }
    }
}

From source file:edu.ku.brc.specify.plugins.HostTaxonPlugin.java

/**
 * 
 */
protected void itemSelected() {
    notifyChangeListeners(new ChangeEvent(this));
}

From source file:net.sf.jabref.external.DroppedFileHandler.java

private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileType fileType, BibEntry entry,
        BibDatabase database) {//w  ww.j a v  a 2  s . co m

    String dialogTitle = Localization.lang("Link to file %0", linkFileName);
    List<String> dirs = panel.getBibDatabaseContext().getFileDirectory();
    int found = -1;
    for (int i = 0; i < dirs.size(); i++) {
        if (new File(dirs.get(i)).exists()) {
            found = i;
            break;
        }
    }
    if (found < 0) {
        destDirLabel.setText(Localization.lang("File directory is not set or does not exist!"));
        copyRadioButton.setEnabled(false);
        moveRadioButton.setEnabled(false);
        renameToTextBox.setEnabled(false);
        renameCheckBox.setEnabled(false);
        linkInPlace.setSelected(true);
    } else {
        destDirLabel.setText(Localization.lang("File directory is '%0':", dirs.get(found)));
        copyRadioButton.setEnabled(true);
        moveRadioButton.setEnabled(true);
        renameToTextBox.setEnabled(true);
        renameCheckBox.setEnabled(true);
    }

    ChangeListener cl = arg0 -> {
        renameCheckBox.setEnabled(!linkInPlace.isSelected());
        renameToTextBox.setEnabled(!linkInPlace.isSelected());
    };

    linkInPlace.setText(Localization.lang("Leave file in its current directory"));
    copyRadioButton.setText(Localization.lang("Copy file to file directory"));
    moveRadioButton.setText(Localization.lang("Move file to file directory"));
    renameCheckBox.setText(Localization.lang("Rename file to").concat(": "));

    // Determine which name to suggest:
    String targetName = FileUtil.createFileNameFromPattern(database, entry, Globals.journalAbbreviationLoader,
            Globals.prefs);

    renameToTextBox.setText(targetName.concat(".").concat(fileType.getExtension()));

    linkInPlace.setSelected(frame.prefs().getBoolean(DroppedFileHandler.DFH_LEAVE));
    copyRadioButton.setSelected(frame.prefs().getBoolean(DroppedFileHandler.DFH_COPY));
    moveRadioButton.setSelected(frame.prefs().getBoolean(DroppedFileHandler.DFH_MOVE));
    renameCheckBox.setSelected(frame.prefs().getBoolean(DroppedFileHandler.DFH_RENAME));

    linkInPlace.addChangeListener(cl);
    cl.stateChanged(new ChangeEvent(linkInPlace));

    try {
        Object[] messages = { Localization.lang("How would you like to link to '%0'?", linkFileName),
                optionsPanel };
        int reply = JOptionPane.showConfirmDialog(frame, messages, dialogTitle, JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE);
        if (reply == JOptionPane.OK_OPTION) {
            // store user's choice
            frame.prefs().putBoolean(DroppedFileHandler.DFH_LEAVE, linkInPlace.isSelected());
            frame.prefs().putBoolean(DroppedFileHandler.DFH_COPY, copyRadioButton.isSelected());
            frame.prefs().putBoolean(DroppedFileHandler.DFH_MOVE, moveRadioButton.isSelected());
            frame.prefs().putBoolean(DroppedFileHandler.DFH_RENAME, renameCheckBox.isSelected());
            return true;
        } else {
            return false;
        }
    } finally {
        linkInPlace.removeChangeListener(cl);
    }
}

From source file:edu.ku.brc.specify.ui.CollectingEventDataObjFmt.java

@Override
public JPanel getCustomEditor(final ChangeListener l) {
    this.changeListener = l;
    this.textField = UIHelper.createTextField();

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p"));
    pb.add(textField, cc.xy(1, 1));//from  w ww . j  a  v a  2  s . co  m

    textField.setText(formatStr);

    textField.getDocument().addDocumentListener(new DocumentAdaptor() {
        @Override
        protected void changed(DocumentEvent e) {
            changeListener.stateChanged(new ChangeEvent(this));
        }
    });
    return pb.getPanel();
}

From source file:edu.ku.brc.ui.ImageDisplay.java

/**
* @param doRepaint//w  ww.  j  av  a  2s  . c  om
* @param notifyChangeListeners
*/
private void notifyOnUIThread(final boolean doRepaint, final boolean notifyChangeListeners) {
    if (!stopLoading) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                if (doRepaint) {
                    ImageDisplay.this.repaint();
                }

                if (notifyChangeListeners && changeListener != null) {
                    changeListener.stateChanged(new ChangeEvent(this));
                }

            }
        });
    }
}

From source file:com.aw.swing.mvp.grid.GridProvider.java

public void removeEditor() {
    JTable jTable = bndSJTable.getJTable();
    if (jTable.isEditing()) {
        jTable.editingStopped(new ChangeEvent(jTable));
    }//  w w w  .j a v  a 2  s .  c o m
    if (hasFixedColumns()) {
        JTable fixedTable = bndSJTable.getFixedColumnTableMgr().getFixedTable();
        if (fixedTable != null && fixedTable.isEditing()) {
            fixedTable.editingStopped(new ChangeEvent(fixedTable));
        }
    }
}

From source file:edu.ku.brc.af.ui.forms.validation.ValFormattedTextField.java

/**
 * Creates the various UI Components for the formatter.
 *//*ww w.  ja v  a  2s  . c om*/
protected void createUI() {
    CellConstraints cc = new CellConstraints();

    if (isViewOnly
            || (formatter != null && !formatter.isUserInputNeeded() && fields != null && fields.size() == 1)) {
        viewtextField = new JTextField();
        setControlSize(viewtextField);

        // Remove by rods 12/5/08 this messes thihngs up
        // values don't get inserted correctly, shouldn't be needed anyway

        //JFormattedDoc document = new JFormattedDoc(viewtextField, formatter, formatter.getFields().get(0));
        //viewtextField.setDocument(document);
        //document.addDocumentListener(this);
        //documents.add(document);

        ViewFactory.changeTextFieldUIForDisplay(viewtextField, false);
        PanelBuilder builder = new PanelBuilder(new FormLayout("1px,f:p:g,1px", "1px,f:p:g,1px"), this);
        builder.add(viewtextField, cc.xy(2, 2));
        bgColor = viewtextField.getBackground();

    } else {
        JTextField txt = new JTextField();

        Font txtFont = txt.getFont();

        Font font = new Font("Courier", Font.PLAIN, txtFont.getSize());

        BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = bi.createGraphics();
        g.setFont(font);
        FontMetrics fm = g.getFontMetrics(font);
        g.dispose();

        Insets ins = txt.getBorder().getBorderInsets(txt);
        int baseWidth = ins.left + ins.right;

        bgColor = txt.getBackground();

        StringBuilder sb = new StringBuilder("1px");
        for (UIFieldFormatterField f : fields) {
            sb.append(",");
            if (f.getType() == FieldType.separator || f.getType() == FieldType.constant) {
                sb.append('p');
            } else {
                sb.append(((fm.getMaxAdvance() * f.getSize()) + baseWidth) + "px");
            }
        }
        sb.append(",1px");
        PanelBuilder builder = new PanelBuilder(new FormLayout(sb.toString(), "1px,P:G,1px"), this);

        comps = new JComponent[fields.size()];
        int inx = 0;
        for (UIFieldFormatterField f : fields) {
            JComponent comp = null;
            JComponent tfToAdd = null;

            if (f.getType() == FieldType.separator || f.getType() == FieldType.constant) {
                comp = createLabel(f.getValue());
                if (f.getType() == FieldType.constant) {
                    comp.setBackground(Color.WHITE);
                    comp.setOpaque(true);
                }
                tfToAdd = comp;

            } else {
                JTextField tf = new BGTextField(f.getSize(), isViewOnly ? "" : f.getValue());
                tfToAdd = tf;

                if (inx == 0) {
                    tf.addKeyListener(new KeyAdapter() {
                        @Override
                        public void keyPressed(KeyEvent e) {
                            checkForPaste(e);
                        }
                    });
                }

                JFormattedDoc document = new JFormattedDoc(tf, formatter, f);
                tf.setDocument(document);
                document.addDocumentListener(new DocumentAdaptor() {
                    @Override
                    protected void changed(DocumentEvent e) {
                        isChanged = true;
                        if (!shouldIgnoreNotifyDoc) {
                            String fldStr = getText();
                            int len = StringUtils.isNotEmpty(fldStr) ? fldStr.length() : 0;
                            if (formatter != null && len > 0 && formatter.isLengthOK(len)) {
                                setState(formatter.isValid(fldStr) ? UIValidatable.ErrorType.Valid
                                        : UIValidatable.ErrorType.Error);
                                repaint();
                            }

                            //validateState();
                            if (changeListener != null) {
                                changeListener.stateChanged(new ChangeEvent(this));
                            }

                            if (documentListeners != null) {
                                for (DocumentListener dl : documentListeners) {
                                    dl.changedUpdate(null);
                                }
                            }
                        }
                        currCachedValue = null;
                    }
                });
                documents.add(document);

                addFocusAdapter(tf);

                comp = tf;
                comp.setFont(font);

                if (f.isIncrementer()) {
                    editTF = tf;
                    cardLayout = new CardLayout();
                    cardPanel = new JPanel(cardLayout);
                    cardPanel.add("edit", tf);

                    viewTF = new BGTextField(f.getSize(), isViewOnly ? "" : f.getValue());
                    viewTF.setDocument(document);
                    cardPanel.add("view", viewTF);

                    cardLayout.show(cardPanel, "view");
                    comp = cardPanel;
                    tfToAdd = cardPanel;
                }
            }

            setControlSize(tfToAdd);
            builder.add(comp, cc.xy(inx + 2, 2));
            comps[inx] = tfToAdd;
            inx++;
        }
    }
}

From source file:org.jdal.swing.PageableTable.java

/**
 * Notify ChangeListeners that state change
 *//*from w  w w.  j  av  a 2 s  .c o m*/
private void fireChangeEvent() {
    ChangeEvent e = new ChangeEvent(this);

    for (ChangeListener l : changeListeners)
        l.stateChanged(e);
}

From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java

private void fireChangeEvent() {
    this.eventSupport.fireEvent(new ChangeEvent(this));
}