📄 importshoeboxwac.java
字号:
*/ public static Object showDialog() { return showDialog(SHOEBOX); } /** * DOCUMENT ME! * * @param type DOCUMENT ME! * * @return DOCUMENT ME! */ public static Object showDialog(int type) { return showDialog(null, type); } /** * Creates a Dialog to select some files for import. * * @param parent the parent Frame, can be null * @param type the type of import, either WAC or Shoebox * * @return a Hashtable with file names, or null */ public static Object showDialog(Frame parent, int type) { ImportShoeboxWAC pane = new ImportShoeboxWAC(type); JDialog dialog = pane.createDialog(parent, type); dialog.setVisible(true); dialog.dispose(); Object o = pane.getValue(); //System.out.println("Return Value: " + o); return o; } /** * Creates the dialog with <code>this</code> as content pane. * * @param parent the parent Frame or null * @param type the type of import, either WAC or Shoebox * * @return a modal JDialog */ private JDialog createDialog(Frame parent, int type) { final JDialog dialog = new ClosableDialog(); if (type == WAC) { dialog.setTitle(ElanLocale.getString("ImportDialog.Title.WAC")); } else { dialog.setTitle(ElanLocale.getString("ImportDialog.Title.Shoebox")); } dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(this, BorderLayout.CENTER); dialog.setModal(true); dialog.pack(); if (parent != null) { dialog.setLocationRelativeTo(parent); } dialog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { setValue(null); } }); // use the java.beans PropertyChangeSupport mechanism addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (dialog.isVisible() && (event.getSource() == ImportShoeboxWAC.this) && event.getPropertyName().equals(VALUE_PROPERTY)) { dialog.setVisible(false); } } }); return dialog; } /** * DOCUMENT ME! * * @param e DOCUMENT ME! */ public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == txtButton) { chooseSbxWAC(); } else if (source == typButton) { chooseTyp(); } else if (source == fieldSpecButton) { specifyFieldSpecs(); // } // else if (source == medButton) { // chooseMedia(); } else if (source == okButton) { checkFields(); /* if (checkFields()) { setValue(fileNames); } */ } else if (source == cancelButton) { setValue(null); } } private void chooseSbxWAC() { String lastUsedDir = (String) Preferences.get("LastUsedShoeboxDir", null); if (lastUsedDir == null) { lastUsedDir = System.getProperty("user.dir"); } JFileChooser chooser = new JFileChooser(lastUsedDir); chooser.setDialogTitle(ElanLocale.getString("ImportDialog.Title.Select")); if (importType == WAC) { chooser.setFileFilter(ElanFileFilter.createFileFilter( ElanFileFilter.WAC_TYPE)); } else { chooser.setAcceptAllFileFilterUsed(false); chooser.setFileFilter(ElanFileFilter.createFileFilter( ElanFileFilter.SHOEBOX_TEXT_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("LastUsedShoeboxDir", curDir.getAbsolutePath(), null); } File f = chooser.getSelectedFile(); if (f != null) { sbxField.setText(f.getAbsolutePath()); } } } 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()); Preferences.set("LastUsedShoeboxTypFile", f.getAbsolutePath(), null); Preferences.set("LastUsedShoeboxImportWithType", Boolean.TRUE, null); } } } private void specifyFieldSpecs() { ShoeboxMarkerDialog smd = new ShoeboxMarkerDialog(null, true); smd.setVisible(true); markers = (List) smd.getValue(); Preferences.set("LastUsedShoeboxImportWithType", Boolean.FALSE, null); //Preferences.set("LastUsedShoeboxMarkers", markers, null); } /** * Checks the contents of all input fields and next the existence of the * designated files. * * @return true if the files exist, false otherwise */ private boolean checkFields() { String sbxPath = null; String typPath = null; if (sbxField.getText() != null) { sbxPath = sbxField.getText().trim(); } if ((sbxPath == null) || (sbxPath.length() == 0)) { if (importType == WAC) { showError(ElanLocale.getString( "ImportDialog.Message.SpecifyWAC")); } else { showError(ElanLocale.getString( "ImportDialog.Message.SpecifyShoebox")); } return false; } if (typField.getText() != null) { typPath = typField.getText().trim(); } if (typeRB.isSelected() && ((typPath == null) || (typPath.length() == 0))) { showError(ElanLocale.getString("ImportDialog.Message.SpecifyType")); return false; } if (!(new File(sbxPath).exists())) { if (importType == WAC) { showError(ElanLocale.getString("ImportDialog.Message.NoWAC")); } else { showError(ElanLocale.getString("ImportDialog.Message.NoShoebox")); } return false; } if (typeRB.isSelected()) { if (!(new File(typPath).exists())) { showError(ElanLocale.getString("ImportDialog.Message.NoType")); return false; } } else { if ((markers == null) || (markers.size() == 0)) { showError(ElanLocale.getString( "ImportDialog.Message.SpecifyMarkers")); return false; } } int durVal = ShoeboxPreferences.DEFAULT_BLOCK_DURATION; if (intervalField != null) { String dur = intervalField.getText(); try { durVal = Integer.parseInt(dur); ShoeboxPreferences.preferredBlockDuration = durVal; Preferences.set(INTERVAL_PREF, durVal, null); } catch (NumberFormatException nfe) { // ignore } } ToolboxDecoderInfo decInfo = new ToolboxDecoderInfo(sbxPath); decInfo.setBlockDuration(durVal); if (typeRB.isSelected()) { decInfo.setTypeFile(typPath); decInfo.setAllUnicode(allUnicodeCB.isSelected()); } else { decInfo.setShoeboxMarkers(markers); } decInfo.setTimeInRefMarker(timeInRefMarker.isSelected()); setValue(decInfo); return true; } /** * Shows an error dialog. * * @param message */ private void showError(String message) { JOptionPane.showMessageDialog(this, message, ElanLocale.getString("Message.Error"), JOptionPane.ERROR_MESSAGE); } /** * DOCUMENT ME! * * @return the user object or null */ public Object getValue() { return value; } /** * Sets the new value the user has chosen. * * @param newValue the new value */ public void setValue(Object newValue) { Object oldValue = value; value = newValue; firePropertyChange(VALUE_PROPERTY, oldValue, value); } /** * DOCUMENT ME! * * @param e DOCUMENT ME! */ public void itemStateChanged(ItemEvent e) { if ((e.getSource() == typeRB) && (e.getStateChange() == ItemEvent.SELECTED)) { typeLabel.setEnabled(true); typButton.setEnabled(true); typField.setEnabled(true); allUnicodeCB.setEnabled(true); fieldSpecButton.setEnabled(false); markers = null; if ((typField.getText() == null) || (typField.getText().length() == 0)) { typButton.doClick(200); } } else if ((e.getSource() == specRB) && (e.getStateChange() == ItemEvent.SELECTED)) { typeLabel.setEnabled(false); typButton.setEnabled(false); typField.setEnabled(false); allUnicodeCB.setEnabled(false); fieldSpecButton.setEnabled(true); fieldSpecButton.doClick(200); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -