/**
 * @(#) ActionLibManager.java 19.07.01
 *
 * jfem - a java finite element system
 *
 * Copyright (C) 1999-2001 HS-MD
 * jfem.support@jfem.de
 * www.jfem.de
 *
 * For License information see License.txt
 */

package org.app.action;

import org.app.action.IActionDefinitions;
import org.app.action.ActionLibConsumer;
import javax.swing.ImageIcon;
import javax.swing.AbstractAction;
import javax.swing.Action;
import org.app.actionproc.*;

/**
 * description:
 *
 * @title       ActionLibConsumer
 * @version     1
 * @copyright   Copyright (c) 1999
 * @see         #org.jfem.Action.IActionDefinitions
 * @see         #org.jfem.Action.ActionLibConsumer Organisation:  FH Magdeburg
 * @version     1.0  19.07.01
 * @author      Thomas Schmidt, Michael Wilhelem
 */

public class ActionLibManager {
    private static final String _pictPath = "org/app/picture/";

    public ActionLibManager() {
    }

    /**
     * getActionLib
     * @return ActMvcAction
     * @param int cmd,  int cmdBez, ActionLibConsumer owner, Object data
     * @exception none
     * @version      1.0
     * @author Thomas Schmidt, Michael Wilhelm FH MD, FB Bauwesen
     * @use Durch die Variable cmd wird die library Proc definiert Example
     * @see #OpenAction
     * @see #LokalProc
     */
    // alte Version
    public static ActMvcAction getActionLib(int cmdLib, int cmdBez, ActionLibConsumer owner, Object data) {
        ActMvcAction action;
        String name;
        ImageIcon openIcon, saveIcon;
        switch (cmdLib) {
            case IActionDefinitions.CMD_OPEN:
                if (cmdBez == 0) cmdBez = cmdLib;
                name = ActionLibManager.getName(cmdBez);
                openIcon = ActionLibManager.getIcon(cmdLib);
                String[] smaske = {"11"};
                smaske[0] = (String)data;
                action = new OpenAction(name, openIcon, cmdLib, owner, smaske);
                return action;
            case IActionDefinitions.CMD_SAVEAS:
                if (cmdBez == 0) cmdBez = cmdLib;
                name = ActionLibManager.getName(cmdBez);
                saveIcon = ActionLibManager.getIcon(cmdLib);
                action = new SaveAction(name, saveIcon, cmdLib, owner, (String)data);
                return action;
            case IActionDefinitions.CMD_Win_Prev:
                if (cmdBez == 0) cmdBez = cmdLib;
                name = ActionLibManager.getName(cmdBez);
                openIcon = ActionLibManager.getIcon(cmdLib);
                action = new WindowPrevAction(name, openIcon, cmdLib, owner, (javax.swing.JDesktopPane) data);
                return action;
            case IActionDefinitions.CMD_Win_Next:
                if (cmdBez == 0) cmdBez = cmdLib;
                name = ActionLibManager.getName(cmdBez);
                openIcon = ActionLibManager.getIcon(cmdLib);
                action = new WindowNextAction(name, openIcon, cmdLib, owner, (javax.swing.JDesktopPane) data);
                return action;
            case IActionDefinitions.CMD_Win_Overlapped:
                if (cmdBez == 0) cmdBez = cmdLib;
                name = ActionLibManager.getName(cmdBez);
                openIcon = ActionLibManager.getIcon(cmdLib);
                action = new WindowKaskadeAction(name, openIcon, cmdLib, owner, (javax.swing.JDesktopPane) data);
                return action;
            case IActionDefinitions.CMD_Win_Tile:
                if (cmdBez == 0) cmdBez = cmdLib;
                name = ActionLibManager.getName(cmdBez);
                openIcon = ActionLibManager.getIcon(cmdLib);
                action = new WindowTileAction(name, openIcon, cmdLib, owner, (javax.swing.JDesktopPane) data);
                return action;
            default:
                return null;
        }
    }
    // -------------------------------------------------------

