This repository was archived by the owner on Jun 18, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLegendPanel.java
More file actions
47 lines (41 loc) · 1.53 KB
/
Copy pathLegendPanel.java
File metadata and controls
47 lines (41 loc) · 1.53 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
package gvisual;
import javax.swing.*;
import java.awt.*;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Reusable legend panel that displays a color-coded key for edge types.
*
* <p>Extracted from {@link Main#initializeLegendSpace()} to separate UI
* component construction from the main frame, making it independently
* testable and reusable in other views (e.g., headless report generation
* or secondary analysis windows).</p>
*
* @author zalenix
*/
public class LegendPanel extends JPanel {
private static final Map<String, String> LEGEND_ENTRIES = new LinkedHashMap<>();
static {
LEGEND_ENTRIES.put("Friend", "images/green.jpg");
LEGEND_ENTRIES.put("Familiar Stranger", "images/gray.jpg");
LEGEND_ENTRIES.put("Stranger", "images/red.jpg");
LEGEND_ENTRIES.put("Classmate", "images/blue.jpg");
LEGEND_ENTRIES.put("Study Group", "images/yellow.jpg");
}
/**
* Creates a legend panel with the default edge-type colour mapping.
*/
public LegendPanel() {
JLabel heading = new JLabel("Legend for the Graph");
Box vbox = Box.createVerticalBox();
for (Map.Entry<String, String> entry : LEGEND_ENTRIES.entrySet()) {
Box row = Box.createHorizontalBox();
row.add(new JLabel(new ImageIcon(entry.getValue())));
row.add(new JLabel(entry.getKey()));
vbox.add(row);
}
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
heading, vbox);
add(splitPane);
}
}