X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTCalendar.java;h=c2005ccb60634279c8a3e5eb064cb59dc083ea04;hb=HEAD;hp=c117fc1615b0ea9545c2f9103d86d3daf1720fe7;hpb=051e29138b18fb4b731a72f8727475b10e4c74e4;p=fanfix.git diff --git a/src/jexer/TCalendar.java b/src/jexer/TCalendar.java index c117fc1..c2005cc 100644 --- a/src/jexer/TCalendar.java +++ b/src/jexer/TCalendar.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2017 Kevin Lamonte + * Copyright (C) 2019 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -33,6 +33,7 @@ import java.util.GregorianCalendar; import jexer.bits.CellAttributes; import jexer.bits.GraphicsChars; +import jexer.bits.StringUtils; import jexer.event.TKeypressEvent; import jexer.event.TMouseEvent; import static jexer.TKeypress.*; @@ -160,7 +161,7 @@ public class TCalendar extends TWidget { @Override public void onMouseDoubleClick(final TMouseEvent mouse) { if (updateAction != null) { - updateAction.DO(); + updateAction.DO(this); } } @@ -183,7 +184,7 @@ public class TCalendar extends TWidget { increment = 1; } else if (keypress.equals(kbEnter)) { if (updateAction != null) { - updateAction.DO(); + updateAction.DO(this); } return; } else { @@ -232,27 +233,30 @@ public class TCalendar extends TWidget { // Fill in the interior background for (int i = 0; i < getHeight(); i++) { - getScreen().hLineXY(0, i, getWidth(), ' ', backgroundColor); + hLineXY(0, i, getWidth(), ' ', backgroundColor); } // Draw the title String title = String.format("%tB %tY", displayCalendar, displayCalendar); - int titleLeft = (getWidth() - title.length() - 2) / 2; - getScreen().putCharXY(titleLeft, 0, ' ', titleColor); - getScreen().putStringXY(titleLeft + 1, 0, title, titleColor); - getScreen().putCharXY(titleLeft + title.length() + 1, 0, ' ', + // This particular title is always single-width (see format string + // above), but for completeness let's treat it the same as every + // other window title string. + int titleLeft = (getWidth() - StringUtils.width(title) - 2) / 2; + putCharXY(titleLeft, 0, ' ', titleColor); + putStringXY(titleLeft + 1, 0, title, titleColor); + putCharXY(titleLeft + StringUtils.width(title) + 1, 0, ' ', titleColor); // Arrows - getScreen().putCharXY(1, 0, GraphicsChars.LEFTARROW, arrowColor); - getScreen().putCharXY(getWidth() - 2, 0, GraphicsChars.RIGHTARROW, + putCharXY(1, 0, GraphicsChars.LEFTARROW, arrowColor); + putCharXY(getWidth() - 2, 0, GraphicsChars.RIGHTARROW, arrowColor); /* * Now draw out the days. */ - getScreen().putStringXY(0, 1, " S M T W T F S ", dayColor); + putStringXY(0, 1, " S M T W T F S ", dayColor); int lastDayNumber = displayCalendar.getActualMaximum( Calendar.DAY_OF_MONTH); GregorianCalendar firstOfMonth = new GregorianCalendar(); @@ -274,10 +278,10 @@ public class TCalendar extends TWidget { && (displayCalendar.get(Calendar.YEAR) == calendar.get( Calendar.YEAR)) ) { - getScreen().putStringXY(dayColumn, row, + putStringXY(dayColumn, row, String.format(" %2d ", dayOfMonth), selectedDayColor); } else { - getScreen().putStringXY(dayColumn, row, + putStringXY(dayColumn, row, String.format(" %2d ", dayOfMonth), dayColor); } dayColumn += 4;