Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.uberfire.ext.wires.bayesian.network.client.factory;
 
 import java.util.List;
 import java.util.Map;
 import  javax.enterprise.context.ApplicationScoped;
 import  javax.enterprise.event.Event;
 import  javax.inject.Inject;
 
 import  com.google.common.collect.Lists;
 import  com.google.common.collect.Maps;
 import  org.jboss.errai.common.client.api.Caller;
 import  org.jboss.errai.common.client.api.ErrorCallback;
 import  org.jboss.errai.common.client.api.RemoteCallback;
 import  org.uberfire.ext.wires.bayesian.network.parser.client.model.BayesNetwork;
 import  org.uberfire.ext.wires.bayesian.network.parser.client.model.BayesVariable;
 import  org.uberfire.ext.wires.bayesian.network.parser.client.service.BayesianService;
 import  org.uberfire.ext.wires.core.client.progressbar.ProgressBar;
 
 @ApplicationScoped
 public class BayesianFactory extends BaseFactory {
 
     @Inject
     private Caller<BayesianService> bayesianService;
 
     @Inject
     private Event<RenderBayesianNetworkEventreadyEvent;
 
     private String[][] colors;
 
     public void initfinal String xml03File ) {
         .call( new RemoteCallback<BayesNetwork>() {
                                   @Override
                                   public void callbackfinal BayesNetwork response ) {
                                       .clear();
                                       for ( BayesVariable bay : response.getNodos() ) {
                                           drawBayesianNodebay );
                                       }
                                       .fire( new RenderBayesianNetworkEvent ) );
 
                                   }
                               }, new ErrorCallback<Object>() {
 
                                   @Override
                                   public boolean errorObject message,
                                                         Throwable throwable ) {
                                       Window.alert"Sorry.. the " + xml03File + " could not be read.." );
                                       ProgressBar.setInfinite( false );
                                       return false;
                                   }
                               }
                             ).buildXml03( . + xml03File );
     }
 
     private void drawBayesianNode( BayesVariable node ) {
          = BayesianUtils.getNodeColors();
         double position[][] = node.getPosition();
         int positionX = (int) ( . + Math.roundposition[ 0 ][ 0 ] ) );
         int positionY = (int) ( . + Math.roundposition[ 0 ][ 1 ] ) );
         String fillNodeColor = [ 0 ][ 0 ];
 
         EditableBayesianNode bayesianNode = new EditableBayesianNode.,
                                                                       .,
                                                                       positionX,
                                                                       positionY,
                                                                       fillNodeColor,
                                                                       node );
 
         this.setHeadernode,
                         bayesianNode );
         this.setPorcentualBarnode,
                                bayesianNode );
 
         bayesianNode.buildNode();
 
         .addbayesianNode );
    }
    private void setHeader( BayesVariable node,
                            EditableBayesianNode bayesianNode ) {
        bayesianNode.setHeadernew RectanglebayesianNode.getWidth(),
                                               . ) );
        bayesianNode.getHeader().setFillColor[ 0 ][ 1 ] );
        bayesianNode.getHeader().setXbayesianNode.getHeader().getX() );
        bayesianNode.setTextHeaderdrawTextnode.getName(),
                                              .,
                                              .,
                                              . ) );
    }
    private void setPorcentualBar( BayesVariable node,
                                   EditableBayesianNode bayesianNode ) {
        String fillColor = [ 0 ][ 1 ];
        int widthFill;
        int positionY = 18;
        positionY = ( node.getOutcomes().size() > 3 ) ? positionY - 10 : positionY;
        String borderColor = fillColor;
        List<RectanglecomponentsProgressBar = Lists.newArrayList();
        Text labelPorcentual;
        Map<TextList<Rectangle>> porcentualsBar = Maps.newHashMap();
        for ( int i = 0; i < node.getOutcomes().size(); i++ ) {
            // Porcentual bar
            positionY += 14;
            labelPorcentual = this.drawTextnode.getOutcomes().get( i ),
                                             .,
                                             .,
                                             positionY + 7 );
            componentsProgressBar.addthis.drawComponent( Color.rgbToBrowserHexColor( 255,
                                                                                       255,
                                                                                       255 ),
                                                           .,
                                                           positionY,
                                                           .,
                                                           .,
                                                           borderColor,
                                                           3 ) );
            // fill bar
            widthFill = calculatePorcentagenode.getProbabilities(),
                                             .i );
            componentsProgressBar.adddrawComponentfillColor,
                                                      .,
                                                      positionY,
                                                      widthFill,
                                                      .,
                                                      borderColor,
                                                      0 ) );
            bayesianNode.getPorcentualsBar().putlabelPorcentual,
                                                  componentsProgressBar );
            porcentualsBar.putlabelPorcentual,
                                componentsProgressBar );
        }
        bayesianNode.setPorcentualBarsporcentualsBar );
    }
    private int calculatePorcentagedouble probabilities[][],
                                     int maxWidthFill,
                                     int position ) {
        double porcentual = 0;
        if ( position == 0 ) {
            porcentual = probabilities[ 0 ][ 0 ];
        } else if ( position == 1 ) {
            porcentual = probabilities[ 0 ][ 1 ];
        }
        porcentual *= 100;
        return (int) ( ( porcentual * maxWidthFill ) / 100 );
    }
New to GrepCode? Check out our FAQ X