remote ECU usability progress
This commit is contained in:
parent
a36a742039
commit
b99c81f7ac
|
@ -0,0 +1,69 @@
|
|||
package com.rusefi.ts_plugin;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.*;
|
||||
|
||||
public class IntegerDocumentFilter extends DocumentFilter {
|
||||
public static void install(JTextField jTextField) {
|
||||
PlainDocument doc = (PlainDocument) jTextField.getDocument();
|
||||
doc.setDocumentFilter(new IntegerDocumentFilter());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertString(FilterBypass fb, int offset, String string,
|
||||
AttributeSet attr) throws BadLocationException {
|
||||
|
||||
Document doc = fb.getDocument();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(doc.getText(0, doc.getLength()));
|
||||
sb.insert(offset, string);
|
||||
|
||||
if (test(sb.toString())) {
|
||||
super.insertString(fb, offset, string, attr);
|
||||
} else {
|
||||
// warn the user and don't allow the insert
|
||||
}
|
||||
}
|
||||
|
||||
private boolean test(String text) {
|
||||
try {
|
||||
Integer.parseInt(text);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(FilterBypass fb, int offset, int length, String text,
|
||||
AttributeSet attrs) throws BadLocationException {
|
||||
|
||||
Document doc = fb.getDocument();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(doc.getText(0, doc.getLength()));
|
||||
sb.replace(offset, offset + length, text);
|
||||
|
||||
if (test(sb.toString())) {
|
||||
super.replace(fb, offset, length, text, attrs);
|
||||
} else {
|
||||
// warn the user and don't allow the insert
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(FilterBypass fb, int offset, int length)
|
||||
throws BadLocationException {
|
||||
Document doc = fb.getDocument();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(doc.getText(0, doc.getLength()));
|
||||
sb.delete(offset, offset + length);
|
||||
|
||||
if (test(sb.toString())) {
|
||||
super.remove(fb, offset, length);
|
||||
} else {
|
||||
// warn the user and don't allow the insert
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -57,9 +57,13 @@ public class RemoteTab {
|
|||
return new Dimension(100, size.height);
|
||||
}
|
||||
};
|
||||
IntegerDocumentFilter.install(applicationPort);
|
||||
IntegerDocumentFilter.install(oneTimePasswordControl);
|
||||
String portProperty = getLocalPort();
|
||||
applicationPort.setText(portProperty);
|
||||
|
||||
JPanel topLines = new JPanel(new VerticalFlowLayout());
|
||||
|
||||
|
||||
JPanel topPanel = new JPanel(new FlowLayout());
|
||||
topPanel.add(refresh);
|
||||
|
@ -67,7 +71,11 @@ public class RemoteTab {
|
|||
topPanel.add(applicationPort);
|
||||
topPanel.add(new JLabel(" One time password:"));
|
||||
topPanel.add(oneTimePasswordControl);
|
||||
content.add(topPanel, BorderLayout.NORTH);
|
||||
|
||||
topLines.add(topPanel);
|
||||
topLines.add(new URLLabel("https://github.com/rusefi/rusefi/wiki/HOWTO-Remote-Tuning"));
|
||||
|
||||
content.add(topLines, BorderLayout.NORTH);
|
||||
content.add(list, BorderLayout.CENTER);
|
||||
list.add(new JLabel("Requesting list of ECUs"));
|
||||
requestListDownload();
|
||||
|
|
Loading…
Reference in New Issue