Mercurial Hosting > junotu
changeset 90:3f068cb07fdf
TabCalendarBoard: Date selection fixes
Made 'end' of the range inclusive instead of exclusive, and now setting default spinners to midnight to avoid issues later.
author | Fox |
---|---|
date | Sun, 19 Feb 2023 02:22:53 +0100 |
parents | 355b3c6c6eb9 |
children | 4979d5820624 |
files | src/junotu/TabCalendarBoard.java |
diffstat | 1 files changed, 21 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/junotu/TabCalendarBoard.java Sun Feb 19 00:51:57 2023 +0100 +++ b/src/junotu/TabCalendarBoard.java Sun Feb 19 02:22:53 2023 +0100 @@ -69,6 +69,7 @@ final static int COLUMN_CONTENT_WIDTH = 256; final static int COLUMN_WIDTH = COLUMN_CONTENT_WIDTH+16; final static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); + final static SimpleDateFormat DEBUG_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public final String KEY_ACTION_CARD_UP = "card_up"; public final String KEY_ACTION_CARD_DOWN = "card_down"; @@ -542,6 +543,7 @@ dateRangeEnd = new JSpinner( new SpinnerDateModel() ); JSpinner.DateEditor dateRangeBeginEditor = (JSpinner.DateEditor)dateRangeBegin.getEditor(); JSpinner.DateEditor dateRangeEndEditor = (JSpinner.DateEditor)dateRangeEnd.getEditor(); + Calendar calendar = Calendar.getInstance(); menu = new JPopupMenu("Options"); menu_onlyFilled = new JCheckBoxMenuItem("Show only filled days"); @@ -559,9 +561,17 @@ this.add( scroll, BorderLayout.CENTER ); this.add( bottom, BorderLayout.SOUTH ); + calendar.set( Calendar.HOUR_OF_DAY, 0 ); + calendar.set( Calendar.MINUTE, 0 ); + calendar.set( Calendar.SECOND, 0 ); + calendar.set( Calendar.MILLISECOND, 0 ); + dateRangeBeginEditor.getFormat().applyPattern("yyyy-MM-dd EEEE"); dateRangeEndEditor.getFormat().applyPattern("yyyy-MM-dd EEEE"); + dateRangeBeginEditor.getModel().setValue(calendar.getTime()); + dateRangeEndEditor.getModel().setValue(calendar.getTime()); + dateRangeBegin.addChangeListener(this); dateRangeEnd.addChangeListener(this); @@ -600,6 +610,8 @@ optionOnlyFilledColumns = card.tagHas( Card.TAG_CALENDAR_BOARD_OPTION_ONLY_FILLED ); menu_onlyFilled.setSelected(optionOnlyFilledColumns); + + populateColumns(); } @@ -642,7 +654,6 @@ public void populateColumns() { - JSpinner.DateEditor dateRangeBeginEditor = (JSpinner.DateEditor)dateRangeBegin.getEditor(); JSpinner.DateEditor dateRangeEndEditor = (JSpinner.DateEditor)dateRangeEnd.getEditor(); @@ -665,11 +676,9 @@ for( int i = 0; i < columnList.length; i++ ) { ColumnWidget columnWidget = (ColumnWidget)columnList[i]; - if( columnWidget.date.before(begin) ) { + if( columnWidget.date.before(begin) || columnWidget.date.after(end) ) { columnWidget.save(); columns.remove( columnWidget ); - } else { - break; } } @@ -677,11 +686,13 @@ Calendar cur = Calendar.getInstance(); cur.setTime(begin); - Date curTime; + Date curTime = begin; int insertPosition = 0; - for( ; cur.getTime().before(end); cur.add( Calendar.DAY_OF_MONTH, 1 ) ) { - curTime = cur.getTime(); - + for( + ; + (curTime = cur.getTime()).before(end) || curTime.equals(end); + cur.add( Calendar.DAY_OF_MONTH, 1 ) + ) { int column = findColumn(curTime); if( column != -1 ) { ColumnWidget columnWidget = getColumnByIndex(column); @@ -696,7 +707,7 @@ Card card = null; - term = term.createTerm( DATE_FORMAT.format(cur.getTime()) ); + term = term.createTerm( DATE_FORMAT.format(curTime) ); Card cards[] = Main.database.searchCustom( new TermQuery(term), 1, false ); if( cards.length != 0 ) { @@ -707,7 +718,7 @@ continue; } - insertColumn( cur.getTime(), card, insertPosition ); + insertColumn( curTime, card, insertPosition ); insertPosition++; } @@ -863,7 +874,6 @@ { Object source = e.getSource(); if( source == dateRangeBegin || source == dateRangeEnd ) { - boardSave(); populateColumns(); } }