We help IT Professionals succeed at work.

Looking for Java Editor

delphi3
delphi3 asked
on
Hi All,

I took this Q to the programming in java group and  I am not satisfied with their responsed, so I  
thought I would ask someone who maybe written a Delphi program that would do the task.

I am looking for an editor that will  take a text that is presented as a unformatted text (1.)  and get it to
look like (2.)  
1.
/** * @version 0.3, 13 Apr 1997 * ? 1996 by * ISC Consultants Inc., all rights
reserved. */ import java.awt.*; import java.applet.Applet; import java.net.*;
import java.io.*; /** TickerApplet */ public class TickerApplet extends Applet {
private final static char URLSeparator = '/'; private String messageFile =
"message.txt"; private TickerTape tickerTape = new TickerTape(); /** fetch
Message String */ private String fetchMessageString() { String messageString =
new String(); // construct the URL of the message file String urlString =
getCodeBase().toString(); urlString = urlString.substring( 0,
urlString.lastIndexOf( URLSeparator)) + URLSeparator + messageFile; // fetch the
message file try { URL url = new URL(urlString); InputStream inStream =
url.openStream(); BufferedReader dataStream = new BufferedReader(new
InputStreamReader(inStream)); // stuff the message into messageString String
inLine = null; while ((inLine = dataStream.readLine()) != null){ messageString
+= inLine; } } catch(MalformedURLException e) { // catch bad URL's
showStatus("Invalid URL: " + urlString); } catch(IOException e) { // catch IO
errors showStatus("Error " + e); } return messageString; } /** init */ public
void init() { add(tickerTape); tickerTape.setText( fetchMessageString()); } /**
start */ public void start() { tickerTape.start(); } /** stop */ public void
stop() { tickerTape.stop(); } } /* TickerTape class */ class TickerTape extends
Canvas implements Runnable { private Dimension preferredDimension = new
Dimension(400,10); private int messageWidth; private int messageX; private int
messageY; private int currentX; private int sleepyTime = 50; private int
scrollStep = 2; private final static int INSET = 2; private String messageString
= "Default Message"; private Thread thread; private boolean isRunning = false;
/** constructor */ public TickerTape() { thread = null;
setBackground(Color.blue); setForeground(Color.white); setFont(new
Font("TimesRoman", Font.BOLD, 14)); } /** run */ public void run() { while
(isRunning) { scroll(); try { Thread.sleep(sleepyTime); }
catch(InterruptedException e) { // caught an exception } } thread = null; } /**
stop */ public void stop() { if((thread != null) & thread.isAlive()) isRunning =
false; } /** start */ public void start() { setSize(preferredDimension);
messageX = getBounds().width; //System.out.printIn("startx="+messageX);//db if
(thread == null) { thread = new Thread(this);
thread.setPriority(Thread.MIN_PRIORITY); } isRunning = true; thread.start(); }
/**scroll*/ private void scroll() { // if the message has scrolled off the edge
// of the canvas, wrap it around if(messageX < (-messageWidth)) { messageX =
getBounds().width ; } else { messageX = messageX - scrollStep; } repaint(); }
/**setext*/ public void setText(String s) { messageString = new String(s);
FontMetrics fontMetrics = getGraphics().getFontMetrics(); messageWidth =
fontMetrics.stringWidth(messageString); messageY = fontMetrics.getHeight() -
fontMetrics.getDescent() + INSET; preferredDimension.height =
fontMetrics.getHeight() + (INSET * 2); } /** Return the Ticker's preferred size
*/ public Dimension getPreferredSize() { return preferredDimension; } /** Return
the Ticker's minimum size */ public Dimension getMinimumSize() { return
preferredDimension; } /**paint*/ public final void paint(Graphics g) {
g.drawString(messageString,messageX,messageY); } }



2.

/**
 *  @version 0.2
 */

import java.awt.*;
import java.applet.Applet;
import java.net.*;
import java.io.*;

/** TickerApplet */
public class TickerApplet extends Applet {

    private final static char URLSeparator = '/';
    private String messageFile = "message.txt";
    private TickerTape tickerTape = new TickerTape();

        /** fetch Message String */
private String fetchMessageString() {
   String messageString = new String();
   // construct the URL of the message file
   String urlString = getCodeBase().toString();
   urlString = urlString.substring(0,urlString.lastIndexOf(URLSeparator))
            + URLSeparator + messageFile;
   // fetch the message file
        try {
            URL url = new URL(urlString);
            InputStream inStream = url.openStream();
            BufferedReader dataStream =
            new BufferedReader(new InputStreamReader(inStream));
            // stuff the message into messageString
            String inLine = null;
            while ((inLine = dataStream.readLine()) != null){
                messageString += inLine;
            }
        }
        catch(MalformedURLException e) { // catch bad URL's
            showStatus("Invalid URL: " + urlString);
        }
        catch(IOException e) { // catch IO errors
            showStatus("Error " + e);
        }
        return messageString;        
}

    /** init */
    public void init() {
        add(tickerTape);
        tickerTape.setText(fetchMessageString());
        tickerTape.start();
    }


    /** stop */
       public void stop() {
        tickerTape.stop();
    }
}

/* TickerTape class */
class TickerTape extends Canvas implements Runnable {

    private Dimension preferredDimension = new Dimension(400,10);
    private int messageWidth;
    private int messageX;
    private int messageY;
    private int currentX;
       private int sleepyTime = 50;
    private int scrollStep = 2;
    private final static int INSET = 2;
    private String messageString = "Default Message";
    private Thread thread;
    private boolean isRunning = false;

    /** constructor */
       public TickerTape() {
        thread = null;
        setBackground(Color.blue);
        setForeground(Color.white);
        setFont(new Font("TimesRoman", Font.BOLD, 14));
    }

    /** run */
public void run() {
    while (isRunning) {
        scroll();
        try {
                Thread.sleep(sleepyTime);
        }  
        catch(InterruptedException e) {
        // caught an exception
        }
    }
}

    /** stop */
       public void stop() {
        if((thread != null) && thread.isAlive()) {
            thread.stop();
            thread = null;
            isRunning = false;
        }
    }

    /** start */
       public void start() {
       setSize(preferredDimension);
             messageX = getBounds().width;
             //System.out.printIn("startx="+messageX;//db
             if (thread == null) {
            thread = new Thread(this);
           thread.setPriority(Thread.MIN_PRIORITY);
        }
        isRunning = true;
        thread.start();
    }

    /**scroll*/
       private void scroll() {
// if the message has scrolled off the edge of the canvas, wrap it around
            if(messageX < (-messageWidth)) {
                messageX = getBounds().width ;
             }
            else {
            messageX = messageX - scrollStep;
             }
       repaint();
    }
   

    /**setext*/
       public void setText(String s) {
        messageString = new String(s);
        FontMetrics fontMetrics = getGraphics().getFontMetrics();
        messageWidth = fontMetrics.stringWidth(messageString);
     messageY = fontMetrics.getHeight() - fontMetrics.getDescent() + INSET;
        preferredDimension.height = fontMetrics.getHeight() + (INSET * 2);
    }

    /** Return the Ticker's preferred size */
    public Dimension getPreferredSize() {
        return preferredDimension;
    }

    /** Return the Ticker's minimum size */
    public Dimension getMinimumSize() {
        return preferredDimension;
    }

       /**paint*/
       public final void paint(Graphics g) {
        g.drawString(messageString,messageX,messageY);
    }
}


Thanks in advance for your reply.

Delphi3
Comment
Watch Question

Oh, that's very easy... you can even write a simple programme to do it... just load up the file, replace all ASCII 10 (LineFeed) characters with the ASCII 13 and ASCII 10 characters (CarriageReturn + LineFeed).

For most of my editing tasks, I use UltraEdit (www.ultraedit.com), and it can load these files correctly... if it's a UNIX file (with only LineFeed), it will even save it correctly as a UNIX file... of course it also has the ability to permanently convert UNIX to DOS format and vice versa.

Author

Commented:
Hi DragonSlayer,
Thanks for your interest.

Please, if it is easy, please indicate a snippet of code that you are suggesting. A procedure processing a memo that contains the data.
Thanks

Delphi3


Author

Commented:
oops,
I forgot to mention that I have D4, standard edition  and win2K with NT.

Delphi3
ok ok, here's an easy example... I don't know how it will 'react' to a huge file, though :)

uses
  SysUtils;

procedure ProcessFile(const OldName, NewName: string);
var
  StringList: TStringList;
begin
  StringList := TStringList.Create;
  try
    StringList.LoadFromFile(OldName);
    StringList.Text := StringReplace(StringList.Text,
      #10, #13#10, [rfReplaceAll]);
    StringList.SaveToFile(NewName);
  finally
    StringList.Free;
  end;
end;

Note that I did not perform any checking to see whether or not a file exists.

Hope it helps!



DragonSlayer.

Author

Commented:
DragonSlayer,

Thanks for your interest and help
I have settled on some form of this and it is still evolving, and I have not done any checking.



procedure TForm1.ProcessFile(const OldName, NewName: string; Sender: TObject);
var
  StringList: TStringList;
  i1, I, C: integer;
  Str: string;
begin
  StringList := TStringList.Create;
  StringList.LoadFromFile(OldName);
  C := StringList.Count;
  // Removing the white space
  for I := 0 to C - 1 do
    Str := Str + StringList[I];
  with TFileStream.Create(ExtractFilePath(Application.exeName) + 'Chug.txt', fmCreate) do
  try
    i1 := Length(str);
    Write(pointer(str)^, i1);
  finally free end;
  StringList.Free;
  StringList := TStringList.Create;
  try
    Edit1.Color := ClYellow;
    StringList.LoadFromFile('Chug.txt');
    //Replaces the note '//'  with a words 'InsertNote'
    StringList.Text := StringReplace(StringList.Text,
      #32#47#47, #10#32#47#42#42#32#73#110#115#101#114#116#78#111#116#101#32#42#47#10, [rfReplaceAll]);
    //Adds to a ':/' the ':/ 'and does a return
    StringList.Text := StringReplace(StringList.Text,
      #32#42#47,#32#42#47#13#10, [rfReplaceAll]);
    // Adds to a ';' with a return
    StringList.Text := StringReplace(StringList.Text,
      #59, #59#13#10, [rfReplaceAll]);
    StringList.SaveToFile(NewName);

    Edit2.Color := $00FF00;
  finally
    StringList.Free;
  end;
end;


thanks again
Delphi3

Author

Commented:
Thanks again.

Delphi3
Sorry Delphi3, something was wrong with EE and I was unable to log in until now.

Well, actually for StringReplace you need not put in the ASCII value if it is a normal ASCII character.

e.g.

StringList.Text := StringReplace(StringList.Text,
  ' //', ' // Insert Note: ', [rfReplaceAll]);


All the best!

Author

Commented:


Yes, I can attest that things at EE are a bit difficult. For me I have to keep clicking error messages , java script errors,
 out of my way so that I can read the file that my Netscape 4.0 browser keeps bumping up against. Furthermore, almost  every time I logon to EE I have to issue my EE name and password.
As for all the char #'s  I think, when I have to make a CrLf = #13#10 then I am all in the same realm of presentation without mixing form. No matter, and thanks again.

Delphi3

Explore More ContentExplore courses, solutions, and other research materials related to this topic.