Styling a document as the document is written

Hi all
is it possible to style a styleddocument as i write text to the document,
i know how to style a document that has text already in it, ie find a string then style it, but i want to see if i can have a toString method that provides a formatted styleddocument (something like toStyledString)
so this is my toString code
StyledDocument doc;
JTextPane jTPHolder=new JTextPane();
doc = jTPHolder.getStyledDocument();
something here rather than add to a string to say doc.setText(name) then style name, perhaps find name in the doc then style that?
result=name+"\n";
result=result+"{"+"\n";
for (Enumeration e = atrib.keys(); e.hasMoreElements(); )
String key = (String)e.nextElement();
result=result+key+":";
result=result+atrib.get(key)+";"+"\n";
result=result+"}"+"\n";in the bold is my ideas on possible styling.
is this something that is possible to do or am i approaching it wrong?

First off i made a simple object that i will pass my jtextpane to, for it to do my looping and styling within a thread
import javax.swing.text.*;
import javax.swing.*;
import java.awt.*;
public class CssSyntax implements Runnable
//this is the jtextpane holder
private JTextPane jTPHolder;
//these are my attributes i want to be coloured
private String[] formatAtribs={"font-size", "color", "background-color","background-image","height","width","border-width","border-top-width","border-left-width","border-right-width","border-bottom-width","border-color","border-top-color","border-left-color","border-right-color","border-bottom-color","padding","padding-top","padding-left","padding-right","padding-bottom","margin","margin-top","margin-left","margin-right","margin-bottom","font-family", "font-weight", "font-style","background-repeat","background-attachment","background-position","text-align","vertical-align","text-transform","overflow","white-space","cursor","display","border-style","border-top-style","border-left-style","border-right-style","border-bottom-style","text-decoration","position","top","left","right","bottom","list-style-type","list-style-position"};
//i want to colour brackets too sooooo
private String[] formatBracket={"{","}"};
//ill be passing in names dynamically
private String[] formatNames;
    private StyledDocument doc;
    private Thread animator;
    /** Creates a new instance of CssSyntax */
    public CssSyntax(JTextPane t, String[] tag)
        jTPHolder=t;
        formatNames=tag;       
        doc = jTPHolder.getStyledDocument();
//make my styles for each required colour
        Style style = jTPHolder.addStyle("Tag", null);
        StyleConstants.setForeground(style, Color.blue);
        Color myGreen=new Color(0,128,0);
        style = jTPHolder.addStyle("Bracket", null);
        StyleConstants.setForeground(style, myGreen);
        Color myBrown=new Color(160,0,0);
        style = jTPHolder.addStyle("Atrib", null);
        StyleConstants.setForeground(style, myBrown);
//this is a standard black to prevent the document from being recoloured
        style = jTPHolder.addStyle("Value", null);
        StyleConstants.setForeground(style, Color.black);
//my style document loop
    private void styleDoc()
//colour everything to black to start with to stop any niggling bugs from colouring things blue
     doc.setCharacterAttributes(0, jTPHolder.getText().length(), jTPHolder.getStyle("Value"), true);
//loop through my atributes and colour them
     for (int i=0;i<formatAtribs.length;i++)
            int pos=0;
            while ((pos = jTPHolder.getText().indexOf(formatAtribs, pos)) >= 0)
doc.setCharacterAttributes(pos, formatAtribs[i].length(), jTPHolder.getStyle("Atrib"), true);
pos += formatAtribs[i].length();
//loop through my brackets and colour them
for (int i=0;i<formatBracket.length;i++)
int pos=0;
while ((pos = jTPHolder.getText().indexOf(formatBracket[i], pos)) >= 0)
doc.setCharacterAttributes(pos, formatBracket[i].length(), jTPHolder.getStyle("Bracket"), true);
pos += formatBracket[i].length();
//loop through my names and colour them
for(int i=0;i<formatNames.length-1;i++)
int pos=0;
while ((pos = jTPHolder.getText().indexOf(formatNames[i], pos)) >= 0)
doc.setCharacterAttributes(pos, formatNames[i].length(), jTPHolder.getStyle("Tag"), true);
pos += formatNames[i].length();
//stop the thread when ive done my colouring, if this is removed then the syntax is constantly checked and coloured, but my logic sucks and the whole thing flashes as i colour everything black at the start, maybe i should double buffer or something, but for now i just stop and colour on a save event
stop();
//start my thread so it doesnt hog up my ap
public void start()
     animator = new Thread(this);
     animator.start();
