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:RGBAColourChooser.java

/**
 * Sets the widget's selected colour/*from   w w w.  j  a  v a  2  s.c  om*/
 * 
 * @param color
 *           The new colour
 */
public void setColour(Color color) {
    if (!oldValue.equals(color)) {
        // copy the values
        oldValue = color;

        redSlider.removeChangeListener(this);
        greenSlider.removeChangeListener(this);
        blueSlider.removeChangeListener(this);
        alphaSlider.removeChangeListener(this);

        redSlider.setValue(oldValue.getRed());
        greenSlider.setValue(oldValue.getGreen());
        blueSlider.setValue(oldValue.getBlue());
        alphaSlider.setValue(oldValue.getAlpha());

        redSlider.setToolTipText(String.valueOf(redSlider.getValue()));
        greenSlider.setToolTipText(String.valueOf(greenSlider.getValue()));
        blueSlider.setToolTipText(String.valueOf(blueSlider.getValue()));
        alphaSlider.setToolTipText(String.valueOf(alphaSlider.getValue()));

        redSlider.addChangeListener(this);
        greenSlider.addChangeListener(this);
        blueSlider.addChangeListener(this);
        alphaSlider.addChangeListener(this);

        previewer.repaint();

        ChangeEvent ce = new ChangeEvent(this);
        for (ChangeListener listener : listeners) {
            listener.stateChanged(ce);
        }
    }
}

From source file:com.anrisoftware.prefdialog.miscswing.docks.dockingframes.dock.AbstractEditorDockWindow.java

private void updateFocus(boolean focus) {
    boolean oldValue = this.focus;
    this.focus = focus;
    if (oldValue != visible) {
        changeSupport.fire().stateChanged(new ChangeEvent(this));
    }/*from   ww  w. ja  v  a2  s.  c o  m*/
}

From source file:MainClass.java

protected void fireEditingCanceled() {
    setValue(originalValue);/*  w  w w  .j  a va  2  s.  c  o  m*/
    ChangeEvent ce = new ChangeEvent(this);
    for (int i = listeners.size() - 1; i >= 0; i--) {
        ((CellEditorListener) listeners.elementAt(i)).editingCanceled(ce);
    }
}

From source file:MainClass.java

protected void fireEditingStopped() {
    ChangeEvent ce = new ChangeEvent(this);
    for (int i = listeners.size() - 1; i >= 0; i--) {
        ((CellEditorListener) listeners.elementAt(i)).editingStopped(ce);
    }/*w ww  . j  a v  a2s. c o m*/
}

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

/**
 * Creates the UI.//from  w  w w.j av  a 2  s .com
 */
