📄 displayengine.java
字号:
i = drawImage(g,i,false,"0");
// g.setColor(Color.darkGray);
// g.drawString(clsScreen.elementAt(i).toString(),x,y);
// g.setColor(Color.black);
}
else if (clsScreen.elementAt(i).toString().equals(END_TAG_IMG))
{
//dont need to do anything here at this stage
}
else if(clsScreen.elementAt(i).toString().equals(START_TAG_TABLE))
{
try {
i = drawTable(g,i);
}
catch(Exception e) {
System.out.println("Error in table " + e);
}
}
else if(clsScreen.elementAt(i).toString().equals(START_TAG_SELECT))
{
i = drawSelect(g,i);
}
else if(clsScreen.elementAt(i).toString().equals(START_TAG_A))
{
try {
System.out.println("found A tag");
i = drawA(g,i);
}
catch(Exception e) {
System.out.println("Error in A " + e);
}
}
else if(clsScreen.elementAt(i).toString().equals(START_TAG_ANCHOR))
{
try {
System.out.println("found anchor");
i = drawAnchor(g,i);
}
catch(Exception e) {
System.out.println("Error in anchor " + e);
}
}
else if(clsScreen.elementAt(i).toString().equals(START_TAG_DO))
{
i = drawDo(g,i);
}
else if(clsScreen.elementAt(i).toString().equals(START_TAG_CARD))
{
i = handleCard(g,i); //handles the begin card tag
c_intDoFound=0; //sets the number of do found in this card to 0
}
else if(clsScreen.elementAt(i).toString().equals(END_TAG_CARD))
{
if (bolTimer)
{
c_timerDelay=c_timerDelay * 100; //since sleep takes in milliseconds
Thread clsth = Thread.currentThread();
clsth.sleep(c_timerDelay);
bolEvents = true;
}
}
else if(clsScreen.elementAt(i).toString().equals(START_TAG_INPUT))
{
i = drawInput(g,i);
}
else if(clsScreen.elementAt(i).toString().equals("<b>"))
{
// try {
// setFont(new Font("SansSerif",Font.BOLD,12));
// }
// catch(Exception e) {
// System.out.println("Error in anchor " + e);
// }
}
else if(clsScreen.elementAt(i).toString().equals("<u>"))
{
}
else if(clsScreen.elementAt(i).toString().equals("</u>"))
{
}
else if(clsScreen.elementAt(i).toString().equals("<small>"))
{
}
else if(clsScreen.elementAt(i).toString().equals("</small>"))
{
}
else if (clsScreen.elementAt(i).toString().equals("</b>"))
{
// setFont(new Font("SansSerif",Font.PLAIN,12));
}
else if (clsScreen.elementAt(i).toString().equals(START_TAG_TIMER))
{
i = handleTimer(i);
}
else
{ //normal text here, word wrapping is done here too
clsWords = split(" ",clsScreen.elementAt(i).toString());
drawNormalText(g,clsWords,intIndent);
}
}
//System.out.println("End of draweverything");
}
catch (Exception e)
{
System.out.println("draweverything threw a " + e.getClass() + " with message: " + e.getMessage());
}
// this.setSize(new Dimension(160,y)); //should change the panel size dynamically.. should change
//the size of the scrollpane too automatically
bolRepaintNeeded = false;
bolRunOnce = true;
}
/**
Sets the name and major version number of the operative system
*/
public void SetOs(String strOs,int intMajor)
{
c_strOs = strOs;
c_intMajor = intMajor;
}
/**
Gets the name of the operative system
*/
public String GetOSName()
{
return c_strOs;
}
/**
Gets the major version number of the operative system
*/
public int GetOsVersion()
{
return c_intMajor;
}
}
interface WMLStringTags
{
// WML start tags as Strings.
public static final String START_TAG_A = (String) "<a>";
public static final String START_TAG_TD = (String) "<td>";
public static final String START_TAG_TR = (String) "<tr>";
public static final String START_TAG_TABLE = (String) "<table>";
public static final String START_TAG_P = (String) "<p>";
public static final String START_TAG_POSTFIELD = (String) "<postfield>";
public static final String START_TAG_ANCHOR = (String) "<anchor>";
public static final String START_TAG_ACCESS = (String) "<access>";
public static final String START_TAG_BR = (String) "<br>";
public static final String START_TAG_CARD = (String) "<card>";
public static final String START_TAG_DO = (String) "<do>";
public static final String START_TAG_FIELDSET = (String) "<fieldset>";
public static final String START_TAG_GO = (String) "<go>";
public static final String START_TAG_HEAD = (String) "<head>";
public static final String START_TAG_IMG = (String) "<img>";
public static final String START_TAG_INPUT = (String) "<input>";
public static final String START_TAG_NOOP = (String) "<noop>";
public static final String START_TAG_PREV = (String) "<prev>";
public static final String START_TAG_ONEVENT = (String) "<onevent>";
public static final String START_TAG_OPTGROUP = (String) "<optgroup>";
public static final String START_TAG_OPTION = (String) "<option>";
public static final String START_TAG_REFRESH = (String) "<refresh>";
public static final String START_TAG_SELECT = (String) "<select>";
public static final String START_TAG_NULL = (String) "<null>";
public static final String START_TAG_TEMPLATE = (String) "<template>";
public static final String START_TAG_TIMER = (String) "<timer>";
public static final String START_TAG_SETVAR = (String) "<setvar>";
public static final String START_TAG_WML = (String) "<wml>";
// WML end tags as Strings.
public static final String END_TAG_A = (String) "</a>";
public static final String END_TAG_TD = (String) "</td>";
public static final String END_TAG_TR = (String) "</tr>";
public static final String END_TAG_TABLE = (String) "</table>";
public static final String END_TAG_P = (String) "</p>";
public static final String END_TAG_POSTFIELD = (String) "</postfield>";
public static final String END_TAG_ANCHOR = (String) "</anchor>";
public static final String END_TAG_ACCESS = (String) "</access>";
public static final String END_TAG_BR = (String) "</br>";
public static final String END_TAG_CARD = (String) "</card>";
public static final String END_TAG_DO = (String) "</do>";
public static final String END_TAG_FIELDSET = (String) "</fieldset>";
public static final String END_TAG_GO = (String) "</go>";
public static final String END_TAG_HEAD = (String) "</head>";
public static final String END_TAG_IMG = (String) "</img>";
public static final String END_TAG_INPUT = (String) "</input>";
public static final String END_TAG_NOOP = (String) "</noop>";
public static final String END_TAG_PREV = (String) "</prev>";
public static final String END_TAG_ONEVENT = (String) "</onevent>";
public static final String END_TAG_OPTGROUP = (String) "</optgroup>";
public static final String END_TAG_OPTION = (String) "</option>";
public static final String END_TAG_REFRESH = (String) "</refresh>";
public static final String END_TAG_SELECT = (String) "</select>";
public static final String END_TAG_NULL = (String) "</null>";
public static final String END_TAG_TEMPLATE = (String) "</template>";
public static final String END_TAG_TIMER = (String) "</timer>";
public static final String END_TAG_SETVAR = (String) "</setvar>";
public static final String END_TAG_WML = (String) "</wml>";
}
/**
A public class that listens for events caused by clicking on a link
*/
class LinkListener implements MouseListener,ActionListener
{
String strClickedLink;
DisplayEngineCore clsDengCore;
/**
Sets up the variables used later on in the class
@param link
@param dengCore needed to be able to set the event that was
triggered
*/
public LinkListener(String link,DisplayEngineCore dengCore)
{
super();
strClickedLink = link;
clsDengCore = dengCore;
}
/**
Convert a string to an int
@return The integer representation of the string
*/
private static int StringToInt(String s)
{
int v = 0;
for (int i=0; i<s.length(); i++)
v = 10*v + s.charAt(i) - '0';
return v;
}
public void mouseClicked(MouseEvent e)
{
System.out.println("eventid: " + strClickedLink);
clsDengCore.bolEvents = true; //this tells the displayenginre core that
clsDengCore.SetEventID(StringToInt(strClickedLink)); //an event occured
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void actionPerformed(ActionEvent e)
{
clsDengCore.bolEvents = true; //this tells the displayenginre core that
clsDengCore.SetEventID(StringToInt(strClickedLink)); //an event occured
}
}
/**
Public class that displays the "enter a url" dialog
*/
class UrlDialog extends Dialog implements ActionListener
{
DisplayEngineCore clsDengCore;
Frame frame;
EventManagement em;
TextField clsText;
public UrlDialog(Frame frame,DisplayEngineCore dengCore,String dialogTitle,EventManagement in_clsEm)
{
super(frame,dialogTitle);
setLayout(null);
clsDengCore = dengCore;
em = in_clsEm;
//clsText = new TextField("Enter url here",15);
clsText = new TextField(clsDengCore.c_clsBrowserCore.getAbsoluteURL(),15);
Button btnGo = new Button("Go");
btnGo.setBounds(10,30,20,20);
btnGo.addActionListener(this);
this.addWindowListener (new CloseDialog (this));
clsText.setSize(new Dimension(150,25));
clsText.setBounds(40,25,70,30);
this.add(btnGo);
this.add(clsText);
// this.setSize(120,60);
this.show();
pack();
validate();
this.repaint();
}
public void actionPerformed(ActionEvent e)
{
String strUrl;
try
{
strUrl = clsText.getText();
strUrl = strUrl.toLowerCase();
// Check if the URL entered is a relative URL or a fragment ID.
if (strUrl.length() == 0 || strUrl.charAt(0) == '#' || strUrl.charAt(0) == '/')
{
// Write a message to the user somewhere to tell them that the URL is invalid.
clsText.setText(clsDengCore.c_clsBrowserCore.getAbsoluteURL());
return;
}
if (strUrl.indexOf("http://") == -1)
strUrl = "http://" + strUrl;
clsDengCore.SetEventID(em.registerGo(strUrl,false,"GET",""));
}
catch (Exception ex)
{
System.out.println(ex);
}
dispose();
clsDengCore.bolEvents = true;
}
}
/**
Class to display the gateway dialog
*/
class GateWayDialog extends Dialog implements ActionListener
{
DisplayEngineCore clsDengCore;
Frame frame;
EventManagement em;
/**The user writes the gateway into this field*/
TextField clsText;
public GateWayDialog(Frame frame,DisplayEngineCore dengCore,String dialogTitle,EventManagement in_clsEm)
{
super(frame,dialogTitle);
setLayout(null);
clsDengCore = dengCore;
em = in_clsEm;
clsText = new TextField("Enter gateway here");
Button btnGo = new Button("Save");
btnGo.setBounds(10,25,30,20);
btnGo.addActionListener(this);
this.addWindowListener (new CloseDialog (this));
clsText.setSize(new Dimension(150,25));
clsText.setBounds(40,25,80,30);
this.add(btnGo);
this.add(clsText);
//this.setSize(120,60);
this.show();
pack();
validate();
}
public void actionPerformed(ActionEvent e)
{
String strGateway;
try
{
strGateway = clsText.getText();
strGateway = strGateway.toLowerCase();
clsDengCore.setGateway(strGateway);
}
catch (Exception ex)
{
System.out.println(ex);
}
dispose();
}
}
/**
Class VariableListener listens for any changes in the variables
*/
class VariableListener implements TextListener
{
String strName;
BrowserCore clsBrowserCore;
/**Contains the text that was in the input box*/
TextField clsTextValue;
public VariableListener(String name,BrowserCore bCore,TextField txt)
{
super();
strName = name;
clsBrowserCore = bCore;
clsTextValue = txt;
}
public void textValueChanged(TextEvent e)
{
String value;
value = clsTextValue.getText();
clsBrowserCore.setVariable(strName ,value);
System.out.println("NAME: "+strName+" VALUE: " + value);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -