/*
 * (C) Copyright IBM Corp. 1997-1998  All rights reserved.
 *
 * US Government Users Restricted Rights Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *
 * The program is provided "as is" without any warranty express or
 * implied, including the warranty of non-infringement and the implied
 * warranties of merchantibility and fitness for a particular purpose.
 * IBM will not be liable for any damages suffered by you as a result
 * of using the Program. In no event will IBM be liable for any
 * special, indirect or consequential damages or lost profits even if
 * IBM has been advised of the possibility of their occurrence. IBM
 * will not be liable for any third party claims against you.
 */

package com.ibm.xml.cdfview;

import com.ibm.xml.parser.*;
import java.awt.event.*;
import java.net.*;

public abstract class XMLComponentM extends TXElement implements java.awt.event.MouseListener {
    
    URL m_url = null;
    java.awt.Panel m_p = null;
    String m_title;

    public XMLComponentM(String qname) {
        super(qname);
    }

    public void ripen() {
        try {
            String u = getAttribute("HREF");
            if (null == u)  u = getAttribute("href");
            if (u.toLowerCase().startsWith("http://")) {
                m_url = new URL(u);
            } else {
                Parent par = this;
                String base = null;
                while (null != (par = (Parent)((TXElement)par).getParentNode())
                       && par instanceof TXElement) {
                    TXElement el = (TXElement)par;
                    if (null != (base = el.getAttribute("BASE")))
                        break;
                }
                m_url = new URL(new URL(base), u);
            }
        } catch (Exception e) {
            System.err.println(e.toString()+this.toString());
        }
        TXElement el = getElementNamed("TITLE");
        m_title = null == el ? (null == m_url ? null : m_url.toString()) : el.getText();
        if (null == m_title)  m_title = "*No Title*";
    }

    Gateway m_gate;
    public void setGateway(Gateway g) {
        m_gate = g;
        Child[] children = getChildrenArray();
        for (int i = 0;  i < children.length;  i ++) {
            if (children[i] instanceof XMLComponentM)
                ((XMLComponentM)children[i]).setGateway(g);
        }
    }
    public  abstract int getConnectedOffset();
    public java.awt.Container getContainer() {
        return m_p;
    }

    boolean m_selected = false;
    public void select(boolean f) {
        m_selected = f;
    }

    public void mouseClicked(MouseEvent e) {
    }
    public void mousePressed(MouseEvent e) {
    }
    public void mouseReleased(MouseEvent e) {
    }
    public void mouseEntered(MouseEvent e) {
        if (null != m_url) {
            m_gate.setText(m_url.toString());
        }
    }
    public void mouseExited(MouseEvent e) {
        if (null != m_url) {
            m_gate.setText("");
        }
    }
}
