-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
privatized Registry.scene and added listener.
- Loading branch information
1 parent
d9484ab
commit 69e8d53
Showing
12 changed files
with
246 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/marginallyclever/ro3/SceneChangeListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.marginallyclever.ro3; | ||
|
||
import com.marginallyclever.ro3.node.Node; | ||
|
||
import java.util.EventListener; | ||
|
||
public interface SceneChangeListener extends EventListener { | ||
void beforeSceneChange(Node oldScene); | ||
void afterSceneChange(Node newScene); | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/marginallyclever/ro3/actions/ImportScene.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.marginallyclever.ro3.actions; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.marginallyclever.ro3.Registry; | ||
import com.marginallyclever.ro3.node.Node; | ||
import com.marginallyclever.robotoverlord.RobotOverlord; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Load a Scene into the existing Scene. | ||
*/ | ||
public class ImportScene extends AbstractAction { | ||
private static final JFileChooser chooser = new JFileChooser(); | ||
private static final Logger logger = LoggerFactory.getLogger(ImportScene.class); | ||
|
||
public ImportScene() { | ||
super("Import Scene"); | ||
} | ||
|
||
/** | ||
* Invoked when an action occurs. | ||
* | ||
* @param e the event to be processed | ||
*/ | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
chooser.setFileFilter(RobotOverlord.FILE_FILTER); | ||
|
||
Component source = (Component) e.getSource(); | ||
JFrame parentFrame = (JFrame)SwingUtilities.getWindowAncestor(source); | ||
if (chooser.showOpenDialog(parentFrame) == JFileChooser.APPROVE_OPTION) { | ||
loadIntoScene(chooser.getSelectedFile()); | ||
} | ||
} | ||
|
||
private void loadIntoScene(File selectedFile) { | ||
logger.info("Import scene from {}",selectedFile.getAbsolutePath()); | ||
|
||
// Create an ObjectMapper instance | ||
ObjectMapper mapper = new ObjectMapper(); | ||
|
||
try { | ||
// Read the JSON file and convert it into a Node object | ||
Node loaded = mapper.readValue(selectedFile, Node.class); | ||
|
||
// option 1: add the loaded scene to the current scene. | ||
Registry.getScene().addChild(loaded); | ||
// TODO option 2: copy the loaded scene into the currently selected Nodes of the NodeTreeView? | ||
} catch (IOException e) { | ||
logger.error("Error loading scene from JSON", e); | ||
} | ||
|
||
logger.error("Import scene not implemented yet."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.