/*
* ExportSessionDialog.java
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2009–2012 Steinbeis Forschungszentrum (STZ Ölbronn),
* Copyright (c) 2007–2012 by Michael Hoffer
*
* This file is part of VRL-Studio.
*
* VRL-Studio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* as published by the Free Software Foundation.
*
* see: http://opensource.org/licenses/LGPL-3.0
* file://path/to/VRL/src/eu/mihosoft/vrl/resources/license/lgplv3.txt
*
* VRL-Studio 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.
*
* This version of VRL-Studio includes copyright notice and attribution requirements.
* According to the LGPL this information must be displayed even if you modify
* the source code of VRL-Studio. Neither the VRL Canvas attribution icon nor any
* copyright statement/attribution may be removed.
*
* Attribution Requirements:
*
* If you create derived work you must do three things regarding copyright
* notice and author attribution.
*
* First, the following text must be displayed on the Canvas:
* "based on VRL source code". In this case the VRL canvas icon must be removed.
*
* Second, keep the links to "About VRL-Studio" and "About VRL". The
* copyright notice must remain.
*
* Third, add an additional notice, stating that you modified VRL. In addition
* you must cite the publications listed below. A suitable notice might read
* "VRL source code modified by YourName 2012".
*
* Note, that these requirements are in full accordance with the LGPL v3
* (see 7. Additional Terms, b).
*
* Publications:
*
* M. Hoffer, C.Poliwoda, G.Wittum. Visual Reflection Library -
* A Framework for Declarative GUI Programming on the Java Platform.
* Computing and Visualization in Science, 2011, in press.
*/
package eu.mihosoft.vrlstudio.main;
import eu.mihosoft.vrl.animation.AnimationTask;
//import eu.mihosoft.vrlstudio.io.SessionExporter;
import eu.mihosoft.vrl.reflection.VisualCanvas;
import eu.mihosoft.vrl.visual.MessageType;
import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
/**
*
* @author Michael Hoffer <info@michaelhoffer.de>
*/
public class ExportSessionDialog extends javax.swing.JFrame {
private VisualCanvas mainCanvas;
private JFrame parentFrame;
private String currentFileName;
/** Creates new form ExportSessionDialog */
public ExportSessionDialog() {
initComponents();
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
modeComboBox.addItem("view");
modeComboBox.addItem("move");
modeComboBox.addItem("connect");
modeComboBox.addItem("create");
modeComboBox.addItem("full-player");
modeComboBox.addItem("edit");
modeComboBox.addItem("full-edit");
// setLocation(
// (screenDim.width - this.getWidth()) / 4,
// (screenDim.height - this.getHeight()) / 4);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
enable3DCheckBox = new javax.swing.JCheckBox();
modeComboBox = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
ExportButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Export Session:");
setLocationByPlatform(true);
enable3DCheckBox.setSelected(true);
enable3DCheckBox.setText("enable 3D rendering");
enable3DCheckBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
enable3DCheckBoxActionPerformed(evt);
}
});
jLabel2.setText("Player Mode:");
jLabel3.setText("Rendering:");
ExportButton.setText("Export");
ExportButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ExportButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(ExportButton, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(modeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(enable3DCheckBox))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(modeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(enable3DCheckBox)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(ExportButton)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void enable3DCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enable3DCheckBoxActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_enable3DCheckBoxActionPerformed
private void ExportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExportButtonActionPerformed
// TODO add your handling code here:
mainCanvas.getEffectPane().
colorize(new Color(0, 0, 0, 120),
0, 0.3, new AnimationTask() {
@Override
public void firstFrameStarted() {
//
}
@Override
public void frameStarted(double time) {
//
}
@Override
public void lastFrameStarted() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
export();
ExportSessionDialog.this.setVisible(false);
mainCanvas.getEffectPane().
colorize(new Color(0, 0, 0, 0),
1, 0.3, null);
}
});
}
});
}//GEN-LAST:event_ExportButtonActionPerformed
private void export() {
// SessionExporter exporter = new SessionExporter();
// exporter.setMainCanvas(getMainCanvas());
String mode = (String) modeComboBox.getSelectedItem();
if (mode == null) {
mode = "";
}
String options = "-enable3d no";
if (enable3DCheckBox.isSelected()) {
options = "-enable3d yes";
}
String sessionFileName = getCurrentFileName();
if (sessionFileName == null) {
mainCanvas.getMessageBox().addMessage("Can't export session:",
"Please save the current session first to export it!",
MessageType.ERROR);
} else {
sessionFileName = sessionFileName.replaceAll("vrlx", "zip");
// try {
// exporter.export(mode,
// generateResolutionString(getParentFrame()),
// options, new File(sessionFileName));
// } catch (FileNotFoundException ex) {
// Logger.getLogger(ExportSessionDialog.class.getName()).
// log(Level.SEVERE, null, ex);
// } catch (IOException ex) {
// Logger.getLogger(ExportSessionDialog.class.getName()).
// log(Level.SEVERE, null, ex);
// } catch (Exception ex) {
// Logger.getLogger(ExportSessionDialog.class.getName()).
// log(Level.SEVERE, null, ex);
// }
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new ExportSessionDialog().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton ExportButton;
private javax.swing.JCheckBox enable3DCheckBox;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JComboBox modeComboBox;
// End of variables declaration//GEN-END:variables
/**
* @return the mainCanvas
*/
public VisualCanvas getMainCanvas() {
return mainCanvas;
}
/**
* @param mainCanvas the mainCanvas to set
*/
public void setMainCanvas(VisualCanvas mainCanvas) {
this.mainCanvas = mainCanvas;
}
private String generateResolutionString(JFrame frame) {
return frame.getSize().width + "x" + frame.getSize().height;
}
/**
* @return the parentFrame
*/
public JFrame getParentFrame() {
return parentFrame;
}
/**
* @param parentFrame the parentFrame to set
*/
public void setParentFrame(JFrame parentFrame) {
this.parentFrame = parentFrame;
}
/**
* @return the currentFileName
*/
public String getCurrentFileName() {
return currentFileName;
}
/**
* @param currentFileName the currentFileName to set
*/
public void setCurrentFileName(String currentFileName) {
this.currentFileName = currentFileName;
}
public void centerDialog(JFrame parentFrame) {
this.setLocation(
parentFrame.getLocation().x +
parentFrame.getWidth() / 2 - this.getWidth() / 2,
parentFrame.getLocation().y +
parentFrame.getHeight() / 2 - this.getHeight() / 2);
}
}