Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiline label support for nodes/sprites #14

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<groupId>org.graphstream</groupId>
<artifactId>gs-ui-swing</artifactId>
<version>2.0</version>
<version>2.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>gs-ui-swing</name>
Expand Down
136 changes: 136 additions & 0 deletions src-test/org/graphstream/ui/viewer_swing/test/Clicks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import org.graphstream.graph.Graph;
import org.graphstream.graph.Node;
import org.graphstream.graph.implementations.SingleGraph;
import org.graphstream.ui.swing_viewer.SwingViewer;
import org.graphstream.ui.swing_viewer.ViewPanel;
import org.graphstream.ui.view.Viewer;
import org.graphstream.ui.view.ViewerListener;
import org.graphstream.ui.view.ViewerPipe;

import javax.swing.*;
import java.awt.*;

public class Clicks {

static Graph graph;
static JDialog mainFrame;
static JPanel mainPanel;

static JTextArea codeArea;


public static void main(String args[]) {
System.setProperty("org.graphstream.ui", "swing");
System.setProperty("sun.java2d.uiScale", "1.0");
new Clicks();
System.out.println("Doneee");

}


boolean loop;
public Clicks() {
loop = true;
mainFrame = new JDialog();
JDialog frame = mainFrame;
mainPanel = new JPanel(){
@Override
public Dimension getPreferredSize() {
return new Dimension(640, 480);
}
};
mainPanel.setLayout(new BorderLayout());
JPanel panel = mainPanel;
codeArea = new JTextArea();
codeArea.setEditable(false);






frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

panel.setBorder(BorderFactory.createLineBorder(Color.blue, 5));
mainFrame.add(panel);

graph = new SingleGraph("Clicks");
graph.setAttribute("ui.stylesheet",
"node {\n" +
" fill-color: yellow;\n" +
" text-color: blue;\n" +
" text-size: 15;\n" +
" shape: box;\n" +
// " size: 50px;\n" +
" size-mode: fit;\n" +
"}\n" +
"sprite.basicBlock {\n" +
" shape: rounded-box;\n" +
" stroke-mode: plain;\n" +
" stroke-color: #000000;\n" +
" fill-color: green;\n" +
" size-mode: fit;\n" +
" text-alignment: center;\n" +
"}");

Node a = graph.addNode("A");
a.setAttribute("ui.label", "Line1\nLine2\nLine3\nLine4\nLine5\nLine6\nLine7\nLine8\nLine9\nLine10\nLine11\nLine12\nLine13\nLine14\nLine15\nLine16\nLine17\nLine18\nLine19\nLine20\nLine21\nLine22\nLine23\nLine24\nLine25");
graph.addNode("B");
graph.addNode("C");
graph.addEdge("AB", "A", "B");
graph.addEdge("BC", "B", "C");
graph.addEdge("CA", "C", "A");

Viewer viewer = new SwingViewer(graph, Viewer.ThreadingModel.GRAPH_IN_GUI_THREAD);


ViewPanel viewPanel = (ViewPanel) viewer.addDefaultView(false);
viewer.getDefaultView().enableMouseOptions();
viewer.enableAutoLayout();

panel.add(viewPanel, BorderLayout.CENTER);
// panel.add(codeArea, BorderLayout.SOUTH);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setModal(true);

ViewerPipe fromViewer = viewer.newViewerPipe();
fromViewer.addViewerListener(new MouseOptions());
fromViewer.addSink(graph);

while(loop) {
fromViewer.pump();
if (!frame.isVisible()) {
break;
}
}

}



public class MouseOptions implements ViewerListener {
public void viewClosed(String id) {

loop = false;
}

public void buttonPushed(String id) {
// codeArea.setText((String) graph.getNode(id).getAttribute("ui.label"));
// codeArea.setEditable(false);
}

public void buttonReleased(String id) {
System.out.println("Button released on node "+id);
}

public void mouseOver(String id) {
System.out.println("Need the Mouse Options to be activated");
}

public void mouseLeft(String id) {
System.out.println("Need the Mouse Options to be activated");
}
}
}
Loading