Skip to content
Permalink
Browse files

NX listener to catch when paths go active.

Update the AddEntryExitPairPanel table when the path is changed to active.
  • Loading branch information...
sidlo64 committed Aug 12, 2019
1 parent 4705135 commit b6dee6d9c9d9ef2b4707f2fd7574bc91b116932d
@@ -303,13 +303,12 @@ void addPointToCombo(String signalMastName, String sensorName) {

static final int NUMCOL = ENABLEDCOL + 1;

//Need to add a property change listener to catch when paths go active.
class TableModel extends javax.swing.table.AbstractTableModel implements PropertyChangeListener {

//needs a method to for when panel changes
//need a method to delete an item
//Possibly also to set a route.
//Add a propertychange listener to hear when the route goes active.
// Since 4.17.4 has added functionality a property change listener to catch when paths go active.
TableModel(LayoutEditor panel) {
setPanel(panel);
nxPairs.addPropertyChangeListener(this);
@@ -46,7 +46,8 @@
*
* @author Kevin Dickerson Copyright (C) 2011
*/
public class EntryExitPairs implements jmri.Manager<DestinationPoints>, jmri.InstanceManagerAutoDefault {
public class EntryExitPairs implements jmri.Manager<DestinationPoints>, jmri.InstanceManagerAutoDefault,
PropertyChangeListener {

public int routingMethod = LayoutBlockConnectivityTools.METRIC;

@@ -659,10 +660,23 @@ private PointDetails providePoint(LayoutBlock source, List<LayoutBlock> protecti
return sourcePoint;
}

/**
* @since 4.17.4
*/
@Override
public void propertyChange(PropertyChangeEvent evt) {
firePropertyChange("active", evt.getOldValue(), evt.getNewValue());
}


public void addNXDestination(NamedBean source, NamedBean destination, LayoutEditor panel) {
addNXDestination(source, destination, panel, null);
}

/**
* @since 4.17.4
* Register in Property Change Listener.
*/
public void addNXDestination(NamedBean source, NamedBean destination, LayoutEditor panel, String id) {
if (source == null) {
log.error("no source Object provided"); // NOI18N
@@ -686,7 +700,10 @@ public void addNXDestination(NamedBean source, NamedBean destination, LayoutEdit
destPoint.setRefObject(destination);
destPoint.getSignal();
if (!nxpair.containsKey(sourcePoint)) {
nxpair.put(sourcePoint, new Source(sourcePoint));
Source sp = new Source(sourcePoint) ;
nxpair.put(sourcePoint, sp);
sp.removePropertyChangeListener(this);
sp.addPropertyChangeListener(this);
}
nxpair.get(sourcePoint).addDestination(destPoint, id);
}
@@ -851,6 +868,8 @@ private boolean confirmDeletePairs() {
/**
* Delete the pairs in the delete pair list.
* @since 4.11.2
* @since 4.17.4
* Remove from Change Listener.
*/
private void deleteNxPairs() {
for (DeletePair dp : deletePairList) {
@@ -859,6 +878,7 @@ private void deleteNxPairs() {
nxpair.get(sourcePoint).removeDestination(destPoint);
firePropertyChange("length", null, null); // NOI18N
if (nxpair.get(sourcePoint).getDestinationPoints().isEmpty()) {
nxpair.get(sourcePoint).removePropertyChangeListener(this);
nxpair.remove(sourcePoint);
}
}
@@ -1,5 +1,8 @@
package jmri.jmrit.entryexit;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -9,7 +12,7 @@
import jmri.jmrit.display.layoutEditor.LayoutBlock;
import jmri.jmrit.display.layoutEditor.LayoutEditor;

public class Source {
public class Source implements PropertyChangeListener {

JMenuItem clear = null;
JMenuItem cancel = null;
@@ -57,6 +60,36 @@ public Source(PointDetails point/*, ArrayList<LayoutBlock> protectingBlock*/) {
pd = point;
}

/**
* Property change support for table in AddEntryExitPairPanel.
* Catch when paths go active.
* @since 4.17.4
*/
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);

/**
* @since 4.17.4
*/
public void addPropertyChangeListener(PropertyChangeListener listener) {
pcs.addPropertyChangeListener(listener);
}

/**
* @since 4.17.4
*/
public void removePropertyChangeListener(PropertyChangeListener listener) {
pcs.removePropertyChangeListener(listener);
}

/**
* @since 4.17.4
*/
@Override
public void propertyChange(PropertyChangeEvent evt) {
pcs.firePropertyChange("active", evt.getOldValue(), evt.getNewValue());
}


void cancelClearInterlockFromSource(int cancelClear) {
for (DestinationPoints dp : pointToDest.values()) {
if (dp.isActive()) {
@@ -105,6 +138,10 @@ NamedBean getSourceSignal() {
return sourceSignal;
}

/**
* @since 4.17.4
* Add Property Change Listener.
*/
public void addDestination(PointDetails dest, String id) {
if (pointToDest.containsKey(dest)) {
return;
@@ -113,11 +150,17 @@ public void addDestination(PointDetails dest, String id) {
DestinationPoints dstPoint = new DestinationPoints(dest, id, this);
dest.setDestination(dstPoint, this);
pointToDest.put(dest, dstPoint);
dstPoint.addPropertyChangeListener(this);
}

/**
* @since 4.17.4
* Remov Property Change Listener.
*/
public void removeDestination(PointDetails dest) {
pointToDest.get(dest).dispose();
pointToDest.remove(dest);
dest.removePropertyChangeListener(this);
if (pointToDest.size() == 0) {
getPoint().removeSource(this);
}
@@ -256,5 +299,4 @@ public DestinationPoints getByUserName(String id) {
return null;
}

// private final static Logger log = LoggerFactory.getLogger(Source.class);
}

0 comments on commit b6dee6d

Please sign in to comment.
You can’t perform that action at this time.