/*
 * @(#)AbstractViewAWT.java  1.0  1999-10-19
 *
 * Copyright (c) 1999 Werner Randelshofer, Immensee, Switzerland.
 * All rights reserved.
 *
 * You may not use, copy or modify this file, except in compliance with the
 * license agreement you entered into with Werner Randelshofer.
 * For details see accompanying license terms.
 */
package ch.randelshofer.view;

import org.monte.media.gui.ImagePanel;
import org.monte.media.ilbm.ILBMDecoder;
import ch.randelshofer.util.PropertyModel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Event;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.MediaTracker;

import java.awt.image.ImageObserver;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.InputStream;
import java.io.IOException;

import java.util.Vector;

import javax.activation.CommandObject;
import javax.activation.DataHandler;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.ButtonGroup;

/**
 * This abstract viewre class implements the methods needed to
 * handle property models.
 *
 * @author  Werner Randelshofer, Hausmatt 10, CH-6405 Immensee, Switzerland
 * <br>history  1.0  1999-10-19
 */
public abstract class AbstractViewAWT extends Panel implements View, PropertyChangeListener {
    private PropertyModel viewProperties_ = new PropertyModel();
    private PropertyModel applicationProperties_ = new PropertyModel();

    /** Sets the model object for shared properties. */
    public void setViewProperties(PropertyModel m) {
        if (viewProperties_ != null) {
            viewProperties_.removePropertyChangeListener(this);
        }

        viewProperties_ = m == null ? new PropertyModel() : m;

        viewProperties_.addPropertyChangeListener(this);
        updateViewProperties();
    }

    public void setApplicationProperties(PropertyModel m) {
        if (applicationProperties_ != null) {
            applicationProperties_.removePropertyChangeListener(this);
        }

        applicationProperties_ = m == null ? new PropertyModel() : m;

        applicationProperties_.addPropertyChangeListener(this);
        updateApplicationProperties();
    }

    public PropertyModel getViewProperties() {
        return viewProperties_;
    }

    public PropertyModel getApplicationProperties() {
        return applicationProperties_;
    }

    public void propertyChange(PropertyChangeEvent event) {
        Object source = event.getSource();
        if (source == viewProperties_) {
            updateViewProperties();
        } else if (source == applicationProperties_) {
            updateApplicationProperties();
        }
    }

    /**
     * Adds menu items to the "View" menu.
     *
     * When the viewer is added to a container with a
     * JMenuBar. Then the container asks the viewer to
     * add his menu items to the "View" menu of the container.
     */
    public void mergeViewMenuItems(JMenu m) {
    }

    /**
     * Adds menu items to the "Settings" menu.
     *
     * When the viewer is added to a container with a
     * JMenuBar. Then the container asks the viewer to
     * add his menu items to the "Settings" menu of the container.
     */
    public void mergeSettingsMenuItems(JMenu m) {
    }


    public boolean hasScrollPane() {
        return false;
    }

    protected void updateViewProperties() {
    }
    protected void updateApplicationProperties() {
    }

    /**
     * This method is called after the view has been added to
     * the parent component.
     */
    public void init() {
    }
}
