Example usage for java.text DateFormat MEDIUM

List of usage examples for java.text DateFormat MEDIUM

Introduction

In this page you can find the example usage for java.text DateFormat MEDIUM.

Prototype

int MEDIUM

To view the source code for java.text DateFormat MEDIUM.

Click Source Link

Document

Constant for medium style pattern.

Usage

From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        AxisSettings axisSettings) {/*from   ww w .j av  a  2  s  . co  m*/
    boolean axisTickLabelsVisible = axisSettings.getTickLabelsVisible() == null
            || axisSettings.getTickLabelsVisible().booleanValue();//FIXMETHEME axis visibility should be dealt with above;

    axis.setTickLabelsVisible(axisTickLabelsVisible);

    if (axisTickLabelsVisible) {
        JRBaseFont font = new JRBaseFont();
        JRFontUtil.copyNonNullOwnProperties(axisSettings.getTickLabelFont(), font);
        JRFontUtil.copyNonNullOwnProperties(tickLabelFont, font);
        font = new JRBaseFont(getChart(), font);
        axis.setTickLabelFont(JRFontUtil.getAwtFont(font, getLocale()));

        RectangleInsets tickLabelInsets = axisSettings.getTickLabelInsets();
        if (tickLabelInsets != null) {
            axis.setTickLabelInsets(tickLabelInsets);
        }

        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : axisSettings.getTickLabelPaint() != null ? axisSettings.getTickLabelPaint().getPaint() : null;

        if (tickLabelPaint != null) {
            axis.setTickLabelPaint(tickLabelPaint);
        }

        TimeZone timeZone = getChartContext().getTimeZone();
        if (axis instanceof DateAxis && timeZone != null) {
            // used when no mask is set
            ((DateAxis) axis).setTimeZone(timeZone);
        }

        if (tickLabelMask != null) {
            if (axis instanceof NumberAxis) {
                NumberFormat fmt = NumberFormat.getInstance();
                if (fmt instanceof DecimalFormat)
                    ((DecimalFormat) fmt).applyPattern(tickLabelMask);
                ((NumberAxis) axis).setNumberFormatOverride(fmt);
            } else if (axis instanceof DateAxis) {
                DateFormat fmt;
                if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT"))
                    fmt = DateFormat.getDateInstance(DateFormat.SHORT);
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM);
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG);
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL);
                else
                    fmt = new SimpleDateFormat(tickLabelMask);

                // FIXME fmt cannot be null
                if (fmt != null) {
                    if (timeZone != null) {
                        fmt.setTimeZone(timeZone);
                    }

                    ((DateAxis) axis).setDateFormatOverride(fmt);
                } else
                    ((DateAxis) axis).setDateFormatOverride(
                            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT));
            }
            // ignore mask for other axis types.
        }
    }
}

From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        Integer baseFontSize) {//from  w w  w  .  j ava2 s  .  c om
    Boolean defaultAxisTickLabelsVisible = (Boolean) getDefaultValue(defaultAxisPropertiesMap,
            ChartThemesConstants.AXIS_TICK_LABELS_VISIBLE);
    if (defaultAxisTickLabelsVisible != null && defaultAxisTickLabelsVisible.booleanValue()) {
        Font themeTickLabelFont = getFont(
                (JRFont) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_FONT),
                tickLabelFont, baseFontSize);
        axis.setTickLabelFont(themeTickLabelFont);

        RectangleInsets defaultTickLabelInsets = (RectangleInsets) getDefaultValue(defaultAxisPropertiesMap,
                ChartThemesConstants.AXIS_TICK_LABEL_INSETS);
        if (defaultTickLabelInsets != null) {
            axis.setTickLabelInsets(defaultTickLabelInsets);
        }
        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : (Paint) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_PAINT);
        if (tickLabelPaint != null) {
            axis.setTickLabelPaint(tickLabelPaint);
        }

        TimeZone timeZone = getChartContext().getTimeZone();
        if (axis instanceof DateAxis && timeZone != null) {
            // used when no mask is set
            ((DateAxis) axis).setTimeZone(timeZone);
        }

        if (tickLabelMask != null) {
            if (axis instanceof NumberAxis) {
                NumberFormat fmt = NumberFormat.getInstance();
                if (fmt instanceof DecimalFormat)
                    ((DecimalFormat) fmt).applyPattern(tickLabelMask);
                ((NumberAxis) axis).setNumberFormatOverride(fmt);
            } else if (axis instanceof DateAxis) {
                DateFormat fmt;
                if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT"))
                    fmt = DateFormat.getDateInstance(DateFormat.SHORT);
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM);
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG);
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL);
                else
                    fmt = new SimpleDateFormat(tickLabelMask);

                // FIXME fmt cannot be null
                if (fmt != null) {
                    if (timeZone != null) {
                        fmt.setTimeZone(timeZone);
                    }

                    ((DateAxis) axis).setDateFormatOverride(fmt);
                } else
                    ((DateAxis) axis).setDateFormatOverride(
                            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT));
            }
            // ignore mask for other axis types.
        }
    }
}

