CPD Results

The following document contains the results of PMD's CPD 4.2.2.

Duplications

File Line
edu/uci/ics/jung/samples/HyperbolicVertexImageShaperDemo.java 334
edu/uci/ics/jung/samples/PerspectiveVertexImageShaperDemo.java 394
        public String transform(Object v) {
            if(isEnabled()) {
                return map.get(v);
            } else {
                return "";
            }
        }

        /**
         * @return Returns the enabled.
         */
        public boolean isEnabled() {
            return enabled;
        }

        /**
         * @param enabled The enabled to set.
         */
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
    }
    
    /**
     * create some vertices
     * @param count how many to create
     * @return the Vertices in an array
     */
    private Number[] createVertices(int count) {
        Number[] v = new Number[count];
        for (int i = 0; i < count; i++) {
            v[i] = new Integer(i);
            graph.addVertex(v[i]);
        }
        return v;
    }

    /**
     * create edges for this demo graph
     * @param v an array of Vertices to connect
     */
    void createEdges(Number[] v) {
        graph.addEdge(new Double(Math.random()), v[0], v[1], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[3], v[0], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[0], v[4], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[4], v[5], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[5], v[3], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[2], v[1], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[4], v[1], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[8], v[2], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[3], v[8], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[6], v[7], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[7], v[5], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[0], v[9], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[9], v[8], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[7], v[6], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[6], v[5], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[4], v[2], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[5], v[4], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[4], v[10], EdgeType.DIRECTED);
        graph.addEdge(new Double(Math.random()), v[10], v[4], EdgeType.DIRECTED);
    }
    
    public static class PickWithIconListener implements ItemListener {
        DefaultVertexIconTransformer<Number> imager;
        Icon checked;
        
        public PickWithIconListener(DefaultVertexIconTransformer<Number> imager) {
            this.imager = imager;
            checked = new Checkmark(Color.red);
        }

        public void itemStateChanged(ItemEvent e) {
            Icon icon = imager.transform((Number)e.getItem());
            if(icon != null && icon instanceof LayeredIcon) {
                if(e.getStateChange() == ItemEvent.SELECTED) {
                    ((LayeredIcon)icon).add(checked);
                } else {
                    ((LayeredIcon)icon).remove(checked);
                }
            }
        }
    }

    /**
     * a simple Icon that draws a checkmark in the lower-right quadrant of its
     * area. Used to draw a checkmark on Picked Vertices.
     */
//    public static class Checkmark implements Icon {
//
//            GeneralPath path = new GeneralPath();
//            AffineTransform highlight = AffineTransform.getTranslateInstance(-1,-1);
//            AffineTransform lowlight = AffineTransform.getTranslateInstance(1,1);
//            AffineTransform shadow = AffineTransform.getTranslateInstance(2,2);
//            Color color;
//            public Checkmark() {
//                this(Color.red);
//            }
//            public Checkmark(Color color) {
//                this.color = color;
//                path.moveTo(10,17);
//                path.lineTo(13,20);
//                path.lineTo(20,13);
//            }
//        public void paintIcon(Component c, Graphics g, int x, int y) {
//            Shape shape = AffineTransform.getTranslateInstance(x, y).createTransformedShape(path);
//            Graphics2D g2d = (Graphics2D)g;
//            g2d.addRenderingHints(Collections.singletonMap(RenderingHints.KEY_ANTIALIASING, 
//                    RenderingHints.VALUE_ANTIALIAS_ON));
//            g2d.setStroke(new BasicStroke(4));
//            g2d.setColor(Color.darkGray);
//            g2d.draw(shadow.createTransformedShape(shape));
//            g2d.setColor(Color.black);
//            g2d.draw(lowlight.createTransformedShape(shape));
//            g2d.setColor(Color.white);
//            g2d.draw(highlight.createTransformedShape(shape));
//            g2d.setColor(color);
//            g2d.draw(shape);
//        }
//
//        public int getIconWidth() {
//            return 20;
//        }
//
//        public int getIconHeight() {
//            return 20;
//        }
//    }
//   /**
//     * An icon that is made up of a collection of Icons.
//     * They are rendered in layers starting with the first
//     * Icon added (from the constructor).
//     * 
//     * @author Tom Nelson
//     *
//     */
//    public static class LayeredIcon extends ImageIcon {
//
//		/**
//		 * 
//		 */
//    	private static final long serialVersionUID = -2975294939874762164L;
//		Set<Icon> iconSet = new LinkedHashSet<Icon>();
//
//		public LayeredIcon(Image image) {
//            super(image);
//		}
//
//        public void paintIcon(Component c, Graphics g, int x, int y) {
//            super.paintIcon(c, g, x, y);
//            Dimension d = new Dimension(getIconWidth(), getIconHeight());
//            for (Iterator iterator = iconSet.iterator(); iterator.hasNext();) {
//                Icon icon = (Icon) iterator.next();
//                 Dimension id = new Dimension(icon.getIconWidth(), icon.getIconHeight());
//                 int dx = (d.width - id.width)/2;
//                 int dy = (d.height - id.height)/2;
//                icon.paintIcon(c, g, x+dx, y+dy);
//            }
//        }
//
//		public void add(Icon icon) {
//			iconSet.add(icon);
//		}
//
//		public boolean remove(Icon icon) {
//			return iconSet.remove(icon);
//		}
//	}

    /**
     * a driver for this demo
     */
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        Container content = frame.getContentPane();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        content.add(new PerspectiveVertexImageShaperDemo());

