public GraphController(Container parentContainer, OWLEditorKit owlEditorKit) { model = new ProtegeGraphModel(owlEditorKit); this.graph = new FlatGraph(model); this.graph.setShowNodeTooltips(false); this.graph.setGraphNodeStyle(nodeStyle); this.graph.setGraphArcStyle(arcStyle); this.graph.addLayoutListener(new ProgressListener() { public void progressEnded(ProgressEvent arg0) { }); this.graph.getFilterManager().addFilterChangedListener(new FilterChangedListener() { public void filtersChanged(FilterChangedEvent fce) {
private void initialize(Container parentContainer) { // setup the layouts List<Object> layoutRelTypes = new ArrayList<Object>(); layoutRelTypes.add(ProtegeGraphModel.DIRECT_SUBCLASS_SLOT_TYPE); layoutRelTypes.add(ProtegeGraphModel.DIRECT_INDIVIDUAL_SLOT_TYPE); for (LayoutAction layoutAction : graph.getLayouts()) { if (layoutAction.getName().equals(LayoutConstants.LAYOUT_TREE_HORIZONTAL)) { layoutAction.setLayout(new HorizontalDirectedGraphLayoutAlgorithm()); this.graph.setLastLayout(layoutAction); layoutAction.setLayoutRelTypes(layoutRelTypes); } else if (layoutAction.getName().equals(LayoutConstants.LAYOUT_TREE_VERTICAL)) { layoutAction.setLayout(new DirectedGraphLayoutAlgorithm()); layoutAction.setLayoutRelTypes(layoutRelTypes); } } view = new DefaultFlatGraphView(graph); parentContainer.add(view, BorderLayout.CENTER); initNodeMenu(graph.getNodeContextMenu()); graph.addInputEventListener(new ProtegeInputEventHandler(model, graph)); }
private FilterPanel getArcFilterPanel() { if (arcFilterPanel == null) { Icon icon = ResourceHandler.getIcon("icon_arc_filter.gif"); final FilterManager filterManager = graph.getFilterManager(); arcFilterPanel = new FilterPanel("Arc Types", icon, graph.getGraphArcStyle()) { private static final long serialVersionUID = -1656466039034202473L; graph.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (Graph.GRAPH_ARC_STYLE_PROPERTY.equals(evt.getPropertyName())) { graph.getModel().addGraphModelListener(new GraphModelAdapter() { @Override public void graphArcTypeAdded(Object arcType) {
public void displayAsSingleNode(OWLEntity entity) { model.show(entity, graph.getFilterManager()); graph.performLayout(); }
private FilterPanel getNodeFilterPanel() { if (nodeFilterPanel == null) { Icon icon = ResourceHandler.getIcon("icon_node_filter.gif"); final FilterManager filterManager = graph.getFilterManager(); nodeFilterPanel = new FilterPanel("Node Types", icon, graph.getGraphNodeStyle()) { private static final long serialVersionUID = -2445793622682539920L; graph.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (Graph.GRAPH_NODE_STYLE_PROPERTY.equals(evt.getPropertyName())) { filterManager.addFilterChangedListener(nodeFilterPanel); graph.getModel().addGraphModelListener(new GraphModelAdapter() { @Override public void graphNodeTypeAdded(Object nodeType) {
public FlatGraph(GraphModel model) { super(model); setDefaultRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); setAnimatingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); setInteractingRenderQuality(PPaintContext.HIGH_QUALITY_RENDERING); this.animationHandler = new AnimationHandler(this); PCamera camera = getCamera(); // use our custom pan handler (when the canvas is dragged) setPanEventHandler(new CameraDragPanHandler()); // this causes panning to happen when the arrow keys are pressed camera.addInputEventListener(new CameraKeyPanHandler(camera)); // disable key zooming - we'll use our own handler setZoomEventHandler(null); // handles keyboard (+/-) and mouse wheel zoom events camera.addInputEventListener(new ZoomHandler(camera)); // handles dragging of nodes camera.addInputEventListener(new NodeDragHandler()); // handles node selections camera.addInputEventListener(new SelectionHandler(getNodeSelection())); // handles highlighting nodes and arcs camera.addInputEventListener(new HighlightHandler()); // ensures that all nodes are displayed on the canvas camera.addInputEventListener(new FocusOnExtentsHandler(animationHandler)); }
this.graph = new FlatGraph(model); this.view = new DefaultFlatGraphView(graph); for (LayoutAction layoutAction : graph.getLayouts()) { if (layoutAction.getName().equals(LayoutConstants.LAYOUT_SPRING)) { layoutAction.setLayout(new HorizontalDirectedGraphLayoutAlgorithm()); this.graph.setLastLayout(layoutAction); this.graph.performLayout();
private void initializeToolBar() { // Home addToolBarAction(new FocusOnHomeAction(graph.getAnimationHandler())); addToolBarAction(new ClearOrphansAction(graph.getModel(), graph)); getToolBar().addSeparator(); // Layouts for (LayoutAction action : graph.getLayouts()) { addToolBarAction(action); } getToolBar().addSeparator(); // zoom addToolBarAction(new ZoomInAction(graph.getCamera())); addToolBarAction(new NoZoomAction(graph.getCamera())); addToolBarAction(new ZoomOutAction(graph.getCamera())); getToolBar().addSeparator(); // node and arc filter actions final JToggleButton nodesToggle = addToolBarToggleAction(new ShowFilterPanelAction(getNodeFilterPanel())); final JToggleButton arcsToggle = addToolBarToggleAction(new ShowFilterPanelAction(getArcFilterPanel())); // listen for panel close events - keep the toggle buttons in sync getNodeFilterPanel().getCloseButton().addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { nodesToggle.setSelected(false); } }); getArcFilterPanel().getCloseButton().addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { arcsToggle.setSelected(false); } }); }
public MainFrame() { super("Baby Shrimp Test"); SampleGraphModel model = new SampleGraphModel(); this.graph = new FlatGraph(model); // color the nodes based on node type DefaultGraphNodeStyle nodeStyle = new DefaultGraphNodeStyle(); nodeStyle.setNodeTypes(model.getNodeTypes()); this.graph.setGraphNodeStyle(nodeStyle); // color the arcs based on arc type DefaultGraphArcStyle arcStyle = new DefaultGraphArcStyle(); arcStyle.setArcTypes(model.getArcTypes()); this.graph.setGraphArcStyle(arcStyle); initialize(); // run the initial layout on the nodes //SwingUtilities.invokeLater(new Runnable() { // public void run() { // try { // Thread.sleep(100); // } catch (InterruptedException e) { // } // graph.performLayout(); //} //}); }
/** * Performs a search on the ontology with the given string. * * @param searchString The entered string to search on * @param searchMode The search type mode that determines how to match the searchString */ public int search(String searchString, String searchMode) { searchString = prepareSearchString(searchString, searchMode); for(GraphNode node : model.getAllNodes()) node.setSelected(false); Collection<GraphNode> matchingNodes = new ArrayList<GraphNode>(); Collection<? extends OWLEntity> searchResults = model.search(searchString, graph.getFilterManager()); for (OWLEntity owlEntity : searchResults) { GraphNode node = model.getNode(owlEntity); if(node != null) { matchingNodes.add(model.getNode(owlEntity)); } } graph.setSelectedNodes(matchingNodes); graph.setMatchingNodes(matchingNodes); graph.performLayout(); //model.recalculateArcTypes(); return searchResults.size(); }
model.show(owlClass, graph.getFilterManager()); graph.setMatchingNodes(matchingNodes); graph.performLayout();
/** * Sets the expansion menu options enabled/disabled flag based on the current state of the * node. If the node has already been expanded, everything is disabled. Otherwise, all the * non-filtered arc types are enabled. * @param node */ private void initNodeActionConditions(GraphNode node) { if (model.isExpanded(node)) { expandAction.setEnabled(false); for (Action action : expandBasedOnActions) { action.setEnabled(false); } } else { expandAction.setEnabled(true); for (Action action : expandBasedOnActions) { if(graph.getFilterManager().isArcTypeVisible(((CajunAction)action).getName())) { action.setEnabled(true); } else { action.setEnabled(false); } } } }
private void initialize() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(new BorderLayout()); DefaultFlatGraphView view = new DefaultFlatGraphView(graph); getContentPane().add(view, BorderLayout.CENTER); graph.getNodeContextMenu().add(new CajunAction("Test #1")); graph.getNodeContextMenu().add(new CajunAction("Test #2")); JPanel buttonsPanel = new JPanel(); buttonsPanel.add(new JButton(new AbstractAction(" Close ") { public void actionPerformed(ActionEvent e) { MainFrame.this.dispose(); } })); pack(); Dimension d = new Dimension(800, 600); setPreferredSize(d); setSize(d); setLocation(100, 50); setVisible(true); }
private void panTo(DefaultGraphNode node) { if(node != null) { double x = node.getFullBoundsReference().getX(); double y = node.getFullBoundsReference().getY(); double w = node.getFullBoundsReference().getWidth(); double h = node.getFullBoundsReference().getHeight(); PBounds bounds = new PBounds(x - w * .01, y - h * .02, w + w * .02, h + h * .04); // only pan to the bounds if the node is not already visible if(!graph.getCamera().getViewBounds().contains(bounds.getBounds2D())) { graph.getRoot().getActivityScheduler().addActivity( graph.getCamera().animateViewToCenterBounds(bounds.getBounds2D(), false, ANIMATION_DURATION) ); } } }
if(entities != null && entities.size() > 0) { for(OWLEntity owlEntity : entities) { model.show(owlEntity, graph.getFilterManager());