From source file:org.eclipse.ecr.core.api.AbstractSession.java

protected String oldLockKey(Lock lock) {
    if (lock == null) {
        return null;
    }//  w w w .j  a  v a  2s  .c  o m
    // return deprecated format, like "someuser:Nov 29, 2010"
    return lock.getOwner() + ':' + DateFormat.getDateInstance(DateFormat.MEDIUM)
            .format(new Date(lock.getCreated().getTimeInMillis()));
}

From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        AxisSettings axisSettings) {/* w  w w.j ava  2 s .  c  o  m*/
    boolean axisTickLabelsVisible = axisSettings.getTickLabelsVisible() == null
            || axisSettings.getTickLabelsVisible();//FIXMETHEME axis visibility should be dealt with above;

    axis.setTickLabelsVisible(axisTickLabelsVisible);

    if (axisTickLabelsVisible) {
        JRBaseFont font = new JRBaseFont();
        FontUtil.copyNonNullOwnProperties(axisSettings.getTickLabelFont(), font);
        FontUtil.copyNonNullOwnProperties(tickLabelFont, font);
        font = new JRBaseFont(getChart(), font);
        axis.setTickLabelFont(getFontUtil().getAwtFont(font, getLocale()));

        RectangleInsets tickLabelInsets = axisSettings.getTickLabelInsets();
        if (tickLabelInsets != null) {
            axis.setTickLabelInsets(tickLabelInsets);
        }

        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : axisSettings.getTickLabelPaint() != null ? axisSettings.getTickLabelPaint().getPaint() : null;

        if (tickLabelPaint != null) {
            axis.setTickLabelPaint(tickLabelPaint);
        }

        TimeZone timeZone = getChartContext().getTimeZone();
        if (axis instanceof DateAxis && timeZone != null) {
            // used when no mask is set
            ((DateAxis) axis).setTimeZone(timeZone);
        }

        if (tickLabelMask != null) {
            if (axis instanceof NumberAxis) {
                NumberFormat fmt = NumberFormat.getInstance(getLocale());
                if (fmt instanceof DecimalFormat)
                    ((DecimalFormat) fmt).applyPattern(tickLabelMask);
                ((NumberAxis) axis).setNumberFormatOverride(fmt);
            } else if (axis instanceof DateAxis) {
                DateFormat fmt;
                if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT"))
                    fmt = DateFormat.getDateInstance(DateFormat.SHORT, getLocale());
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG, getLocale());
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL, getLocale());
                else
                    fmt = new SimpleDateFormat(tickLabelMask, getLocale());

                // FIXME fmt cannot be null
                if (fmt != null) {
                    if (timeZone != null) {
                        fmt.setTimeZone(timeZone);
                    }

                    ((DateAxis) axis).setDateFormatOverride(fmt);
                } else
                    ((DateAxis) axis).setDateFormatOverride(
                            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()));
            }
            // ignore mask for other axis types.
        }
    }
}

From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java

