⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exportshoebox.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    private Vector getHierarchicallySortedTiers(TranscriptionImpl transcription) {        // for each root tier, find dependency tree.        // store in a Vector with Vectors, one for each root.        // take the largest tier tree first, this is likely to be the interlinear tree        Vector tierTrees = new Vector();        Vector sortedTiers = new Vector();        Vector topTiers = transcription.getTopTiers();        for (int i = 0; i < topTiers.size(); i++) {            TierImpl topTier = (TierImpl) topTiers.elementAt(i);            tierTrees.add(getTierTree(topTier));        }        Collections.sort(tierTrees, new VectorComparator());        for (int j = 0; j < tierTrees.size(); j++) {            sortedTiers.addAll((Vector) tierTrees.elementAt(j));        }        return sortedTiers;    }    private void setShoeboxMarkerRB() {        Object useTyp = Preferences.get("LastUsedShoeboxExport", null);        if (useTyp == null) {            tierNamesRB.setSelected(true);        } else if (useTyp instanceof String &&                ((String) useTyp).equalsIgnoreCase("markers")) {            specRB.setSelected(true);            //typButton.setEnabled(false);            fieldSpecButton.setEnabled(true);            Object mo = Preferences.get("LastUsedShoeboxMarkers", null);            if (mo instanceof List) {                markers = (List) mo;            }        } else if (useTyp instanceof String &&                ((String) useTyp).equalsIgnoreCase("typ")) {            typeRB.setSelected(true);            Object luTypFile = Preferences.get("LastUsedShoeboxTypFile", null);            if (luTypFile instanceof String) {                typField.setText((String) luTypFile);            }            //typButton.setEnabled(true);        } else {            tierNamesRB.setSelected(true);        }    }    private void autoGenerateMarkerFile() {        // generate marker records for each tier.        // only marker, parent marker and stereotype have to be set, rest is default        Vector markerRecords = new Vector();        try {            Vector tiers = transcription.getTiers();            for (int i = 0; i < tiers.size(); i++) {                TierImpl t = (TierImpl) tiers.elementAt(i);                MarkerRecord mkrRecord = new MarkerRecord();                mkrRecord.setMarker(t.getName());                if (t.hasParentTier()) {                    mkrRecord.setParentMarker(t.getParentTier().getName());                    if (t.getLinguisticType() != null) {                        int stereotype = t.getLinguisticType().getConstraints()                                          .getStereoType();                        if ((stereotype == Constraint.SYMBOLIC_SUBDIVISION) ||                                (stereotype == Constraint.TIME_SUBDIVISION) ||                                (stereotype == Constraint.INCLUDED_IN)) {                            //mkrRecord.setStereoType(Constraint.publicStereoTypes[2]);                            mkrRecord.setStereoType(Constraint.stereoTypes[Constraint.SYMBOLIC_SUBDIVISION]);                        } else if (stereotype == Constraint.SYMBOLIC_ASSOCIATION) {                            //mkrRecord.setStereoType(Constraint.publicStereoTypes[3]);                            mkrRecord.setStereoType(Constraint.stereoTypes[Constraint.SYMBOLIC_ASSOCIATION]);                        }                    }                }                mkrRecord.setCharset(MarkerRecord.UNICODESTRING);                mkrRecord.setParticipantMarker(false);                mkrRecord.setExcluded(false);                markerRecords.add(mkrRecord);            }            // store in mkr file with name of transcription, next to eaf            // dec 2006 HS: by default the .mkr file will now be saved next to the export file            String fileName = ((TranscriptionImpl) transcription).getPathName();            if (exportFileName != null) {                fileName = exportFileName.substring(0,                        exportFileName.lastIndexOf("."));            } else if (fileName.toLowerCase().endsWith(".eaf")) {                fileName = fileName.substring(0, fileName.lastIndexOf("."));            }            fileName += ".mkr";            final File newSaveFile = new File(fileName);            if (newSaveFile != null) {                if (newSaveFile.exists()) {                    int answer = JOptionPane.showConfirmDialog(null,                            ElanLocale.getString("Message.Overwrite") + "\n" +                            fileName,                            ElanLocale.getString("SaveDialog.Message.Title"),                            JOptionPane.YES_NO_OPTION);                    if (answer == JOptionPane.NO_OPTION) {                        return;                    }                }                FileOutputStream out = new FileOutputStream(newSaveFile);                BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(                            out, "UTF-8"));                Iterator markerIter = markerRecords.iterator();                while (markerIter.hasNext()) {                    writer.write(((MarkerRecord) markerIter.next()).toString());                }                writer.close();            }        } catch (Exception ex) {            ex.printStackTrace();        }    }    /**     * Checks the contents of marker input fields and next the existence of the     * designated files.     *     * @return true if the files exist, false otherwise     */    private boolean checkMarkerFields() {        if (typeRB.isSelected() &&                ((typField.getText() == null) ||                (typField.getText().length() == 0))) {            showError(ElanLocale.getString("ImportDialog.Message.SpecifyType"));            return false;        }        if (typeRB.isSelected()) {            File tf = new File(typField.getText());            if (!tf.exists()) {                showError(ElanLocale.getString("ImportDialog.Message.NoType"));                return false;            } else {                try {                    ShoeboxTypFile typFile = new ShoeboxTypFile(tf);                    databaseType = typFile.getDatabaseType();                } catch (Exception e) {                }            }        } else {            databaseType = dbTypField.getText();        }        return true;    }    private void chooseTyp() {        String lastUsedDir = (String) Preferences.get("LastUsedShoeboxTypDir",                null);        if (lastUsedDir == null) {            lastUsedDir = System.getProperty("user.dir");        }        JFileChooser chooser = new JFileChooser(lastUsedDir);        chooser.setDialogTitle(ElanLocale.getString("ImportDialog.Title.Select"));        chooser.setFileFilter(ElanFileFilter.createFileFilter(                ElanFileFilter.SHOEBOX_TYP_TYPE));        chooser.setApproveButtonText(ElanLocale.getString(                "ImportDialog.Approve"));        chooser.setDialogType(JFileChooser.OPEN_DIALOG);        int option = chooser.showDialog(this, null);        if (option == JFileChooser.APPROVE_OPTION) {            File curDir = chooser.getCurrentDirectory();            if (curDir != null) {                Preferences.set("LastUsedShoeboxTypDir",                    curDir.getAbsolutePath(), null);            }            File f = chooser.getSelectedFile();            if (f != null) {                typField.setText(f.getAbsolutePath());            }        }    }    //******************************    // actual export methods from here, for the time being    //******************************    /**     * The actual writing.     *     * @param fileName path to the file, not null     * @param orderedTiers tier names, ordered by the user, min size 1     * @param charsPerLine num of chars per line if linewrap is selected     * @param timeFormat DOCUMENT ME!     * @param correctTimes DOCUMENT ME!     *     * @return true if all went well, false otherwise     */    private boolean doExport(final String fileName, final List orderedTiers,        final int charsPerLine, final int timeFormat, final boolean correctTimes) {        int markerSource = ToolboxEncoderInfo.TIERNAMES; // default        if (typeRB.isSelected()) {            markerSource = ToolboxEncoderInfo.TYPFILE;            Preferences.set("LastUsedShoeboxExport", "typ", null);            Preferences.set("LastUsedShoeboxTypFile", typField.getText(), null);        } else if (specRB.isSelected()) {            markerSource = ToolboxEncoderInfo.DEFINED_MARKERS;            Preferences.set("LastUsedShoeboxExport", "markers", null);            if (markers != null) {                Preferences.set("LastUsedShoeboxMarkers", markers, null);            }        } else {            Preferences.set("LastUsedShoeboxExport", "", null);        }        ToolboxEncoderInfo tbEncoderInfo = new ToolboxEncoderInfo(charsPerLine,                markerSource, timeFormat);        tbEncoderInfo.setCorrectAnnotationTimes(correctTimes);        if (databaseType != null) {            tbEncoderInfo.setDatabaseType(databaseType);        }        if (typeRB.isSelected()) {            //   tbEncoderInfo.setDatabaseType(databaseType);            if (allUnicodeCB.isSelected()) {                tbEncoderInfo.setAllUnicode(true);            }        } else if (specRB.isSelected()) {            tbEncoderInfo.setMarkers(markers);        }        if (fileName != null) {            new ACM24TranscriptionStore().storeTranscriptionIn(transcription,                tbEncoderInfo, new Vector(orderedTiers), fileName,                TranscriptionStore.SHOEBOX);        }        return true;    }    /**     * Moves selected tiers up in the list of tiers.     */    private void moveDown() {        if ((tierTable == null) || (model == null) ||                (model.getRowCount() < 2)) {            return;        }        int[] selected = tierTable.getSelectedRows();        for (int i = selected.length - 1; i >= 0; i--) {            int row = selected[i];            if ((row < (model.getRowCount() - 1)) &&                    !tierTable.isRowSelected(row + 1)) {                model.moveRow(row, row, row + 1);                tierTable.changeSelection(row, 0, true, false);                tierTable.changeSelection(row + 1, 0, true, false);            }        }    }    /**     * Moves selected tiers up in the list of tiers.     */    private void moveUp() {        if ((tierTable == null) || (model == null) ||                (model.getRowCount() < 2)) {            return;        }        int[] selected = tierTable.getSelectedRows();        for (int i = 0; i < selected.length; i++) {            int row = selected[i];            if ((row > 0) && !tierTable.isRowSelected(row - 1)) {                model.moveRow(row, row, row - 1);                tierTable.changeSelection(row, 0, true, false);                tierTable.changeSelection(row - 1, 0, true, false);            }        }    }    /**     * Shows an error dialog.     *     * @param message     */    private void showError(String message) {        JOptionPane.showMessageDialog(this, message,            ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE);    }    private void specifyFieldSpecs() {        ShoeboxMarkerDialog smd = new ShoeboxMarkerDialog(null, true);        smd.setVisible(true);        markers = smd.getMarkers();    }    //***********************    // inner classes    //***********************	    class VectorComparator implements Comparator {        /**         * Compares Vectors, on basis of their size. The largest one comes         * first         *         * @see java.util.Comparator#compare(java.lang.Object,         *      java.lang.Object)         */        public int compare(Object arg0, Object arg1) {            Vector v0 = (Vector) arg0;            Vector v1 = (Vector) arg1;            if (v0.size() < v1.size()) {                return 1;            }            if (v0.size() > v1.size()) {                return -1;            }            return 0;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -