GUIHTMLDialog.java

1
// Copyright © 2004-2006 University of Helsinki, Department of Computer Science
2
// Copyright © 2012 various contributors
3
// This software is released under GNU Lesser General Public License 2.1.
4
// The license text is at http://www.gnu.org/licenses/lgpl-2.1.html
5
6
package fi.helsinki.cs.titokone;
7
8
import javax.swing.*;
9
import javax.swing.event.*;
10
import javax.swing.text.html.*;
11
import java.awt.*;
12
import java.io.IOException;
13
import java.net.URL;
14
15
16
public class GUIHTMLDialog extends JDialog {
17
18
    JEditorPane contents;
19
    JScrollPane contentsScrollPane;
20
21
    String pathToURL;
22
    URL htmlURL;
23
24
25
    public GUIHTMLDialog(Frame ownerFrame, boolean modal, String path) {
26
        super(ownerFrame, modal);
27
28
29 1
        pathToURL = path;
30
31 2
        contents = new JEditorPane();
32 3
        contents.setEditable(false);
33
34 3
        contents.addHyperlinkListener(new HyperlinkListener() {
35
            public void hyperlinkUpdate(HyperlinkEvent e) {
36 2
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
37 1
                    JEditorPane pane = (JEditorPane) e.getSource();
38 1
                    if (e instanceof HTMLFrameHyperlinkEvent) {
39
                        HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
40 1
                        HTMLDocument doc = (HTMLDocument) pane.getDocument();
41 1
                        doc.processHTMLFrameHyperlinkEvent(evt);
42
                    } else {
43
                        try {
44 2
                            pane.setPage(e.getURL());
45
                        } catch (Throwable t) {
46 1
                            t.printStackTrace();
47
                        }
48
                    }
49
                }
50
            }
51
        });
52
53 2
        contentsScrollPane = new JScrollPane(contents);
54 6
        contentsScrollPane.setPreferredSize(new Dimension(400, 300));
55
56 2
        getContentPane().add(contentsScrollPane);
57 1
        pack();
58
    }
59
60
    public void updateAllTexts() {
61 2
        String newPath = new Message(pathToURL).toString();
62
63
        try {
64 2
            htmlURL = new URL(newPath);
65
        } catch (Exception e) {
66
            try {
67 11
                htmlURL = new URL(getClass().getClassLoader().getResource("doc").toString() + "/" + newPath);
68
            } catch (Exception e2) {
69
                //System.out.println(e);
70
            }
71
        }
72
73 1
        if (htmlURL != null) {
74
            try {
75 1
                contents.setPage(htmlURL);
76
            } catch (IOException e) {
77 5
                System.err.println("Attempted to read a bad URL: " + htmlURL);
78
            }
79
        } else {
80 1
            System.err.println("Requested URL was not found.");
81
        }
82
83
    }
84
85
}

Mutations

29

Removed assignment to member variable pathToURL : NO_COVERAGE

31

removed call to javax/swing/JEditorPane::<init> : NO_COVERAGE

Removed assignment to member variable contents : NO_COVERAGE

32

Substituted 0 with 1 : NO_COVERAGE

removed call to javax/swing/JEditorPane::setEditable : NO_COVERAGE

Substituted 0 with 1 : NO_COVERAGE

34

Removed assignment to member variable this$0 : NO_COVERAGE

removed call to javax/swing/JEditorPane::addHyperlinkListener : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/GUIHTMLDialog$1::<init> : NO_COVERAGE

36

removed call to javax/swing/event/HyperlinkEvent::getEventType : NO_COVERAGE

negated conditional : NO_COVERAGE

37

removed call to javax/swing/event/HyperlinkEvent::getSource : NO_COVERAGE

38

negated conditional : NO_COVERAGE

40

removed call to javax/swing/JEditorPane::getDocument : NO_COVERAGE

41

removed call to javax/swing/text/html/HTMLDocument::processHTMLFrameHyperlinkEvent : NO_COVERAGE

44

removed call to javax/swing/event/HyperlinkEvent::getURL : NO_COVERAGE

removed call to javax/swing/JEditorPane::setPage : NO_COVERAGE

46

removed call to java/lang/Throwable::printStackTrace : NO_COVERAGE

53

removed call to javax/swing/JScrollPane::<init> : NO_COVERAGE

Removed assignment to member variable contentsScrollPane : NO_COVERAGE

54

removed call to java/awt/Dimension::<init> : NO_COVERAGE

Substituted 400 with 401 : NO_COVERAGE

Replaced constant value of 300 with 301 : NO_COVERAGE

Substituted 300 with 301 : NO_COVERAGE

removed call to javax/swing/JScrollPane::setPreferredSize : NO_COVERAGE

Replaced constant value of 400 with 401 : NO_COVERAGE

56

removed call to fi/helsinki/cs/titokone/GUIHTMLDialog::getContentPane : NO_COVERAGE

removed call to java/awt/Container::add : NO_COVERAGE

57

removed call to fi/helsinki/cs/titokone/GUIHTMLDialog::pack : NO_COVERAGE

61

removed call to fi/helsinki/cs/titokone/Message::<init> : NO_COVERAGE

removed call to fi/helsinki/cs/titokone/Message::toString : NO_COVERAGE

64

removed call to java/net/URL::<init> : NO_COVERAGE

Removed assignment to member variable htmlURL : NO_COVERAGE

67

removed call to java/lang/Class::getClassLoader : NO_COVERAGE

removed call to java/net/URL::<init> : NO_COVERAGE

removed call to java/lang/StringBuilder::toString : NO_COVERAGE

removed call to java/lang/ClassLoader::getResource : NO_COVERAGE

removed call to java/net/URL::toString : NO_COVERAGE

removed call to java/lang/Object::getClass : NO_COVERAGE

removed call to java/lang/StringBuilder::append : NO_COVERAGE

Removed assignment to member variable htmlURL : NO_COVERAGE

removed call to java/lang/StringBuilder::append : NO_COVERAGE

removed call to java/lang/StringBuilder::<init> : NO_COVERAGE

removed call to java/lang/StringBuilder::append : NO_COVERAGE

73

negated conditional : NO_COVERAGE

75

removed call to javax/swing/JEditorPane::setPage : NO_COVERAGE

77

removed call to java/lang/StringBuilder::append : NO_COVERAGE

removed call to java/io/PrintStream::println : NO_COVERAGE

removed call to java/lang/StringBuilder::append : NO_COVERAGE

removed call to java/lang/StringBuilder::<init> : NO_COVERAGE

removed call to java/lang/StringBuilder::toString : NO_COVERAGE

80

removed call to java/io/PrintStream::println : NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 0.27