Package com.ubx1.pdpscanner.client.views.project

Source Code of com.ubx1.pdpscanner.client.views.project.CommentsWidget

package com.ubx1.pdpscanner.client.views.project;

import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.ubx1.pdpscanner.client.views.AbstractView;
import com.ubx1.pdpscanner.shared.Project;

/**
* The widget for showing how well-commented the code is
*
* @author wbraik
*
*/
public class CommentsWidget extends AbstractView {

  /**
   * The associated Project object
   */
  protected Project project = null;

  /**
   * The current version to display the stats for
   */
  private int version;

  // View components

  private final HorizontalPanel titlePanel = new HorizontalPanel();
  private final Label titleLabel = new Label("Commentaires");
  private final Label sourcesLabel = new Label("(d'après CLOC)");
  private final HorizontalPanel comPanel = new HorizontalPanel();
  private final Label comLabel = new Label("Commentaires :");
  private final Label comValueLabel = new Label();
  private final Label diffComLabel = new Label();
  private final CommentsPieChart chart;

  /**
   * Threshold to good commentary level in percent
   */
  private static final int COM_THRESHOLD = 25;

  public CommentsWidget(Project project) {

    super(new VerticalPanel());
    this.project = project;

    this.chart = new CommentsPieChart(project);

    this.titleLabel.setStyleDependentName("widgetTitle", true);
    this.sourcesLabel.setStyleDependentName("widgetSources", true);
    this.comValueLabel.setStyleDependentName("diff", true);
    this.diffComLabel.setStyleDependentName("diff", true);
    this.viewPanel.setStyleName("commentsWidget");
  }

  public void setVersion(int version) {

    this.version = version;

    this.chart.setVersion(version);
  }

  @Override
  public void buildView() {

    comValueLabel.setText("");
    diffComLabel.setText("");

    fillValueLabel();
    fillDiffLabel();
    this.chart.buildView();

    comPanel.add(comLabel);
    comPanel.add(comValueLabel);
    comPanel.add(diffComLabel);

    titlePanel.add(titleLabel);
    titlePanel.add(sourcesLabel);

    viewPanel.add(titlePanel);
    viewPanel.add(comPanel);
    viewPanel.add(this.chart.getViewPanel());
  }

  /**
   * Fill the value label
   */
  private void fillValueLabel() {

    Project p = this.project;
    int v = this.version;

    int ncom = p.getNcom(v);
    int nloc = p.getNloc(v);

    if (ncom == -1 || nloc == -1) {
      comValueLabel.setText("--");
    } else {

      Double pcom = (new Double(ncom) / new Double(nloc+ncom)) * 100.;

      comValueLabel.setText(Math.round(pcom) + "%");
      if (pcom < CommentsWidget.COM_THRESHOLD) {
        comValueLabel.setStyleDependentName("green", false);
        comValueLabel.setStyleDependentName("red", true);
      } else {
        comValueLabel.setStyleDependentName("red", false);
        comValueLabel.setStyleDependentName("green", true);
      }
    }
  }

  /**
   * Fill the label for displaying the differential with the previous version
   */
  private void fillDiffLabel() {

    Project p = this.project;
    int v = this.version;

    // If there is an anterior version
    if (v > 1) {

      if (p.getNcom(v) != -1 && p.getNcom(v - 1) != -1) {

        if (p.getNcom(v) > p.getNcom(v - 1)) {
          diffComLabel.setText("(+)");
          diffComLabel.setStyleDependentName("red", false);
          diffComLabel.setStyleDependentName("green", true);
        } else if (p.getNcom(v) < p.getNcom(v - 1)) {
          diffComLabel.setText("(-)");
          diffComLabel.setStyleDependentName("green", false);
          diffComLabel.setStyleDependentName("red", true);
        }
      }
    }
  }
}
TOP

Related Classes of com.ubx1.pdpscanner.client.views.project.CommentsWidget

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.