Make sure error message updates at start-up
This commit is contained in:
parent
fa27fd0b9a
commit
1a32012aa1
@ -19,6 +19,7 @@ import net.sf.openrocket.util.Color;
|
|||||||
public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfigurator<JavaCode> {
|
public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfigurator<JavaCode> {
|
||||||
private JavaCode extension;
|
private JavaCode extension;
|
||||||
private JTextField classNameField;
|
private JTextField classNameField;
|
||||||
|
private StyledLabel errorMsg;
|
||||||
|
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfig
|
|||||||
panel.add(new JLabel(trans.get("SimulationExtension.javacode.className")), "wrap rel");
|
panel.add(new JLabel(trans.get("SimulationExtension.javacode.className")), "wrap rel");
|
||||||
classNameField = new JTextField(extension.getClassName());
|
classNameField = new JTextField(extension.getClassName());
|
||||||
panel.add(classNameField, "growx, wrap");
|
panel.add(classNameField, "growx, wrap");
|
||||||
StyledLabel errorMsg = new StyledLabel();
|
this.errorMsg = new StyledLabel();
|
||||||
errorMsg.setFontColor(Color.DARK_RED.toAWTColor());
|
errorMsg.setFontColor(Color.DARK_RED.toAWTColor());
|
||||||
errorMsg.setVisible(false);
|
errorMsg.setVisible(false);
|
||||||
panel.add(errorMsg, "growx, wrap");
|
panel.add(errorMsg, "growx, wrap");
|
||||||
@ -52,26 +53,34 @@ public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
// Display error message if the class name is invalid
|
updateErrorMsg();
|
||||||
String text = classNameField.getText().trim();
|
|
||||||
try {
|
|
||||||
Class.forName(text);
|
|
||||||
errorMsg.setVisible(false);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
// Don't display an error message for an empty field
|
|
||||||
if (text.length() == 0) {
|
|
||||||
errorMsg.setVisible(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
errorMsg.setText(trans.get("SimulationExtension.javacode.classnotfound"));
|
|
||||||
errorMsg.setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
updateErrorMsg();
|
||||||
|
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateErrorMsg() {
|
||||||
|
if (this.errorMsg == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Display error message if the class name is invalid
|
||||||
|
String text = classNameField.getText().trim();
|
||||||
|
try {
|
||||||
|
Class.forName(text);
|
||||||
|
errorMsg.setVisible(false);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// Don't display an error message for an empty field
|
||||||
|
if (text.length() == 0) {
|
||||||
|
errorMsg.setVisible(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
errorMsg.setText(trans.get("SimulationExtension.javacode.classnotfound"));
|
||||||
|
errorMsg.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void close() {
|
protected void close() {
|
||||||
if (this.extension != null && this.classNameField != null) {
|
if (this.extension != null && this.classNameField != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user