TE Edit Control for Java
The Tej class extends the the Panel class. Here are the steps to add a Tej class object to your application Frame window.
(Please refer to the ASP.NET Interface for a description of the steps needed to insert a Tejw Applet object into your ASP.NET application).
To start, extract the tej32.jar files into one of the folders in the class path:
jar -xfv tej32.jar
This would create a new subdirectory called tej where the Tej class files are extracted. 'tej' is also the name of the package for this product. The 'import' statement should be used on the top of your application to access the editor classes.
Now follow these steps to insert a Tej control to your application.
import tej.*;
public class dmo_te extends Frame implements WindowListener
{
Tej tej=null;
JMenuBar MainMenu=null;
public dmo_te()
{
frame=this;
addWindowListener(this);
// Set the frame dimensions
setLocation(x,y);
setSize(width,height);
setTitle("Unknown");
// Create tej control
// Only design-time methods should be used here since the Tej control is not yet created.
// Such code should is added in the OnCreate function below
tej = new Tej();
tej.addTejListener(tej_listener);
tej.setWordWrap(true); // Word wrap
tej.setPageMode(true); // page mode
tej.setPrintViewMode(true); // print-view mode
tej.setFittedView(true); // fitted view mode
tej.setShowRuler(true); // show the ruler
tej.setShowVertRuler(true); // show vertical ruler
tej.setShowStatusBar(true); // show the status bar
tej.setShowToolBar(true); // show the toolbar
tej.setVertScrollBar(true); // show vertical toolbar
tej.setHorzScrollBar(true); // show the horizontal scroll bar
tej.setBorderMargin(true); // create the border margin
tej.setReadOnlyMode(false); // read only
// add following to show the menu
MainMenu=tej.TerBuildMenu();
MainMenu.setBorder(BorderFactory.createLineBorder(Color.black));
add(MainMenu,BorderLayout.NORTH);
// add the Tej control, the control is actually constructed in the WindowActivated event
add(tej); // add tej control to your Frame
/*********************************************************************
OnCreate:
Here you can add additional code that relies on Tej control
handle being already created. The function is called from the
windowActivated method located below.
**********************************************************************/
void OnCreate()
{
tej.ReadTerFile(MyFile.rtf); // read the initial file into the
control
setTitle(MyFile.rtf); // show the file name on the title
}
////////////////////////////////////////////////////////////////
// Handle events using the TejAdapter class. Please refer to the
// 'Control Events' topic for the description of all methods exported // by this adapter class.
////////////////////////////////////////////////////////////////
TejListener tej_listener = new TejAdapter() {
// provide overrides for the event which you would like to use
// this event fires when the user clicks on a hyperlink and
when the Hyperlink cursor is made visible
public void Hypertext(TejEvent ev) {
JOptionPane.showMessageDialog(frame,ev.text,ev.code, JOptionPane.PLAIN_MESSAGE);
}
// this event fires when a new file is opened in the control
public void OpenFile(TejEvent ev) {
frame.setTitle(ev.DocName);
}
};
///////////////////////////////////////////////////////////////////////
// WindowListener methods
//////////////////////////////////////////////////////////////////////
public void windowActivated(WindowEvent ex) {
if (!tej.TerControlCreated()) {
tej.TerCreateControl(); // construct the Tej control, if
// not already constructed
OnCreate();
}
}
public void windowClosed(WindowEvent ex) {}
public void windowClosing(WindowEvent ex) {
if (tej!=null && tej.TerIsModified() && !tej.TerGetReadOnly()) {
int MessageResult;
if (JOptionPane.YES_OPTION==(MessageResult=
JOptionPane.showConfirmDialog(this,"File modified.
Do you wish to save the Modifications?","", JOptionPane.YES_NO_CANCEL_OPTION))) {
if (!tej.SaveTerFile(null)) return;
}
else if (MessageResult==JOptionPane.CANCEL_OPTION) return;
}
// close window now
Window w = ex.getWindow();
w.setVisible(false);
w.dispose();
}
public void windowDeactivated(WindowEvent ex) {}
public void windowDeiconified(WindowEvent ex) {}
public void windowIconified(WindowEvent ex) {}
public void windowOpened(WindowEvent ex){}