001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.swimmingPool; 020 021import icy.util.ClassUtil; 022import icy.util.DateUtil; 023import icy.util.StringUtil; 024 025import java.util.ArrayList; 026import java.util.Date; 027 028import javax.swing.ImageIcon; 029 030public class SwimmingObject 031{ 032 public static ArrayList<String> getObjectTypes(ArrayList<SwimmingObject> objects) 033 { 034 final ArrayList<String> result = new ArrayList<String>(); 035 036 for (SwimmingObject obj : objects) 037 { 038 final String type = obj.getObjectClassName(); 039 040 if (!result.contains(type)) 041 result.add(type); 042 } 043 044 return result; 045 } 046 047 private static final String DEFAULT_NAME = "object"; 048 private static final ImageIcon DEFAULT_ICON = null; 049 050 private static int id_gen = 1; 051 052 private final Object object; 053 054 private final String name; 055 /** 32x32 icon */ 056 private final ImageIcon icon; 057 private final int id; 058 /** Stores the creation date of this object. */ 059 private final Date creationDate; 060 061 public SwimmingObject(Object object, String name, ImageIcon icon) 062 { 063 super(); 064 065 synchronized (SwimmingObject.class) 066 { 067 id = id_gen; 068 id_gen++; 069 } 070 071 this.object = object; 072 if (StringUtil.isEmpty(name)) 073 this.name = DEFAULT_NAME + " " + id; 074 else 075 this.name = name; 076 if (icon == null) 077 this.icon = DEFAULT_ICON; 078 else 079 this.icon = icon; 080 081 creationDate = DateUtil.now(); 082 083 } 084 085 public SwimmingObject(Object object, String name) 086 { 087 this(object, name, null); 088 } 089 090 public SwimmingObject(Object object, ImageIcon icon) 091 { 092 this(object, null, icon); 093 } 094 095 public SwimmingObject(Object object) 096 { 097 this(object, null, null); 098 } 099 100 /** 101 * @return the object 102 */ 103 public Object getObject() 104 { 105 return object; 106 } 107 108 /** 109 * @return the name 110 */ 111 public String getName() 112 { 113 return name; 114 } 115 116 public String getObjectClassName() 117 { 118 if (object != null) 119 return object.getClass().getName(); 120 121 return ""; 122 } 123 124 public String getObjectSimpleClassName() 125 { 126 return ClassUtil.getSimpleClassName(getObjectClassName()); 127 } 128 129 /** 130 * @return the icon 131 */ 132 public ImageIcon getIcon() 133 { 134 return icon; 135 } 136 137 public Date getCreationDate() { 138 return creationDate; 139 } 140 141 /** 142 * @return the id 143 */ 144 public int getId() 145 { 146 return id; 147 } 148 149}