List of usage examples for javax.swing.event ChangeListener stateChanged
void stateChanged(ChangeEvent e);
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);//from w w w . j a va2 s. c o m 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: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$ }/* ww w. j a v a 2 s.c o m*/ 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:com.diversityarrays.util.DefaultDALClientProvider.java
protected void fireStateChanged() { if (SwingUtilities.isEventDispatchThread()) { // We want to run OUTSIDE the event dispatch thread. new Thread(() -> fireStateChanged()).start(); return;//ww w . jav a 2s . com } for (ChangeListener l : listenerList.getListeners(ChangeListener.class)) { try { l.stateChanged(changeEvent); } catch (Throwable t) { t.printStackTrace(); if (t instanceof OutOfMemoryError) { // Give up ! break; } } } }
From source file:edu.ku.brc.specify.ui.AttachmentIconMapper.java
/** * Sends notification on GUI thread//from w ww . j a v a 2 s .com * @param listener * @param imgIcon */ private ImageIcon notifyListener(final ChangeListener listener, final ImageIcon imgIcon) { if (listener != null) { SwingWorker<Boolean, Boolean> worker = new SwingWorker<Boolean, Boolean>() { @Override protected Boolean doInBackground() throws Exception { try { Thread.sleep(100); } catch (Exception ex) { } return null; } @Override protected void done() { listener.stateChanged(new ChangeEvent(imgIcon)); } }; worker.execute(); } return imgIcon; }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTabSheet.java
public DesktopTabSheet() { impl = new JTabbedPaneExt(); impl.addChangeListener(e -> {/*from w w w .j av a2 s. co m*/ for (ChangeListener listener : new ArrayList<>(implTabSheetChangeListeners)) { listener.stateChanged(e); } }); setWidth("100%"); }
From source file:edu.ku.brc.af.ui.forms.validation.ValComboBox.java
/** * Notify all the change listeners.// www. j ava 2 s . c o m * @param e the change event or null */ protected void notifyChangeListeners(final ChangeEvent e) { if (listeners != null) { for (ChangeListener l : listeners) { l.stateChanged(e); } } }
From source file:org.jdal.swing.PageableTable.java
/** * Notify ChangeListeners that state change *//*from ww w .j av a 2s .c om*/ private void fireChangeEvent() { ChangeEvent e = new ChangeEvent(this); for (ChangeListener l : changeListeners) l.stateChanged(e); }
From source file:edu.ku.brc.specify.plugins.ipadexporter.iPadDBExporterPlugin.java
/** * /* www .ja v a 2 s . c o m*/ */ private void processDB() { try { loadAndPushResourceBundle(RESOURCE_NAME); int totalColObjRecords = BasicSQLUtils.getCountAsInt("SELECT COUNT(*) FROM collectionobject"); if (totalColObjRecords > maxRequiredRecs - 1) { double ratio = 510.0 / 720.0; int width = 1024; int height = (int) ((width * ratio) + 0.5); if (iPadDBExporterObj == null) { iPadDBExporterObj = new iPadDBExporter(iPadCloud, "isite.db", width, height); } writeSimpleGlassPaneMsg(getResourceString("EXPORTING"), 24); AppContextMgr ac = AppContextMgr.getInstance(); if (ac != null) { Collection coll = AppContextMgr.getInstance().getClassObject(Collection.class); Discipline disp = AppContextMgr.getInstance().getClassObject(Discipline.class); Division div = AppContextMgr.getInstance().getClassObject(Division.class); TaxonTreeDef taxDef = disp.getTaxonTreeDef(); GeographyTreeDef geoDef = disp.getGeographyTreeDef(); LithoStratTreeDef lithoDef = disp.getLithoStratTreeDef(); GeologicTimePeriodTreeDef gtpDef = disp.getGeologicTimePeriodTreeDef(); iPadDBExporterObj.initialize(); iPadDBExporterObj.createMappings(coll.getId(), disp.getId(), div.getId(), taxDef.getId(), geoDef.getId(), lithoDef.getId(), gtpDef.getId()); exportBtn.setEnabled(false); ChangeListener cl = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { popResourceBundle(); clearSimpleGlassPaneMsg(); exportBtn.setEnabled(true); enableRemoveDatasetBtn(); } }; if (!iPadDBExporterObj.createSQLiteDatabase(null, cl)) { cl.stateChanged(new ChangeEvent(this)); } } } else { showLocalizedError("ERR_TOO_FEW", maxRequiredRecs); popResourceBundle(); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:net.sf.jabref.external.DroppedFileHandler.java
private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileType fileType, BibEntry entry, BibDatabase database) {/*from w w w . j ava2 s .c o 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.dbsupport.cleanuptools.GeoCleanupFuzzySearch.java
/** * @param earthId/*from w w w . ja v a2s .c o m*/ * @param cl */ public void startIndexingProcessAsync(final int earthId, final ProgressFrame frame, final ChangeListener cl) { this.frame = frame; centerAndShow(frame); SwingWorker<Boolean, Boolean> worker = new SwingWorker<Boolean, Boolean>() { boolean isOK = true; @Override protected Boolean doInBackground() throws Exception { setProgressDesc("Build Geography Names cross-reference..."); // I18N stCntXRef = new StateCountryContXRef(readConn); isOK = stCntXRef.build(); if (isOK) { setProgressDesc("Creating searchable index..."); // I18N isOK = buildLuceneIndex(earthId); } return isOK; } @Override protected void done() { super.done(); // NOTE: need to check here that everything built OK cl.stateChanged(new ChangeEvent((Boolean) isOK)); } }; worker.execute(); }