From b4e4decc2e3dbe395c2541df97a463d21f0f8d7b Mon Sep 17 00:00:00 2001 From: eg3p Date: Sat, 2 Nov 2002 22:11:02 +0000 Subject: [PATCH] Updates, including support for internationalized strings. --- source/org/thdl/savant/Savant.java | 305 ++++++++++++++---------- source/org/thdl/savant/SavantShell.java | 107 ++++++--- 2 files changed, 241 insertions(+), 171 deletions(-) diff --git a/source/org/thdl/savant/Savant.java b/source/org/thdl/savant/Savant.java index cd04e9e..b9c7675 100644 --- a/source/org/thdl/savant/Savant.java +++ b/source/org/thdl/savant/Savant.java @@ -22,6 +22,8 @@ import java.awt.Font; import java.awt.Label; import java.awt.Color; import java.awt.Frame; +import java.awt.Cursor; +import java.awt.Window; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.BorderLayout; @@ -42,6 +44,7 @@ import java.util.Enumeration; import java.util.StringTokenizer; import java.util.Timer; import java.util.TimerTask; +import java.util.ResourceBundle; import java.io.CharArrayWriter; import java.io.CharArrayReader; @@ -59,12 +62,14 @@ import javax.swing.*; import javax.swing.text.*; import javax.swing.text.rtf.RTFEditorKit; +import org.thdl.media.*; import org.thdl.util.ThdlDebug; import org.thdl.util.ThdlActionListener; +import org.thdl.util.ThdlI18n; public class Savant extends JDesktopPane { - protected SoundPanel sp = null; + protected SmartMoviePanel sp = null; protected TwoWayTextPlayer tp = null; protected JInternalFrame videoFrame = null; @@ -75,25 +80,47 @@ public class Savant extends JDesktopPane protected boolean isFullScreen = false; protected Dimension fullScreenSize = null; - protected JPanel videoPanel = null; protected JPanel textPanel = null; protected JScrollPane vocabPanel = null; + protected URL mediaURL = null; protected URL extras = null; + protected TranscriptView[] transcriptViews; protected int orientation = 0; + + protected ResourceBundle messages; + public final int TOP_TO_BOTTOM = 1; public final int LEFT_TO_RIGHT = 2; public Savant() { + messages = ThdlI18n.getResourceBundle(); + setBackground(new JFrame().getBackground()); setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); - setLayout(new BorderLayout()); - String labelString = "Please wait while Savant loads this transcript and media."; - JLabel label = new JLabel(labelString, SwingConstants.CENTER); - label.setFont(new Font("Serif", Font.PLAIN, 14)); - add("Center", label); + + //(String title, boolean resizable, boolean closable, boolean maximizable, boolean iconifiable) + videoFrame = new JInternalFrame(null, false, false, false, false); + videoFrame.setVisible(true); + videoFrame.setLocation(0,0); + videoFrame.setSize(0,0); + add(videoFrame, JLayeredPane.POPUP_LAYER); + invalidate(); + validate(); + repaint(); + + textFrame = new JInternalFrame(messages.getString("Transcript"), false, false, false, true); + textPanel = new JPanel(new BorderLayout()); + textFrame.setVisible(true); + textFrame.setLocation(0,0); + textFrame.setSize(0,0); + textFrame.setContentPane(textPanel); + add(textFrame, JLayeredPane.DEFAULT_LAYER); + invalidate(); + validate(); + repaint(); addComponentListener(new ComponentAdapter() { @@ -103,24 +130,13 @@ public class Savant extends JDesktopPane case TOP_TO_BOTTOM: videoFrame.setLocation(getSize().width/2 - videoFrame.getSize().width/2, 0); textFrame.setLocation(0, videoFrame.getSize().height); - if (vocabFrame != null) - { - textFrame.setSize(getSize().width / 2, getSize().height - videoFrame.getSize().height); - vocabFrame.setLocation(textFrame.getSize().width, videoFrame.getSize().height); - vocabFrame.setSize(getSize().width - textFrame.getSize().width, getSize().height - videoFrame.getSize().height); - } else - textFrame.setSize(getSize().width, getSize().height - videoFrame.getSize().height); + textFrame.setSize(getSize().width, getSize().height - videoFrame.getSize().height); break; case LEFT_TO_RIGHT: videoFrame.setLocation(0,0); textFrame.setLocation(videoFrame.getSize().width, 0); textFrame.setSize(getSize().width - videoFrame.getSize().width, getSize().height); - if (vocabFrame != null) - { - vocabFrame.setLocation(0, videoFrame.getSize().height); - vocabFrame.setSize(videoFrame.getSize().width, getSize().height - videoFrame.getSize().height); - } break; default: @@ -132,8 +148,13 @@ public class Savant extends JDesktopPane public void close() { - if (sp != null) - sp.destroy(); + if (sp != null) { + try { + sp.destroy(); + } catch (SmartMoviePanelException smpe) { + smpe.printStackTrace(); + } + } } public void open(TranscriptView[] views, String video, String vocabulary) @@ -149,14 +170,108 @@ public class Savant extends JDesktopPane } } - public void open(final TranscriptView[] views, final URL video, final URL vocabulary) - { - videoPanel = new JPanel(new GridLayout(1,1)); - textPanel = new JPanel(new BorderLayout()); + public void setMediaPlayer(SmartMoviePanel smp) { + if (sp == smp) + return; - sp = new SoundPanel(this, video, views[0].getT1s(), views[0].getT2s(), views[0].getIDs()); + if (sp != null) { + try { + sp.destroy(); + videoFrame.getContentPane().removeAll(); + } catch (SmartMoviePanelException smpe) { + smpe.printStackTrace(); + ThdlDebug.noteIffyCode(); + } + } + + sp = smp; + sp.setParentContainer(Savant.this); + if (mediaURL != null) { + String t1s = convertTimesForSmartMoviePanel(transcriptViews[0].getT1s()); + String t2s = convertTimesForSmartMoviePanel(transcriptViews[0].getT2s()); + sp.initForSavant(t1s, t2s, transcriptViews[0].getIDs()); + sp.addAnnotationPlayer(tp); + try { + sp.loadMovie(mediaURL); + startTimer(); + } catch (SmartMoviePanelException smpe) { + smpe.printStackTrace(); + ThdlDebug.noteIffyCode(); + } + } + } + + private void startTimer() { + final java.util.Timer timer = new java.util.Timer(true); + timer.schedule(new TimerTask() { + public void run() + { + if (sp.isInitialized()) + { + System.out.println("initialized"); + + timer.cancel(); + videoFrame.getContentPane().add(sp); + videoFrame.pack(); + videoFrame.setMaximumSize(videoFrame.getSize()); + if (videoFrame.getSize().height < 100) //must be audio file, so frame top to bottom + { + orientation = TOP_TO_BOTTOM; + videoFrame.setTitle(messages.getString("Audio")); + videoFrame.setLocation(getSize().width/2 - videoFrame.getSize().width/2, 0); + textFrame.setLocation(0, videoFrame.getSize().height); + textFrame.setSize(getSize().width, getSize().height - videoFrame.getSize().height); + } else { //must be video file, so frame left to right + orientation = LEFT_TO_RIGHT; + videoFrame.setTitle(messages.getString("Video")); + videoFrame.setLocation(0,0); + textFrame.setLocation(videoFrame.getSize().width, 0); + textFrame.setSize(getSize().width - videoFrame.getSize().width, getSize().height); + } + invalidate(); + validate(); + repaint(); + + Window rootWindow = (Window)SwingUtilities.getAncestorOfClass(Window.class, Savant.this); + rootWindow.setCursor(null); + } + }}, 0, 50); + } + + public SmartMoviePanel getMediaPlayer() { + return sp; + } + + private String convertTimesForSmartMoviePanel(String s) { + StringBuffer sBuff = new StringBuffer(); + StringTokenizer sTok = new StringTokenizer(s, ","); + while (sTok.hasMoreTokens()) { + sBuff.append(String.valueOf(new Float(Float.parseFloat(sTok.nextToken()) * 1000).intValue())); + sBuff.append(','); + } + return sBuff.toString(); + } + public void open(TranscriptView[] views, URL video, final URL vocabulary) + { +/* FIXME eventually + w/Savant and SoundPanel times were in seconds. QuillDriver's + SmartMoviePanel uses milliseconds instead, so here I convert + (for the time being anyway - eventually we need the same + time code format for both QD and Savant. */ + + String t1s = convertTimesForSmartMoviePanel(views[0].getT1s()); + String t2s = convertTimesForSmartMoviePanel(views[0].getT2s()); + + if (sp == null) { + JOptionPane.showConfirmDialog(Savant.this, messages.getString("SupportedMediaError"), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); + return; + } + + sp.initForSavant(t1s, t2s, views[0].getIDs()); tp = new TwoWayTextPlayer(sp, views[0], Color.cyan); + transcriptViews = views; + JPanel jp = new JPanel(); String[] viewNames = new String[views.length]; for (int i=0; i 0) { + SmartMoviePanel defaultPlayer = (SmartMoviePanel)moviePlayers.get(0); + savant.setMediaPlayer(defaultPlayer); //set savant media player to default + if (moviePlayers.size() > 1) + preferencesMenu.add(mediaPlayerMenu); + } + + JMenu infoMenu = new JMenu(messages.getString("InfoShort")); + JMenuItem helpItem = new JMenuItem(messages.getString("Help")); helpItem.addActionListener(new ThdlActionListener() { public void theRealActionPerformed(ActionEvent e) { - new SimpleFrame("Help", helpPane); + new SimpleFrame(messages.getString("Help"), helpPane); } }); - JMenuItem aboutItem = new JMenuItem("About"); + JMenuItem aboutItem = new JMenuItem(messages.getString("About")); aboutItem.addActionListener(new ThdlActionListener() { public void theRealActionPerformed(ActionEvent e) { - new SimpleFrame("About", aboutPane); + new SimpleFrame(messages.getString("About"), aboutPane); } }); infoMenu.add(helpItem); @@ -235,6 +261,7 @@ public class SavantShell extends JFrame infoMenu.getPopupMenu().setLightWeightPopupEnabled(false); menuBar.add(fileMenu); + menuBar.add(preferencesMenu); menuBar.add(infoMenu); setJMenuBar(menuBar); @@ -269,13 +296,14 @@ public class SavantShell extends JFrame public void newSavantWindow(String project, String titleName, URL trn, URL vid, URL abt) { try { - if (numberOfSavantsOpen == 0) + if (numberOfSavantsOpen == 0) { + setCursor(new Cursor(Cursor.WAIT_CURSOR)); openSavant(project, titleName, trn, vid, abt); - else { + } else { SavantShell scp = new SavantShell(); scp.setVisible(true); + setCursor(new Cursor(Cursor.WAIT_CURSOR)); scp.openSavant(project, titleName, trn, vid, abt); - scp.setFileChooser(fileChooser); } numberOfSavantsOpen++; } catch (NoClassDefFoundError err) { @@ -286,7 +314,6 @@ public class SavantShell extends JFrame public void openSavant(String project, String titleName, URL trn, URL vid, URL abt) { setTitle(titleName); - savant = new Savant(); setContentPane(savant); validate(); savant.paintImmediately(0,0,savant.getWidth(),savant.getHeight()); @@ -324,11 +351,13 @@ public class SavantShell extends JFrame if (i!=-1) { +/* JOptionPane.showMessageDialog(this, "If you want to see text in Tibetan script, "+ "please visit www.thdl.org to download and "+ "install the Tibetan Machine Web fonts.", "Note", JOptionPane.INFORMATION_MESSAGE); +*/ TranscriptView[] views = new TranscriptView[3]; views[0] = new org.thdl.savant.tib.Wylie(isr);