Source code: com/virtuosotechnologies/asaph/standardmodel/BaseSongMember.java
1 /*
2 ================================================================================
3
4 FILE: BaseSongMember.java
5
6 PROJECT:
7
8 Asaph
9
10 CONTENTS:
11
12 SongMember base class
13
14 PROGRAMMERS:
15
16 Daniel Azuma (DA) <dazuma@kagi.com>
17
18 COPYRIGHT:
19
20 Copyright (C) 2003 Daniel Azuma (dazuma@kagi.com)
21
22 This program is free software; you can redistribute it and/or
23 modify it under the terms of the GNU General Public License as
24 published by the Free Software Foundation; either version 2
25 of the License, or (at your option) any later version.
26
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31
32 You should have received a copy of the GNU General Public
33 License along with this program; if not, write to
34 Free Software Foundation, Inc.
35 59 Temple Place, Suite 330
36 Boston, MA 02111-1307 USA
37
38 ================================================================================
39 */
40
41
42 package com.virtuosotechnologies.asaph.standardmodel;
43
44
45 import javax.swing.event.UndoableEditListener;
46 import javax.swing.event.UndoableEditEvent;
47 import javax.swing.undo.UndoableEdit;
48
49 import com.virtuosotechnologies.lib.base.LinkedObject;
50
51 import com.virtuosotechnologies.asaph.model.Song;
52 import com.virtuosotechnologies.asaph.model.SongMember;
53
54
55 /**
56 * SongMember base class
57 */
58 /*package*/ abstract class BaseSongMember
59 extends LinkedObject
60 implements
61 SongMember
62 {
63 private boolean defunct_;
64 private BaseSongMember parent_;
65
66
67 /*package*/ BaseSongMember(
68 BaseSongMember parent)
69 {
70 assert (parent != null) || (this instanceof StdSong);
71 parent_ = parent;
72 defunct_ = false;
73 }
74
75
76 /*package*/ void internalSetDefunct()
77 {
78 assert !defunct_;
79 defunct_ = true;
80 }
81
82
83 /*package*/ void internalClearDefunct()
84 {
85 assert defunct_;
86 defunct_ = false;
87 }
88
89
90 /*package*/ void internalReportUndoableEdit(
91 UndoableEditListener undoListener,
92 UndoableEdit edit)
93 {
94 if (edit.isSignificant())
95 {
96 undoListener.undoableEditHappened(new UndoableEditEvent(this, edit));
97 }
98 }
99
100
101 /*package*/ BaseSongMember internalGetParent()
102 {
103 return parent_;
104 }
105
106
107 //-------------------------------------------------------------------------
108 // Methods of SongMember
109 //-------------------------------------------------------------------------
110
111 /**
112 * Returns true if this object is defunct-- that is, if it or any of its
113 * ancestors has been removed. If this returns true, the behavior of any
114 * other methods on this object is undefined.
115 *
116 * @return true if the object is defunct.
117 */
118 public boolean isDefunct()
119 {
120 for (BaseSongMember member = this; member != null; member = member.parent_)
121 {
122 if (member.defunct_)
123 {
124 return true;
125 }
126 }
127 return false;
128 }
129
130
131 /**
132 * Returns the Song containing this SongMember. If this member is defunct,
133 * this will return the song that contained this member before the member
134 * was defuncted.
135 *
136 * @return the containing Song
137 */
138 public Song getSong()
139 {
140 BaseSongMember member = this;
141 while (member.parent_ != null)
142 {
143 member = member.parent_;
144 }
145 return (StdSong)member;
146 }
147 }