interlinearviewer.java
来自「编辑视频文件」· Java 代码 · 共 2,005 行 · 第 1/5 页
JAVA
2,005 行
* Returns the index of the specified tag in the tier's array of tags. * * @param tier the tier * @param tag the tag * * @return the index */ private int getTagIndex(Tier2D tier, SBTime tag) { int j = visibleTiers.indexOf(tier); if (j > -1) { Vector v = (Vector) _vTiers.get(j); return v.indexOf(tag); } return -1; } /** * Tries to find the tag / annotation at the specified point on the canvas.<br> * Collections.binarySearch seems to work properly here. * * @param p the Point to get the tag for * * @return the selected tag or null when there is no tag at Point p */ private SBTime getTagAtPoint(Point p) { if (p.y <= VER_MARGIN) { return null; } p.x += horizontalScrollOffset; p.y += verticalScrollOffset; int size = _vTiers.size(); int curtier = getTierIndexForPoint(p); //System.out.println("Curtier: " + curtier); if ((curtier >= size) || (curtier < 0)) { return null; } // get current tier Vector v = (Vector) _vTiers.elementAt(curtier); // iterate through the rects and find match SBTime sb = null; int pos = -1; if ((pos = Collections.binarySearch(v, p)) >= 0) { sb = (SBTime) v.elementAt(pos); return sb; } return null; } /** * Create a popup menu to enable the manipulation of some settings for this * viewer. */ private void createPopupMenu() { popup = new JPopupMenu("Interlinear Viewer"); // font size items int fontSize = getFont().getSize(); fontSizeBG = new ButtonGroup(); fontMenu = new JMenu(ElanLocale.getString("Menu.View.FontSize")); JRadioButtonMenuItem fontRB; for (int i = 0; i < Constants.FONT_SIZES.length; i++) { fontRB = new JRadioButtonMenuItem(String.valueOf( Constants.FONT_SIZES[i])); fontRB.setActionCommand("font" + Constants.FONT_SIZES[i]); if (fontSize == Constants.FONT_SIZES[i]) { fontRB.setSelected(true); } fontRB.addActionListener(this); fontSizeBG.add(fontRB); fontMenu.add(fontRB); } popup.add(fontMenu); popup.addSeparator(); // tier menu items activeTierMI = new JMenuItem(ElanLocale.getString( "Menu.Tier.ActiveTier")); activeTierMI.setActionCommand("activeTier"); activeTierMI.addActionListener(this); popup.add(activeTierMI); deleteTierMI = new JMenuItem(ElanLocale.getString( "Menu.Tier.DeleteTier")); deleteTierMI.setActionCommand("deleteTier"); deleteTierMI.addActionListener(this); popup.add(deleteTierMI); changeTierMI = new JMenuItem(ElanLocale.getString( "Menu.Tier.ChangeTier")); //changeTierMI = new JMenuItem(ELANCommandFactory.CHANGE_TIER_ATTR); changeTierMI.setActionCommand("changeTier"); changeTierMI.addActionListener(this); popup.add(changeTierMI); popup.addSeparator(); // annotation menu items newAnnoMI = new JMenuItem(ElanLocale.getString( "Menu.Annotation.NewAnnotation")); newAnnoMI.setActionCommand("newAnn"); newAnnoMI.addActionListener(this); popup.add(newAnnoMI); newAnnoBeforeMI = new JMenuItem(ElanLocale.getString( "Menu.Annotation.NewAnnotationBefore")); newAnnoBeforeMI.setActionCommand("annBefore"); newAnnoBeforeMI.addActionListener(this); popup.add(newAnnoBeforeMI); newAnnoAfterMI = new JMenuItem(ElanLocale.getString( "Menu.Annotation.NewAnnotationAfter")); newAnnoAfterMI.setActionCommand("annAfter"); newAnnoAfterMI.addActionListener(this); popup.add(newAnnoAfterMI); modifyAnnoMI = new JMenuItem(ElanLocale.getString( "Menu.Annotation.ModifyAnnotation")); modifyAnnoMI.setActionCommand("modifyAnn"); modifyAnnoMI.addActionListener(this); popup.add(modifyAnnoMI); deleteAnnoMI = new JMenuItem(ElanLocale.getString( "Menu.Annotation.DeleteAnnotation")); deleteAnnoMI.setActionCommand("deleteAnn"); deleteAnnoMI.addActionListener(this); popup.add(deleteAnnoMI); JPopupMenu.setDefaultLightWeightPopupEnabled(false); } /** * Enables / disables annotation and tier specific menuitems, depending on * the mouse click position.<br> * <b>Note: </b> this might need to be changed once usage of Action and * Command objects is implemented. * * @param p the position of the mouse click */ private void updatePopup(Point p) { //disable all first newAnnoMI.setEnabled(false); newAnnoBeforeMI.setEnabled(false); newAnnoAfterMI.setEnabled(false); modifyAnnoMI.setEnabled(false); deleteAnnoMI.setEnabled(false); activeTierMI.setEnabled(false); deleteTierMI.setEnabled(false); changeTierMI.setEnabled(false); if (p.y < VER_MARGIN) { return; } else { Point pp = new Point(p); rightClickTier = getTierAtPoint(pp); if (rightClickTier == null) { return; } TierImpl tier = rightClickTier.getTier(); if (tier == null) { return; } deleteTierMI.setEnabled(true); changeTierMI.setEnabled(true); if (!rightClickTier.isActive()) { activeTierMI.setEnabled(true); } Point tp = new Point(p); rightClickTag = getTagAtPoint(tp); if (rightClickTag == null) { // nothing to do when we are not on a tag return; } boolean supportsInsertion = false; try { LinguisticType lt = tier.getLinguisticType(); Constraint c = null; if (lt != null) { c = lt.getConstraints(); } if (c != null) { supportsInsertion = c.supportsInsertion(); } if (rightClickTag == cursorTag) { //?? need this ?? modifyAnnoMI.setEnabled(true); deleteAnnoMI.setEnabled(true); if (supportsInsertion) { newAnnoAfterMI.setEnabled(true); newAnnoBeforeMI.setEnabled(true); } else if (tier.isTimeAlignable() && (rightClickTag.annotation != null) /*&& !(rightClickTag.annotation instanceof RefAnnotation)*/) { // should be else if (tier.isTimeAlignable()){ newAnnoMI.setEnabled(true); //replace an existing annotation?? } } else if ((rightClickTag.startt == rightClickTag.endt) && (rightClickTag.startt != -1)) { //there is a tag but not an annotation? newAnnoMI.setEnabled(true); } } catch (Exception rex) { rex.printStackTrace(); } } } /** * Set the inline edit box to invisible by canceling the edit. */ private void dismissEditBox() { if (editBox.isVisible()) { editBox.cancelEdit(); } } /** * Display the edit box for the specified SBTime. * * @param sbt the tag to edit */ private void showEditBoxForTag(SBTime sbt) { if (sbt.annotation == null) { return; } editBox.setAnnotation(sbt.annotation); editBox.setSize(new Dimension(sbt._rect.width, sbt._rect.height)); editBox.setLocation(sbt._rect.x - horizontalScrollOffset, sbt._rect.y - verticalScrollOffset); editBox.configureEditor(JPanel.class, null, new Dimension(sbt._rect.width, sbt._rect.height)); editBox.startEdit(); } /** * Try to find the SBTime for the specified annotation and forward to * <code>showEditBoxForTag</code>. * * @param a the annotation to edit */ private void showEditBoxForAnnotation(Annotation a) { if (a == null) { return; } Iterator visIt = _vTiers.iterator(); while (visIt.hasNext()) { Vector v = (Vector) visIt.next(); Iterator tagIt = v.iterator(); while (tagIt.hasNext()) { SBTime tag = (SBTime) tagIt.next(); if (tag.annotation == a) { showEditBoxForTag(tag); return; } } } } //***** editing and data changed methods **************************************// /** * Add a new Tier to the existing list of tiers.<br> * This method is private because it does not check whether the specified * Tier already is present in the transcription. * * @param tier the new Tier */ private void tierAdded(TierImpl tier) { Tier2D t2d = new Tier2D(tier); allTiers.add(t2d); sbl.getSegOrder(); tierYPositions = new int[allTiers.size()]; // wait for a call to setVisibleTiers to show the tier } /** * Remove a Tier from the list of tiers. * * @param tier the Tier to remove */ private void tierRemoved(TierImpl tier) { dismissEditBox(); for (int i = 0; i < allTiers.size(); i++) { Tier2D tier2d = (Tier2D) allTiers.get(i); if (tier2d.getTier() == tier) { allTiers.remove(i); //wait for a call to setVisibleTiers if ((cursorTag != null) && (cursorTag.annotation != null) && (cursorTag.annotation.getTier() == tier)) { cursorTag = null; setActiveAnnotation(null); } break; } } } /** * Check the name of the Tier2D object of the specified Tier.<br> * Other changes to the tier such as linguistic type or parent are * expected to become manifest through (a series of) changes in * annotations. * * @param tier the Tier that has been changed */ private void tierChanged(TierImpl tier) { for (int i = 0; i < allTiers.size(); i++) { Tier2D tier2d = (Tier2D) allTiers.get(i); if (tier2d.getTier() == tier) { tier2d.updateName(); break; } } } /** * This method inserts a new annotation if there is an empty slot at the * specified point on the tier.<br> * <b>Note: </b> The current implementation relies on the annotation / text * layout, i.e. if there is an SBTime object with annotation == null and * start time == end time and start time != -1, it is assumed that we can * insert a new annotation. * * @param tier2d the Tier2D * @param p the location of a doubleclick in component space */ private void autoInsertAnnotation(Tier2D tier2d, Point p) { dismissEditBox(); TierImpl child = (TierImpl) tier2d.getTier(); if ((child == null) || child.isTimeAlignable() || !child.hasParentTier()) { return; } SBTime sbt = getTagAtPoint(p); if ((sbt == null) || (sbt.annotation != null) || (sbt.startt == -1) || (sbt.startt != sbt.endt)) { return; } else { Command c = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.NEW_ANNOTATION); Object[] args = new Object[] { new Long(sbt.startt + 1), new Long(sbt.startt + 1) }; c.execute(child, args); Annotation aa = child.getAnnotationAtTime(sbt.startt + 1); if (aa != null) { sbt.annotation = aa; setActiveAnnotation(aa); showEditBoxForTag(sbt); if (editBox.isVisible()) { editBox.requestFocus(); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?