Link to home
Start Free TrialLog in
Avatar of delphi3
delphi3

asked on

Looking for Java Editor

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
Avatar of DragonSlayer
DragonSlayer
Flag of Malaysia image

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.
Avatar of delphi3
delphi3

ASKER

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


Avatar of delphi3

ASKER

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

Delphi3
ASKER CERTIFIED SOLUTION
Avatar of DragonSlayer
DragonSlayer
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of delphi3

ASKER

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
Avatar of delphi3

ASKER

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!
Avatar of delphi3

ASKER



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