Skip to content

Commit

Permalink
Making disconnect button work based on the port on the Dropdown list.
Browse files Browse the repository at this point in the history
  • Loading branch information
palmada committed Aug 18, 2018
1 parent 303d44d commit 3699c8c
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 13 deletions.
Binary file modified NanoJ-Fluidics.jar
Binary file not shown.
Binary file modified NanoJ-Fluidics_IJ.jar
Binary file not shown.
Binary file modified NanoJ-Fluidics_MM.jar
Binary file not shown.
Binary file modified PackagedBinaries/NanoJ-Fluidics.zip
Binary file not shown.
Binary file modified PackagedBinaries/NanoJ-Fluidics_IJ.zip
Binary file not shown.
Binary file modified PackagedBinaries/NanoJ-Fluidics_MM.zip
Binary file not shown.
10 changes: 7 additions & 3 deletions src/nanoj/pumpControl/java/pumps/ConnectedSubPumpsList.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ public void removePump(String pumpName,String port) {
}

public void removePump(Pump pump) {
ArrayList<ConnectedSubPump> found = new ArrayList<ConnectedSubPump>();
for (ConnectedSubPump subPump: list)
if (subPump.name.equals(pump.name))
list.remove(subPump);
if (subPump.pump.equals(pump))
found.add(subPump);

connectedPumps.remove(pump);
for (ConnectedSubPump foundPump : found)
list.remove(foundPump);

connectedPumps.remove(found.get(0).pump);
}

public ConnectedSubPump getConnectedSubPump(String name, String subPump, String port) throws PumpNotFoundException {
Expand Down
40 changes: 40 additions & 0 deletions src/nanoj/pumpControl/java/pumps/PumpManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ public synchronized void stopPumping(String pumpName, String subPump, String por
notifyObservers(NEW_STATUS_AVAILABLE);
}

public synchronized boolean disconnect(String port) throws Exception {
boolean success = false;
Pump pump = null;
for (ConnectedSubPump subPump: connectedSubPumps)
if (subPump.port.equals(port)) {
pump = subPump.pump;
success = subPump.pump.disconnect();
break;
}

if (success)
connectedSubPumps.removePump(pump);

setChanged();
notifyObservers(PUMP_DISCONNECTED);
return success;
}

public synchronized boolean disconnect(int index) throws Exception {
boolean success = connectedSubPumps.getConnectedSubPump(index).pump.disconnect();
String name = connectedSubPumps.getConnectedSubPump(index).name;
Expand All @@ -147,6 +165,28 @@ public ConnectedSubPumpsList getConnectedPumpsList() {
return connectedSubPumps;
}

public Pump getPumpOnPort(String port) {
Pump pump = null;
for (ConnectedSubPump subPump: connectedSubPumps)
if (subPump.port.equals(port)) {
pump = subPump.pump;
break;
}

return pump;
}

public String getPumpNameOnPort(String port) {
String pump = "Not found";
for (ConnectedSubPump subPump: connectedSubPumps)
if (subPump.port.equals(port)) {
pump = subPump.name;
break;
}

return pump;
}

public synchronized boolean isConnected(int pumpIndex) {
return connectedSubPumps != null &&
pumpIndex < connectedSubPumps.size() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,12 @@ private class Disconnect implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
boolean success = false;
if (connectedPumpsTable.getSelectedRow() < 0) {
return;
}
String pump = null;
String port = null;
String port = "Undefined";
String name = "Undefined";
try {
int selection = connectedPumpsTable.getSelectedRow();
success = pumpManager.disconnect(selection);
pump = (String) connectedPumpsTableModel.getValueAt(selection,0);
port = (String) connectedPumpsTableModel.getValueAt(selection,2);
port = (String) portsList.getSelectedItem();
name = pumpManager.getPumpNameOnPort(port);
success = pumpManager.disconnect(port);
} catch (Exception e1) {
gui.log.message("Error, failed to disconnect properly.");
e1.printStackTrace();
Expand All @@ -124,7 +120,7 @@ public void actionPerformed(ActionEvent e) {
for (ConnectedSubPump subPump: pumpManager.getConnectedPumpsList())
connectedPumpsTableModel.addRow(subPump.asConnectionArray());

gui.log.message("Disconnected from " + pump + " on port " + port + ".");
gui.log.message("Disconnected from " + name + " on port " + port + ".");
}
}
}
Expand Down

0 comments on commit 3699c8c

Please sign in to comment.