Below are some java code snippets which displays various features of the Java Calendar package.
CalendarComboBox calendarComboBox = new CalendarComboBox();
CalendarComponent calendarComponent = calendarComboBox.getCalendarComponent();
calendarComponent.setCalendarProperty(CalendarComponent.FIRST_DAY_OF_WEEK, new Integer(java.util.Calendar.MONDAY));
calendarComponent.getCalendarSkin().applyCalendarSkinStyle(new CalendarSkinStyleAqua());
calendarComponent.setCalendarRendererProvider(new CalendarRendererProviderRoundRect());
JFrame frame = new JFrame("Calendar Test");
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(new JLabel("Enter a date:"));
panel.add(calendarComboBox);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
CalendarComponent calendarComponent = new CalendarComponent();
JFrame frame = new JFrame("Calendar Test");
frame.getContentPane().add(calendarComponent);
frame.pack();
frame.setVisible(true);
CalendarDialog calendarDialog = new CalendarDialog(null);
CalendarComponent calendarComponent = calendarDialog.getCalendarComponent();
calendarComponent.setCalendarProperty(CalendarComponent.FIRST_DAY_OF_WEEK, new Integer(java.util.Calendar.MONDAY));
calendarComponent.getCalendarSkin().applyCalendarSkinStyle(new CalendarSkinStyleAqua());
calendarComponent.setCalendarRendererProvider(new CalendarRendererProviderRoundRect());
calendarDialog.getDialog().setTitle("Choose the date of the event");
calendarDialog.getDialog().pack();
calendarDialog.setVisible(true);
Date date = calendarDialog.getDate();
class CustomTable extends JTable {
public CalendarTableCellEditor calendarTableCellEditor = new CalendarTableCellEditor();
public CustomTable() {
this.setModel(new CustomTableModel());
this.setRowHeight(20);
TableColumnModel tableColumnModel = this.getColumnModel();
tableColumnModel.getColumn(0).setMinWidth(100);
tableColumnModel.getColumn(1).setMinWidth(200);
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd");
this.setDefaultEditor(Date.class, calendarTableCellEditor);
this.setDefaultRenderer(Date.class, new DefaultTableCellRenderer() {
protected void setValue(Object value) {
if (value == null) {
setText("null");
} else {
setText(simpleDateFormat.format((Date) value));
}
}
});
}
public void updateUI() {
super.updateUI();
if (calendarTableCellEditor != null) {
calendarTableCellEditor.updateUI();
}
}
}
class CustomTableModel extends AbstractTableModel {
Vector data = new Vector();
public CustomTableModel() {
GregorianCalendar calendar = new GregorianCalendar();
calendar.set(2005, Calendar.JANUARY, 12);
data.add(new TableLine("First Event", calendar.getTime()));
calendar.set(1989, Calendar.DECEMBER, 22);
data.add(new TableLine("Second Event", calendar.getTime()));
calendar.set(1995, Calendar.MARCH, 23);
data.add(new TableLine("Third Event", calendar.getTime()));
}
public int getColumnCount() {
return 2;
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return true;
}
public int getRowCount() {
return data.size();
}
public String getColumnName(int column) {
if (column == 0) {
return "Event Name";
} else {
return "Date";
}
}
public Class getColumnClass(int columnIndex) {
if (columnIndex == 0) {
return String.class;
} else {
return Date.class;
}
}
public Object getValueAt(int rowIndex, int columnIndex) {
Object value = null;
TableLine tableLine = (TableLine)data.elementAt(rowIndex);
if (columnIndex == 0) {
value = tableLine.eventName;
} else if (columnIndex == 1) {
value = tableLine.date;
}
return value;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
TableLine tableLine = (TableLine)data.elementAt(rowIndex);
if (columnIndex == 0) {
tableLine.eventName = (String)value;
} else if (columnIndex == 1) {
tableLine.date = (Date)value;
}
}
}
class TableLine {
String eventName;
Date date;
public TableLine(String eventName, Date date) {
this.eventName = eventName;
this.date = date;
}
}
CustomTable customTable = new CustomTable();
JFrame frame = new JFrame("Calendar Table Cell Editor");
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(customTable);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
CalendarComponent calendarComponent = new CalendarComponent(); calendarComponent.getCalendarSkin().setSkinProperty(CalendarSkin.CELL_TEXT_COLOR, new Color(18, 230, 100));
CalendarComponent calendarComponent = new CalendarComponent(); calendarComponent.getCalendarSkin().applyCalendarSkinStyle(new CalendarSkinStyleAqua());
class CalendarSkinStyleCustom extends CalendarSkinStyle {
public void applyStyle(CalendarSkin calendarSkin) throws CalendarPropertyException {
calendarSkin.setSkinProperty(CalendarSkin.CELL_TEXT_COLOR, new Color(101, 101, 31));
calendarSkin.setSkinProperty(CalendarSkin.CELL_FILL_COLOR, new Color(189, 209, 173));
calendarSkin.setSkinProperty(CalendarSkin.EXTRA_MONTH_CELL_TEXT_COLOR, new Color(128, 128, 128));
calendarSkin.setSkinProperty(CalendarSkin.WEEKEND_CELL_TEXT_COLOR, new Color(54, 54, 16));
calendarSkin.setSkinProperty(CalendarSkin.TODAY_COLOR, new Color(255, 0, 0));
calendarSkin.setSkinProperty(CalendarSkin.DISABLED_COLOR, new Color(255, 0, 0));
calendarSkin.setSkinProperty(CalendarSkin.GRID_COLOR, new Color(134, 151, 130));
calendarSkin.setSkinProperty(CalendarSkin.SELECTED_CELL_FILL_COLOR, new Color(82, 107, 61));
calendarSkin.setSkinProperty(CalendarSkin.SELECTED_CELL_TEXT_COLOR, new Color(255, 255, 255));
calendarSkin.setSkinProperty(CalendarSkin.HOVERED_CELL_FILL_COLOR, new Color(82, 107, 61));
calendarSkin.setSkinProperty(CalendarSkin.HOVERED_CELL_TEXT_COLOR, new Color(255, 255, 255));
calendarSkin.setSkinProperty(CalendarSkin.HEADER_CELL_TEXT_COLOR, new Color(212, 208, 200));
calendarSkin.setSkinProperty(CalendarSkin.HEADER_CELL_FILL_COLOR, new Color(128, 128, 128));
calendarSkin.setSkinProperty(CalendarSkin.WEEK_CELL_TEXT_COLOR, new Color(212, 208, 200));
calendarSkin.setSkinProperty(CalendarSkin.WEEK_CELL_FILL_COLOR, new Color(128, 128, 128));
calendarSkin.setSkinProperty(CalendarSkin.STATUS_PANEL_TEXT_COLOR, new Color(101, 101, 31));
calendarSkin.setSkinProperty(CalendarSkin.STATUS_PANEL_HOVERED_TEXT_COLOR, new Color(82, 107, 61));
calendarSkin.setSkinProperty(CalendarSkin.STATUS_PANEL_FILL_COLOR, new Color(189, 209, 173));
// Set the fixed font value to null in order to be obtained a dynamical font value which is based on the component font.
calendarSkin.setSkinProperty(CalendarSkin.CELL_FONT, null);
// Set the font for the specified property to be the default component font but with the specified style.
getCalendarSkinStyleAdapter().getFontWrapperProperty(CalendarSkinStyleAdapter.CELL_FONT_WRAPPER).setStyle(Font.PLAIN);
// Set the fixed font value to null in order to be obtained a dynamical font value which is based on the component font.
calendarSkin.setSkinProperty(CalendarSkin.EXTRA_MONTH_CELL_FONT, null);
// Set the font for the specified property to be the default component font but with the specified style.
getCalendarSkinStyleAdapter().getFontWrapperProperty(CalendarSkinStyleAdapter.EXTRA_MONTH_CELL_FONT_WRAPPER).setStyle(Font.ITALIC);
// Set the fixed font value to null in order to be obtained a dynamical font value which is based on the component font.
calendarSkin.setSkinProperty(CalendarSkin.WEEKEND_CELL_FONT, null);
// Set the font for the specified property to be the default component font but with the specified style.
getCalendarSkinStyleAdapter().getFontWrapperProperty(CalendarSkinStyleAdapter.WEEKEND_CELL_FONT_WRAPPER).setStyle(Font.ITALIC |Font.BOLD);
// Set the fixed font value to null in order to be obtained a dynamical font value which is based on the component font.
calendarSkin.setSkinProperty(CalendarSkin.HEADER_CELL_FONT, null);
// Set the font for the specified property to be the default component font but with the specified style.
getCalendarSkinStyleAdapter().getFontWrapperProperty(CalendarSkinStyleAdapter.HEADER_FONT_WRAPPER).setStyle(Font.PLAIN);
// Set the fixed font value to null in order to be obtained a dynamical font value which is based on the component font.
calendarSkin.setSkinProperty(CalendarSkin.WEEK_CELL_FONT, null);
// Set the font for the specified property to be the default component font but with the specified style.
getCalendarSkinStyleAdapter().getFontWrapperProperty(CalendarSkinStyleAdapter.WEEK_FONT_WRAPPER).setStyle(Font.PLAIN);
// Set the fixed font value to null in order to be obtained a dynamical font value which is based on the component font.
calendarSkin.setSkinProperty(CalendarSkin.STATUS_PANEL_FONT, null);
// Set the font for the specified property to be the default component font but with the specified style.
getCalendarSkinStyleAdapter().getFontWrapperProperty(CalendarSkinStyleAdapter.STATUS_PANEL_FONT_WRAPPER).setStyle(Font.BOLD);
calendarSkin.setSkinProperty(CalendarSkin.BACKGROUND_IMAGE, null);
}
public String getName() {
return "Custom";
}
}
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.getCalendarSkin().applyCalendarSkinStyle(new CalendarSkinStyleCustom());
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.getCalendarSkin().applyCalendarSkinStyle(new CalendarSkinStyleExternalFile(new File("./skins/skin01.skin")));
calendarComponent.getCalendarSkin().applyCalendarSkinStyle(new CalendarSkinStyleExternalURL(new URL("http://www.calendarcomponent.com/skins/skin01.skin")));
CalendarSkinStyleExternalFile.exportSkin(calendarComponent.getCalendarSkin(), new File("./skins/test.skin"));
CalendarComponent calendarComponent = new CalendarComponent(); calendarComponent.setCalendarRendererProvider(new CalendarRendererProviderRoundRect());
class CalendarTableCellRendererCustom implements CalendarTableCellRenderer {
public void paint(Graphics g, CalendarComponent calendarComponent, CalendarTableCellInfo calendarTableCellInfo) {
// If the calendar has a background renderer then this will actually paint the calendar background.
// So this table cell renderer will no longer paint the cell background in this case.
if (!calendarComponent.getCalendarRendererProvider().hasBackgroundRenderer()) {
g.setColor(calendarComponent.getCalendarSkin().getColorSkinProperty(CalendarSkin.CELL_FILL_COLOR));
g.fillRect(0, 0, calendarTableCellInfo.getWidth(), calendarTableCellInfo.getHeight());
}
g.setColor(new Color(255, 0, 0));
g.fillOval(0, 0, calendarTableCellInfo.getWidth(), calendarTableCellInfo.getHeight());
g.setColor(new Color(0, 0, 255));
drawCenteredString(g, calendarTableCellInfo.getWidth(), calendarTableCellInfo.getHeight(), (String)calendarTableCellInfo.getValue());
if (calendarTableCellInfo.isDisabled()) {
g.setColor(calendarComponent.getCalendarSkin().getColorSkinProperty(CalendarSkin.DISABLED_COLOR));
int count = 3;
g.drawLine(count, count, calendarTableCellInfo.getWidth() - count, calendarTableCellInfo.getHeight() - count);
g.drawLine(count, calendarTableCellInfo.getHeight() - count, calendarTableCellInfo.getWidth() - count, count);
}
}
public String toString() {
return "Custom";
}
public static void drawCenteredString(Graphics g, int width, int height, String text) {
FontMetrics fontMetrics = g.getFontMetrics();
int currentWidth = fontMetrics.stringWidth(text);
int currentHeight = fontMetrics.getAscent() - 3;
int x = (width - currentWidth) / 2;
if (x < 0) {
x = 0;
}
int y = (height - currentHeight) / 2;
if (y < 0) {
y = 0;
}
y = height - y;
g.drawString(text, x, y);
}
}
class CalendarRendererProviderCustom extends CalendarRendererProviderDefault {
CalendarTableCellRendererCustom calendarTableCellRendererCustom = new CalendarTableCellRendererCustom();
public CalendarTableCellRenderer getTableCellRenderer(CalendarTableCellInfo calendarTableCellInfo) {
if (calendarTableCellInfo.getMonthType() == CalendarMonthType.CURRENT_MONTH && calendarTableCellInfo.getDayOfMonth() == 12 || calendarTableCellInfo.getDayOfMonth() == 21) {
return calendarTableCellRendererCustom;
}
return super.getTableCellRenderer(calendarTableCellInfo);
}
public String getName() {
return "Custom";
}
}
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarRendererProvider(new CalendarRendererProviderCustom());
CalendarComponent calendarComponent = new CalendarComponent(); calendarComponent.setCalendarProperty(CalendarComponent.FIRST_DAY_OF_WEEK, new Integer(java.util.Calendar.TUESDAY));
CalendarComponent calendarComponent = new CalendarComponent(); // show week calendarComponent.setCalendarProperty(CalendarComponent.SHOW_WEEK, new Boolean(true)); // hide week calendarComponent.setCalendarProperty(CalendarComponent.SHOW_WEEK, new Boolean(false));
CalendarComponent calendarComponent = new CalendarComponent(); // show grid calendarComponent.setCalendarProperty(CalendarComponent.SHOW_GRID, new Boolean(true)); // hide grid calendarComponent.setCalendarProperty(CalendarComponent.SHOW_GRID, new Boolean(false));
CalendarComponent calendarComponent = new CalendarComponent(); // show extra month days calendarComponent.setCalendarProperty(CalendarComponent.SHOW_EXTRA_MONTH_DAYS, new Boolean(true)); // hide extra month days calendarComponent.setCalendarProperty(CalendarComponent.SHOW_EXTRA_MONTH_DAYS, new Boolean(false));
CalendarComponent calendarComponent = new CalendarComponent(); //enable hover effect calendarComponent.setCalendarProperty(CalendarComponent.SHOW_HOVER, new Boolean(true)); //disable hover effect calendarComponent.setCalendarProperty(CalendarComponent.SHOW_HOVER, new Boolean(false));
CalendarComponent calendarComponent = new CalendarComponent(); calendarComponent.setCalendarProperty(CalendarComponent.MAX_WEEK_DAYS_NAMES_LENGTH, new Integer(2));
CalendarComponent calendarComponent = new CalendarComponent(); calendarComponent.setCalendarProperty(CalendarComponent.MAX_MONTHS_NAMES_LENGTH, new Integer(5));
CalendarComponent calendarComponent = new CalendarComponent(); calendarComponent.setCalendarProperty(CalendarComponent.INTER_ROWS_SPACING, new Integer(2));
CalendarComponent calendarComponent = new CalendarComponent(); calendarComponent.setCalendarProperty(CalendarComponent.INTER_COLUMNS_SPACING, new Integer(2));
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.addDateListener(new DateListener() {
public void dateChanged(Date date) {
// some java code here
}
});
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.addCalendarComponentListener(new CalendarComponentListener() {
public void processCalendarEvent(CalendarEvent calendarEvent) {
if (calendarEvent instanceof CalendarEventFirstDayOfWeekChanged) {
CalendarEventFirstDayOfWeekChanged calendarEventFirstDayOfWeekChanged = (CalendarEventFirstDayOfWeekChanged)calendarEvent;
System.out.println("First day of week:" + calendarEventFirstDayOfWeekChanged.getFirstDayOfWeek());
// some java code here
} else if (calendarEvent instanceof CalendarEventMaxMonthsNamesLengthChanged) {
CalendarEventMaxMonthsNamesLengthChanged calendarEventMaxMonthsNamesLengthChanged = (CalendarEventMaxMonthsNamesLengthChanged)calendarEvent;
System.out.println("Max Months Names Length:" + calendarEventMaxMonthsNamesLengthChanged.getMaxMonthsNamesLength());
// other java code here
}
}
public Class[] getEventsListened() {
return new Class[] {
CalendarEventFirstDayOfWeekChanged.class,
CalendarEventMaxMonthsNamesLengthChanged.class
};
}
});
CalendarComponent calendarComponent = new CalendarComponent(); calendarComponent.setCalendarProperty(CalendarComponent.LOCALE, Locale.FRANCE);
CalendarComponent calendarComponent = new CalendarComponent(); calendarComponent.setCalendarSelectionModel(new CalendarSelectionModelSingleIntervalSelection());
CalendarComponent calendarComponent = new CalendarComponent(); // allow empty selection calendarComponent.getCalendarSelectionModel().setEmptySelectionAllowed(true); // not allow empty selection calendarComponent.getCalendarSelectionModel().setEmptySelectionAllowed(false);
class CalendarSelectionModelCustom extends CalendarSelectionModelMultipleIntervalSelection {
private GregorianCalendar calendar = new GregorianCalendar();
public boolean isDateDisabled(Date date) {
calendar.setTime(date);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
return (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY);
}
public String getName() {
return "Custom";
}
}
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarSelectionModel(new CalendarSelectionModelCustom());
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.getCalendarSelectionModel().addCalendarSelectionListener(new CalendarSelectionListener() {
public void selectionChanged(CalendarSelectionModel calendarSelectionModel) {
Date[] selectedDates = calendarSelectionModel.getSelectedDates();
// Process the selected dates.
}
});
CalendarComponent calendarComponent = new CalendarComponent(); // show status panel calendarComponent.setCalendarProperty(CalendarComponent.SHOW_STATUS_PANEL, new Boolean(true)); // hide status panel calendarComponent.setCalendarProperty(CalendarComponent.SHOW_STATUS_PANEL, new Boolean(false));
CalendarComponent calendarComponent = new CalendarComponent(); // enable null dates calendarComponent.getCalendarSelectionModel().setEmptySelectionAllowed(true); // disable null dates calendarComponent.getCalendarSelectionModel().setEmptySelectionAllowed(false);
CalendarComponent calendarComponent = new CalendarComponent();
// set text for today label
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Hoy: {MM.dd.yyyy}");
// set text for none label
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "Ninguno");
final CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.addCalendarComponentListener(new CalendarComponentListener() {
public Class[] getEventsListened() {
return new Class[]{CalendarEventLocaleChanged.class};
}
public void processCalendarEvent(CalendarEvent calendarEvent) {
Locale locale = calendarComponent.getLocaleCalendarProperty(CalendarComponent.LOCALE);
if (locale.getLanguage().equals(Locale.ENGLISH.getLanguage())) {
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Today: {MM.dd.yyyy}");
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "None");
} else if (locale.getLanguage().equals(Locale.GERMAN.getLanguage())) {
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Heute: {MM.dd.yyyy}");
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "Kein");
} else if (locale.getLanguage().equals(Locale.FRENCH.getLanguage())) {
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Aujourd''hui: {MM.dd.yyyy}");
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "Aucun");
} else if (locale.getLanguage().equals(Locale.ITALIAN.getLanguage())) {
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Oggi: {MM.dd.yyyy}");
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "Nessuno");
} else if (locale.getLanguage().equals(new Locale("es", "", "").getLanguage())) {
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Hoy: {MM.dd.yyyy}");
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "Ninguno");
} else if (locale.getLanguage().equals(new Locale("ro", "", "").getLanguage())) {
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_TODAY_LABEL, "Astazi: {MM.dd.yyyy}");
calendarComponent.setCalendarProperty(CalendarComponent.STATUS_PANEL_NONE_LABEL, "Nimic");
}
}
});
CalendarComponent calendarComponent = new CalendarComponent(); int row = 0; int column = 3; CalendarTableCellInfo calendarTableCellInfo = calendarComponent.getCalendarView().getMonthView().getTableCellInfo(row, column);
CalendarComponent calendarComponent = new CalendarComponent(); int column = 4; CalendarHeaderCellInfo calendarHeaderCellInfo = calendarComponent.getCalendarView().getMonthView().getHeaderCellInfo(column);
CalendarComponent calendarComponent = new CalendarComponent(); int row = 4; CalendarWeekCellInfo calendarWeekCellInfo = calendarComponent.getCalendarView().getMonthView().getWeekCellInfo(row);
CalendarComponent calendarComponent = new CalendarComponent(); CalendarStatusPanelInfo calendarStatusPanelInfo = calendarComponent.getCalendarView().getMonthView().getCalendarStatusPanelInfo();
CalendarComponent calendarComponent = new CalendarComponent(); CalendarBackgroundInfo calendarBackgroundInfo = calendarComponent.getCalendarView().getMonthView().getCalendarBackgroundInfo();
CalendarComponent calendarComponent = new CalendarComponent(); CalendarPartInfo calendarPartInfo = calendarComponent.getCalendarView().getMonthView().getCurrentCalendarPartInfo();
CalendarComponent calendarComponent = new CalendarComponent(); CalendarPartInfo calendarPartInfo = calendarComponent.getCalendarView().getMonthView().getHoveredCalendarPartInfo();
CalendarComponent calendarComponent = new CalendarComponent(); // Get the month view current date. // The current date is the date from which the key operations are started. Date currentDate = calendarComponent.getCalendarView().getMonthView().getMonthViewCurrentDate(); // Set the date displayed by the month view. // This become the date from which the key operations are started. // This is not usually the calendar date. The calendar may display a month but it can have selected dates in other months. GregorianCalendar calendar = new GregorianCalendar(); calendar.set(Calendar.YEAR, 1990); calendar.set(Calendar.MONTH, Calendar.AUGUST); calendar.set(Calendar.DAY_OF_MONTH, 15); calendarComponent.getCalendarView().getMonthView().setMonthViewCurrentDate(calendar.getTime());
CalendarComponent calendarComponent = new CalendarComponent(); calendarComponent.setCalendarMetricsProvider(new CalendarMetricsProviderTight());
class CalendarMetricsProviderCustomTable extends CalendarMetricsProviderDefault {
CalendarTableCellMetricsCustom calendarTableCellMetricsCustom = new CalendarTableCellMetricsCustom();
public CalendarTableCellMetrics getTableCellMetrics(CalendarTableCellInfo calendarTableCellInfo) {
return calendarTableCellMetricsCustom;
}
public String getName() {
return "Custom";
}
}
class CalendarTableCellMetricsCustom implements CalendarTableCellMetrics {
Dimension dimension = new Dimension(0, 0);
/**
* @inheritDoc
*/
public Dimension getPreferredSize(CalendarComponent calendarComponent, CalendarTableCellInfo calendarTableCellInfo) {
FontMetrics fontMetrics = getFontMetrics(calendarComponent, calendarTableCellInfo);
dimension.width = fontMetrics.stringWidth( (String)calendarTableCellInfo.getValue() + " ") + 20;
dimension.height = fontMetrics.getAscent() + 15;
return dimension;
}
private FontMetrics getFontMetrics(CalendarComponent calendarComponent, CalendarTableCellInfo calendarTableCellInfo) {
Font font = calendarComponent.getFont();
int dayOfWeek = calendarTableCellInfo.getDayOfWeek();
CalendarMonthType calendarMonthType = calendarTableCellInfo.getMonthType();
boolean isFromWeekend = (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY);
if (calendarMonthType != CalendarMonthType.CURRENT_MONTH) {
font = calendarComponent.getCalendarSkin().getFontSkinProperty(CalendarSkin.EXTRA_MONTH_CELL_FONT);
} else if (isFromWeekend) {
font = calendarComponent.getCalendarSkin().getFontSkinProperty(CalendarSkin.WEEKEND_CELL_FONT);
} else {
font = calendarComponent.getCalendarSkin().getFontSkinProperty(CalendarSkin.CELL_FONT);
}
return calendarComponent.getFontMetrics(font);
}
public String toString() {
return "Custom";
}
}
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarMetricsProvider(new CalendarMetricsProviderCustomTable());
class CalendarMetricsProviderCustomHeader extends CalendarMetricsProviderDefault {
CalendarHeaderCellMetricsCustom calendarHeaderCellMetricsCustom = new CalendarHeaderCellMetricsCustom();
public CalendarHeaderCellMetrics getHeaderCellMetrics(CalendarHeaderCellInfo calendarHeaderCellInfo) {
return calendarHeaderCellMetricsCustom;
}
public String getName() {
return "Custom";
}
}
class CalendarHeaderCellMetricsCustom implements CalendarHeaderCellMetrics {
Dimension dimension = new Dimension(0, 0);
/**
* @inheritDoc
*/
public Dimension getPreferredSize(CalendarComponent calendarComponent, CalendarHeaderCellInfo calendarHeaderCellInfo) {
FontMetrics fontMetrics = getFontMetrics(calendarComponent, calendarHeaderCellInfo);
dimension.width = fontMetrics.stringWidth( (String)calendarHeaderCellInfo.getValue() + " ") + 14;
dimension.height = fontMetrics.getAscent() + 14;
return dimension;
}
private FontMetrics getFontMetrics(CalendarComponent calendarComponent, CalendarHeaderCellInfo calendarHeaderCellInfo) {
Font font = calendarComponent.getCalendarSkin().getFontSkinProperty(CalendarSkin.HEADER_CELL_FONT);
return calendarComponent.getFontMetrics(font);
}
public String toString() {
return "Custom";
}
}
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarMetricsProvider(new CalendarMetricsProviderCustomHeader());
class CalendarMetricsProviderCustomWeek extends CalendarMetricsProviderDefault {
CalendarWeekCellMetricsCustom calendarWeekCellMetricsCustom = new CalendarWeekCellMetricsCustom();
public CalendarWeekCellMetrics getWeekCellMetrics(CalendarWeekCellInfo calendarWeekCellInfo) {
return calendarWeekCellMetricsCustom;
}
public String getName() {
return "Custom";
}
}
class CalendarWeekCellMetricsCustom implements CalendarWeekCellMetrics {
Dimension dimension = new Dimension(0, 0);
/**
* @inheritDoc
*/
public Dimension getPreferredSize(CalendarComponent calendarComponent, CalendarWeekCellInfo calendarWeekCellInfo) {
FontMetrics fontMetrics = getFontMetrics(calendarComponent, calendarWeekCellInfo);
dimension.width = fontMetrics.stringWidth( "AA") + 14;
dimension.height = fontMetrics.getAscent() + 14;
return dimension;
}
private FontMetrics getFontMetrics(CalendarComponent calendarComponent, CalendarWeekCellInfo calendarWeekCellInfo) {
Font font = calendarComponent.getCalendarSkin().getFontSkinProperty(CalendarSkin.WEEK_CELL_FONT);
return calendarComponent.getFontMetrics(font);
}
public String toString() {
return "Custom";
}
}
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarMetricsProvider(new CalendarMetricsProviderCustomWeek());
class CalendarMetricsProviderCustomStatusPanel extends CalendarMetricsProviderDefault {
CalendarStatusPanelMetricsCustom calendarStatusPanelMetricsCustom = new CalendarStatusPanelMetricsCustom();
public CalendarStatusPanelMetrics getStatusPanelMetrics(CalendarStatusPanelInfo calendarStatusPanelInfo) {
return calendarStatusPanelMetricsCustom;
}
public String getName() {
return "Custom";
}
}
class CalendarStatusPanelMetricsCustom implements CalendarStatusPanelMetrics {
Dimension dimension = new Dimension(0, 0);
/**
* @inheritDoc
*/
public Dimension getPreferredSize(CalendarComponent calendarComponent, CalendarStatusPanelInfo calendarStatusPanelInfo) {
FontMetrics fontMetrics = getFontMetrics(calendarComponent, calendarStatusPanelInfo);
dimension.width = fontMetrics.stringWidth(calendarStatusPanelInfo.getTodayLabel() + " " + calendarStatusPanelInfo.getNoneLabel() + " ") + 14;
dimension.height = fontMetrics.getAscent() + 14;
return dimension;
}
private FontMetrics getFontMetrics(CalendarComponent calendarComponent, CalendarStatusPanelInfo calendarStatusPanelInfo) {
Font font = calendarComponent.getCalendarSkin().getFontSkinProperty(CalendarSkin.STATUS_PANEL_FONT);
return calendarComponent.getFontMetrics(font);
}
public String toString() {
return "Custom";
}
}
CalendarComponent calendarComponent = new CalendarComponent();
calendarComponent.setCalendarMetricsProvider(new CalendarMetricsProviderCustomStatusPanel());
CalendarComponent calendarComponent = new CalendarComponent();
CalendarNavigationController calendarNavigationController = calendarComponent.getCalendarView().getNavigationController();
if (calendarNavigationController instanceof CalendarNavigationControllerDefault) {
CalendarNavigationControllerDefault calendarNavigationControllerDefault = ((CalendarNavigationControllerDefault)calendarNavigationController);
JComboBox monthComboBox = calendarNavigationControllerDefault.getMonthComboBox();
JTextField yearTextField = calendarNavigationControllerDefault.getYearTextField();
JButton yearButtonUp = calendarNavigationControllerDefault.getYearButtonUp();
JButton yearButtonDown = calendarNavigationControllerDefault.getYearButtonDown();
}
CalendarComboBox calendarComboBox = new CalendarComboBox();
CalendarComboBoxView calendarComboBoxView = calendarComboBox.getCalendarComboBoxView();
if (calendarComboBoxView instanceof CalendarComboBoxViewDefault) {
CalendarComboBoxViewDefault calendarComboBoxViewDefault = ((CalendarComboBoxViewDefault)calendarComboBoxView);
JTextField textField = calendarComboBoxViewDefault.getTextField();
JButton buttonDown = calendarComboBoxViewDefault.getButtonDown();
}