How do I male keywords (only) upper case in a JTextPane

I'm using a DefaultStyledDocument subclass to handle SQL syntax highlighting but what I want to do is ensure that keywords are converted to upper case so as to maintain a "good" style without the hassle of shift or caps lock.
Now, the StyledDocument seems the wrong place to implement this functionality as it should be just for display purposes while changing text to upper case is an actual change to the character values selected by the user.
The JTextPane class itself has a replaceSelection(String content) method but this relies on the text being selected.
I guess I could do this if I had a hook back to the JTextPane from my StyledDocument. When I find a keyword, select the text and replaceSelection.
Is there a cleaner way to do this?

Okay, top tip.
I added the document listener which processed the text on each insert.
At this stage, I've only implemented keyword checking on single character inserts (to capture changes as they are typed) - multi character inserts need to be handled differently.
If I have a character I know can signal the end of a SQL keyword (space, carriage return, brace, parenthesis, comment etc) then I jump back to the last space in the document. This gives me the last "word" in the document.
Remove the last character (as this is the character that has triggered the event) and then see whether it is upper case or not? If not, should it be (is it a keyword)? If so, insert the upper case String in its place.
It was a bit fiddly to put the pieces together (a document listener which then has to use SwingUtilities to make the change using a third Runnable class) but it does exactly what I ask of it.
I have to implement a similar algorithm now to cope with deletions (what if a delete the "a" at the end of "selecta") and multi-character inserts.
Thanks for the advice. I've not used DocumentListeners before so this was doubly helpful.