protected void setAxisTickLabels(Axis axis, JRFont tickLabelFont, Paint tickLabelColor, String tickLabelMask,
        Integer baseFontSize) {//w w  w .  j a  va 2 s  .co  m
    Boolean defaultAxisTickLabelsVisible = (Boolean) getDefaultValue(defaultAxisPropertiesMap,
            ChartThemesConstants.AXIS_TICK_LABELS_VISIBLE);
    if (defaultAxisTickLabelsVisible != null && defaultAxisTickLabelsVisible) {
        Font themeTickLabelFont = getFont(
                (JRFont) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_FONT),
                tickLabelFont, baseFontSize);
        axis.setTickLabelFont(themeTickLabelFont);

        RectangleInsets defaultTickLabelInsets = (RectangleInsets) getDefaultValue(defaultAxisPropertiesMap,
                ChartThemesConstants.AXIS_TICK_LABEL_INSETS);
        if (defaultTickLabelInsets != null) {
            axis.setTickLabelInsets(defaultTickLabelInsets);
        }
        Paint tickLabelPaint = tickLabelColor != null ? tickLabelColor
                : (Paint) getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_TICK_LABEL_PAINT);
        if (tickLabelPaint != null) {
            axis.setTickLabelPaint(tickLabelPaint);
        }

        TimeZone timeZone = getChartContext().getTimeZone();
        if (axis instanceof DateAxis && timeZone != null) {
            // used when no mask is set
            ((DateAxis) axis).setTimeZone(timeZone);
        }

        if (tickLabelMask != null) {
            if (axis instanceof NumberAxis) {
                NumberFormat fmt = NumberFormat.getInstance(getLocale());
                if (fmt instanceof DecimalFormat)
                    ((DecimalFormat) fmt).applyPattern(tickLabelMask);
                ((NumberAxis) axis).setNumberFormatOverride(fmt);
            } else if (axis instanceof DateAxis) {
                DateFormat fmt;
                if (tickLabelMask.equals("SHORT") || tickLabelMask.equals("DateFormat.SHORT"))
                    fmt = DateFormat.getDateInstance(DateFormat.SHORT, getLocale());
                else if (tickLabelMask.equals("MEDIUM") || tickLabelMask.equals("DateFormat.MEDIUM"))
                    fmt = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
                else if (tickLabelMask.equals("LONG") || tickLabelMask.equals("DateFormat.LONG"))
                    fmt = DateFormat.getDateInstance(DateFormat.LONG, getLocale());
                else if (tickLabelMask.equals("FULL") || tickLabelMask.equals("DateFormat.FULL"))
                    fmt = DateFormat.getDateInstance(DateFormat.FULL, getLocale());
                else
                    fmt = new SimpleDateFormat(tickLabelMask, getLocale());

                // FIXME fmt cannot be null
                if (fmt != null) {
                    if (timeZone != null) {
                        fmt.setTimeZone(timeZone);
                    }

                    ((DateAxis) axis).setDateFormatOverride(fmt);
                } else
                    ((DateAxis) axis).setDateFormatOverride(
                            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()));
            }
            // ignore mask for other axis types.
        }
    }
}

From source file:de.innovationgate.wga.server.api.WGA.java

/**
 * Returns an OpenWGA date format/*from w  w w .j  a va  2s.c  om*/
 * @param pattern The date format pattern
 * @param locale A locale to use for locale-dependent date parts. Specify null to let the current WebTML context choose the locale.
 * @throws WGException
 */
public DateFormat getDateFormat(String pattern, Locale locale) throws WGException {

    // Select language for language dependent date formats
    if (locale == null) {
        locale = chooseLocale(locale);
    }

    // Language Fallback(s)

    if (WGUtils.isEmpty(pattern)) {
        return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale);
    }

    // For default patterns
    String lcPattern = pattern.toLowerCase();
    if (lcPattern.endsWith("date") || lcPattern.endsWith("time")) {
        int patternLength;
        if (lcPattern.startsWith("short")) {
            patternLength = DateFormat.SHORT;
        } else if (lcPattern.startsWith("medium")) {
            patternLength = DateFormat.MEDIUM;
        } else if (lcPattern.startsWith("long")) {
            patternLength = DateFormat.LONG;
        } else {
            patternLength = DateFormat.FULL;
        }

        if (lcPattern.endsWith("datetime")) {
            return new TextualDateFormat(locale,
                    DateFormat.getDateTimeInstance(patternLength, patternLength, locale));
        } else if (lcPattern.endsWith("time")) {
            return new TextualDateFormat(locale, DateFormat.getTimeInstance(patternLength, locale));
        } else {
            return new TextualDateFormat(locale, DateFormat.getDateInstance(patternLength, locale));
        }

    } else if (lcPattern.equals("iso8601")) {
        return new ISO8601DateFormat();
    }

    // For custom patterns
    SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, locale);
    dateFormat.setLenient(false);
    return new TextualDateFormat(locale, dateFormat);

}

From source file:org.hoteia.qalingo.core.web.mvc.factory.ViewBeanFactory.java

/**
 * //from w  ww . jav a 2s  . c om
 */
