Parent: [r3] (diff)

Child: [r22] (diff)

Download this file

TreeNodeSPDX.java    143 lines (114 with data), 3.5 kB

  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
/*
* SPDXVersion: SPDX-1.1
*
* Creator: Person: Nuno Brito (nuno.brito@triplecheck.de)
*
* Creator: Organization: TripleCheck (contact@triplecheck.de)
*
* Created: 2013-09-01T00:00:00Z
*
* LicenseName: NOASSERTION
*
* FileName: TreeNodeSPDX.java
*
* FileType: SOURCE
*
* FileCopyrightText: <text> Copyright 2013 Nuno Brito, TripleCheck </text>
*
* FileComment: <text> A tree node object adapted for SPDX documents </text>
*/
package GUI;
import java.io.File;
import java.util.ArrayList;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.tree.DefaultMutableTreeNode;
import main.core;
public class TreeNodeSPDX extends DefaultMutableTreeNode{
public NodeType // define the type of node that we have here
nodeType = NodeType.none;
public String
id = "";
private String
title = "";
private int
// counts the number of relevant childs
counter = 0;
// in case we want to run a file with a script
public File
scriptFile = null,
scriptFolder = null;
// if a file with a script was added, which method should be run?
public String scriptMethod;
public ArrayList<String[]> scriptParameters = new ArrayList();
public Icon
icon = null,
iconWhenSelected = null;
public TreeNodeSPDX(String library) {
super(library);
title = library;
}
// @Override
// public String toString(){
// return "";
// }
public TreeNodeSPDX(TreeNodeSPDX root) {
super(root);
title = root.toString();
}
@Override
public String toString(){
String result = getTitle();
if(counter > 0){
result += " (" + counter + ")";
}
return result;
}
public String getTitle() {
if(title == null){
title = id;
}
if(title.isEmpty()){
title = id;
}
return title;
}
public void setTitle(String title) {
this.title = title;
}
/**
* Given a specific tree node, generate a unique ID
* @param node the node from where start to calculate the ID string
* @return a unique ID based on the parent nodes of this entry
*/
public String getUID(){
String result = "";
TreeNodeSPDX currentNode = this;
while(currentNode.getParent() != null){
result = result + ">> " + currentNode.id + " ";
currentNode = (TreeNodeSPDX) currentNode.getParent();
}
return result;
}
/**
* Defines a new Icon for this node
* @param what the icon file name that is located under the "icons" folder
*/
public void setIcon(String what){
icon = new ImageIcon(core.getIcon(what).getAbsolutePath());
}
/**
* Defines a new Icon for this node
* @param what the icon file name that is located under the "icons" folder
*/
public void setIconWhenSelected(String what){
iconWhenSelected = new ImageIcon(core.getIcon(what).getAbsolutePath());
}
/**
* Sets the number of relevant children on this node
* @param counter a positive, decimal value
*/
public void setCounter(int counter) {
this.counter = counter;
}
}