Similar Messages

  • How to set up an automatic upper case at the begining of a sentence

    Can someone help me if or how to set up an automatic upper case at the beggining of each sentence. I am doing huge amount of writing and just got fed up with it.

    What application? Pages? If so, that option (and many others) is not available in the current version. You can use the previous version which should be in your application folder. Or you can do what I finally did and use Open Office or Libre Office.

  • How to convert a string from upper case to lower case in FOX formula

    Hi Experts,
    How to convert a string from upper case to lower case in FOX formula?
    Thanks,
    Cheers!!!
    PANKAJ

    The last result.append( c ) should be:
    result.append( Character.toLowerCase(c) );

  • BigString to Big String - how do I detect index of upper case?

    bigString to Big String - how do I detect index of upper
    case?
    Is there a way to detect, insert space and replace the upper
    case letters in a string?

    Something like this?
    <CFOUTPUT>#REReplace("bigString", "[A-Z]"," "&
    Mid("bigString", REfind("[A-Z]", "bigString"),
    1))#</CFOUTPUT>
    This will at least give you a break at the first upper case
    letter. You can then replace the first character in the result with
    an upper case as well, which I didn't do, since I figured that you
    knew how to do that.
    Phil

  • RFC function callls a SAP Business Connector Flow - only upper case

    Hi everybody,
    I wrote a function in SE37 which is calling a Flow in SAP Business Connector.
    R/3 and SAP BC, both are Non Unicode systems.
    The export parameter is TYPE makt-maktx.
    The call to SAP BC works fine. Only all the text I can see in the pipeline of SAP BC is upper case.
    I checked wether the domain of the makt-maktx allows case sensitive texts.
    This is OK.
    I have no idea how I can tell SAP BC to receive case sensitive texts.
    I checked the forums. Seems nobody had such a problem.
    Can somebyody help?
    Best regards
    Jochen
    Hi to all,
    it was not the JAVA Version, or a bug or whatelse.
    I just ingnored while testing in SE37 that there is
    a Flag [X] case sensitive - That's all!
    Shame on me!
    Greetings Joe
    Message was edited by:
            Jochen Seeliger

    Hi Priya
    Seeing the messages, it appears that server is down.
    "java.net.ConnectException" occurs whenever you try to connect to a system which is not up and running.
    cheers
    Sameer
    PS: Please award points if you find the answer useful

  • Only upper case in geocoding servie response?

    when calling the geocoding service, I always get the the result in upper case
    (i.e.
    http://elocation.oracle.com/geocoder/gcdemo.jsp?country=DE&match_mode=DEFAULT&address=ctive+media+NEUHAUS%0D%0Asteinstr.+75%0D%0A81667+m%FCnchen
    Is it possible to get the result in the correct case?
    Edited by: beHam on Sep 21, 2011 5:45 AM

    Okay, top tip.
    I added the document listener which processed the text on each insert.
    At this stage, I've only implemented keyword checking on single character inserts (to capture changes as they are typed) - multi character inserts need to be handled differently.
    If I have a character I know can signal the end of a SQL keyword (space, carriage return, brace, parenthesis, comment etc) then I jump back to the last space in the document. This gives me the last "word" in the document.
    Remove the last character (as this is the character that has triggered the event) and then see whether it is upper case or not? If not, should it be (is it a keyword)? If so, insert the upper case String in its place.
    It was a bit fiddly to put the pieces together (a document listener which then has to use SwingUtilities to make the change using a third Runnable class) but it does exactly what I ask of it.
    I have to implement a similar algorithm now to cope with deletions (what if a delete the "a" at the end of "selecta") and multi-character inserts.
    Thanks for the advice. I've not used DocumentListeners before so this was doubly helpful.

  • How to Handle the lower and upper case in 'POPUP_GET_VALUES'

    Hi All
    i am using the following FM and when i enter value on the
    popup in lower case or with capital letters i see the field
    with upper case ,this is problem for me since i need to
    take the field and compare it ,there is a way to handle this
    issue ?
    CALL FUNCTION 'POPUP_GET_VALUES'                      "#EC FB_RC
            EXPORTING
              popup_title     = lv_head_msg
            IMPORTING
              returncode      = lv_rc    " User response
            TABLES
              fields          = lt_field    " Table fields, values and attributes
            EXCEPTIONS
              error_in_fields = 1
              OTHERS          = 2.
    Best regards
    Alex

    Hi Alex,
    This because, the field and table name that You are passing in lt_field, has a conversion attached to it, which causes the converison in case.
    For e.g. If You pass MARA-MATNR and try to get the values from pop-up, the value will get converted to upper case, but if You pass MAKT-MAKTX (which does not have a converison attached to it), the value will be retrieved as it was entered. This is standard SAP, which is correct.
    If You need to get values of any text field, pass any SAP text field as reference in your table lt_field. Hope this helps...
    Rgds,
    Birendra

  • Create user for CPS in _ UPPER CASE LETTERS _ if using JSM on SolMan

    only create users for CPS in UPPER CASE LETTERS if using JSM on SolMan
    Dear CPS Admins,
    If you plan to use Job Scheduling Management (JSM) on SAP Solution Manager together with CPS by Redwood please always create any users in CPS only with upper case letters to avoid issues in the communication between SolMan and CPS.
    The user creation for CPS is done in the UME (Java user administration, alias /useradmin).
    Actually the CPS user itself is only created in CPS during the first logon.
    Both CPS and the Java UME are case sensitive. So you can create users in uppercase, lowercase or mixed letters. But of course the system does still not allow duplicate names. So you can either create MUELLERP, MuellerP or muellerp - but not multiple of them.
    Now, if the SolMan communicates with CPS for Job Scheduling, the actual user name is taken in some kind of a "trusted RFC like" way and checked on the CPS system connected to the SolMan. If the current SAP user does not exist on CPS no activities are possible, neither in read mode (read existing CPS jobs) nor in write mode (change existing jobs or create new ones).
    Unfortunately the Solution Manager transmits the current user name to CPS only in upper case letter. So if the CPS user was not created in UPPERCASE letters in CPS the communication will fail. Therefore, think about creating CPS users in UME only in UPPERCASE letters. Changing this later is difficult to impossible.
    Best regards,
    Peter

    hi,
    I tried to reproduce your issue but I was not able to create a UME user with lower case letters.
    UME automatically converted the user name into upper case after saving. So even if I enter "cps" as user name UME stored the user name as "CPS".
    (maybe that happend because of the existing SU01-UME integration in our SolMan system)
    If UME would be case sensitive I would expect that it is possible to create the user "CPS", "cPs" and "cps".
    Regarding the SolMan-CPS connectivity:
    Transaction SU01 allows only upper case letters (in user name and alias). Since you're starting from an ABAP system only user names with upper case letters are supported. It's a technical constraint of the ABAP user management that user names consist of upper case letters only.
    Kind regards,
    Martin

  • How can I read an input which only contain the 26 upper case letter

    Are there any method that can read an input which only contain 1 character and it is in upper case too.
    should I use readChar( ), or readString( )??
    How should I implement them if I do use one of them?
    thx

    Try this :
    import java.io.*;
    public class Read
    public static void main(String[] x)
    System.out.println("Upper case char typed : "+readUpperCaseChar());
    public static char readUpperCaseChar()
    // method that read char and return the last upper case char
    char x='\0',tmp='\0';
    try
    while(tmp!='\n')
    tmp=(char) System.in.read();
    if(tmp >= 'A' && tmp <= 'Z')
    x=tmp;
    catch(IOException ioex)
    ioex.printStackTrace();
    return x;

  • How to CHECK WHETHER LOWER CASE OR UPPER CASE  IN CUSTOM TABLE

    Dear Friends,
                     I have a requirement where from  the flat file  i have collected into the internal table is as below :
      IDNo.     Name     Date      Location   Designation  Dept
      101       raja      4/12/2007  Delhi      manager      HR
      102       james    4/12/2007  Delhi      clerk          HR
    now iam checking against my custom table where iam   if the designation for the employee name already exists then i shouldnt modify/update the custom table that record
      now iam facing a problem where is the flat file is always having the Lower Case only ,
    as per the scenario  if my custom table already have the employee name i shouldnt modify/update i.e i shouldnt overwrite,
    this scenario is working but it is failing in the case
    by chance in the Custom table the employee name or designation is in Upper Case  the condition where iam checking in the code  is failing as the flat file data coming into the internal table is having always lower Case.
    So could any one please let me know how i should check in my custom table whether iam having upper case or lower case and how can i make it lower case ?
    because iam able to manage in the case where if the flat file data coming in Upper case i can check before only by
    using Translate to lower case . how i unalbe to  check for the data coming from the Custom table if  in Uppercase , so i want to change that to lower case then checking my condition whether that data already exists in my custom table before modifying the data coming from the flat .
    because the condition is failing when the data in the custom table is in upper case and the Flat file data is in lower case.
    please help how i can check for the data in the Custom table is in upper case and then change it to lower case.
    Regards
    Madhuri.

    Hi Madhuri,
    Translate both data in your flat file & custom table to lowercase before comparing them. With that, you're able to identify if there's a differences in for both data.
    If you're putting data that is pulled from custom table, what you can do is after selecting/reading the data, translate to lowercase or uppercase (whichever you prefer) but make sure if you translate to lowercase, your data in the flat file must be lowercase to and vice versa.
    Happy doing !!..
    Regards,
    Loo

  • How to disable Automatic UPPER case in SQL Developer

    Hi,
    I am using SQL developer more than two years. I have recently downloaded SQL Developer 2.1.1.64.
    My problem is, while editing the package body when move to newline the previous line get converted to UPPER case automatically. But, I don't want to get all the code I have written to be converted to UPPER case.
    I have tried all possible preference changes but no change. Can you please help me how disable the case change in SQL developer.
    Looking forward your response.
    Thanks,
    Prashantha Konkodi

    You can always define how you want to format the SQL or normal text by using the keyboard CTRL+' to manage text/keyword case to all UPPERCASE, Initcap, or all lowercase.
    The system remembers your settings and will keep the text the same format in future.

  • How do u convert  to upper case?

    hi...
    i'm new to oop and i couldnt find the syntax to change lower case to upper case anywhere...can someone kindly give me the link to that syntax please and thank you

    if i have an "apple" how do i make it to uppercase
    using the abovementioned codes??trust me i am not
    giving you my homework..i am truly in need of helpI am going to take a guess and say you tried:
    String yummy = "apple";
    yummy.toUpperCase();
    System.out.println( yummy ); only to see the "apple" returned.
    Now the answer has been given above, but why do you need to do this? String is an Immutable object. Basiclly this means that it can not change.
    Now you might say that the code
    yummy = yummy.toUpperCase();changes the String. Well it does not. It changes the refrence (yummy) to point from one string ("apple") to a brand new string "APPLE".
    This might have confused you even more, so here are some links to people who have explained it much better than I.
    JavaRanch Campfire - Cup Size: a Story About Variables
    JavaRanch Campfire - Pass By Value, Please

  • How to convert a text file in lower case to upper case?

    I've a beginner in java world and I just come through the tutorial in http://java.sun.com/docs/books/tutorial/essential/io/filestreams.html showing how to copy a text file:
    import java.io.*;
    public class Copy {
    public static void main(String[] args) throws IOException {
         File inputFile = new File("farrago.txt");
         File outputFile = new File("outagain.txt");
    FileReader in = new FileReader(inputFile);
    FileWriter out = new FileWriter(outputFile);
    int c;
    while ((c = in.read()) != -1)
    out.write(c);
    in.close();
    out.close();
    And I would like to ask how to covert all lower case letters in input file to upper case letter in output file at the same time of copying.
    I guess it'll be using Character.toUpperCase(c), but I don't know how to do it actually.
    Any help would be much appreciated.

    Hope this helps
    import java.io.*;
    public class Copy {
    public static void main(String[] args) throws IOException {
    File inputFile = new File("farrago.txt");
    File outputFile = new File("outagain.txt");
    FileReader in = new FileReader(inputFile);
    FileWriter out = new FileWriter(outputFile);
    BufferedReader buff = new BufferedReader(in);
    String c;
    while ((c = buff.readLine()) != null)
    out.write(c.toUpperCase());
    in.close();
    out.close();
    }

  • How to cast a fieldinput value to upper case.

    Im not a java programer I guess that this must be a silly thing.
    Im searching data in R/3 from 2 fields 1 numeric and the other alphanumeric. This alphanumeric fields if I put it in upper case works, if I wirte it in lower case doesnt works.
    In R/3 when I test the FM doesnt matter if I put it lower or upper case, it works fine.
    so I wanna know how can I in WD cast the value that I put in that fieldinput be converted to upper case when I hit the search button.
    Thx

    > Im not a java programer I guess that this must be a
    > silly thing.
    >
    > Im searching data in R/3 from 2 fields 1 numeric and
    > the other alphanumeric. This alphanumeric fields if I
    > put it in upper case works, if I wirte it in lower
    > case doesnt works.
    >
    > In R/3 when I test the FM doesnt matter if I put it
    > lower or upper case, it works fine.
    >
    > so I wanna know how can I in WD cast the value that I
    > put in that fieldinput be converted to upper case
    > when I hit the search button.
    >
    > Thx
    Hi,
    When you test the FM in SE37 in R3 there is an option at the top of the screen Called Uppercase/Lowercase - this controls whether the input is automatically converted to upper case for alphanumeric fields.
    The other option you have, if it is a custom FM, is to translate the input of the alphanumeric fields in the ABAP - it is quite common to have to translate or convert input data to make sure it is in the same format as the backend system.
    I prefer to do this sort of conversion on the backend system as usually you have a better guarentee that it will be in the correct format, than if you do it in the Java element.
    Just my opinion,
    Gareth.

  • How to translate the key words in ABAp program from lower case to upper cas

    How to translate the key words in ABAp program from lower case to upper case?

    Hi Kittu,
    You need to set the Pretty Printer settings to achieve key words in ABAP program from lower case to upper case.
    Utilities -> Settings -> Pretty Printer (tab) -> Select third radio button.
    Thats all.
    <b>Reward points if this helps.
    Manish</b>

Maybe you are looking for

  • After upgrading to Lion, my Macbook Air's built in iSight camera has disappeared.  I'm not sure how to get it recognized again.

    After upgrading to Lion, my Macbook Air's built in iSight camera has disappeared.  I'm not sure how to get it recognized again.  Help -Sami

  • CS5.5 freezes on export

    Hello This question has obviosly been ask before, but I couldn't find an answer that helped me. I've had this problem for a while now, on CS4, CS5 and now on CS5.5. In the past I could barely live with it, but now I HAVE to finish a couple of project

  • Deployment Error: Deployment Timed Out after 60 seconds

    I am having problems simply deploying my webapp through creator. The application that I am working on was completely developed in the creator IDE and at some point took a really log time to deploy. Now it actually times out. This is my ide.log file.

  • Error in sending external mail

    hi .. while sending mail using BCS objects .... i am geting error Internal error: SO_OBJECT_MIME_GET Exception: 2 ....i too configured SCOT transaction wit port number 25 , mail host and also given the internet email id for mailing user.... plz do he

  • Form personalization requirement

    Hi All, I have a requirement where we need to throw error (or disable delete option) message if a user tries to delete a particular element (loan) which has been processed once either in regular payroll run or quick pay. (in element entries screen: A