/** * Method paint. Paints the rings on the graph. * * @param g Graphics - the graphics to be painted. */ @Override public void paint(Graphics g) { Collection<Double> depths = getDepths(); g.setColor(Color.gray); Graphics2D g2d = (Graphics2D) g; Point2D center = radialLayout.getCenter(); Ellipse2D ellipse = new Ellipse2D.Double(); for (double d : depths) { ellipse.setFrameFromDiagonal( center.getX() - d, center.getY() - d, center.getX() + d, center.getY() + d); AffineTransform at = AffineTransform.getTranslateInstance(0, 0); Shape shape = at.createTransformedShape(ellipse); // Shape shape = // vv.getRenderContext().getMultiLayerTransformer().transform(ellipse); // // vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).transform(ellipse); MutableTransformer viewTransformer = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW); if (viewTransformer instanceof MutableTransformerDecorator) { shape = vv.getRenderContext().getMultiLayerTransformer().transform(shape); } else { shape = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, shape); } g2d.draw(shape); } }
/** * Method getDepths. - gets the radii for each of the rings in the graph * * @return Collection - returns the radii results. */ public Collection<Double> getDepths() { Set<Double> depths = new HashSet<>(); Map<SEMOSSVertex, PolarPoint> polarLocations = radialLayout.getPolarLocations(); for (SEMOSSVertex v : graph.getVertices()) { PolarPoint pp = polarLocations.get(v); depths.add(pp.getRadius()); } return depths; }
public SearchTreeFrame(DelegateForest<MetaVariable, ConstraintNetwork> graph) { this.graph = graph; treeLayout = new TreeLayout<MetaVariable, ConstraintNetwork>(graph); radialLayout = new RadialTreeLayout<MetaVariable, ConstraintNetwork>(graph); radialLayout.setSize(new Dimension(600, 600)); vv = new VisualizationViewer<MetaVariable, ConstraintNetwork>( treeLayout, new Dimension(600, 600)); vv.setBackground(Color.white); vv.getRenderContext() .setEdgeShapeTransformer(new EdgeShape.Line<MetaVariable, ConstraintNetwork>()); vv.getRenderContext() .setVertexLabelTransformer( new Transformer<MetaVariable, String>() { @Override public String transform(MetaVariable arg0) { return arg0.toString(); } }); vv.setVertexToolTipTransformer( new Transformer<MetaVariable, String>() { @Override public String transform(MetaVariable arg0) { return arg0.toString(); } }); // vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); vv.getRenderContext() .setArrowFillPaintTransformer( new Transformer<ConstraintNetwork, Paint>() { @Override public Paint transform(ConstraintNetwork arg0) { return Color.lightGray; } }); // System.out.println(graph.getVertices()); rings = new Rings(); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse<?, ?> graphMouse = new DefaultModalGraphMouse<Object, Object>(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton radial = new JToggleButton("Radial"); radial.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { LayoutTransition<MetaVariable, ConstraintNetwork> lt = new LayoutTransition<MetaVariable, ConstraintNetwork>( vv, treeLayout, radialLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { LayoutTransition<MetaVariable, ConstraintNetwork> lt = new LayoutTransition<MetaVariable, ConstraintNetwork>( vv, radialLayout, treeLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); content.add(controls, BorderLayout.SOUTH); }