Java Editor Abstract
Java Editor Abstract
Chennai-600 063.
BONAFIDE
CERTIFICATE
Certificate that this Mini project report titled “JAVA EDITOR” the bonafide work of
Mr. M.NATARAJAN, REG.NO -40708104042 who carried out the research under my
supervision. Certified further, that to the best of my knowledge the work reported herein does not
form part of any other project report or dissertation on the basis of which
degree or award was conferred on an earlier occasion on this or any other candidate.
1. SYNOPSIS.
2. SYSTEM CONFIGURATION.
3. SOFTWARE DESCRIPTION.
• ABOUT JAVA.
4. PROJECT DETAILS.
5. BIBILOGRAPHY.
6. SOURCE CODE.
7. SNAPSHOT.
8. FUTURE ENCHANCEMENTS.
9. CONCLUSION.
SYNOPSIS:
Java Editor is the easy-to-use and it is developed with many powerful features to
improve your productivity and programming experience. Ideal for both the beginner and more
experienced programmer.
Java Editor is very useful developing large scale projects. The developer can
avoid the typing of the commands for each and every operation so he can finish the project and
deliver the user in time.
It reduces the complexity to the programmer and he can concentrate in his concept and do his
work correctly.
SYSTEM CONFIGURATION:
CD DRIVE : 52X.
SOFTWARE DESCRIPTION:
ABOUT JAVA:
The original and reference implementation Java compilers, virtual machines, and class libraries
were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the
Java Community Process, Sun relicensed most of its Java technologies under the GNU General
Public License. Others have also developed alternative implementations of these Sun
technologies, such as the GNU Compiler for Java, GNU Class path, and Dalvik.
James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June
1991. Java was originally designed for interactive television, but it was too advanced. The
language was initially called Oak after an oak tree that stood outside Gosling's office; it went by
the name Green later, and was later renamed Java, from a list of random words. Gosling aimed
to implement a virtual machine and a language that had a familiar C/C++ style of notation.
Sun Microsystems released the first public implementation as Java 1.0 in 1995. It promised
"Write Once, Run anywhere" (WORA), providing no-cost run-times on popular platforms. Fairly
secure and featuring configurable security, it allowed network- and file-access restrictions. Major
web browsers soon incorporated the ability to run Java applets within web pages, and Java
quickly became popular. With the advent of Java 2 (released initially as J2SE 1.2 in December
1998–1999), new versions had multiple configurations built for different types of platforms. For
example, J2EE targeted enterprise applications and the greatly stripped-down version J2ME for
mobile applications (Mobile Java). J2SE designated the Standard Edition. In 2006, for marketing
purposes, Sun renamed new J2 versions as Java EE, Java ME, and Java SE, respectively.
In 1997, Sun Microsystems approached the ISO/IEC JTC1 standards body and later the Ecma
International to formalize Java, but it soon withdrew from the process. Java remains a de facto
standard, controlled through the Java Community Process. At one time, Sun made most of its
Java implementations available without charge, despite their proprietary software status. Sun
generated revenue from Java through the selling of licenses for specialized products such as the
Java Enterprise System. Sun distinguishes between its Software Development Kit (SDK) and
Runtime Environment (JRE) (a subset of the SDK); the primary distinction involves the JRE's
lack of the compiler, utility programs, and header file.
PROJECT DETAILS:
MOUDULES:
• MENUS.
• EDIT.
• EXECUTE.
MENUS:
New:
Open:
Close:
Print:
EDIT:
Cut:
Paste:
Undo:
COMPILE:
A Java compiler is a compiler for the Java programming language. The most
common form of output from a Java compiler are Java class files containing platform-neutral
Java bytecode. There exist also compilers emitting optimized native machine code for a
particular hardware/operating system combination
BUILD:
In java programming language the dataflow between the programs can be identified by
using the build option.
RUN:
In java programming language the java interpreter produces machine code from the
bytecode and run the program.
BIBILOGRAPHY:
• AG98
Ken Arnold and James Gosling, The Java Programming Language, second ed., Addison-
Wesley, 2009.
• Chan98
Patrick Chan, The Java Developers Almanac, Addison-Wesley, 2007.
• CM96
Peter Coad and Mark Mayfield, Java Design: Building Better Apps and Applets, Yourdon
Press, 1996.
• CH97
Gary Cornell and Cay S. Horstmann, Core Java, second ed., SunSoft Press, 1997.
• ELW98
Robert Eckstein and Marc Loy and Dave Wood, Java Swing, O'Reilly, 2009.
• Englander97
Robert Englander, Developing Java Beans, O'Reilly, 2007.
• Flanagan96
David Flanagan, Java in a Nutshell, second ed., O'Reilly, 2006.
• Flanagan99
David Flanagan, Java Foundation Classes in a Nutshell, O'Reilly, 2009.
• Gea99a
David M. Geary, Graphic Java 2: Mastering the JFC, vol. I, AWT, third ed., Sun
Microsystems Press, 2001.
• Gea99b
David M. Geary Graphic Java 2: Mastering the JFC, vol. II, Swing, third ed., Sun
Microsystems Press, 2001.
SOURCE CODE:
import sd.components.tabbedpanel.titledtab.TitledTabProperties;
import sd.components.tabbedpanel.theme.*;
import java.awt.*;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.event.*;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import java.io.File;
import javax.swing.*;
import sd.components.tabbedpanel.*;
public class MainForm extends JFrame implements TabListener {
private TitledTabProperties titledTabProperties = new TitledTabProperties();
public sd.components.SDTabbedPanel mainTab;
public SDMenuBar mnub;
public static java.util.ArrayList commandList=new java.util.ArrayList();
public MainForm() {
super("SDJEditor");
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
int n = JOptionPane.showConfirmDialog(null,"Are You Sure to Close This
Programe","SDJCreator",JOptionPane.YES_NO_OPTION);
if(n==JOptionPane.YES_OPTION)
{
System.exit(0);
}
}
});
Dimension size=Toolkit.getDefaultToolkit().getScreenSize();
setSize(size.width-60,size.height-40);
setLocationRelativeTo(null);
mainTab=new sd.components.SDTabbedPanel();
mainTab.setCloseButton();
TabbedPanelTitledTabTheme themes =new ShapedGradientTheme();
mainTab.getProperties().addSuperObject(themes.getTabbedPanelProperties());
titledTabProperties.addSuperObject(themes.getTitledTabProperties());
mainTab.getProperties().setEnsureSelectedTabVisible(true);
mainTab.getProperties().setTabLayoutPolicy(sd.components.tabbedpanel.TabLayoutPolicy.SCROLLING);
mainTab.getProperties().setTabDropDownListVisiblePolicy(sd.components.tabbedpanel.TabDropDownLi
stVisiblePolicy.MORE_THAN_ONE_TAB);
getContentPane().add(mainTab,BorderLayout.CENTER);
sd.components.swing.StatusBar sb=new sd.components.swing.StatusBar();
sb.show(true);
getContentPane().add(sb,BorderLayout.PAGE_END);
mainTab.setBackground(Color.RED);
mnub=new SDMenuBar();
setJMenuBar(mnub);
mainTab.addTabListener(this);
// new Tray();
} public void addTab(sd.components.tabbedpanel.titledtab.TitledTab tab)
{ tab.setInheritsPopupMenu(true);
tab.getProperties().addSuperObject(titledTabProperties);
mainTab.addTab(tab);
mainTab.setSelectedTab(tab);
} public javax.swing.JTextPane getEditor()
{ if(mainTab.getTabCount()==0)
return null;
if(mainTab==null)
return null;
if(mainTab.getSelectedTab()==null)
return null;
return ((NewFile)mainTab.getSelectedTab().getTag()).getEditor();
//return ((NewFile)mainTab.getSelectedTab().getContentComponent()).getEditor()
} public javax.swing.JTextArea getConsole()
{
if(mainTab.getTabCount()==0)
return null;
if(mainTab==null)
return null;
if(mainTab.getSelectedTab()==null)
return null;
return ((NewFile)mainTab.getSelectedTab().getTag()).getConsole();
} public NewFile getFileDetails()
{
if(mainTab.getTabCount()==0)
return null;
if(mainTab==null)
return null;
if(mainTab.getSelectedTab()==null)
return null;
return ((NewFile)mainTab.getSelectedTab().getTag());
}
public void tabAdded(TabEvent event)
{
}
public void tabRemoved(TabRemovedEvent event)
{
/*sd.components.tabbedpanel.titledtab.TitledTab
tab=(sd.components.tabbedpanel.titledtab.TitledTab)event.getTab();
if(tab.getText().indexOf("*")!=-1)
{
int n = JOptionPane.showConfirmDialog(null,"Do You Want To Save The
Changes","SDJCreator",JOptionPane.YES_NO_CANCEL_OPTION);
if(n==JOptionPane.YES_OPTION)
{
}else if(n==JOptionPane.NO_OPTION)
{
}else
{}}*/ }
public void tabDragged(TabDragEvent event)
{
}
public void tabDropped(TabDragEvent event)
{
}
public void tabDragAborted(TabEvent event)
{
}
public void tabSelected(TabStateChangedEvent event)
{
SDJEditor.frmMain.mnub.setSaveSaveAsMenuItemEnableDisable();
}
public void tabDeselected(TabStateChangedEvent event)
{
}
public void tabHighlighted(TabStateChangedEvent event)
{ }
public void tabDehighlighted(TabStateChangedEvent event)
{ }
public void tabMoved(TabEvent event)
{ }
}
COMPILE:
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.awt.*;
import java.util.*;
class Build extends Thread {
private String stop = "< Press the STOP button on the toolbar to force " +
"termination of current process >",
finish = "Project Building Finished. ",
command, currentDir, fileName;
try {
file = (File)files[i];
if ( file.isDirectory() || !file.getName().endsWith(".java") )
continue;
fileName = file.getName();
command = "javac " + fileName;
lock = true;
Runtime rt = Runtime.getRuntime();
SDJEditor.frmMain.commandList.add(rt);
Process p = rt.exec( command, null, project );
SDJEditor.frmMain.commandList.add(p);
BufferedReader reader1 = new BufferedReader(
new InputStreamReader( p.getInputStream() ) );
while ( execute ) {
if ( !lock )
break;
else {
try {
Thread.sleep(500);
}
catch (InterruptedException ie ) {}
}
}
p.destroy();
reader1.close();
reader2.close();
if ( !execute )
break;
console.append("\n========================================================");
console.append( "\n" );
} // for
if ( execute ) {
report();
console.append( "\n" + finish +" \n" );
} else {
console.append( "\n" + "The Process has been Terminated !!! \n" );
}
console.append("\n---------------------------------------------------------------------------------------------------\n");
console.setCaretPosition(console.getText().length()); // Alternative
method scrollBar.setValue(scrollBar.getMaximum());
}
catch(Exception e) {
JOptionPane.showMessageDialog( SDJEditor.frmMain,
"Error: Invalid Command!!!", "Warning", JOptionPane.ERROR_MESSAGE);
}
Toolkit.getDefaultToolkit().beep();
} // End run()
RUN:
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.awt.*;
import java.util.*;
command, currentDir;
private final String fileName;
this.option = option;
this.index = index;
}
this.console =SDJEditor.frmMain.getConsole();
this.myUID = (TextAreaUI)console.getUI();
this.Locks = new Boolean[2];
Locks[0] = new Boolean(true);
Locks[1] = new Boolean(true);
try {
Runtime rt = Runtime.getRuntime();
startTime = System.currentTimeMillis();
SDJEditor.frmMain.commandList.add(rt);
Process p = rt.exec( command, null, new File( currentDir ) );
SDJEditor.frmMain.commandList.add(p);
console.append( "\n\n" );
console.setCaretPosition(console.getText().length());
while ( execute ) {
if ( Locks[0].equals( Boolean.FALSE ) &&
Locks[1].equals( Boolean.FALSE ) )
break;
else {
try {
Thread.sleep(500);
}
catch (InterruptedException ie ) {}
}
}
reader1.close();
reader2.close();
endTime = System.currentTimeMillis() - startTime;
long lg = endTime/1000;
String time = "\n Time taken: " + lg + "." + (endTime-lg*1000) + "
seconds.";
if ( execute ) {
if ( option == 1 ) {
if ( compilingSuccess )
console.append( "Compiling Java Code
Success. " );
else
console.append( "\n" + "Compiling Java
Code Failed!!! ");
console.append( time + "\n" );
}
if ( option != 1 )
finish = "\n" + finish+"\n";
//console.append( finish );
} else {
console.append("\n\n---------------------------------------------------------------------------------------------------\n");
console.setCaretPosition(console.getText().length()); // Alternative
method scrollBar.setValue(scrollBar.getMaximum());
p.destroy();
}
catch(Exception e) {
JOptionPane.showMessageDialog( SDJEditor.frmMain,
"Error: Invalid Command!!!", "Warning", JOptionPane.ERROR_MESSAGE);
}
} // End run()
}
SYNTAX HIGHLIGHTING:
import java.awt.*;
import java.awt.event.*;
import java.awt.Toolkit.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
public SyntaxDocument(){
doc = this;
rootElement = doc.getDefaultRootElement();
putProperty( DefaultEditorKit.EndOfLineStringProperty, "\n" );
normal = new SimpleAttributeSet();
StyleConstants.setForeground(normal, Color.black);
comment = new SimpleAttributeSet();
Color green = new Color(0, 120, 0);
StyleConstants.setForeground(comment, green);
keyword = new SimpleAttributeSet();
Color blue = new Color(0, 0, 140);
StyleConstants.setForeground(keyword, blue);
StyleConstants.setBold(keyword, true);
quote = new SimpleAttributeSet();
Color red = new Color(140,0,0);
StyleConstants.setForeground(quote, red);
Object dummyObject = new Object();
javaClasses.put("ASCIICaseInsensitiveComparator",dummyObject );
javaClasses.put("ATR",dummyObject );
javaClasses.put("AWTAutoShutdown",dummyObject );
javaClasses.put("AWTCharset",dummyObject );
javaClasses.put("AWTError",dummyObject );
javaClasses.put("AWTEvent",dummyObject );
javaClasses.put("AWTEventMulticaster",dummyObject );
javaClasses.put("AWTException",dummyObject );
javaClasses.put("AWTKeyStroke",dummyObject );
javaClasses.put("AWTPermission",dummyObject );
javaClasses.put("AWTSecurityManager",dummyObject );
javaClasses.put("AbstractAction",dummyObject );
javaClasses.put("AbstractButton",dummyObject );
javaClasses.put("AbstractButtonBeanInfo",dummyObject
);
javaClasses.put("AbstractCellEditor",dummyObject );
javaClasses.put("AbstractCollection",dummyObject );
javaClasses.put("AbstractList",dummyObject );
javaClasses.put("AbstractListModel",dummyObject );
javaClasses.put("AbstractMap",dummyObject );
javaClasses.put("AbstractMethodError",dummyObject );
javaClasses.put("AbstractQueue",dummyObject );
javaClasses.put("AbstractScriptEngine",dummyObject );
javaClasses.put("AbstractSequentialList",dummyObject );
javaClasses.put("AbstractSet",dummyObject );
javaClasses.put("AbstractSpinnerModel",dummyObject );
javaClasses.put("AbstractStringBuilder",dummyObject );
javaClasses.put("AccessControlContext",dummyObject );
javaClasses.put("AccessControlException",dummyObject );
javaClasses.put("AccessController",dummyObject );
javaClasses.put("AccessException",dummyObject );
javaClasses.put("Accessible",dummyObject );
javaClasses.put("AccessibleAction",dummyObject );
javaClasses.put("AccessibleAttributeSequence",dummyObject );
javaClasses.put("AccessibleBundle",dummyObject );
javaClasses.put("AccessibleComponent",dummyObject );
javaClasses.put("AccessibleContext",dummyObject );
javaClasses.put("AccessibleEditableText",dummyObject );
javaClasses.put("AccessibleExtendedComponent",dummyObject );
javaClasses.put("AccessibleExtendedTable",dummyObject );
javaClasses.put("AccessibleExtendedText",dummyObject );
javaClasses.put("AccessibleHyperlink",dummyObject );
javaClasses.put("AccessibleHypertext",dummyObject );
javaClasses.put("AccessibleIcon",dummyObject );
javaClasses.put("AccessibleKeyBinding",dummyObject );
javaClasses.put("AccessibleMethod",dummyObject );
javaClasses.put("AccessibleRelation",dummyObject );
javaClasses.put("AccessibleRelationSet",dummyObject );
javaClasses.put("AccessibleResourceBundle",dummyObject );
javaClasses.put("AccessibleRole",dummyObject );
public void insertString(int offset, String str, AttributeSet a) throws BadLocationException{
if (str.equals("{"))
str = addMatchingBrace(offset);
super.insertString(offset, str, a);
processChangedLines(offset, str.length());
}
/* Override to apply syntax highlighting after the document has been updated */
public void remove(int offset, int length) throws BadLocationException{
super.remove(offset, length);
processChangedLines(offset, 0);
}
/* Determine how many lines have been changed, then apply highlighting to each line */
private void processChangedLines(int offset, int length) throws BadLocationException {
String content = doc.getText(0, doc.getLength());
// The lines affected by the latest document update
int startLine = rootElement.getElementIndex( offset );
int endLine = rootElement.getElementIndex( offset + length );
// Make sure all comment lines prior to the start line are commented
// and determine if the start line is still in a multi line comment
setMultiLineComment( commentLinesBefore( content, startLine ) );
// Do the actual highlighting
for (int i=startLine; i <=endLine; i++)applyHighlighting(content, i);
// Resolve highlighting to the next end multi line delimiter
if (isMultiLineComment()) commentLinesAfter(content, endLine);
else highlightLinesAfter(content, endLine);
}
/* Highlight lines when a multi line comment is still 'open' */
private boolean commentLinesBefore(String content, int line){
int offset = rootElement.getElement( line ).getStartOffset();
// Start of comment not found, nothing to do
int startDelimiter = lastIndexOf( content, getStartDelimiter(), offset-2);
if (startDelimiter < 0)return false;
// Matching start/end of comment found, nothing to do
int endDelimiter = indexOf( content, getEndDelimiter(), startDelimiter );
if (endDelimiter < offset & endDelimiter != -1)return false;
// End of comment not found, highlight the lines
doc.setCharacterAttributes(startDelimiter, offset - startDelimiter + 1, comment, false);
return true;
}
/* Highlight comment lines to matching end delimiter */
private void commentLinesAfter(String content, int line){
int offset = rootElement.getElement( line ).getEndOffset();
// End of comment not found, nothing to do
int endDelimiter = indexOf( content, getEndDelimiter(), offset );
if (endDelimiter < 0) return;
// Matching start/end of comment found, comment the lines
int startDelimiter = lastIndexOf( content, getStartDelimiter(), endDelimiter );
if (startDelimiter < 0 || startDelimiter <= offset){
doc.setCharacterAttributes(offset, endDelimiter - offset + 1, comment, false);
}
}
/* Highlight lines to start or end delimiter */
private void highlightLinesAfter(String content, int line) throws BadLocationException{
int offset = rootElement.getElement( line ).getEndOffset();
// Start/End delimiter not found, nothing to do
int startDelimiter = indexOf( content, getStartDelimiter(), offset );
int endDelimiter = indexOf( content, getEndDelimiter(), offset );
if (startDelimiter < 0) startDelimiter = content.length();
if (endDelimiter < 0)endDelimiter = content.length();
int delimiter = Math.min(startDelimiter, endDelimiter);
if (delimiter < offset)return;
// Start/End delimiter found, reapply highlighting
int endLine = rootElement.getElementIndex( delimiter );
for (int i = line + 1; i < endLine; i++){
Element branch = rootElement.getElement( i );
Element leaf = doc.getCharacterElement( branch.getStartOffset() );
AttributeSet as = leaf.getAttributes();
if ( as.isEqual(comment) ) applyHighlighting(content, i);
}
}
/* Parse the line to determine the appropriate highlighting */
private void applyHighlighting(String content, int line) throws BadLocationException{
int startOffset = rootElement.getElement( line ).getStartOffset();
int endOffset = rootElement.getElement( line ).getEndOffset() - 1;
int lineLength = endOffset - startOffset;
int contentLength = content.length();
if (endOffset >= contentLength)endOffset = contentLength - 1;
// check for multi line comments
// (always set the comment attribute for the entire line)
if( ( endingMultiLineComment(content, startOffset, endOffset) )
||( isMultiLineComment() )
||( startingMultiLineComment(content, startOffset, endOffset) ) ){
doc.setCharacterAttributes(startOffset, endOffset - startOffset + 1, comment, false);
return;
}
// set normal attributes for the line
doc.setCharacterAttributes(startOffset, lineLength, normal, true);
// check for single line comment
int index = content.indexOf(getSingleLineDelimiter(), startOffset);
if ( (index > -1) && (index < endOffset) ){
doc.setCharacterAttributes(index, endOffset - index + 1, comment, false);
endOffset = index - 1;
}
// check for tokens
checkForTokens(content, startOffset, endOffset);
}
/* This line contain the start delimiter */
private boolean startingMultiLineComment(String content, int startOffset, int endOffset) throws
BadLocationException{
int index = indexOf( content, getStartDelimiter(), startOffset );
if( (index < 0) || (index > endOffset) ) return false;
else{
setMultiLineComment( true );
return true;
}
}
/* Does this line contain the end delimiter */
private boolean endingMultiLineComment(String content, int startOffset, int endOffset) throws
BadLocationException{
int index = indexOf( content, getEndDelimiter(), startOffset );
if( (index < 0) || (index > endOffset) ) return false;
else{
setMultiLineComment( false );
return true;
}
}
/* We have found a start delimiter and are still searching for the end delimiter */
private boolean isMultiLineComment(){
return multiLineComment;
}
private void setMultiLineComment(boolean value){
multiLineComment = value;
}
return endOfToken + 1;
}
private int indexOf(String content, String needle, int offset){
int index;
while( (index = content.indexOf(needle, offset)) != -1 ){
String text = getLine( content, index ).trim();
if(text.startsWith(needle) || text.endsWith(needle)) break;
else offset = index + 1;
}
return index;
}
CONCLUSION:
The project work entitled “JAVA EDITOR” was initiated to work in a
more efficient and personal way. The main trademark of the project is many powerful features to
improve your productivity and programming experience. Ideal for both the beginner and more
experienced programmer.