|
@@ -1,88 +0,0 @@
|
1
|
|
-/*
|
2
|
|
- * Copyright (c) 2006-2015 DMDirc Developers
|
3
|
|
- *
|
4
|
|
- * Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
|
- * of this software and associated documentation files (the "Software"), to deal
|
6
|
|
- * in the Software without restriction, including without limitation the rights
|
7
|
|
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
|
- * copies of the Software, and to permit persons to whom the Software is
|
9
|
|
- * furnished to do so, subject to the following conditions:
|
10
|
|
- *
|
11
|
|
- * The above copyright notice and this permission notice shall be included in
|
12
|
|
- * all copies or substantial portions of the Software.
|
13
|
|
- *
|
14
|
|
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
|
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
|
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
|
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
|
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
|
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
|
- * SOFTWARE.
|
21
|
|
- */
|
22
|
|
-
|
23
|
|
-package com.dmdirc.addons.ui_swing.dialogs.about;
|
24
|
|
-
|
25
|
|
-import com.dmdirc.DMDircMBassador;
|
26
|
|
-import com.dmdirc.addons.ui_swing.components.LoggingSwingWorker;
|
27
|
|
-import com.dmdirc.interfaces.ui.AboutDialogModel;
|
28
|
|
-import com.dmdirc.ui.core.about.LicensedComponent;
|
29
|
|
-
|
30
|
|
-import java.io.IOException;
|
31
|
|
-
|
32
|
|
-import javax.swing.JTree;
|
33
|
|
-import javax.swing.tree.DefaultMutableTreeNode;
|
34
|
|
-import javax.swing.tree.DefaultTreeModel;
|
35
|
|
-import javax.swing.tree.MutableTreeNode;
|
36
|
|
-import javax.swing.tree.TreeNode;
|
37
|
|
-
|
38
|
|
-/**
|
39
|
|
- * Background loader of licences into a list.
|
40
|
|
- */
|
41
|
|
-public class LicenceLoader extends LoggingSwingWorker<Void, Void> {
|
42
|
|
-
|
43
|
|
- /** Tree to add licenses to. */
|
44
|
|
- private final JTree tree;
|
45
|
|
- private final AboutDialogModel model;
|
46
|
|
- /** Model to load licences into. */
|
47
|
|
- private final DefaultTreeModel treeModel;
|
48
|
|
-
|
49
|
|
- /**
|
50
|
|
- * Instantiates a new licence loader.
|
51
|
|
- *
|
52
|
|
- * @param tree Tree to add licenses to
|
53
|
|
- * @param model Model to load licences into
|
54
|
|
- * @param eventBus The event bus to post errors to
|
55
|
|
- */
|
56
|
|
- public LicenceLoader(final AboutDialogModel model, final JTree tree,
|
57
|
|
- final DefaultTreeModel treeModel, final DMDircMBassador eventBus) {
|
58
|
|
- super(eventBus);
|
59
|
|
- this.tree = tree;
|
60
|
|
- this.model = model;
|
61
|
|
- this.treeModel = treeModel;
|
62
|
|
- }
|
63
|
|
-
|
64
|
|
- @Override
|
65
|
|
- protected Void doInBackground() throws IOException {
|
66
|
|
- model.getLicensedComponents().forEach(this::addLicensedComponent);
|
67
|
|
- return null;
|
68
|
|
- }
|
69
|
|
-
|
70
|
|
- private void addLicensedComponent(final LicensedComponent component) {
|
71
|
|
- final MutableTreeNode componentNode = new DefaultMutableTreeNode(component);
|
72
|
|
- treeModel.insertNodeInto(componentNode, (MutableTreeNode) treeModel.getRoot(),
|
73
|
|
- treeModel.getChildCount(treeModel.getRoot()));
|
74
|
|
- component.getLicences().forEach(l -> treeModel.insertNodeInto(
|
75
|
|
- new DefaultMutableTreeNode(l), componentNode,
|
76
|
|
- treeModel.getChildCount(componentNode)));
|
77
|
|
- }
|
78
|
|
-
|
79
|
|
- @Override
|
80
|
|
- protected void done() {
|
81
|
|
- treeModel.nodeStructureChanged((TreeNode) treeModel.getRoot());
|
82
|
|
- for (int i = 0; i < tree.getRowCount(); i++) {
|
83
|
|
- tree.expandRow(i);
|
84
|
|
- }
|
85
|
|
- tree.setSelectionRow(0);
|
86
|
|
- super.done();
|
87
|
|
- }
|
88
|
|
-}
|