/*
 This file is part of the software framework JStatCom, 
 a library for building applications for data based analysis.

 Copyright (C) 2000-2005  Markus Kraetzig

 This library is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as
 published by the Free Software Foundation; either version 2.1 of the
 License, or (at your option) any later version.

 This library 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
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 USA
 */

package com.jstatcom.ts;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;

/**
 * This class is in a preliminary state. It certainly needs to work with a yet
 * to build TSProjectManager. So far its only purpose is to
 * store project descriptions. Further experience needs to be gained on how a
 * usable project management for time series projects can be implemented.
 * 

* * Stores common information for a set of TS. This is so far: *

* TSProject is in sync with TSHolder via a * PropertyChangeListener. This means that series that are * removed from the TSHolder are also removed from the projects * they belong to. * * @author Markus Kraetzig */ public final class TSProject implements PropertyChangeListener { private final List tsList = new ArrayList(); private String projectDescription = ""; private String name = "Default project"; /** * Default project, where all TS are added if no other * project is specified. */ public static final TSProject DEFAULT_PROJECT = new TSProject( "DEFAULT_PROJECT", ""); /** * Creates a new TSProject with a name. * * @param projectName * the name of the new project */ public TSProject(String projectName) { this(projectName, null); } /** * Creates a new TSProject with a name and a project * description. * * @param projectName * the name of the new project * @param description * the project description */ public TSProject(String projectName, String description) { super(); name = projectName; setDescription(description); } /** * Adds a time series to this project. Nothing happens, if the series is * already contained. * * @param ts * time series to be added to this project */ public void addTS(TS ts) { if (!tsList.contains(ts.name())) tsList.add(ts.name()); } /** * Gets the description of this project. It should contain a short remark * about every time series in the project. * * @return the project description */ public String getDescription() { return projectDescription; } /** * This method is called whenever there is a property change in the * connected property fields. The action depends on the source determined. * * @param evt * a property change event */ public void propertyChange(PropertyChangeEvent evt) { /* * if (evt.getSource() instanceof TSHolder && evt.getPropertyName() == * TSHolder.TS_ADDED) { // empty } */ if (evt.getSource() instanceof TSHolder && evt.getPropertyName() == TSHolder.TS_REMOVED) { String tsName = evt.getNewValue().toString(); removeTS(tsName); } } /** * Removes a time series from this project. Nothing happens, if series is * not in the project. * * @param name * the String identifying the time series to * remove */ public void removeTS(String name) { if (tsList.contains(name)) tsList.remove(name); } /** * Sets the description for this project. It should contain a short remark * about every time series in the project. * * @param newProjectDescription * the new description */ public void setDescription(String newProjectDescription) { if (newProjectDescription == null || newProjectDescription.trim().length() == 0) newProjectDescription = ""; projectDescription = newProjectDescription; } /** * Gets a string representation of this project. * * @return representation contains this name and the names of all contained * TS */ public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append(getClass().getName() + "[name=" + name); for (int i = 0; i < tsList.size(); i++) buffer.append("," + tsList.get(i)); buffer.append("]"); return buffer.toString(); } /** * Gets the name of this project. * * @return name */ public String getName() { return name; } }

Ads help maintain this website.