Example usage for java.text DateFormatSymbols getShortWeekdays

List of usage examples for java.text DateFormatSymbols getShortWeekdays

Introduction

In this page you can find the example usage for java.text DateFormatSymbols getShortWeekdays.

Prototype

public String[] getShortWeekdays() 

Source Link

Document

Gets short weekday strings.

Usage

From source file:org.shredzone.cilla.site.renderer.CalendarRenderStrategyImpl.java

/**
 * Writes the headline of the calendar table. It consists of the weekdays.
 *///w  w w . j ava 2  s  .c  o  m
protected void writeHeadline() throws IOException {
    Calendar calendar = Calendar.getInstance(generator.getLocale());
    int firstDay = calendar.getFirstDayOfWeek();

    DateFormatSymbols symbols = DateFormatSymbols.getInstance(generator.getLocale());
    String[] weekdays = symbols.getShortWeekdays();

    out.append("<tr>");
    for (int wd = firstDay; wd < firstDay + 7; wd++) {
        int weekdayIndex = (wd - 1) % 7;

        String wdname = weekdays[weekdayIndex + 1];
        if (wdname.length() > 2) {
            wdname = wdname.substring(0, 2);
        }

        out.append("<th>");
        out.append(HtmlUtils.htmlEscape(wdname));
        out.append("</th>");
    }
    out.append("</tr>");
}

From source file:com.googlecode.commons.swing.component.datetime.MiniDateCalendar.java

private void init() {
    final DateFormatSymbols dfs = new DateFormatSymbols(locale);
    CollectionUtils.addAll(this.weekdays, dfs.getShortWeekdays());

    for (int i = 0; i < 7; i++) {
        orderedWeekdays.add(((i + weekDayStart - 1) % 7) + 1);
    }//from www .j  a  va2  s .c  o  m

    setLayout(new BorderLayout());
    SizeUtils.setAllWidths(this, 150);
    SizeUtils.setAllHeights(this, 180);

    panNorth = new JPanel(new BorderLayout());
    add(panNorth, BorderLayout.NORTH);

    btnPrev = new JButton();
    SizeUtils.setAllWidths(btnPrev, 18);
    SizeUtils.setAllHeights(btnPrev, 18);
    btnPrev.setIcon(DefaultIcons.resultset_previous());
    btnPrev.setMargin(new Insets(0, 0, 0, 0));
    btnPrev.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            onClickPrev();
        }
    });
    panNorth.add(btnPrev, BorderLayout.WEST);

    lblMonth = new JLabel();
    SizeUtils.setMinHeight(lblMonth, 0);
    SizeUtils.setPreferredHeight(lblMonth, 0);
    lblMonth.setHorizontalAlignment(SwingConstants.CENTER);
    panNorth.add(lblMonth, BorderLayout.CENTER);

    btnNext = new JButton();
    btnNext.setIcon(DefaultIcons.resultset_next());
    SizeUtils.setAllWidths(btnNext, 18);
    SizeUtils.setAllHeights(btnNext, 18);
    btnNext.setMargin(new Insets(0, 0, 0, 0));
    btnNext.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            onClickNext();
        }
    });
    panNorth.add(btnNext, BorderLayout.EAST);

    panCenter = new JPanel();
    panCenter.setLayout(new GridLayout(7, 7));
    add(panCenter, BorderLayout.CENTER);

    for (int col = 0; col < 7; col++) {
        JLabel lblDay = new JLabel(weekdays.get(orderedWeekdays.get(col)));
        lblDay.setHorizontalAlignment(SwingConstants.CENTER);
        panCenter.add(lblDay);
    }

    ButtonGroup grp = new ButtonGroup();
    for (int row = 0; row < 6; row++) {
        for (int col = 0; col < 7; col++) {
            final int day = orderedWeekdays.get(col);
            final DayButton btn = createDayButton(day, weekdays.get(day));
            btn.setMargin(new Insets(0, 0, 0, 0));
            btn.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    onClickDay(btn.value);
                }
            });
            days.add(btn);
            grp.add(btn);
            panCenter.add(btn);
        }
    }
    refresh();
}