//dunno if this is totally right to be honest, i just nicked it from a thread example :)
public void run()
     while (Thread.currentThread() == animator)
styleDoc();
//apparently this has been deprecated but its here anyway
public void stop()
     animator=null;
now in my code i just do this
CssSyntax colMe=new CssSyntax(jTPCode,workSheet.getTags());
colMe.start();it works for my syntax highlighting and i hope is easy enough for others to grasp a quick and messy way of syntax highlighting.
To all the super brains out there, id be happy for improvements to my code (as im sure there are many!) i know its far far far from efficent, but im learning along the way :) and i hope it helps others work on syntax highlighting without having to resort to those complicated syntax highlighters that are already out there ;)

Similar Messages

  • After i export a pdf file (written in Hebrew) to a Word document, the Word document is written in a Mirror-writing, how can i fix it?

    after i export a pdf file (written in Hebrew) to a Word document, the Word document is written in a Mirror-writing, how can i fix it?

    Hi,
    thank you for your help.
    I am using an Adobe Acrobat XI Pro.
    It is not a specific file that causes trouble, it is happening with all the documents with Hebrew fonts.
    I tried the "Save as" option and the same problem happened.

  • Unable to depoly Web Serivce for the source code written in other editors

    Hi all,
    I am planning to implement webservice with the following code. But I am facing few problems with this can some body help me with this.
    The code looks like this AND IS NOT WRITTEN IN Jdeveloper BUT EDITPLUS
    package package1;
    public class Sum
    public int getSum(int a, int b)
              return a+b;
    package package2;
    public class Sub
    public int getSub(int a, int b)
              return a-b;
    package package3;
    import package1.*;
    import package2.*;
    public class Mul implements TestInterface
         Sum sm = new Sum();
         Sub sb = new Sub();
    public int getMul(int a, int b)
              return sm.getSum(a,b)*sb.getSub(a,b);
    public static void main(String [] args)
              Mul ml = new Mul();
              System.out.println(“The result of (3+6)*(3-6) is “+ ml.getMul(3,6));
    package package3;
    interface TestInterface extends java.rmi.Remote;
         public int getMul(int a, int b) throws java.rmi.RemoteException;
    I have written this in editplus. Not in Jdeveloper.
    Now I want publish getMul() as web service using Jdeveloper.
    I have created a new application work space. And from File--&gt;New
    I have choose project from existing source and imported “package3”.
    At this stage it was unable to find the class files Sum and Sub so I placed Sum.class and Sub.class in Appliction1-Project1-classes-
    Now the Mul class did not have any errors and it compiled fine. When run it gave the correct output.
    Using the web service wizard I was able to generate wsdl file , deployment descriptors etc.
    The problem I was facing was form this stage when I am trying to deploy it on to a standalone oc4j server it is not able generate the WebServices.war file and hence is not deployed on to the server.
    With the same code written in Jdeveloper everything is working fine.
    My doubts are
    1)     why is it not able to generate WebService.war file?
    2)     It is giving some ClassNotFound exception during the deployment. But when compiled and run its giving the correct output.
    3)     Even when everything was written from within the Jdevelper it did not include Sum.calss and Sub.class in WebSevice.war. Is there any way we could mention during its (WebService.war) generation , the class files to be Included.
    The other issue is how to add an existing source code to already existing project. In my case Once I have imported package3 I also want to import package2 and package1 in different steps.
    I thank in advance for helping me.
    Raja Vamshi k Gopu

    Can you tell us what you mean by correct type of project?
    You can start with an empty project. Then, you have to create an "EAR file" deployment profile (New Gallery / General / Deployment Profiles).
    So when I deploy a J2SE module onto oc4j server should I specify the class path? If so where ? How can I solve this problem?
    Once you deploy your code into oc4j, it becomes a J2EE application. You don't need to deal with the classpath - just make sure that all the required code is included in your .war file. To do so, check the list of classes packaged under the deployement properties dialog.
    Can you send me the links of few articles where I can learn more about these kind of stuff?
    If you want to assemble applications without to use JDeveloper wizard, you have another option: using the WebServiceAssembler tool that is par of the oc4j bits will help you to do this from a command line promt, and will handle the J2EE packaging aspect for you.
    See online documentation (10.1.2): http://download-west.oracle.com/docs/cd/B14099_04/web.htm
    In the "Developer's Guide", chapter 9 is about "Web Services Tools"
    For JDeveloper J2EE samples, you can start by looking at the OBE: http://www.oracle.com/technology/obe/obe_as_1012/j2ee/index.html
    Hope this helps,
    Eric

  • Does anyone know how to add a preface page at the beginning of the book in ibooks author once the book is written? No matter how I try to add a Preface page, it goes to the end of the book.

    Does anyone know how to add a preface page at the beginning of the book in ibooks author once the book is written? No matter how I try to add a Preface page, it goes to the end of the book.

    Thanks. I've tried this and apparently the template I'm using is one of those where it doesn't work. I've tried dragging it as well as cutting a pasting but it always travels back to the end of the book. Maybe I can try changing the template temporarily, move the preface page, and then convert back to the original template. I'll experiment a little.

  • Sender file communication channel polling only when the file is written

    Hi guys,
    I have the following scenario:
    I have developed an XI interface that takes a .txt file from SAP R/3's file system, usr/sap/trans/ and delivers it into another ftp location. The problem that we face is that the file is written into source directory from an ABAP program. As a result, XI go and polls into source directory when the file is not completely written, or when it is empty, which blocks the process.
    Is there a way to force XI in order to poll the source directory only when the file is complete?
    We have thought of exporting the file into a name that XI does not expect and as soon as the file is complete to rename the file from inside ABAP program into what XI expects.
    However, the command inside ABAP changed the Code page of the file and we cannot see some special characters in the file that is delivered to the ftp location.
    Any ideas??

    Hi Evaggelos,
    from <a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/e3/94007075cae04f930cc4c034e411e1/content.htm">SAP help: Configuring the Sender File/FTP Adapter</a>:
    Advanced Mode
    To specify additional parameters in the adapter configuration, set the Advanced Mode indicator.
    &#9679;      Msecs to Wait Before Modification Check
    Enter the number of milliseconds that the adapter must wait before it checks whether the files have been changed
    Regards,
    Udo

  • Accessing a .csv file in vi while the data is written by 3rd party java applicaito​n

    Hi
    I have a requirement like below explained.
    A java applicaiton reads data from hardware and writes in a .csv file. This java applicaiton is triggered by a button click in Labview VI.
        --> cmd window   -- cmd /C java Client n
    the data will be read from hardware and written to the file per every second.
    In the labview vi, we are reading the .csv file simultaneously and plotting the graph. 
    The above operations need to happen simultaneously. 
    When we tried this, we are geeting the "File Not Found Excpetion(the file is used by other process) in java application.
    Can anyone help me why this might be happening in Labview. I tried this with a "c" applicaiton instead of Labview and it is working fine.
    Problem observed only with labivew.
    Regards
    Kris

    Naah, I said, that will never work.  But to my shock and (pleasant) surprise, it does!  Here is a snippet of a little routine I cobbled together using LabVIEW for both the Writer and the Reader.
    The Writer is on top.  It creates a Temp.txt file on my Temp directory, deletes it if it is already there, then opens it for writing.  There's a boolean "Done" flag that tells me when the Writer finishes, so I clear it before entering the Writing Loop.  Here, every half-second, I write the sequential numbers 0 .. 9, with a New Line to create a Text File of Lines.  When I'm finished, I close the file.
    Below this is the Reader Loop, designed to start after the Writer Loop has opened (and created) the file.  Here we open the same file in Read-Only mode.  The Reader Loop also goes 10 times (I could have built in a Stop condition, but this is only a Proof-of-Concept).  The loop is initialized with the current File Position (0) in a Shift Register.  The inner While Loop is a "Wait for Data to Appear", a loop which checks 10 times a second to see if the File Position has changed, exiting when it does (meaning the Writer has Written Something).  It then reads a line from the File (the Read Text function has its "Read Lines" property set) and displays it.
    When you run this, you will see the Reader's output, Line, count up, 0 .. 9, and then the program stops with no errors.  What fun!
    Bob Schor

  • I have a rectangle with the word caption written twice on it which appears on my page and obscures my information - how can I get rid of this please?

    I have a rectangle with the word 'caption' written twice on it which appears on my page and obscures my information. How can I get rid of it please?

    Can you post the URL so we can test the page and look at its code?

  • Import the last row written in a database

    Hello!
    I want know what i have to do to import the last row written in a table from a MySQL database.
    I'm using labview database toolkit.
    Thank you in advanced.
    Larson

    Hi Larson
    I total agree that my first suggestion isn't what you want but I wanted to put the idea across that you can retrieve records from table in the order they were written using a simple SQL command.
    When dealing with databases I always design my queries using Design View in MS Access. Once you have the query designed you can then convert the query you have just designed in Design View to SQL by changing to SQL View.
    So this example SQL statement would return the MAX Timestamp.
    SELECT Max(tblTimeStampTest.Timestamp) AS MaxOfTimestamp
    FROM tblTimeStampTest;
    Say the timestamp was 12/14/2005 8:18:33
    SELECT tblTimeStampTest.*
    FROM tblTimeStampTest
    WHERE (((tblTimeStampTest.Timestamp)=#12/14/2005 8:18:33#));
    This will return your last record as long at the timestamps are unique and records are written in timestamp order. You can then use Build Text Express VI or Format into String to build your SQL strings that have variables like the timestamp above.
    I have no experience with mySQL but I would assume MS Access could interface to it somehow either through ODBC or MS Access Projects so that can build you SQL commands.
    David

  • I've got the labview vi written to read my IMU data from a serial port in COM1 and it displays onto the table on the front panel. I'm having trouble getting this data onto an excel spreadshee​t. Any ideas?

    I've got the labview vi written to read my IMU data from a serial port in COM1 and it displays onto the table on the front panel. I'm having trouble getting this data onto an excel spreadsheet. Any ideas? Right now my data will collect one reading instead of continuously reading my IMU which displays data in a continuous stream.
    Thanks
    Attachments:
    Read_IMU_Drew.vi ‏21 KB

    Hi
    Your vi is in 2009 version, which i am unable to open in 8.6
    However, if you want your data to be saved in excel sheet, here is the VI
    Somil Gautam
    Think Weird
    Attachments:
    save to excel.vi ‏12 KB

  • I got this weird screen with all of those weird signs a and don't know what that means. Anybody knows? By the way, in the white square written "confirm". Thanks in advance!

    I got this weird screen with all of those weird signs a and don't know what that means. Anybody knows? By the way, in the white square written "confirm". Thanks in advance! By the way, it happened three times already !

    Hi KLB,
    Welcome to the forum. I would like to look into this for you. Please could you send me in your details using the link found in the "About Me" section of my profile?
    Thanks
    PaddyB
    BTCare Community Mod
    If we have asked you to email us with your details, please make sure you are logged in to the forum, otherwise you will not be able to see our ‘Contact Us’ link within our profiles.
    We are sorry but we are unable to deal with service/account queries via the private message(PM) function so please don't PM your account info, we need to deal with this via our email account :-)

  • I want to be able to tweak the graphic equalizer in real time while recording - and have this have the audible effect written to the recording.   At the moment i have to go into post-production and manually set the graph equalizer at various time points .

    i want to be able to tweak the graphic equalizer in real time while recording - and have this have the audible effect written to the recording.
    At the moment i have to go into post-production and manually set the graph equalizer at various time points ...

    This won't be real-time as you record, but you could tweak the EQ in real-time after the recording thus:
    Record what you want to tweak into GB with no effects.
    Solo the track and output it into something like Audacity.
    Start Audacity recording, then play your track in GB as you make those tweaks. That's what Audacity will record.
    Get that file from Audacity and put it into GB, then you'll have that effect.
    Sorry if it's complicated, but that's what came to mind. Hope it works.

  • Capturing the errro message written to stderr by a 'C' binary ..

    Hi Fello Developers,
    I've tried using Runtime.exec to execute a 'C' binary from Java.
    I am getting the normal output written by the 'C' binary to STDOUT.
    I am using process.getInputStream(); to read the output returned by the 'C' binary.
    But when the 'C' binary is written the error messages to stderr, I am unable to capture them through process.getInputStream();
    Can some one help in this regard ?
    Thanks and regards,
    - mailtork

    It just working fine.good.
    Thank you once again.You're welcome of course; have a good Weekend yourself too and,
    kind regards,
    Jos

  • I need a BADI that's called after Shipment Cost Document is written...

    Hi,
    I'm trying to locate a BADI that gets called after a Shipment Cost Document is created ( Written to file ) OR one that gets called before the lines are transfered to invoicing.
    I need to alter some of the data on tables VFKP items & VFKN acct determination.  We are getting condiotions with zero prices that I need to remove.
    Any suggestions appreciated......

    You will probably not find a BADI to suit your needs.  However if you look at include program MV45AFZZ you should find two subroutines:  USEREXIT_SAVE_DOCUMENT_PREPARE and USEREXIT_SAVE_DOCUMENT.  You can put the code you need directly into these subroutines.  If these have not been changed yet on your system, you will need an access key to make these changes.
    Please read the documentation in the header of the subroutines for furtner information on when they are called.
    Best Regards,
    Chris H.

  • My documents are written in Arabic language which should be read from right to left, so how can I create a flipbook with flipping pages from right to left?

    We want to make it flipping like Arabic books, from the end to the begin, or from right to left. Is it possible?

    I don't think so.   You can ask Apple to add this feature
    http://www.apple.com/feedback/ibooks-author.html
    Have you actually been composing Arabic in iBooks Author?  It has various bugs with RTL scripts that could make that difficult:
    http://m10lmac.blogspot.com/2012/01/new-ibook-author-app-has-same-rtl-bugs.html

  • I have an email validation script on my page and a populate form fields script that doesn't work unless it's the only script written. Here are the scripts. Thanks

              <script type="text/javascript"><!--
    function validateForm() {
    with (document.drbrake) {
    var alertMsg = "The following REQUIRED fields\nhave been left empty:\n";
    if (fullname.value == "") alertMsg += "\nfullname";
    if (emailcheck.value == "") alertMsg += "\nemailcheck";
    if (telephone.value == "") alertMsg += "\ntelephone";
    if (selectproduct.value == "") alertMsg += "\nselectproduct";
    if (problem.value == "") alertMsg += "\nproblem";
    if (alertMsg != "The following REQUIRED fields\nhave been left empty:\n") { alert(alertMsg);
    return false;
    } else {
    return true;
    // -->
    </script>
            <script language="JavaScript1.2">
    //Advanced Email Check credit-
    //By JavaScript Kit (http://www.javascriptkit.com)
    //Over 200+ free scripts here!
    var testresults
    function checkemail(){
    var str=document.validation.emailcheck.value
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$ /i
    if (filter.test(str))
    testresults=true
    else{
    alert("Please input a valid email address!")
    testresults=false
    return (testresults)
            </script>
                                <script>
    function checkbae(){
    if (document.layers||document.getElementById||document.all)
    return checkemail()
    else
    return true
    </script>

    I do see issues with the script, but do you realize that HTML5 has all this capability build in, so not a single bit of the code you posted is needed? Of course there may be a reason you are doing it the way you are, but I don't know what that reason would be.
    In your forms, you can simply add "required" to an input field to make it required. And by making an email field the email type, it will automatically be validated for correctness. See below:
    <input type='text' value='<?php echo last_name ?>' name='last_name' required />
    <input type='email' value='<?php echo email ?>' name='email' required />
    Assuming that your form is processed by PHP, you would then use further validation in PHP. But the HTML5 validation is just as good as javascript validation and easier to use.
    With the HTML5 validation, all fields remain populated and the form cannot be submitted if anything fails validation.  I added the value attribute to the input examples because normally, if the PHP validation fails, you want to re-populate the form with what is stored in the POST array.

Maybe you are looking for

  • Very bad bluetooth connection with car

    I also have major back ground noise when connecting new 2730 classic (Software 10.40) to blue tooth in car (Mercedes C204) I tryed it with with some other Mercedes (E-Class an B-Class) and my old Medion Navigation system - same problem- can't underst

  • How do I apply textFormat to a single line in a textField.

    I have very little experience with text in flash. In a dynamic text field I know I can apply a TextFormat to the entire field but can I apply different fromatting to individual workd in the field if for example I wanted to make a word or a few words

  • Ora-1000 max openCursor exceeded

    Hi, i have a question about the ora-1000. My prog is a "C"-coded Programm. Which is connected to the database. After few days the Ora-message ora-1000 will be shown in the tracefile. The Parameter Max open Cursor is meanwhile set 1000. Knows anyone t

  • Dual Core Intel iMac 10.5.5 suddenly sees no firewire video decks

    We have 7 iMacs used in a general area for students to digitize. This week NONE of them will see any sort of video deck or camera through the firewire port. I did repair permissions, unplugged everything for 10 minutes (including power), zapped the p

  • TS3276 Mail app says my imap.google is not responsive

    I have gone through the following steps and am unable to still have the app recognize my google imap. Any suggestions?