/*
* InitEventScreen.java
*
* Created on 30 nov. 2011, 22:00:31
*/
package editor.screen.popup;
import beans.serializable.EventBloc;
import beans.enumeration.EventBlocType;
import beans.core.GeneralConstant;
import beans.serializable.Objet;
import java.awt.Point;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import editor.model.EditorModel;
import editor.model.EventModel;
/**
* Fenetre de creation d'un evenement
* @author mastersnes
*/
public class InitEventScreen extends javax.swing.JFrame {
private boolean playerPosition;
private final EventModel eventModel;
private JPanel currentPanel;
/**
* Constructeur de la fenetre
* @param editorModel
* @param position
* @see EditorModel
*/
public InitEventScreen(final EditorModel editorModel, final Point position) {
this.eventModel = new EventModel(editorModel, position);
initComponents();
currentPanel = eventModel.getOnScreen();
sousFrame.setContentPane(currentPanel);
this.setVisible(true);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
contentField.setEnabled(false);
positionFieldX.setEnabled(false);
positionFieldX.setText(String.valueOf(position.x));
positionFieldY.setEnabled(false);
positionFieldY.setText(String.valueOf(position.y));
playerPosition = false;
}
/**
* Constructeur de la fenetre avec chargement d'un evenement deja existant
* @param editorModel
* @param position
* @param eventBloc
* @see EditorModel
* @see EventBloc
*/
public InitEventScreen(final EditorModel editorModel, Point position, final EventBloc eventBloc) {
this.eventModel = new EventModel(editorModel, position, eventBloc);
initComponents();
currentPanel = eventModel.getOnScreen();
sousFrame.setContentPane(currentPanel);
this.setVisible(true);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
contentField.setEnabled(false);
positionFieldX.setEnabled(false);
positionFieldX.setText(String.valueOf(position.x));
positionFieldY.setEnabled(false);
positionFieldY.setText(String.valueOf(position.y));
activeBox.setSelected(eventBloc.getIdActive() != null);
activeField.setText(eventBloc.getIdActive());
cycliqueBox.setSelected(eventBloc.isCyclique());
idField.setText(eventBloc.getId());
automatiqueBox.setSelected(eventBloc.isAutomatique());
contentBox.setSelected(!eventBloc.getContent().isEmpty());
if (!eventBloc.getContent().isEmpty()) {
contentField.setText(eventBloc.getContent().get(0).getName());
}
imageField.setText(eventBloc.getImagePath());
playerPosition = false;
}
/** 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() {
jPanel2 = new javax.swing.JPanel();
typeLabel = new javax.swing.JLabel();
typeBox = new javax.swing.JComboBox();
sousFrame = new javax.swing.JInternalFrame();
confirmerButton = new javax.swing.JButton();
annuleButton = new javax.swing.JButton();
idLabel = new javax.swing.JLabel();
idField = new javax.swing.JTextField();
automatiqueBox = new javax.swing.JCheckBox();
contentBox = new javax.swing.JCheckBox();
contentField = new javax.swing.JTextField();
imageLabel = new javax.swing.JLabel();
imageField = new javax.swing.JTextField();
parcourirButton = new javax.swing.JButton();
positionLabel = new javax.swing.JLabel();
positionFieldX = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
positionFieldY = new javax.swing.JTextField();
cycliqueBox = new javax.swing.JCheckBox();
activeBox = new javax.swing.JCheckBox();
activeField = new javax.swing.JTextField();
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
typeLabel.setText("Configuration du mode :");
typeBox.setModel(new javax.swing.DefaultComboBoxModel(EventBlocType.values()));
typeBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
typeBoxItemStateChanged(evt);
}
});
sousFrame.setVisible(true);
javax.swing.GroupLayout sousFrameLayout = new javax.swing.GroupLayout(sousFrame.getContentPane());
sousFrame.getContentPane().setLayout(sousFrameLayout);
sousFrameLayout.setHorizontalGroup(
sousFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 566, Short.MAX_VALUE)
);
sousFrameLayout.setVerticalGroup(
sousFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 464, Short.MAX_VALUE)
);
confirmerButton.setText("Confirmer");
confirmerButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
confirmerButtonActionPerformed(evt);
}
});
annuleButton.setText("Annuler");
annuleButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
annuleButtonActionPerformed(evt);
}
});
idLabel.setText("id : ");
automatiqueBox.setText("automatique?");
contentBox.setText("Possede?");
contentBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
contentBoxItemStateChanged(evt);
}
});
imageLabel.setText("image(on puis off) : ");
parcourirButton.setText("Parcourir");
parcourirButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
parcourirButtonActionPerformed(evt);
}
});
positionLabel.setText("position : ");
jLabel5.setText("x");
cycliqueBox.setText("cyclique");
activeBox.setText("active (id) : ");
activeBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
activeBoxItemStateChanged(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)
.addGroup(layout.createSequentialGroup()
.addComponent(cycliqueBox)
.addContainerGap())
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(sousFrame)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(idLabel)
.addGap(18, 18, 18)
.addComponent(idField, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(89, 89, 89)
.addComponent(confirmerButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 218, Short.MAX_VALUE)
.addComponent(annuleButton)
.addGap(137, 137, 137)))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(positionLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(positionFieldX, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(positionFieldY))
.addComponent(typeLabel, javax.swing.GroupLayout.Alignment.LEADING))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(typeBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 226, Short.MAX_VALUE)
.addComponent(contentBox))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(184, 184, 184)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(imageLabel)
.addComponent(activeBox))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(activeField, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(imageField, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(parcourirButton)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(automatiqueBox)
.addComponent(contentField, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(24, 24, 24)))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(idLabel)
.addComponent(idField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(automatiqueBox))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(typeLabel)
.addComponent(typeBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(contentField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(contentBox))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(imageLabel)
.addComponent(imageField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(parcourirButton))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(positionLabel)
.addComponent(positionFieldX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(positionFieldY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cycliqueBox)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(activeBox)
.addComponent(activeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(27, 27, 27)
.addComponent(sousFrame, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(confirmerButton)
.addComponent(annuleButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void typeBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_typeBoxItemStateChanged
final EventBlocType currentEventType = (EventBlocType) typeBox.getSelectedItem();
switch (currentEventType) {
case ON:
activeAll();
playerPosition = false;
currentPanel = eventModel.getOnScreen();
break;
case OFF:
activeAll();
playerPosition = false;
currentPanel = eventModel.getOffScreen();
break;
case PLAYER_POSITION:
playerPosition = true;
desactiveAll();
break;
}
sousFrame.setContentPane(currentPanel);
}//GEN-LAST:event_typeBoxItemStateChanged
private void annuleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_annuleButtonActionPerformed
this.dispose();
}//GEN-LAST:event_annuleButtonActionPerformed
private void confirmerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmerButtonActionPerformed
final String id = idField.getText();
final boolean automatique = automatiqueBox.isSelected();
final List<Objet> content = new ArrayList<Objet>();
if (contentBox.isSelected()) {
String[] contentParser = contentField.getText().split(",");
for (int i = 0; i < contentParser.length; i++) {
content.add((Objet) GeneralConstant.deSerialize(GeneralConstant.SAVE_OBJECT_PATH + contentParser[i]));
}
}
final String imagePath = imageField.getText();
final boolean cyclique = cycliqueBox.isSelected();
String idActive = null;
if (activeBox.isSelected()) {
idActive = activeField.getText();
}
eventModel.submitResponse(id, automatique, content, imagePath, cyclique, idActive, playerPosition);
this.dispose();
}//GEN-LAST:event_confirmerButtonActionPerformed
private void contentBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_contentBoxItemStateChanged
if (contentBox.isSelected()) {
contentField.setEnabled(true);
} else {
contentField.setEnabled(false);
}
}//GEN-LAST:event_contentBoxItemStateChanged
private void parcourirButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_parcourirButtonActionPerformed
final JFileChooser fileChooser = new JFileChooser(new File(GeneralConstant.TILESET_PATH));
fileChooser.showOpenDialog(this);
if (fileChooser.getSelectedFile() != null) {
imageField.setText(GeneralConstant.TILESET_PATH + fileChooser.getSelectedFile().getName());
}
}//GEN-LAST:event_parcourirButtonActionPerformed
private void activeBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_activeBoxItemStateChanged
if (activeBox.isSelected()) {
activeField.setEnabled(true);
} else {
activeField.setEnabled(false);
}
}//GEN-LAST:event_activeBoxItemStateChanged
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox activeBox;
private javax.swing.JTextField activeField;
private javax.swing.JButton annuleButton;
private javax.swing.JCheckBox automatiqueBox;
private javax.swing.JButton confirmerButton;
private javax.swing.JCheckBox contentBox;
private javax.swing.JTextField contentField;
private javax.swing.JCheckBox cycliqueBox;
private javax.swing.JTextField idField;
private javax.swing.JLabel idLabel;
private javax.swing.JTextField imageField;
private javax.swing.JLabel imageLabel;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel2;
private javax.swing.JButton parcourirButton;
private javax.swing.JTextField positionFieldX;
private javax.swing.JTextField positionFieldY;
private javax.swing.JLabel positionLabel;
private javax.swing.JInternalFrame sousFrame;
private javax.swing.JComboBox typeBox;
private javax.swing.JLabel typeLabel;
// End of variables declaration//GEN-END:variables
private void desactiveAll() {
activeBox.setVisible(false);
activeField.setVisible(false);
automatiqueBox.setVisible(false);
contentBox.setVisible(false);
contentField.setVisible(false);
cycliqueBox.setVisible(false);
imageField.setVisible(false);
typeLabel.setVisible(false);
imageLabel.setVisible(false);
jLabel5.setVisible(false);
parcourirButton.setVisible(false);
sousFrame.setVisible(false);
idLabel.setVisible(false);
idField.setVisible(false);
}
private void activeAll() {
activeBox.setVisible(true);
activeField.setVisible(true);
automatiqueBox.setVisible(true);
contentBox.setVisible(true);
contentField.setVisible(true);
cycliqueBox.setVisible(true);
imageField.setVisible(true);
typeLabel.setVisible(true);
imageLabel.setVisible(true);
jLabel5.setVisible(true);
parcourirButton.setVisible(true);
sousFrame.setVisible(true);
idLabel.setVisible(false);
idField.setVisible(false);
}
}