Mercurial Hosting > junotu
changeset 89:355b3c6c6eb9
TabCalendarBoard: Made populateColumns() more careful
Practically, that means that there isn't a delay anymore when toggling 'show only filled days' option.
author | Fox |
---|---|
date | Sun, 19 Feb 2023 00:51:57 +0100 |
parents | a22a6d60a669 |
children | 3f068cb07fdf |
files | src/junotu/TabCalendarBoard.java |
diffstat | 1 files changed, 62 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/junotu/TabCalendarBoard.java Sun Feb 19 00:15:34 2023 +0100 +++ b/src/junotu/TabCalendarBoard.java Sun Feb 19 00:51:57 2023 +0100 @@ -642,25 +642,58 @@ public void populateColumns() { - columns.removeAll(); - columns.validate(); - columns.repaint(); JSpinner.DateEditor dateRangeBeginEditor = (JSpinner.DateEditor)dateRangeBegin.getEditor(); JSpinner.DateEditor dateRangeEndEditor = (JSpinner.DateEditor)dateRangeEnd.getEditor(); Date begin = dateRangeBeginEditor.getModel().getDate(); Date end = dateRangeEndEditor.getModel().getDate(); + + Component[] columnList = columns.getComponents(); if( begin.after(end) ) { + ColumnWidget columnWidget; + for( int i = 0; i < columnList.length; i++ ) { + columnWidget = (ColumnWidget)columnList[i]; + columnWidget.save(); + } + columns.removeAll(); + columns.validate(); + columns.repaint(); return; } + for( int i = 0; i < columnList.length; i++ ) { + ColumnWidget columnWidget = (ColumnWidget)columnList[i]; + if( columnWidget.date.before(begin) ) { + columnWidget.save(); + columns.remove( columnWidget ); + } else { + break; + } + } + Term term = new Term(Card.TAG_CALENDAR_BOARD_COLUMN_DATE); Calendar cur = Calendar.getInstance(); cur.setTime(begin); + Date curTime; + int insertPosition = 0; for( ; cur.getTime().before(end); cur.add( Calendar.DAY_OF_MONTH, 1 ) ) { + curTime = cur.getTime(); + + int column = findColumn(curTime); + if( column != -1 ) { + ColumnWidget columnWidget = getColumnByIndex(column); + if( !optionOnlyFilledColumns || columnWidget.cardCount() != 0 ) { + insertPosition = column+1; + } else { + columnWidget.save(); + columns.remove( columnWidget ); + } + continue; + } + Card card = null; term = term.createTerm( DATE_FORMAT.format(cur.getTime()) ); @@ -674,21 +707,25 @@ continue; } - insertColumn( cur.getTime(), card ); + insertColumn( cur.getTime(), card, insertPosition ); + insertPosition++; } + + columns.validate(); + columns.repaint(); } - public void insertColumn( Date date, Card card ) + public void insertColumn( Date date, Card card, int insertPosition ) { ColumnWidget column = new ColumnWidget(this, card, date); column.titleSet( DateFormat.getDateInstance().format(date) ); - insertColumnRaw(column); + insertColumnRaw(column, insertPosition); } - public void insertColumnRaw( ColumnWidget column ) + public void insertColumnRaw( ColumnWidget column, int insertPosition ) { column.addMouseListener(this); - columns.add(column); + columns.add(column, insertPosition); columns.revalidate(); } @@ -703,6 +740,23 @@ return -1; } + public int findColumn( Date date ) + { + Component[] columnsList = columns.getComponents(); + for( int i = 0; i < columnsList.length; i++ ) { + if( ((ColumnWidget)columnsList[i]).date.equals(date) ) { + return i; + } + } + return -1; + } + + public ColumnWidget getColumnByIndex( int index ) + { + Component[] columnsList = columns.getComponents(); + return (ColumnWidget)columnsList[index]; + } + public void removeColumn( ColumnWidget columnWidget ) { columnWidget.delete(); columns.remove( columnWidget ); @@ -760,7 +814,6 @@ return; } else if( source == menu_onlyFilled ) { optionOnlyFilledColumns = menu_onlyFilled.isSelected(); - boardSave(); populateColumns(); return; }