001 /*
002 * This file is part of muCommander, http://www.mucommander.com
003 * Copyright (C) 2002-2008 Maxence Bernard
004 *
005 * muCommander is free software; you can redistribute it and/or modify
006 * it under the terms of the GNU General Public License as published by
007 * the Free Software Foundation; either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * muCommander is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program. If not, see <http://www.gnu.org/licenses/>.
017 */
018
019
020 package com.mucommander.bookmark;
021
022 /**
023 * Represents a bookmark.
024 * <p>Bookmarks are simple name/location pairs:
025 * <ul>
026 * <li>The name is a String describing the bookmark.</li>
027 * <li>
028 * The location should designate a path or file URL. The designated location may not exist or may not even be
029 * a valid path or URL, so it is up to classes that call {@link #getLocation()} to deal with it appropriately.
030 * </li>
031 * </ul>
032 * </p>
033 * @author Maxence Bernard
034 */
035 public class Bookmark implements Cloneable {
036 private String name;
037 private String location;
038
039
040 /**
041 * Creates a new Bookmark using the given name and location.
042 *
043 * @param name name given to this bookmark
044 * @param location location (path or URL) this bookmark points to
045 */
046 public Bookmark(String name, String location) {
047 // Use setters to checks for null values
048 setName(name);
049 setLocation(location);
050 }
051
052
053 /**
054 * Returns this bookmark's name.
055 * @return this bookmark's name.
056 * @see #setName(String)
057 */
058 public String getName() {
059 return name;
060 }
061
062
063 /**
064 * Changes this bookmark's name to the given one and fires an event to registered {@link BookmarkListener}
065 * instances.
066 * @param newName bookmark's new name.
067 * @see #getName()
068 */
069 public void setName(String newName) {
070 // Replace null values by empty strings
071 if(newName==null)
072 newName = "";
073
074 if(!newName.equals(this.name)) {
075 this.name = newName;
076
077 // Notify registered listeners of the change
078 BookmarkManager.fireBookmarksChanged();
079 }
080 }
081
082
083 /**
084 * Returns this bookmark's location which should normally designate a path or file URL, but which isn't
085 * necessarily valid nor exists.
086 * @return this bookmark's location.
087 * @see #setLocation(String)
088 */
089 public String getLocation() {
090 return location;
091 }
092
093
094 /**
095 * Changes this bookmark's location to the given one and fires an event to registered {@link BookmarkListener}
096 * instances.
097 * @param newLocation bookmark's new location.
098 * @see #getLocation()
099 */
100 public void setLocation(String newLocation) {
101 // Replace null values by empty strings
102 if(newLocation==null)
103 newLocation = "";
104
105 if(!newLocation.equals(this.location)) {
106 this.location = newLocation;
107
108 // Notify registered listeners of the change
109 BookmarkManager.fireBookmarksChanged();
110 }
111 }
112
113
114 /**
115 * Returns a clone of this bookmark.
116 */
117 public Object clone() throws CloneNotSupportedException {return super.clone();}
118
119
120 /**
121 * Returns the bookmark's name.
122 */
123 public String toString() {
124 return name;
125 }
126
127 public boolean equals(Object object) {
128 if(!(object instanceof Bookmark))
129 return false;
130
131 Bookmark bookmark;
132 bookmark = (Bookmark)object;
133 return bookmark.getName().equals(name);
134 }
135 }