public static Month getMonth(final String id) { for (Month aMonth : Month.values()) { if (aMonth.toString().equals(id)) { return aMonth; } } throw new IllegalArgumentException("invalid calendar value " + id); }
public void setTime(Combo dayCombo, Combo monthCombo, Combo yearCombo) { Calendar cal = Calendar.getInstance(); monthCombo.setText(Month.getMonthName(cal.get(Calendar.MONTH))); dayCombo.setItems(Month.getDays(monthCombo.getText())); int day = cal.get(Calendar.DAY_OF_MONTH); if (day < 10) dayCombo.setText("0" + cal.get(Calendar.DAY_OF_MONTH)); else dayCombo.setText("" + cal.get(Calendar.DAY_OF_MONTH)); yearCombo.setText("" + cal.get(Calendar.YEAR)); }
/** * Convert month number to its name. E.g. 12 -> December. Silently fails if the conversion cant * happen. * * @param fv * @return monthStr */ private String substituteMonthNamesForNums(String fv) { String monthStr = new String(fv); try { int m = Integer.parseInt(monthStr); Month month = Month.get(m - 1); // 1 index months monthStr = month.name(); } catch (Exception e) { // ignore } return monthStr; }
@Test public void testFieldBridge() { Transaction transaction = fullTextSession.beginTransaction(); final QueryBuilder monthQb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Month.class).get(); Query query = monthQb.keyword().onField("monthRomanNumber").matching(2).createQuery(); FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(query, Month.class); List<?> results = fullTextQuery.list(); assertEquals(1, results.size()); Month february = (Month) results.get(0); assertEquals(2, february.getMonthValue()); transaction.commit(); }
/** * DESCRIPTION: Obtains (x,y) values from the current data set for plotting. Also calculates the * range (min/max) of x-axis and y-axis values for the series. * * @return a SimpleXYSeries instance containing (x,y) values to plot. */ private SimpleXYSeries getPlotSeries() { final String tag = TAG + ".getPlotSeries()"; // create lists of x-axis, and y-axis numbers to plot List<Number> xNumbers = new LinkedList<Number>(); List<Number> yNumbers = new LinkedList<Number>(); // get numbers to plot from gas record monthly data, where (x,y) is: // x = sequential index [0..n] with labels mapped to specific months // y = calculated gallons used for that month sumy = 0; miny = Float.MAX_VALUE; maxy = Float.MIN_VALUE; minx = Long.MAX_VALUE; maxx = Long.MIN_VALUE; xlabels.clear(); long x = 0L; float y = 0f; for (Month month : PlotActivity.monthly) { y = PlotActivity.monthly.getTrips(month).getGallons(); Log.d(tag, "month=" + month.toString() + " x=" + x + " y=" + y); minx = Math.min(minx, x); maxx = Math.max(maxx, x); miny = Math.min(miny, y); maxy = Math.max(maxy, y); xNumbers.add(x); yNumbers.add(y); sumy += y; xlabels.put(x++, month.getLabel()); } // adjust min/max values if no data if (xNumbers.isEmpty()) minx = maxx = 0; if (yNumbers.isEmpty()) miny = maxy = 0; // calculate average for the series average = 0; if (!yNumbers.isEmpty()) { average = sumy / yNumbers.size(); } Log.d(tag, "minx=" + minx + " maxx=" + maxx); Log.d(tag, "miny=" + miny + " maxy=" + maxy); Log.d(tag, "sumy=" + sumy + " size=" + yNumbers.size() + " average=" + average); // create a new series from the x and y axis numbers String title = ""; return new SimpleXYSeries(xNumbers, yNumbers, title); }
/** getMonth() - return the Month object for the given month. */ public Month getMonth(String month) { int count = 0; boolean found = false; Month currMonth = this.jan; while (!found && count < MONTHS_IN_YEAR) { if (currMonth.getFull().equals(month)) found = true; else { currMonth = currMonth.getNext(); ++count; } } return currMonth; }
@Test public void testBasic() { System.out.println(Year.now()); System.out.println(Year.of(2015)); System.out.println(Year.isLeap(2016)); Locale locale = Locale.getDefault(); System.out.println(Month.DECEMBER.getDisplayName(TextStyle.FULL, locale)); System.out.println(Month.DECEMBER.getDisplayName(TextStyle.SHORT, locale)); System.out.println(Month.DECEMBER.getDisplayName(TextStyle.NARROW, locale)); System.out.println(Month.DECEMBER.getDisplayName(TextStyle.FULL_STANDALONE, locale)); System.out.println(Month.of(8).ordinal()); System.out.println(Month.AUGUST.minus(2)); System.out.println(YearMonth.now()); System.out.println(MonthDay.now()); System.out.println(DayOfWeek.FRIDAY.plus(2)); System.out.println(DayOfWeek.of(1)); System.out.println( DayOfWeek.from(LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()))); System.out.println(Period.between(Year.now().atDay(1), LocalDate.now())); System.out.println(ChronoUnit.DAYS.between(Year.now().atDay(1), LocalDate.now())); }
public String toString() { StringBuilder out = new StringBuilder(); if (timeMode != null) { out.append(timeMode.name().toLowerCase()); if (!TimeMode.NOW.equals(timeMode)) { out.append("[").append(intervalType.name().toLowerCase()); if (intervalType != null && intervalType.getIndex() > DateIntervalType.MONTH.getIndex() && firstMonthOfYear != null) { out.append(" ").append(firstMonthOfYear.name().toLowerCase()); } out.append("]"); } } if (timeAmount != null && timeAmount.getQuantity() != 0) { if (out.length() > 0) out.append(" "); out.append(timeAmount); } if (out.length() == 0) { out.append(TimeMode.NOW.name().toLowerCase()); } return out.toString(); }
public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter a month number (1 through 12) "); if (in.hasNextInt() == true) { int monthNumber = in.nextInt(); if (monthNumber > 12 || monthNumber < 1) { System.out.println("Number must be 1 through 12"); } else { Month myMonth = new Month(monthNumber); System.out.printf("%s %d", myMonth.getMonthName(), myMonth.getNumberOfDays()); } } else { System.out.println("Not an integer. Terminating"); } }
public static Month fromValue(int v) { for (Month c : Month.values()) { if (c.value == v) { return c; } } throw new IllegalArgumentException(v + ""); }
/** * Month conversion from entity object to jaxb model. * * @param data month entity object * @return jaxb model of month */ public static Month transformMonthToModel(org.kaleta.scheduler.backend.entity.Month data) { Month model = new Month(); model.setId(String.valueOf(data.getId())); Month.Specification specification = new Month.Specification(); specification.setName(data.getName()); specification.setDays(String.valueOf(data.getDaysNumber())); specification.setFirstDay(String.valueOf(data.getDayStartsWith())); for (Integer day : data.getPublicFreeDays()) { Month.Specification.FreeDay freeDay = new Month.Specification.FreeDay(); freeDay.setDay(String.valueOf(day)); specification.getFreeDayList().add(freeDay); } model.setSpecification(specification); Month.Schedule schedule = new Month.Schedule(); for (Task task : data.getTasks()) { Month.Schedule.Task taskModel = new Month.Schedule.Task(); taskModel.setId(String.valueOf(task.getId())); taskModel.setType(task.getType()); taskModel.setDescription(task.getDescription()); taskModel.setDay(String.valueOf(task.getDay())); taskModel.setStarts(task.getStarts().toString()); taskModel.setDuration(task.getDuration().toString()); taskModel.setPriority(String.valueOf(task.getPriority())); taskModel.setSuccessful(String.valueOf(task.getSuccessful())); schedule.getTaskList().add(taskModel); } model.setSchedule(schedule); Month.Accounting accounting = new Month.Accounting(); for (Item item : data.getItems()) { Month.Accounting.Item itemModel = new Month.Accounting.Item(); itemModel.setId(String.valueOf(item.getId())); itemModel.setType(item.getType()); itemModel.setDescription(item.getDescription()); itemModel.setDay(String.valueOf(item.getDay())); itemModel.setIncome(String.valueOf(item.getIncome())); itemModel.setAmount(String.valueOf(item.getAmount())); accounting.getItemList().add(itemModel); } model.setAccounting(accounting); return model; }
protected int monthAsInteger(String monthAsString) throws ParseException { try { return Month.getMonth(monthAsString).getCalendarMonth(); } catch (IllegalArgumentException e) { try { return Integer.parseInt(monthAsString); } catch (Exception f) { throw new ParseException("Invalid Month value: '" + monthAsString + "'", 0); } } }
public static void main(String[] args) { Month birthMonth; String userEntry; int position; int comparison; Scanner input = new Scanner(System.in); for (Month mon : Month.values()) System.out.print(mon + " "); System.out.print("\n\nEnter the first three letters of " + "your birth month >> "); userEntry = input.nextLine().toUpperCase(); birthMonth = Month.valueOf(userEntry); System.out.println("You entered " + birthMonth); position = birthMonth.ordinal(); System.out.println(birthMonth + " is in position " + position); System.out.println("So its month number is " + (position + 1)); comparison = birthMonth.compareTo(Month.JUN); if (comparison < 0) System.out.println(birthMonth + " is earlier in the year than " + Month.JUN); else if (comparison > 0) System.out.println(birthMonth + " is later in the year than " + Month.JUN); else System.out.println(birthMonth + " is " + Month.JUN); }
/** * This method accepts three types of months given: - Single and Double Digit months from 1 to 12 * (01 to 12) - 3 Digit BibTex strings (jan, feb, mar...) - Full English Month identifiers. * * @param value the given value * @return the corresponding Month instance */ public static Month getMonth(String value) { if (value == null) { return MonthUtil.NULL_OBJECT; } // Much more liberal matching covering most known abbreviations etc. String testString = value.replace("#", "").trim(); if (testString.length() > 3) { testString = testString.substring(0, 3); } Month m = MonthUtil.getMonthByShortName(testString); if (m.isValid()) { return m; } try { int number = Util.intValueOf(value); return MonthUtil.getMonthByNumber(number); } catch (NumberFormatException e) { return MonthUtil.NULL_OBJECT; } }
/** * @param date * @throws DateParseException */ public void parseDate(String date) throws DateParseException { String[] dateChunks = date.split(DELIMETER); if (dateChunks.length != 3) { throw new DateParseException( "Date not properly formatted, " + date + " should have been in the form DD-MM-YYYY"); } try { year = Integer.parseInt(dateChunks[2]); if (year > YEAR_MAX || year < YEAR_MIN) { throw new DateParseException( "Year field for " + date + " is beyond the valid range of " + YEAR_MIN + " and " + YEAR_MAX); } } catch (NumberFormatException nfe) { throw new DateParseException("Year field for " + date + " did not parse properly"); } try { month = Month.values()[Integer.parseInt(dateChunks[1])]; } catch (Exception ex) { // covers Array Index Out of Bounds throw new DateParseException("Month field for " + date + " did not parse properly"); } try { dayOfMonth = Integer.parseInt(dateChunks[0]); month.setYear(this.year); if (dayOfMonth > month.daysInMonth()) { throw new DateParseException( "Day field for " + date + " was out of range for month " + month.toString()); } } catch (NumberFormatException nfe) { throw new DateParseException("Day field for " + date + " did not parse properly"); } }
public List<TimeEntry> getByMonth(Month month, RowMapper<TimeEntry> mapper) { List<TimeEntry> entries = new ArrayList<>(); Cursor cursor = getDb() .query( TimeEntryContract.TimeEntry.TABLE_NAME, TimeEntryContract.TimeEntry.columns, "strftime('%m', date) = ?", new String[] {month.numeric()}, null, null, "date"); while (cursor.moveToNext()) { TimeEntry timeEntry = mapper.mapRow(cursor); entries.add(timeEntry); } return entries; }
/** * Month conversion from jaxb model to entity object. * * @param model jaxb model of month * @return month entity object */ public static org.kaleta.scheduler.backend.entity.Month transformMonthToData(Month model) { org.kaleta.scheduler.backend.entity.Month data = new org.kaleta.scheduler.backend.entity.Month(); data.setId(Integer.valueOf(model.getId())); data.setName(model.getSpecification().getName()); data.setDaysNumber(Integer.valueOf(model.getSpecification().getDays())); data.setDayStartsWith(Integer.valueOf(model.getSpecification().getFirstDay())); for (Month.Specification.FreeDay freeDay : model.getSpecification().getFreeDayList()) { data.getPublicFreeDays().add(Integer.valueOf(freeDay.getDay())); } for (Month.Schedule.Task modelTask : model.getSchedule().getTaskList()) { Task task = new Task(); task.setId(Integer.valueOf(modelTask.getId())); task.setType(modelTask.getType()); task.setDescription(modelTask.getDescription()); task.setDay(Integer.valueOf(modelTask.getDay())); Time starts = new Time(); starts.setFromString(modelTask.getStarts()); task.setStarts(starts); Time duration = new Time(); duration.setFromString(modelTask.getDuration()); task.setDuration(duration); task.setPriority(Boolean.valueOf(modelTask.getPriority())); task.setSuccessful(Boolean.valueOf(modelTask.getSuccessful())); data.getTasks().add(task); } for (Month.Accounting.Item modelItem : model.getAccounting().getItemList()) { Item item = new Item(); item.setId(Integer.valueOf(modelItem.getId())); item.setType(modelItem.getType()); item.setDescription(modelItem.getDescription()); item.setDay(Integer.valueOf(modelItem.getDay())); item.setIncome(Boolean.valueOf(modelItem.getIncome())); item.setAmount(new BigDecimal(modelItem.getAmount())); data.getItems().add(item); } return data; }
public static void main(String[] args) { Month.calculeteDaysInPeriod(Month.August, 2012, Month.May); System.out.println(Month.calculeteDaysInPeriod(Month.April, 2015, Month.March)); System.out.println(Month.detectSeason(Month.April)); System.out.println(Month.detectSeason(Month.December)); }
public static FiniteLocalDate on(final int year, final Month month, final int day) { return new FiniteLocalDate(new org.joda.time.LocalDate(year, month.ordinal() + 1, day)); }
public static String formatDateTime(Context ctx, String date) { /* * Date as: Tue Sep 03 19:12:43 +0800 2013 */ String[] times = date.split(" "); Loge.i("Origin Data : " + date); Loge.i("times.length : " + times.length); StringBuffer sbDate = new StringBuffer(""); if (times.length < 6) { return null; } Date finalDate = new Date(); Month mKey = Month.valueOf(times[1]); switch (mKey) { case Jan: finalDate.setMonth(1); break; case Feb: finalDate.setMonth(2); break; case Apr: finalDate.setMonth(3); break; case May: finalDate.setMonth(4); break; case Mar: finalDate.setMonth(5); break; case Jun: finalDate.setMonth(6); break; case Jul: finalDate.setMonth(7); break; case Aug: finalDate.setMonth(8); break; case Sep: finalDate.setMonth(9); break; case Oct: finalDate.setMonth(10); break; case Nov: finalDate.setMonth(11); break; case Dec: finalDate.setMonth(12); break; default: break; } String day = times[2]; Loge.i("Data day : " + day); if (day.startsWith("0")) { day = day.substring(1); } finalDate.setDate(Integer.parseInt(day)); String[] dayTimes = times[3].split(":"); for (int i = 0; i < dayTimes.length; i++) { switch (i) { case 0: finalDate.setHours(Integer.parseInt(dayTimes[0])); break; case 1: finalDate.setMinutes(Integer.parseInt(dayTimes[1])); break; case 2: finalDate.setSeconds(Integer.parseInt(dayTimes[2])); break; default: break; } } finalDate.setYear(Integer.valueOf(times[5])); sbDate.append(finalDate.getMonth()); sbDate.append(ctx.getResources().getString(R.string.month)); sbDate.append(finalDate.getDate()); sbDate.append(ctx.getResources().getString(R.string.day)); sbDate.append(" "); sbDate.append(finalDate.getHours()); sbDate.append(":"); if (finalDate.getMinutes() == 0) { sbDate.append("00"); } else { sbDate.append(finalDate.getMinutes()); } finalDate = null; Loge.i("Data String : " + sbDate.toString()); return sbDate.toString(); }
/** setLeapYear() - set the number of days in February. */ public void setLeapYear(int year) { Month feb = this.jan.getNext(); feb.setLeapYear(this.isLeapYear(year)); }
public Month getMonth() { return Month.getMonth(month); }
public Calendar() { // initialize days of the week this.sun = new DayNode("Sunday", 'N'); DayNode currDayNode = sun; currDayNode.setNext(new DayNode("Monday", 'Y')); currDayNode = currDayNode.getNext(); currDayNode.setNext(new DayNode("Tuesday", 'Y')); currDayNode = currDayNode.getNext(); currDayNode.setNext(new DayNode("Wednesday", 'Y')); currDayNode = currDayNode.getNext(); currDayNode.setNext(new DayNode("Thursday", 'Y')); currDayNode = currDayNode.getNext(); currDayNode.setNext(new DayNode("Friday", 'Y')); currDayNode = currDayNode.getNext(); currDayNode.setNext(new DayNode("Saturday", 'N')); currDayNode = currDayNode.getNext(); currDayNode.setNext(sun); // initialize the months this.jan = new Month("JAN", "January", 31, 1); Month currMonth = jan; currMonth.setNext(new Month("FEB", "February", 28, 2)); currMonth = currMonth.getNext(); currMonth.setNext(new Month("MAR", "March", 31, 3)); currMonth = currMonth.getNext(); currMonth.setNext(new Month("APR", "April", 30, 4)); currMonth = currMonth.getNext(); currMonth.setNext(new Month("MAY", "May", 31, 5)); currMonth = currMonth.getNext(); currMonth.setNext(new Month("JUN", "June", 30, 6)); currMonth = currMonth.getNext(); currMonth.setNext(new Month("JUL", "July", 31, 7)); currMonth = currMonth.getNext(); currMonth.setNext(new Month("AUG", "August", 31, 8)); currMonth = currMonth.getNext(); currMonth.setNext(new Month("SEP", "September", 30, 9)); currMonth = currMonth.getNext(); currMonth.setNext(new Month("OCT", "October", 31, 10)); currMonth = currMonth.getNext(); currMonth.setNext(new Month("NOV", "November", 30, 11)); currMonth = currMonth.getNext(); currMonth.setNext(new Month("DEC", "December", 31, 12)); currMonth = currMonth.getNext(); currMonth.setNext(jan); }
/** * Parses a time instant expression. * * @param timeInstantExpr A valid time instant expression (<i>see TimeInstant class javadoc</i>) * @return A TimeInstant instance * @throws IllegalArgumentException If the expression is not valid */ public static TimeInstant parse(String timeInstantExpr) { if (timeInstantExpr == null || timeInstantExpr.length() == 0) { throw new IllegalArgumentException("Empty time instant expression"); } TimeInstant instant = new TimeInstant(); String expr = timeInstantExpr.toLowerCase().trim(); // now + time amount (optional) boolean begin = expr.startsWith("begin"); boolean end = expr.startsWith("end"); if (!begin && !end) { if (expr.startsWith("now")) { instant.setTimeMode(TimeMode.NOW); if (expr.length() > 3) { instant.setTimeAmount(TimeAmount.parse(expr.substring(3))); } } else { instant.setTimeMode(null); instant.setTimeAmount(TimeAmount.parse(expr)); } return instant; } // begin/end modes instant.setTimeMode(begin ? TimeMode.BEGIN : TimeMode.END); // Look for braces limits "begin[year March]" String example = begin ? "begin[year March]" : "end[year March]"; int bracesBegin = expr.indexOf('['); int bracesEnd = expr.indexOf(']'); if (bracesBegin == -1 || bracesEnd == -1 || bracesBegin >= bracesEnd) { throw new IllegalArgumentException( "Missing braces (ex '" + example + "'): " + timeInstantExpr); } // Interval type String[] intervalTerms = expr.substring(bracesBegin + 1, bracesEnd).split("\\s+"); if (intervalTerms.length > 2) { throw new IllegalArgumentException( "Too many settings (ex '" + example + "'): " + timeInstantExpr); } instant.setIntervalType(DateIntervalType.getByName(intervalTerms[0])); if (instant.getIntervalType() == null) { throw new IllegalArgumentException( "Invalid interval (ex '" + example + "'): " + timeInstantExpr); } // First month of year if (intervalTerms.length == 2) { instant.setFirstMonthOfYear(Month.getByName(intervalTerms[1])); if (instant.getFirstMonthOfYear() == null) { throw new IllegalArgumentException( "Invalid first year month (ex '" + example + "'): " + timeInstantExpr); } } // Time amount if (bracesEnd < expr.length()) { expr = expr.substring(bracesEnd + 1).trim(); if (!expr.isEmpty()) { TimeAmount timeAmount = TimeAmount.parse(expr); instant.setTimeAmount(timeAmount); } } return instant; }
protected Date calculateStartTime() { Date startDate = getStartTime(); if (timeMode == null || TimeMode.NOW.equals(timeMode)) { return startDate; } if (DateIntervalType.MILLENIUM.equals(intervalType)) { int base = startDate.getYear() / 1000; int inc = TimeMode.END.equals(timeMode) ? 1 : 0; startDate.setYear((base + inc) * 1000); startDate.setMonth(firstMonthOfYear.getIndex() - 1); startDate.setDate(1); startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); } if (DateIntervalType.CENTURY.equals(intervalType)) { int base = startDate.getYear() / 100; int inc = TimeMode.END.equals(timeMode) ? 1 : 0; startDate.setYear((base + inc) * 100); startDate.setMonth(firstMonthOfYear.getIndex() - 1); startDate.setDate(1); startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); } if (DateIntervalType.DECADE.equals(intervalType)) { int base = startDate.getYear() / 10; int inc = TimeMode.END.equals(timeMode) ? 1 : 0; startDate.setYear((base + inc) * 10); startDate.setMonth(firstMonthOfYear.getIndex() - 1); startDate.setDate(1); startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); } if (DateIntervalType.YEAR.equals(intervalType)) { int month = startDate.getMonth(); int firstMonth = firstMonthOfYear.getIndex() - 1; int yearInc = 0; if (TimeMode.BEGIN.equals(timeMode)) yearInc = month < firstMonth ? -1 : 0; else yearInc = month < firstMonth ? 0 : 1; startDate.setYear(startDate.getYear() + yearInc); startDate.setMonth(firstMonth); startDate.setDate(1); startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); } if (DateIntervalType.QUARTER.equals(intervalType)) { int month = startDate.getMonth(); int firstMonth = Quarter.getQuarterFirstMonth(firstMonthOfYear.getIndex(), month + 1) - 1; int yearInc = 0; int monthInc = 3; if (TimeMode.BEGIN.equals(timeMode)) { yearInc = firstMonth > month ? -1 : 0; monthInc = 0; } startDate.setYear(startDate.getYear() + yearInc); startDate.setMonth(firstMonth + monthInc); startDate.setDate(1); startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); } if (DateIntervalType.MONTH.equals(intervalType)) { startDate.setDate(1); startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); if (TimeMode.END.equals(timeMode)) { startDate.setMonth(startDate.getMonth() + 1); } } if (DateIntervalType.DAY.equals(intervalType)) { startDate.setHours(0); startDate.setMinutes(0); startDate.setSeconds(0); if (TimeMode.END.equals(timeMode)) { startDate.setDate(startDate.getDate() + 1); } } if (DateIntervalType.HOUR.equals(intervalType)) { startDate.setMinutes(0); startDate.setSeconds(0); if (TimeMode.END.equals(timeMode)) { startDate.setHours(startDate.getHours() + 1); } } if (DateIntervalType.MINUTE.equals(intervalType)) { startDate.setSeconds(0); if (TimeMode.END.equals(timeMode)) { startDate.setMinutes(startDate.getMinutes() + 1); } } return startDate; }
public Birthdate withMonth(final Month month) { this.birthdateMonth = month.getNumeric(); return this; }
public static Month getMonth(final int calendar) { return Month.values()[calendar]; }
public NewUserDialog(Frame frame, ModelingCommons communicator, String errorLabelText) { super(frame); this.communicator = communicator; this.frame = frame; initializeGUIComponents(); errorLabel.setText(errorLabelText); getRootPane().setDefaultButton(createAccountButton); for (String country : communicator.getPriorityCountries()) { countryComboBox.addItem(country, true); } countryComboBox.addItem("--------", false); for (String country : communicator.getUnpriorityCountries()) { countryComboBox.addItem(country, true); } femaleRadioButton.setSelected(true); userAgreementTextPane.setText(communicator.getNewUserAgreement()); userAgreementTextPane.setCaretPosition(0); int startYear = 1930; birthdayYearComboBox.addItem(null); for (int y = Calendar.getInstance().get(Calendar.YEAR); y >= startYear; y--) { birthdayYearComboBox.addItem(y); } birthdayMonthComboBox.addItem(null); for (Month month : Month.getMonths()) { birthdayMonthComboBox.addItem(month); } birthdayDayComboBox.addItem(null); for (int d = 1; d <= 31; d++) { birthdayDayComboBox.addItem(d); } imageFromFileRadioButton.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent changeEvent) { if (imageFromFileRadioButton.isSelected()) { fileSelector.setEnabled(true); } else { fileSelector.setEnabled(false); } } }); imageFromFileRadioButton.setSelected(true); createAccountButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onOK(); } }); cancelButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }); loginButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { dispose(); NewUserDialog.this.communicator.promptForLogin(); } }); // call onCancel() when cross is clicked setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { onCancel(); } }); // call onCancel() on ESCAPE topLevelContainer.registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); setModal(true); pack(); setLocationRelativeTo(frame); setResizable(true); }
public static int compare(String name) { for (Month c : Month.values()) { if (c.name().equalsIgnoreCase(name)) return c.value; } return 0; }