Package simtools.ui.test

Source Code of simtools.ui.test.SplitTabPaneTest

/* ========================
* 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-2005, by :
*     Corporate:
*         EADS Astrium SAS
*         EADS CRC
*     Individual:
*         Claude Cazenave
*
* $Id: SplitTabPaneTest.java,v 1.2 2005/12/20 10:00:51 cazenave Exp $
*
* Changes
* -------
* 11 d�c. 2005 : Initial public release (CC);
*
*/
package simtools.ui.test;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JViewport;

import simtools.ui.SplitTabPane;
import simtools.ui.UserProperties;

/**
* A test class for the SplitTabPane
*/
public class SplitTabPaneTest extends SplitTabPane {

  public SplitTabPaneTest(Frame owner, int orientation) {
    super(owner, orientation, true, true);
  }
 
  public void print(){
    for (int i = 0; i < elements.size(); i++) {
      Element e=(Element)elements.get(i);
      System.out.println(e.getName()+" owned by "+e.getOwner());
    }
  }
  public Component add(Component c){
    int i=getElementIndex(c);
    if(i>=0){
      System.out.println("ROOT ADD "+getElement(c).getName());
    }
    else{
      System.out.println("ROOT ADD "+c);
    }
    return super.add(c);
   
  }
 
  public void changeElement(Component c, int newMode) {
    System.out.println("==============");
    if(firstSplitBorder!=null)
      System.out.println("FIRST="+getElement(firstSplitBorder.getComp()).getName());
    System.out.println("==============");
    Element e=getElement(c);
    System.out.println(e.getName()+" owned by "+e.getOwner());
    System.out.println("    =>");
    super.changeElement(c,newMode);
    e=getElement(c);
    System.out.println(e.getName()+" owned by "+e.getOwner());
    System.out.println("================================");
    print();
    System.out.println("==============");
    if(firstSplitBorder!=null)
      System.out.println("FIRST="+getElement(firstSplitBorder.getComp()).getName());
    System.out.println("==============");
  }


  /**
   * For testing purpose
   * @param args
   */
  public static void main(String[] args){
    final UserProperties userProperties=new UserProperties("splitTab");
    userProperties.read();

   
    javax.swing.JFrame f=new javax.swing.JFrame(SplitTabPane.class.getName());
   
    SplitTabPaneTest sts=new SplitTabPaneTest(f,JSplitPane.HORIZONTAL_SPLIT);
   
    addElement(sts, "one", TAB);

    f.getContentPane().add(sts,BorderLayout.SOUTH);
    System.out.println("SOUTH=====================");
    sts.print();

    SplitTabPaneTest stn=new SplitTabPaneTest(f,JSplitPane.HORIZONTAL_SPLIT);
   
    addElement(stn, "one", SPLIT);
    addElement(stn, "two", TAB);
    addElement(stn, "three", SPLIT);

    f.getContentPane().add(stn,BorderLayout.NORTH);
    System.out.println("NORTH=====================");
    stn.print();

    SplitTabPaneTest ste=new SplitTabPaneTest(f,JSplitPane.VERTICAL_SPLIT);
   
    addElement(ste, "one", TAB);
    addElement(ste, "two", TAB);

    f.getContentPane().add(ste,BorderLayout.EAST);
    System.out.println("EAST=====================");
    ste.print();

    SplitTabPaneTest stw=new SplitTabPaneTest(f,JSplitPane.VERTICAL_SPLIT);
   
    addElement(stw, "one", SPLIT);
    addElement(stw, "two", SPLIT);
    addElement(stw, "three", SPLIT);

    f.getContentPane().add(stw,BorderLayout.WEST);
    System.out.println("WEST=====================");
    stw.print();

    final SplitTabPaneTest stc=new SplitTabPaneTest(f,JSplitPane.VERTICAL_SPLIT);
   
    addElement(stc, "one", SPLIT);
    addElement(stc, "two", TAB);
    addElement(stc, "three", TAB);
    addElement(stc, "four", SPLIT);

    f.getContentPane().add(stc,BorderLayout.CENTER);
    System.out.println("CENTER=====================");
    stc.print();

    f.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
    f.addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent e) {
        stc.save(userProperties,"center");
        userProperties.write();
        System.exit(0);
      }
     
    });
    f.pack();
    stc.load(userProperties,"center");

    f.show();
   
  }
 
  private static int id=0;
 
  private static void addElement(SplitTabPane st, String name, int mode){
    JTextArea ta=new JTextArea(name+id, 5 , 4);
    id++;
    JScrollPane scroller = new JScrollPane(
        JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
        JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    JViewport port = scroller.getViewport();
    port.add(ta);
   
    st.addElement(scroller, name, mode);
  }

}
TOP

Related Classes of simtools.ui.test.SplitTabPaneTest

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.