protected void createUI() {
    DocumentAdaptor docListener = null;
    if (!isDisplayOnly) {
        docListener = new DocumentAdaptor() {
            @Override
            protected void changed(DocumentEvent e) {
                super.changed(e);

                if (!ignoreDocChanges) {
                    isChanged = true;
                    isDateChanged = true;
                    if (changeListener != null) {
                        changeListener.stateChanged(new ChangeEvent(PartialDateUI.this));
                    }
                }
            }
        };
    }

    List<UIFieldFormatterIFace> partialDateList = UIFieldFormatterMgr.getInstance().getDateFormatterList(true);
    for (UIFieldFormatterIFace uiff : partialDateList) {
        if (uiff.getName().equals("PartialDateMonth")) {
            ValFormattedTextField tf = new ValFormattedTextField(uiff, isDisplayOnly, !isDisplayOnly);
            tf.setRequired(isRequired);

            if (docListener != null)
                tf.addDocumentListener(docListener);
            uivs[1] = tf;
            textFields[1] = tf.getTextField();
            if (isDisplayOnly) {
                ViewFactory.changeTextFieldUIForDisplay(textFields[1], false);
            } else {
                setupPopupMenu(tf);
            }

        } else if (uiff.getName().equals("PartialDateYear")) {
            ValFormattedTextField tf = new ValFormattedTextField(uiff, isDisplayOnly, !isDisplayOnly);
            tf.setRequired(isRequired);

            if (docListener != null)
                tf.addDocumentListener(docListener);
            uivs[2] = tf;
            textFields[2] = tf.getTextField();
            if (isDisplayOnly) {
                ViewFactory.changeTextFieldUIForDisplay(textFields[2], false);
            } else {
                setupPopupMenu(tf);
            }
        }
    }

    List<UIFieldFormatterIFace> dateList = UIFieldFormatterMgr.getInstance().getDateFormatterList(false);
    for (UIFieldFormatterIFace uiff : dateList) {
        if (uiff.getName().equals("Date")) {
            ValFormattedTextFieldSingle tf = new ValFormattedTextFieldSingle(uiff, isDisplayOnly, false);
            tf.setRequired(isRequired);

            if (docListener != null)
                tf.addDocumentListener(docListener);
            uivs[0] = tf;
            textFields[0] = tf;
            if (isDisplayOnly) {
                ViewFactory.changeTextFieldUIForDisplay(textFields[0], false);
            } else {
                ViewFactory.addTextFieldPopup(this, tf, true);
            }
        }
    }

    cardPanel = new JPanel(cardLayout);

    String[] formatKeys = { "PARTIAL_DATE_FULL", "PARTIAL_DATE_MONTH", "PARTIAL_DATE_YEAR" };
    String[] labels = new String[formatKeys.length];
    for (int i = 0; i < formatKeys.length; i++) {
        labels[i] = UIRegistry.getResourceString(formatKeys[i]);
        cardPanel.add(labels[i], (JComponent) uivs[i]);
    }

    formatSelector = createComboBox(labels);
    formatSelector.setSelectedIndex(0);

    JComponent typDisplayComp = null;
    if (!isDisplayOnly) {
        comboBoxAL = new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                JComboBox cbx = (JComboBox) ae.getSource();
                Object dataValue = ((GetSetValueIFace) currentUIV).getValue();//isDateChanged ? ((GetSetValueIFace)currentUIV).getValue() : Calendar.getInstance();
                currentUIV = uivs[cbx.getSelectedIndex()];

                ignoreDocChanges = true;
                ((GetSetValueIFace) currentUIV).setValue(dataValue, null);
                ignoreDocChanges = false;

                cardLayout.show(cardPanel, formatSelector.getSelectedItem().toString());

                isChanged = true;
                if (changeListener != null) {
                    changeListener.stateChanged(new ChangeEvent(PartialDateUI.this));
                }
            }
        };
        typDisplayComp = formatSelector;
        formatSelector.addActionListener(comboBoxAL);
    }

    PanelBuilder builder = new PanelBuilder(
            new FormLayout((typDisplayComp != null ? "p, 2px, f:p:g" : "f:p:g"), "p"), this);
    CellConstraints cc = new CellConstraints();
    if (typDisplayComp != null) {
        builder.add(typDisplayComp, cc.xy(1, 1));
        builder.add(cardPanel, cc.xy(3, 1));
    } else {
        builder.add(cardPanel, cc.xy(1, 1));
    }
}

From source file:EmailTree.java

protected void fireEditingStopped() {
    if (listeners.size() > 0) {
        ChangeEvent ce = new ChangeEvent(this);
        for (int i = listeners.size() - 1; i >= 0; i--) {
            ((CellEditorListener) listeners.elementAt(i)).editingStopped(ce);
        }/* www  .  j  a  v a  2  s. co  m*/
    }
}

From source file:edu.ku.brc.af.ui.db.PropertiesPickListAdapter.java