From source file:org.onebusaway.webapp.actions.where.ScheduleAction.java

public List<String> getShortWeekDays() {

    List<String> result = new ArrayList<String>();
    DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(getLocale());

    String shortWeekdays[] = dateFormatSymbols.getShortWeekdays();
    Calendar calendar = Calendar.getInstance(getLocale());
    int firstDayOfWeek = calendar.getFirstDayOfWeek();

    for (int dayOfWeek = firstDayOfWeek; dayOfWeek < shortWeekdays.length; dayOfWeek++) {
        result.add(shortWeekdays[dayOfWeek]);
    }/* w  w  w .  j  av  a2  s .co  m*/

    for (int dayOfWeek = Calendar.SUNDAY; dayOfWeek < firstDayOfWeek; dayOfWeek++) {
        result.add(shortWeekdays[dayOfWeek]);
    }

    return result;
}

From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java

private static String[] mapShortWeekdaysStartingWithSunday(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getShortWeekdays();

    weekdays[0] = localeWeekdays[Calendar.SUNDAY];
    weekdays[1] = localeWeekdays[Calendar.MONDAY];
    weekdays[2] = localeWeekdays[Calendar.TUESDAY];
    weekdays[3] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[4] = localeWeekdays[Calendar.THURSDAY];
    weekdays[5] = localeWeekdays[Calendar.FRIDAY];
    weekdays[6] = localeWeekdays[Calendar.SATURDAY];

    return weekdays;
}

From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java

private static String[] mapShortWeekdaysStartingWithSaturday(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getShortWeekdays();

    weekdays[0] = localeWeekdays[Calendar.SATURDAY];
    weekdays[1] = localeWeekdays[Calendar.SUNDAY];
    weekdays[2] = localeWeekdays[Calendar.MONDAY];
    weekdays[3] = localeWeekdays[Calendar.TUESDAY];
    weekdays[4] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[5] = localeWeekdays[Calendar.THURSDAY];
    weekdays[6] = localeWeekdays[Calendar.FRIDAY];

    return weekdays;
}

From source file:com.spacejake.jake.ultimatepurduediner.NavigationDrawerFragment.java

public void showDatePicker() {
    new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
        @Override//w  w  w.j a v  a 2 s  .  co  m
        public void onDateSet(DatePicker datePicker, int year, int month, int day) {
            if (!dateSet) {
                Calendar cal = Calendar.getInstance();
                ((MainActivity) getActivity()).dateChange(year, month, day);
                if (datePicker.getDayOfMonth() == cal.get(Calendar.DAY_OF_MONTH)
                        && datePicker.getYear() == cal.get(Calendar.YEAR)) {
                    datePickerButton.setTitle("Today");
                } else {
                    DateFormatSymbols dfs = new DateFormatSymbols(new Locale("en"));
                    cal.set(year, month, day);
                    datePickerButton.setTitle(String.format("%s, %d/%d/%d",
                            dfs.getShortWeekdays()[cal.get(Calendar.DAY_OF_WEEK)], month + 1, day, year));
                }
                dateSet = true;
            } else {
                dateSet = false;
            }
        }
    }, year, month, day).show();
}

From source file:DateChooserPanel.java

/**
 * Returns a panel of buttons, each button representing a day in the month.
 * This is a sub-component of the DatePanel.
 *
 * @return the panel./*from  w w w .j  av  a  2  s .  co m*/
 */
private JPanel getCalendarPanel() {

    final JPanel p = new JPanel(new GridLayout(7, 7));
    final DateFormatSymbols dateFormatSymbols = new DateFormatSymbols();
    final String[] weekDays = dateFormatSymbols.getShortWeekdays();

    for (int i = 0; i < this.WEEK_DAYS.length; i++) {
        p.add(new JLabel(weekDays[this.WEEK_DAYS[i]], SwingConstants.CENTER));
    }

    this.buttons = new JButton[42];
    for (int i = 0; i < 42; i++) {
        final JButton b = new JButton("");
        b.setMargin(new Insets(1, 1, 1, 1));
        b.setName(Integer.toString(i));
        b.setFont(this.dateFont);
        b.setFocusPainted(false);
        b.setActionCommand("dateButtonClicked");
        b.addActionListener(this);
        this.buttons[i] = b;
        p.add(b);
    }
    return p;

}

