Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* SimpleGotoEventSource.java
*
* created: Sat Jun 17 2000
*
* This file is part of Artemis
*
* Copyright (C) 2000 Genome Research Limited
*
* 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 (at your option) 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.
*
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/SimpleGotoEventSource.java,v 1.1 2004-06-09 09:45:10 tjc Exp $
*/
package uk.ac.sanger.artemis;
import uk.ac.sanger.artemis.*;
import uk.ac.sanger.artemis.sequence.*;
import uk.ac.sanger.artemis.util.*;
import java.util.Vector;
import java.util.EventObject;
/**
* An simple implementation of GotoEventSource.
*
* @author Kim Rutherford <kmr@sanger.ac.uk>
* @version $Id: SimpleGotoEventSource.java,v 1.1 2004-06-09 09:45:10 tjc Exp $
**/
public class SimpleGotoEventSource
implements GotoEventSource {
/**
* Create a new SimpleGotoEventSource that operates on the given
* EntryGroup. We need an EntryGroup reference so we know where the last
* base is.
**/
public SimpleGotoEventSource (final EntryGroup entry_group) {
this.entry_group = entry_group;
}
/**
* This method sends an GotoEvent to all the GotoEvent listeners that will
* make the given base visible.
* @param base_marker The base to make visible.
**/
public void gotoBase (final Marker base_marker) {
final GotoEvent new_event = new GotoEvent (this, base_marker);
sendGotoEvent (new_event);
}
/**
* This method sends a GotoEvent to all the GotoEvent listeners that will
* make the first base of the sequence visible.
**/
public void gotoFirstBase () {
gotoBase (1);
}
/**
* This method sends a GotoEvent to all the GotoEvent listeners that will
* make the last base of the sequence visible.
**/
public void gotoLastBase () {
gotoBase (getEntryGroup ().getSequenceLength ());
}
/**
* This method sends an GotoEvent to all the GotoEvent listeners that will
* make the given base visible.
* @param destination_base The base to make visible.
* @return The reference of a MarkerRange object for the given base or null
* if the call fails. It will fail only if the destination_base is less
* than 1 or greater than the length of the sequence.
**/
public MarkerRange gotoBase (final int destination_base) {
try {
final Strand forward_strand =
getEntryGroup ().getBases ().getForwardStrand ();
final Marker destination_marker =
forward_strand.makeMarker (destination_base);
gotoBase (destination_marker);
return new MarkerRange (destination_marker.getStrand (),
destination_base, destination_base);
} catch (OutOfRangeException e) {
return null;
}
}
/**
* Send the given event to all the GotoListeners.
**/
public void sendGotoEvent (final GotoEvent goto_event) {
// don't send if there is nowhere to go to
if (goto_event.getMarker () != null) {
fireAction (goto_listener_list, goto_event);
}
}
/**
* Send an event to those object listening for it.
* @param listeners A Vector of the objects that the event should be sent
* to.
* @param event The event to send
**/
private void fireAction (final Vector listeners, final EventObject event) {
final Vector targets;
// copied from a book - synchronising the whole method might cause a
// deadlock
synchronized (this) {
targets = (Vector) listeners.clone ();
}
for (int i = 0 ; i < targets.size () ; ++i) {
GotoListener target = (GotoListener) targets.elementAt (i);
if (event instanceof GotoEvent) {
final GotoListener goto_listener = (GotoListener) target;
goto_listener.performGoto ((GotoEvent) event);
} else {
throw new Error ("EntryEdit.fireAction () - unknown event");
}
}
}
/**
* Adds the specified event listener to receive Goto events from this
* object.
* @param l the GotoEvent listener.
**/
public void addGotoListener (final GotoListener l) {
goto_listener_list.addElement (l);
}
/**
* Removes the specified event listener so that it no longer receives Goto
* events from this object.
* @param l the GotoEvent listener.
**/
public void removeGotoListener (final GotoListener l) {
goto_listener_list.removeElement (l);
}
/**
* Return the EntryGroup object that was passed to the constructor.
**/
public EntryGroup getEntryGroup () {
return entry_group;
}
/**
* The EntryGroup object that was passed to the constructor.
**/
private EntryGroup entry_group;
/**
* A vector of those objects listening for Goto events.
**/
final private Vector goto_listener_list = new Vector ();
}