public PickListItemIFace addItem(final String title, final String value) {
    // this should never happen!
    if (pickList.getReadOnly()) {
        throw new RuntimeException("Trying to add an item to a readonly picklist [" + pickList.getName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
    }//from  www. j  a v a2 s. c om

    int sizeLimit = 50; // arbitrary size could be a pref (XXX PREF)
    Integer sizeLimitInt = pickList.getSizeLimit();
    if (sizeLimitInt != null) {
        sizeLimit = sizeLimitInt.intValue();
    }

    searchablePLI.setTitle(title);
    int index = Collections.binarySearch(items, searchablePLI);
    if (index < 0) {
        // find oldest item and remove it
        if (items.size() >= sizeLimit) {
            PickListItemIFace oldest = null;
            for (PickListItemIFace pli : items) {
                if (oldest == null
                        || pli.getTimestampCreated().getTime() < oldest.getTimestampCreated().getTime()) {
                    oldest = pli;
                }
            }
            items.remove(oldest);
            pickList.removeItem(oldest);
        }

        PickListItemIFace item = PickListDBAdapterFactory.getInstance().createPickListItem();
        item.setTitle(title);
        item.setValue(value);
        items.add(item);

        if (pickList != null) {
            pickList.addItem(item);
            item.setPickList(pickList);
            pickList.reorder();
        }
        Collections.sort(items);

        final int newItemInx = items.indexOf(item);

        if (doAutoSaveOnAdd) {
            save();
        }

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                for (ChangeListener cl : changeListeners) {
                    cl.stateChanged(new ChangeEvent(PropertiesPickListAdapter.this));
                }
                PropertiesPickListAdapter.this.comboBox.getComboBox().setSelectedIndex(newItemInx);
            }
        });

        return item;

    }
    // else
    return items.elementAt(index);
}

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

@Override
public void initialize(final Properties propertiesArg, final boolean isViewModeArg) {
    super.initialize(propertiesArg, isViewModeArg);

    String relName = propertiesArg.getProperty("relname");
    String rightSide = propertiesArg.getProperty("rightside");
    isRightOverride = StringUtils.isNotEmpty(rightSide) && rightSide.equalsIgnoreCase("true");

    if (StringUtils.isNotEmpty(relName)) {
        DataProviderSessionIFace tmpSession = null;
        try {//from   w w  w.jav a  2s.  co  m
            tmpSession = DataProviderFactory.getInstance().createSession();
            colRelType = tmpSession.getData(CollectionRelType.class, "name", relName,
                    DataProviderSessionIFace.CompareType.Equals);
            if (colRelType != null) {
                leftSideCol = colRelType.getLeftSideCollection();
                rightSideCol = colRelType.getRightSideCollection();
                //colRelType.getRelationships().size();
                rightSideCol.getCollectionId();
                leftSideCol.getCollectionId();

                Collection currCollection = AppContextMgr.getInstance().getClassObject(Collection.class);
                isLeftSide = currCollection.getId().equals(leftSideCol.getId());
                if (isLeftSide && isRightOverride) {
                    isLeftSide = false;
                }

                catNumFormatter = CollectionRelOneToManyPlugin.getCatNumFormatter(leftSideCol, rightSideCol);

            } else {
                DBTableInfo ti = DBTableIdMgr.getInstance()
                        .getInfoById(CollectionRelationship.getClassTableId());
                UIRegistry.showError(
                        String.format("The %s name '%s' doesn't exist (defined in the form for the plugin).",
                                ti.getTitle(), relName));

            }
        } catch (Exception ex) {
            ex.printStackTrace();

        } finally {
            if (tmpSession != null) {
                tmpSession.close();
            }
        }

        DBTableInfo coTI = DBTableIdMgr.getInstance().getInfoById(CollectionObject.getClassTableId());
        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(new FormLayout("MAX(p;40px)", "p"), this);

        if (isViewModeArg || !isLeftSide) {
            textWithInfo = new TextFieldWithInfo(coTI.getClassName(), CATNUM_NAME, // id name
                    CATNUM_NAME, // key name
                    null, // format
                    CATNUM_NAMECAP, // uiFieldFormatterName
                    COLOBJ_NAME, // dataObjFormatterName
                    COLOBJ_NAME, // displayInfoDialogName
                    ""); // objTitle  
            pb.add(textWithInfo, cc.xy(1, 1));
            ViewFactory.changeTextFieldUIForDisplay(textWithInfo.getTextField(), false);

        } else {
            int btnOpts = ValComboBoxFromQuery.CREATE_VIEW_BTN | ValComboBoxFromQuery.CREATE_SEARCH_BTN;
            cbx = new ValComboBoxFromQuery(coTI, CATNUM_NAME, CATNUM_NAME, CATNUM_NAME, null, CATNUM_NAMECAP,
                    COLOBJ_NAME, "", null, // helpContext
                    btnOpts);
            pb.add(cbx, cc.xy(1, 1));

            cbx.setEnabled(colRelType != null);

            adjustSQLTemplate();

            cbx.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    itemSelected();
                    notifyChangeListeners(new ChangeEvent(CollectionRelPlugin.this));
                }
            });

            cbx.registerQueryBuilder(createSearchQueryBuilder(isLeftSide, leftSideCol, rightSideCol));
        }

    } else {
        // no Relationship name
    }
}

