/*
 * @(#)AbstractView.java  1.1  2003-04-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 ch.randelshofer.util.PropertyModel;

import java.awt.dnd.*;
import java.beans.*;
import java.io.*;
import javax.activation.*;
import javax.swing.*;

/**
 * This abstract viewre class implements the methods needed to
 * handle property models.
 *
 * @author  Werner Randelshofer, Hausmatt 10, CH-6405 Immensee, Switzerland
 * @version 1.1 2003-04-19 The form editor in NetBeans 3.4 does not support
 * abstract classes. This class is now concrete.
 * <br>1.0  1999-10-19
 */
public class AbstractView extends JPanel implements View, PropertyChangeListener {
    private PropertyModel viewProperties = new PropertyModel();
    private PropertyModel applicationProperties = new PropertyModel();
    
    /** Sets the model object for shared properties. */
    @Override
    public void setViewProperties(PropertyModel m) {
        if (viewProperties != null) {
            viewProperties.removePropertyChangeListener(this);
        }
        
        viewProperties = m == null ? new PropertyModel() : m;
        
        viewProperties.addPropertyChangeListener(this);
        if (m != null) {
            updateViewProperties();
        }
        
    }
    
    public void setApplicationProperties(PropertyModel m) {
        if (applicationProperties != null) {
            applicationProperties.removePropertyChangeListener(this);
        }
        
        applicationProperties = m == null ? new PropertyModel() : m;
        
        applicationProperties.addPropertyChangeListener(this);
        if (m != null) {
            updateApplicationProperties();
        }
    }
    
    public PropertyModel getViewProperties() {
        return viewProperties;
    }
    
    public PropertyModel getApplicationProperties() {
        return applicationProperties;
    }
    
    public void propertyChange(PropertyChangeEvent event) {
    }
    
    /**
     * 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() {
    }
    
    /**
     * This method should be abstract but the form editor in NetBeans 3.4
     * does not suport abstract classes.
     */
    public void setCommandContext(String verb, final DataHandler dh)
    throws IOException {
        throw new InternalError("Subclass responsibility");
    }
    /**
     * This method adds the given drop target listener to
     * all components of the viewer.
     * <p>
     * This method should be abstract but the form editor in NetBeans 3.4
     * does not suport abstract classes.
     */
    public void addDropTargetListener(DropTargetListener listener) {
        throw new InternalError("Subclass responsibility");
    }
    /**
     * This method should be abstract but the form editor in NetBeans 3.4
     * does not suport abstract classes.
     */
    public void dispose() {
        viewProperties.removePropertyChangeListener(this);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        
        setLayout(new java.awt.BorderLayout());
        
    }//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    
}
