Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
shannah committed Sep 21, 2017
2 parents 5b71589 + 99843a2 commit e150ae7
Showing 4 changed files with 71 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CodenameOne/src/cn1-version-numbers
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7ff2ab7747628f6d0777b0bf0db2c282b2f76933
c9b9c14d28bcb89e6348b2b2eebb392226d61531
62 changes: 59 additions & 3 deletions CodenameOne/src/com/codename1/ui/Calendar.java
Original file line number Diff line number Diff line change
@@ -85,6 +85,7 @@ public class Calendar extends Container {
static final long WEEK = DAY * 7;
private EventDispatcher dispatcher = new EventDispatcher();
private EventDispatcher dataChangedListeners = new EventDispatcher();
private EventDispatcher monthChangedListeners = new EventDispatcher();
private long[] dates = new long[42];
private boolean changesSelectedDateEnabled = true;
private TimeZone tmz;
@@ -120,14 +121,38 @@ public Calendar() {
* @param tmz a reference timezone
*/
public Calendar(long time, TimeZone tmz) {
this(time, java.util.TimeZone.getDefault(), null, null);
}

/**
* Constructs a calendar with the current date and time with left and right
* images set
*
* @param leftArrowImage an image for calendar left arrow
* @param rightArrowImage an image for calendar right arrow
*/
public Calendar(Image leftArrowImage, Image rightArrowImage) {
this(System.currentTimeMillis(), java.util.TimeZone.getDefault(), leftArrowImage, rightArrowImage);
}

/**
* Creates a new instance of Calendar set to the given date based on time
* since epoch (the java.util.Date convention)
*
* @param time time since epoch
* @param tmz a reference timezone
* @param leftArrowImage an image for calendar left arrow
* @param rightArrowImage an image for calendar right arrow
*/
public Calendar(long time, TimeZone tmz, Image leftArrowImage, Image rightArrowImage) {
super(new BorderLayout());
this.tmz = tmz;
setUIID("Calendar");
mv = new MonthView(time);

Image leftArrow = UIManager.getInstance().getThemeImageConstant("calendarLeftImage");
if (leftArrow != null) {
Image rightArrow = UIManager.getInstance().getThemeImageConstant("calendarRightImage");
Image leftArrow = leftArrowImage != null ? leftArrowImage : UIManager.getInstance().getThemeImageConstant("calendarLeftImage");
Image rightArrow = rightArrowImage != null ? rightArrowImage : UIManager.getInstance().getThemeImageConstant("calendarRightImage");
if (leftArrow != null && rightArrow != null) {
final Button left = new Button(leftArrow, "CalendarLeft");
final Button right = new Button(rightArrow, "CalendarRight");
ActionListener progress = new ActionListener() {
@@ -414,6 +439,24 @@ public void removeActionListener(ActionListener l) {
mv.removeActionListener(l);
}

/**
* Fires when a new month is selected
*
* @param l listener to add
*/
public void addMonthChangedListener(ActionListener l) {
mv.addMonthChangedListener(l);
}

/**
* Fires when a new month is selected
*
* @param l listener to remove
*/
public void removeMonthChangedListener(ActionListener l) {
mv.removeMonthChangedListener(l);
}

/**
* Adds an ActionListener to the day buttons. This is different from
* {@code Calendar.addActionListener} and will only fire when an active day
@@ -1105,6 +1148,7 @@ public void setSelectedDay(long selectedDay) {
}

private void setMonth(int year, int month) {
fireMonthChangedEvent();
java.util.Calendar cal = java.util.Calendar.getInstance(tmz);
cal.setTimeZone(TimeZone.getDefault());
cal.set(java.util.Calendar.MONTH, month);
@@ -1148,6 +1192,14 @@ public void removeActionListener(ActionListener l) {
dispatcher.removeListener(l);
}

public void addMonthChangedListener(ActionListener l) {
monthChangedListeners.addListener(l);
}

public void removeMonthChangedListener(ActionListener l) {
monthChangedListeners.removeListener(l);
}

public void addDayActionListener(ActionListener l) {
dayListeners.add(l);
for (Component cmp : components) {
@@ -1186,6 +1238,10 @@ protected void fireActionEvent() {
dispatcher.fireActionEvent(new ActionEvent(Calendar.this, ActionEvent.Type.Calendar));
}

protected void fireMonthChangedEvent() {
monthChangedListeners.fireActionEvent(new ActionEvent(Calendar.this, ActionEvent.Type.Calendar));
}

public void actionPerformed(ActionEvent evt) {
Object src = evt.getSource();
if (src instanceof ComboBox) {
2 changes: 1 addition & 1 deletion CodenameOne/src/com/codename1/ui/TextArea.java
Original file line number Diff line number Diff line change
@@ -301,7 +301,7 @@ public TextArea(String text, int rows, int columns, int constraint){
public TextArea(String text, int maxSize){
this(text,maxSize, 1, 3, ANY);
}

/**
* Creates an area with the given text, this constructor
* will create a single line text area similar to a text field!
Original file line number Diff line number Diff line change
@@ -4827,6 +4827,14 @@ public int getStorageEntrySize(String name) {
return (int)new File(getContext().getFilesDir(), name).length();
}

private String addFile(String s) {
// I explicitly don't create a "proper URL" since code might rely on the fact that the file isn't encoded
if(s != null && s.startsWith("/")) {
return "file:/" + s;
}
return s;
}

/**
* @inheritDoc
*/
@@ -4840,10 +4848,10 @@ public String[] listFilesystemRoots() {
if(storageDirs != null){
String [] roots = new String[storageDirs.length + 1];
System.arraycopy(storageDirs, 0, roots, 0, storageDirs.length);
roots[roots.length - 1] = Environment.getRootDirectory().getAbsolutePath();
roots[roots.length - 1] = addFile(Environment.getRootDirectory().getAbsolutePath());
return roots;
}
return new String[]{Environment.getRootDirectory().getAbsolutePath()};
return new String[]{addFile(Environment.getRootDirectory().getAbsolutePath())};
}

@Override

0 comments on commit e150ae7

Please sign in to comment.