From source file:com.icesoft.faces.component.selectinputdate.SelectInputDateRenderer.java

private static String[] mapWeekdays(DateFormatSymbols symbols) {
    String[] weekdays = new String[7];

    String[] localeWeekdays = symbols.getShortWeekdays();

    weekdays[0] = localeWeekdays[Calendar.MONDAY];
    weekdays[1] = localeWeekdays[Calendar.TUESDAY];
    weekdays[2] = localeWeekdays[Calendar.WEDNESDAY];
    weekdays[3] = localeWeekdays[Calendar.THURSDAY];
    weekdays[4] = localeWeekdays[Calendar.FRIDAY];
    weekdays[5] = localeWeekdays[Calendar.SATURDAY];
    weekdays[6] = localeWeekdays[Calendar.SUNDAY];

    return weekdays;
}

From source file:org.richfaces.renderkit.CalendarRendererBase.java

protected Map<String, String[]> getSymbolsMap(FacesContext facesContext, UICalendar calendar) {
    Map<String, String[]> map = new HashMap<String, String[]>();

    Locale locale = calendar.getAsLocale(calendar.getLocale());
    Calendar cal = calendar.getCalendar();
    int maximum = cal.getActualMaximum(Calendar.DAY_OF_WEEK);
    int minimum = cal.getActualMinimum(Calendar.DAY_OF_WEEK);

    int monthMax = cal.getActualMaximum(Calendar.MONTH);
    int monthMin = cal.getActualMinimum(Calendar.MONTH);

    DateFormatSymbols symbols = new DateFormatSymbols(locale);
    String[] weekDayLabels = ComponentUtil.asArray(calendar.getWeekDayLabels());
    if (weekDayLabels == null) {
        weekDayLabels = symbols.getWeekdays();
        weekDayLabels = shiftDates(minimum, maximum, weekDayLabels);
    }//from   w  w  w. java2s  . c om

    String[] weekDayLabelsShort = ComponentUtil.asArray(calendar.getWeekDayLabelsShort());
    if (weekDayLabelsShort == null) {
        weekDayLabelsShort = symbols.getShortWeekdays();
        weekDayLabelsShort = shiftDates(minimum, maximum, weekDayLabelsShort);
    }

    String[] monthLabels = ComponentUtil.asArray(calendar.getMonthLabels());
    if (monthLabels == null) {
        monthLabels = symbols.getMonths();
        monthLabels = shiftDates(monthMin, monthMax, monthLabels);
    }

    String[] monthLabelsShort = ComponentUtil.asArray(calendar.getMonthLabelsShort());
    if (monthLabelsShort == null) {
        monthLabelsShort = symbols.getShortMonths();
        monthLabelsShort = shiftDates(monthMin, monthMax, monthLabelsShort);
    }

    map.put(WEEK_DAY_LABELS, weekDayLabels);
    map.put(WEEK_DAY_LABELS_SHORT, weekDayLabelsShort);
    map.put(MONTH_LABELS, monthLabels);
    map.put(MONTH_LABELS_SHORT, monthLabelsShort);

    return map;
}

From source file:com.todoroo.astrid.repeats.RepeatControlSet.java

@Nullable
@Override// w  ww  . j  av  a2  s .co m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    if (savedInstanceState != null) {
        recurrence = savedInstanceState.getString(EXTRA_RECURRENCE);
        repeatUntilValue = savedInstanceState.getLong(EXTRA_REPEAT_UNTIL);
        repeatAfterCompletion = savedInstanceState.getBoolean(EXTRA_REPEAT_AFTER_COMPLETION);
    }

    dialogView = inflater.inflate(R.layout.control_set_repeat, null);
    value = (Button) dialogView.findViewById(R.id.repeatValue);
    Spinner interval = (Spinner) dialogView.findViewById(R.id.repeatInterval);
    ArrayAdapter<String> intervalAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item,
            getResources().getStringArray(R.array.repeat_interval));
    intervalAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    interval.setAdapter(intervalAdapter);
    Spinner type = (Spinner) dialogView.findViewById(R.id.repeatType);
    ArrayAdapter<String> typeAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item,
            getResources().getStringArray(R.array.repeat_type));
    typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    type.setAdapter(typeAdapter);
    type.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            repeatAfterCompletion = position == TYPE_COMPLETION_DATE;
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
    daysOfWeekContainer = (LinearLayout) dialogView.findViewById(R.id.repeatDayOfWeekContainer);
    repeatUntil = (Spinner) dialogView.findViewById(R.id.repeat_until);
    repeatUntilAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, repeatUntilOptions);
    repeatUntilAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    repeatUntil.setAdapter(repeatUntilAdapter);
    // set up days of week
    DateFormatSymbols dfs = new DateFormatSymbols();
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
    CompoundButton[] daysOfWeek = new CompoundButton[7];
    for (int i = 0; i < 7; i++) {
        final int index = i;
        CheckBox checkBox = (CheckBox) daysOfWeekContainer.getChildAt(i);
        checkBox.setOnCheckedChangeListener(
                (buttonView, isChecked1) -> RepeatControlSet.this.isChecked[index] = isChecked1);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        checkBox.setText(dfs.getShortWeekdays()[dayOfWeek].substring(0, 1));
        daysOfWeek[i] = checkBox;
        weekdays[i] = Weekday.values()[dayOfWeek - 1];
        calendar.add(Calendar.DATE, 1);
    }

    // set up listeners
    value.setOnClickListener(v -> repeatValueClick());

    setRepeatValue(1);
    interval.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parentView, View view, int position, long id) {
            daysOfWeekContainer.setVisibility(position == INTERVAL_WEEKS ? View.VISIBLE : View.GONE);
            intervalValue = position;
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            //
        }
    });

    setRepeatUntilValue(repeatUntilValue);
    repeatUntil.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (repeatUntilOptions.size() == 2) {
                if (i == 0) {
                    setRepeatUntilValue(0);
                } else {
                    repeatUntilClick();
                }
            } else {
                if (i == 1) {
                    setRepeatUntilValue(0);
                } else if (i == 2) {
                    repeatUntilClick();
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            //
        }
    });

    daysOfWeekContainer.setVisibility(View.GONE);
    type.setSelection(repeatAfterCompletion ? TYPE_COMPLETION_DATE : TYPE_DUE_DATE);
    doRepeat = !Strings.isNullOrEmpty(recurrence);
    if (doRepeat) {
        // read recurrence rule
        try {
            RRule rrule = new RRule(recurrence);

            setRepeatValue(rrule.getInterval());

            for (WeekdayNum day : rrule.getByDay()) {
                for (int i = 0; i < 7; i++) {
                    if (weekdays[i].equals(day.wday)) {
                        daysOfWeek[i].setChecked(true);
                    }
                }
            }

            switch (rrule.getFreq()) {
            case DAILY:
                intervalValue = INTERVAL_DAYS;
                break;
            case WEEKLY:
                intervalValue = INTERVAL_WEEKS;
                break;
            case MONTHLY:
                intervalValue = INTERVAL_MONTHS;
                break;
            case HOURLY:
                intervalValue = INTERVAL_HOURS;
                break;
            case MINUTELY:
                intervalValue = INTERVAL_MINUTES;
                break;
            case YEARLY:
                intervalValue = INTERVAL_YEARS;
                break;
            default:
                Timber.e(new Exception("Unhandled rrule frequency: " + recurrence), "repeat-unhandled-rule");
            }
            interval.setSelection(intervalValue);

        } catch (Exception e) {
            // invalid RRULE
            recurrence = ""; //$NON-NLS-1$
            Timber.e(e, e.getMessage());
        }
    }
    refreshDisplayView();
    return view;
}