From source file:fungus.JungGraphObserver.java

public boolean execute() {
    if (CDState.getCycle() % period != 0)
        return false;

    MycoCast mycocast = (MycoCast) Network.get(0).getProtocol(mycocastPid);

    int bio = mycocast.countBiomass();
    int ext = mycocast.countExtending();
    int bra = mycocast.countBranching();
    int imm = mycocast.countImmobile();

    // Update vertices
    Set<MycoNode> activeNodes = new HashSet<MycoNode>();
    for (int i = 0; i < Network.size(); i++) {
        MycoNode n = (MycoNode) Network.get(i);
        activeNodes.add(n);/* ww  w . java 2  s . c  om*/
        HyphaData data = n.getHyphaData();
        //if (data.isBiomass()) { continue; }
        if (graph.containsVertex(n)) {
            graph.removeVertex(n);
        }
        if (!graph.containsVertex(n)) {
            graph.addVertex(n);
        }
    }
    Set<MycoNode> jungNodes = new HashSet<MycoNode>(graph.getVertices());
    jungNodes.removeAll(activeNodes);

    for (MycoNode n : jungNodes) {
        graph.removeVertex(n);
    }

    // Update edges
    for (int i = 0; i < Network.size(); i++) {
        MycoNode n = (MycoNode) Network.get(i);
        HyphaData data = n.getHyphaData();
        HyphaLink link = n.getHyphaLink();

        synchronized (graph) {

            // We now add in all links and tune out display in Visualizer
            java.util.List<MycoNode> neighbors = (java.util.List<MycoNode>) link.getNeighbors();

            //// Adding only links to hypha thins out links to biomass
            //    (java.util.List<MycoNode>) link.getHyphae();

            Collection<MycoNode> jungNeighbors = graph.getNeighbors(n);

            // Remove edges from Jung graph that are not in peersim graph
            for (MycoNode o : jungNeighbors) {
                if (!neighbors.contains(o)) {
                    MycoEdge edge = graph.findEdge(n, o);
                    while (edge != null) {
                        graph.removeEdge(edge);
                        edge = graph.findEdge(n, o);
                    }
                }
            }

            // Add missing edges to Jung graph that are in peersim graph
            for (MycoNode o : neighbors) {
                if (graph.findEdge(n, o) == null) {
                    MycoEdge edge = new MycoEdge();
                    graph.addEdge(edge, n, o, EdgeType.DIRECTED);
                }
            }
        }

        //log.finest("VERTICES: " + graph.getVertices());
        //log.finest("EDGES: " + graph.getEdges());
    }

    for (ChangeListener cl : changeListeners) {
        cl.stateChanged(new ChangeEvent(graph));
    }
    if (walking) {
        try {
            Thread.sleep(walkDelay);
        } catch (InterruptedException e) {
        }
        stepBlocked = false;
    }

    try {
        while (stepBlocked && !noBlock) {
            synchronized (JungGraphObserver.class) {
                JungGraphObserver.class.wait();
            }
        }
    } catch (InterruptedException e) {
        stepBlocked = true;
    }
    stepBlocked = true;
    //System.out.println(graph.toString());
    return false;
}

From source file:FSM.java

/**
 * Fire a change event to registered listeners.
 *///w  ww  . j  a  v a2  s  . c  om
protected void fireChangeEvent() {
    ChangeEvent changeEvent = new ChangeEvent(this);
    for (ChangeListener cl : changeListeners) {
        cl.stateChanged(changeEvent);
    }
}