Package jsynoptic.ui

Source Code of jsynoptic.ui.FiledDesktopCardPanel$FileCardPopupMenu

/* ========================
* 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-2003, by :
*     Corporate:
*         Astrium SAS
*         EADS CRC
*     Individual:
*         Nicolas Brodu
*
* $Id: FiledDesktopCardPanel.java,v 1.11 2007/11/20 15:50:54 ogor Exp $
*
* Changes
* -------
* 25-Sep-2003 : Initial public release (NB);
*
*/

package jsynoptic.ui;

import java.util.*;
import java.awt.event.ActionEvent;
import java.io.*;
import javax.swing.JComponent;
import javax.swing.JOptionPane;

import simtools.diagram.DiagramComponent;
import simtools.ui.*;

/**
* DesktopCardPanel extension that associates a file to each component
*
* @author Nicolas Brodu
*
* @version 1.0 2001
*/
public class FiledDesktopCardPanel extends DesktopCardPanel {

  protected Vector files;
 
   public FiledDesktopCardPanel(boolean scrollable) {
    super(scrollable);
    files = new Vector();
  }

  
    /* (non-Javadoc)
     * @see simtools.ui.DesktopCardPanel#removeAllComponents()
     */
    public void removeAllComponents() { 
        if (((JSynopticPanels)JSynoptic.gui).closeAll()){
            Object[] components = _components.toArray()
            for (int i = 0; i < components.length; i++){
                JComponent d = (JComponent) components[i];
                int index = indexOfComponent(d);
                super.removeComponent(d);
                files.remove(index);
            }
            repaint();
        }
    }
   
   /* (non-Javadoc)
    * @see simtools.ui.DesktopCardPanel#removeComponent(javax.swing.JComponent)
    */
   public void removeComponent(JComponent d) {
     int index = indexOfComponent(d);
     if (index==-1) return;

     if (((JSynopticPanels)JSynoptic.gui).close((DiagramComponent)d)){
       super.removeComponent(d);
       files.remove(index);
     }
   }
    
    
   /* (non-Javadoc)
    * @see simtools.ui.DesktopCardPanel#addComponent(javax.swing.JComponent)
    */
   public void addComponent(JComponent d) {
    addComponent(d, null);
  }

   public void addComponent(JComponent d, File f) {
    if ((d!=null) && (f!=null)) d.setName(f.getName());
    super.addComponent(d);
    files.add(indexOfComponent(d), f);
  }

  public void setFile(int index, File f) {
    if ((index<0) || (index>=files.size())) return;
    files.set(index, f);
  }

  public File getFile(int index) {
    if ((index<0) || (index>=files.size())) return null;
    return (File)files.get(index);
  }
 
  public int getFileCount() {
    return files.size();
  }

  public void setFile(JComponent d, File f) {
    if ((d!=null) && (f!=null)) {
      d.setName(f.getName());
      updateComponentName(d);
    }
    setFile(indexOfComponent(d), f);
  }

  public File getFile(JComponent d) {
    return getFile(indexOfComponent(d));
  }

  protected void createCardPopupMenu() {
    _cardPopup = new FileCardPopupMenu();
  }

 
    /**
     * A file popup menu to be displayed when a card is selected
     * @author zxpletran007
     */
    public class FileCardPopupMenu extends CardPopupMenu {

        //
        //   ActionListener interface
      //
        public void actionPerformed(ActionEvent e) {
              if (e.getSource() == _miClose) {
                  removeComponent(getSelectedComponent());
              }else  if (e.getSource() == _miCloseOther) {
                removeOtherComponents(getSelectedComponent());
              }else  if (e.getSource() == _miCloseAll) {
                removeAllComponents();
              }   
          }
    }
}
TOP

Related Classes of jsynoptic.ui.FiledDesktopCardPanel$FileCardPopupMenu

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.