Package com.nexirius.framework.onlinehelp

Source Code of com.nexirius.framework.onlinehelp.HTMLHelpDialog$LoadCommand

//{HEADER
/**
* This class is part of jnex 'Nexirius Application Framework for Java'
* Copyright (C) Nexirius GmbH, CH-4450 Sissach, Switzerland (www.nexirius.ch)
*
* <p>This library is free software; you can redistribute it and/or<br>
* modify it under the terms of the GNU Lesser General Public<br>
* License as published by the Free Software Foundation; either<br>
* version 2.1 of the License, or (at your option) any later version.</p>
*
* <p>This library is distributed in the hope that it will be useful,<br>
* but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
* Lesser General Public License for more details.</p>
*
* <p>You should have received a copy of the GNU Lesser General Public<br>
* License along with this library; if not, write to the Free Software<br>
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</p>
* </blockquote>
*
* <p>
* Nexirius GmbH, hereby disclaims all copyright interest in<br>
* the library jnex' 'Nexirius Application Framework for Java' written<br>
* by Marcel Baumann.</p>
*/
//}HEADER
package com.nexirius.framework.onlinehelp;

import com.nexirius.framework.datamodel.DefaultDataModelCommand;
import com.nexirius.framework.datamodel.StringModel;
import com.nexirius.framework.datamodel.StructModel;
import com.nexirius.framework.dataviewer.ViewerFactory;
import com.nexirius.framework.gadgets.HtmlPanel;
import com.nexirius.framework.gadgets.HtmlPanelAdaptor;
import com.nexirius.util.SortedVector;

import javax.swing.*;
import java.awt.*;
import java.net.URL;


/**
* A Dialog window for html help
*
* @author Marcel Baumann
*         <p/>
*         Date        Author           Changes/Enhancements
*         2000-4-5    Marcel Baumann   Created
*/
public class HTMLHelpDialog extends JDialog implements HtmlPanelAdaptor {



    HtmlPanel htmlPanel;
    StructModel control;
    SortedVector history;
    NextURLCommand next;
    PrevURLCommand prev;
    StringModel urlString;
    int act = 0;
    boolean walking = false;

    public HTMLHelpDialog(Frame owner, URL url, ViewerFactory factory) {
        super(owner, "Hilfe");
        init(url, factory);
    }

/*  public HTMLHelpDialog(Dialog owner, URL url, ViewerFactory factory)
  {
    super(owner, "Hilfe");
    init(url, factory);
  }
*/
    private void init(URL url, ViewerFactory factory) {
        history = new SortedVector();
        control = new StructModel("Controls");
        control.append(urlString = new StringModel(url.toString(), "URL"));
        control.appendMethod(new LoadCommand());
        control.appendMethod(prev = new PrevURLCommand());
        control.appendMethod(next = new NextURLCommand());
        control.appendMethod(new CloseCommand());

        next.setEnabled(false);
        prev.setEnabled(false);

        htmlPanel = new HtmlPanel(url);
        htmlPanel.setAdaptor(this);
        htmlPanel.setPreferredSize(new Dimension(500, 400));
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(htmlPanel, BorderLayout.CENTER);

        try {
            getContentPane().add(factory.createDefaultEditor(control).getJComponent(), BorderLayout.SOUTH);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void help(URL url) {
        notify(url);
        jump();
    }

    public void notify(URL url) {
        if (walking) {
            walking = false;
        } else {

            if (history.size() == 0 || !url.equals(history.lastElement())) {
                history.addElement(url);
            }

            act = history.size() - 1;
        }

        urlString.setText(url.toString());
        updateButtons();
    }

    private void updateButtons() {
        if (act == 0) {
            prev.setEnabled(false);
        } else {
            prev.setEnabled(true);
        }

        if (act + 1 == history.size()) {
            next.setEnabled(false);
        } else {
            next.setEnabled(true);
        }
    }

    public void jump() {
        URL url = (URL) history.getObject(act);

        htmlPanel.linkActivated(url);
    }

    public void closeWindow() {
        setVisible(false);
    }

    class LoadCommand extends DefaultDataModelCommand {
        LoadCommand() {
            super("Load");
        }

        public void doAction() {
            try {
                help(new URL(urlString.getText()));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    class NextURLCommand extends DefaultDataModelCommand {
        NextURLCommand() {
            super("Next");
        }

        public void doAction() {
            if (history.size() > act + 1) {
                walking = true;
                ++act;
                jump();
            }
        }
    }

    class PrevURLCommand extends DefaultDataModelCommand {
        PrevURLCommand() {
            super("Previous");
        }

        public void doAction() {
            if (act > 0) {
                walking = true;
                --act;
                jump();
            }
        }
    }

    class CloseCommand extends DefaultDataModelCommand {
        CloseCommand() {
            super("Close");
        }

        public void doAction() {
            closeWindow();
        }
    }
}
TOP

Related Classes of com.nexirius.framework.onlinehelp.HTMLHelpDialog$LoadCommand

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.