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(MalformedURLExceptio n 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("star tx="+messa geX);//db if
(thread == null) { thread = new Thread(this);
thread.setPriority(Thread. MIN_PRIORI TY); } 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().getFontMetri cs(); messageWidth =
fontMetrics.stringWidth(me ssageStrin g); 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,urlS tring.last IndexOf(UR LSeparator ))
+ 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(MalformedURLExceptio n 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(fetchMe ssageStrin g());
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("star tx="+messa geX;//db
if (thread == null) {
thread = new Thread(this);
thread.setPriority(Thread. MIN_PRIORI TY);
}
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().getFontMetri cs();
messageWidth = fontMetrics.stringWidth(me ssageStrin g);
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
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
inLine = null; while ((inLine = dataStream.readLine()) != null){ messageString
+= inLine; } } catch(MalformedURLExceptio
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);
Font("TimesRoman", Font.BOLD, 14)); } /** run */ public void run() { while
(isRunning) { scroll(); try { Thread.sleep(sleepyTime); }
catch(InterruptedException
stop */ public void stop() { if((thread != null) & thread.isAlive()) isRunning =
false; } /** start */ public void start() { setSize(preferredDimension
messageX = getBounds().width; //System.out.printIn("star
(thread == null) { thread = new Thread(this);
thread.setPriority(Thread.
/**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().getFontMetri
fontMetrics.stringWidth(me
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
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,urlS
+ 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(MalformedURLExceptio
showStatus("Invalid URL: " + urlString);
}
catch(IOException e) { // catch IO errors
showStatus("Error " + e);
}
return messageString;
}
/** init */
public void init() {
add(tickerTape);
tickerTape.setText(fetchMe
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
// 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("star
if (thread == null) {
thread = new Thread(this);
thread.setPriority(Thread.
}
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().getFontMetri
messageWidth = fontMetrics.stringWidth(me
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
}
}
Thanks in advance for your reply.
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
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
ASKER
oops,
I forgot to mention that I have D4, standard edition and win2K with NT.
Delphi3
I forgot to mention that I have D4, standard edition and win2K with NT.
Delphi3
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(Ol dName);
C := StringList.Count;
// Removing the white space
for I := 0 to C - 1 do
Str := Str + StringList[I];
with TFileStream.Create(Extract FilePath(A pplication .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('C hug.txt');
//Replaces the note '//' with a words 'InsertNote'
StringList.Text := StringReplace(StringList.T ext,
#32#47#47, #10#32#47#42#42#32#73#110# 115#101#11 4#116#78#1 11#116#101 #32#42#47# 10, [rfReplaceAll]);
//Adds to a ':/' the ':/ 'and does a return
StringList.Text := StringReplace(StringList.T ext,
#32#42#47,#32#42#47#13#10, [rfReplaceAll]);
// Adds to a ';' with a return
StringList.Text := StringReplace(StringList.T ext,
#59, #59#13#10, [rfReplaceAll]);
StringList.SaveToFile(NewN ame);
Edit2.Color := $00FF00;
finally
StringList.Free;
end;
end;
thanks again
Delphi3
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(Ol
C := StringList.Count;
// Removing the white space
for I := 0 to C - 1 do
Str := Str + StringList[I];
with TFileStream.Create(Extract
try
i1 := Length(str);
Write(pointer(str)^, i1);
finally free end;
StringList.Free;
StringList := TStringList.Create;
try
Edit1.Color := ClYellow;
StringList.LoadFromFile('C
//Replaces the note '//' with a words 'InsertNote'
StringList.Text := StringReplace(StringList.T
#32#47#47, #10#32#47#42#42#32#73#110#
//Adds to a ':/' the ':/ 'and does a return
StringList.Text := StringReplace(StringList.T
#32#42#47,#32#42#47#13#10,
// Adds to a ';' with a return
StringList.Text := StringReplace(StringList.T
#59, #59#13#10, [rfReplaceAll]);
StringList.SaveToFile(NewN
Edit2.Color := $00FF00;
finally
StringList.Free;
end;
end;
thanks again
Delphi3
ASKER
Thanks again.
Delphi3
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.T ext,
' //', ' // Insert Note: ', [rfReplaceAll]);
All the best!
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.T
' //', ' // Insert Note: ', [rfReplaceAll]);
All the best!
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
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.