01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Anton Avtamonov
19: * @version $Revision$
20: */package javax.swing.event;
21:
22: import java.util.EventObject;
23:
24: import javax.swing.tree.TreePath;
25:
26: import org.apache.harmony.x.swing.internal.nls.Messages;
27:
28: public class TreeSelectionEvent extends EventObject {
29: protected TreePath[] paths;
30: protected boolean[] areNew;
31: protected TreePath oldLeadSelectionPath;
32: protected TreePath newLeadSelectionPath;
33:
34: public TreeSelectionEvent(final Object source, final TreePath path,
35: final boolean isNew, final TreePath oldLeadSelectionPath,
36: final TreePath newLeadSelectionPath) {
37:
38: this (source, new TreePath[] { path }, new boolean[] { isNew },
39: oldLeadSelectionPath, newLeadSelectionPath);
40: }
41:
42: public TreeSelectionEvent(final Object source,
43: final TreePath[] paths, final boolean[] areNew,
44: final TreePath oldLeadSelectionPath,
45: final TreePath newLeadSelectionPath) {
46:
47: super (source);
48: this .paths = paths;
49: this .areNew = areNew;
50: this .oldLeadSelectionPath = oldLeadSelectionPath;
51: this .newLeadSelectionPath = newLeadSelectionPath;
52: }
53:
54: public TreePath[] getPaths() {
55: return paths != null ? (TreePath[]) paths.clone() : null;
56: }
57:
58: public TreePath getPath() {
59: return paths != null ? paths[0] : null;
60: }
61:
62: public boolean isAddedPath() {
63: return areNew != null ? areNew[0] : false;
64: }
65:
66: public boolean isAddedPath(final TreePath path) {
67: for (int i = 0; i < paths.length; i++) {
68: if (paths[i] == path) {
69: return isAddedPath(i);
70: }
71: }
72: throw new IllegalArgumentException(Messages
73: .getString("swing.69")); //$NON-NLS-1$
74: }
75:
76: public boolean isAddedPath(final int index) {
77: if (index < 0 || index >= areNew.length) {
78: throw new IllegalArgumentException(Messages
79: .getString("swing.6A")); //$NON-NLS-1$
80: }
81: return areNew[index];
82: }
83:
84: public TreePath getOldLeadSelectionPath() {
85: return oldLeadSelectionPath;
86: }
87:
88: public TreePath getNewLeadSelectionPath() {
89: return newLeadSelectionPath;
90: }
91:
92: public Object cloneWithSource(final Object newSource) {
93: return new TreeSelectionEvent(newSource, paths, areNew,
94: oldLeadSelectionPath, newLeadSelectionPath);
95: }
96: }
|