public ProductMarketingCustomerCommentViewBean buildViewBeanProductMarketingCustomerComment(
        final RequestData requestData, final ProductMarketing productMarketing,
        final ProductMarketingCustomerComment customerComment) throws Exception {
    final Localization localization = requestData.getMarketAreaLocalization();
    final String localizationCode = localization.getCode();

    final ProductMarketingCustomerCommentViewBean customerCommentViewBean = new ProductMarketingCustomerCommentViewBean();
    customerCommentViewBean.setTitle(customerComment.getTitle());
    customerCommentViewBean.setComment(customerComment.getComment());

    if (customerComment.getCustomer() != null) {
        customerCommentViewBean.setCustomerDisplayName(customerComment.getCustomer().getScreenName());
        customerCommentViewBean.setCustomerUrl(
                urlService.buildCustomerDetailsUrl(requestData, customerComment.getCustomer().getPermalink()));
        customerCommentViewBean.setCustomerAvatarImg(
                requestUtil.getCustomerAvatar(requestData.getRequest(), customerComment.getCustomer()));
    }

    customerCommentViewBean.setComment(customerComment.getComment());

    if (customerComment.getDateCreate() != null) {
        customerCommentViewBean
                .setDateCreate(buildCommonFormatDate(requestData, customerComment.getDateCreate()));
    }
    if (customerComment.getDateUpdate() != null) {
        customerCommentViewBean
                .setDateUpdate(buildCommonFormatDate(requestData, customerComment.getDateUpdate()));
    }

    ReviewDataVocabularyPojo reviewDataVocabulary = new ReviewDataVocabularyPojo();
    reviewDataVocabulary.setItemreviewed(productMarketing.getI18nName(localizationCode));
    if (customerComment.getCustomer() != null) {
        reviewDataVocabulary.setReviewer(customerComment.getCustomer().getScreenName());
    }
    //        DateFormat dateFormatDataVocabulary = requestUtil.getDataVocabularyFormatDate(requestData);
    DateFormat dateFormat = requestUtil.getCommonFormatDate(requestData, DateFormat.MEDIUM, DateFormat.MEDIUM);
    reviewDataVocabulary.setDtreviewed(dateFormat.format(customerComment.getDateCreate()));
    // reviewDataVocabulary.setSummary(summary);
    reviewDataVocabulary.setDescription(customerComment.getComment());
    // reviewDataVocabulary.setRating(rating);

    customerCommentViewBean.setReviewDataVocabulary(reviewDataVocabulary);

    return customerCommentViewBean;
}

From source file:org.sakaiproject.lessonbuildertool.tool.beans.SimplePageBean.java

public String addAssignment() {
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT,
            new ResourceLoader().getLocale());
    df.setTimeZone(TimeService.getLocalTimeZone());
    if (!itemOk(itemId))
        return "permission-failed";
    if (!canEditPage())
        return "permission-failed";
    if (!checkCsrf())
        return "permission-failed";

    if (selectedAssignment == null) {
        return "failure";
    } else {/*from w ww. j  a va2s .  c  om*/
        try {
            LessonEntity selectedObject = assignmentEntity.getEntity(selectedAssignment);
            if (selectedObject == null)
                return "failure";

            SimplePageItem i;
            // editing existing item?
            if (itemId != null && itemId != -1) {
                i = findItem(itemId);

                // if no change, don't worry
                LessonEntity existing = assignmentEntity.getEntity(i.getSakaiId());
                String ref = null;
                if (existing != null)
                    ref = existing.getReference();
                // if same quiz, nothing to do
                if ((existing == null) || !ref.equals(selectedAssignment)) {
                    // if access controlled, clear restriction from old assignment and add to new
                    if (i.isPrerequisite()) {
                        if (existing != null) {
                            i.setPrerequisite(false);
                            checkControlGroup(i, false);
                        }
                        // sakaiid and name are used in setting control
                        i.setSakaiId(selectedAssignment);
                        i.setName(selectedObject.getTitle());
                        i.setPrerequisite(true);
                        checkControlGroup(i, true);
                    } else {
                        i.setSakaiId(selectedAssignment);
                        i.setName(selectedObject.getTitle());
                    }
                    // reset assignment-specific stuff
                    // Because we don't update the due date when it changes, this raises more
                    // problems than it fixes. It's also done only for assignments and not tests
                    //   if (selectedObject.getDueDate() != null)
                    //    i.setDescription("(" + messageLocator.getMessage("simplepage.due") + " " + df.format(selectedObject.getDueDate()) + ")");
                    //  else
                    // i.setDescription(null);

                    update(i);
                }
            } else {
                // no, add new item
                i = appendItem(selectedAssignment, selectedObject.getTitle(), SimplePageItem.ASSIGNMENT);
                //if (selectedObject.getDueDate() != null)
                //  i.setDescription("(" + messageLocator.getMessage("simplepage.due") + " " + df.format(selectedObject.getDueDate()) + ")");
                //else
                i.setDescription(null);
                update(i);
            }
            return "success";
        } catch (Exception ex) {
            ex.printStackTrace();
            return "failure";
        } finally {
            selectedAssignment = null;
        }
    }
}

From source file:com.miz.functions.MizLib.java

public static String getPrettyDate(Context context, long millis) {
    if (millis > 0) {
        try {//  w  w  w .j a  v  a2s .com
            Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis(millis);

            return DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(cal.getTime());
        } catch (Exception e) { // Fall back if something goes wrong
            return String.valueOf(millis);
        }
    } else {
        return context.getString(R.string.stringNA);
    }
}