    /**
     * getActionLib
     * @return ActMvcAction
     * @param int cmd,  int cmdBez, ImageIcon openIcon, ActionLibConsumer owner, Object data
     * @exception none
     * @version      1.0
     * @author Thomas Schmidt, Michael Wilhelm FH MD, FB Bauwesen
     * @use Durch die Variable cmd wird die library Proc definiert Example
     * @see #OpenAction
     * @see #LokalProc
     */
    // neue Version
    public static ActMvcAction getActionLib(String mfName, int cmdLib, ActionLibConsumer owner, Object data) {
        ActMvcAction action;
        switch (cmdLib) {
            case IActionDefinitions.CMD_OPEN:
                // (new String[] {"snp","dxf","dot"})
                String[] smaske = (String[]) data;
                action = new OpenAction(mfName, null, cmdLib, owner, smaske);
                return action;
            case IActionDefinitions.CMD_SAVEAS:
                action = new SaveAction(mfName, null, cmdLib, owner, (String)data);
                return action;
            case IActionDefinitions.CMD_Win_Prev:
                action = new WindowPrevAction(mfName, null, cmdLib, owner, (javax.swing.JDesktopPane) data);
                return action;
            case IActionDefinitions.CMD_Win_Next:
                action = new WindowNextAction(mfName, null, cmdLib, owner, (javax.swing.JDesktopPane) data);
                return action;
            case IActionDefinitions.CMD_Win_Overlapped:
                action = new WindowKaskadeAction(mfName, null, cmdLib, owner, (javax.swing.JDesktopPane) data);
                return action;
            case IActionDefinitions.CMD_Win_Tile:
                action = new WindowTileAction(mfName, null, cmdLib, owner, (javax.swing.JDesktopPane) data);
                return action;
            default:
                return null;
        }
    }

    public static Action getLocalAction(int cmd) {
        ImageIcon Icon;
        String name;
        name = ActionLibManager.getName(cmd);
        Icon = ActionLibManager.getIcon(cmd);
        Action act = new LocalAction(name, Icon);
        return act;
    }

    /**
     * getIcon
     * @return ImageIcon
     * @param int cmd
     * @exception none
     * @version      1.0
     * @author Thomas Schmidt, Michael Wilhelm FH MD, FB Bauwesen
     * @use Example
     * @see #getName
     */
    public static ImageIcon getIcon(int cmd) {
        switch (cmd) {
            case IActionDefinitions.CMD_OPEN:
                return new ImageIcon(_pictPath + "open.gif");
            case IActionDefinitions.CMD_SAVEAS:
                return new ImageIcon(_pictPath + "save.gif");
            default:
                return null;
        }
    }

    /**
     * getName
     * @return String
     * @param int cmd
     * @exception none
     * @version      1.0
     * @author Thomas Schmidt, Michael Wilhelm FH MD, FB Bauwesen
     * @use Example
     * @see #getIcon
     */
    public static String getName(int cmd) {
        switch (cmd) {
            case IActionDefinitions.CMD_OPEN:
                return new String("Öffnen LibManager");
            case IActionDefinitions.CMD_OPEN_DAT:
                return new String("Öffnen (*.DAT)");
            case IActionDefinitions.CMD_OPEN_DIT:
                return new String("Öffnen (*.DIT)");
            case IActionDefinitions.CMD_SAVEAS:
                return new String("Sichern als");
            case IActionDefinitions.CMD_Win_Prev:
                return new String("Vorheriges Fenster");
            case IActionDefinitions.CMD_Win_Next:
                return new String("Nächstes Fenster");
            case IActionDefinitions.CMD_Win_Overlapped:
                return new String("Kaskade");
            case IActionDefinitions.CMD_Win_Tile:
                return new String("Teilen");
            default:
                return null;
        }
    }

/*
        ImageIcon openIcon = LibManager.getIcon(cmd);
        String name = LibManager.getName(cmd);
*/
}
