Add warning text if simulation listener not recognized as class
This commit is contained in:
parent
1021bbc8a9
commit
fa27fd0b9a
@ -4,6 +4,8 @@ import java.awt.Dialog.ModalityType;
|
|||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
@ -50,17 +52,21 @@ public abstract class AbstractSwingSimulationExtensionConfigurator<E extends Sim
|
|||||||
close.addActionListener(new ActionListener() {
|
close.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
dialog.setVisible(false);
|
close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel.add(close, "right");
|
panel.add(close, "right");
|
||||||
|
|
||||||
|
dialog.addWindowListener(new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
dialog.add(panel);
|
dialog.add(panel);
|
||||||
GUIUtil.setDisposableDialogOptions(dialog, close);
|
GUIUtil.setDisposableDialogOptions(dialog, close);
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
close();
|
|
||||||
GUIUtil.setNullModels(dialog);
|
|
||||||
dialog = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,10 +84,12 @@ public abstract class AbstractSwingSimulationExtensionConfigurator<E extends Sim
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the default dialog is closed. By default does nothing.
|
* Called when the default dialog is closed. By default hides the dialog and cleans up the component models.
|
||||||
*/
|
*/
|
||||||
protected void close() {
|
protected void close() {
|
||||||
|
dialog.setVisible(false);
|
||||||
|
GUIUtil.setNullModels(dialog);
|
||||||
|
dialog = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract JComponent getConfigurationComponent(E extension, Simulation simulation, JPanel panel);
|
protected abstract JComponent getConfigurationComponent(E extension, Simulation simulation, JPanel panel);
|
||||||
|
@ -8,22 +8,37 @@ import javax.swing.event.DocumentEvent;
|
|||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
|
|
||||||
import net.sf.openrocket.document.Simulation;
|
import net.sf.openrocket.document.Simulation;
|
||||||
|
import net.sf.openrocket.gui.components.StyledLabel;
|
||||||
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.plugin.Plugin;
|
import net.sf.openrocket.plugin.Plugin;
|
||||||
import net.sf.openrocket.simulation.extension.AbstractSwingSimulationExtensionConfigurator;
|
import net.sf.openrocket.simulation.extension.AbstractSwingSimulationExtensionConfigurator;
|
||||||
|
import net.sf.openrocket.startup.Application;
|
||||||
|
import net.sf.openrocket.util.Color;
|
||||||
|
|
||||||
@Plugin
|
@Plugin
|
||||||
public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfigurator<JavaCode> {
|
public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfigurator<JavaCode> {
|
||||||
|
private JavaCode extension;
|
||||||
|
private JTextField classNameField;
|
||||||
|
|
||||||
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
public JavaCodeConfigurator() {
|
public JavaCodeConfigurator() {
|
||||||
super(JavaCode.class);
|
super(JavaCode.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JComponent getConfigurationComponent(final JavaCode extension, Simulation simulation, JPanel panel) {
|
protected JComponent getConfigurationComponent(final JavaCode extension, Simulation simulation, JPanel panel) {
|
||||||
|
this.extension = extension;
|
||||||
panel.add(new JLabel(trans.get("SimulationExtension.javacode.desc")), "wrap para");
|
panel.add(new JLabel(trans.get("SimulationExtension.javacode.desc")), "wrap para");
|
||||||
panel.add(new JLabel(trans.get("SimulationExtension.javacode.className")), "wrap rel");
|
panel.add(new JLabel(trans.get("SimulationExtension.javacode.className")), "wrap rel");
|
||||||
final JTextField textField = new JTextField(extension.getClassName());
|
classNameField = new JTextField(extension.getClassName());
|
||||||
textField.getDocument().addDocumentListener(new DocumentListener() {
|
panel.add(classNameField, "growx, wrap");
|
||||||
|
StyledLabel errorMsg = new StyledLabel();
|
||||||
|
errorMsg.setFontColor(Color.DARK_RED.toAWTColor());
|
||||||
|
errorMsg.setVisible(false);
|
||||||
|
panel.add(errorMsg, "growx, wrap");
|
||||||
|
|
||||||
|
classNameField.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
public void changedUpdate(DocumentEvent e) {
|
public void changedUpdate(DocumentEvent e) {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@ -37,11 +52,33 @@ public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
extension.setClassName(textField.getText());
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel.add(textField, "growx");
|
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void close() {
|
||||||
|
if (this.extension != null && this.classNameField != null) {
|
||||||
|
this.extension.setClassName(this.classNameField.getText().trim());
|
||||||
|
|
||||||
|
}
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user