public Element renderCheckBox ( SVGPlot svgp , double x , double y , double size ) { // create check final Element checkmark = SVGEffects . makeCheckmark ( svgp ) ; checkmark . setAttribute ( SVGConstants . SVG_TRANSFORM_ATTRIBUTE , "scale(" + ( size / 12 ) + ") translate(" + x + " " + y + ")" ) ; if ( ! checked ) { checkmark . setAttribute ( SVGConstants . SVG_STYLE_ATTRIBUTE , SVGConstants . CSS_DISPLAY_PROPERTY + ":" + SVGConstants . CSS_NONE_VALUE ) ; } // create box Element checkbox_box = SVGUtil . svgRect ( svgp . getDocument ( ) , x , y , size , size ) ; checkbox_box . setAttribute ( SVGConstants . SVG_FILL_ATTRIBUTE , "#d4e4f1" ) ; checkbox_box . setAttribute ( SVGConstants . SVG_STROKE_ATTRIBUTE , "#a0a0a0" ) ; checkbox_box . setAttribute ( SVGConstants . SVG_STROKE_WIDTH_ATTRIBUTE , "0.5" ) ; // create checkbox final Element checkbox = svgp . svgElement ( SVGConstants . SVG_G_TAG ) ; checkbox . appendChild ( checkbox_box ) ; checkbox . appendChild ( checkmark ) ; // create Label if ( label != null ) { Element labele = svgp . svgText ( x + 2 * size , y + size , label ) ; // TODO: font size! checkbox . appendChild ( labele ) ; } // add click event listener EventTarget targ = ( EventTarget ) checkbox ; targ . addEventListener ( SVGConstants . SVG_CLICK_EVENT_TYPE , new EventListener ( ) { @ Override public void handleEvent ( Event evt ) { if ( checked ^= true ) { checkmark . removeAttribute ( SVGConstants . SVG_STYLE_ATTRIBUTE ) ; } else { checkmark . setAttribute ( SVGConstants . SVG_STYLE_ATTRIBUTE , SVGConstants . CSS_DISPLAY_PROPERTY + ":" + SVGConstants . CSS_NONE_VALUE ) ; } fireSwitchEvent ( new ChangeEvent ( SVGCheckbox . this ) ) ; } } , false ) ; return checkbox ; }
Render the SVG checkbox to a plot