0
votes

I am trying to retrieve 2 columns from MySQL database. One column is used to create vertexes using Jung. In second column i have 2 values. I have to change the vertex size based on the values in the second field. the Coding part:

try {

        String query = "select GeneID, GenExpression from gene1 where Disease= 'Hereditery Breast Cancer '";
        PreparedStatement pest = connection.prepareStatement(query);
        ResultSet rs = pest.executeQuery();

        while (rs.next()) {

            name1[i] = rs.getString("GeneID");
            g.addVertex(name1[i]);
            name2[j] = rs.getString("GenExpression");
            System.out.println(name2[j]);

            i++;
            j++;
        }

        rs.close();
        pest.close();

and I was trying with the following code.

ransformer<String, Paint> vertexPaint = new Transformer<String, Paint>() {
        public Paint transform(String i) {
            return Color.red;
        }
    };

    Transformer<String, Shape> vertexSize = new Transformer<String, Shape>() {
        public Shape transform(String x) {
            Ellipse2D circle = new Ellipse2D.Double(-10, -10, 40, 40);
            for (i = 0; i < name2.length; i++) {
                for (j = 0; j < name2.length; j++) {
                    if (name2[j] == "Upregulated") {
                        AffineTransform.getScaleInstance(3, 3)
                                .createTransformedShape(circle);
                    } else {

                        AffineTransform.getScaleInstance(3, 3)
                                .createTransformedShape(circle);
                    }

                }
            }
            return circle;
        }
    };

    // Set up a new stroke Transformer for the edges
    float dash[] = { 10.0f };
    final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
            BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
    Transformer<Integer, Stroke> edgeStrokeTransformer = new Transformer<Integer, Stroke>() {
        public Stroke transform(Integer i) {
            return edgeStroke;
        }
    };

    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    // vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    vv.getRenderContext().setEdgeArrowStrokeTransformer(
            edgeStrokeTransformer);

    vv.getRenderContext().setVertexShapeTransformer(vertexSize);
vv.getRenderContext().setVertexLabelTransformer(
            new ToStringLabeller<String>());   

But the size is not changing according to the condition. Can anyone help me with this?

1
You're not showing anything about how (or whether) you're trying to use this Transformer in your code. For an example of how to specify a shape for your vertex, you may want to consult the source for PluggableRendererDemo (specifically the VertexShapeSizeAspect inner class: grepcode.com/file/repo1.maven.org/maven2/net.sf.jung/…) and for VertexShapeFactory (jung.sourceforge.net/doc/api/edu/uci/ics/jung/visualization/…). - Joshua O'Madadhain
Side comment: this code is really hard to read because of your peculiar indenting and bracketing. Consider running your code snippets through an autoformatter before posting them. - Joshua O'Madadhain
Thank you. But I couldn't understand it clearly since i am new to Jung. Can u explain me with simple examples. - Steffi Matchado

1 Answers

0
votes

Your code has at least two problems:

(1) you are creating a transformed copy of your shape but you're not using that copy for anything

(2) the transformation that you're applying is the same in all cases so there won't be any difference.

I don't know whether your data (based on which you're choosing which transformation to perform) are set up correctly, but that's another possible source of error.