BasicMonthViewUI extends MonthViewUI { protected Point getDayGridPositionAtLocation(int x, int y) { Rectangle monthDetailsBounds = getMonthDetailsBoundsAtLocation(x, y); if ((monthDetailsBounds == null) ||(!monthDetailsBounds.contains(x, y))) return null; int calendarRow = (y - monthDetailsBounds.y) / fullBoxHeight + DAY_HEADER_ROW; int absoluteColumn = (x - monthDetailsBounds.x) / fullBoxWidth; int calendarColumn = absoluteColumn + FIRST_DAY_COLUMN; if (!isLeftToRight) { int leading = monthDetailsBounds.x + monthDetailsBounds.width; calendarColumn = (leading - x) / fullBoxWidth + FIRST_DAY_COLUMN; } if (monthView.isShowingWeekNumber()) { calendarColumn -= 1; } return new Point(calendarColumn, calendarRow); }  @SuppressWarnings({"UnusedDeclaration"}) static ComponentUI createUI(JComponent c); @Override void installUI(JComponent c); @Override void uninstallUI(JComponent c); @Override String[] getDaysOfTheWeek(); boolean isUsingKeyboard(); void setUsingKeyboard(boolean val); @Override Date getDayAtLocation(int x, int y); @Override void update(Graphics g, JComponent c); @Override void paint(Graphics g, JComponent c); @Override Date getLastDisplayedDay(); static final int MONTH_DOWN; static final int MONTH_UP; }
@Test public void testDayGridPositionAtLocationRows() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.RIGHT_TO_LEFT); int calendarRow = BasicMonthViewUI.DAY_HEADER_ROW; for (int row = 0; row <= BasicMonthViewUI.WEEKS_IN_MONTH; row++) { Point location = getLocationInRow(ui, row); Point dayGridPosition = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("calendarRow at absolute row " + row, calendarRow, dayGridPosition.y); calendarRow++; } }
@Test public void testDayGridPositionAtLocationColumnsLToR() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.LEFT_TO_RIGHT); int calendarColumn = BasicMonthViewUI.FIRST_DAY_COLUMN; for (int column = 0; column < BasicMonthViewUI.DAYS_IN_WEEK; column++) { Point location = getLocationInColumn(ui, column); Point dayGridPosition = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("calendarColumn at absolute column " + column, calendarColumn, dayGridPosition.x); calendarColumn++; } }
@Test public void testDayGridPositionAtLocationColumnsLToRWithWeekNumber() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.LEFT_TO_RIGHT, true); int calendarColumn = BasicMonthViewUI.WEEK_HEADER_COLUMN; for (int column = 0; column <= BasicMonthViewUI.DAYS_IN_WEEK; column++) { Point location = getLocationInColumn(ui, column); Point dayGridPosition = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("calendarColumn at absolute column " + column, calendarColumn, dayGridPosition.x); calendarColumn++; } }
@Test public void testDayGridPositionAtLocationColumnsRToL() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.RIGHT_TO_LEFT); int calendarColumn = BasicMonthViewUI.LAST_DAY_COLUMN; for (int column = 0; column < BasicMonthViewUI.DAYS_IN_WEEK; column++) { Point location = getLocationInColumn(ui, column); Point dayGridPosition = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("calendarColumn at absolute column " + column, calendarColumn, dayGridPosition.x); calendarColumn--; } }
@Test public void testDayGridPositionAtLocationColumnsRToLWithWeekNumber() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.RIGHT_TO_LEFT, true); int calendarColumn = BasicMonthViewUI.LAST_DAY_COLUMN; for (int column = 0; column <= BasicMonthViewUI.DAYS_IN_WEEK; column++) { Point location = getLocationInColumn(ui, column); Point dayGridPosition = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("calendarColumn at absolute column " + column, calendarColumn, dayGridPosition.x); calendarColumn--; } }
@Test public void testDayGridPositionAtLocationDayHeader() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.RIGHT_TO_LEFT); Point location = getLocationInRow(ui, 0); Point dayGridPosition = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("first row below header must be day column header", BasicMonthViewUI.DAY_HEADER_ROW, dayGridPosition.y); }
@Test public void testDayGridPositionAtLocationFirstWeekRow() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.RIGHT_TO_LEFT); Point location = getLocationInRow(ui, 1); Point dayInGrid = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("first row", BasicMonthViewUI.FIRST_WEEK_ROW, dayInGrid.y); }
@Test public void testDayGridPositionAtLocationLastWeekRow() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.RIGHT_TO_LEFT); Point location = getLocationInRow(ui, BasicMonthViewUI.WEEKS_IN_MONTH); Point dayInGrid = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("first row", BasicMonthViewUI.LAST_WEEK_ROW, dayInGrid.y); }
@Test public void testDayGridPositionAtLocationLastColumnRToL() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.RIGHT_TO_LEFT); Point location = getLocationInColumn(ui, 0); Point dayGridPosition = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("last logical column in RToL", BasicMonthViewUI.LAST_DAY_COLUMN, dayGridPosition.x); }
@Test public void testDayGridPositionAtLocationFirstColumnRToL() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.RIGHT_TO_LEFT); Point location = getLocationInColumn(ui, BasicMonthViewUI.DAYS_IN_WEEK - 1); Point dayGridPosition = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("last logical column in RToL", BasicMonthViewUI.FIRST_DAY_COLUMN, dayGridPosition.x); }
@Test public void testDayGridPositionAtLocationFirstColumnRToLWithWeekNumber() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.RIGHT_TO_LEFT, true); Point location = getLocationInColumn(ui, BasicMonthViewUI.DAYS_IN_WEEK - 1); Point dayGridPosition = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("last logical column in RToL", BasicMonthViewUI.FIRST_DAY_COLUMN, dayGridPosition.x); }
@Test public void testDayGridPositionAtLocationFirstColumnLToR() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.LEFT_TO_RIGHT); Point location = getLocationInColumn(ui, 0); Point dayGridPosition = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("first logical column in LToR", BasicMonthViewUI.FIRST_DAY_COLUMN, dayGridPosition.x); }
@Test public void testDayGridPositionAtLocationLastColumnLToR() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.LEFT_TO_RIGHT); Point location = getLocationInColumn(ui, BasicMonthViewUI.DAYS_IN_WEEK - 1); Point dayGridPosition = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("first logical column in LToR", BasicMonthViewUI.LAST_DAY_COLUMN, dayGridPosition.x); }
@Test public void testDayGridPositionAtLocationWeekHeaderRToL() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.RIGHT_TO_LEFT, true); Point location = getLocationInColumn(ui, BasicMonthViewUI.DAYS_IN_WEEK); Point dayGridPosition = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("weeks of year column in RTL", BasicMonthViewUI.WEEK_HEADER_COLUMN, dayGridPosition.x); }
@Test public void testDayGridPositionAtLocationWeekHeaderLToR() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.LEFT_TO_RIGHT, true); Point location = getLocationInColumn(ui, 0); Point dayGridPosition = ui.getDayGridPositionAtLocation(location.x, location.y); assertEquals("first logical column in LToR", BasicMonthViewUI.WEEK_HEADER_COLUMN, dayGridPosition.x); }
@Test public void testDayGridPositionAtLocationMonthHeaderHitLToR() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.LEFT_TO_RIGHT); Point location = getLocationInMonthHeader(ui); assertNull("hit in header must return null grid position", ui.getDayGridPositionAtLocation(location.x, location.y)); }
@Test public void testDayGridPositionAtLocationMonthHeaderHitRToL() { if (GraphicsEnvironment.isHeadless()) { LOG.fine("cannot run test - headless environment"); return; } BasicMonthViewUI ui = getRealizedMonthViewUI(ComponentOrientation.RIGHT_TO_LEFT); Point location = getLocationInMonthHeader(ui); assertNull("hit in header must return null grid position", ui.getDayGridPositionAtLocation(location.x, location.y)); }