/**
  * a value has changed in one of the text fields, try to update the model and display the error
  * message if it fails
  */
 @Override
 public void actionPerformed(ActionEvent e) {
   try {
     model.modifyShape(
         currentSelection,
         Double.parseDouble(view.xTextField.getText()),
         Double.parseDouble(view.yTextField.getText()),
         Double.parseDouble(view.widthTextField.getText()),
         Double.parseDouble(view.heightTextField.getText()));
   } catch (NumberFormatException nfe) {
     view.showError("Please provide valid number for shape properties");
   } catch (IllegalArgumentException iae) {
     view.showError(iae.getMessage());
   }
 }
 /** a selection has changed in the list, update the view */
 @Override
 public void valueChanged(ListSelectionEvent e) {
   if (e.getValueIsAdjusting() == false) {
     currentSelection = view.list.getSelectedValue();
     view.updateSelected(currentSelection);
   }
 }
示例#3
0
  @Override
  protected void initPosition() {
    super.initPosition();
    screen_height = getMeasuredHeight();
    screen_width = getMeasuredWidth();
    int count = dataList.size();

    double sum = 0;
    double withdrawal = 0;
    double min = Integer.MAX_VALUE;
    double max = -Integer.MAX_VALUE;
    for (int i = 0; i < count; i++) {
      withdrawal = dataList.get(i).getWithdrawals();
      sum += withdrawal;
      if (withdrawal > max) {
        max = withdrawal;
      }
      if (withdrawal < min) {
        min = withdrawal;
      }
    }
    averageWithdrawal = (int) sum / count;

    averageText =
        "Average Expenditure on Card: " + Utils.generateFormatMoney(dollar, averageWithdrawal);

    xPaintScale = (int) (screen_height * x_paint_scale);
    yPaintScale = (int) (screen_height * y_paint_scale);

    detailText1Size = (int) (detail_text_1_size * screen_height);
    detailText2Size = (int) (detail_text_2_size * screen_height);
    titleSecondSize = (int) (title_second_size * screen_height);
    titleSecondY = titleLineY + (int) (titleSecondSize * 1.2F);

    yAxisStartYPosition = titleSecondY + padding;
    yAxisEndYPosition = screen_height - padding - 2 * yPaintScale;

    initYValues(max, min);

    yAxisXPosition = getMaxYValueLen() + padding;

    xAxisStartXPosition = yAxisXPosition;
    xAxisEndXPosition = screen_width - padding;

    xCellLength = (int) ((float) (xAxisEndXPosition - xAxisStartXPosition) / (count + 1));

    detailRoundR = (int) (detail_round_r * screen_height);

    generateBarList();
  }
示例#4
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    drawChart(canvas);
    drawAxis(canvas);

    if (touchedBarIndex != INVALID_BAR_INDEX) {
      Bar bar = barList.get(touchedBarIndex);
      mPaint.setColor(Color.BLUE);
      bar.drawSelf(canvas, mPaint);
      textPaint.setTextSize(detailText1Size);
      float text1Length = textPaint.measureText(bar.yValue) + detailText1Size;
      textPaint.setTextSize(detailText2Size);
      float text2Length = textPaint.measureText(bar.xValue) + detailText2Size;
      int detailWidth = (int) (Math.max(text1Length, text2Length) * 1.5f);
      int detailHeight = (int) (1.2f * (detailText1Size + detailText2Size));
      float start_x = (bar.middle - 0.5f * detailWidth);
      float end_x = start_x + detailWidth;
      float start_y = 0;
      float end_y = 0;
      if (bar.withdrawal >= 0) {
        start_y = bar.top - detailHeight;
        end_y = bar.top;
      } else {
        start_y = bar.bottom;
        end_y = bar.bottom + detailHeight;
      }

      detailedRect.set(start_x, start_y, end_x, end_y);
      mPaint.setColor(HALF_TRANSPARENT_BLUE);
      canvas.drawRoundRect(detailedRect, detailRoundR, detailRoundR, mPaint);

      textPaint.setColor(Color.WHITE);
      textPaint.setTextAlign(Paint.Align.CENTER);
      textPaint.setTextSize(detailText1Size);
      float text1Y = start_y + 1f * detailText1Size;
      canvas.drawText(bar.yValue, bar.middle, text1Y, textPaint);

      textPaint.setTextSize(detailText2Size);
      float text2Y = end_y - 0.5f * detailText2Size;
      canvas.drawText(bar.xValue, bar.middle, text2Y, textPaint);
    }
  }