~ubuntu-branches/ubuntu/raring/accessodf/raring

« back to all changes in this revision

Viewing changes to core/be/docarch/accessodf/Issue.java

  • Committer: Package Import Robot
  • Author(s): Sebastian Humenda
  • Date: 2012-04-09 11:21:13 UTC
  • Revision ID: package-import@ubuntu.com-20120409112113-v0kmfdj1ks80xoj8
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *  AccessODF - Accessibility checker for OpenOffice.org and LibreOffice Writer.
 
3
 *
 
4
 *  Copyright (c) 2011 by DocArch <http://www.docarch.be>.
 
5
 *
 
6
 *  This program is free software: you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU Lesser General Public License as
 
8
 *  published by the Free Software Foundation, either version 3 of the
 
9
 *  License, or (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU Lesser General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU Lesser General Public License
 
17
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
package be.docarch.accessodf;
 
21
 
 
22
import java.util.Date;
 
23
import java.util.Collection;
 
24
import java.util.ArrayList;
 
25
 
 
26
/**
 
27
 *
 
28
 * @author Bert Frees
 
29
 */
 
30
public class Issue {
 
31
 
 
32
    private Collection<IssueListener> listeners;
 
33
 
 
34
    private final Element element;
 
35
    private final Check check;
 
36
    private final Checker checker;
 
37
    private final Date checkDate;
 
38
    private final int count;
 
39
 
 
40
    private boolean ignored = false;
 
41
    private boolean repaired = false;
 
42
 
 
43
    public Issue(Element element, Check check, Checker checker) {
 
44
        this(element, check, checker, 1);
 
45
    }
 
46
 
 
47
    public Issue(Element element, Check check, Checker checker, int count) {
 
48
        this(element, check, checker, new Date(), count);
 
49
    }
 
50
 
 
51
    public Issue(Element element, Check check, Checker checker, Date checkDate) {
 
52
        this(element, check, checker, checkDate, 1);
 
53
    }
 
54
 
 
55
    public Issue(Element element,
 
56
                 Check check,
 
57
                 Checker checker,
 
58
                 Date checkDate,
 
59
                 int count) {
 
60
 
 
61
        this.element = element;
 
62
        this.check = check;
 
63
        this.checker = checker;
 
64
        this.checkDate = checkDate;
 
65
        this.count = count;
 
66
    }
 
67
 
 
68
    public Element getElement() {
 
69
        return element;
 
70
    }
 
71
 
 
72
    public boolean ignored() {
 
73
        return ignored;
 
74
    }
 
75
 
 
76
    public boolean repaired() {
 
77
        return repaired;
 
78
    }
 
79
 
 
80
    public Date getCheckDate() {
 
81
        return checkDate;
 
82
    }
 
83
 
 
84
    public Check getCheck() {
 
85
        return check;
 
86
    }
 
87
 
 
88
    public Checker getChecker() {
 
89
        return checker;
 
90
    }
 
91
 
 
92
    public int getCount() {
 
93
        return count;
 
94
    }
 
95
 
 
96
    public void ignored(boolean ignored) {
 
97
        this.ignored = ignored;
 
98
        fireEvent(IssueEvent.Type.IGNORE);
 
99
    }
 
100
 
 
101
    public void repaired(boolean repaired) {
 
102
        this.repaired = repaired;
 
103
        fireEvent(IssueEvent.Type.REPAIR);
 
104
    }
 
105
 
 
106
    public void remove() {
 
107
        fireEvent(IssueEvent.Type.REMOVE);
 
108
    }
 
109
 
 
110
    public String getName() {
 
111
 
 
112
        if (element == null) {
 
113
            return "";
 
114
        } else {
 
115
            return element.toString();
 
116
        }
 
117
    }
 
118
 
 
119
    private void fireEvent(IssueEvent.Type type) {
 
120
        if (listeners == null) { return; }
 
121
        IssueEvent event = new IssueEvent(this, type);
 
122
        for (IssueListener listener : listeners) {
 
123
            listener.issueUpdated(event);
 
124
        }
 
125
    }
 
126
 
 
127
    public void addListener(IssueListener listener) {
 
128
        if (listeners == null) { listeners = new ArrayList<IssueListener>(); }
 
129
        listeners.add(listener);
 
130
    }
 
131
 
 
132
    @Override
 
133
    public int hashCode() {
 
134
 
 
135
        final int PRIME = 31;
 
136
        int hash = 1;
 
137
        hash = hash * PRIME + getCheck().hashCode();
 
138
        if (element != null) {
 
139
            hash = hash * PRIME + element.hashCode();
 
140
        }
 
141
        return hash;
 
142
   }
 
143
 
 
144
    @Override
 
145
    public boolean equals(Object obj) {
 
146
 
 
147
        if (this == obj) { return true; }
 
148
        if (obj == null) { return false; }
 
149
        if (!(obj instanceof Issue)){ return false; }
 
150
        final Issue that = (Issue)obj;
 
151
        if (!this.getCheck().equals(that.getCheck())) {
 
152
            return false;
 
153
        }
 
154
        if (element == null) {
 
155
            return (that.getElement() == null);
 
156
        } else {
 
157
            return element.equals(that.getElement());
 
158
        }
 
159
    }
 
160
}