//*********************************************************************************************
//
// Author: Dackral Scott Phillips
//
// File: SWOGDesktop.java
//
// Date: August 5, 2K2
//
// Description: This is a java program written to satisfy the requirements necessary to
// fulfill my master's degree. This program creates a Sematic Web Ontology
// Generator (SWOG). It's primary purpose is to give semantic web newbies
// an introduction to the syntax. It provides help menus for beginning
// users as well as an advanced code viewer with highlighted syntax.
//
// Copyright © 2002 by Dackral Scott Phillips. All Rights Reserved.
//
//*********************************************************************************************
// Import Necessary Files
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.filechooser.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.border.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
import javax.swing.undo.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import java.awt.image.*;
import java.util.*;
public class SWOGDesktop extends JInternalFrame
{
private static final int NO_MASK = 0; // Needed for Menu Accelerator
private String fileName; //Name of File When Saved
private String filePath; //Path to File When Saved
private File theFile; //The Pointer to the File When Saved
private boolean modified; //Has the File Been Modified?
private static int desktopCount = 1; //Number of Desktops Opened
private int desktopID; //Number of the Current Desktop
private SWOGHelp helpBrowser; //Pointer to the Help Window
private JPopupMenu popup; //Popup Menu
private JMenuItem fmSaveAll; //Pointers to SWOGUI Menu Options to toggle them on when an editor is opened
private JMenuItem fmCloseAll;
private JMenuItem wndCascade;
private SWOGXMLDocument document; //Document for highlighting syntax
private JTextPane codeEditorPane; //Text Editor Area
private JScrollPane scrollPane; //Scrolling Window
private UndoManager undo = new UndoManager(); //Allows undos
private UndoAction edUndo; //Undo Menu Option
private RedoAction edRedo; //Redo Menu Option
private JLabel lineNoLbl; //Label of Current Line Number
private JLabel colNoLbl; //Label of Current Column Number
private ArrayList desktops; //Pointer to the Desktops Array in SWOGUI
public SWOGDesktop(SWOGHelp help, ArrayList arraylist, JMenuItem fSaveAll, JMenuItem fCloseAll, JMenuItem wCascade)
{
// Name the desktop Untitled until a file name is opened. Then make it
// resizable, closable, maximizeable, and iconifiable
super("[Untitled Ontology " + (desktopCount) + "]", true, true, true, true);
// The window hasn't been modified yet
modified = false;
// Assign a number to the current desktop for reference
desktopID = desktopCount;
desktopCount++;
// Enable Close All, Cascade, and Save All in main application based on
// How many Windows are Open
fmSaveAll = fSaveAll;
fmCloseAll = fCloseAll;
wndCascade = wCascade;
// Variables used to calculate where to place windows
int x = 30;
int y = 30;
// Set a pointer to the main help window
helpBrowser = help;
// Set a pointer to the desktops ArrayList and a pointer to the desktop itself
desktops = arraylist;
// Set the size of the internal window
setSize(660, 520);
// Set the window's original location
setLocation(x * (desktopCount - 2), y * (desktopCount - 2));
// Change the default icon for the internal frame
ImageIcon logoIcon = new ImageIcon("images/swogInternalIcon.gif");
setFrameIcon(logoIcon);
// Create the Editor Window and an XML Document for Syntax Highlighting
document = new SWOGXMLDocument();
codeEditorPane=
new JTextPane(document)
{
// Hack from http://www.jalice.net/textfaq.htm that makes
// JTextPane not Line Wrap
public boolean getScrollableTracksViewportWidth()
{
return (getSize().width < getParent().getSize().width);
}
public void setSize(Dimension d)
{
if (d.width < getParent().getSize().width)
{
d.width = getParent().getSize().width;
}
super.setSize(d);
}
};
codeEditorPane.setCaretPosition(0); //Set the Caret at the beginning of the Text Pane
document.addUndoableEditListener(new SWOGUndoableEditListener()); //Add Undo Listener
codeEditorPane.addCaretListener( //Listen for the Caret Moving and update things accordingly
new CaretListener()
{
public void caretUpdate(CaretEvent e)
{
//As the cursor moves, update Line and Column
lineNoLbl.setText("Line:" + (codeEditorPane.getStyledDocument().getDefaultRootElement().getElementIndex(codeEditorPane.getCaretPosition()) + 1));
colNoLbl.setText("Col:" + ((codeEditorPane.getCaretPosition() + 1 - (codeEditorPane.getStyledDocument().getParagraphElement(codeEditorPane.getCaretPosition()).getStartOffset()))));
if (codeEditorPane.getText() == "") //Check to see if the document has been modified
{
modified = false;
}
else
{
modified = true;
}
}
});
scrollPane = new JScrollPane(codeEditorPane); //Set the Editor inside a Scroll Pane
//Create an Editor Popup Menu.
popup = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("Cut");
menuItem.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Cut();
}
});
popup.add(menuItem);
menuItem = new JMenuItem("Copy");
menuItem.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Copy();
}
});
popup.add(menuItem);
menuItem = new JMenuItem("Paste");
menuItem.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Paste();
}
});
popup.add(menuItem);
popup.addSeparator();
menuItem = new JMenuItem("Select All");
menuItem.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
SelectAll();
}
});
popup.add(menuItem);
popup.addSeparator();
edUndo = new UndoAction();
popup.add(edUndo);
edRedo = new RedoAction();
popup.add(edRedo);
//Add listener to components that can bring up popup menus.
MouseListener popupListener = new PopupListener();
codeEditorPane.addMouseListener(popupListener);
scrollPane.addMouseListener(popupListener);
//Lay out the content pane.
JToolBar toolBar = ConstructToolBar(); //Create the editor toolbar
JToolBar ontToolBar = ConstructOntologyToolBar(); // Create the Ontology Toolbar
JMenuBar menuBar = ConstructMenuBar();
getContentPane().setLayout(new BorderLayout());
setJMenuBar(menuBar);
getContentPane().add(toolBar, BorderLayout.NORTH);
getContentPane().add(scrollPane, BorderLayout.CENTER);
getContentPane().add(ontToolBar, BorderLayout.SOUTH);
}
// Construct the Toolbar
private JToolBar ConstructToolBar()
{
JToolBar toolbar = new JToolBar();
JButton button = null;
// New button
button = new JButton(new ImageIcon("images/New24.gif"));
button.setToolTipText("Create New Ontology");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
New();
}
});
toolbar.add(button);
// Open button
button = new JButton(new ImageIcon("images/Open24.gif"));
button.setToolTipText("Open Existing Ontology");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Open();
}
});
toolbar.add(button);
// Save button
button = new JButton(new ImageIcon("images/Save24.gif"));
button.setToolTipText("Save Ontology");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Save();
}
});
toolbar.add(button);
// SaveAs button
button = new JButton(new ImageIcon("images/SaveAs24.gif"));
button.setToolTipText("Save Ontology As...");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
SaveAs();
}
});
toolbar.add(button);
toolbar.addSeparator();
// Cut button
button = new JButton(new ImageIcon("images/Cut24.gif"));
button.setToolTipText("Cut Highlighted Text");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Cut();
}
});
toolbar.add(button);
// Copy button
button = new JButton(new ImageIcon("images/Copy24.gif"));
button.setToolTipText("Copy Highlighted Text");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Copy();
}
});
toolbar.add(button);
// Paste button
button = new JButton(new ImageIcon("images/Paste24.gif"));
button.setToolTipText("Paste Text");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Paste();
}
});
toolbar.add(button);
toolbar.addSeparator();
// Undo button
button = new JButton(new ImageIcon("images/Undo24.gif"));
button.setToolTipText("Undo");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Undo();
}
});
toolbar.add(button);
// Redo button
button = new JButton(new ImageIcon("images/Redo24.gif"));
button.setToolTipText("Redo");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Redo();
}
});
toolbar.add(button);
toolbar.addSeparator();
// Help button
button = new JButton(new ImageIcon("images/Help24.gif"));
button.setToolTipText("Help");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Contents();
}
});
toolbar.add(button);
return toolbar;
}
//Construct the Ontology Toolbar
private JToolBar ConstructOntologyToolBar()
{
JToolBar toolbar = new JToolBar();
lineNoLbl = new JLabel("Line:");
colNoLbl = new JLabel("Col:");
toolbar.add(lineNoLbl);
toolbar.addSeparator();
toolbar.add(colNoLbl);
toolbar.addSeparator();
JButton button = null;
// Skeleton button
button = new JButton(new ImageIcon("images/skeletonIcon.gif"));
button.setToolTipText("Create Ontology XML Skeleton");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Skeleton();
}
});
toolbar.add(button);
toolbar.addSeparator();
// Class button
button = new JButton(new ImageIcon("images/classIcon.gif"));
button.setToolTipText("Create XML Class Skeleton");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Class();
}
});
toolbar.add(button);
// Object Property button
button = new JButton(new ImageIcon("images/propertyObjIcon.gif"));
button.setToolTipText("Create XML Object Property Skeleton");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ObjProperty();
}
});
toolbar.add(button);
// Datatype Property button
button = new JButton(new ImageIcon("images/propertyDatIcon.gif"));
button.setToolTipText("Create XML Datatype Property Skeleton");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
DatProperty();
}
});
toolbar.add(button);
// Individual button
button = new JButton(new ImageIcon("images/individualIcon.gif"));
button.setToolTipText("Create XML Individual Skeleton");
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Individual();
}
});
toolbar.add(button);
return toolbar;
}
// Construct Various and Sundry Menus
private JMenuBar ConstructMenuBar()
{
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = ConstructFileMenu(); //File Menu
JMenu editMenu = ConstructEditMenu(); //Edit Menu
JMenu syntaxMenu = ConstructSyntaxMenu(); //Syntax Menu
JMenu helpMenu = ConstructHelpMenu(); //Help menu
// Add the Menus to the MenuBar
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(syntaxMenu);
menuBar.add(helpMenu);
// Return the finished Menu Bar
return menuBar;
}
private JMenu ConstructFileMenu()
{
// Define the File Menu
JMenu fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F); //Alt F Brings It Up
// Create Menu Item objects
JMenuItem fmNew = new JMenuItem("Clear");
fmNew.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
New();
}
});
JMenuItem fmOpen = new JMenuItem("Open");
fmOpen.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Open();
}
});
JMenuItem fmSave = new JMenuItem("Save");
fmSave.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Save();
}
});
JMenuItem fmSaveAs = new JMenuItem("Save As...");
fmSaveAs.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
SaveAs();
}
});
JMenuItem fmClose = new JMenuItem("Close");
fmClose.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Close();
}
});
// Set Shortcuts for the Menu Items (CTRL Letter)
fmNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_MASK));
fmOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
fmSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
fmSaveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_MASK));
fmClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_MASK));
// Alt Letter Brings The Menu Options Up
fmNew.setMnemonic(KeyEvent.VK_L);
fmOpen.setMnemonic(KeyEvent.VK_O);
fmSave.setMnemonic(KeyEvent.VK_S);
fmSaveAs.setMnemonic(KeyEvent.VK_A);
fmClose.setMnemonic(KeyEvent.VK_C);
// Add Items to the File Menu
fileMenu.add(fmNew);
fileMenu.add(fmOpen);
fileMenu.addSeparator();
fileMenu.add(fmSave);
fileMenu.add(fmSaveAs);
fileMenu.addSeparator();
fileMenu.add(fmClose);
return fileMenu;
}
private JMenu ConstructEditMenu()
{
// Define the Edit Menu
JMenu editMenu = new JMenu("Edit");
editMenu.setMnemonic(KeyEvent.VK_E); //Alt E
// Create Menu Item objects
edUndo = new UndoAction(); //Add Undo
edRedo = new RedoAction(); //Add Redo
JMenuItem edCut = new JMenuItem("Cut");
edCut.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Cut();
}
});
JMenuItem edCopy = new JMenuItem("Copy");
edCopy.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Copy();
}
});
JMenuItem edPaste = new JMenuItem("Paste");
edPaste.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Paste();
}
});
JMenuItem edSelect = new JMenuItem("Select All");
edSelect.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
SelectAll();
}
});
// Set Shortcuts for the Menu Items (CTRL Letter)
edCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_MASK));
edCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK));
edPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_MASK));
edSelect.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_MASK));
edUndo.setEnabled(false); //Disable Undo until an action is performed
edRedo.setEnabled(false); //Disable Redo until an Undo is performed
edCut.setMnemonic(KeyEvent.VK_U); //Alt U
edCopy.setMnemonic(KeyEvent.VK_C); //Alt C
edPaste.setMnemonic(KeyEvent.VK_P); //Alt P
edSelect.setMnemonic(KeyEvent.VK_S); //Alt S
// Add Items to the Edit Menu
editMenu.add(edUndo);
editMenu.add(edRedo);
editMenu.addSeparator();
editMenu.add(edCut);
editMenu.add(edCopy);
editMenu.add(edPaste);
editMenu.addSeparator();
editMenu.add(edSelect);
return editMenu;
}
// The Syntax menu inserts code skeletons into the Editor Pane
private JMenu ConstructSyntaxMenu()
{
// Define the Syntax Menu
JMenu syntaxMenu = new JMenu("Syntax");
syntaxMenu.setMnemonic(KeyEvent.VK_S);
// Define Submenus
JMenu RDFMenu = new JMenu("RDF");
RDFMenu.setMnemonic(KeyEvent.VK_R);
JMenu RDFSMenu = new JMenu("RDFS");
RDFSMenu.setMnemonic(KeyEvent.VK_F);
JMenu DAMLMenu = new JMenu("DAML + OIL");
DAMLMenu.setMnemonic(KeyEvent.VK_D);
// Define DAML Submenus
JMenu classMenu = new JMenu("Class Menu");
classMenu.setMnemonic(KeyEvent.VK_C);
DAMLMenu.add(classMenu);
JMenu indMenu = new JMenu("Individual Menu");
indMenu.setMnemonic(KeyEvent.VK_I);
DAMLMenu.add(indMenu);
JMenu listMenu = new JMenu("List Menu");
listMenu.setMnemonic(KeyEvent.VK_L);
DAMLMenu.add(listMenu);
JMenu ontMenu = new JMenu("Ontology Menu");
ontMenu.setMnemonic(KeyEvent.VK_O);
DAMLMenu.add(ontMenu);
JMenu propMenu = new JMenu("Property Menu");
propMenu.setMnemonic(KeyEvent.VK_P);
DAMLMenu.add(propMenu);
JMenu rstrctMenu = new JMenu("Restriction Menu");
rstrctMenu.setMnemonic(KeyEvent.VK_R);
DAMLMenu.add(rstrctMenu);
// Create RDF Menu Item objects
JMenuItem rdfAlt = new JMenuItem("Alternate");
rdfAlt.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n\n";
skeleton = skeleton + " \n";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfAlt.setMnemonic(KeyEvent.VK_A);
RDFMenu.add(rdfAlt);
JMenuItem rdfBag = new JMenuItem("Bag");
rdfBag.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n\n";
skeleton = skeleton + " \n";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfBag.setMnemonic(KeyEvent.VK_B);
RDFMenu.add(rdfBag);
JMenuItem rdfSeq = new JMenuItem("Sequence");
rdfSeq.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n\n";
skeleton = skeleton + " \n";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfSeq.setMnemonic(KeyEvent.VK_S);
RDFMenu.add(rdfSeq);
JMenuItem rdfLI = new JMenuItem("list item");
rdfLI.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfLI.setMnemonic(KeyEvent.VK_I);
RDFMenu.add(rdfLI);
RDFMenu.addSeparator();
JMenuItem rdfAboutEach = new JMenuItem("about each");
rdfAboutEach.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "aboutEach=\"\"";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfAboutEach.setMnemonic(KeyEvent.VK_E);
RDFMenu.add(rdfAboutEach);
JMenuItem rdfAboutEachPrefix = new JMenuItem("about each prefix");
rdfAboutEachPrefix.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "aboutEachPrefix=\"\"";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfAboutEachPrefix.setMnemonic(KeyEvent.VK_P);
RDFMenu.add(rdfAboutEachPrefix);
RDFMenu.addSeparator();
JMenuItem rdfParseLiteral = new JMenuItem("literal parse type");
rdfParseLiteral.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "parseType=\"Literal\"";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfParseLiteral.setMnemonic(KeyEvent.VK_L);
RDFMenu.add(rdfParseLiteral);
JMenuItem rdfParseResource = new JMenuItem("resource parse type");
rdfParseResource.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "parseType=\"Resource\"";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfParseResource.setMnemonic(KeyEvent.VK_R);
RDFMenu.add(rdfParseResource);
RDFMenu.addSeparator();
JMenuItem rdfType = new JMenuItem("type");
rdfType.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfType.setMnemonic(KeyEvent.VK_T);
RDFMenu.add(rdfType);
JMenuItem rdfValue = new JMenuItem("value");
rdfValue.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfValue.setMnemonic(KeyEvent.VK_V);
RDFMenu.add(rdfValue);
// Create RDFS Menu Item objects
JMenuItem rdfsCont = new JMenuItem("Container");
rdfsCont.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "rdf:resource=\"rdfs:Container\"";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfsCont.setMnemonic(KeyEvent.VK_C);
RDFSMenu.add(rdfsCont);
JMenuItem rdfsCMP = new JMenuItem("Container Membership Property");
rdfsCMP.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "rdf:resource=\"rdfs:ContainerMembershipProperty\"";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfsCMP.setMnemonic(KeyEvent.VK_M);
RDFSMenu.add(rdfsCMP);
JMenuItem rdfsLit = new JMenuItem("Literal");
rdfsLit.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "rdf:resource=\"rdfs:Literal\"";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfsLit.setMnemonic(KeyEvent.VK_L);
RDFSMenu.add(rdfsLit);
JMenuItem rdfsResource = new JMenuItem("Resource");
rdfsResource.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "rdf:resource=\"rdfs:Resource\"";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfsResource.setMnemonic(KeyEvent.VK_R);
RDFSMenu.add(rdfsResource);
RDFSMenu.addSeparator();
JMenuItem rdfsCP = new JMenuItem("Constraint Property");
rdfsCP.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n\n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfsCP.setMnemonic(KeyEvent.VK_P);
RDFSMenu.add(rdfsCP);
JMenuItem rdfsDomain = new JMenuItem("domain");
rdfsDomain.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n\n";
skeleton = skeleton + " \n";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfsDomain.setMnemonic(KeyEvent.VK_D);
RDFSMenu.add(rdfsDomain);
JMenuItem rdfsRange = new JMenuItem("range");
rdfsRange.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n\n";
skeleton = skeleton + " \n";
codeEditorPane.replaceSelection(skeleton);
codeEditorPane.replaceSelection(skeleton);
}
});
rdfsRange.setMnemonic(KeyEvent.VK_G);
RDFSMenu.add(rdfsRange);
RDFSMenu.addSeparator();
JMenuItem rdfsDefined = new JMenuItem("is defined by");
rdfsDefined.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfsDefined.setMnemonic(KeyEvent.VK_I);
RDFSMenu.add(rdfsDefined);
JMenuItem rdfsAlso = new JMenuItem("see also");
rdfsAlso.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
rdfsAlso.setMnemonic(KeyEvent.VK_S);
RDFSMenu.add(rdfsAlso);
RDFSMenu.addSeparator();
JMenuItem subClass = new JMenuItem("subclass of");
subClass.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
codeEditorPane.replaceSelection(skeleton);
}
});
subClass.setMnemonic(KeyEvent.VK_O);
RDFSMenu.add(subClass);
JMenuItem subProp = new JMenuItem("subproperty of");
subProp.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
subProp.setMnemonic(KeyEvent.VK_Y);
RDFSMenu.add(subProp);
// Add DAML + OIL Sub menu elements
// Add DAML Class Sub Menu Sub-Sub Menu Items
JMenuItem DataType = new JMenuItem("Datatype");
DataType.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "daml:Datatype";
codeEditorPane.replaceSelection(skeleton);
}
});
DataType.setMnemonic(KeyEvent.VK_D);
classMenu.add(DataType);
JMenuItem Nothing = new JMenuItem("Nothing");
Nothing.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "daml:Nothing";
codeEditorPane.replaceSelection(skeleton);
}
});
Nothing.setMnemonic(KeyEvent.VK_N);
classMenu.add(Nothing);
JMenuItem Thing = new JMenuItem("Thing");
Thing.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n\n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
});
Thing.setMnemonic(KeyEvent.VK_T);
classMenu.add(Thing);
classMenu.addSeparator();
JMenuItem compOf = new JMenuItem("complement of");
compOf.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
compOf.setMnemonic(KeyEvent.VK_C);
classMenu.add(compOf);
JMenuItem disjoint = new JMenuItem("disjoint with");
disjoint.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
disjoint.setMnemonic(KeyEvent.VK_J);
classMenu.add(disjoint);
JMenuItem equiv = new JMenuItem("equivalent to");
equiv.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
equiv.setMnemonic(KeyEvent.VK_E);
classMenu.add(equiv);
JMenuItem sameClass = new JMenuItem("same class as");
sameClass.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
sameClass.setMnemonic(KeyEvent.VK_S);
classMenu.add(sameClass);
classMenu.addSeparator();
JMenuItem disunionOf = new JMenuItem("disjoint union of");
disunionOf.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
});
disunionOf.setMnemonic(KeyEvent.VK_O);
classMenu.add(disunionOf);
JMenuItem intOf = new JMenuItem("intersection of");
intOf.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
});
intOf.setMnemonic(KeyEvent.VK_I);
classMenu.add(intOf);
JMenuItem unionOf = new JMenuItem("union of");
unionOf.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
});
unionOf.setMnemonic(KeyEvent.VK_U);
classMenu.add(unionOf);
// Add DAML Individual Sub Menu Sub-Sub Menu Item
JMenuItem diffInd = new JMenuItem("different individual from");
diffInd.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
diffInd.setMnemonic(KeyEvent.VK_D);
indMenu.add(diffInd);
JMenuItem sameInd = new JMenuItem("same individual as");
sameInd.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
sameInd.setMnemonic(KeyEvent.VK_S);
indMenu.add(sameInd);
// Add DAML List Sub Menu Sub-Sub Menu Item
JMenuItem List = new JMenuItem("List");
List.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n\n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
});
List.setMnemonic(KeyEvent.VK_L);
listMenu.add(List);
listMenu.addSeparator();
JMenuItem nilList = new JMenuItem("nil");
nilList.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
nilList.setMnemonic(KeyEvent.VK_N);
listMenu.add(nilList);
listMenu.addSeparator();
JMenuItem first = new JMenuItem("first");
first.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n\n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
});
first.setMnemonic(KeyEvent.VK_F);
listMenu.add(first);
JMenuItem rest = new JMenuItem("rest");
rest.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n\n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
});
rest.setMnemonic(KeyEvent.VK_R);
listMenu.add(rest);
listMenu.addSeparator();
JMenuItem item = new JMenuItem("item");
item.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
item.setMnemonic(KeyEvent.VK_I);
listMenu.add(item);
listMenu.addSeparator();
JMenuItem oneOf = new JMenuItem("one of");
oneOf.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n";
skeleton = skeleton + " < rdf:ID=\"\"/>\n";
skeleton = skeleton + " < rdf:ID=\"\"/>\n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
});
oneOf.setMnemonic(KeyEvent.VK_O);
listMenu.add(oneOf);
// Add DAML Ontology Sub Menu Sub-Sub Menu Item
JMenuItem ontImport = new JMenuItem("imports");
ontImport.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
ontImport.setMnemonic(KeyEvent.VK_I);
ontMenu.add(ontImport);
// Add DAML Property Sub Menu Sub-Sub Menu Items
JMenuItem transProp = new JMenuItem("Transitive");
transProp.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
});
transProp.setMnemonic(KeyEvent.VK_T);
propMenu.add(transProp);
JMenuItem unamProp = new JMenuItem("Unambiguous");
unamProp.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
});
unamProp.setMnemonic(KeyEvent.VK_A);
propMenu.add(unamProp);
JMenuItem unqProp = new JMenuItem("Unique");
unqProp.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
});
unqProp.setMnemonic(KeyEvent.VK_U);
propMenu.add(unqProp);
propMenu.addSeparator();
JMenuItem invProp = new JMenuItem("inverse of");
invProp.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
invProp.setMnemonic(KeyEvent.VK_I);
propMenu.add(invProp);
JMenuItem sameProp = new JMenuItem("same property as");
sameProp.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
sameProp.setMnemonic(KeyEvent.VK_S);
propMenu.add(sameProp);
// Add DAML Restriction Sub Menu Sub-Sub Menu Items
JMenuItem rstrct = new JMenuItem("Restriction");
rstrct.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " \n\n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
});
rstrct.setMnemonic(KeyEvent.VK_R);
rstrctMenu.add(rstrct);
rstrctMenu.addSeparator();
JMenuItem card = new JMenuItem("cardinality");
card.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "daml:cardinality=\"\"";
codeEditorPane.replaceSelection(skeleton);
}
});
card.setMnemonic(KeyEvent.VK_C);
rstrctMenu.add(card);
JMenuItem cardq = new JMenuItem("cardinality q");
cardq.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "daml:cardinalityQ=\"\"";
codeEditorPane.replaceSelection(skeleton);
}
});
cardq.setMnemonic(KeyEvent.VK_A);
rstrctMenu.add(cardq);
rstrctMenu.addSeparator();
JMenuItem hasClass = new JMenuItem("has class");
hasClass.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
hasClass.setMnemonic(KeyEvent.VK_H);
rstrctMenu.add(hasClass);
JMenuItem hasClassQ = new JMenuItem("has class q");
hasClassQ.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
hasClassQ.setMnemonic(KeyEvent.VK_S);
rstrctMenu.add(hasClassQ);
JMenuItem hasVal = new JMenuItem("has value");
hasVal.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
hasVal.setMnemonic(KeyEvent.VK_V);
rstrctMenu.add(hasVal);
rstrctMenu.addSeparator();
JMenuItem maxCard = new JMenuItem("max cardinality");
maxCard.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
maxCard.setMnemonic(KeyEvent.VK_X);
rstrctMenu.add(maxCard);
JMenuItem maxCardQ = new JMenuItem("max cardinality q");
maxCardQ.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "daml:maxCardinalityQ=\"\"";
codeEditorPane.replaceSelection(skeleton);
}
});
maxCardQ.setMnemonic(KeyEvent.VK_D);
rstrctMenu.add(maxCardQ);
JMenuItem minCard = new JMenuItem("min cardinality");
minCard.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
minCard.setMnemonic(KeyEvent.VK_N);
rstrctMenu.add(minCard);
JMenuItem minCardQ = new JMenuItem("min cardinality q");
minCardQ.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = "daml:minCardinalityQ=\"\"";
codeEditorPane.replaceSelection(skeleton);
}
});
minCardQ.setMnemonic(KeyEvent.VK_M);
rstrctMenu.add(minCardQ);
rstrctMenu.addSeparator();
JMenuItem onProp = new JMenuItem("on property");
onProp.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
onProp.setMnemonic(KeyEvent.VK_O);
rstrctMenu.add(onProp);
JMenuItem toClass = new JMenuItem("to class");
toClass.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String skeleton = " ";
codeEditorPane.replaceSelection(skeleton);
}
});
toClass.setMnemonic(KeyEvent.VK_T);
rstrctMenu.add(toClass);
syntaxMenu.add(RDFMenu);
syntaxMenu.add(RDFSMenu);
syntaxMenu.add(DAMLMenu);
syntaxMenu.addSeparator();
//Add Menu Options for the buttons on the Ontology Bar for navigation redundance
JMenuItem synSkeleton = new JMenuItem("Ontology Skeleton");
synSkeleton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Skeleton();
}
});
synSkeleton.setMnemonic(KeyEvent.VK_S);
syntaxMenu.add(synSkeleton);
JMenuItem synClass = new JMenuItem("Class Skeleton");
synClass.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Class();
}
});
synClass.setMnemonic(KeyEvent.VK_C);
syntaxMenu.add(synClass);
JMenuItem synOT = new JMenuItem("Object Property Skeleton");
synOT.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ObjProperty();
}
});
synOT.setMnemonic(KeyEvent.VK_O);
syntaxMenu.add(synOT);
JMenuItem synDT = new JMenuItem("Datatype Property Skeleton");
synDT.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
DatProperty();
}
});
synDT.setMnemonic(KeyEvent.VK_T);
syntaxMenu.add(synDT);
JMenuItem synInd = new JMenuItem("Individual Skeleton");
synInd.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Individual();
}
});
synInd.setMnemonic(KeyEvent.VK_I);
syntaxMenu.add(synInd);
return syntaxMenu;
}
private JMenu ConstructHelpMenu()
{
// Define the Help Menu
JMenu helpMenu = new JMenu("Help");
helpMenu.setMnemonic(KeyEvent.VK_H); //Alt H
// Create Menu Item objects
JMenuItem hlpContents = new JMenuItem("Help Contents");
hlpContents.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Contents();
}
});
JMenuItem hlpSWOG = new JMenuItem("SWOG Help");
hlpSWOG.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
SWOG();
}
});
JMenuItem hlpSW = new JMenuItem("Semantic Web Help");
hlpSW.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
SW();
}
});
JMenuItem hlpLicense = new JMenuItem("License");
hlpLicense.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
License();
}
});
JMenuItem hlpAbout = new JMenuItem("About");
hlpAbout.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
About();
}
});
// Set Shortcuts for the Menu Items
// help - F1
hlpContents.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, NO_MASK));
// Alt Letter
hlpContents.setMnemonic(KeyEvent.VK_H);
hlpSWOG.setMnemonic(KeyEvent.VK_S);
hlpSW.setMnemonic(KeyEvent.VK_W);
hlpLicense.setMnemonic(KeyEvent.VK_L);
hlpAbout.setMnemonic(KeyEvent.VK_A);
// Add Items to the Help Menu
helpMenu.add(hlpContents);
helpMenu.add(hlpSWOG);
helpMenu.add(hlpSW);
helpMenu.addSeparator();
helpMenu.add(hlpLicense);
helpMenu.add(hlpAbout);
return helpMenu;
}
//Function to create a new help window if it does not exist
private SWOGHelp createHelpWindow(String u)
{
if (helpBrowser == null)
{
helpBrowser = new SWOGHelp(u);
helpBrowser.setVisible(true);
helpBrowser.requestFocus();
}
else if (helpBrowser.getState() == Frame.ICONIFIED) //Restore it if it is minimized
{
helpBrowser.setState(Frame.NORMAL);
}
else
{
helpBrowser.setVisible(true);
helpBrowser.requestFocus();
}
return helpBrowser;
}
//Check to see whether the document has been modified or not
public boolean isModified()
{
return modified;
}
// File Menu/ToolBar Methods
private void New()
{
if (isModified())
{
switch(showNotSavedDialog()) //Check to see if the document needs to be saved
{
case JOptionPane.YES_OPTION: //Save the file, then do what's in NO_OPTION
{
Save();
}
case JOptionPane.NO_OPTION: //Reset Variables
{
codeEditorPane.setText("");
modified = false;
fileName = null;
filePath = null;
theFile = null;
this.setTitle("[Untitled Ontology " + (desktopID) + "]");
break;
}
case JOptionPane.CANCEL_OPTION:
{
break;
}
}
}
else
{
//Reset Variables
codeEditorPane.setText("");
modified = false;
fileName = null;
filePath = null;
theFile = null;
this.setTitle("[Untitled Ontology " + (desktopID) + "]");
}
}
public void Open()
{
if(!isModified())
{
codeEditorPane.setText("");
JFileChooser fc = new JFileChooser();
String[] damlStr = new String[] {"daml"}; //File Filer for DAML files
String[] xmlStr = new String[] {"xml"}; //File Filter for XML files
fc.setMultiSelectionEnabled(false); //Only 1 File at the time, please!
fc.addChoosableFileFilter(new SWOGFileFilter(damlStr, "DAML (*.daml)"));
fc.addChoosableFileFilter(new SWOGFileFilter(xmlStr, "XML (*.xml)"));
int returnVal = fc.showOpenDialog(this); //Show the open dialog box
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
// Open the file
JTextPane tempPane = new JTextPane();
EditorKit editorKit = new StyledEditorKit();
tempPane.setEditorKit(editorKit);
try
{
editorKit.read(new FileInputStream(file), tempPane.getStyledDocument(),0);
}
catch (Exception e)
{
JOptionPane.showMessageDialog(SWOGDesktop.this, "There Was an Error Trying To Read the File As Plain Text.\n" + e, "I/O Error", JOptionPane.ERROR_MESSAGE);
}
codeEditorPane.selectAll();
codeEditorPane.replaceSelection(tempPane.getText());
fileName = file.getName();
filePath = file.getPath();
theFile = file;
this.setTitle(fileName);
}
}
else
{
switch(showNotSavedDialog())
{
case JOptionPane.YES_OPTION:
{
Save();
Open();
break;
}
case JOptionPane.NO_OPTION:
{
modified = false;
Open();
}
break;
case JOptionPane.CANCEL_OPTION:
{
break;
}
}
}
}
public void Open(File file)
{
// Open the file
JTextPane tempPane = new JTextPane();
EditorKit editorKit = new StyledEditorKit();
tempPane.setEditorKit(editorKit);
try
{
editorKit.read(new FileInputStream(file), tempPane.getStyledDocument(),0);
}
catch (Exception e)
{
JOptionPane.showMessageDialog(SWOGDesktop.this, "There Was an Error Trying To Read the File As Plain Text.\n" + e, "I/O Error", JOptionPane.ERROR_MESSAGE);
}
codeEditorPane.selectAll();
codeEditorPane.replaceSelection(tempPane.getText());
fileName = file.getName();
filePath = file.getPath();
theFile = file;
this.setTitle(fileName);
}
public void Save()
{
if (fileName == null)
{
SaveAs();
}
else if (isModified())
{
// Save the file
try
{
BufferedWriter writer = new BufferedWriter(new FileWriter(theFile));
writer.write(codeEditorPane.getText());
writer.flush();
writer.close();
}
catch (FileNotFoundException fnfe)
{
JOptionPane.showMessageDialog(SWOGDesktop.this, "The file could not be saved.\n" + fnfe, "File Not Found Error", JOptionPane.ERROR_MESSAGE);
}
catch (IOException ioe)
{
JOptionPane.showMessageDialog(SWOGDesktop.this, "An I/O Error has occured.\n" + ioe, "I/O Error", JOptionPane.ERROR_MESSAGE);
}
modified = false;
}
else
{
// No need, file has not been modified
}
}
private void SaveAs()
{
final JFileChooser fc = new JFileChooser();
String[] damlStr = new String[] {"daml"}; //File filter for DAML Files
String[] xmlStr = new String[] {"xml"}; //FIle Filter for XML files
fc.setMultiSelectionEnabled(false); //Only One File At the time, Please!
fc.addChoosableFileFilter(new SWOGFileFilter(damlStr, "DAML (*.daml)"));
fc.addChoosableFileFilter(new SWOGFileFilter(xmlStr, "XML (*.xml)"));
int returnVal = fc.showSaveDialog(this); //Show the dialog
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
// Set the File Name
fileName = file.getName();
filePath = file.getPath();
theFile = file;
this.setTitle(fileName);
// Save the File
try
{
BufferedWriter writer = new BufferedWriter(new FileWriter(theFile));
writer.write(codeEditorPane.getText());
writer.flush();
writer.close();
}
catch (FileNotFoundException fnfe)
{
JOptionPane.showMessageDialog(SWOGDesktop.this, "There Was an Error Trying To Save the File.\n" + fnfe, "File Write Error", JOptionPane.ERROR_MESSAGE);
}
catch (IOException ioe)
{
JOptionPane.showMessageDialog(SWOGDesktop.this, "There Was an Error Trying To Save the File.\n" + ioe, "I/O Error", JOptionPane.ERROR_MESSAGE);
}
modified = false;
}
}
public void Close() //Check for save, then close
{
if (isModified())
{
switch(showNotSavedDialog2())
{
case JOptionPane.YES_OPTION:
{
Save();
break;
}
case JOptionPane.NO_OPTION:
{
break;
}
}
}
desktops.remove(desktops.lastIndexOf(SWOGDesktop.this));
if (desktops.size() == 0) //Toggle Menu Items off if no editor windows exist
{
fmSaveAll.setEnabled(false);
fmCloseAll.setEnabled(false);
wndCascade.setEnabled(false);
}
dispose();
}
// Edit Menu/ToolBar Methods
private void Undo()
{
try
{
undo.undo();
}
catch (CannotUndoException cue)
{
JOptionPane.showMessageDialog(SWOGDesktop.this, "Unable to Undo.\n" + cue, "Undo Error", JOptionPane.ERROR_MESSAGE);
}
updateUndo();
}
private void Redo()
{
try
{
undo.redo();
}
catch (CannotUndoException cue)
{
JOptionPane.showMessageDialog(SWOGDesktop.this, "Unable to Redo.\n" + cue, "Redo Error", JOptionPane.ERROR_MESSAGE);
}
updateUndo();
}
private void Cut()
{
codeEditorPane.cut();
}
private void Copy()
{
codeEditorPane.copy();
}
private void Paste()
{
codeEditorPane.paste();
}
private void SelectAll()
{
codeEditorPane.selectAll();
}
// Help Menu/ToolBar Methods
private void Contents()
{
helpBrowser = createHelpWindow("file:///" + System.getProperty("user.dir") + "\\help\\contents.html");
}
private void SWOG()
{
helpBrowser = createHelpWindow("file:///" + System.getProperty("user.dir") + "\\help\\contents.html#SWOG");
}
private void SW()
{
helpBrowser = createHelpWindow("file:///" + System.getProperty("user.dir") + "\\help\\contents.html#SW");
}
private void License()
{
helpBrowser = createHelpWindow("file:///" + System.getProperty("user.dir") + "\\help\\contents.html#License");
}
private void About()
{
helpBrowser = createHelpWindow("file:///" + System.getProperty("user.dir") + "\\help\\contents.html#About");
}
// Ontology Tool Bar Methods
private void Skeleton() //Add text when button of menu item is selected
{
String skeleton = "\n\n";
skeleton = skeleton + " \n\n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n\n\n";
skeleton = skeleton + " ";
codeEditorPane.replaceSelection(skeleton);
}
private void Class() //Add text when button of menu item is selected
{
String skeleton = " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n\n";
codeEditorPane.replaceSelection(skeleton);
}
private void ObjProperty() //Add text when button of menu item is selected
{
String skeleton = " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n\n";
codeEditorPane.replaceSelection(skeleton);
}
private void DatProperty() //Add text when button of menu item is selected
{
String skeleton = " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n\n";
codeEditorPane.replaceSelection(skeleton);
}
private void Individual() //Add text when button of menu item is selected
{
String skeleton = " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
skeleton = skeleton + " \n";
codeEditorPane.replaceSelection(skeleton);
}
// Miscellaneous Field Setting Methods
private void setFileName(String fName)
{
fileName = fName;
}
private void setPathName(String pName)
{
filePath = pName;
}
// Menu Called Submethods
// Create "Save? Yes/No" dialog for all windows before application close
public void checkSaveBeforeClose()
{
switch(showNotSavedDialog2())
{
case JOptionPane.YES_OPTION:
{
Save();
Close();
break;
}
case JOptionPane.NO_OPTION:
{
Close();
break;
}
}
}
// Create "Save? Yes/No/Cancel" Dialog
private int showNotSavedDialog()
{
int returnVal = JOptionPane.showConfirmDialog(SWOGDesktop.this,"The last document has not been saved. \nDo you want to save it first?", "Save Changes?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
return returnVal;
}
// Create "Save? Yes/No" dialog
private int showNotSavedDialog2()
{
int returnVal = JOptionPane.showConfirmDialog(SWOGDesktop.this,"The last document has not been saved. \nDo you want to save it first?", "Save Changes?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
return returnVal;
}
private void updateUndo()
{
if(undo.canUndo())
{
edUndo.setEnabled(true);
edUndo.putValue(Action.NAME, undo.getUndoPresentationName());
}
else
{
edUndo.setEnabled(false);
edUndo.putValue(Action.NAME, "Undo");
}
if(undo.canRedo())
{
edRedo.setEnabled(true);
edRedo.putValue(Action.NAME, undo.getRedoPresentationName());
}
else
{
edRedo.setEnabled(false);
edRedo.putValue(Action.NAME, "Redo");
}
}
// Helper Classes
// Class to Listen for Popup Menu
private class PopupListener extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
maybeShowPopup(e);
}
public void mouseReleased(MouseEvent e)
{
maybeShowPopup(e);
}
private void maybeShowPopup(MouseEvent e)
{
if (e.isPopupTrigger())
{
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
}
//Class that listens for edits that can be undone.
private class SWOGUndoableEditListener implements UndoableEditListener
{
public void undoableEditHappened(UndoableEditEvent e)
{
//Remember the edit and update the menus.
undo.addEdit(e.getEdit());
edUndo.updateUndoState();
edRedo.updateRedoState();
}
}
// Class Defining Undo Action
private class UndoAction extends AbstractAction
{
public UndoAction()
{
super("Undo");
setEnabled(false);
}
public void actionPerformed(ActionEvent e)
{
try
{
undo.undo();
}
catch (CannotUndoException ex)
{
JOptionPane.showMessageDialog(SWOGDesktop.this, "Unable to Undo Previous Action.\n" + ex, "Undo Error", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
}
updateUndoState();
edRedo.updateRedoState();
}
private void updateUndoState()
{
if (undo.canUndo())
{
setEnabled(true);
putValue(Action.NAME, undo.getUndoPresentationName());
}
else
{
setEnabled(false);
putValue(Action.NAME, "Undo");
}
}
}
// Class Defining Redo Action
private class RedoAction extends AbstractAction
{
public RedoAction()
{
super("Redo");
setEnabled(false);
}
public void actionPerformed(ActionEvent e)
{
try
{
undo.redo();
}
catch (CannotRedoException ex)
{
JOptionPane.showMessageDialog(SWOGDesktop.this, "Unable to Redo Previous Action.\n" + ex, "Redo Error", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
}
updateRedoState();
edUndo.updateUndoState();
}
private void updateRedoState()
{
if (undo.canRedo())
{
setEnabled(true);
putValue(Action.NAME, undo.getRedoPresentationName());
}
else
{
setEnabled(false);
putValue(Action.NAME, "Redo");
}
}
}
}