Package jsynoptic.base

Source Code of jsynoptic.base.Template$TemplatePanel

/* ========================
* 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: Template.java,v 1.3 2008/07/22 09:14:52 ogor Exp $
*
* Changes
* -------
* 25 february 2008 : Initial public release (CC);
*
*/
package jsynoptic.base;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.swing.Icon;

import simtools.diagram.DiagramComponent;
import simtools.ui.MenuResourceBundle;
import simtools.ui.GridBagPanel;
import simtools.ui.ResourceFinder;
import jsynoptic.ui.JSynoptic;
import jsynoptic.ui.ShapesContainer;


/**
*
* A template class is a JSynoptic sheets factory.
* A template is able to create a unique kind of shape containers.
*
* Note: When creating a new sheet, user can be asked to select a template for sheet creation.
* A template can provide a option panel to customize template parameters.
* @author zxpletran007
*
*/
public abstract class Template {

    public static MenuResourceBundle resources = ResourceFinder.getMenu(Template.class);
   
   
    /**
     * The list of all known templates.
     */
    protected static List templates = new ArrayList();
   
    /**
     * The current used Template
     */
    protected static Template currentTemplate;
   
    /**
     * The default template
     */
    protected static Template defaultTemplate;
    static{
        defaultTemplate = new EmptySheetTemplate();
        templates.add(defaultTemplate);
        currentTemplate = defaultTemplate;
    }

    public static Template getTemplateFromId(String id) {
        if (templates != null) {
            for (Iterator it = templates.iterator(); it.hasNext(); ) {
                Template t = (Template)it.next();
                if ((t.getName()!=null) &&(t.getName().equals(id)))
                    return t;
            }
        }
        return null;
    }
   
    /**
     * The Template is asked to create a new sheet
     * Note: the newly created sheet will be inserted in the desktopCard panel.
     * @param name, the sheet name
     * @return The created sheet
     */
    public ShapesContainer createShapeContainer(String name){
       
        // Get panel properties
        TemplatePanel templatePanel = getOptionPanelForTemplate();
        if (templatePanel != null){
            templatePanel.getProperties();
        }
       
        // create the sheet
        ShapesContainer sc = new ShapesContainer(name);
       
        // Sheet dimensions - In case we are in Page Display Mode, we can get page dimension from DiagramComponent class
        // Otherwise, we consider the editor panel dimensions
        int height, width;
        if (DiagramComponent.isPrintViewEnabled()){
            height = DiagramComponent.getPageHeight();
            width = DiagramComponent.getPageWidth();
           
        } else {
            height = JSynoptic.gui.getFilePanel().getHeight() 46;        // 18 =  width taken by panel bordures
            width = JSynoptic.gui.getFilePanel().getWidth() - 18;       // 46 =  height taken by panel bordures   
        }
      
        sc.getComponent().setDiagramSize(width,height);
       
        // set the sheet
        setShapeContainer(sc);
       
        return sc;
    }
   
   
    /**
     * Set the shape container.
     * Shall be overloaded
     * @param sc
     */
    public void setShapeContainer(ShapesContainer sc){
        // by default, do nothing
    }
   
   

    /**
     * Enables a template to show an option panel
     * to customize template parameters.
     * 
     * @return a component to display
     */
    public TemplatePanel getOptionPanelForTemplate(){
        return  null;
    }


    /**
     * Get template name
     * @return template name
     */
    public abstract String getName();
   
    /**
     * It is possible to attach an icon to the template
     * @return
     */
    public Icon getIcon(){
        return resources.getIcon("templateIcon");
    }
   
    /**
     * Provides information about the template utilization
     * @return
     */
    public abstract String getTemplateInformation();


    /**
     * @return  - the list of templates
     */
    public static List getTemplates() {
        return templates;
    }


    /**
     * @return - the current used template
     * if null, set the current template with the default empty template.
     */
    public static Template getCurrentTemplate() {
        if ( currentTemplate == null ){
            currentTemplate = defaultTemplate;
        }
        return currentTemplate;
    }
   
    /**
     * @param currentTemplate
     */
    public static void setCurrentTemplate(Template currentTemplate) {
        Template.currentTemplate = currentTemplate;
    }
   
    public String toString(){
        return getName();
    }
   
   
   
    public static class EmptySheetTemplate extends Template {
  
        public ShapesContainer createShapeContainer(String name){
            return new ShapesContainer(name);
        }

        public String getName(){
            return resources.getString("emptySheetTemplate");
        }

        public String getTemplateInformation(){
            return resources.getString("emptySheetTemplateInformation");
        }
    }
 
    /**
     * The optional panel related to the current template.
     * @author zxpletran007
     *
     */
    protected abstract class TemplatePanel extends GridBagPanel {

        public TemplatePanel(String title) {
            super(title);
        }

        public TemplatePanel() {
            super();
        }
       
        /**
         * Set Template from GUI element values
         */
        public abstract void getProperties();
    }
}
TOP

Related Classes of jsynoptic.base.Template$TemplatePanel

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.
d', 'pageview');