Detecting key events and setting caret position from a Document model

Hello, I have created a "masked" JTextField that contains specific formatting (these subclasses were created prior to the advent of Sun's implementation of masked fields, and are used extensively throughout my system, so I can't easily implement Sun's version at this time)
At any rate, here is the problem:
Consider the following "masked" field contents (date USA format):
The user keyboard input is:
"10252002", which results in the text field display of "10/25/2002"
The user presses the "delete" key in the first position of the masked field. The following result is "0/25/2002".
This is undesirable, since all the contents of the field have shifted to the left by one position, so the first "/" is now in position 2, instead of position 3. Also, the length of the field is now 9, instead of 10.
The field should really have the following contents: "02/52/002_", and the cursor should remain on the first position of the text field.
I believe need for the Document model to be able to differentiate between a "back space", and a "delete", so that my overridden "remove" method in my PlainDocument subclass can handle
insertion/repositioning of "masked literal" characters correctly, and also control the cursor movement accordingly.
What would be the best way to handle this?

I would re-post to the Flex Data Services forum.

Similar Messages

  • How to listen and obtain caret positions of changed text in JTextPane?

    Hi,
    I have a JTextPane that displays text with some styles on particular words in the text. For example, I highlight words with red color if they are in my dictionary file. I use regular expression to find matches, replace them with their corresponded definitions, and call setCharacterAttributes to add styles to the definitions. I store all start and end caret positions of the matched words/definitions in a vector. So, I can redisplay styles of all previous matches.
    The problem is that I'd like to be able to edit the text of some previous matches. So, with those changes all caret positions that I already store in the vector need to be updated.
    How can I obtain caret positions of changed text in JTextPane?
    How can I know that a user is currently changing text in the JTextPane?
    How can I get style of text such as color that is being changed?
    Thank you very much.

    Thank you very much, camickr, for your reply.
    I think that I might not know the right way to handle JTextPane and Document object.
    What I have done are:
    - Add style to JTextPane using, for example,
    Style targetCurrentMatchStyle = this.targetWindowTextPane.addStyle("Red", null);
    StyleConstants.setForeground(targetCurrentMatchStyle, Color.red);//For highlight - Then, I use regular expression (Pattern and Matcher) to find a match in text. For each match, I get start and end position from matcher.start() and matcher.end().
    if(matcher.find(start)){
    String term=matcher.group();
    int start=matcher.start();
    int end = matcher.end();
    //find definition for the matched term.
    String definition=mydictionaryHash.get(term);
    //Store caret positions in lists
    startPositionList.add(start);
    matchedLength=lengthList.add(definition.length());
    //Add changed to text in textpane
    StringBuffer sb=new StringBuffer();
    matcher.appendReplacement(sb, definition);
    matcher.appendTail(sb);
    //Get translated text from StringBuffer after replacement
    String translatedText=sb.toString();
    targetWindoTextPane.setText(translatedText);
    //Update start position for next search
    start=start+definition.length();
    //Add style to matched regions below.
    }- From the lists of start positions and matched lengths, I use the following code to add "Red" color to the matched text regions including all previously matched.
    for(int i=0;i<startPositionList.size();i++){
    this.targetWindowTextPane.getStyledDocument().setCharacterAttributes(
    startPositionList.get(i),
    lengthList.get(i),
    this.targetWindowTextPane.getStyle("Red"),
    true);
    }My issue is that I'd like to be able edit previously matched regions and update all positions of the matched regions stored in the lists.

  • Capture Hyperlink event and set value

    Hello everyone,
    I have a hyperlink on a report column and when I click on the hyperlink it takes me to an URL. Now I need to capture the time the user clicked on the URL and update a DB table column. So I created a Dynamic event to update an item, but I am not able to get the hyperlink event. When I select the Event as 'Click' and 'Selection Type' as 'Item', the report column does not show up on the Item(s) LOV. Can Dynamic Actions be based only on click of page items?
    If so, is there any other to capture this Hyperlink event and set value? Also, as my 'Column Link' target is 'URL', I cannot set any value for items there!
    Please help,
    Ramya

    Thanks a lot Vee, that was very helpful.
    I added the dummy page with 'OnLoad' page process with the PL/SQL code and my current page redirects to a new page with the new page's attributes set. Now I am able to update the timestamp on the table with the sysdate when I click on the click. However, my URL does not work. A page cannot be found error is returned. I displayed the P2_URL_ITEM on the page and it displays only until 'http', the rest of the text is cut. Is there a way I can increase the length of this page item?
    As the URL value assigned to the page item did not work, I tried to hardcode the URL. Below is my page process on the load of dummy page,
    BEGIN
    UPDATE xxnf.XXNF_APEX_RR_REPORTS
    SET last_used = SYSDATE
    WHERE report_id = :P2_REPORT_ID;
    sys.owa_util.redirect_url('www.google.com');
    --owa_util.redirect_url(:P2_URL_ITEM);
    END;
    However, still the page not found error comes up. Could you please help fix both these issues?
    1) P2_URL_ITEM - not having the complete URL
    2) redirect_url not working.
    Looking forward to any helpful pointers,
    Ramya

  • I use classical Hebrew for my work, and Pages will only display English characters even with a Hebrew font selected. If I cut and paste Hebrew characters from another document, as long as the font is supported, it will appear in Pages.  If I type it won't

    I use classical Hebrew for my work, and Pages will only display English characters even with a Hebrew font selected. If I cut and paste Hebrew characters from another document, as long as the font is supported, it will appear in Pages.  If I type it won't continue in Hebrew.  I have tried downloading several fonts, including those from professional societies, but the only way to get Hebrew in my document is to cut and paste.  Does anyone know how to fix this?  I use an older MacBook running OS 10.9.1.  I used to do my Hebrew work in Word, but it is no longer supported by Mac OS.

    Just clarifying:
    Pages '09 has bad support for Hebrew, Arabic etc but will accept pasted text.
    Pages 5 has much better support but with bugs.
    If you have columns they are in the wrong order ie Text starts in the left column and ends in the right column.
    If you type English into Hebrew text it tends to fall in the wrong position eg instead of to the left of Hebrew punctuation it goes to the right.
    As Tom recommends the only real solution on the Mac is Mellel.
    Peter
    btw Tell Apple, they are amazingly slow to fix this running sore which has been broken since RtoL was supposedly introduced in OSX 10.2.3 over a decade ago.
    Peter

  • Does anyone know how to use pages so you can export pdfs from the internet and automatically drag words from the document into the file name of the pdf (i.e., author, title of a scientific paper)

    Does anyone know how to use pages so you can export pdfs from the internet and automatically drag words from the document into the file name of the pdf (i.e., author, title of a scientific paper). For example, if I am downloading a paper by smith called "Surgery" that was published in 2002, it will automatically set the file name in the download to smith- surgery 2002. I have heard pages is smart enough to do this.
    thank you

    Pages can export only its own documents. They may be exported as PDF, MS Word, RTF or Text files.
    Pages can import (ie. Open a file as, or Insert a file into, a Pages document) documents in several formats, but won't rename the document as you describe. Documents that can be Opened (eg. Text, AppleWorks 6 WP, MS Word files) are converted to Pages documents, and retain their original names, with .pages replacing the original file extension. Files that can be Inserted (generally .jpg, .pdf and other image files) become part of the existing Pages file and lose their names.
    It may be possible, using AppleScript, to extract the text you want and to Save a Pages file using that text as the filename, but that would depend in part on being able to identify which text is wanted and which is not.
    How will the script determine where the author's name begins and where it ends?
    How will the script recognize the beginning and of the title, an decide how much of the title to use in the filename?
    How will the script recognize the year of publication?
    For papers published in a specific journal, with a strict format for placing each of these pieces on information, or containing the needed information as searchable meta data in the file, this might be possible. But it would require knowledge of the structure of these files, and would probably handle only papers published in a specific journal or set of journals.
    Outside my field of knowledge, but there are some talented scripters around here who might want to take a closer look.
    Best of luck.
    Regards,
    Barry

  • Detect key events on anything

    If I have a JFrame with many components on it, how do I detect if a key is pressed, without having to add a listener to every component? For example, how can I check for the escape key being pressed, but not having to have componentN.addKeyListener(this); for everything?
    Thanks
    US101

    The correct way to collect the key events is the following:
    from java 1.2 to java 1.3 use the FocusManager. This class can be found in the javax.swing package. You would then need to extend the DefaultFocusManager and override specific behavior.
    for java 1.4 use the KeyBoardFocusManager. This class can be found in the java.awt package.
    Please see the following for a better explanation:
    http://java.sun.com/j2se/1.4/docs/api/java/awt/doc-files/FocusSpec.html
    Thanks for your time,
    Nate

  • Setting Caret Position

    Dears,
    How do I set the Caret position to a required position in the SpinnerNumberModel? Do I need to use setDot() and NavigationFilter? The position should be set as soon as Spinner is constructed.
    Please help.
    Thanks,
    Raj

    Hi,
    I didn't get it work too, but this workaround seems to work.
    Cheers
    import javafx.application.Application;
    import javafx.application.Platform;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.scene.Scene;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    public class CaretPositioner extends Application {
         public static void main(String[] args) {
              Application.launch((java.lang.String[]) null);
         @Override
         public void start(Stage primaryStage) {
              BorderPane root = new BorderPane();
              final TextField tf = new TextField();
              tf.textProperty().addListener(new ChangeListener<String>() {
                   @Override
                   public void changed(ObservableValue<? extends String> arg0, String arg1, String arg2) {
                        System.out.println(tf.getCaretPosition());
                        Platform.runLater(new Runnable() {
                             @Override
                             public void run() {
                                  tf.positionCaret(0);
              root.setCenter(tf);
              Scene scene = new Scene(root);
              primaryStage.setScene(scene);
              primaryStage.show();
    }

  • Many events and photos are missing from my iphoto.  I have time machine and would like to restore without creating duplicates. The issue is although my photos are presently blank time machine/iphoto does see the file so importing them will create duplicat

    For some unknown reason, events and photos in my Iphoto are appearing blank. The photos have a title / placeholder but no picture. I use time machine and have back ups, my goal is to restore the photos without creating duplicates. Unfortunately iphoto sees the blank photos as if the picture exists?  Help

    If you want to use your back up you need to restore then entire Library from Time Machine, and then replace the damaged Library with it.
    Regards
    TD

  • Moving Events and archiving videos directly from Canon HF100 to External HD

    Hello,
    After purchasing my Macbook and my canon HF100 camcorder I got too carried away and excitedly imported too many videos to Imovie. When the Macbook had no more space to import new movies, without reading instructions ( NOW I KNOW... ALWAYS to read instructions first) I archived the videos directly onto an external HD ( 500 gb FAT 32 format).
    Now in order to free up some space I tried to move the existing events and projects from macbook to the same hard drive , but the HD icon has a yellow exclamation mark, which I now know means that it has to be formatted to MAC OS. and MAcbook will not allow moving of any events or projects to the hard drive..
    My problem as below:
    1- If I format my external HD now, it would loose all the previous data etc which I do not want. Since the directly archived videos are stored in FAT 32, does that mean they are now unusable for I Movie import? What should I do next in order to store the currently archived movies properly that Mac recognizes and reads the data correctly?
    2-I need to free up space on my macbook as soon as possible as the startup disk is totally full. I do not want to buy another external HD to move my data but i do already possess an I book external hard drive which is also Fat 32 format and has photos etc.. which I do not want to loose by formatting it.
    Can I copy all the files from my external HD ( where I archived the movies) to the I book ( where there are other movies and photos from windows computer) which is FAT 32 format and then format it to MAC OS and re transfer the archived movies back. Will Macbook recognize the files then?
    All the videos and photos are very precious to me and I do not want to lose them. Any help with my problem is highly appreciated. I wait eagerly for an answer. Many thanks in advance.

    Do I need to create a seperate folder for the RAW archived files which are yet to be processed by I >movie?
    In general, you want to be able to move it back exactly as it was, you can drag it over to the iBook, then drag it back. If it helps to put everything under one folder to do this, that is OK. When you move it back, make sure it looks like it looked before you moved it.
    Can the RAW files be transferred to a FAT 32 HD without formatting to MAC OS.. will this not >corrupt the data?
    Probably. I'm guessing you are using an 8GB SDHC card or similar with your Canon. If you put your card in a card reader on your Mac you should see it in the Finder (or you can connect your camera directly). If you see it in the Finder, do a right-click/Get Info. I would bet that your SDHC is formatted as FAT32. So if the original camera is Fat32, you know that FAT32 is fine for the archive.
    Here is why. FAT32 has an architectural limitation for file sizes. Files cannot be more than 4GB (minus one byte) - or 3.999999999 GB.
    The files on the camera are highly compressed AVCHD. Further, you would typically press record and stop several times while shooting, so no one clip is going to be bigger than 3.999999999GB. The only way you would exceed this is if you recorded a 2 hour event by pressing the record button once and letting it run without stopping. Even then, Canon probably has a workaround where they divide it up into 2 files that are each smaller than 3.999999999GB.
    So if the camera can accept FAT32, why can't iMovie? The reason is that on import, iMOvie converts the highly compressed AVCHD into full frames of Apple Intermediate Codec. The file size will typically increase by a factor of 8 to 10. So now it is quite possible to have a clip that exceeds the 4GB limitation. So iMovie does not allow FAT32 as a valid file structure.

  • Looping and setting cfset values (from a query)

    Stuck on how to get this to work.
    How would I go about looping and setting these values instead
    of doing them individually?
    The query this <cfset> references works fine and will
    work but repeats...
    <cfset ans1 = (qryGetPcts1.q1Ct / qryGetCounts.qID2) *
    100>
    <cfset ans2 = (qryGetPcts2.q2Ct / qryGetCounts.qID2) *
    100>
    <cfset ans3 = (qryGetPcts3.q3Ct / qryGetCounts.qID2) *
    100>
    <cfset ans4 = (qryGetPcts4.q4Ct / qryGetCounts.qID2) *
    100>
    <cfset ans5 = (qryGetPcts5.q5Ct / qryGetCounts.qID2) *
    100>
    So I'd like to loop and set them all instead...
    <cfloop index="i" from="1" to="27">
    <cfset ans#i# = (qryGetPcts#i#.q#i#Ct /
    qryGetCounts.qID2) * 100>
    </cfloop>
    But it's responding with this...
    Invalid CFML construct found on line 196 at column 19.
    ColdFusion was looking at the following text:
    I'm sure I'm missing something simple b/c this must be
    possible? Can I use a cfset in a loop?
    Help is appreciated

    In the main everything is in CF is in a struct. Armed with
    this information you use array notation to help you.
    <cfloop index="iCount" from="1" to="27">
    <cfset variables["ans" & iCount] =
    (variables["qryGetPcts" & iCount]["q" & iCount & "Ct"]
    / qryGetCounts.qID2) * 100>
    </cfloop>

  • Grouping and  setting attributes by group in data modeler

    Hi,
    I wanted the enhancement to hide foreign keys but until that comes I was thinking I could simply set all the foreign key I want not visible to a colour of white, which worked quite well.
    For the tables that are basically System such as Language Codes - I defined a Classification Type of System and set them to an identifiable colour to show they are connected but the connections will not be visible on the diagram.
    Then I tried to do the same for the Foreign keys but there is no way of setting a standard colour which can be changed.
    So I had to set each one to white, which is a pain but then I have white marks across my diagram which I may be able to live
    with. In most diagrammer mappers they have a send to back which would solve this - please???
    But then I come to the problem that I can't then see them to change them back as they are white ;)
    Is there any grouping mechanism that I can group together foreign keys so I can put in this temporary fix?
    So I guess I'm on
    1. Classification for Foreign Keys - any way to do this?
    2. Grouping and Sending groups to the front or back of the diagram.
    Thanks,
    p.

    Hi,
    you can use dynamic properties to build your own functionality - there is dynamic properties page for each object. you can create them using UI and use them in scripting.
    the following script uses dynamic property "cl_type" and check for value "t2"
    fkeys =  model.getFKIndexAssociationSet().toArray();
    //create color using integer
    color =   new java.awt.Color(16724838);
    for (var i = 0; i < fkeys.length; i++) {
    fk = fkeys;
    cl_type = fk.getProperty("cl_type");
    if(cl_type!=null){
    if(cl_type.indexOf("t2")==0){
    fk.setUseDefaultColor(false);
    fk.setBackgroundColor(color);
    fk.resetEdgeParams();
    }else{
    // set for other types or reset to default
    fk.setUseDefaultColor(true);
    fk.setBackgroundColor(null);
    fk.resetEdgeParams();
    you need to transform RGB color to integer - I found calculator here http://www.shodor.org/stella2java/rgbint.html
    Philip                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Move (or copy or cut and paste) entire sheet from one document to another.

    I have several sheets I want to move from one document to another and retain all formatting and spacing, etc.
    What is the best way to do this?
    Thanks

    On the left of the screen is the list of sheets and tables and charts. Select the sheet. Copy. Paste into the same area (i.e., in the area where the sheets are listed) of the new document.

  • Detect Key Press and Mouse Motion in ONE event?

    Hi
    I am trying to create a functionality where a mouse motion from left to right performs one action, and the same motion while a given key is pressed performs another action.
    How can i combine the two events? How do I unify the KeyEvent and MouseEvent, particulary when I need to capture the directional motion of the mouse together with the key press?
    many thanks for any insight

    you cannot actualy combine them into 1 event but there is an easy way around this:boolean mouseKeyPressed = false;
    public void keyPressed (KeyEvent e)
      if (e.getKeyCode () == ??) \\ or e.isCtrlDown(), e.isAltDown(), ...
        mouseKeyPressed = true;
    public void keyReleased (KeyEvent e)
      if (e.getKeyCode () == ??) \\ or !e.isCtrlDown(), !e.isAltDown(), ...
        mouseKeyPressed = false;
    public void mouseMoved (MouseEvent e)
      if (mouseKeyPressed)
        //processAction
    }hope this helps,
    greetz,
    Stijn

  • Detect user event and session expiration

    Hi,
    Can we monitor the time gap between user events in a flash
    movie. This is to detect when the user doesn't do anything, or
    leave, and his/her logged profile is still open in the flash movie
    on the browser. So to avoid to have inappropriate use of the logged
    profile by a third party, then the flash movie could detect if
    there is no activity for 5 min. then redirect to the login screen.
    Does a case like that need an actionscript timer ? Have you
    seen any examples of that?
    Thanks,
    Marty

    You don't.
    You might be able to use the session for this. You could have an Object that gets notified when the user session is unbound. This would atleast close your stuff after the session times out if the user closes the browser.
    Take a look at http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpSessionBindingListener.html

  • Chunk expressions: Need the first and last char position from member.word[x]?

    I need to build a linear list of the string positions of the
    first and last character of each word in a string. For example if I
    have the string myPet = “DOG CAT FISH” then myList =
    [[1,3],[5,7],[9,12]]
    myPet.word[x] will let me access the individual words but
    I’m not sure how to get the char position of the beginning
    and end of each. Please help, it’s Friday and my brain has
    left for the weekend.

    Touche, Sean.
    "Sean Wilson" <[email protected]> wrote in
    message
    news:fqa8ap$bga$[email protected]..
    > Hi Craig,
    >
    > Your's fails if any word is repeated. Try it with "DOG
    CAT FISH DOG"
    >
    > This one seems to work, although there are probably more
    efficient ways to
    > go about it. A regular expression and the PRegEx xtra
    would certainly be
    > quicker, especially as the string gets longer
    >
    > on mGetWordBoundaries aString
    > -- basic error check
    > if stringP(aString) = 0 then return []
    > if length(aString) = 0 then return []
    >
    > lWhitespace = [SPACE, TAB, RETURN, numToChar(10)]
    > tStart = 1
    > tChar = aString.char[tStart]
    > repeat while lWhitespace.getPos(tChar)
    > tStart = tStart + 1
    > tChar = aString.char[tStart]
    > end repeat
    >
    > lPositions = []
    > repeat with w = 1 to aString.word.count
    > tEnd = tStart + aString.word[w].char.count - 1
    > lPositions.append([tStart, tEnd])
    > tStart = tEnd + 1
    > tChar = aString.char[tStart]
    > repeat while lWhitespace.getPos(tChar)
    > tStart = tStart + 1
    > tChar = aString.char[tStart]
    > end repeat
    > end repeat
    > return lPositions
    > end

Maybe you are looking for