alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 * ProjectEvent.java - Jext project event model
 * 07/21/2001 - 13:43:53
 * Copyright (C) 2001 Matt Benson
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

package org.jext.project;


import java.io.File;


/**
 * The event emitted by a Jext ProjectManager when a meaningful
 * change happens to one of its Projects.
 *
 * @author Matt Benson
 * @see org.jext.project.ProjectListener
 */
public class ProjectEvent
{
// project related events
	public static final int PROJECT_OPENED = 0;
	public static final int PROJECT_CLOSED = 1;
	public static final int PROJECT_SELECTED = 2;

// file related events
  public static final int FILE_ADDED = 100;
  public static final int FILE_REMOVED = 101;
  public static final int FILE_OPENED = 102;
  public static final int FILE_CLOSED = 103;
  public static final int FILE_SELECTED = 104;
  public static final int FILE_CHANGED = 105;
	
// attribute related events
	public static final int ATTRIBUTE_SET = 201;
	public static final int ATTRIBUTE_UNSET = 202;
	
	public static final int OTHER = Integer.MAX_VALUE;

	
  private int event;
	private ProjectManager projectManager;
  private Project project;
	private Object target;

	
/**
 * Creates a new ProjectEvent, registering the parent ProjectManager
 * of this event and the type of the event (the event is assumed to be specific
 * to the ProjectManager's currently active Project.
 * @param projectManager   ProjectManager parent.
 * @param eventType        int value which specifies the nature of
 *                         the ProjectEvent.
 */
  public ProjectEvent(ProjectManager projectManager, int eventType)
  {
		this(projectManager, projectManager.getCurrentProject(), eventType);
  }//end constructor(ProjectManager, int)

	
/**
 * Creates a new ProjectEvent, registering the parent ProjectManager
 * of this event, the type of the event and the relevant Project.
 * @param projectManager   ProjectManager parent.
 * @param project          Project relevant to this
 *                         ProjectEvent.
 * @param eventType        int value which specifies the nature of
 *                         the ProjectEvent.
 */
  public ProjectEvent(ProjectManager projectManager,
	                    Project project, int eventType)
  {
		this(projectManager, project, eventType, null);
  }//end constructor(ProjectManager, Project, int)
	
	
	
/**
 * Creates a new ProjectEvent, registering the parent ProjectManager
 * of this event, the type of the event, the relevant Project, and
 * the target of the event.
 * @param projectManager   ProjectManager parent.
 * @param project          Project relevant to this
 *                         ProjectEvent.
 * @param eventType        int value which specifies the nature of
 *                         the ProjectEvent.
 * @param target           Object which, along with the
 *                         Project, is the target of the
 *                         ProjectEvent.
 */
	public ProjectEvent(ProjectManager projectManager,
	                    Project project, int eventType, Object target)
	{
		if (projectManager == null)
		{
			throw new IllegalArgumentException("ProjectEvent.:  ProjectManager is null!");
		}//end if null projectManager
		if (project == null)
		{
			throw new IllegalArgumentException("ProjectEvent.:  Project is null!");
		}//end if null project
    this.projectManager = projectManager;
    this.project = project;
    this.event = eventType;
		
		switch(eventType)
		{
			case PROJECT_OPENED:
			case PROJECT_CLOSED:
			case PROJECT_SELECTED:
				this.target = project;
				break;
				
			case FILE_ADDED:
			case FILE_REMOVED:
			case FILE_OPENED:
			case FILE_CLOSED:
			case FILE_SELECTED:
			case FILE_CHANGED:
				if (target instanceof File)
				{
					this.target = target;
				}//end if File
				else
				{
					this.target = this.project.getSelectedFile();
				}//end else
				break;
				
			case ATTRIBUTE_SET:
			case ATTRIBUTE_UNSET:
				if (target instanceof String)
				{
					this.target = target;
				}//end if String
				break;
		}//end switch event type
  }//end constructor(ProjectManager, Project, int)

	
/**
 * Returns the type of event.
 * @return int.
 */
  public int getWhat()
  {
    return event;
  }//end getWhat

	
/**
 * Returns the ProjectManager from which the event was fired.
 * @return ProjectManager.
 */
  public ProjectManager getProjectManager()
  {
    return projectManager;
  }//end getProjectManager


/**
 * Returns the Project for which the ProjectEvent was
 * generated.
 * @return Project.
 */
  public Project getProject()
  {
    return project;
  }//end getProject
	
	
/**
 * Returns the Object target of the event; if this is a "project"
 * event, then the result should be the same Project as returned by
 * getProject; if this is a "file" event, the result should be the
 * affected File; if this is an "attribute" event, the result
 * should be the affected String attribute name.
 * @return Object.
 */
	public Object getTarget()
	{
		return target;
	}//end getTarget
	
	
/**
 * @see java.lang.Object#toString()
 */
	public String toString()
	{
		return new StringBuffer("ProjectEvent:  ").append(
		 "projectManager=").append(String.valueOf(getProjectManager())).append(
		 ", ").append(
		 "project=").append(getProject().getName()).append(
		 ", ").append(
		 "what=").append(String.valueOf(getWhat())).append(
		 ", ").append(
		 "target=").append(String.valueOf(getTarget())).toString();
	}//end
	
}//end class ProjectEvent
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.