Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Gvisual/src/gvisual/LegendPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
}
67 changes: 2 additions & 65 deletions Gvisual/src/gvisual/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -674,70 +674,7 @@ public void addGraph() throws ParserConfigurationException, IOException, SAXExce
* initialize the Legend Space
*/
public final void initializeLegendSpace(){
legendPanel = new JPanel();

JLabel legendHeading = new JLabel("Legend for the Graph");

String blueImgPath = "images/blue.jpg";
String redImgPath = "images/red.jpg";
String greenImgPath = "images/green.jpg";
String yellowImgPath = "images/yellow.jpg";
String grayImgPath = "images/gray.jpg";

Icon blue = new ImageIcon(blueImgPath);
Icon red = new ImageIcon(redImgPath);
Icon green = new ImageIcon(greenImgPath);
Icon yellow = new ImageIcon(yellowImgPath);
Icon gray = new ImageIcon(grayImgPath);

JLabel fLabel = new JLabel("Friend");
JLabel fColor= new JLabel(green);
JLabel fsLabel= new JLabel("Familiar Stranger");
JLabel fsColor= new JLabel(gray);
JLabel sLabel= new JLabel("Stranger");
JLabel sColor= new JLabel(red);
JLabel cLabel= new JLabel("Classmate");
JLabel cColor = new JLabel(blue);
JLabel sgLabel= new JLabel("Study Group");
JLabel sgColor= new JLabel(yellow);

Box HBox[] = new Box[5];
Box VBox[] = new Box[1];

VBox[0]= Box.createVerticalBox();

HBox[0]= Box.createHorizontalBox();
HBox[1]= Box.createHorizontalBox();
HBox[2]= Box.createHorizontalBox();
HBox[3]= Box.createHorizontalBox();
HBox[4]= Box.createHorizontalBox();


HBox[0].add(fColor);
HBox[1].add(fsColor);
HBox[2].add(sColor);
HBox[3].add(cColor);
HBox[4].add(sgColor);

HBox[0].add(fLabel);
HBox[1].add(fsLabel);
HBox[2].add(sLabel);
HBox[3].add(cLabel);
HBox[4].add(sgLabel);

VBox[0].add(HBox[0]);
VBox[0].add(HBox[1]);
VBox[0].add(HBox[2]);
VBox[0].add(HBox[3]);
VBox[0].add(HBox[4]);

JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
legendHeading, VBox[0]);


legendPanel.add(splitPane);

}
legendPanel = new LegendPanel();

/**
* Initializes the shortest path finder panel with source/target selection,
Expand Down Expand Up @@ -2683,4 +2620,4 @@ public static void main(String[] args) {
}
});
}
}
}
Loading