/** * Static initialization of the predefined calendars found in the lib/calendars.properties file. */ static { try { calendarProperties = j86.sun.util.calendar.BaseCalendar.getCalendarProperties(); } catch (IOException ioe) { throw new InternalError("Can't initialize lib/calendars.properties", ioe); } try { INSTANCE = new HijrahChronology("Hijrah-umalqura"); // Register it by its aliases AbstractChronology.registerChrono(INSTANCE, "Hijrah"); AbstractChronology.registerChrono(INSTANCE, "islamic"); } catch (DateTimeException ex) { // Absence of Hijrah calendar is fatal to initializing this class. PlatformLogger logger = PlatformLogger.getLogger("j86.java.time.chrono"); logger.severe("Unable to initialize Hijrah calendar: Hijrah-umalqura", ex); throw new RuntimeException("Unable to initialize Hijrah-umalqura calendar", ex.getCause()); } registerVariants(); }
/** * For each Hijrah variant listed, create the HijrahChronology and register it. Exceptions during * initialization are logged but otherwise ignored. */ private static void registerVariants() { for (String name : calendarProperties.stringPropertyNames()) { if (name.startsWith(PROP_PREFIX)) { String id = name.substring(PROP_PREFIX.length()); if (id.indexOf('.') >= 0) { continue; // no name or not a simple name of a calendar } if (id.equals(INSTANCE.getId())) { continue; // do not duplicate the default } try { // Create and register the variant HijrahChronology chrono = new HijrahChronology(id); AbstractChronology.registerChrono(chrono); } catch (DateTimeException ex) { // Log error and continue PlatformLogger logger = PlatformLogger.getLogger("j86.java.time.chrono"); logger.severe("Unable to initialize Hijrah calendar: " + id, ex); } } } }
public final void runComponents(Component[] comps, Graphics g, int weightFlags) { int ncomponents = comps.length; Shape clip = g.getClip(); if (log.isLoggable(PlatformLogger.Level.FINER) && (clip != null)) { Rectangle newrect = clip.getBounds(); log.finer( "x = " + newrect.x + ", y = " + newrect.y + ", width = " + newrect.width + ", height = " + newrect.height); } // A seriously sad hack-- // Lightweight components always paint behind peered components, // even if they are at the top of the Z order. We emulate this // behavior by making two printing passes: the first for lightweights; // the second for heavyweights. // // ToDo(dpm): Either build a list of heavyweights during the // lightweight pass, or redesign the components array to keep // lightweights and heavyweights separate. if ((weightFlags & TWO_PASSES) != 0) { for (int i = ncomponents - 1; i >= 0; i--) { runOneComponent(comps[i], null, g, clip, LIGHTWEIGHTS); } for (int i = ncomponents - 1; i >= 0; i--) { runOneComponent(comps[i], null, g, clip, HEAVYWEIGHTS); } } else { for (int i = ncomponents - 1; i >= 0; i--) { runOneComponent(comps[i], null, g, clip, weightFlags); } } }
/** * Loads and processes the Hijrah calendar properties file for this calendarType. The starting * Hijrah date and the corresponding ISO date are extracted and used to calculate the epochDate * offset. The version number is identified and ignored. Everything else is the data for a year * with containing the length of each of 12 months. * * @throws DateTimeException if initialization of the calendar data from the resource fails */ private void loadCalendarData() { try { String resourceName = calendarProperties.getProperty(PROP_PREFIX + typeId); Objects.requireNonNull( resourceName, "Resource missing for calendar: " + PROP_PREFIX + typeId); Properties props = readConfigProperties(resourceName); Map<Integer, int[]> years = new HashMap<>(); int minYear = Integer.MAX_VALUE; int maxYear = Integer.MIN_VALUE; String id = null; String type = null; String version = null; int isoStart = 0; for (Map.Entry<Object, Object> entry : props.entrySet()) { String key = (String) entry.getKey(); switch (key) { case KEY_ID: id = (String) entry.getValue(); break; case KEY_TYPE: type = (String) entry.getValue(); break; case KEY_VERSION: version = (String) entry.getValue(); break; case KEY_ISO_START: { int[] ymd = parseYMD((String) entry.getValue()); isoStart = (int) LocalDate.of(ymd[0], ymd[1], ymd[2]).toEpochDay(); break; } default: try { // Everything else is either a year or invalid int year = Integer.valueOf(key); int[] months = parseMonths((String) entry.getValue()); years.put(year, months); maxYear = Math.max(maxYear, year); minYear = Math.min(minYear, year); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("bad key: " + key); } } } if (!getId().equals(id)) { throw new IllegalArgumentException("Configuration is for a different calendar: " + id); } if (!getCalendarType().equals(type)) { throw new IllegalArgumentException( "Configuration is for a different calendar type: " + type); } if (version == null || version.isEmpty()) { throw new IllegalArgumentException("Configuration does not contain a version"); } if (isoStart == 0) { throw new IllegalArgumentException("Configuration does not contain a ISO start date"); } // Now create and validate the array of epochDays indexed by epochMonth hijrahStartEpochMonth = minYear * 12; minEpochDay = isoStart; hijrahEpochMonthStartDays = createEpochMonths(minEpochDay, minYear, maxYear, years); maxEpochDay = hijrahEpochMonthStartDays[hijrahEpochMonthStartDays.length - 1]; // Compute the min and max year length in days. for (int year = minYear; year < maxYear; year++) { int length = getYearLength(year); minYearLength = Math.min(minYearLength, length); maxYearLength = Math.max(maxYearLength, length); } } catch (Exception ex) { // Log error and throw a DateTimeException PlatformLogger logger = PlatformLogger.getLogger("j86.java.time.chrono"); logger.severe("Unable to initialize Hijrah calendar proxy: " + typeId, ex); throw new DateTimeException("Unable to initialize HijrahCalendar: " + typeId, ex); } }
public abstract class SunGraphicsCallback { public static final int HEAVYWEIGHTS = 0x1; public static final int LIGHTWEIGHTS = 0x2; public static final int TWO_PASSES = 0x4; private static final PlatformLogger log = PlatformLogger.getLogger("j86.sun.awt.SunGraphicsCallback"); public abstract void run(Component comp, Graphics cg); protected void constrainGraphics(Graphics g, Rectangle bounds) { if (g instanceof ConstrainableGraphics) { ((ConstrainableGraphics) g).constrain(bounds.x, bounds.y, bounds.width, bounds.height); } else { g.translate(bounds.x, bounds.y); } g.clipRect(0, 0, bounds.width, bounds.height); } @SuppressWarnings("deprecation") public final void runOneComponent( Component comp, Rectangle bounds, Graphics g, Shape clip, int weightFlags) { if (comp == null || comp.getPeer() == null || !comp.isVisible()) { return; } boolean lightweight = comp.isLightweight(); if ((lightweight && (weightFlags & LIGHTWEIGHTS) == 0) || (!lightweight && (weightFlags & HEAVYWEIGHTS) == 0)) { return; } if (bounds == null) { bounds = comp.getBounds(); } if (clip == null || clip.intersects(bounds)) { Graphics cg = g.create(); try { constrainGraphics(cg, bounds); cg.setFont(comp.getFont()); cg.setColor(comp.getForeground()); if (cg instanceof Graphics2D) { ((Graphics2D) cg).setBackground(comp.getBackground()); } else if (cg instanceof Graphics2Delegate) { ((Graphics2Delegate) cg).setBackground(comp.getBackground()); } run(comp, cg); } finally { cg.dispose(); } } } public final void runComponents(Component[] comps, Graphics g, int weightFlags) { int ncomponents = comps.length; Shape clip = g.getClip(); if (log.isLoggable(PlatformLogger.Level.FINER) && (clip != null)) { Rectangle newrect = clip.getBounds(); log.finer( "x = " + newrect.x + ", y = " + newrect.y + ", width = " + newrect.width + ", height = " + newrect.height); } // A seriously sad hack-- // Lightweight components always paint behind peered components, // even if they are at the top of the Z order. We emulate this // behavior by making two printing passes: the first for lightweights; // the second for heavyweights. // // ToDo(dpm): Either build a list of heavyweights during the // lightweight pass, or redesign the components array to keep // lightweights and heavyweights separate. if ((weightFlags & TWO_PASSES) != 0) { for (int i = ncomponents - 1; i >= 0; i--) { runOneComponent(comps[i], null, g, clip, LIGHTWEIGHTS); } for (int i = ncomponents - 1; i >= 0; i--) { runOneComponent(comps[i], null, g, clip, HEAVYWEIGHTS); } } else { for (int i = ncomponents - 1; i >= 0; i--) { runOneComponent(comps[i], null, g, clip, weightFlags); } } } public static final class PaintHeavyweightComponentsCallback extends SunGraphicsCallback { private static PaintHeavyweightComponentsCallback instance = new PaintHeavyweightComponentsCallback(); private PaintHeavyweightComponentsCallback() {} public void run(Component comp, Graphics cg) { if (!comp.isLightweight()) { comp.paintAll(cg); } else if (comp instanceof Container) { runComponents(((Container) comp).getComponents(), cg, LIGHTWEIGHTS | HEAVYWEIGHTS); } } public static PaintHeavyweightComponentsCallback getInstance() { return instance; } } public static final class PrintHeavyweightComponentsCallback extends SunGraphicsCallback { private static PrintHeavyweightComponentsCallback instance = new PrintHeavyweightComponentsCallback(); private PrintHeavyweightComponentsCallback() {} public void run(Component comp, Graphics cg) { if (!comp.isLightweight()) { comp.printAll(cg); } else if (comp instanceof Container) { runComponents(((Container) comp).getComponents(), cg, LIGHTWEIGHTS | HEAVYWEIGHTS); } } public static PrintHeavyweightComponentsCallback getInstance() { return instance; } } }