Commit 29066317 authored by Valérie Maquil's avatar Valérie Maquil

added file chooser (GUI) to select xml file

parent 73686f34
......@@ -27,13 +27,13 @@ cursor.id.remapping.constant = 1024
adapter.class = lu.list.itis.dkd.tui.adapter.TuioAdapter
# The location and name of the root bootstrapping file.
bootstrapping.root = test/Windmill(4).xml
bootstrapping.root = circuit_scenario.xml
# Properties for the equation system
scriptEngine.executable = C:/Octave/Octave-3.8.2/bin/octave.exe
scriptEngine.workingDir = model
equation.system = test/Windmill(4).xml
scenario.description = test/Windmill(4).xml
equation.system = circuit_scenario.xml
scenario.description = circuit_scenario.xml
# Properties for the Logger
logger.event.output.location = log.txt
logger.event.output.enabled = false
logger.level = ALL
logger.event.configuration = logger.xml
# Widget IDs to be mapped
# Properties for calibrating the interface
frameTitle = NUI Application
windowWidth = 1920
windowHeight = 1080
fullScreen = false
font = Arial
fontSize = 13
colour = BLACK
centred = false
# Properties for the calibration of the object manager
#The value below is best left at or above 1024
cursor.id.remapping.constant = 1024
# The low-level computer vision (or similar) adapter to load.
# Syntax is : adapter.class = packageName.ClassName
adapter.class = lu.list.itis.dkd.tui.adapter.TuioAdapter
# The location and name of the root bootstrapping file.
bootstrapping.root = light_scenario.xml
# Properties for the equation system
scriptEngine.executable = C:/Octave/Octave-3.8.2/bin/octave.exe
scriptEngine.workingDir = model
equation.system = light_scenario.xml
scenario.description = light_scenario.xml
/**
* Copyright Luxembourg Institute of Science and Technology, 2016.
*
* This file is part of TULIP.
*
* TULIP is licensed under a dual-licensing scheme. For non-commercial purposes, the LGPL version 3,
* as stated below, is applicable. For all commercial purposes TULIP is licensed under a LIST
* proprietary license. Please contact LIST at tto@list.lu to obtain a commercial license.
*
* For all non-commercial purposes, TULIP is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, version 3 of the License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.scenario;
import lu.list.itis.dkd.tui.exception.BuildException;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* @author Valrie Maquil
*
*/
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.filechooser.FileNameExtensionFilter;
public class FileChooser extends JPanel
implements ActionListener {
/** */
private static final long serialVersionUID = 1L;
static private final String newline = "\n"; //$NON-NLS-1$
JButton openButton, startButton;
JLabel log;
JFileChooser fc;
File file;
public FileChooser() {
super(new GridLayout(2, 1));
log = new JLabel(""); //$NON-NLS-1$
// Create a file chooser
fc = new JFileChooser("."); //$NON-NLS-1$
final FileNameExtensionFilter filter = new FileNameExtensionFilter("Microworld XML file", "xml"); //$NON-NLS-1$//$NON-NLS-2$
fc.setFileFilter(filter);
// Create the open button. We use the image from the JLF
// Graphics Repository (but we extracted it from the jar).
openButton = new JButton("Select File"); //$NON-NLS-1$
openButton.addActionListener(this);
// Create the save button. We use the image from the JLF
// Graphics Repository (but we extracted it from the jar).
startButton = new JButton("Start Microworld"); //$NON-NLS-1$
startButton.addActionListener(this);
startButton.setEnabled(false);
// For layout purposes, put the buttons in a separate panel
final JPanel buttonPanel1 = new JPanel(); // use FlowLayout
buttonPanel1.add(openButton);
buttonPanel1.add(log);
final JPanel buttonPanel2 = new JPanel();
buttonPanel2.add(startButton);
add(buttonPanel1);
add(buttonPanel2);
}
@Override
public void actionPerformed(ActionEvent e) {
// Handle open button action.
if (e.getSource() == openButton) {
final int returnVal = fc.showOpenDialog(FileChooser.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = fc.getSelectedFile();
log.setText(file.getName() + " selected"); //$NON-NLS-1$
startButton.setEnabled(true);
} else {}
} else if (e.getSource() == startButton) {
try {
final Scenario scenario = new Scenario("scenario.properties", file.getPath());
} catch (final BuildException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// log.setCaretPosition(log.getDocument().getLength());
}
}
/**
* Create the GUI and show it. For thread safety, this method should be invoked from the event
* dispatch thread.
*/
private static void createAndShowGUI() {
// Create and set up the window.
final JFrame frame = new JFrame("Load Microworld"); //$NON-NLS-1$
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Add content to the window.
frame.add(new FileChooser());
frame.setMinimumSize(new Dimension(350, 150));
// set to center
final Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation(dim.width / 3, dim.height / 3);
// Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
// Schedule a job for the event dispatch thread:
// creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// Turn off metal's use of bold fonts
UIManager.put("swing.boldMetal", Boolean.FALSE); //$NON-NLS-1$
createAndShowGUI();
}
});
}
}
......@@ -40,6 +40,7 @@ import com.google.common.base.Preconditions;
import java.io.File;
import java.util.Map;
import java.util.Properties;
/**
* Class used to run a tangible scenario. It uses bootstrappers to initialize all the necessary
......@@ -57,6 +58,7 @@ public class Scenario {
private static Map<String, Variable> outputs;
private EquationSystemBuilder equationSystemBuilder;
Properties properties;
private TangibleApplication tangibleApplication;
......@@ -91,6 +93,36 @@ public class Scenario {
tangibleApplication.connect();
}
public Scenario(String file, String filename) throws BuildException {
properties = PropertiesFetcher.fetchProperties(file);
properties.setProperty("equation.system", filename); //$NON-NLS-1$
properties.setProperty("bootstrapping.root", filename); //$NON-NLS-1$
properties.setProperty("scenario.description", filename); //$NON-NLS-1$
try {
equationSystemBuilder = new EquationSystemBuilder();
equationSystemBuilder.parseEquationFile(new File(properties.getProperty("equation.system"))); //$NON-NLS-1$
} catch (final EquationSystemException exception) {
throw new BuildException("The equation system for this scenario could not be built!", exception); //$NON-NLS-1$
}
inputs = equationSystemBuilder.getInputVariables();
outputs = equationSystemBuilder.getOutputVariables();
tangibleApplication = new TangibleApplicationBootstrapper(file);
populateVariables();
scenes = SceneBootstrapper.getScenes();
StageManager.setScenes(scenes);
tangibleApplication.setContentManager(StageManager.getInstance());
tangibleApplication.connect();
}
/**
* Method used to replace the placeholder variables in each widget with the variable as
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment