//
// VideoGrok.java
// VideoGrok
//
// Created by Michael Fischer on Thu Jul 24 2003.
// Copyright (c) 2009 CSAC. All rights reserved.
//
// For information on setting Java configuration information, including
// setting Java properties, refer to the documentation at
// http://developer.apple.com/techpubs/java/java.html
//
// package org.csac.vid
import net.roydesign.mac.MRJAdapter;
import net.roydesign.app.*;
import java.util.Locale;
import java.util.ResourceBundle;
import java.awt.*;
import java.awt.event.*;
import com.apple.mrj.*;
import quicktime.*;
import quicktime.io.*;
// import quicktime.app.players.*;
import quicktime.std.movies.*;
import quicktime.std.clocks.TimeRecord;
import java.util.Hashtable;
public class VideoGrok extends Frame
implements ActionListener{
// },
// MRJAboutHandler,
// MRJQuitHandler {
private Font font = new Font("serif", Font.ITALIC+Font.BOLD, 36);
protected AboutBox aboutBox;
protected ResourceBundle resbundle;
// Declarations for menus
static MenuBar mainMenuBar = new MenuBar();
protected Menu fileMenu;
protected MenuItem miNew;
protected MenuItem miOpen;
protected MenuItem miLoad;
protected MenuItem miClose;
protected MenuItem miSave;
protected MenuItem miSaveAs;
protected MenuItem miMovieAs;
protected MenuItem miMovieAsNoMeta;
protected MenuItem miQuit;
protected Menu editMenu;
protected MenuItem miUndo;
protected MenuItem miCut;
protected MenuItem miCopy;
protected MenuItem miPaste;
protected MenuItem miClear;
protected MenuItem miSelectAll;
final static long winbase=34359738368L; // constant to subtract for finding differences between times on windows;
public void addFileMenuItems() {
miNew = new MenuItem (resbundle.getString("newItem"));
miNew.setShortcut(new MenuShortcut(KeyEvent.VK_N, false));
fileMenu.add(miNew).setEnabled(true);
miNew.addActionListener(this);
fileMenu.addSeparator();
miOpen = new MenuItem (resbundle.getString("openItem"));
miOpen.setShortcut(new MenuShortcut(KeyEvent.VK_O, false));
fileMenu.add(miOpen).setEnabled(true);
miOpen.addActionListener(this);
miLoad = new MenuItem (resbundle.getString("loadItem"));
miLoad.setShortcut(new MenuShortcut(KeyEvent.VK_T, false));
fileMenu.add(miLoad).setEnabled(true);
miLoad.addActionListener(this);
/*
miClose = new MenuItem (resbundle.getString("closeItem"));
miClose.setShortcut(new MenuShortcut(KeyEvent.VK_W, false));
fileMenu.add(miClose).setEnabled(true);
miClose.addActionListener(this);
*/
fileMenu.addSeparator();
miSave = new MenuItem (resbundle.getString("saveItem"));
miSave.setShortcut(new MenuShortcut(KeyEvent.VK_S, false));
fileMenu.add(miSave).setEnabled(true);
miSave.addActionListener(this);
miSaveAs = new MenuItem (resbundle.getString("saveasItem"));
miSaveAs.setShortcut(new MenuShortcut(KeyEvent.VK_S, true));
fileMenu.add(miSaveAs).setEnabled(true);
miSaveAs.addActionListener(this);
miMovieAs = new MenuItem (resbundle.getString("movieasItem"));
miMovieAs.setShortcut(new MenuShortcut(KeyEvent.VK_M, true));
fileMenu.add(miMovieAs).setEnabled(true);
miMovieAs.addActionListener(this);
miMovieAsNoMeta = new MenuItem (resbundle.getString("movieasnometaItem"));
miMovieAsNoMeta.setShortcut(new MenuShortcut(KeyEvent.VK_M, true));
fileMenu.add(miMovieAsNoMeta).setEnabled(true);
miMovieAsNoMeta.addActionListener(this);
fileMenu.addSeparator();
MRJAdapter.addQuitApplicationListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
handleQuit();
}
});
if (!QuitMenuItem.isAutomaticallyPresent()) {
miQuit = new MenuItem (resbundle.getString("quitItem"));
miQuit.setShortcut(new MenuShortcut(KeyEvent.VK_E, false));
fileMenu.add(miQuit).setEnabled(true);
miQuit.addActionListener(this);
}
mainMenuBar.add(fileMenu);
}
public void addEditMenuItems() {
miUndo = new MenuItem(resbundle.getString("undoItem"));
miUndo.setShortcut(new MenuShortcut(KeyEvent.VK_Z, false));
editMenu.add(miUndo).setEnabled(true);
miUndo.addActionListener(this);
editMenu.addSeparator();
miCut = new MenuItem(resbundle.getString("cutItem"));
miCut.setShortcut(new MenuShortcut(KeyEvent.VK_X, false));
editMenu.add(miCut).setEnabled(true);
// miCut.addActionListener(this);
miCopy = new MenuItem(resbundle.getString("copyItem"));
miCopy.setShortcut(new MenuShortcut(KeyEvent.VK_C, false));
editMenu.add(miCopy).setEnabled(true);
// miCopy.addActionListener(this);
miPaste = new MenuItem(resbundle.getString("pasteItem"));
miPaste.setShortcut(new MenuShortcut(KeyEvent.VK_V, false));
editMenu.add(miPaste).setEnabled(true);
// miPaste.addActionListener(this);
miClear = new MenuItem(resbundle.getString("clearItem"));
editMenu.add(miClear).setEnabled(true);
miClear.addActionListener(this);
// editMenu.addSeparator();
miSelectAll = new MenuItem(resbundle.getString("selectAllItem"));
miSelectAll.setShortcut(new MenuShortcut(KeyEvent.VK_A, false));
editMenu.add(miSelectAll).setEnabled(true);
miSelectAll.addActionListener(this);
mainMenuBar.add(editMenu);
}
public void addMenus() {
editMenu = new Menu(resbundle.getString("editMenu"));
fileMenu = new Menu(resbundle.getString("fileMenu"));
addFileMenuItems();
addEditMenuItems();
setMenuBar (mainMenuBar);
}
public void makeMenus(Frame f) {
MenuBar save = mainMenuBar;
mainMenuBar = new MenuBar();
editMenu = new Menu(resbundle.getString("editMenu"));
fileMenu = new Menu(resbundle.getString("fileMenu"));
addFileMenuItems();
addEditMenuItems();
f.setMenuBar (mainMenuBar);
mainMenuBar = save;
}
public VideoGrok() {
super("CSAC Video Annotater");
WindowAdpt WAdapter = new WindowAdpt();
this.addWindowListener(WAdapter);
// The ResourceBundle below contains all of the strings used in this application. ResourceBundles
// are useful for localizing applications - new localities can be added by adding additional
// properties files.
resbundle = ResourceBundle.getBundle("VideoGrokstrings", Locale.getDefault());
setTitle (resbundle.getString("frameConstructor"));
setSize(600,780); // need to adjust size
// setLayout(new BorderLayout());
setLayout(new VerticalFlow());
addMenus();
aboutBox = new AboutBox();
Toolkit.getDefaultToolkit();
//MRJApplicationUtils.registerAboutHandler(this);
//MRJApplicationUtils.registerQuitHandler(this);
MRJAdapter.addAboutListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
handleAbout();
}
});
try {
QTSession.open();
gd = new MediaPresenter();
add(gd,"Center");
gd.show();
Panel p= new Panel();
p.setSize(320,96);
// p.setLayout(new GridLayout(3,1,0,0));
p.setLayout(new VerticalFlow());
ctrl = new MovieControlPanel (gd);
p.add (ctrl);
nudge = new MovieNudgePanel(gd);
p.add(nudge);
// transFrame.setLayout(new BorderLayout());
// transcript = new Transcript(gd);
// transFrame.add(transcript);
Panel d = new Panel();
d.setSize(320,32);
Button startSelection = new Button("Begin");
startSelection.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
try {
MovieController mc = getMovieController();
if (mc != null) {
TimeRecord ts = mc.getSelectionBegin();
TimeRecord td = mc.getSelectionDuration();
System.out.println("Begin ts="+ts);
System.out.println("Begin td="+td);
long diff = mc.getCurrentTime();
System.out.println("Begin current="+diff);
ts.setValue(diff);
ts = new TimeRecord(ts.getScale(),diff);
td = new TimeRecord(td.getScale(),0L);
long winbase=34359738368L;
// td.setValue(10000L);
/*
diff -= ts.getValue();
if (diff > 0) {
if (diff > td.getValue()) {
td.setValue(0);
} else {
td.setValue(td.getValue()-diff);
}
} else {
td.setValue(td.getValue()-diff);
}
ts.setValue( mc.getCurrentTime());
*/
mc.setSelectionBegin(ts);
mc.setSelectionDuration(td);
gd.setRate(1.0);
gd.requestFocus();
}
} catch (QTException e) {
// if (e.errorCode() != Errors.userCanceledErr)
e.printStackTrace();
}
}
});
Button endSelection = new Button("End");
endSelection.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
try {
MovieController mc = getMovieController();
if (mc != null) {
gd.setRate(0);
TimeRecord ts = mc.getSelectionBegin();
TimeRecord td = mc.getSelectionDuration();
long diff = mc.getCurrentTime();
System.out.println("End ts="+ts);
System.out.println("End td="+td);
System.out.println("End diff="+diff);
long tsx = ts.getValue();
if (tsx >= winbase) tsx -= winbase;
if (diff < tsx) {
ts.setValue(diff);
td.setValue(tsx - diff);
} else {
td.setValue(diff-tsx);
}
/*
ts.setValue(diff);
td.setValue(0L);
diff -= ts.getValue();
if (diff > 0) {
td.setValue(diff);
} else {
td.setValue(10);
ts.setValue(mc.getCurrentTime());
}
*/
mc.setSelectionBegin(ts); // clears selection and sets start point
mc.setSelectionDuration(td);
if (true) {
// transcript.addItem(mc, ts, td); // mc to set icon
transcript.addItem(ts, td); // mc to set icon
transcript.lastComponentVisible();
}
gd.requestFocus();
}
} catch (QTException e) {
if (e.errorCode() != Errors.userCanceledErr)
e.printStackTrace();
}
}
});
Button noSelection = new Button("Clear Selection");
noSelection.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
try {
MovieController mc = getMovieController();
if (mc != null) {
TimeRecord ts = mc.getSelectionBegin();
TimeRecord td = mc.getSelectionDuration();
ts.setValue(mc.getCurrentTime());
td.setValue(0);
mc.setSelectionBegin(ts);
mc.setSelectionDuration(td);
gd.requestFocus();
}
} catch (QTException e) {
if (e.errorCode() != Errors.userCanceledErr)
e.printStackTrace();
}
}
});
/*
Button selectButton = new Button("Save Selection");
selectButton.addActionListener (new ActionListener () {
public void actionPerformed(ActionEvent event) {
try {
MovieController mc = getMovieController();
if (mc != null) {
TimeRecord ts = mc.getSelectionBegin();
TimeRecord td = mc.getSelectionDuration();
transcript.addItem(ts, td);
}
} catch (QTException e) {
if (e.errorCode() != Errors.userCanceledErr)
e.printStackTrace();
}
}
});
*/
d.add(startSelection);d.add(endSelection); d.add(noSelection); // d.add(selectButton);
p.add(d);
add(p,"South");
} catch (Exception e) {
e.printStackTrace();
QTSession.close();
}
Panel searchPanel = new Panel();
searchPanel.setLayout(new VerticalFlow());
searchPanel.setSize(325,70);
Panel s = new Panel(); // search panel
s.setSize(320,32);
s.add(new Label("Keywords"));
s.add(searchText = new TextField("", 40));
searchPanel.add(s);
s = new Panel(); // search panel
s.setSize(320,32);
s.add(new Label("Codes "));
s.add(searchCodes = new TextField("", 40));
searchPanel.add(s);
Button searchButton = new Button("Search clips");
searchButton.addActionListener (new ActionListener () {
public void actionPerformed(ActionEvent event) {
try {
searchClips();
} catch (Exception e) {
e.printStackTrace();
}
}
});
searchPanel.add(searchButton);
add(searchPanel);
/* Panel searchPanel = new Panel();
searchPanel.setLayout(new VerticalFlow());
Panel s = new Panel(); // search panel
s.setSize(320,32);
s.add(new Checkbox("All", null, true));
s.add(new Checkbox("Speaker"));
s.add(new Checkbox("Summary"));
s.add(new Checkbox("Note"));
s.add(new Checkbox("Codes"));
searchPanel.add(s);
add(searchPanel);
*/
prefs = Preferences.loadPrefs("org.csac.VideoGrok.prefs",false);
if (prefs != null) try {
if (prefs.getString("PrevMovieTime") != null) {
prevMovieTime = prefs.getLong("PrevMovieTime");
}
if (prefs.getString("PrevMovie") != null) {
gd.openFromURL(prefs.getString("PrevMovie"), prevMovieTime);
enableButtons();
nudge.mediaSet();
}
if (prefs.getString("PrevTranscript") != null) {
subLoad(prefs.getString("PrevTranscript"));
}
if (prefs.getString("PrevMovieVolume") != null) {
if (getMovieController() != null)
getMovieController().setVolume(prefs.getFloat("PrevMovieVolume"));
}
} catch (Exception e) {
e.printStackTrace();
}
if (prefs == null)
try {
gd.openFromPath("StartText.mov", 0); // make a help video!!!
enableButtons();
nudge.mediaSet();
doNew();
} catch (Exception e) {
e.printStackTrace();
}
if (transcript == null) doNew();
/*
Panel dx = new Panel();
dx.setSize(320,320);
dx.setLayout(null);
dx.setBackground(java.awt.Color.red);
add(dx);
CodeTermListPanel cp = new CodeTermListPanel();
cp.setSize(640,320);
// cp.setBackground(java.awt.Color.blue);
dx.add(cp);
cp.setLocation(0,0);
cp.layout();
XFile xf = new XFile(System.getProperty("user.dir")+"/"+"CSACCodes.xml");
xf.Open();
cp.load(xf);
xf.Close();
*/
// ContentCodesHandler contentcodeshandler = new ContentCodesHandler();
/* if(prefs.getPref("optionsdtd") != null)
{
try
{
// contentcodeshandler.readDTD(prefs.getPref("optionsdtd"));
// optionMenus(contentcodeshandler);
}
catch(Exception exception)
{
exception.printStackTrace();
}
// theDtd = prefs.getPref("optionsdtd");
} else */
{
try
{
// contentcodeshandler.readDTD("contentcodes.dtd");
// optionMenus(contentcodeshandler);
}
catch(Exception exception1)
{
exception1.printStackTrace();
}
// theDtd = "contentcodes.dtd";
}
setVisible(true);
}
TextField searchText = null;
TextField searchCodes = null;
public void searchClips() {
String text = searchText.getText().toLowerCase();
String codes = searchCodes.getText().toLowerCase();
System.out.println("Searching for "+text+":"+codes);
SearchClips sc = new SearchClips(this);
if (sc.search()) {
System.out.println(sc.outCome);
XFile xr = new XFile();
doNew();
try {
xr.Open(sc.outCome.toString());
System.out.println("File "+xr);
transcript.load(xr);
transcript.setDirty(true);
// xr.Close();
transFrame.setTitle("Search Results: "+text+" - "+codes);
saveFile = null;
} catch (Exception e) {
e.printStackTrace();
}
// transcript.paintComponents(transcript.getGraphics());
// transcript.invalidate();
// transFrame.invalidate();
// doLayout();
} else {
//@@ do a failure dialog
}
}
Frame transFrame = new Frame();
Transcript transcript = null;
ListVector transcripts = new ListVector();
public void enableButtons() {
ctrl.enableButtons();
}
MovieControlPanel ctrl = null;
MovieNudgePanel nudge = null;
long prevMovieTime = 0L;
public MovieController getMovieController() {
return gd.getMovieController();
}
static MediaPresenter gd=null;
/*
public void paint(Graphics g) {
g.setColor(Color.blue);
g.setFont (font);
g.drawString(resbundle.getString("message"), 40, 80);
}
*/
public void handleAbout()
{
aboutBox.setResizable(false);
aboutBox.setVisible(true);
aboutBox.show();
}
public void handleQuit()
{
// If the application needs to save document/state before exiting, do so here
int n=0;
for(transcripts.reset();transcripts.isNext();) {
transcript = (Transcript) transcripts.getNext();
System.out.println("Transcript "+(++n));
DoYouWantToSave ds;
if (transcript.isDirty()) {
ds = new DoYouWantToSave(this,true);
ds.show();
// while (ds.getResult() == DoYouWantToSave.STASIS);
if (ds.getResult() == DoYouWantToSave.CANCEL) return;
if (ds.getResult() == DoYouWantToSave.SAVE) {
doSave();
}
transcript.setDirty(false);
}
}
if (getMovieController() != null) {
try {
if (getMovieController().getMovie() != null) {
float vol = getMovieController().getVolume();
prefs.putPreference("PrevMovieVolume",vol+"");
long tr = getMovieController().getCurrentTime();
prefs.putPreference("PrevMovieTime",tr+"");
prefs.savePrefs("org.csac.VideoGrok.prefs",false);
}
} catch(Exception e){
}
// System.out.println(transcript.toXML());
}
QTSession.close();
System.exit(0);
}
// ActionListener interface (for menus)
public void actionPerformed(ActionEvent newEvent)
{
if (newEvent.getActionCommand().equals(miNew.getActionCommand())) doNew();
else if (newEvent.getActionCommand().equals(miOpen.getActionCommand())) doOpen();
else if (newEvent.getActionCommand().equals(miLoad.getActionCommand())) doLoad();
// else if (newEvent.getActionCommand().equals(miClose.getActionCommand())) doClose();
else if (newEvent.getActionCommand().equals(miSave.getActionCommand())) doSave();
else if (newEvent.getActionCommand().equals(miSaveAs.getActionCommand())) doSaveAs();
else if (newEvent.getActionCommand().equals(miMovieAs.getActionCommand())) doMovieAs();
else if (newEvent.getActionCommand().equals(miMovieAsNoMeta.getActionCommand())) doMovieNoMetaAs();
else if (newEvent.getActionCommand().equals(miQuit.getActionCommand())) handleQuit();
else if (newEvent.getActionCommand().equals(miUndo.getActionCommand())) doUndo();
else if (newEvent.getActionCommand().equals(miCut.getActionCommand())) doCut();
else if (newEvent.getActionCommand().equals(miCopy.getActionCommand())) doCopy();
else if (newEvent.getActionCommand().equals(miPaste.getActionCommand())) doPaste();
else if (newEvent.getActionCommand().equals(miClear.getActionCommand())) doClear();
else if (newEvent.getActionCommand().equals(miSelectAll.getActionCommand())) doSelectAll();
}
class WindowAct extends java.awt.event.WindowAdapter {
public void windowActivated(java.awt.event.WindowEvent event) {
transcript = (Transcript) event.getWindow().getComponent(0);
saveFile = transcript.getFile();
transFrame= (Frame) event.getWindow();
System.err.println("Window Activated");
}
}
int fileCount=0;
public void doNew() {
transFrame = new Frame("Untitled "+(++fileCount));
WindowAct WAdapter;
WAdapter = new WindowAct();
transFrame.addWindowListener(WAdapter);
WindowAdptTranscript WindowCloseAdpt = new WindowAdptTranscript();
transFrame.addWindowListener(WindowCloseAdpt);
makeMenus(transFrame);
transFrame.setSize(700,640);
transFrame.setLocation(getSize().width+30+(fileCount-2)*20,30+(fileCount-2)*20);
transFrame.setLayout(new BorderLayout());
transcript = new Transcript(gd);
transcripts.addElement(transcript);
transcript.ourFile = new XFile();
transcript.setFont(new Font("serif",Font.PLAIN,12));
transFrame.add(transcript,"Center");
transFrame.setVisible(true);
}
public void importFolder() {
}
public void doOpen() {
try {
String loc = System.getProperty("user.dir");
String opath="";
QTFile qtf = QTFile.standardGetFilePreview (QTFile.kStandardQTFileTypes);
if (qtf.getPath().startsWith(loc)) {
opath = qtf.getPath().substring(loc.length()+1);
System.out.println(loc + ": " + qtf.getPath() + ": " + opath);
gd.openFromURL("file://" + opath);
} else {
gd.openFromURL("file://" + qtf.getPath());
opath = qtf.getPath();
}
enableButtons();
nudge.mediaSet();
if (prefs == null) prefs = new Preferences();
prefs.putPreference("PrevMovie","file://" + opath);
prefs.savePrefs("org.csac.VideoGrok.prefs",false);
layout();
} catch (Exception e) {
e.printStackTrace();
}
}
Preferences prefs=null;
public void doClose() {
}
static MediaPresenter getPresenter() {
return gd;
}
public void doLoad() {
XFile xr = new XFile();
if (!xr.Choose(XFile.READ)) return; // cancelled
doNew();
try {
xr.Open();
transcript.load(xr);
transcript.setDirty(false);
xr.Close();
transFrame.setTitle(xr.getFileName());
saveFile = xr;
} catch (Exception e) {
e.printStackTrace();
}
enableButtons();
// transcript.paintComponents(transcript.getGraphics());
// transcript.invalidate();
// transFrame.invalidate();
// doLayout();
}
public void subLoad(String xpath) {
XFile xr = new XFile(xpath);
doNew();
try {
xr.Open();
transcript.load(xr);
transcript.setDirty(false);
xr.Close();
transFrame.setTitle(xr.getFileName());
saveFile = xr;
} catch (Exception e) {
e.printStackTrace();
}
// transcript.paintComponents(transcript.getGraphics());
// transcript.invalidate();
// transFrame.invalidate();
// doLayout();
}
XFile saveFile=null;
public boolean doSave() {
saveFile=transcript.ourFile;
if (saveFile == null) saveFile = new XFile();
if (saveFile.OpenPrint()) {
// toFront(); // does this do any harm? Or good?
String out = transcript.toXML();
saveFile.WriteXML(out);
saveFile.Close();
transcript.setDirty(false);
transFrame.setTitle(saveFile.getFileName());
transcript.ourFile = saveFile;
transcript.name = saveFile.getFileName();
if (prefs == null) prefs = new Preferences();
prefs.putPreference("PrevTranscript","" + saveFile.aFile.getPath());
prefs.savePrefs("org.csac.VideoGrok.prefs",false);
return true;
} else {
System.out.println("File not written"); //@@ need dialog box denoting failure to write
return false;
}
}
public void doSaveAs() {
XFile oldfile = transcript.ourFile;
transcript.ourFile = new XFile();
if (doSave())
transFrame.setTitle(saveFile.getFileName());
else
transcript.ourFile = oldfile;
}
public void doMovieAs() {
transcript.makeMovie(true);
}
public void doMovieNoMetaAs() {
transcript.makeMovie(false);
}
public void doUndo() {
}
public void doCut() {
}
public void doCopy() {
}
public void doPaste() {
}
public void doClear() {
}
public void doSelectAll() {
}
class WindowAdpt extends java.awt.event.WindowAdapter {
public void windowClosing(java.awt.event.WindowEvent event) {
handleQuit();
}
}
class WindowAdptTranscript extends java.awt.event.WindowAdapter {
public void windowClosing(java.awt.event.WindowEvent event) {
closeWindow();
}
}
public boolean closeWindow() {
DoYouWantToSave ds;
if (transcript.isDirty()) { // the current transcript
ds = new DoYouWantToSave(VideoGrok.this,true);
ds.show();
// while (ds.getResult() == DoYouWantToSave.STASIS);
if (ds.getResult() == DoYouWantToSave.CANCEL) return false;
if (ds.getResult() == DoYouWantToSave.SAVE) {
doSave();
}
transcript.setDirty(false);
}
transcripts.remove(transcript);
transFrame.dispose();
transFrame=null;
return true;
}
PopupMenu coding;
/* public void optionMenus(ContentCodesHandler contentcodeshandler)
{
Menu menu = new Menu("Coding", true);
coding = new PopupMenu("Coding");
add(coding);
char c = 'A';
SymCode symcode = new SymCode();
contentcodeshandler.menus.reset();
Menu menu1;
for(; contentcodeshandler.menus.isNext(); menu.add(menu1))
{
String s = contentcodeshandler.menus.getNextString();
menu1 = new Menu(s);
StringVector stringvector = (StringVector)contentcodeshandler.menucontents.get(s);
stringvector.reset();
MenuItem menuitem1;
for(; stringvector.isNext(); menuitem1.addActionListener(symcode))
{
String s1 = stringvector.getNextString();
MenuItem menuitem = new MenuItem(s1);
if(s.equals("ContentCodes"))
menuitem.setShortcut(new MenuShortcut(c++, true));
menu1.add(menuitem);
menuitem1 = new MenuItem(s1);
coding.add(menuitem1);
menuitem.addActionListener(symcode);
}
}
mainMenuBar.add(menu);
}
*/
class SymCode
implements ActionListener
{
public void actionPerformed(ActionEvent actionevent)
{
Object obj = actionevent.getSource();
String s = ((MenuItem)obj).getLabel();
menuCoding(s);
}
SymCode()
{
}
}
public void menuCoding(String s)
{
Component component = getFocusOwner();
if(component instanceof TextArea)
{
// setUndo((TextComponent)component);
TextArea textarea = (TextArea)component;
if(textarea == null)
{
System.out.println("No text area active for " + s + " in FieldnoteEditor.menuCoding");
return;
}
int i = textarea.getSelectionStart();
int j = textarea.getSelectionEnd();
if(i == j)
{
// setUndo(textarea);
textarea.insert(s + "; ", i);
textarea.setCaretPosition(i + 2 + s.length());
// setDirty(true);
return;
} else {
String s1 = "<" + s + ">" + textarea.getSelectedText() + "</" + s + ">";
// setUndo(textarea);
textarea.replaceText(s1, i, j);
textarea.select(i, i + s1.length());
// setDirty(true);
}
}
}
public static void main(String args[]) {
new VideoGrok();
}
}