@Test
 public void formatBytes() {
   final PFUserDO user = new PFUserDO();
   user.setLocale(Locale.UK);
   PFUserContext.setUser(user);
   assertEquals("0 bytes", NumberHelper.formatBytes(0));
   assertEquals("1023 bytes", NumberHelper.formatBytes(1023));
   assertEquals("1 kb", NumberHelper.formatBytes(1024));
   assertEquals("1 kb", NumberHelper.formatBytes(1075));
   assertEquals("1.1 kb", NumberHelper.formatBytes(1076));
   assertEquals("99.9 kb", NumberHelper.formatBytes(102297));
   assertEquals("1,023 kb", NumberHelper.formatBytes(1047552));
   assertEquals("1 Mb", NumberHelper.formatBytes(1048576));
   assertEquals("1 Gb", NumberHelper.formatBytes(1073741824));
 }
 /**
  * @param parentPage
  * @param data
  */
 public SkillRatingEditForm(final SkillRatingEditPage parentPage, final SkillRatingDO data) {
   super(parentPage, data);
   data.setUser(PFUserContext.getUser());
 }
  /**
   * @param forecast
   * @param settings (next days)
   * @return
   */
  public JFreeChart createXYPlot(
      final LiquidityForecast forecast, final LiquidityForecastSettings settings) {
    Validate.isTrue(settings.getNextDays() > 0 && settings.getNextDays() < 500);

    final LiquidityForecastCashFlow cashFlow =
        new LiquidityForecastCashFlow(forecast, settings.getNextDays());

    final TimeSeries accumulatedSeries =
        new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.dueDate"));
    final TimeSeries accumulatedSeriesExpected =
        new TimeSeries(
            PFUserContext.getLocalizedString("plugins.liquidityplanning.forecast.expected"));
    final TimeSeries worstCaseSeries =
        new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.worstCase"));
    double accumulatedExpected = settings.getStartAmount().doubleValue();
    double accumulated = accumulatedExpected;
    double worstCase = accumulated;

    final DayHolder dh = new DayHolder();
    final Date lower = dh.getDate();
    for (int i = 0; i < settings.getNextDays(); i++) {
      if (log.isDebugEnabled() == true) {
        log.debug(
            "day: "
                + i
                + ", credits="
                + cashFlow.getCredits()[i]
                + ", debits="
                + cashFlow.getDebits()[i]);
      }
      final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear());
      if (i > 0) {
        accumulated +=
            cashFlow.getDebits()[i - 1].doubleValue() + cashFlow.getCredits()[i - 1].doubleValue();
        accumulatedExpected +=
            cashFlow.getDebitsExpected()[i - 1].doubleValue()
                + cashFlow.getCreditsExpected()[i - 1].doubleValue();
        worstCase += cashFlow.getCredits()[i - 1].doubleValue();
      }
      accumulatedSeries.add(day, accumulated);
      accumulatedSeriesExpected.add(day, accumulatedExpected);
      worstCaseSeries.add(day, worstCase);
      dh.add(Calendar.DATE, 1);
    }
    dh.add(Calendar.DATE, -1);
    final XYChartBuilder cb = new XYChartBuilder(null, null, null, null, true);

    int counter = 0;

    final TimeSeriesCollection xyDataSeries = new TimeSeriesCollection();
    xyDataSeries.addSeries(accumulatedSeries);
    xyDataSeries.addSeries(worstCaseSeries);
    final XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
    lineRenderer.setSeriesPaint(0, Color.BLACK);
    lineRenderer.setSeriesVisibleInLegend(0, true);
    lineRenderer.setSeriesPaint(1, cb.getGrayMarker());
    lineRenderer.setSeriesStroke(1, cb.getDashedStroke());
    lineRenderer.setSeriesVisibleInLegend(1, true);
    cb.setRenderer(counter, lineRenderer).setDataset(counter++, xyDataSeries);

    final TimeSeriesCollection accumulatedSet = new TimeSeriesCollection();
    accumulatedSet.addSeries(accumulatedSeriesExpected);
    final XYDifferenceRenderer diffRenderer =
        new XYDifferenceRenderer(cb.getGreenFill(), cb.getRedFill(), true);
    diffRenderer.setSeriesPaint(0, cb.getRedMarker());
    cb.setRenderer(counter, diffRenderer)
        .setDataset(counter++, accumulatedSet)
        .setStrongStyle(diffRenderer, false, accumulatedSeriesExpected);
    diffRenderer.setSeriesVisibleInLegend(0, true);

    cb.setDateXAxis(true).setDateXAxisRange(lower, dh.getDate()).setYAxis(true, null);
    return cb.getChart();
  }
