- improve blender tool, iconify main window when blender is opened

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10159 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 12 years ago
parent 93fc13b7b2
commit 91939086cd
  1. 75
      sdk/jme3-blender/src/com/jme3/gde/blender/BlenderTool.java
  2. 3
      sdk/jme3-blender/src/com/jme3/gde/blender/OutputReader.java

@ -5,8 +5,11 @@
package com.jme3.gde.blender; package com.jme3.gde.blender;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import java.awt.Frame;
import java.awt.Window;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.openide.DialogDisplayer; import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor; import org.openide.NotifyDescriptor;
@ -14,6 +17,7 @@ import org.openide.filesystems.FileObject;
import org.openide.modules.InstalledFileLocator; import org.openide.modules.InstalledFileLocator;
import org.openide.util.Exceptions; import org.openide.util.Exceptions;
import org.openide.util.Utilities; import org.openide.util.Utilities;
import org.openide.windows.WindowManager;
/** /**
* *
@ -23,7 +27,7 @@ public class BlenderTool {
private static final Logger logger = Logger.getLogger(BlenderTool.class.getName()); private static final Logger logger = Logger.getLogger(BlenderTool.class.getName());
private static boolean running = false; private static boolean running = false;
// private static AtomicBoolean running = new AtomicBoolean(false); private static Window blenderWindow = null;
private static String getBlenderExeName() { private static String getBlenderExeName() {
if (Utilities.isWindows()) { if (Utilities.isWindows()) {
@ -36,7 +40,8 @@ public class BlenderTool {
public static File getBlenderExecutable() { public static File getBlenderExecutable() {
File blender = InstalledFileLocator.getDefault().locate("../blender/" + getBlenderExeName(), null, false); File blender = InstalledFileLocator.getDefault().locate("../blender/" + getBlenderExeName(), null, false);
if (blender == null) { if (blender == null) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message("Error finding Blender!")); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message("Error finding Blender executable at\n" + blender.getPath()));
logger.log(Level.SEVERE, "Error finding Blender executable at {0}", blender.getPath());
} }
return blender; return blender;
} }
@ -44,7 +49,8 @@ public class BlenderTool {
public static File getBlenderSettingsFolder() { public static File getBlenderSettingsFolder() {
File blender = InstalledFileLocator.getDefault().locate("../blender/2.64", null, false); File blender = InstalledFileLocator.getDefault().locate("../blender/2.64", null, false);
if (blender == null) { if (blender == null) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message("Error finding Blender!")); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message("Error finding Blender settings at\n" + blender.getPath()));
logger.log(Level.SEVERE, "Error finding Blender settings at {0}", blender.getPath());
} }
return blender; return blender;
} }
@ -56,28 +62,64 @@ public class BlenderTool {
// } // }
File blender = InstalledFileLocator.getDefault().locate("../blender", null, false); File blender = InstalledFileLocator.getDefault().locate("../blender", null, false);
if (blender == null) { if (blender == null) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message("Error finding Blender!")); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message("Error finding Blender root folder at\n" + blender.getPath()));
logger.log(Level.SEVERE, "Error finding Blender root folder at {0}", blender.getPath());
} }
return blender; return blender;
} }
public static boolean openInBlender(FileObject file){ public static boolean openInBlender(FileObject file) {
String path = file.getPath().replace("/", File.separator); String path = file.getPath().replace("/", File.separator);
return runBlender(path, true); return runBlender(path, true);
} }
private static void setBlendWin(Window win) {
blenderWindow = win;
}
public static boolean blenderToFront() {
Window win = blenderWindow;
if (win != null) {
logger.log(Level.INFO, "Request focus of Blender window {0}", win);
win.requestFocus();
return true;
}
return false;
}
public static boolean runBlender(final String options, boolean async) { public static boolean runBlender(final String options, boolean async) {
logger.log(Level.INFO, "Try running blender with options {0}", options);
if (running) { if (running) {
logger.log(Level.INFO, "Blender seems to be running");
return false; return false;
} }
blenderWindow = null;
running = true; running = true;
//TODO: wtf, for some reason i cannot access AtomicBoolean.. //TODO: wtf, for some reason i cannot access AtomicBoolean..
final Vector3f v = new Vector3f(0, 0, 0); final Vector3f v = new Vector3f(0, 0, 0);
final File exe = getBlenderExecutable(); final File exe = getBlenderExecutable();
if (exe == null) { if (exe == null) {
logger.log(Level.SEVERE, "Could not find blender executable!");
running = false;
return false; return false;
} }
final Frame mainWin = WindowManager.getDefault().getMainWindow();
assert (mainWin != null);
logger.log(Level.INFO, "Adding focus listener to window {0}", mainWin);
// mainWin.addWindowFocusListener(new WindowFocusListener() {
// public void windowGainedFocus(WindowEvent e) {
// }
//
// public void windowLostFocus(WindowEvent e) {
// Window blendWin = e.getOppositeWindow();
// logger.log(Level.INFO, "Lost focus to window {0}, use as Blender window", blendWin);
// setBlendWin(blendWin);
// mainWin.removeWindowFocusListener(this);
// logger.log(Level.INFO, "Remove focus listener from window {0}", mainWin);
// }
// });
mainWin.setState(Frame.ICONIFIED);
Runnable r = new Runnable() { Runnable r = new Runnable() {
public void run() { public void run() {
try { try {
@ -89,9 +131,7 @@ public class BlenderTool {
} }
Process proc = Runtime.getRuntime().exec(command); Process proc = Runtime.getRuntime().exec(command);
OutputReader outReader = new OutputReader(proc.getInputStream()); OutputReader outReader = new OutputReader(proc.getInputStream());
// outReader.setProgress(handle);
OutputReader errReader = new OutputReader(proc.getErrorStream()); OutputReader errReader = new OutputReader(proc.getErrorStream());
// errReader.setProgress(handle);
outReader.start(); outReader.start();
errReader.start(); errReader.start();
try { try {
@ -102,10 +142,22 @@ public class BlenderTool {
if (proc.exitValue() != 0) { if (proc.exitValue() != 0) {
v.x = 1; v.x = 1;
} }
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
mainWin.setState(Frame.NORMAL);
}
});
blenderWindow = null;
running = false; running = false;
} catch (IOException ex) { } catch (IOException ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
v.x = 1; v.x = 1;
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
mainWin.setState(Frame.NORMAL);
}
});
blenderWindow = null;
running = false; running = false;
} }
} }
@ -123,8 +175,13 @@ public class BlenderTool {
} }
public static void runBlender() { public static void runBlender() {
if(!runBlender(null, true)){ if (!runBlender(null, true)) {
DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message("Error running Blender.")); logger.log(Level.INFO, "Could not run blender, already running? Trying to focus window.");
if (!blenderToFront()) {
logger.log(Level.INFO, "Could not bring blender to front.");
} else {
logger.log(Level.INFO, "Requested Blender window focus.");
}
} }
} }
} }

@ -17,6 +17,7 @@ import org.netbeans.api.progress.ProgressHandle;
*/ */
public class OutputReader implements Runnable { public class OutputReader implements Runnable {
private static final Logger logger = Logger.getLogger(OutputReader.class.getName());
private Thread thread; private Thread thread;
private BufferedReader in; private BufferedReader in;
private ProgressHandle progress; private ProgressHandle progress;
@ -42,7 +43,7 @@ public class OutputReader implements Runnable {
if (progress != null) { if (progress != null) {
progress.progress(line); progress.progress(line);
} else { } else {
Logger.getLogger(OutputReader.class.getName()).log(Level.INFO, "{0}",line); logger.log(Level.INFO, "{0}", line);
} }
} }
} }

Loading…
Cancel
Save