Package syn3d.ui

Source Code of syn3d.ui.SceneGraphDataUI

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This program 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;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program 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 this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2004, by :
*     Corporate:
*         Astrium SAS
*     Individual:
*         Claude Cazenave
*
* $Id: SceneGraphDataUI.java,v 1.20 2007/01/23 17:22:17 ogor Exp $
*
* Changes
* -------
* 3-Mar-2004 : Creation date (CC);
*
*/
package syn3d.ui;

import java.awt.Container;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.UIManager;


import syn3d.base.ActiveNode;
import syn3d.data.SceneGraphData;
import simtools.ui.MenuResourceBundle;
import simtools.ui.SourceTree;

/**
* Class description ...
*
* @author Claude CAZENAVE
*
*/
public abstract class SceneGraphDataUI implements ActionListener{

  protected SourceTree dstree;
  protected JTextField tf;
  protected JDialog dialog=null;
  protected JButton bok,bclose,bapply;
  protected JCheckBox bedit;
  protected JTextField nameField;
  protected ActiveNode node;
 
  protected static MenuResourceBundle resources=SceneGraphModel.resources;
 
  protected SceneGraphData data;
  protected SceneGraphData dataCopy;
 
  protected boolean transformAvailable;
 
  public SceneGraphDataUI(ActiveNode node, SceneGraphData d, boolean transformAvailable ){
    this.node = node;
    data=d;
    this.transformAvailable = transformAvailable;
    try {
      dataCopy=(SceneGraphData)data.clone();
    } catch (CloneNotSupportedException e) {
      throw new IllegalArgumentException();
    }
   
  }
 
  protected abstract JPanel createDataPanel();
 
  protected abstract JTable createTableDataPanel(SceneGraphData dataCopy);
 
  protected JScrollPane createSourcePanel(){
    dstree = SourceTree.getFromPool("SceneGraphDataChooser");
    dstree.setVisibleRowCount(12);
    JScrollPane dslistScrollPane = new JScrollPane(dstree);
    return dslistScrollPane;
  }
 
  protected JPanel createNamePanel(String name){

    JPanel p=new JPanel(new GridLayout(0,2));
    JLabel jpName = new JLabel(resources.getString("name"));
    nameField = new JTextField(name);
    p.add(jpName);
    p.add(nameField);
    return p;
  }
 
  protected JPanel createButtonPanel(){
    JPanel p=new JPanel();
    bapply = resources.getButton("applyButton", this);
    bclose = resources.getButton("closeButton", this);
    bok = resources.getButton("OKButton", this);
    p.add(bok);
    p.add(bapply);
    p.add(bclose);
    return p;
  }
 
  public JDialog createDialog(
    Frame parent,
    String title
    ) {
    if(dialog!=null){
      return null
    }
    dialog = new JDialog(parent, title, false);
 
    // TODO : should not be resizable if it worked correctly
    //dialog.setResizable(false);
     
    Container contentPane = dialog.getContentPane();

    contentPane.setLayout(new BorderLayout());
    contentPane.add(createSourcePanel(), BorderLayout.EAST);
   
   
    contentPane.add( new JScrollPane(createDataPanel(), JScrollPane.VERTICAL_SCROLLBAR_ALWAYS , JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ), BorderLayout.CENTER);
   
    contentPane.add(createNamePanel(node.getName()), BorderLayout.NORTH);
    contentPane.add(createButtonPanel(), BorderLayout.SOUTH);
    if (JDialog.isDefaultLookAndFeelDecorated()) {
      boolean supportsWindowDecorations =
        UIManager.getLookAndFeel().getSupportsWindowDecorations();
      if (supportsWindowDecorations) {
        dialog.setUndecorated(true);
        dialog.getRootPane().setWindowDecorationStyle(JRootPane.QUESTION_DIALOG);
      }
    }
    updateEditable();
    dialog.pack();
    dialog.setLocationRelativeTo(parent);
       
    return dialog;
  }

  public void updateEditable(){
    if (transformAvailable)
      bedit.setSelected(dataCopy.isEditable());
  }
  public void setEditable(boolean b){
    dataCopy.setEditable(b)
  }
 
  public void updateAllData(){
    if (transformAvailable) data.updateFrom(dataCopy);
     node.setName(nameField.getText());
  }
 
  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {
    if(e.getSource()==bok){
      synchronizeDataPanel();
      updateAllData();
      dialog.dispose();
      dispose();
    }
    else if(e.getSource()==bapply){
      synchronizeDataPanel();
      updateAllData();
      dialog.repaint()
    }
    else if(e.getSource()==bclose){
      dialog.dispose();
      dispose();
    }
    else if(e.getSource()==bedit){
      setEditable(bedit.isSelected());
      updateEditable();
      dialog.repaint()
    }
  }

  public abstract void synchronizeDataPanel();
 
  public void dispose() {
    dataCopy.dispose();
  }
 
}
TOP

Related Classes of syn3d.ui.SceneGraphDataUI

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.