예제 #4
0
  @Override
  @SuppressWarnings("serial")
  protected void init() {
    super.init();
    gridBuilder.newSplitPanel(GridSize.COL50);
    gridBuilder.newFormHeading(getString("system.admin.group.title.alertMessage"));
    {
      final FieldsetPanel fs =
          gridBuilder.newFieldset(getString("system.admin.group.title.alertMessage"));
      alertMessage = WicketApplication.getAlertMessage();

      fs.add(
              new MaxLengthTextArea(
                  TextAreaPanel.WICKET_ID, new PropertyModel<String>(this, "alertMessage"), 1000))
          .setAutogrow();
    }
    {
      final FieldsetPanel fs = gridBuilder.newFieldset("").suppressLabelForWarning();
      fs.add(
          new MyButtonPanel(fs.newChildId(), "setAlertMessage") {
            @Override
            public void onSubmit() {
              parentPage.setAlertMessage();
            }
          }.getButtonPanel());
      fs.add(
          new MyButtonPanel(fs.newChildId(), "clearAlertMessage") {
            @Override
            public void onSubmit() {
              parentPage.clearAlertMessage();
            }

            /** @see org.projectforge.web.admin.AdminForm.MyButtonPanel#isVisible() */
            @Override
            public boolean isVisible() {
              return StringUtils.isNotBlank(alertMessage);
            }
          }.getButtonPanel());
    }
    {
      final FieldsetPanel fs =
          gridBuilder
              .newFieldset(getString("system.admin.alertMessage.copyAndPaste.title"))
              .suppressLabelForWarning();
      fs.add(
          new DivTextPanel(
              fs.newChildId(),
              PFUserContext.getLocalizedMessage(
                  "system.admin.alertMessage.copyAndPaste.text", AppVersion.NUMBER)));
    }

    gridBuilder.newSplitPanel(GridSize.COL50);
    {
      final FieldsetPanel fs =
          gridBuilder.newFieldset(
              getString("system.admin.reindex.newestEntries"),
              getString("system.admin.reindex.newestEntries.subtitle"));
      fs.add(
          new MinMaxNumberField<Integer>(
              InputPanel.WICKET_ID,
              new PropertyModel<Integer>(this, "reindexNewestNEntries"),
              0,
              Integer.MAX_VALUE));
      fs.addHelpIcon(getString("system.admin.reindex.newestEntries.tooltip"));
    }
    {
      final FieldsetPanel fs = gridBuilder.newFieldset(getString("system.admin.reindex.fromDate"));
      final DatePanel datePanel =
          new DatePanel(fs.newChildId(), new PropertyModel<Date>(this, "reindexFromDate"));
      fs.add(datePanel);
      fs.addHelpIcon(
          new Model<String>() {
            @Override
            public String getObject() {
              return getString("system.admin.reindex.fromDate.tooltip")
                  + (reindexFromDate != null
                      ? " (" + DateHelper.formatAsUTC(reindexFromDate) + ")"
                      : "");
            }
          });
      fs.add(
          new MyButtonPanel(fs.newChildId(), "reindex") {
            @Override
            public void onSubmit() {
              parentPage.reindex();
            }
          }.getButtonPanel());
    }

    gridBuilder.newGridPanel();
    {
      final FieldsetPanel fs =
          gridBuilder.newFieldset(getString("system.admin.group.title.misc.logEntries"));
      final MaxLengthTextArea logEntries =
          new MaxLengthTextArea(
              TextAreaPanel.WICKET_ID, new PropertyModel<String>(this, "logEntries"), 10000);
      logEntries.add(AttributeModifier.append("style", "width: 100%; height: 20em;"));
      fs.add(logEntries);
      fs.addHelpIcon(getString("system.admin.button.formatLogEntries.textarea.tooltip"));
    }
    {
      final FieldsetPanel fs = gridBuilder.newFieldset("").suppressLabelForWarning();
      fs.add(
          new MyButtonPanel(fs.newChildId(), "formatLogEntries") {
            @Override
            public void onSubmit() {
              parentPage.formatLogEntries();
            }
          }.getButtonPanel());
    }
    gridBuilder.newGridPanel();
    final DivPanel section = gridBuilder.getPanel();
    final DivTextPanel logMessages =
        new DivTextPanel(
            section.newChildId(),
            new Model<String>() {
              @Override
              public String getObject() {
                return formattedLogEntries;
              }
            });
    logMessages.getLabel().setEscapeModelStrings(false);
    section.add(logMessages);
  }
예제 #5
0
 private static int getFirstDayOfWeek() {
   return PFUserContext.getCalendarFirstDayOfWeek();
 }