Re: Multiple foreground colors in AWT TextArea?
Hi Qu0ll,
"Qu0ll" <Qu0llSixFour@gmail.com> wrote in message
news:4a8169f5$0$22812$5a62ac22@per-qv1-newsreader-01.iinet.net.au...
"Richard Maher" <maher_rj@hotspamnotmail.com> wrote in message
news:h5rovm$l5a$1@news-01.bur.connect.com.au...
Hi,
I would like to be able to specify a different color for each line in an
AWT
TextArea. As this doesn't seem possible, can someone please advise me of
the
easiest way of achieving this sort of with standard AWT widgets?
I started to read up on 2D graphics and TextAttributes and
AttributedStrings
but it all began to look complicated :-(
I have a console (TextArea a present but can change) that's logging
status
messages and I'd like to have some green/red etc.
Does it have to be AWT? There are Swing components which permit
colouring.
If you are limited to AWT then you may have to use a Canvas and handle the
coloured text rendering explicitly.
Stuck with AWT at the moment as it's all I know(ish). Although the interface
is vary basic: -
/**
* Copyright Tier3 (c) Software. All rights reserved.
*
* Display "Welcome" dialogue after successful User authorization.
*
* @author Richard Maher
* @version 1.0
*
*/
package tier3Client;
interface Tier3UserDialog {
boolean doCredentials();
String getUsername();
String getPassword();
boolean isWelcomeRequired();
void doWelcome(byte[] t3IdBuf);
void doConsole(byte[] t3IdBuf,
Tier3Logoff sourceSession,
String codeHost,
int portNum);
void updateRcvd(int bytes);
void updateSent(int bytes);
void showRefCnt(int pages);
void closeConsole();
}
And there is an Applet parameter that let's you specify a GUI Toolkit (Of
which there is only AWT at the moment :-) See below. *The rendezvous method
for async send completion* functionality shaping up to be just too sexy for
words!
-Qu0ll (Rare, not extinct)
Regards Richard Maher
/**
* Copyright (c) Richard Maher. All rights reserved.
*
*/
function Tier3Client(application,
codeBase,
port,
maxBuf,
hostCharSet,
sslReqd,
guiToolkit,
idleTimeout,
verbosity)
{
if (arguments.length < 4) {
throw new Error("Insufficient arguments for Tier3Client");
}
this.facPrefix = "T3$";
this.application = application;
this.codeBase = codeBase;
this.port = port;
this.maxBuf = maxBuf;
if (hostCharSet == undefined) {
this.hostCharSet = "ISO-8859-1";
} else {
this.hostCharSet = hostCharSet;
}
if (sslReqd == undefined) {
this.sslReqd = "N";
} else {
this.sslReqd = sslReqd;
}
if (guiToolkit == undefined) {
this.guiToolkit = Tier3Client.GUIAWT;
} else {
this.guiToolkit = guiToolkit;
}
if (idleTimeout == undefined) {
this.idleTimeout = 0;
} else {
this.idleTimeout = idleTimeout;
}
if (verbosity == undefined) {
this.verbosity = Tier3Client.FATAL;
} else {
this.verbosity = verbosity;
}
var appletId = "Tier3__" + application + "_Applet";
try {
var idTaken = document.getElementById(appletId);
}
catch (err) {};
if (idTaken != null) {
throw new Error("Tier3 Client already registered for " +
this.application);
return;
}
var archiveName = "tier3Client.jar";
var className = "tier3Client/Tier3Application";
var appletParams = [{"name":"archive",
"value":archiveName },
{"name":"codebase",
"value":codeBase },
{"name":"code",
"value":className },
{"name":"mayscript",
lue":"true" },
{"name":"scriptable",
ue":"true" },
{"name":"codebase_lookup",
"false" },
{"name":"APPLICATION",
"value":application },
{"name":"PORT",
"value":port },
{"name":"MAXBUF",
"value":maxBuf },
{"name":"HOSTCHARSET",
"value":this.hostCharSet},
{"name":"SSLREQD",
"value":this.sslReqd },
{"name":"GUITOOLKIT",
"value":this.guiToolkit },
{"name":"IDLETIMEOUT",
"value":this.idleTimeout},
{"name":"VERBOSITY",
"value":this.verbosity }];
var startParam = 0;
var objectTag = "<object classid=";
if (/Internet Explorer/.test(navigator.appName)) {
objectTag = objectTag +
'"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" ';
} else {
objectTag = objectTag +
'"java:' + className + '.class" type="application/x-java-applet
" ' +
'archive="' + codeBase + archiveName + '"';
startParam = 1;
}
objectTag = objectTag + ' width= "0" height= "0" id="' + appletId +
'">';
for (i=startParam; i<appletParams.length; i++){
objectTag = objectTag + '<param name ="' + appletParams[i].name +
'" ' +
'value ="' + appletParams[i].value +
'">';
}
objectTag = objectTag + "</object>";
var appletDiv = document.createElement("div");
appletDiv.innerHTML = objectTag;
try {
document.body.appendChild(appletDiv);
this.chan = document.getElementById(appletId);
}
catch(err) {
alert("Tier3 unable to load applet for " + this.application +
": -\n" + err.description);
this.chan = null;
};
if (this.chan == null) {
throw new Error("Tier3 was unable to initialize the applet for " +
this.application);
} else {
try {
if (!this.chan.isAuthorized()) {
throw new Error("Tier3 User authentication unsuccessful for
" + this.application);
}
}
catch(err) {
this.chan = null;
throw new Error("Tier3 unable to load applet for " +
this.application);
}
}
Tier3Client.applications[this.application] = this;
return this;
}
Tier3Client.MAJVERS = 1;
Tier3Client.MINVERS = 0;
Tier3Client.GUIAWT = 1;
Tier3Client.FATAL = 0;
Tier3Client.errorPage = "Tier3Error.html";
Tier3Client.logoffPage = "Tier3Logoff.html";
Tier3Client.launder =
function(jsobject) {
return jsobject;
};
Tier3Client.prototype = {
send:
function(msgBody, callback, async)
{
if (arguments.length < 2) {
throw new Error("Insufficient arguments for send(msgBody,
callback)");
}
if (typeof callback != "function") {
throw new Error("The 'callback' parameter must be a
function");
}
var noWait = true;
if (arguments.length > 2) {
if (typeof async != "boolean") {
throw new Error("The 'async' parameter must be a
boolean");
}
noWait = async;
}
var chan = this.chan;
var callbackArgs = new Array();
var responseCnt = 0;
var i = 0;
var msgCandidate =
{
msgSlotId : -1,
msgSeqNum : -1,
chan : chan,
callback : callback,
callbackArgs : callbackArgs,
dispatcher :
function(responseMsg,
msgSlotId,
msgSeqNum)
{
this.responseCnt++;
this.msgSlotId = msgSlotId;
this.msgSeqNum = msgSeqNum;
callbackArgs[0] = responseMsg;
try {
callback.apply(this, callbackArgs);
}
catch (err) {
throw new Error("Error calling callback
routine: -\n" + err.description);
}
},
getMsgSeqNum :
function() {
return this.msgSeqNum;
},
getResponseCnt:
function() {
return this.responseCnt;
},
rendezvous :
function() {
return chan.rendezvous();
}
};
for (i=3; i<arguments.length; i++) {
callbackArgs[i - 2] = arguments[i];
}
return chan.send(msgCandidate, msgBody, noWait);
}
};
Tier3Client.applications = {};