Skip to content

Commit

Permalink
At Adam's suggestion, removed the timeout stored in a local file in f…
Browse files Browse the repository at this point in the history
…avor of a value stored in the preferences. Also switched to a less busy wait.
  • Loading branch information
Ted authored and Ted committed Oct 26, 2011
1 parent 4e444a9 commit 2bdad72
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
1 change: 0 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@
<copy todir="${target.dir}">
<filelist dir="." files="license.txt,readme.txt,todo.txt,contributors.txt"/>
</copy>
<copy todir="${target.dir}" failonerror="false" file="timeout.txt"/>
<copy tofile="${target.dir}/GCodeDocumentation.txt" failonerror="false" file="docs/GCodeDocumentation.txt"/>
<copy todir="${target.dir}/skein_engines">
<fileset dir="skein_engines" excludes="*.pyc"/>
Expand Down
29 changes: 28 additions & 1 deletion src/replicatorg/app/ui/PreferencesWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void actionPerformed(ActionEvent e) {
backgroundColor = JColorChooser.showDialog(
null,
"Choose Background Color",
backgroundColor);;
backgroundColor);

Base.preferences.putInt("ui.backgroundColor", backgroundColor.getRGB());
Base.getEditor().refreshPreviewPanel();
Expand Down Expand Up @@ -227,6 +227,33 @@ public void propertyChange(PropertyChangeEvent evt) {
});
}

{
content.add(new JLabel("Skeinforge timeout: "),"split");
int value = Base.preferences.getInt("replicatorg.skeinforge.timeout", -1);
JFormattedTextField sfTimeoutField = new JFormattedTextField(new Integer(value));
content.add(sfTimeoutField,"wrap");
String sfTimeoutHelp = "<html><small><em>" +
"The Skeinforge timeout is the number of seconds that replicatorg will wait while the<br>" +
"Skeinforge preferences window is open. If you find that RepG freezes after editing profiles<br>" +
"you can set this number greater than -1 (-1 means no timeout)." +
"</em></small></html>";
content.add(new JLabel(sfTimeoutHelp),"growx,wrap");
sfTimeoutField.setColumns(10);
sfTimeoutField.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName() == "value") {
try {
Integer v = (Integer)evt.getNewValue();
if (v == null) return;
Base.preferences.putInt("replicatorg.skeinforge.timeout", v.intValue());
} catch (ClassCastException cce) {
Base.logger.warning("Unexpected value type: "+evt.getNewValue().getClass().toString());
}
}
}
});
}

{
content.add(new JLabel("Debugging level (default INFO):"),"split");
content.add(makeDebugLevelDropdown(),"wrap");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,8 @@ public void editProfile(Profile profile) {
try {
// force failure if something goes wrong
int value = 1;
File timeout = new File("timeout.txt");
long timeoutValue = -1;

// This is not production code, grab the timeout value
if(timeout.exists())
timeoutValue = Long.parseLong(new BufferedReader(new FileReader(timeout)).readLine());
long timeoutValue = Base.preferences.getInt("replicatorg.skeinforge.timeout", -1);

process = pb.start();

Expand All @@ -399,6 +395,7 @@ public void editProfile(Profile profile) {
Base.logger.log(Level.FINEST, "\tRunning SF with a timeout");
while(timeoutValue > 0)
{
Thread.sleep(1000);
try
{
value = process.exitValue();
Expand All @@ -411,13 +408,14 @@ public void editProfile(Profile profile) {
}
if(timeoutValue == 0)
{
JOptionPane.showConfirmDialog(null, "\tSkeinforge has not returned, This may be due to a communication error\n" +
JOptionPane.showConfirmDialog(null,
"\tSkeinforge has not returned, This may be due to a communication error\n" +
"between Skeinforge and ReplicatorG. If you are still editing a Skeinforge\n" +
"profile, ignore this message; any changes you make in the skeinforge window\n" +
"and save will be used when generating the gcode file.\n\n" +
"\tAdjusting the number in the \"timeout.txt\" file will affect how long ReplicatorG\n" +
"waits before assuming that Skeinforge has failed, if you frequently\n" +
"encounter this message you may want to increase the timeout.",
"\tAdjusting the \"Skeinforge timeout\" in the preferences window will affect how\n" +
"long ReplicatorG waits before assuming that Skeinforge has failed, if you\n" +
"frequently encounter this message you may want to increase the timeout.",
"SF Timeout", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
}
}
Expand Down
1 change: 0 additions & 1 deletion timeout.txt

This file was deleted.

0 comments on commit 2bdad72

Please sign in to comment.