protected String layout(DateComponent dc, FontMetrics fm, int width, int height) { Insets insets = dc.getInsets(null); String text = getText(dc); Icon icon = isEnabled(dc) ? dc.getIcon() : dc.getDisabledIcon(); Rectangle paintViewR = new Rectangle(); paintViewR.x = insets.left; paintViewR.y = insets.top; paintViewR.width = width - (insets.left + insets.right); paintViewR.height = height - (insets.top + insets.bottom); this.paintTextR.x = 3; this.paintTextR.y = 3; this.paintTextR.width = 0; this.paintTextR.height = 0; if (icon != null) { int gap = 5; int xx = fm.charWidth('X') * 2; this.paintIconR.x = this.paintTextR.x + xx + gap; this.paintIconR.y = (paintViewR.height - icon.getIconHeight()) / 2; this.paintIconR.width = 0; this.paintIconR.height = 0; } return text; }
protected void fillContentArea(Graphics g, DateComponent b, Color background) { Insets margin = new Insets(2, 2, 2, 2); Insets insets = b.getInsets(); Dimension size = b.getSize(); g.setColor(background); g.fillRect( insets.left - margin.left, insets.top - margin.top, size.width - (insets.left - margin.left) - (insets.right - margin.right), size.height - (insets.top - margin.top) - (insets.bottom - margin.bottom)); }
/** * @see org.olat.core.gui.components.ComponentRenderer#render(org.olat.core.gui.render.Renderer, * org.olat.core.gui.render.StringOutput, org.olat.core.gui.components.Component, * org.olat.core.gui.render.URLBuilder, org.olat.core.gui.translator.Translator, * org.olat.core.gui.render.RenderResult, java.lang.String[]) */ @Override public void render( Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) { DateComponent dateC = (DateComponent) source; Date date = dateC.getDate(); Locale locale = translator.getLocale(); sb.append("<div class=\"b_datecomp "); // Optional css class as render arg if (args != null && args.length == 1) { sb.append(args[0]); } sb.append("\">"); // Add year if configured if (dateC.isShowYear()) { SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy", locale); String year = yearFormat.format(date); sb.append("<div class=\"b_year b_year_").append(year); sb.append("\"><span>"); sb.append(year); sb.append("</span>"); sb.append("</div>"); } // Add month. SimpleDateFormat monthNumberFormat = new SimpleDateFormat("MM", locale); sb.append("<div class=\"b_month b_month_").append(monthNumberFormat.format(date)); sb.append("\"><span>"); SimpleDateFormat monthDisplayFormat = new SimpleDateFormat("MMM", locale); sb.append(monthDisplayFormat.format(date).toUpperCase()); sb.append("</span>"); sb.append("</div>"); // Add day SimpleDateFormat dayFormat = new SimpleDateFormat("dd", locale); String day = dayFormat.format(date); sb.append("<div class=\"b_day b_day_").append(day); sb.append("\"><span>"); sb.append(day); sb.append("</span>"); sb.append("</div>"); // sb.append("</div>"); }
protected void paintDisabledText(DateComponent dc, Graphics g, String s, int textX, int textY) { Color background = dc.getBackground(); g.setColor(background.brighter()); SwingUtilities2.drawString(dc, g, s, textX + 1, textY + 1); g.setColor(background.darker()); SwingUtilities2.drawString(dc, g, s, textX, textY); }
@Override public void paint(Graphics g, JComponent c) { DateComponent dc = (DateComponent) c; // --- boolean today = dc.isToday(); boolean selected = dc.isSelected(); boolean selectedMonth = dc.isSelectedMonth(); boolean isNone = !today && !selected && !selectedMonth; if (selectedMonth) { fillContentArea(g, dc, Color.WHITE); drawBorder(g, dc, this.defaultBorder); } if (selected) { fillContentArea(g, dc, Color.LIGHT_GRAY); drawBorder(g, dc, this.defaultBorder); } if (today) { drawBorder(g, dc, this.todayBorder); } if (isNone) { drawBorder(g, dc, this.defaultBorder); g.setColor(Color.GRAY); } g.setColor(c.getForeground()); g.setFont(c.getFont()); // --- String text = getText(dc); boolean enabled = isEnabled(dc); Icon icon = enabled ? dc.getIcon() : dc.getDisabledIcon(); if (icon == null && text == null) { return; } FontMetrics fm = SwingUtilities2.getFontMetrics(dc, g); String clippedText = layout(dc, fm, c.getWidth(), c.getHeight()); if (icon != null) { icon.paintIcon(c, g, this.paintIconR.x, this.paintIconR.y); } if (text != null) { View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, this.paintTextR); } else { int textX = this.paintTextR.x; int textY = this.paintTextR.y + fm.getAscent(); if (enabled) { paintEnabledText(dc, g, clippedText, textX, textY); } else { paintDisabledText(dc, g, clippedText, textX, textY); } } } }
protected String getText(DateComponent dc) { return String.valueOf(dc.getDayOfMonth()); }
protected boolean isEnabled(DateComponent dc) { return dc.isSelectedMonth(); }