modules/controls/src/main/java/com/sun/javafx/scene/control/DatePickerHijrahContent.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.scene.control.skin;
  27 
  28 import java.time.LocalDate;
  29 import java.time.DateTimeException;
  30 import java.time.YearMonth;
  31 import java.time.format.DecimalStyle;
  32 import java.time.chrono.Chronology;
  33 import java.time.chrono.HijrahChronology;
  34 import java.time.chrono.HijrahDate;
  35 import java.time.chrono.IsoChronology;
  36 import java.util.Locale;
  37 
  38 import static java.time.temporal.ChronoField.*;
  39 
  40 import javafx.geometry.Pos;
  41 import javafx.scene.control.DatePicker;
  42 import javafx.scene.control.DateCell;
  43 import javafx.scene.control.Label;
  44 import javafx.scene.layout.BorderPane;
  45 import javafx.scene.text.Text;
  46 
  47 /**
  48  * Extends DatePickerContent to add a secondary calendar, allowing the
  49  * ISO and Islamic calendars to be displayed simultaneously.  The
  50  * secondary month, day, and year values are displayed as a colored
  51  * overlay, offset from the primary values.
  52  *
  53  * If the current DatePicker Chronology is HijrahChronology, then sets
  54  * the content's primary Chronology to be IsoChronology, and sets
  55  * HijrahChronology as the secondary.
  56  */
  57 class DatePickerHijrahContent extends DatePickerContent {
  58     private Label hijrahMonthYearLabel;
  59 
  60     DatePickerHijrahContent(final DatePicker datePicker) {
  61         super(datePicker);
  62     }
  63 
  64     /**
  65      * The primary chronology for display. This is overridden because
  66      * DatePickerHijrahContent uses ISO as primary and Hijrah as a
  67      * secondary chronology.
  68      */
  69     @Override protected Chronology getPrimaryChronology() {
  70         return IsoChronology.INSTANCE;
  71     }
  72 
  73     @Override protected BorderPane createMonthYearPane() {
  74         BorderPane monthYearPane = super.createMonthYearPane();
  75 
  76         hijrahMonthYearLabel = new Label();
  77         hijrahMonthYearLabel.getStyleClass().add("secondary-label");
  78         monthYearPane.setBottom(hijrahMonthYearLabel);
  79         BorderPane.setAlignment(hijrahMonthYearLabel, Pos.CENTER);
  80 


 133                 }
 134             } catch (DateTimeException ex) {
 135                 // Date is out of range, ignore.
 136 
 137                 //System.err.println(dayCellDate(dayCell) + " " + ex);
 138             }
 139         }
 140 
 141         hijrahMonthYearLabel.setText(hijrahStr);
 142     }
 143 
 144     @Override protected void createDayCells() {
 145         super.createDayCells();
 146 
 147         for (DateCell dayCell : dayCells) {
 148             Text secondaryText = new Text();
 149             dayCell.getProperties().put("DateCell.secondaryText", secondaryText);
 150         }
 151     }
 152 
 153     @Override void updateDayCells() {
 154         super.updateDayCells();
 155 
 156         Locale locale = getLocale();
 157         HijrahChronology chrono = HijrahChronology.INSTANCE;
 158 
 159         int majorityMonth = -1;
 160         int visibleDaysInMajorityMonth = -1;
 161         int curMonth = -1;
 162         int visibleDaysInCurMonth = 0;
 163 
 164         for (DateCell dayCell : dayCells) {
 165             Text secondaryText = (Text)dayCell.getProperties().get("DateCell.secondaryText");
 166             dayCell.getStyleClass().add("hijrah-day-cell");
 167             secondaryText.getStyleClass().setAll("text", "secondary-text");
 168 
 169             try {
 170                 HijrahDate cDate = chrono.date(dayCellDate(dayCell));
 171 //             long month = cDate.getLong(MONTH_OF_YEAR);
 172 
 173                 String hijrahStr =




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.scene.control;
  27 
  28 import java.time.LocalDate;
  29 import java.time.DateTimeException;
  30 import java.time.YearMonth;
  31 import java.time.format.DecimalStyle;
  32 import java.time.chrono.Chronology;
  33 import java.time.chrono.HijrahChronology;
  34 import java.time.chrono.HijrahDate;
  35 import java.time.chrono.IsoChronology;
  36 import java.util.Locale;
  37 
  38 import static java.time.temporal.ChronoField.*;
  39 
  40 import javafx.geometry.Pos;
  41 import javafx.scene.control.DatePicker;
  42 import javafx.scene.control.DateCell;
  43 import javafx.scene.control.Label;
  44 import javafx.scene.layout.BorderPane;
  45 import javafx.scene.text.Text;
  46 
  47 /**
  48  * Extends DatePickerContent to add a secondary calendar, allowing the
  49  * ISO and Islamic calendars to be displayed simultaneously.  The
  50  * secondary month, day, and year values are displayed as a colored
  51  * overlay, offset from the primary values.
  52  *
  53  * If the current DatePicker Chronology is HijrahChronology, then sets
  54  * the content's primary Chronology to be IsoChronology, and sets
  55  * HijrahChronology as the secondary.
  56  */
  57 public class DatePickerHijrahContent extends DatePickerContent {
  58     private Label hijrahMonthYearLabel;
  59 
  60     public DatePickerHijrahContent(final DatePicker datePicker) {
  61         super(datePicker);
  62     }
  63 
  64     /**
  65      * The primary chronology for display. This is overridden because
  66      * DatePickerHijrahContent uses ISO as primary and Hijrah as a
  67      * secondary chronology.
  68      */
  69     @Override protected Chronology getPrimaryChronology() {
  70         return IsoChronology.INSTANCE;
  71     }
  72 
  73     @Override protected BorderPane createMonthYearPane() {
  74         BorderPane monthYearPane = super.createMonthYearPane();
  75 
  76         hijrahMonthYearLabel = new Label();
  77         hijrahMonthYearLabel.getStyleClass().add("secondary-label");
  78         monthYearPane.setBottom(hijrahMonthYearLabel);
  79         BorderPane.setAlignment(hijrahMonthYearLabel, Pos.CENTER);
  80 


 133                 }
 134             } catch (DateTimeException ex) {
 135                 // Date is out of range, ignore.
 136 
 137                 //System.err.println(dayCellDate(dayCell) + " " + ex);
 138             }
 139         }
 140 
 141         hijrahMonthYearLabel.setText(hijrahStr);
 142     }
 143 
 144     @Override protected void createDayCells() {
 145         super.createDayCells();
 146 
 147         for (DateCell dayCell : dayCells) {
 148             Text secondaryText = new Text();
 149             dayCell.getProperties().put("DateCell.secondaryText", secondaryText);
 150         }
 151     }
 152 
 153     @Override public void updateDayCells() {
 154         super.updateDayCells();
 155 
 156         Locale locale = getLocale();
 157         HijrahChronology chrono = HijrahChronology.INSTANCE;
 158 
 159         int majorityMonth = -1;
 160         int visibleDaysInMajorityMonth = -1;
 161         int curMonth = -1;
 162         int visibleDaysInCurMonth = 0;
 163 
 164         for (DateCell dayCell : dayCells) {
 165             Text secondaryText = (Text)dayCell.getProperties().get("DateCell.secondaryText");
 166             dayCell.getStyleClass().add("hijrah-day-cell");
 167             secondaryText.getStyleClass().setAll("text", "secondary-text");
 168 
 169             try {
 170                 HijrahDate cDate = chrono.date(dayCellDate(dayCell));
 171 //             long month = cDate.getLong(MONTH_OF_YEAR);
 172 
 173                 String hijrahStr =