File Line
edu/uci/ics/jung/samples/PerspectiveTransformerDemo.java 156
edu/uci/ics/jung/samples/PerspectiveVertexImageShaperDemo.java 221
        this.layoutSupport = new PerspectiveLayoutTransformSupport<Number,Number>(vv);
        
        final ScalingControl scaler = new CrossoverScalingControl();

        JButton plus = new JButton("+");
        plus.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                scaler.scale(vv, 1.1f, vv.getCenter());
            }
        });
        JButton minus = new JButton("-");
        minus.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                scaler.scale(vv, 0.9f, vv.getCenter());
            }
        });
        final JSlider horizontalSlider = new JSlider(-120,120,0){

			/* (non-Javadoc)
			 * @see javax.swing.JComponent#getPreferredSize()
			 */
			@Override
			public Dimension getPreferredSize() {
				return new Dimension(80, super.getPreferredSize().height);
			}
        };
        
        final JSlider verticalSlider = new JSlider(-120,120,0) {

			/* (non-Javadoc)
			 * @see javax.swing.JComponent#getPreferredSize()
			 */
			@Override
			public Dimension getPreferredSize() {
				return new Dimension(super.getPreferredSize().width, 80);
			}
        };
        verticalSlider.setOrientation(JSlider.VERTICAL);
        final ChangeListener changeListener = new ChangeListener() {

			public void stateChanged(ChangeEvent e) {
                int vval = -verticalSlider.getValue();
                int hval = horizontalSlider.getValue();

                Dimension d = vv.getSize();
                 PerspectiveTransform pt = null;
                    pt = PerspectiveTransform.getQuadToQuad(
                            vval,          hval, 
                            d.width-vval, -hval, 
                            d.width+vval, d.height+hval, 
                            -vval,         d.height-hval,
                            
                            0, 0, 
                            d.width, 0, 
                            d.width, d.height, 
                            0, d.height);

                viewSupport.getPerspectiveTransformer().setPerspectiveTransform(pt);
                layoutSupport.getPerspectiveTransformer().setPerspectiveTransform(pt);
                vv.repaint();
			}};
		horizontalSlider.addChangeListener(changeListener);
		verticalSlider.addChangeListener(changeListener);
		
		
        JPanel perspectivePanel = new JPanel(new BorderLayout());
        JPanel perspectiveCenterPanel = new JPanel(new BorderLayout());
        perspectivePanel.setBorder(BorderFactory.createTitledBorder("Perspective Controls"));
        final JButton center = new JButton("Center");
        center.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				horizontalSlider.setValue(0);
				verticalSlider.setValue(0);
			}});

File Line
edu/uci/ics/jung/samples/HyperbolicVertexImageShaperDemo.java 184
edu/uci/ics/jung/samples/PerspectiveVertexImageShaperDemo.java 173
        vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl);
        PickedState<Number> ps = vv.getPickedVertexState();
        ps.addItemListener(new PickWithIconListener(vertexIconFunction));


        vv.addPostRenderPaintable(new VisualizationServer.Paintable(){
            int x;
            int y;
            Font font;
            FontMetrics metrics;
            int swidth;
            int sheight;
            String str = "Thank You, slashdot.org, for the images!";
            
            public void paint(Graphics g) {
                Dimension d = vv.getSize();
                if(font == null) {
                    font = new Font(g.getFont().getName(), Font.BOLD, 20);
                    metrics = g.getFontMetrics(font);
                    swidth = metrics.stringWidth(str);
                    sheight = metrics.getMaxAscent()+metrics.getMaxDescent();
                    x = (d.width-swidth)/2;
                    y = (int)(d.height-sheight*1.5);
                }
                g.setFont(font);
                Color oldColor = g.getColor();
                g.setColor(Color.lightGray);
                g.drawString(str, x, y);
                g.setColor(oldColor);
            }
            public boolean useTransform() {
                return false;
            }
        });

        // add a listener for ToolTips
        vv.setVertexToolTipTransformer(new ToStringLabeller<Number>());
        
        Container content = getContentPane();
        final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
        content.add(panel);
        
        final DefaultModalGraphMouse<Number, Number> graphMouse = 
            new DefaultModalGraphMouse<Number, Number>();

        vv.setGraphMouse(graphMouse);

File Line
edu/uci/ics/jung/samples/HyperbolicVertexImageShaperDemo.java 128
edu/uci/ics/jung/samples/PerspectiveVertexImageShaperDemo.java 129
	public PerspectiveVertexImageShaperDemo() {
        
        // create a simple graph for the demo
        graph = new DirectedSparseMultigraph<Number,Number>();
        Number[] vertices = createVertices(11);
        
        // a Map for the labels
        Map<Number,String> map = new HashMap<Number,String>();
        for(int i=0; i<vertices.length; i++) {
            map.put(vertices[i], iconNames[i%iconNames.length]);
        }
        
        // a Map for the Icons
        Map<Number,Icon> iconMap = new HashMap<Number,Icon>();
        for(int i=0; i<vertices.length; i++) {
            String name = "/images/topic"+iconNames[i]+".gif";
            try {
                Icon icon = 
                    new LayeredIcon(new ImageIcon(PerspectiveVertexImageShaperDemo.class.getResource(name)).getImage());