Skip to content

Commit

Permalink
trim() the entered/pasted IPs without triggering modify listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
angryziber committed Jun 11, 2024
1 parent 6069b1f commit 16bb80b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/net/azib/ipscan/gui/feeders/RandomFeederGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ public void initialize() {
}

public Feeder createFeeder() {
feeder = new RandomFeeder(ipPrototypeText.getText(), ipMaskCombo.getText(), countSpinner.getSelection());
feeder = new RandomFeeder(ipPrototypeText.getText().trim(), ipMaskCombo.getText().trim(), countSpinner.getSelection());
return feeder;
}

public String[] serialize() {
return new String[] {ipPrototypeText.getText(), ipMaskCombo.getText(), String.valueOf(countSpinner.getSelection())};
return new String[] {ipPrototypeText.getText().trim(), ipMaskCombo.getText().trim(), String.valueOf(countSpinner.getSelection())};
}

public void unserialize(String[] parts) {
Expand Down
23 changes: 9 additions & 14 deletions src/net/azib/ipscan/gui/feeders/RangeFeederGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import net.azib.ipscan.feeders.RangeFeeder;
import net.azib.ipscan.gui.actions.FeederActions;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
Expand Down Expand Up @@ -76,7 +78,7 @@ public void initialize() {
toLabel.setText(getLabel("feeder.range.to"));

startIPText.addModifyListener(new StartIPModifyListener());
endIPText.addKeyListener(new EndIPKeyListener());
endIPText.addModifyListener(new EndIPModifyListener());

FeederActions.HostnameButton hostnameListener = new FeederActions.HostnameButton(hostnameText, startIPText, netmaskCombo) {
public void widgetSelected(SelectionEvent event) {
Expand Down Expand Up @@ -130,13 +132,11 @@ protected void setInterfaceAddress(InterfaceAddress ifAddr) {
}

public Feeder createFeeder() {
startIPText.setText(startIPText.getText().trim());
endIPText.setText(endIPText.getText().trim());
return feeder = new RangeFeeder(startIPText.getText(), endIPText.getText());
return feeder = new RangeFeeder(startIPText.getText().trim(), endIPText.getText().trim());
}

public String[] serialize() {
return new String[] {startIPText.getText(), endIPText.getText()};
return new String[] {startIPText.getText().trim(), endIPText.getText().trim()};
}

public void unserialize(String[] parts) {
Expand All @@ -150,13 +150,10 @@ public String[] serializePartsLabels() {
return new String[] {"feeder.range.startIP", "feeder.range.endIP"};
}

final class EndIPKeyListener implements KeyListener {
public void keyPressed(KeyEvent e) {
final class EndIPModifyListener implements ModifyListener {
@Override public void modifyText(ModifyEvent modifyEvent) {
isEndIPUnedited = false;
}

public void keyReleased(KeyEvent e) {
}
}

final class NetmaskResetListener implements Listener {
Expand All @@ -169,9 +166,7 @@ public void handleEvent(Event event) {

final class StartIPModifyListener implements ModifyListener {
public void modifyText(ModifyEvent e) {
if (isEndIPUnedited) {
endIPText.setText(startIPText.getText());
}
if (isEndIPUnedited) endIPText.setText(startIPText.getText());
}
}

Expand Down

0 comments on commit 16bb80b

Please sign in to comment.