JTextPane (reading char and its attributes)

Hellow,
I am trying to write a simple editor, where a person could write his text (in different size and color etc.) and than i need to turn this text to html code.
So the way that i determen the shape of the text in JTextPane is:
StyleConstants.setBold(set, false);
*               pane.setCharacterAttributes(set, false);*
And now i have to you trought the document and read the chars and its asstributes.
And the way that i go trought the doc is by using the caret: moveCaretPosition(x);
Reading the char: char c=pane.getText(pane.getCaretPosition(),1).charAt(0);
But the problem now is... by moving the caret (dot) the mark stays in its place, so when I try to read the attribues(*AttributeSet crka;crka=pane.getCharacterAttributes();*), i read them for all the chars selected so far (0->x).
How do i move this oround, so that only one char is read and its attributes?
Edited by: Defero on Jul 19, 2008 3:09 AM

Sorry for that,
Yeah but it still doesnt work right.
Example:
Text in pane:
AB C DEFGH... (ignore spacers)
And then if i read the number of attributes on each char, they go like this:
00111111...
Just in case, i post my code of setting the arguments:
JButton gumb=new JButton("bold");
        gumb.addActionListener((
                 new ActionListener() {
                     public void actionPerformed(ActionEvent e) {
                          if(bold==false){     
                        StyleConstants.setBold(set, true);
                       pane.setCharacterAttributes(set, true);
                       pane.requestFocus();
                      bold=true;
                          }else {
                               StyleConstants.setBold(set, false);
                               pane.setCharacterAttributes(set, false);
                               bold=false;
                               pane.requestFocus();
             ));And reading should go like this right?:
StyledDocument ddoc=pane.getStyledDocument();
for(int i=0;i<ddoc.getLength();i++){
int x=ddoc.getCharacterElement(i).getAttributes().getAttributeCount();
}Edited by: Defero on Jul 19, 2008 10:12 PM
Edited by: Defero on Jul 19, 2008 10:12 PM

Similar Messages

  • [JS-CS4] - How to read the XML Element and its Attributes

    Dear All,
      I have the doubt regarding: reading the xmlElement and its attributes.
    Here I droping the xml script
    //============= Start ======================//
    var myDoc = app.activeDocument;
    var Fpath = File("../Projects/Entity_map.xml");
      if (Fpath.exists)
       Fpath.open("r");
       var Cont= Fpath.read();
      var roots = new XML(Cont);
      var myEveryName = new Array();
      var myEveryContent = new Array();
      var myEveryAttributes = new Array();
      traverse(roots);
    //$.writeln(myEveryName);
    //$.writeln(myEveryContent);
    $.writeln(myEveryAttributes.length);
    for(var i=0; i<myEveryAttributes.length; i++)
      $.writeln(myEveryAttributes[i]);
    function traverse(tree) {
        myEveryName.push(tree.name());
    myEveryContent.push(tree.text());
      myEveryAttributes.push(tree.getAttribute);
    // you get the contents by using .text() insted of .name()
        if(tree.elements().length() > 0) {
            for(var i=0; i<tree.elements().length(); i++) {
                traverse(tree.elements()[i]);
    //============== End =====================//
    and the XML Structure is
    //===============XML =====================//
    <?xml version="1.0" encoding="UTF-8"?>< Entity_Convertion>
    < Entitys char="Ç" GID="173"/></ 
    Entity_Convertion>
    //===============End ====================//
    Here I'm getting the XML Elements and its contents, but not xmlAttributes.
    Please any one can help me, then I will appreciate...
    Thanks & Regards
    T.R.Harihara SudhaN

    Dear All,
      I have the doubt regarding: reading the xmlElement and its attributes.
    Here I droping the xml script
    //============= Start ======================//
    var myDoc = app.activeDocument;
    var Fpath = File("../Projects/Entity_map.xml");
      if (Fpath.exists)
       Fpath.open("r");
       var Cont= Fpath.read();
      var roots = new XML(Cont);
      var myEveryName = new Array();
      var myEveryContent = new Array();
      var myEveryAttributes = new Array();
      traverse(roots);
    //$.writeln(myEveryName);
    //$.writeln(myEveryContent);
    $.writeln(myEveryAttributes.length);
    for(var i=0; i<myEveryAttributes.length; i++)
      $.writeln(myEveryAttributes[i]);
    function traverse(tree) {
        myEveryName.push(tree.name());
    myEveryContent.push(tree.text());
      myEveryAttributes.push(tree.getAttribute);
    // you get the contents by using .text() insted of .name()
        if(tree.elements().length() > 0) {
            for(var i=0; i<tree.elements().length(); i++) {
                traverse(tree.elements()[i]);
    //============== End =====================//
    and the XML Structure is
    //===============XML =====================//
    <?xml version="1.0" encoding="UTF-8"?>< Entity_Convertion>
    < Entitys char="Ç" GID="173"/></ 
    Entity_Convertion>
    //===============End ====================//
    Here I'm getting the XML Elements and its contents, but not xmlAttributes.
    Please any one can help me, then I will appreciate...
    Thanks & Regards
    T.R.Harihara SudhaN

  • How to get nodes and its attributes of an XML file usiong DOM parsing?

    how to get nodes and its attributes of an XML file usiong DOM parsing?
    i am new to XML parsing.......
    Thanking you........

    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;      ...
    //Setup the document
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
         DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
         Document doc = docBuilder.parse (new File("MY_XML_FILE.xml"));
    //get elemets by name
         String elementValue = doc.getElementsByTagName("MY_ELEMENT").item(0).getTextContent();
    //This method can return multiple nodes, in this instance I get item(0) , first nodeRead the api for other methods of getting data.

  • Develop a report to migrate territories and its attributes

    Hi All,
    My requirement -> create territories, assign BP and attributes to it through a custom report. Using BAPI BAPI_TERRITORY_CREATE I manage to create territories but assign BP and Attributes i did not find any FM and BAPI. kindly guide me how i can assign BP and Attributes to a territories.
    By debugging transaction crmm_terrman i found some FMs but not working for me.
    regards,
    Noor Gani

    Hello Noor,
    I'm not sure but if you are talking about the marketing attributes, you can definitely use FM - CRM_MKTBP_ASSIGN_ATTRIBUT_TAB
    You need to pass the profile id, partner id and marketing attributes data. Thats it.
    I think the FM you ar eusing for terrritory is fine. It should work.
    I hope this helps.
    Thanks
    Vishal

  • CHAR (and VARCHAR2) attribute semantics in Catalog Views

    Hello,
    It may sound quite elementary but I am struggling to find information about this.
    I have created an object that contains an attribute declared in the type spec as CHAR(8 CHAR).
    But where in the catalog views will I find the character semantic ?
    For example, in the case of TABLEs, I can look at the column CHAR_USED in the DBA_TAB_COLUMNS view. Unfortunately though, none of the three views (DBA_TYPES, DBA_TYPE_VERSIONS and DBA_TYPE_ATTRS) related to type specifications have such an indicator.
    I could of course do a string analysis on the TEXT column of the DBA_TYPE_VERSIONS view, but that would seem rather unnatural if there is a direct wayl ...
    Any ideas?
    Best Regards
    Philip

    mouratos wrote:
    But where in the catalog views will I find the character semantic?Good question. Oracle obviously keeps it in data dictionary tables but not in views. If you check DBA_TYPE_ATTRS view, you'll see it is based on sys.attribute$ table. It has column PROPERTIES and it looks like it holds attribute character semantic:
    SQL> create or replace
      2    type mouratos_chars
      3    as object(n varchar2(10 char))
      4  /
    Type created.
    SQL> create or replace
      2    type mouratos_bytes
      3    as object(n varchar2(10 byte))
      4  /
    Type created.
    SQL> select  ta.type_name,
      2          ta.attr_type_name,
      3          properties
      4    from  user_types t,
      5          user_type_attrs ta,
      6          sys.attribute$
      7    where toid = t.type_oid
      8      and ta.type_name = t.type_name
      9      and t.type_name like 'MOURATOS%'
    10  /
    TYPE_NAME                      ATTR_TYPE_NAME                 PROPERTIES
    MOURATOS_BYTES                 VARCHAR2                                2
    MOURATOS_CHARS                 VARCHAR2                             4098
    SQL> Now based on the above we can deduce it is 13th bit (from the right):
    select  ta.type_name,
            ta.attr_type_name,
            case
              when ta.attr_type_name in ('CHAR','VARCHAR2') then decode(bitand(properties,4096),0,'BYTE','CHAR')
            end char_semantic
      from  user_types t,
            user_type_attrs ta,
            sys.attribute$
      where toid = t.type_oid
        and ta.type_name = t.type_name
        and t.type_name like 'MOURATOS%'
    TYPE_NAME                      ATTR_TYPE_NAME                 CHAR
    MOURATOS_BYTES                 VARCHAR2                       BYTE
    MOURATOS_CHARS                 VARCHAR2                       CHAR
    SQL>  SY.

  • TLD tags and their attribute types

    Hello,
    I created custom component, and i created TLD file, where i specified tag and its attribute (Value) as a type String, all possibles types are (String, boolean, byte, char, double, int, float, long ).
    In another projct where i am using this component i set Value = #{row.X} and then error occures, because attribute Value has type String and i set there expression.
    In Jdev 11TP4 everything works ok, but now in JDeveloper 11 it does not.
    Does anyone know how can i specify attributes type to expression, or how can i expression convert to a string?
    Thank you
    Katka

    Rather than pull more than you're going to display on the page and try to paginate from within your app why don't you limit the rows right from your query and then work the limit numbers into your page as hidden form fields or query string parameters?
    See:
    http://faq.javaranch.com/java/PaginationOrPaging

  • How to get string from jtextpane along with its attributes

    sir,
    How to get string from jtextpane along with its attributes
    i,e font,size,style,color etc.
    please help me out.
    my mail id is [email protected]

    JTextPane extends JTextComponent
    JTextComponent.getDocument()
    a Document is a set of Element, see Document.getRootElements(). Each Element has attributes, stored within an AttributSet object see Element.getAttributes()
    a Document can also be rendered as a String, see Document.getText( offest, length ), use it with 0 and Document.getLength() as parameters.

  • How do I copy and paste a shape (or layer) from one file to another keeping all of its attributes?

    Our department currently uses MS Paint to place varied colored boxes for callouts on top of screen figures used in our documentation. As you know, MS Paint is not a robust image editing application, and we are frustrated at its limitations (especially not having a "non-destructive" edit capability). Consequently, we are evaluating a trial version of PS to see how a workflow could be developed that would allow the department to use callout boxes "stored" in a PS file that could be applied in an easy, consistent manner to our screen figures (but also keep each callout box editable) using PS.
    Consequently, in PS using the shape tool, I created a file with our colored boxes for callouts, each on its own layer. Now I am trying to determine how you copy and paste a box (or layer) from this file to a "working" file (one containing a screen figure), while keeping all of its attributes (color, line weight, being editable, etc.). I can't seem to find an option to do this. Is there? If not, is there another workflow in PS that you can recommend for this type of procedure?

    Thanks - I used the Layer > Duplicate command and it worked great!
    P.S. How do you drag and drop a layer? I tried dragging a layer to the other open image, but nothing happened. Do you have to hold down a specific key for this (I'm using Windows)?

  • Hiding a table column and its contents yet reading the values

    Hi all,
    hope someone can help as i urgently need a solution for this although its probably more of a javascript and html forms question than a JSP - but i couldnt find a good javascript forum - if any one has come across a good JS and HTML - i would appreciate if you would let me have a url for it - in the meantime as i need this urgentely and most JS sites that i have visted and posted on seem to be useless, i havent got a reply back yet , and since i've always found java sun forum good and helpful thought would post it here - hope no one minds it too much . Thanks in advance for any help with resolving my urgent problem.
    overview of question:
    I need to, using an onclick() event read the contents of the 4th cell in the clicked row and set the value of a hidden element � (not sure what element to use here attribute tag? Or some other - but basically, this needs to also be hidden, as I�m going to use this as one of the parameters to send through as part of the form - )
    explanation of question
    So when I do :-
    <td><netui:label value="{container.item.TELECARERID}"/></td> And using javascript :-
    row.cells[4].innerText;I can read the value and print it to screen as :-
    alert('row.cells[4].innerText)) = ' + row.cells[4].innerText);although at this stage I�m not sure how to now set this value to an element in the form so that I can include this value as part of the submit action of the form.
    However when I do the following, which is closer to what I�m trying to achieve (ie hide the 4th column of the table and its values � but when I just hide the value as in:-
    <td><netui:hidden dataInput="{container.item.TELECARERID}" dataSource="" /></td> I can�t use the above (row.cells[4].innerText;), javascript syntax to get to the value although the value is still in the viewsource of the html page.
    How can I hide this forth column of the table yet get the values of the 4th column and also set it to some element of the form so that it can be submitted with the date range as part of a criteria to search against by the backend server.
    the full code (well... relevant parts)
    Here is all the code:
    <table id="table1" class="tablebody" border="1">
            <tbody>
             <tr>
               <th><rpb:columnHeader field="FIRSTNAME"><i18n:getMessage messageName="first_name"/></rpb:columnHeader></th>
               <th><rpb:columnHeader field="LASTNAME"><i18n:getMessage messageName="last_name"/></rpb:columnHeader></th>
              <th><rpb:columnHeader field="LOGONNAME"><i18n:getMessage messageName="logon_name"/></rpb:columnHeader></th>
              <th><rpb:columnHeader field="TEAM"><i18n:getMessage messageName="team"/></rpb:columnHeader></th>
               <th><rpb:columnHeader field="TELECARERID"><i18n:getMessage messageName="telecarer_id"/></rpb:columnHeader></th>
            </tr>
           </netui-data:repeaterHeader>
           <netui-data:repeaterItem>
            <tr bgcolor="#FFFFFF" onMouseOver="this.bgColor='gold';" onMouseOut="this.bgColor='#FFFFFF';" onclick="selectTeleCarer(this)">
            <td><netui:label  value="{container.item.FIRSTNAME}"/></td>
              <td><netui:label value="{container.item.LASTNAME}"/></td>
             <td><netui:label  value="{container.item.LOGONNAME}"/></td>
           <td><netui:label  value="{container.item.TEAM}"/></td> 
            <td><netui:label value="{container.item.TELECARERID}"/></td>
           </tr>
          </tbody>///////and then I�m trying to using the below sepertaely printed javascript set it to the below hidden attribute so that it can be submitted as part of the form
    <netui:hidden tagId="teleCarerId" dataSource="{actionForm.teleCarerId}" dataInput=""/>
                                 <div>
                             <i18n:getMessage messageName="created_between"/>
                                <netui:textBox tagId="data" dataSource="{actionForm.fromDate}"/>
                                <button id="trigger" onclick="jscalendar/calendar.js">...</button>
                               <i18n:getMessage messageName="and"/>
                                <netui:textBox tagId="data1" dataSource="{actionForm.toDate}"/>
                                <button id="trigger2" onclick="jscalendar/calendar.js">...</button>
                            </div>
                    <br />
                    <netui:button value="Submit" type="submit"/>
                </netui:form>/// the java script is :-
    function selectTeleCarer(row)
        if ( row.style ) {
    row.style.backgroundColor = ('gold' == row.style.backgroundColor)?
    'white' : 'gold';
    //document.form.teleCarerId.value = row.cells[4].innerText;
    alert('row.cells[4].innerText)) = ' + row.cells[4].innerText);
    }

    thanks for the reply,
    but i cant use just html like <input type hidden > as i'm using the struts like framework with the netui tags in weblogic where i need to link the tag value to the form bean to be passed to the server . thus i need to use the netui tag , which doesnt have a name but a tagId instead, so i'm using it like this :
    <netui:hidden tagId="teleCarerId" dataSource="{actionForm.teleCarerId}" dataInput=""/>and then in javascrpit doing:
    //document.form.teleCarerId.value = row.cells[4].innerText;but thats not my problem ()as it probably will work and its only an issue after i resolve the first part of my question:-
    which is how do i hide a cloumn in a table and its values so that when the user selects a row i can pass the hidden value of row as part of my form .
    as i mentioned before when i make the cloumn visible as in
      <th><rpb:columnHeader field="TELECARERID"><i18n:getMessage messageName="telecarer_id"/></rpb:columnHeader></th>and give it a visible value:
      <td><netui:label value="{container.item.TELECARERID}"/></td>
           </tr>i can pick up the value fine using the javascript syntax:
    row.cells[4].innerText;however when i hide only the value - which is only part of what i want to do as i want to also hide the column heading so that this part of the table isnt seen- as in:-
    <td><netui:hidden dataInput="{container.item.TELECARERID}" dataSource="" /></td>then i cant use
    row.cells[4].innerText;to pick up the value although it does hide the value and in viewsourec the value is there - is there some other syntax that i should be using here - and also how can i hide the cloumn heading so that the table looks asthtically good on the browser?
    ie. what should i change this line of code to?
      <th><rpb:columnHeader field="TELECARERID"><i18n:getMessage messageName="telecarer_id"/></rpb:columnHeader></th>thanks in advance for any help.

  • Exception:"Decrease the number of char between the beginning of the document and its root element"

    I'm now using a javabean in my jsp page to parse xml;when my xml file's size is
    about 10k,it just work fine;when my xml file's size became 50k,it throws the followng
    Exception:
    Failed to open xml document,Failed to retrieve Public id or system id from the
    document. Decrease the number of char between the beginning of the document and
    its root element. But when I run this javabean in JBuild ,it works fine no matter
    how big the xml file becomes;
    Why? the error message is in the attachment.

    The prologue must be included at the top of the document, followed by the root
              element.
              joden2000 wrote:
              > what does this exception mean:decrease the number of char between the beginning
              > of the document and its root element? When my xml file is about 10k,it works
              > just fine,when it becomes 50k ,the exception show.How can I deal with this?
              

  • I have a question about Lightroom 5... I used it last night, I go to get on it today and its will not open. I have an error msg "Lightroom encountered an error when reading from its preview cache and needs to quit" Lightroom will attempt to fix the proble

    I have a question about Lightroom 5... I used it last night, I go to get on it today and its will not open. I have an error msg "Lightroom encountered an error when reading from its preview cache and needs to quit" Lightroom will attempt to fix the problem when reopened

    https://forums.adobe.com/message/6219922#6219922
    See if the issue in the thread above helps you to solve your problem.

  • When i boot i get a flashing folder with a question mark. disk utility doesnt work or read my harddrives to boot with. i installed a new SSD and its not reading that either. i have a macbook pro 2011, any help?

    So I came to this problem a while ago. M ycomputer basically froze so I was forced to shut down by holding the button down. When I started it up I got the flashing folder with a question mark. I started it up holding down the command and r keys which brought me to disk utility. Although my computer doesn't read that I have a hard drive to start it up. When I click on the disk utility app, I cannot verify or repair anything either. The buttons won't allow me to click on them. It also shows "Mac OSX Base System" which shows I have files and what not saved. I had been told that I need a new hard drive so I bought and manually installed a OWC SSD 240GB drive and when i booted the computer up it booted up yo the operating system fine with all my files and what not on there. After about twenty minutes, it froze again. I forced a shut down, restarted and the same thing happened. I am not able to choose my SSD to boot up, although thats probably because it doesn't have an operating system installed on it??
    i have a Macbook Pro 13" 2011
    any help would be great, I'm overall confused.

    ryansaint11,
    this isn’t Apple support; this is a user-to-user forum. We’re just fellow users of Apple products here.
    If you want to boot from your SSD, then you should put the SSD where your HDD currently is, and put the HDD into the optical bay. (That setup will also get you the best performance.) At the moment, you’re still booting from your HDD. Note that you will need to format your SSD in Disk Utility [with the “Mac OS X Extended (Journaled)” format] so that you can install OS X onto it.
    Since you have an Early 2011 model, it might or might not have originally come with grey installation DVDs. You will be able to find out whether it did or not by trying to use OS X Internet Recovery to install OS X onto your SSD. If it does not work, or if the installed OS turns out to be Snow Leopard, then it will have originally come with the DVDs, and you should purchase a replacement pair of DVDs from Apple or iFixit; those discs will have your MacBook Pro’s Apple Hardware Test and its iLife apps. If the installed OS turns out to be Lion, then it will not originally have come with the grey installation DVDs, and your Apple Hardware Test will be installed along with Lion, and your iLife apps will be downloadable from the Mac App Store.

  • When i plug my ipod in it says ipod cant be read cuz the apple mobile device is not started.And i went to services and apple mobile device properties and start stops in the middle.and its on automatic.and there isnt a stop button.

    when i plug my ipod in it says ipod cant be read cuz the apple mobile device is not started.And i went to services and apple mobile device properties and start stops in the middle.and its on automatic.and there isnt a stop button.when i click start it says the apple mobile device services stopped in the middle then stopped.it said some services stop in the middle if not used by other services.and i just updated itunes before all a this and ever since ive had errors.

    Have you looked at this article:
    iPhone, iPad, iPod touch: How to restart the Apple Mobile Device Service (AMDS) on Windows

  • How to read Images associate with Purchase Requisitions and its Line Items

    Hello,
    My scenario: i need to read the Images associated with PR and its line items and pass them as Idoc FM.
    Any idea where are these images stored in the SAP table or they just available till runtime
    Regards,
    Abhishek

    You can have a look at the link here [GOS Contents|http://help-abap.zevolving.com/2009/02/generic-object-services-gos-toolbar-part-5-get-note-attachment-contents/]
    Please note that in your case if its attachments only then pass la_relat-low = 'ATTA*'. if there is no filtering then pass 'NOTE', 'URL', 'ATTA' as required.
    For the business object of PR pass BUS2105 and instance id pass the PR no.
    The tables related to this are srrelroles,srgbinrel,sood etc.

  • Char and Attributes

    Hi all,
    I am having a requirement wer i need to create the report which include the fields
    PO line item, PO del. date, PO LOI date, and some other char
    Now can i create the PO line item and char and PO del dat, PO LOI dat as attributes of it. Does it works fine.
    Another thing i am getting all the 3  fields from the R3 and v r not any of them as varibles.
    pls suggest me u a optimal solution and let me know the reasons for the same
    Regard

    Priya,
    can i create the PO line item and char and PO del dat, PO LOI dat as attributes of it. is that fine.
    --> Attribute of what..? Create as a characteristics and use.
    what happen if i create every field as a saperate char.
    --> Create as a characteristics only, not attribute.
    when creating the char what the difference between creating by reference char and template.
    --> Template: Copies only technical properties(type, length...ect). For these objects data has to be loaded.
    Reference: Cpies technical properties and also uses same tables from source characteristics, so for these objects no need to maintain data. As it picks data from reference objects.
    You create objects by using template. or if you want to use same master data, create as with reference.
    Hope it Helps
    Srini

Maybe you are looking for

  • "Date Modified" changes in iTunes 11

    Hi.  I'm running iTunes 11 on a Windows 7 machine.  I've noticed that after I close iTunes and reopen it, some of my music files get their "Date Modified" changed as soon as I play the track.  This wouldn't be a problem if it happens once, but for so

  • How to autoextend tablespace in Oracle 9i

    Dear All, I have currenctly a tablespace ABC. Database is failing to writing. I want to alter tablespace ABC and want to make its AUTOEXTEND ON. Could any body please suggest the SQL Query how to do this. Regards,

  • What are the charges if you overrun the monthly data charges on a 2Gb contract for Ipad Air2

    I overran my data allocation by 03 Gb and was told I have now have an additional 1 Gb at $10.  However, It also said to avoid "additional" charges I could retro my acct and add more Gb, but the price would be the same @ $10 per Gb.....what's the poin

  • Running RMI in different networks

    Hi iam developing RMI based application like videoconference system. in this iam able to run the application successfully in the same network . when i try the client from another network iam getting an Exception like connectException iam running the

  • When i open an app it closes immediately how do i fix it

    Every time i click on my snap chat app it opens and then closes a few seconds after. It was working a few hours ago and then all of a sudden stopped. I have tried deleting and downloading it again and also restarting my phone but nothing seems to be