allow tunnels table rows to be edited

pull/35/head
knaccc 4 years ago
parent 52fc1b14dd
commit 8ce2d51512

@ -14,8 +14,9 @@ public class AddTunnelController {
@FXML Pane serverTunnelConfigPane;
@FXML Pane httpProxyConfigPane;
@FXML Pane socksProxyConfigPane;
@FXML Button addButton;
@FXML Button okButton;
@FXML Button cancelButton;
@FXML Label tunnelAddEditLabel;
@FXML ToggleGroup tunnelType;
@FXML RadioButton clientTunnelRadioButton;
@FXML RadioButton serverTunnelRadioButton;
@ -30,19 +31,55 @@ public class AddTunnelController {
@FXML TextField socksPortField;
@FXML TextField httpProxyPortField;
public AddTunnelController() {
super();
}
Runnable existingTunnelDestroyer;
void setExistingTunnelDestroyer(Runnable r) {
existingTunnelDestroyer = r;
}
private void updateAddButtonState() {
void setExistingTunnel(Tunnel t) {
switch(t.getType()) {
case "server":
serverTunnelRadioButton.fire();
TunnelControl.ServerTunnel serverTunnel = (TunnelControl.ServerTunnel) t;
serverHostField.setText(serverTunnel.host);
serverPortField.setText(serverTunnel.port + "");
serverKeyField.setText(serverTunnel.keyPair.toString());
break;
case "client":
clientTunnelRadioButton.fire();
TunnelControl.ClientTunnel clientTunnel = (TunnelControl.ClientTunnel) t;
clientDestAddrField.setText(clientTunnel.dest);
clientPortField.setText(clientTunnel.port + "");
break;
case "socks":
socksProxyRadioButton.fire();
TunnelControl.SocksTunnel socksTunnel = (TunnelControl.SocksTunnel) t;
socksPortField.setText(socksTunnel.port + "");
break;
case "http":
httpProxyRadioButton.fire();
TunnelControl.HttpClientTunnel httpClientTunnel = (TunnelControl.HttpClientTunnel) t;
socksPortField.setText(httpClientTunnel.port + "");
break;
}
}
private void updateOkButtonState() {
if(tunnelType.getSelectedToggle().equals(clientTunnelRadioButton)) {
addButton.setDisable(Stream.of(clientDestAddrField, clientPortField).anyMatch(f->f.getText().isBlank()));
okButton.setDisable(Stream.of(clientDestAddrField, clientPortField).anyMatch(f->f.getText().isBlank()));
}
else if(tunnelType.getSelectedToggle().equals(serverTunnelRadioButton)) {
addButton.setDisable(Stream.of(serverHostField, serverPortField, serverKeyField, serverAddrField).anyMatch(f->f.getText().isBlank()));
okButton.setDisable(Stream.of(serverHostField, serverPortField, serverKeyField, serverAddrField).anyMatch(f->f.getText().isBlank()));
}
else if(tunnelType.getSelectedToggle().equals(socksProxyRadioButton)) {
addButton.setDisable(Stream.of(socksPortField).anyMatch(f->f.getText().isBlank()));
okButton.setDisable(Stream.of(socksPortField).anyMatch(f->f.getText().isBlank()));
}
else if(tunnelType.getSelectedToggle().equals(httpProxyRadioButton)) {
addButton.setDisable(Stream.of(httpProxyPortField).anyMatch(f->f.getText().isBlank()));
okButton.setDisable(Stream.of(httpProxyPortField).anyMatch(f->f.getText().isBlank()));
}
}
@ -53,8 +90,9 @@ public class AddTunnelController {
socksProxyConfigPane.setVisible(false);
httpProxyConfigPane.setVisible(false);
addButton.setOnAction(ev->{
okButton.setOnAction(ev->{
try {
if(existingTunnelDestroyer!=null) existingTunnelDestroyer.run();
var controller = Gui.instance.getController();
var tunnelControl = controller.getRouterWrapper().getTunnelControl();
var tunnelList = tunnelControl.getTunnelList();
@ -80,10 +118,9 @@ public class AddTunnelController {
TextField[] allTextFields = new TextField[] {clientDestAddrField, clientPortField, serverHostField, serverPortField, serverKeyField, serverAddrField, socksPortField, httpProxyPortField};
for(TextField f : allTextFields) {
f.textProperty().addListener((observable, oldValue, newValue) -> updateAddButtonState());
f.textProperty().addListener((observable, oldValue, newValue) -> updateOkButtonState());
}
cancelButton.setOnAction(e->{
clientTunnelConfigPane.getScene().getWindow().hide();
});
@ -103,7 +140,7 @@ public class AddTunnelController {
}
if (newToggle.equals(httpProxyRadioButton)) httpProxyConfigPane.setVisible(true);
if (newToggle.equals(socksProxyRadioButton)) socksProxyConfigPane.setVisible(true);
updateAddButtonState();
updateOkButtonState();
}
catch (Exception e) {
throw new RuntimeException(e);

@ -39,6 +39,7 @@ import java.net.URI;
import java.text.DecimalFormat;
import java.util.Optional;
import java.util.Properties;
import java.util.function.Supplier;
import java.util.stream.Stream;
public class Controller {
@ -50,6 +51,7 @@ public class Controller {
@FXML private Label maxBandwidthLabel;
@FXML private ImageView masterToggle;
@FXML private AnchorPane bandwidthDisabledOverlay;
@FXML private TabPane tabPane;
@FXML private Tab bandwidthTab;
@FXML private Tab tunnelsTab;
@FXML private Tab eepSiteTab;
@ -57,6 +59,7 @@ public class Controller {
@FXML private Label statusLabel;
@FXML private Button tunnelAddButton;
@FXML private Button tunnelRemoveButton;
@FXML private Button tunnelEditButton;
@FXML private TableView<Tunnel> tunnelsTableView;
@FXML private TableColumn typeCol;
@FXML private TableColumn stateCol;
@ -115,10 +118,12 @@ public class Controller {
tunnelsTableView.getSelectionModel().selectedItemProperty().addListener((observableValue, oldSelection, newSelection) -> {
if (newSelection == null) {
tunnelRemoveButton.setDisable(true);
tunnelRemoveButton.setVisible(false);
tunnelEditButton.setVisible(false);
}
else {
tunnelRemoveButton.setDisable(false);
tunnelRemoveButton.setVisible(true);
tunnelEditButton.setVisible(true);
}
});
@ -129,20 +134,43 @@ public class Controller {
tunnelRemoveButton.setDisable(true);
});
tunnelAddButton.setOnAction(event->{
record DialogRefs(Scene scene, Stage stage, AddTunnelController controller){};
Supplier<DialogRefs> showAddTunnelDialog = ()->{
try {
Stage dialogStage = new Stage();
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(getStage());
dialogStage.setResizable(false);
dialogStage.setTitle("New tunnel");
Scene dialogScene = new Scene(FXMLLoader.load(getClass().getResource("addTunnel.fxml")));
FXMLLoader loader = new FXMLLoader(getClass().getResource("addTunnel.fxml"));
Scene dialogScene = new Scene(loader.load());
dialogScene.getStylesheets().add("org/getmonero/i2p/zero/gui/gui.css");
dialogStage.setScene(dialogScene);
dialogStage.show();
return new DialogRefs(dialogScene, dialogStage, loader.getController());
} catch (Exception e) {
throw new RuntimeException(e);
}
};
tunnelAddButton.setOnAction(event->{
DialogRefs dialogRefs = showAddTunnelDialog.get();
dialogRefs.stage.show();
});
tunnelEditButton.setOnAction(event->{
Tunnel existingTunnel = tunnelsTableView.getSelectionModel().getSelectedItem();
if(existingTunnel.getType().equals("eepsite")) {
tabPane.getSelectionModel().select(eepSiteTab);
}
else {
DialogRefs dialogRefs = showAddTunnelDialog.get();
dialogRefs.stage.setTitle("Edit tunnel");
dialogRefs.controller.setExistingTunnel(existingTunnel);
dialogRefs.controller.setExistingTunnelDestroyer(()->{
getRouterWrapper().getTunnelControl().getTunnelList().removeTunnel(existingTunnel);
existingTunnel.destroy(false);
});
dialogRefs.stage.show();
}
});
EventHandler<Event> tabSelectionEventHandler = e->{

@ -10,7 +10,7 @@
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="267.0" prefWidth="770.0" stylesheets="@gui.css" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.getmonero.i2p.zero.gui.AddTunnelController">
<children>
<Label layoutX="18.0" layoutY="9.0" prefHeight="27.0" prefWidth="120.0" text="Add a tunnel">
<Label fx:id="tunnelAddEditLabel" layoutX="18.0" layoutY="9.0" prefHeight="27.0" prefWidth="120.0" text="Add a tunnel">
</Label>
<RadioButton fx:id="clientTunnelRadioButton" layoutX="19.0" layoutY="48.0" mnemonicParsing="false" selected="true" style="" text="Client tunnel - create a local port that forwards requests to a specified I2P destination address">
<toggleGroup>
@ -19,9 +19,9 @@
</RadioButton>
<RadioButton fx:id="serverTunnelRadioButton" layoutX="19.0" layoutY="73.0" mnemonicParsing="false" text="Server tunnel - create an I2P destination address that will forward requests to the specified host and port" toggleGroup="$tunnelType" />
<RadioButton fx:id="httpProxyRadioButton" layoutX="19.0" layoutY="97.0" mnemonicParsing="false" text="HTTP proxy - create a proxy that your web browser can use to access I2P web sites" toggleGroup="$tunnelType" />
<Button fx:id="addButton" defaultButton="true" disable="true" layoutX="712.0" layoutY="221.0" mnemonicParsing="false" text="Add" />
<Button fx:id="cancelButton" cancelButton="true" layoutX="647.0" layoutY="221.0" mnemonicParsing="false" text="Cancel" />
<Pane fx:id="clientTunnelConfigPane" layoutX="40.0" layoutY="156.0" prefHeight="67.0" prefWidth="523.0" >
<Button fx:id="okButton" defaultButton="true" disable="true" layoutX="716.0" layoutY="221.0" mnemonicParsing="false" text="OK" />
<Button fx:id="cancelButton" cancelButton="true" layoutX="652.0" layoutY="221.0" mnemonicParsing="false" text="Cancel" />
<Pane fx:id="clientTunnelConfigPane" layoutX="40.0" layoutY="156.0" prefHeight="67.0" prefWidth="523.0">
<children>
<TextField fx:id="clientDestAddrField" layoutX="165.0" prefHeight="27.0" prefWidth="353.0" />
<Label layoutX="1.0" layoutY="4.0" text="I2P destination address" />

@ -20,7 +20,7 @@
<BorderPane fx:id="rootBorderPane" minHeight="340.0" minWidth="360.0" prefHeight="500.0" prefWidth="900.0" stylesheets="@gui.css" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.getmonero.i2p.zero.gui.Controller">
<center>
<TabPane>
<TabPane fx:id="tabPane">
<tabs>
<Tab fx:id="bandwidthTab" closable="false" text="Bandwidth">
<content>
@ -98,10 +98,11 @@
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="32.0" prefWidth="339.0" BorderPane.alignment="CENTER">
<children>
<Button fx:id="tunnelAddButton" layoutX="301.0" layoutY="7.0" mnemonicParsing="false" text="Add">
<Button fx:id="tunnelAddButton" layoutX="296.0" layoutY="6.0" mnemonicParsing="false" text="Add">
</Button>
<Button fx:id="tunnelRemoveButton" disable="true" layoutX="231.0" layoutY="7.0" mnemonicParsing="false" text="Remove">
<Button fx:id="tunnelRemoveButton" layoutX="226.0" layoutY="6.0" mnemonicParsing="false" text="Remove" visible="false">
</Button>
<Button fx:id="tunnelEditButton" layoutX="182.0" layoutY="6.0" mnemonicParsing="false" text="Edit" visible="false" />
</children>
</AnchorPane>
</right>

@ -250,7 +250,7 @@ public class TunnelControl implements Runnable {
@Override public int getPort() { return port; }
@Override public String getI2P() { return "n/a"; }
}
public static class ServerTunnel<T extends ServerTunnel> extends Tunnel {
public static class ServerTunnel extends Tunnel {
public String dest;
public String host;
public int port;

Loading…
Cancel
Save