Skip to content
Snippets Groups Projects
Unverified Commit 3bd8710a authored by David Bohn's avatar David Bohn
Browse files

Added file selector to select topology file

parent 76c6e39b
No related branches found
No related tags found
1 merge request!6Overlay topology
......@@ -8,12 +8,14 @@ import fucoin.actions.transaction.ActionGetAmount;
import fucoin.actions.transaction.ActionGetAmountAnswer;
import fucoin.configurations.internal.ConfigurationName;
import fucoin.configurations.internal.GephiLoader;
import fucoin.gui.gephi.GephiFileSelector;
import fucoin.gui.gephi.GraphWindow;
import org.gephi.graph.api.Graph;
import scala.concurrent.Future;
import scala.concurrent.duration.Duration;
import java.io.FileNotFoundException;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
@ConfigurationName("Gephi Test Configuration")
......@@ -26,11 +28,14 @@ public class GephiConfiguration extends AbstractConfiguration {
initSupervisor();
GephiLoader gephiLoader = new GephiLoader();
GephiFileSelector fileSelector = new GephiFileSelector();
Graph g;
File selectedTopology;
try {
g = gephiLoader.loadFileFromResources("/topology2.gexf");
} catch (URISyntaxException | FileNotFoundException e) {
selectedTopology = fileSelector.selectTopology();
g = gephiLoader.loadFile(selectedTopology);
} catch (URISyntaxException | IOException e) {
e.printStackTrace();
return;
}
......@@ -38,6 +43,9 @@ public class GephiConfiguration extends AbstractConfiguration {
createOverlayNetwork(g);
GraphWindow graphWindow = new GraphWindow();
graphWindow.setDisplayedFilename(selectedTopology.getName());
graphWindow.setVisible(true);
graphWindow.addNodeClickHandler((node, event) -> {
ActorRef wallet = walletByName(node.getLabel());
......@@ -51,6 +59,5 @@ public class GephiConfiguration extends AbstractConfiguration {
}, context().dispatcher());
});
graphWindow.setVisible(true);
}
}
......@@ -2,7 +2,6 @@ package fucoin.configurations.internal;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.Node;
import org.gephi.io.importer.api.Container;
import org.gephi.io.importer.api.ImportController;
import org.gephi.io.processor.plugin.DefaultProcessor;
......@@ -12,22 +11,28 @@ import org.openide.util.Lookup;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
/**
* @author davidbohn
*/
public class GephiLoader {
Workspace workspace;
private Workspace workspace;
/**
* Load a graph file that is in the resources directory of the application
*
* @throws URISyntaxException
* @throws FileNotFoundException
*/
public Graph loadFileFromResources(String path) throws URISyntaxException, FileNotFoundException {
return loadFile(getClass().getResource(path).toURI());
return loadFile(new File(getClass().getResource(path).toURI()));
}
public Graph loadFile(URI filename) throws FileNotFoundException {
/**
* Initialize the Gephi toolkit and load the provided file
*
* @throws FileNotFoundException
*/
public Graph loadFile(File file) throws FileNotFoundException {
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
......@@ -35,7 +40,6 @@ public class GephiLoader {
Container container;
ImportController importController = Lookup.getDefault().lookup(ImportController.class);
File file = new File(filename);
container = importController.importFile(file);
......
package fucoin.gui.gephi;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;
public class GephiFileSelector {
/**
* Display a file selector to select a gephi graph file
* @return the selected file or the first graph in the resources directory if none selected
* @throws IOException
* @throws URISyntaxException
*/
public File selectTopology() throws IOException, URISyntaxException {
JFileChooser fileChooser = new JFileChooser(new File(getClass().getResource("/").toURI()));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
FileNameExtensionFilter fileNameExtensionFilter = new FileNameExtensionFilter("Graph Files", "gexf");
fileChooser.setFileFilter(fileNameExtensionFilter);
int result = fileChooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
return fileChooser.getSelectedFile();
}
return getBundledTopologies().get(0);
}
/**
* Get a list of all bundled topology files (i.e. that are stored in the resources)
* @throws URISyntaxException
* @throws IOException
*/
public List<File> getBundledTopologies() throws URISyntaxException, IOException {
return Files.list(Paths.get(getClass().getResource("/").toURI()))
.filter(Files::isRegularFile)
.filter(path -> path.toString().toLowerCase().endsWith(".gexf"))
.map(Path::toFile).collect(Collectors.toList());
}
}
......@@ -20,10 +20,12 @@ public class GraphWindow extends JFrame implements NodeMouseListener {
private JLabel infobarText;
private final String baseWindowTitle = "Network Overlay Graph";
public GraphWindow() {
super();
setTitle("Network Overlay Graph");
setTitle(baseWindowTitle);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
......@@ -79,6 +81,10 @@ public class GraphWindow extends JFrame implements NodeMouseListener {
this.setSize(800, 600);
}
public void setDisplayedFilename(String filename) {
setTitle(baseWindowTitle + " - " + filename);
}
public static boolean isRetina() {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice device = env.getDefaultScreenDevice();
......
package fucoin.gui.gephi;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.Node;
import org.gephi.preview.api.Item;
import org.gephi.preview.spi.ItemBuilder;
import org.openide.util.lookup.ServiceProvider;
import java.util.Arrays;
@ServiceProvider(service = ItemBuilder.class)
public class ItemBuilderTemplate implements ItemBuilder {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment