/**
* Project Wonderland
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., All Rights Reserved
*
* Redistributions in source code form must reproduce the above
* copyright and this condition.
*
* The contents of this file are subject to the GNU General Public
* License, Version 2 (the "License"); you may not use this file
* except in compliance with the License. A copy of the License is
* available at http://www.opensource.org/licenses/gpl-license.php.
*
* Sun designates this particular file as subject to the "Classpath"
* exception as provided by Sun in the License file that accompanied
* this code.
*/
package org.jdesktop.wonderland.modules.jmecolladaloader.client;
import java.util.ResourceBundle;
import javax.swing.JPanel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.jdesktop.wonderland.client.cell.properties.CellPropertiesEditor;
import org.jdesktop.wonderland.client.cell.properties.annotation.PropertiesFactory;
import org.jdesktop.wonderland.client.cell.properties.spi.PropertiesFactorySPI;
import org.jdesktop.wonderland.common.cell.state.CellComponentServerState;
import org.jdesktop.wonderland.common.cell.state.CellServerState;
import org.jdesktop.wonderland.modules.jmecolladaloader.common.cell.state.JmeColladaCellComponentServerState;
/**
*
* @author Jordan Slott <jslott@dev.java.net>
* @author Ronny Standtke <ronny.standtke@fhnw.ch>
*/
@PropertiesFactory(JmeColladaCellComponentServerState.class)
public class JmeColladaCellComponentProperties
extends JPanel implements PropertiesFactorySPI {
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle(
"org/jdesktop/wonderland/modules/jmecolladaloader/client/Bundle");
private CellPropertiesEditor editor;
private String originalInfo;
/** Creates new form SampleComponentProperties */
public JmeColladaCellComponentProperties() {
// Initialize the GUI
initComponents();
// Listen for changes to the info text field
urlTF.getDocument().addDocumentListener(new InfoTextFieldListener());
}
/**
* @inheritDoc()
*/
public String getDisplayName() {
return BUNDLE.getString("Model_Info_Collada");
}
/**
* @inheritDoc()
*/
public JPanel getPropertiesJPanel() {
return this;
}
/**
* @inheritDoc()
*/
public void setCellPropertiesEditor(CellPropertiesEditor editor) {
this.editor = editor;
}
/**
* @inheritDoc()
*/
public void open() {
CellServerState state = editor.getCellServerState();
CellComponentServerState compState = state.getComponentServerState(
JmeColladaCellComponentServerState.class);
if (state != null) {
originalInfo =
((JmeColladaCellComponentServerState) compState).getModel();
urlTF.setText(originalInfo);
}
}
/**
* @inheritDoc()
*/
public void close() {
// Do nothing for now.
}
/**
* @inheritDoc()
*/
public void apply() {
// Fetch the latest from the info text field and set it.
CellServerState state = editor.getCellServerState();
CellComponentServerState compState = state.getComponentServerState(
JmeColladaCellComponentServerState.class);
// Model is read only
// ((JmeColladaCellComponentServerState)compState).setModel(urlTF.getText());
editor.addToUpdateList(compState);
}
/**
* @inheritDoc()
*/
public void restore() {
// Restore from the original state stored.
urlTF.setText(originalInfo);
}
/**
* Inner class to listen for changes to the text field and fire off dirty
* or clean indications to the cell properties editor.
*/
class InfoTextFieldListener implements DocumentListener {
public void insertUpdate(DocumentEvent e) {
checkDirty();
}
public void removeUpdate(DocumentEvent e) {
checkDirty();
}
public void changedUpdate(DocumentEvent e) {
checkDirty();
}
private void checkDirty() {
if (editor != null) {
String name = urlTF.getText();
editor.setPanelDirty(JmeColladaCellComponentProperties.class,
!name.equals(originalInfo));
}
}
}
/** 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() {
jLabel1 = new javax.swing.JLabel();
urlTF = new javax.swing.JTextField();
jLabel1.setText("URL");
urlTF.setEditable(false);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(urlTF, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(urlTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(252, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField urlTF;
// End of variables declaration//GEN-END:variables
}