gateway.setEnabled(s); mac.setEnabled(s);
method.setEnabled(s); port.setEnabled(s);
portScan.setEnabled(s);
}
});
PreferencePanel p = new PreferencePanel() {
@Override
public void save() {
//TODO skip new command if nothing has changed
Controller.getCurrentMap().getHistory().execute(new Command() {
String oldName = i.getName(), newName = name.getText(),
newAddress = address.getText(),
newSubnet = subnet.getText(), newGateway = gateway.getText(),
oldMac = (isPhysical)?((PhysicalIF)i).getMacAddress():null, newMac = mac.getText();
PingMethod newMethod = nameToMethod((String)method.getSelectedItem(), (Integer) port.getValue());
Connection connection = i.getConnection();
Device parent = i.getDevice();
NetworkIF newIF = null;
@Override
public Object undo() {
if (isPhysical && !addressCheckbox.isSelected()) {
PhysicalIF pif = new PhysicalIF(parent, connection, oldAddress);
pif.setSubnet(oldSubnet);
pif.setGateway(oldGateway);
pif.setMacAddress(oldMac);
pif.setPingMethod(oldMethod);
pif.setName(oldName);
parent.addInterface(pif);
parent.removeInterface(newIF);
} else if (isTransparent && addressCheckbox.isSelected()) {
TransparentIF tif = new TransparentIF(parent, connection, Controller.getCurrentMap().
getOpposite(parent, i.getConnection()).getInterfaceFor(connection));
tif.setName(oldName);
parent.addInterface(tif);
parent.removeInterface(newIF);
} else {
i.setAddress(oldAddress);
i.setSubnet(oldSubnet);
i.setGateway(oldGateway);
i.setName(oldName);
if (isPhysical) {
((PhysicalIF)i).setMacAddress(oldMac);
((PhysicalIF)i).setPingMethod(oldMethod);
}
}
return null;
}
@Override
public Object redo() {
NetworkIF counterpart = Controller.getCurrentMap().
getOpposite(parent, i.getConnection()).getInterfaceFor(connection);
if (isPhysical && !addressCheckbox.isSelected()) {
newIF = new TransparentIF(parent, connection, counterpart);
newIF.setName(newName);
parent.addInterface(newIF);
parent.removeInterface(i);
} else if (isTransparent && addressCheckbox.isSelected()) {
PhysicalIF pif = new PhysicalIF(parent, connection, newAddress);
pif.setSubnet(newSubnet);
pif.setGateway(newGateway);
pif.setMacAddress(newMac);
pif.setPingMethod(newMethod);
pif.setName(newName);
newIF = pif;
parent.addInterface(pif);
parent.removeInterface(i);
if (counterpart instanceof TransparentIF) ((TransparentIF) counterpart).setCounterpart(pif);
} else {
i.setAddress(newAddress);
i.setSubnet(newSubnet);
i.setGateway(newGateway);
i.setName(newName);
if (isPhysical) {
((PhysicalIF)i).setMacAddress(newMac);
((PhysicalIF)i).setPingMethod(newMethod);
}
}
return null;
}
});
}
};
p.setLayout(new GridLayout(0, 2, 5, 5));
p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
p.add(new JLabel(Lang.get("interface.name"))); p.add(name);
p.add(addressCheckbox); p.add(address);
p.add(new JLabel(" "+Lang.getNoHTML("interface.subnet"))); p.add(subnet);
p.add(new JLabel(" "+Lang.getNoHTML("interface.gateway"))); p.add(gateway);
p.add(new JLabel(" "+Lang.getNoHTML("interface.mac"))); p.add(mac);
p.add(new JLabel(" "+Lang.getNoHTML("interface.pingmethod"))); p.add(method);
p.add(new JLabel()); p.add(portWrapper);
if (isPhysical) address.requestFocus();
else name.requestFocus();
return p;
}