microba-controls Mailing List for Microba controls (Page 2)
Brought to you by:
michaelbaranov
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
(4) |
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(5) |
Dec
(2) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(10) |
Nov
|
Dec
(2) |
2008 |
Jan
|
Feb
(2) |
Mar
|
Apr
(7) |
May
(2) |
Jun
|
Jul
|
Aug
(8) |
Sep
(13) |
Oct
|
Nov
(2) |
Dec
|
2009 |
Jan
|
Feb
|
Mar
|
Apr
(4) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(3) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Michael B. <mic...@gm...> - 2008-08-12 19:05:21
|
OK, I'll fix this for you. If I don't show up by the end of the week please bump it. Michael. > Looks good to me ! I assume that is still a code change for you ( I > don't have a CalendarPanelUI right) |
From: Greg C. <cau...@gm...> - 2008-08-12 18:41:51
|
Looks good to me ! I assume that is still a code change for you ( I don't have a CalendarPanelUI right) On 8/12/08, Michael Baranov <mic...@gm...> wrote: > Greg, > DatePicker is derived from CalendarPane so I don't want DatePicker to > inherit methods that are not related to it from CalendarPane. However, I > see a way -- use UI delegate which are different for DatePicker and > CalendarPane. The code might look something like this: > > CalendarPanelUI ui = (CalendarPanelUI) cPanel.getUI(); > ui.observeMonth(2009, Calendar.MAY); > > What about this? This will take care of your special needs... > Michael. > > Awefully nice of you if you can. I was thinking of a few options on > > CalendarPane > > > > a) setDate(null) change so it does not change the currently selected month > > of course that might affect your community > > > > b) setMonth(int month) which just changes the month and the calendar > > but does not select a date. Perhaps that is a little funky behaviour > > though so how about > > > > c) clearSelection() which clears the selection > > > > but hang on now you have got me thinking c) is probably already > > possible... actually no I just checked - I thought I might be able to > > change the foreground color selection to white to hide it - but it > > looks like the color map cannot be modified at runtime? > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Microba-controls mailing list > Mic...@li... > https://lists.sourceforge.net/lists/listinfo/microba-controls > -- Greg Caulton Principal PatientOS Inc. Cell: (857) 869-0394 Fax: (857) 241-3022 |
From: Michael B. <mic...@gm...> - 2008-08-12 18:33:10
|
Greg, a quick follow-up: The method still might be of value for the DatePicker -- it may forward the request to the dropdown CalendarPane! Michael. |
From: Michael B. <mic...@gm...> - 2008-08-12 18:29:42
|
Greg, DatePicker is derived from CalendarPane so I don't want DatePicker to inherit methods that are not related to it from CalendarPane. However, I see a way -- use UI delegate which are different for DatePicker and CalendarPane. The code might look something like this: CalendarPanelUI ui = (CalendarPanelUI) cPanel.getUI(); ui.observeMonth(2009, Calendar.MAY); What about this? This will take care of your special needs... Michael. > Awefully nice of you if you can. I was thinking of a few options on > CalendarPane > > a) setDate(null) change so it does not change the currently selected month > of course that might affect your community > > b) setMonth(int month) which just changes the month and the calendar > but does not select a date. Perhaps that is a little funky behaviour > though so how about > > c) clearSelection() which clears the selection > > but hang on now you have got me thinking c) is probably already > possible... actually no I just checked - I thought I might be able to > change the foreground color selection to white to hide it - but it > looks like the color map cannot be modified at runtime? |
From: Greg C. <cau...@gm...> - 2008-08-12 18:12:09
|
Awefully nice of you if you can. I was thinking of a few options on CalendarPane a) setDate(null) change so it does not change the currently selected month of course that might affect your community b) setMonth(int month) which just changes the month and the calendar but does not select a date. Perhaps that is a little funky behaviour though so how about c) clearSelection() which clears the selection but hang on now you have got me thinking c) is probably already possible... actually no I just checked - I thought I might be able to change the foreground color selection to white to hide it - but it looks like the color map cannot be modified at runtime? On 8/12/08, Michael Baranov <mic...@gm...> wrote: > Greg, > I'm not sure if it can be easily done. In fact it's a *very* specific > behavior, but I know what you need. > I can try to fix this for you. The question is what API do you think is > right for this? > > Michael. > > Hi I would like to clear the calendar selection (the blue on the > > calendar) without resetting the month. So if you look at this picture > > you can see 3 calendars but only the first calendar should have a date > > selected > > > > http://www.patientos.org/forum_temp/v82highlight.png > > > > But when I set the other calendars dates to null it flips the month > > drop down selection back to the current month instead of sticking with > > the two future months. > > > > Is this possible? I guess if I can choose a month without selecting a > > date would achieve the same goal. > > > > thanks! > > > > Greg > > > > ------------------------------------------------------------------------- > > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > > Build the coolest Linux based applications with Moblin SDK & win great prizes > > Grand prize is a trip for two to an Open Source event anywhere in the world > > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > > _______________________________________________ > > Microba-controls mailing list > > Mic...@li... > > https://lists.sourceforge.net/lists/listinfo/microba-controls > > > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Microba-controls mailing list > Mic...@li... > https://lists.sourceforge.net/lists/listinfo/microba-controls > -- Greg Caulton Principal PatientOS Inc. Cell: (857) 869-0394 Fax: (857) 241-3022 |
From: Michael B. <mic...@gm...> - 2008-08-12 17:45:41
|
Greg, I'm not sure if it can be easily done. In fact it's a *very* specific behavior, but I know what you need. I can try to fix this for you. The question is what API do you think is right for this? Michael. > Hi I would like to clear the calendar selection (the blue on the > calendar) without resetting the month. So if you look at this picture > you can see 3 calendars but only the first calendar should have a date > selected > > http://www.patientos.org/forum_temp/v82highlight.png > > But when I set the other calendars dates to null it flips the month > drop down selection back to the current month instead of sticking with > the two future months. > > Is this possible? I guess if I can choose a month without selecting a > date would achieve the same goal. > > thanks! > > Greg > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Microba-controls mailing list > Mic...@li... > https://lists.sourceforge.net/lists/listinfo/microba-controls > |
From: Greg C. <cau...@gm...> - 2008-08-12 14:01:08
|
Hi I would like to clear the calendar selection (the blue on the calendar) without resetting the month. So if you look at this picture you can see 3 calendars but only the first calendar should have a date selected http://www.patientos.org/forum_temp/v82highlight.png But when I set the other calendars dates to null it flips the month drop down selection back to the current month instead of sticking with the two future months. Is this possible? I guess if I can choose a month without selecting a date would achieve the same goal. thanks! Greg |
From: Michael B. <mic...@gm...> - 2008-05-12 02:52:25
|
Greg, I've seen Microba used with some Asian hieroglyphic alphabets. The problem you describe has nothing to do with UTF8 implementation or Microba. Please make sure that the fonts installed in the system really have the necessary glyphs in them. It looks like they don't -- boxes are displayed. Those boxes are glyphs by themselves and are placed into the unicode (multi-alphabet) fonts as placeholders/stubs. So what font family is used by Microba? The default font family/size is used. It's provided by the L&F. A quick and dirty way to know it is try to create a JLabel and see what Font it gets by default. And no, there is no font override functionality ;-) I just did not care to implement that 'cos no one seems to need it. Cheers, Michael. > Hi, > > I have a user who is attempting to get a chinese version of the > application working but the chinese calendar (CalendarPane) is > displaying square boxes instead of chinese symbols. > > Normally I have to set the font to something with UTF8 support (like > Arial MS) - how do I do that for the calendar - and if that can be > done is there anything else to support Chinese (or Japanese) > calendars? > > thanks! > > Greg > > http://www.patientos.org > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > _______________________________________________ > Microba-controls mailing list > Mic...@li... > https://lists.sourceforge.net/lists/listinfo/microba-controls > |
From: Greg C. <cau...@gm...> - 2008-05-12 02:07:36
|
Hi, I have a user who is attempting to get a chinese version of the application working but the chinese calendar (CalendarPane) is displaying square boxes instead of chinese symbols. Normally I have to set the font to something with UTF8 support (like Arial MS) - how do I do that for the calendar - and if that can be done is there anything else to support Chinese (or Japanese) calendars? thanks! Greg http://www.patientos.org |
From: Michael B. <mic...@gm...> - 2008-04-12 02:44:28
|
Greg, Write it as if it will be used by more people than just you: make things more generic, think of extending your code, follow good naming practices and comment your code well (at least try to). Ideally, I would think of parsing date/time pattern for fields and non-field chars and based on that enhance the edit field with listeners that will enforce the desired editing style. In fact, I have implemented that for SWT edit field as part of my real-word job and it works OK... Feel free to contact me for more tech details. Michael. > No worries, I would happy to contribute - but your controls are beyond > my skill - my coding would not meet most needs :-) > > On 4/11/08, *Michael Baranov* <mic...@gm... > <mailto:mic...@gm...>> wrote: > > Greg, > > No, I don't have any plans for it as of now. Contributions are > welcome... if you manage to implement it I'd be happy to include > that in > Microba. > > Michael. > > > > Hi, > > > > So far I have been using the text formatting to add the time to the > > date. I would love to have a spinner though with the time > and/or make > > it so you can work on just the hour or minute or a single digit > at a time. > > > > Is this in any upcoming of recent release? I can build a separate > > control to modify that same time but I lose some obvious benefits of > > it being a single cohesive control > > > > thanks! > > > > Greg > > > > > ------------------------------------------------------------------------ > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > > Don't miss this year's exciting event. There's still time to > save $100. > > Use priority code J8TL2D2. > > > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Microba-controls mailing list > > Mic...@li... > <mailto:Mic...@li...> > > https://lists.sourceforge.net/lists/listinfo/microba-controls > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save > $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > _______________________________________________ > Microba-controls mailing list > Mic...@li... > <mailto:Mic...@li...> > https://lists.sourceforge.net/lists/listinfo/microba-controls > > > > > -- > Greg Caulton > Principal > PatientOS Inc. > Cell: (857) 869-0394 > Fax: (857) 241-3022 > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > ------------------------------------------------------------------------ > > _______________________________________________ > Microba-controls mailing list > Mic...@li... > https://lists.sourceforge.net/lists/listinfo/microba-controls > |
From: Greg C. <cau...@gm...> - 2008-04-12 01:45:03
|
No worries, I would happy to contribute - but your controls are beyond my skill - my coding would not meet most needs :-) On 4/11/08, Michael Baranov <mic...@gm...> wrote: > > Greg, > > No, I don't have any plans for it as of now. Contributions are > welcome... if you manage to implement it I'd be happy to include that in > Microba. > > Michael. > > > > Hi, > > > > So far I have been using the text formatting to add the time to the > > date. I would love to have a spinner though with the time and/or make > > it so you can work on just the hour or minute or a single digit at a > time. > > > > Is this in any upcoming of recent release? I can build a separate > > control to modify that same time but I lose some obvious benefits of > > it being a single cohesive control > > > > thanks! > > > > Greg > > > > ------------------------------------------------------------------------ > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > > Don't miss this year's exciting event. There's still time to save $100. > > Use priority code J8TL2D2. > > > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Microba-controls mailing list > > Mic...@li... > > https://lists.sourceforge.net/lists/listinfo/microba-controls > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save $100. > Use priority code J8TL2D2. > > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > _______________________________________________ > Microba-controls mailing list > Mic...@li... > https://lists.sourceforge.net/lists/listinfo/microba-controls > -- Greg Caulton Principal PatientOS Inc. Cell: (857) 869-0394 Fax: (857) 241-3022 |
From: Michael B. <mic...@gm...> - 2008-04-11 22:59:44
|
Greg, No, I don't have any plans for it as of now. Contributions are welcome... if you manage to implement it I'd be happy to include that in Microba. Michael. > > Hi, > > So far I have been using the text formatting to add the time to the > date. I would love to have a spinner though with the time and/or make > it so you can work on just the hour or minute or a single digit at a time. > > Is this in any upcoming of recent release? I can build a separate > control to modify that same time but I lose some obvious benefits of > it being a single cohesive control > > thanks! > > Greg > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > ------------------------------------------------------------------------ > > _______________________________________________ > Microba-controls mailing list > Mic...@li... > https://lists.sourceforge.net/lists/listinfo/microba-controls > |
From: Greg C. <cau...@gm...> - 2008-04-11 22:02:16
|
Hi, So far I have been using the text formatting to add the time to the date. I would love to have a spinner though with the time and/or make it so you can work on just the hour or minute or a single digit at a time. Is this in any upcoming of recent release? I can build a separate control to modify that same time but I lose some obvious benefits of it being a single cohesive control thanks! Greg |
From: Greg C. <cau...@gm...> - 2008-04-04 22:43:56
|
Cool that worked. thank you. On 4/4/08, Michael Baranov <mic...@gm...> wrote: > > Hi, > > Yes you can. Implement your own Date format that will do what you want > and apply it to DatePicker. > > Michael. > > > > Hi, > > > > In healthcare when entering dates it is common to use T instead of > > typing mm/dd/yy or whatever formats the date control accepts. > > > > They also use T+1 or T-2 etc to shortcut entering tomorrow or day > > before yesterday. > > > > Is there a method I can override or listener I can add to CalendarPane > > to achieve this equivalent functionality? > > > > thanks! > > > > Greg > > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > _______________________________________________ > Microba-controls mailing list > Mic...@li... > https://lists.sourceforge.net/lists/listinfo/microba-controls > -- Greg Caulton Principal PatientOS Inc. Cell: (857) 869-0394 Fax: (857) 241-3022 |
From: Michael B. <mic...@gm...> - 2008-04-04 22:15:37
|
Hi, Yes you can. Implement your own Date format that will do what you want and apply it to DatePicker. Michael. > > Hi, > > In healthcare when entering dates it is common to use T instead of > typing mm/dd/yy or whatever formats the date control accepts. > > They also use T+1 or T-2 etc to shortcut entering tomorrow or day > before yesterday. > > Is there a method I can override or listener I can add to CalendarPane > to achieve this equivalent functionality? > > thanks! > > Greg |
From: Greg C. <cau...@gm...> - 2008-04-04 21:24:52
|
Hi, In healthcare when entering dates it is common to use T instead of typing mm/dd/yy or whatever formats the date control accepts. They also use T+1 or T-2 etc to shortcut entering tomorrow or day before yesterday. Is there a method I can override or listener I can add to CalendarPane to achieve this equivalent functionality? thanks! Greg |
From: Michael B. <mic...@gm...> - 2008-02-23 13:38:21
|
Greg, As far as I remember, you're wrong ;-) . Possible values classes for the map are either Color/s or String/s. CalendarColors.COLOR_CALENDAR_GRID_SELECTION_BACKGROUND_DISABLED means color of grid selection when disabled, not a command to disable the color somehow. Read towards the end of this FAQ for explanation: http://microba.sourceforge.net/faq.html If still not clear, feel free to ask. Ah, and if you are going to use Microba, could you plz name your project and URL so I can put it onto the list of "who uses Microba". Thanks. Michael. > Hi, > > Great calendar control. > > I found that on some PCs the date selected and the weekday header are > set with a very dark blue (perhaps JGoodies LAF is related, not sure). > > I want experiment with the colors and trying to figure how to do that. > > This does not do anything > > Map<String, Boolean> map = new ConcurrentHashMap<String, Boolean>(); > map.put(CalendarColors.COLOR_CALENDAR_GRID_SELECTION_BACKGROUND_DISABLED, > Boolean.TRUE); > setColorOverrideMap(map); > > Neither does putting into the client properties. > > I seem to be doing something wrong? |
From: Greg C. <cau...@gm...> - 2008-02-23 05:50:17
|
Hi, Great calendar control. I found that on some PCs the date selected and the weekday header are set with a very dark blue (perhaps JGoodies LAF is related, not sure). I want experiment with the colors and trying to figure how to do that. This does not do anything Map<String, Boolean> map = new ConcurrentHashMap<String, Boolean>(); map.put(CalendarColors.COLOR_CALENDAR_GRID_SELECTION_BACKGROUND_DISABLED, Boolean.TRUE); setColorOverrideMap(map); Neither does putting into the client properties. I seem to be doing something wrong? -- Greg Caulton Principal PatientOS Inc. Cell: (857) 869-0394 Fax: (857) 241-3022 |
From: Michael B. <mic...@gm...> - 2007-12-18 15:47:02
|
Hi! I haven't heard about this before! I'm sure it can overlap anything. Maybe it's another bug or a combination? Can you plz give me a snippet to reproduce it? Tanks. Mike Wilson wrote: > I am having a problem using DatePicker which I think is because > DatePicker's popup wants to be completely within its container. If the > DatePicker as added to a JPanel within a larger form and and the JPanel isn't > large enough to contain the popup, hitting DataPicker's button doesn't > seem to do anything. If there a way to get the popup to cover other > containers? > > ----------------------------------- > Mike Wilson, Coedpoeth, Wrexham, North Wales > www.whisperingwind.co.uk > > > > > > __________________________________________________________ > Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com > > > ------------------------------------------------------------------------- > SF.Net email is sponsored by: > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services > for just about anything Open Source. > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > _______________________________________________ > Microba-controls mailing list > Mic...@li... > https://lists.sourceforge.net/lists/listinfo/microba-controls > > -- Michael Baranov |
From: Mike W. <mik...@ya...> - 2007-12-18 14:16:00
|
I am having a problem using DatePicker which I think is because=0A DatePick= er's popup wants to be completely within its container. If the=0A DatePicke= r as added to a JPanel within a larger form and and the JPanel isn't=0A lar= ge enough to contain the popup, hitting DataPicker's button doesn't=0A seem= to do anything. If there a way to get the popup to cover other=0A containe= rs?=0A =0A-----------------------------------=0AMike Wilson, Coedpoeth, Wre= xham, North Wales=0Awww.whisperingwind.co.uk=0A=0A=0A=0A=0A=0A _______= ___________________________________________________=0ASent from Yahoo! Mail= - a smarter inbox http://uk.mail.yahoo.com=0A |
From: Chris M. <ch...@st...> - 2007-10-24 06:57:06
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> <br> Hi Michael,<br> <br> I hope this isn't too much of an oblique comment, but in conjunction with using the NullCapableDateFormatter, it makes sense to not ever use new Date() in the code, but instead replace that statement with null. I have been looking at the mseries code (MDateEntryField) and found that that's what it needed, and I presume your code will be similar.<br> <br> - Chris<br> <br> Michael Baranov wrote: <blockquote cite="mid:471...@gm..." type="cite"> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <tt>Chris,</tt><br> <br> I just have checked the behavior of DatePicker with a quick snippet and I am able to set null date to it programmatically just OK out of the box! Can you please double-check it and send me a quick snippet to illustrate the failure (I'm confused with your description right now)? Here is my snippet to start with:<br> <br> <br> import java.awt.FlowLayout;<br> import java.awt.event.ActionEvent;<br> import java.awt.event.ActionListener;<br> import java.beans.PropertyVetoException;<br> <br> import javax.swing.JButton;<br> import javax.swing.JFrame;<br> <br> import com.michaelbaranov.microba.calendar.DatePicker;<br> <br> public class Snippet {<br> <br> public static void main(String[] args) {<br> JFrame frame = new JFrame();<br> frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);<br> frame.setLayout(new FlowLayout());<br> <br> final DatePicker picker = new DatePicker();<br> picker.addActionListener(new ActionListener() {<br> public void actionPerformed(ActionEvent e) {<br> System.out.println(picker.getDate());<br> }<br> });<br> <br> JButton btn = new JButton("NULL");<br> btn.addActionListener(new ActionListener() {<br> public void actionPerformed(ActionEvent e) {<br> try {<br> picker.setDate(null);<br> } catch (PropertyVetoException e1) {<br> System.out.println("Could not set null date.");<br> e1.printStackTrace();<br> }<br> }<br> });<br> frame.add(picker);<br> frame.add(btn);<br> frame.setSize(640, 480);<br> frame.setVisible(true);<br> }<br> }<br> <br> <br> Cheers!<br> <br> Chris Murphy wrote: <blockquote cite="mid:471...@st..." type="cite"> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <br> Hi Michael,<br> <br> Michael Baranov wrote: <blockquote cite="mid:471...@gm..." type="cite"> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> Chris,<br> <br> Thanks for digging in! <br> One more question before we go on: DateFormat vs. DateFormatter. You're using DateFormatter and even suggest to update the API for it. But what's the purpose? What's the difference? Can't you do the same null/empty check with DateFormat? DateFormat is in the API already.<br> <br> </blockquote> Maybe you can! But then I would have thought Sun's workaround would be on DateFormat if that was the case. To tell you the truth I don't really want to become a DatePicker/JFormattedText/DateFormatter/DateFormat expert right now; I just want to use it.<br> <blockquote cite="mid:471...@gm..." type="cite">About the deep-buried UI: it was the initial idea to hide the implementation, the fact that DatePicker is really composed of a text edit and a button. Maybe it's a good idea to expose the parts from their UI delegates and make them accessible like this:<br> ( (DatePickerUI)picker.getUI() ).getButton()<br> // etc...<br> Is this what you mean?<br> </blockquote> Yes. You could do worse than take a look at the source of <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://web.ukonline.co.uk/mseries/">http://web.ukonline.co.uk/mseries/</a> and borrow some of the good ideas there from there - if there are any. I've never created a composite component with its own UI.<br> <blockquote cite="mid:471...@gm..." type="cite"><br> Chris, please get the latest sources from sourceforge. If you can't make a patch for me, plz send me back the modified sources.<br> </blockquote> I'm pretty sure I got the latest source. Am attaching the source file I'm using currently. <br> <br> I have it on my list of things to do to compare MDateEntryField with DatePicker a bit more. Things I will look at are focusing and validation and also how well they work when they are XMLEncoded. Will get back to you then ...<br> <br> - Chris<br> <blockquote cite="mid:471...@gm..." type="cite"><br> Cheers!<br> Michael.<br> <blockquote cite="mid:471...@st..." type="cite"> <pre wrap="">Hi Michael, Send me your latest source file for BasicDatePickerUI and I'll do a patch if you like (have never done such a thing before); however all that needs to be done is to use this new inner class NullCapableDateFormatter instead of DateFormatter as your code has it. I have since made the new inner class private and static as well - but haven't really tested it. Apart from that all the necessary code is as sent. Alternatively you could change the code so that API users can put in their own DateFormatter. One small problem with this I see is that your UIs seem to be hard to get to - there is no reference to them from the controller as I would expect. I have had to code this method: public static Component getDisplay( DatePicker dp) { Component result; Component components[] = dp.getComponents(); //Print.prArray( components, "Which one is a text field?"); //A: //value: null, class: com.michaelbaranov.microba.calendar.ui.basic.BasicDatePickerUI$MyJFormattedTextField //value: null, class: javax.swing.JButton result = components[0]; return result; } Is there a better way? I experienced the problem when programmatically setting the date to null. What would happen was that a null wouldn't get through the commitEdit() validation (which presumably happened at the time of a focus change), and the last successfully committed value would come back to being the actual value. This was a difficult thing to track down, and indeed also exists on MDateEntryField, and was the reason that I came to your Component - hoping it would allow null date values. - Chris Murphy (<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="http://www.strandz.org">www.strandz.org</a>) Michael Baranov wrote: </pre> <blockquote type="cite"> <pre wrap="">Chris, Thanks for the path! But can you describe the effect of the change from the point of view of a user? What was wrong (but now OK)? Can you please send me a regular machine-processable patch for BasicDatePicketUI against the latest sources (so I ca patch a local copy free of mistakes)? Thanks for using Microba and contributing! Chris Murphy wrote: </pre> <blockquote type="cite"> <pre wrap="">Hi Michael, I found something for your consideration, which has required changing the microba source as configuration was not possible. The problem is that JFormattedTextField does not properly support the concept of a null date. A null date can't be committed (commitEdit()) to a JFormattedTextField. As you can see from the code Sun's bug database offers a workaround that I've implemented on your code. This code is from changes I've made to BasicDatePickerUI: private DefaultFormatterFactory createFormatterFactory() { return new DefaultFormatterFactory(new NullCapableDateFormatter(peer .getDateFormat())); } /** * To do this enhancement: * <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4745048">http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4745048</a> */ public class NullCapableDateFormatter extends DateFormatter { public NullCapableDateFormatter(DateFormat dateFormat) { super( dateFormat); } public Object stringToValue(String string) throws ParseException { if(string == null || string.length() == 0) { return null; } return super.stringToValue(string); } } thanks - Chris ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://get.splunk.com/">http://get.splunk.com/</a> _______________________________________________ Microba-controls mailing list <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:Mic...@li...">Mic...@li...</a> <a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/microba-controls">https://lists.sourceforge.net/lists/listinfo/microba-controls</a> </pre> </blockquote> </blockquote> <pre wrap=""><!----> ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://get.splunk.com/">http://get.splunk.com/</a> _______________________________________________ Microba-controls mailing list <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:Mic...@li...">Mic...@li...</a> <a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/microba-controls">https://lists.sourceforge.net/lists/listinfo/microba-controls</a> </pre> </blockquote> </blockquote> </blockquote> <br> <pre class="moz-signature" cols="42">-- Michael Baranov </pre> </blockquote> </body> </html> |
From: Chris M. <ch...@st...> - 2007-10-20 21:01:30
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title></title> </head> <body bgcolor="#ffffff" text="#000000"> <br> For the change to not be backed out as soon as you focus away from the JFormattedTextField, you need to not only set the value to null, but also commitEdit() on it. The unit test I was using is quite Strandz (<a class="moz-txt-link-abbreviated" href="http://www.strandz.org">www.strandz.org</a>) orientated. If I was going to write a simple unit test to prove this behaviour I would:<br> <br> 1./ set JFormattedTextField to a valid value<br> 2./ commitEdit that value<br> 3./ set to null as you have done below<br> 4./ focus on another field<br> 5./ notice that the JFormattedTextField's value has gone back to the value set at 1<br> <br> - Chris <br> <br> Michael Baranov wrote: <blockquote cite="mid:471...@gm..." type="cite"> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <tt>Chris,</tt><br> <br> I just have checked the behavior of DatePicker with a quick snippet and I am able to set null date to it programmatically just OK out of the box! Can you please double-check it and send me a quick snippet to illustrate the failure (I'm confused with your description right now)? Here is my snippet to start with:<br> <br> <br> import java.awt.FlowLayout;<br> import java.awt.event.ActionEvent;<br> import java.awt.event.ActionListener;<br> import java.beans.PropertyVetoException;<br> <br> import javax.swing.JButton;<br> import javax.swing.JFrame;<br> <br> import com.michaelbaranov.microba.calendar.DatePicker;<br> <br> public class Snippet {<br> <br> public static void main(String[] args) {<br> JFrame frame = new JFrame();<br> frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);<br> frame.setLayout(new FlowLayout());<br> <br> final DatePicker picker = new DatePicker();<br> picker.addActionListener(new ActionListener() {<br> public void actionPerformed(ActionEvent e) {<br> System.out.println(picker.getDate());<br> }<br> });<br> <br> JButton btn = new JButton("NULL");<br> btn.addActionListener(new ActionListener() {<br> public void actionPerformed(ActionEvent e) {<br> try {<br> picker.setDate(null);<br> } catch (PropertyVetoException e1) {<br> System.out.println("Could not set null date.");<br> e1.printStackTrace();<br> }<br> }<br> });<br> frame.add(picker);<br> frame.add(btn);<br> frame.setSize(640, 480);<br> frame.setVisible(true);<br> }<br> }<br> <br> <br> Cheers!<br> <br> Chris Murphy wrote: <blockquote cite="mid:471...@st..." type="cite"> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <br> Hi Michael,<br> <br> Michael Baranov wrote: <blockquote cite="mid:471...@gm..." type="cite"> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> Chris,<br> <br> Thanks for digging in! <br> One more question before we go on: DateFormat vs. DateFormatter. You're using DateFormatter and even suggest to update the API for it. But what's the purpose? What's the difference? Can't you do the same null/empty check with DateFormat? DateFormat is in the API already.<br> <br> </blockquote> Maybe you can! But then I would have thought Sun's workaround would be on DateFormat if that was the case. To tell you the truth I don't really want to become a DatePicker/JFormattedText/DateFormatter/DateFormat expert right now; I just want to use it.<br> <blockquote cite="mid:471...@gm..." type="cite">About the deep-buried UI: it was the initial idea to hide the implementation, the fact that DatePicker is really composed of a text edit and a button. Maybe it's a good idea to expose the parts from their UI delegates and make them accessible like this:<br> ( (DatePickerUI)picker.getUI() ).getButton()<br> // etc...<br> Is this what you mean?<br> </blockquote> Yes. You could do worse than take a look at the source of <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://web.ukonline.co.uk/mseries/">http://web.ukonline.co.uk/mseries/</a> and borrow some of the good ideas there from there - if there are any. I've never created a composite component with its own UI.<br> <blockquote cite="mid:471...@gm..." type="cite"><br> Chris, please get the latest sources from sourceforge. If you can't make a patch for me, plz send me back the modified sources.<br> </blockquote> I'm pretty sure I got the latest source. Am attaching the source file I'm using currently. <br> <br> I have it on my list of things to do to compare MDateEntryField with DatePicker a bit more. Things I will look at are focusing and validation and also how well they work when they are XMLEncoded. Will get back to you then ...<br> <br> - Chris<br> <blockquote cite="mid:471...@gm..." type="cite"><br> Cheers!<br> Michael.<br> <blockquote cite="mid:471...@st..." type="cite"> <pre wrap="">Hi Michael, Send me your latest source file for BasicDatePickerUI and I'll do a patch if you like (have never done such a thing before); however all that needs to be done is to use this new inner class NullCapableDateFormatter instead of DateFormatter as your code has it. I have since made the new inner class private and static as well - but haven't really tested it. Apart from that all the necessary code is as sent. Alternatively you could change the code so that API users can put in their own DateFormatter. One small problem with this I see is that your UIs seem to be hard to get to - there is no reference to them from the controller as I would expect. I have had to code this method: public static Component getDisplay( DatePicker dp) { Component result; Component components[] = dp.getComponents(); //Print.prArray( components, "Which one is a text field?"); //A: //value: null, class: com.michaelbaranov.microba.calendar.ui.basic.BasicDatePickerUI$MyJFormattedTextField //value: null, class: javax.swing.JButton result = components[0]; return result; } Is there a better way? I experienced the problem when programmatically setting the date to null. What would happen was that a null wouldn't get through the commitEdit() validation (which presumably happened at the time of a focus change), and the last successfully committed value would come back to being the actual value. This was a difficult thing to track down, and indeed also exists on MDateEntryField, and was the reason that I came to your Component - hoping it would allow null date values. - Chris Murphy (<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="http://www.strandz.org">www.strandz.org</a>) Michael Baranov wrote: </pre> <blockquote type="cite"> <pre wrap="">Chris, Thanks for the path! But can you describe the effect of the change from the point of view of a user? What was wrong (but now OK)? Can you please send me a regular machine-processable patch for BasicDatePicketUI against the latest sources (so I ca patch a local copy free of mistakes)? Thanks for using Microba and contributing! Chris Murphy wrote: </pre> <blockquote type="cite"> <pre wrap="">Hi Michael, I found something for your consideration, which has required changing the microba source as configuration was not possible. The problem is that JFormattedTextField does not properly support the concept of a null date. A null date can't be committed (commitEdit()) to a JFormattedTextField. As you can see from the code Sun's bug database offers a workaround that I've implemented on your code. This code is from changes I've made to BasicDatePickerUI: private DefaultFormatterFactory createFormatterFactory() { return new DefaultFormatterFactory(new NullCapableDateFormatter(peer .getDateFormat())); } /** * To do this enhancement: * <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4745048">http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4745048</a> */ public class NullCapableDateFormatter extends DateFormatter { public NullCapableDateFormatter(DateFormat dateFormat) { super( dateFormat); } public Object stringToValue(String string) throws ParseException { if(string == null || string.length() == 0) { return null; } return super.stringToValue(string); } } thanks - Chris ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://get.splunk.com/">http://get.splunk.com/</a> _______________________________________________ Microba-controls mailing list <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:Mic...@li...">Mic...@li...</a> <a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/microba-controls">https://lists.sourceforge.net/lists/listinfo/microba-controls</a> </pre> </blockquote> </blockquote> <pre wrap=""><!----> ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://get.splunk.com/">http://get.splunk.com/</a> _______________________________________________ Microba-controls mailing list <a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:Mic...@li...">Mic...@li...</a> <a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/microba-controls">https://lists.sourceforge.net/lists/listinfo/microba-controls</a> </pre> </blockquote> </blockquote> </blockquote> <br> <pre class="moz-signature" cols="42">-- Michael Baranov </pre> </blockquote> </body> </html> |
From: Michael B. <mic...@gm...> - 2007-10-20 07:22:38
|
Chris, I just have checked the behavior of DatePicker with a quick snippet and I am able to set null date to it programmatically just OK out of the box! Can you please double-check it and send me a quick snippet to illustrate the failure (I'm confused with your description right now)? Here is my snippet to start with: import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyVetoException; import javax.swing.JButton; import javax.swing.JFrame; import com.michaelbaranov.microba.calendar.DatePicker; public class Snippet { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLayout(new FlowLayout()); final DatePicker picker = new DatePicker(); picker.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(picker.getDate()); } }); JButton btn = new JButton("NULL"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { picker.setDate(null); } catch (PropertyVetoException e1) { System.out.println("Could not set null date."); e1.printStackTrace(); } } }); frame.add(picker); frame.add(btn); frame.setSize(640, 480); frame.setVisible(true); } } Cheers! Chris Murphy wrote: > > Hi Michael, > > Michael Baranov wrote: >> Chris, >> >> Thanks for digging in! >> One more question before we go on: DateFormat vs. DateFormatter. >> You're using DateFormatter and even suggest to update the API for it. >> But what's the purpose? What's the difference? Can't you do the same >> null/empty check with DateFormat? DateFormat is in the API already. >> > Maybe you can! But then I would have thought Sun's workaround would be > on DateFormat if that was the case. To tell you the truth I don't > really want to become a > DatePicker/JFormattedText/DateFormatter/DateFormat expert right now; I > just want to use it. >> About the deep-buried UI: it was the initial idea to hide the >> implementation, the fact that DatePicker is really composed of a text >> edit and a button. Maybe it's a good idea to expose the parts from >> their UI delegates and make them accessible like this: >> ( (DatePickerUI)picker.getUI() ).getButton() >> // etc... >> Is this what you mean? > Yes. You could do worse than take a look at the source of > http://web.ukonline.co.uk/mseries/ and borrow some of the good ideas > there from there - if there are any. I've never created a composite > component with its own UI. >> >> Chris, please get the latest sources from sourceforge. If you can't >> make a patch for me, plz send me back the modified sources. > I'm pretty sure I got the latest source. Am attaching the source file > I'm using currently. > > I have it on my list of things to do to compare MDateEntryField with > DatePicker a bit more. Things I will look at are focusing and > validation and also how well they work when they are XMLEncoded. Will > get back to you then ... > > - Chris >> >> Cheers! >> Michael. >>> Hi Michael, >>> >>> Send me your latest source file for BasicDatePickerUI and I'll do a >>> patch if you like (have never done such a thing before); however all >>> that needs to be done is to use this new inner class >>> NullCapableDateFormatter instead of DateFormatter as your code has it. I >>> have since made the new inner class private and static as well - but >>> haven't really tested it. Apart from that all the necessary code is as >>> sent. Alternatively you could change the code so that API users can put >>> in their own DateFormatter. One small problem with this I see is that >>> your UIs seem to be hard to get to - there is no reference to them from >>> the controller as I would expect. I have had to code this method: >>> >>> public static Component getDisplay( DatePicker dp) >>> >>> { >>> >>> Component result; >>> >>> Component components[] = dp.getComponents(); >>> >>> //Print.prArray( components, "Which one is a text field?"); >>> >>> //A: >>> >>> //value: null, class: com.michaelbaranov.microba.calendar.ui.basic.BasicDatePickerUI$MyJFormattedTextField >>> >>> //value: null, class: javax.swing.JButton >>> >>> result = components[0]; >>> >>> return result; >>> >>> } >>> >>> Is there a better way? >>> >>> I experienced the problem when programmatically setting the date to >>> null. What would happen was that a null wouldn't get through the >>> commitEdit() validation (which presumably happened at the time of a >>> focus change), and the last successfully committed value would come back >>> to being the actual value. This was a difficult thing to track down, and >>> indeed also exists on MDateEntryField, and was the reason that I came to >>> your Component - hoping it would allow null date values. >>> >>> - Chris Murphy (www.strandz.org) >>> >>> Michael Baranov wrote: >>> >>>> Chris, >>>> >>>> Thanks for the path! But can you describe the effect of the change >>>> from the point of view of a user? What was wrong (but now OK)? Can you >>>> please send me a regular machine-processable patch for >>>> BasicDatePicketUI against the latest sources (so I ca patch a local >>>> copy free of mistakes)? >>>> >>>> Thanks for using Microba and contributing! >>>> >>>> Chris Murphy wrote: >>>> >>>>> Hi Michael, >>>>> >>>>> I found something for your consideration, which has required changing >>>>> the microba source as configuration was not possible. The problem is >>>>> that JFormattedTextField does not properly support the concept of a >>>>> null date. A null date can't be committed (commitEdit()) to a >>>>> JFormattedTextField. As you can see from the code Sun's bug database >>>>> offers a workaround that I've implemented on your code. This code is >>>>> from changes I've made to BasicDatePickerUI: >>>>> >>>>> private DefaultFormatterFactory createFormatterFactory() { >>>>> return new DefaultFormatterFactory(new >>>>> NullCapableDateFormatter(peer >>>>> .getDateFormat())); >>>>> } >>>>> >>>>> >>>>> /** >>>>> * To do this enhancement: >>>>> * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4745048 >>>>> */ >>>>> public class NullCapableDateFormatter extends DateFormatter >>>>> { >>>>> public NullCapableDateFormatter(DateFormat dateFormat) >>>>> { >>>>> super( dateFormat); >>>>> } >>>>> >>>>> public Object stringToValue(String string) >>>>> throws ParseException >>>>> { >>>>> if(string == null || string.length() == 0) >>>>> { >>>>> return null; >>>>> } >>>>> return super.stringToValue(string); >>>>> } >>>>> } >>>>> >>>>> >>>>> thanks - Chris >>>>> >>>>> ------------------------------------------------------------------------- >>>>> >>>>> This SF.net email is sponsored by: Splunk Inc. >>>>> Still grepping through log files to find problems? Stop. >>>>> Now Search log events and configuration files using AJAX and a browser. >>>>> Download your FREE copy of Splunk now >> http://get.splunk.com/ >>>>> _______________________________________________ >>>>> Microba-controls mailing list >>>>> Mic...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/microba-controls >>>>> >>>>> >>>>> >>> >>> ------------------------------------------------------------------------- >>> This SF.net email is sponsored by: Splunk Inc. >>> Still grepping through log files to find problems? Stop. >>> Now Search log events and configuration files using AJAX and a browser. >>> Download your FREE copy of Splunk now >> http://get.splunk.com/ >>> _______________________________________________ >>> Microba-controls mailing list >>> Mic...@li... >>> https://lists.sourceforge.net/lists/listinfo/microba-controls >>> >>> -- Michael Baranov |
From: Chris M. <ch...@st...> - 2007-10-19 18:45:58
|
package com.michaelbaranov.microba.calendar.ui.basic; import com.michaelbaranov.microba.calendar.CalendarPane; import com.michaelbaranov.microba.calendar.CalendarResources; import com.michaelbaranov.microba.calendar.DatePicker; import com.michaelbaranov.microba.calendar.HolidayPolicy; import com.michaelbaranov.microba.calendar.VetoPolicy; import com.michaelbaranov.microba.calendar.resource.Resource; import com.michaelbaranov.microba.calendar.ui.DatePickerUI; import com.michaelbaranov.microba.common.CommitEvent; import com.michaelbaranov.microba.common.CommitListener; import javax.swing.AbstractAction; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.InputMap; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFormattedTextField; import javax.swing.JFormattedTextField.AbstractFormatter; import javax.swing.JPopupMenu; import javax.swing.JTextField; import javax.swing.KeyStroke; import javax.swing.plaf.ComponentUI; import javax.swing.text.DateFormatter; import javax.swing.text.DefaultFormatterFactory; import java.awt.BorderLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; import java.text.DateFormat; import java.text.ParseException; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class BasicDatePickerUI extends DatePickerUI implements PropertyChangeListener { protected static final String POPUP_KEY = "##BasicVetoDatePickerUI.popup##"; protected DatePicker peer; protected CalendarPane calendarPane; protected JButton button; protected JPopupMenu popup; protected MyJFormattedTextField field; protected ComponentListener componentListener; public static class MyJFormattedTextField extends JFormattedTextField { public MyJFormattedTextField(AbstractFormatterFactory factory) { super(factory); } } public static ComponentUI createUI(JComponent c) { return new BasicDatePickerUI(); } public void installUI(JComponent c) { peer = (DatePicker) c; installComponents(); istallListeners(); installKeyboardActions(); } public void uninstallUI(JComponent c) { uninstallKeyboardActions(); uninstallListeners(); uninstallComponents(); peer = null; } protected void installKeyboardActions() { InputMap input = peer .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); input.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK), POPUP_KEY); input.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), POPUP_KEY); peer.getActionMap().put(POPUP_KEY, new AbstractAction() { public void actionPerformed(ActionEvent e) { showPopup(true); } }); } protected void uninstallKeyboardActions() { InputMap input = peer .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); input .remove(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK)); input.remove(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0)); peer.getActionMap().remove(POPUP_KEY); } protected void istallListeners() { peer.addPropertyChangeListener(this); } protected void uninstallListeners() { peer.removePropertyChangeListener(this); } protected void uninstallComponents() { button.removeActionListener(componentListener); field.removePropertyChangeListener(componentListener); calendarPane.removePropertyChangeListener(componentListener); calendarPane.removeCommitListener(componentListener); calendarPane.removeActionListener(componentListener); peer.remove(field); peer.remove(button); popup = null; calendarPane = null; button = null; field = null; } protected void installComponents() { field = new MyJFormattedTextField(createFormatterFactory()); field.setValue(peer.getDate()); field.setFocusLostBehavior(peer.getFocusLostBehavior()); field.setEditable(peer.isFieldEditable()); field.setToolTipText(peer.getToolTipText()); // button button = new JButton(); button.setFocusable(false); button.setMargin(new Insets(0, 0, 0, 0)); button.setToolTipText(peer.getToolTipText()); setSimpeLook(false); // calendar calendarPane = new CalendarPane(peer.getStyle()); calendarPane.setShowTodayButton(peer.isShowTodayButton()); calendarPane.setFocusLostBehavior(JFormattedTextField.REVERT); calendarPane.setFocusCycleRoot(true); calendarPane.setBorder(BorderFactory.createEmptyBorder(1, 3, 0, 3)); calendarPane.setStripTime(false); calendarPane.setLocale(peer.getLocale()); calendarPane.setZone(peer.getZone()); calendarPane.setFocusable(peer.isDropdownFocusable()); calendarPane.setColorOverrideMap(peer.getColorOverrideMap()); // popup popup = new JPopupMenu(); popup.setLayout(new BorderLayout()); popup.add(calendarPane, BorderLayout.CENTER); popup.setLightWeightPopupEnabled(true); // add peer.setLayout(new BorderLayout()); switch (peer.getPickerStyle()) { case DatePicker.PICKER_STYLE_FIELD_AND_BUTTON: peer.add(field, BorderLayout.CENTER); peer.add(button, BorderLayout.EAST); break; case DatePicker.PICKER_STYLE_BUTTON: peer.add(button, BorderLayout.EAST); break; } peer.revalidate(); peer.repaint(); componentListener = new ComponentListener(); button.addActionListener(componentListener); field.addPropertyChangeListener(componentListener); calendarPane.addPropertyChangeListener(componentListener); calendarPane.addCommitListener(componentListener); calendarPane.addActionListener(componentListener); peerDateChanged(peer.getDate()); } public void setSimpeLook(boolean b) { if (b) { field.setBorder(BorderFactory.createEmptyBorder()); button.setText("..."); button.setIcon(null); } else { field.setBorder(new JTextField().getBorder()); button.setText(""); button.setIcon(new ImageIcon(Resource.class .getResource("picker-16.png"))); } } public void showPopup(boolean visible) { if (visible) { // try to apply date to calendar pane popup, but not cause commit if (peer.isKeepTime()) try { AbstractFormatter formatter = field.getFormatter(); Date value = (Date) formatter .stringToValue(field.getText()); calendarPane .removePropertyChangeListener(componentListener); calendarPane.setDate(value); calendarPane.addPropertyChangeListener(componentListener); } catch (ParseException e) { // ignore } catch (PropertyVetoException e) { // can not happen } popup.show(peer, 0, peer.getHeight()); calendarPane.requestFocus(false); } else { popup.setVisible(false); } } public void propertyChange(PropertyChangeEvent evt) { if (JComponent.TOOL_TIP_TEXT_KEY.equals(evt.getPropertyName())) { field.setToolTipText((String) evt.getNewValue()); button.setToolTipText((String) evt.getNewValue()); } else if (evt.getPropertyName().equals(DatePicker.PROPERTY_NAME_DATE)) { Date newValue = (Date) evt.getNewValue(); peerDateChanged(newValue); } else if (evt.getPropertyName().equals( DatePicker.PROPERTY_NAME_FIELD_EDITABLE)) { field.setEditable(peer.isFieldEditable()); } else if (evt.getPropertyName().equals( DatePicker.PROPERTY_NAME_FOCUS_LOST_BEHAVIOR)) { field.setFocusLostBehavior(peer.getFocusLostBehavior()); } else if (evt.getPropertyName() .equals(DatePicker.PROPERTY_NAME_LOCALE)) { field.setFormatterFactory(createFormatterFactory()); calendarPane.setLocale(peer.getLocale()); } else if (evt.getPropertyName().equals( DatePicker.PROPERTY_NAME_DATE_FORMAT)) { field.setFormatterFactory(createFormatterFactory()); } else if (evt.getPropertyName().equals(DatePicker.PROPERTY_NAME_ZONE)) { field.setFormatterFactory(createFormatterFactory()); calendarPane.setZone((TimeZone) evt.getNewValue()); } else if (evt.getPropertyName().equals( DatePicker.PROPERTY_NAME_SHOW_TODAY_BTN)) { boolean value = ((Boolean) evt.getNewValue()).booleanValue(); calendarPane.setShowTodayButton(value); } else if (evt.getPropertyName().equals( DatePicker.PROPERTY_NAME_SHOW_NONE_BTN)) { boolean value = ((Boolean) evt.getNewValue()).booleanValue(); calendarPane.setShowNoneButton(value); } else if (evt.getPropertyName().equals( DatePicker.PROPERTY_NAME_SHOW_NUMBER_WEEK)) { boolean value = ((Boolean) evt.getNewValue()).booleanValue(); calendarPane.setShowNumberOfWeek(value); } else if (evt.getPropertyName().equals(DatePicker.PROPERTY_NAME_STYLE)) { int value = ((Integer) evt.getNewValue()).intValue(); calendarPane.setStyle(value); } else if (evt.getPropertyName().equals( DatePicker.PROPERTY_NAME_VETO_POLICY)) { calendarPane.setVetoPolicy((VetoPolicy) evt.getNewValue()); } else if (evt.getPropertyName().equals( DatePicker.PROPERTY_NAME_HOLIDAY_POLICY)) { calendarPane.setHolidayPolicy((HolidayPolicy) evt.getNewValue()); } else if (evt.getPropertyName().equals("focusable")) { boolean value = ((Boolean) evt.getNewValue()).booleanValue(); field.setFocusable(value); } else if (evt.getPropertyName().equals( DatePicker.PROPERTY_NAME_RESOURCES)) { CalendarResources resources = (CalendarResources) evt.getNewValue(); calendarPane.setResources(resources); } else if (evt.getPropertyName() .equals("enabled"/* DatePicker.PROPERTY_NAME_ENABLED */)) { boolean value = ((Boolean) evt.getNewValue()).booleanValue(); field.setEnabled(value); button.setEnabled(value); } else if (evt.getPropertyName().equals( DatePicker.PROPERTY_NAME_PICKER_STYLE)) { peer.updateUI(); } else if (evt.getPropertyName().equals( DatePicker.PROPERTY_NAME_DROPDOWN_FOCUSABLE)) { calendarPane.setFocusable(peer.isDropdownFocusable()); } } private void peerDateChanged(Date newValue) { try { calendarPane.removePropertyChangeListener(componentListener); calendarPane.setDate(newValue); calendarPane.addPropertyChangeListener(componentListener); } catch (PropertyVetoException e) { // Ignore. CalendarPane has no VetoModel here. } field.removePropertyChangeListener(componentListener); field.setValue(newValue); field.addPropertyChangeListener(componentListener); } private DefaultFormatterFactory createFormatterFactory() { return new DefaultFormatterFactory(new NullCapableDateFormatter(peer .getDateFormat())); } /** * To do this enhancement: * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4745048 */ private static class NullCapableDateFormatter extends DateFormatter { public NullCapableDateFormatter(DateFormat dateFormat) { super( dateFormat); } public Object stringToValue(String string) throws ParseException { if(string == null || string.length() == 0) { return null; } return super.stringToValue(string); } } protected class ComponentListener implements ActionListener, PropertyChangeListener, CommitListener { public void actionPerformed(ActionEvent e) { if (e.getSource() != calendarPane) showPopup(true); else showPopup(false); } public void propertyChange(PropertyChangeEvent evt) { if (evt.getSource() == calendarPane) { if (CalendarPane.PROPERTY_NAME_DATE.equals(evt .getPropertyName())) { showPopup(false); Date fieldValue = null; try { AbstractFormatter formatter = field.getFormatter(); fieldValue = (Date) formatter.stringToValue(field .getText()); } catch (ParseException e) { fieldValue = (Date) field.getValue(); } if (fieldValue != null || evt.getNewValue() != null) { if (peer.isKeepTime() && fieldValue != null && evt.getNewValue() != null) { Calendar fieldCal = Calendar.getInstance(peer .getZone(), peer.getLocale()); fieldCal.setTime(fieldValue); Calendar valueCal = Calendar.getInstance(peer .getZone(), peer.getLocale()); valueCal.setTime((Date) evt.getNewValue()); // era fieldCal.set(Calendar.ERA, valueCal .get(Calendar.ERA)); // year fieldCal.set(Calendar.YEAR, valueCal .get(Calendar.YEAR)); // month fieldCal.set(Calendar.MONTH, valueCal .get(Calendar.MONTH)); // date fieldCal.set(Calendar.DAY_OF_MONTH, valueCal .get(Calendar.DAY_OF_MONTH)); field.setValue(fieldCal.getTime()); } else field.setValue((Date) evt.getNewValue()); } } } if (evt.getSource() == field) { if ("value".equals(evt.getPropertyName())) { Date value = (Date) field.getValue(); try { peer.setDate(value); } catch (PropertyVetoException e) { field.setValue(peer.getDate()); } } } } public void commit(CommitEvent action) { showPopup(false); if (field.getValue() != null || calendarPane.getDate() != null) field.setValue(calendarPane.getDate()); } public void revert(CommitEvent action) { showPopup(false); } } public void commit() throws PropertyVetoException, ParseException { field.commitEdit(); } public void revert() { peerDateChanged(peer.getDate()); } } |
From: Michael B. <mic...@gm...> - 2007-10-19 10:50:30
|
Chris, Thanks for digging in! One more question before we go on: DateFormat vs. DateFormatter. You're using DateFormatter and even suggest to update the API for it. But what's the purpose? What's the difference? Can't you do the same null/empty check with DateFormat? DateFormat is in the API already. About the deep-buried UI: it was the initial idea to hide the implementation, the fact that DatePicker is really composed of a text edit and a button. Maybe it's a good idea to expose the parts from their UI delegates and make them accessible like this: ( (DatePickerUI)picker.getUI() ).getButton() // etc... Is this what you mean? Chris, please get the latest sources from sourceforge. If you can't make a patch for me, plz send me back the modified sources. Cheers! Michael. > Hi Michael, > > Send me your latest source file for BasicDatePickerUI and I'll do a > patch if you like (have never done such a thing before); however all > that needs to be done is to use this new inner class > NullCapableDateFormatter instead of DateFormatter as your code has it. I > have since made the new inner class private and static as well - but > haven't really tested it. Apart from that all the necessary code is as > sent. Alternatively you could change the code so that API users can put > in their own DateFormatter. One small problem with this I see is that > your UIs seem to be hard to get to - there is no reference to them from > the controller as I would expect. I have had to code this method: > > public static Component getDisplay( DatePicker dp) > > { > > Component result; > > Component components[] = dp.getComponents(); > > //Print.prArray( components, "Which one is a text field?"); > > //A: > > //value: null, class: com.michaelbaranov.microba.calendar.ui.basic.BasicDatePickerUI$MyJFormattedTextField > > //value: null, class: javax.swing.JButton > > result = components[0]; > > return result; > > } > > Is there a better way? > > I experienced the problem when programmatically setting the date to > null. What would happen was that a null wouldn't get through the > commitEdit() validation (which presumably happened at the time of a > focus change), and the last successfully committed value would come back > to being the actual value. This was a difficult thing to track down, and > indeed also exists on MDateEntryField, and was the reason that I came to > your Component - hoping it would allow null date values. > > - Chris Murphy (www.strandz.org) > > Michael Baranov wrote: > >> Chris, >> >> Thanks for the path! But can you describe the effect of the change >> from the point of view of a user? What was wrong (but now OK)? Can you >> please send me a regular machine-processable patch for >> BasicDatePicketUI against the latest sources (so I ca patch a local >> copy free of mistakes)? >> >> Thanks for using Microba and contributing! >> >> Chris Murphy wrote: >> >>> Hi Michael, >>> >>> I found something for your consideration, which has required changing >>> the microba source as configuration was not possible. The problem is >>> that JFormattedTextField does not properly support the concept of a >>> null date. A null date can't be committed (commitEdit()) to a >>> JFormattedTextField. As you can see from the code Sun's bug database >>> offers a workaround that I've implemented on your code. This code is >>> from changes I've made to BasicDatePickerUI: >>> >>> private DefaultFormatterFactory createFormatterFactory() { >>> return new DefaultFormatterFactory(new >>> NullCapableDateFormatter(peer >>> .getDateFormat())); >>> } >>> >>> >>> /** >>> * To do this enhancement: >>> * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4745048 >>> */ >>> public class NullCapableDateFormatter extends DateFormatter >>> { >>> public NullCapableDateFormatter(DateFormat dateFormat) >>> { >>> super( dateFormat); >>> } >>> >>> public Object stringToValue(String string) >>> throws ParseException >>> { >>> if(string == null || string.length() == 0) >>> { >>> return null; >>> } >>> return super.stringToValue(string); >>> } >>> } >>> >>> >>> thanks - Chris >>> >>> ------------------------------------------------------------------------- >>> >>> This SF.net email is sponsored by: Splunk Inc. >>> Still grepping through log files to find problems? Stop. >>> Now Search log events and configuration files using AJAX and a browser. >>> Download your FREE copy of Splunk now >> http://get.splunk.com/ >>> _______________________________________________ >>> Microba-controls mailing list >>> Mic...@li... >>> https://lists.sourceforge.net/lists/listinfo/microba-controls >>> >>> >>> > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Microba-controls mailing list > Mic...@li... > https://lists.sourceforge.net/lists/listinfo/microba-controls > > |