From 0be9ae469a058d8f3605cca1c76faaed8ab994a4 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 18 Mar 2023 17:56:07 +0800 Subject: [PATCH] remove: legacy user interface --- src/cli/WhisperPrep.java | 177 -------- src/gui/CustomJTable.java | 49 -- src/gui/EXTHAddRecordListener.java | 8 - src/gui/GenericFileFilter.java | 37 -- src/gui/GuiException.java | 14 - src/gui/GuiModel.java | 201 -------- src/gui/HeaderInfoDialog.java | 73 --- src/gui/LanguageCodes.java | 76 ---- src/gui/LanguageDialog.java | 249 ---------- src/gui/LanguageModel.java | 12 - src/gui/Main.java | 708 ----------------------------- src/gui/MetaInfoProvider.java | 6 - src/gui/NewRecordDialog.java | 175 ------- 13 files changed, 1785 deletions(-) delete mode 100644 src/cli/WhisperPrep.java delete mode 100644 src/gui/CustomJTable.java delete mode 100644 src/gui/EXTHAddRecordListener.java delete mode 100644 src/gui/GenericFileFilter.java delete mode 100644 src/gui/GuiException.java delete mode 100644 src/gui/GuiModel.java delete mode 100644 src/gui/HeaderInfoDialog.java delete mode 100644 src/gui/LanguageCodes.java delete mode 100644 src/gui/LanguageDialog.java delete mode 100644 src/gui/LanguageModel.java delete mode 100644 src/gui/Main.java delete mode 100644 src/gui/MetaInfoProvider.java delete mode 100644 src/gui/NewRecordDialog.java diff --git a/src/cli/WhisperPrep.java b/src/cli/WhisperPrep.java deleted file mode 100644 index 6ce7d13..0000000 --- a/src/cli/WhisperPrep.java +++ /dev/null @@ -1,177 +0,0 @@ -package cli; - -import java.util.Iterator; -import java.util.List; -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.LinkedList; - -import mobimeta.*; - -public class WhisperPrep -{ - private File inDir; - private File outDir; - private BufferedReader in; - - public final static void main(String[] args) - { - if (args.length != 2) printUsage(); - - File inDir = new File(args[0]); - File outDir = new File(args[1]); - - if (!inDir.exists() || !inDir.isDirectory()) - printUsage("Input directory " + args[0] + " does not exist."); - - if (!outDir.exists() || !outDir.isDirectory()) - printUsage("Output directory " + args[1] + " does not exist."); - - if (inDir.getAbsolutePath().equals(outDir.getAbsolutePath())) - printUsage("Input and output directories cannot be the same."); - - WhisperPrep wp = new WhisperPrep(inDir, outDir); - wp.start(); - } - - private static void printUsage() - { - printUsage(null); - } - - private static void printUsage(String message) - { - if (message != null) System.err.println(message); - System.err.println("Usage: WhisperPrep "); - System.exit(0); - } - - public WhisperPrep(File inDir, File outDir) - { - this.inDir = inDir; - this.outDir = outDir; - } - - public void start() - { - LinkedList fileList = new LinkedList(); - for (File f : inDir.listFiles()) - { - if (f.isFile() && f.getName().toLowerCase().endsWith(".mobi")) - fileList.add(f); - } - - in = new BufferedReader(new InputStreamReader(System.in)); - - int fileCount = fileList.size(); - int current = 1; - for (File f : fileList) - { - log("********************"); - log("File " + (current++) + "/" + fileCount); - log("Filename: " + f.getName()); - MobiMeta meta = null; - try - { - meta = new MobiMeta(f); - } - catch (MobiMetaException e) - { - log("Error: " + e.getMessage()); - continue; - } - - log("Fullname: " + meta.getFullName()); - List exthList = meta.getEXTHRecords(); - String encoding = meta.getCharacterEncoding(); - String author = null; - String isbn = null; - String oldasin = null; - for (EXTHRecord rec : exthList) - { - switch (rec.getRecordType()) - { - case 100: - author = StreamUtils.byteArrayToString(rec.getData(), encoding); - break; - - case 104: - isbn = StreamUtils.byteArrayToString(rec.getData(), encoding); - break; - - case 113: - oldasin = StreamUtils.byteArrayToString(rec.getData(), encoding); - break; - - default: - break; - } - } - - if (author != null) log("Author: " + author); - if (isbn != null) log("ISBN: " + isbn); - String asin = null; - if (oldasin == null) - asin = getInput("ASIN: "); - else - asin = getInput("ASIN [" + oldasin + "]: "); - - if (asin.length() == 0) - { - if (oldasin != null) - asin = oldasin; - else - asin = null; - } - - for (Iterator it = exthList.iterator(); it.hasNext(); ) - { - EXTHRecord rec = it.next(); - int recType = rec.getRecordType(); - if (recType == 113) - { - if (asin != null) it.remove(); - } - else if (recType == 501) - it.remove(); - } - - if (asin != null) exthList.add(new EXTHRecord(113, asin, encoding)); - exthList.add(new EXTHRecord(501, "EBOK", encoding)); - meta.setEXTHRecords(); - - try - { - meta.saveToNewFile(new File(outDir, f.getName())); - } - catch (MobiMetaException e) - { - log("Error saving file: " + e.getMessage()); - } - - log(""); - } - } - - private void log(String message) - { - System.out.println(message); - } - - private String getInput(String message) - { - System.out.print(message); - String value = null; - try - { - value = in.readLine(); - } - catch (IOException e) - { - } - - return (value == null)?"":value; - } -} diff --git a/src/gui/CustomJTable.java b/src/gui/CustomJTable.java deleted file mode 100644 index c951ae3..0000000 --- a/src/gui/CustomJTable.java +++ /dev/null @@ -1,49 +0,0 @@ -package gui; - -import javax.swing.JTable; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableColumn; -import javax.swing.table.TableModel; - -public class CustomJTable extends JTable -{ - /** - * This code was adapted from - * http://www.javalobby.org/java/forums/t84905.html - * - * A traditional JTable lets you specify custom renderers and editors on a - * column by column basis. This class lets you have different renderers and - * editors in the same column (but different rows). - */ - private static final long serialVersionUID = 1L; - - public CustomJTable(TableModel model) - { - super(model); - } - - public TableCellRenderer getCellRenderer(int row, int column) - { - TableColumn tableColumn = getColumnModel().getColumn(column); - TableCellRenderer renderer = tableColumn.getCellRenderer(); - if (renderer != null) return renderer; - if (getValueAt(row, column) != null) - { - return getDefaultRenderer(getValueAt(row, column).getClass()); - } - return getDefaultRenderer(getColumnClass(column)); - } - - public TableCellEditor getCellEditor(int row, int column) - { - TableColumn tableColumn = getColumnModel().getColumn(column); - TableCellEditor editor = tableColumn.getCellEditor(); - if (editor != null) return editor; - if (getValueAt(row, column) != null) - { - return getDefaultEditor(getValueAt(row, column).getClass()); - } - return getDefaultEditor(getColumnClass(column)); - } -} diff --git a/src/gui/EXTHAddRecordListener.java b/src/gui/EXTHAddRecordListener.java deleted file mode 100644 index bfcdcf2..0000000 --- a/src/gui/EXTHAddRecordListener.java +++ /dev/null @@ -1,8 +0,0 @@ -package gui; - -import mobimeta.EXTHRecord; - -public interface EXTHAddRecordListener -{ - public void addEXTHRecord(EXTHRecord rec); -} diff --git a/src/gui/GenericFileFilter.java b/src/gui/GenericFileFilter.java deleted file mode 100644 index 35d291c..0000000 --- a/src/gui/GenericFileFilter.java +++ /dev/null @@ -1,37 +0,0 @@ -package gui; - -import java.io.File; -import java.io.FilenameFilter; - -import javax.swing.filechooser.FileFilter; - -class GenericFileFilter extends FileFilter implements FilenameFilter -{ - public String extension; - - public String getExtension() { - return extension; - } - - public GenericFileFilter(String extension) { - this.extension = extension.toLowerCase(); - } - - public String getDescription() - { - return extension; - } - - public boolean accept(File f, String name) - { - return (accept(f)); - } - - public boolean accept(File f) - { - if (f.isDirectory()) return true; - - return (f.getName().toLowerCase().endsWith(extension)); - } - -} diff --git a/src/gui/GuiException.java b/src/gui/GuiException.java deleted file mode 100644 index 4d8113d..0000000 --- a/src/gui/GuiException.java +++ /dev/null @@ -1,14 +0,0 @@ -package gui; - -public class GuiException extends Exception -{ - /** - * - */ - private static final long serialVersionUID = 1L; - - public GuiException(String message) - { - super(message); - } -} diff --git a/src/gui/GuiModel.java b/src/gui/GuiModel.java deleted file mode 100644 index e76083f..0000000 --- a/src/gui/GuiModel.java +++ /dev/null @@ -1,201 +0,0 @@ -package gui; - -import mobimeta.*; - -import java.io.File; -import java.util.List; - -import javax.swing.table.AbstractTableModel; - -class GuiModel extends AbstractTableModel implements EXTHAddRecordListener, LanguageModel, MetaInfoProvider -{ - /** - * This is essentially a proxy to the MobiMeta object. In addition, it - * serves as a TableModel for the JTable - */ - private static final long serialVersionUID = 1L; - - private MobiMeta model = null; - - // static globals for convenience - // - private static String fullName = null; - private static List exthRecords = null; - private static String characterEncoding = null; - - - public GuiModel() - { - } - - public void setModel(File f) throws GuiException - { - try - { - model = new MobiMeta(f); - } - catch (MobiMetaException e) - { - throw new GuiException(e.getMessage()); - } - - fullName = model.getFullName(); - exthRecords = model.getEXTHRecords(); - characterEncoding = model.getCharacterEncoding(); - } - - public String getColumnName(int col) - { - if (col == 0) - return "Record Type"; - else - return "Value"; - } - - public int getColumnCount() - { - return 2; - } - - public int getRowCount() - { - return (exthRecords == null)?0:exthRecords.size(); - } - - public Object getValueAt(int row, int col) - { - EXTHRecord rec = exthRecords.get(row); - int type = rec.getRecordType(); - String typeDesc = rec.getTypeDescription(); - - if (col == 0) - { - if (typeDesc == null) - return Integer.toString(type); - else - return type + " (" + typeDesc + ")"; - } - else - { - byte[] data = rec.getData(); - - if (typeDesc == null) - { - StringBuffer sb = new StringBuffer(); - sb.append("{ "); - int len = data.length; - for (int i=0; i 0) sb.append(", "); - sb.append(data[i] & 0xff); - } - sb.append(" }"); - return sb.toString(); - } - else if (EXTHRecord.isBooleanType(type)) - { - int value = StreamUtils.byteArrayToInt(data); - if (value == 0) - return Boolean.FALSE; - else - return Boolean.TRUE; - } - else - return StreamUtils.byteArrayToString(data, characterEncoding); - } - } - - public boolean isCellEditable(int row, int col) - { - if ((col == 0) || MobiCommon.safeMode) return false; - - return exthRecords.get(row).isKnownType(); - } - - public void setValueAt(Object value, int row, int column) - { - if (column != 1) return; - - if (value instanceof String) - exthRecords.get(row).setData((String)value, characterEncoding); - else if (value instanceof Boolean) - exthRecords.get(row).setData(((Boolean)value).booleanValue()); - else - return; - - fireTableCellUpdated(row, column); - } - - public String getFullName() - { - return fullName; - } - - public void setFullName(String s) - { - fullName = s; - } - - public void removeRecordAtRow(int row) - { - exthRecords.remove(row); - fireTableRowsDeleted(row, row); - } - - - public void addEXTHRecord(EXTHRecord rec) - { - exthRecords.add(rec); - int lastIndex = exthRecords.size() - 1; - fireTableRowsInserted(lastIndex, lastIndex); - } - - public static String getCharacterEncoding() - { - return characterEncoding; - } - - public void save(File outputFile, boolean packHeader) throws GuiException - { - if (packHeader) - { - model.setFullName(fullName); - model.setEXTHRecords(); - } - - try - { - model.saveToNewFile(outputFile, packHeader); - } - catch (MobiMetaException e) - { - throw new GuiException("Problems encountered while saving file: " - + e.getMessage()); - } - } - - public int getLocale() - { - return model.getLocale(); - } - - public int getDictInput() - { - return model.getDictInput(); - } - - public int getDictOutput() - { - return model.getDictOutput(); - } - - public void setLanguages(int locale, int dictInput, int dictOutput) - { - model.setLanguages(locale, dictInput, dictOutput); - } - - public String getMetaInfo() - { - return model.getMetaInfo(); - } -} diff --git a/src/gui/HeaderInfoDialog.java b/src/gui/HeaderInfoDialog.java deleted file mode 100644 index 80cf1ab..0000000 --- a/src/gui/HeaderInfoDialog.java +++ /dev/null @@ -1,73 +0,0 @@ -package gui; - -import java.awt.BorderLayout; -import java.awt.FlowLayout; - -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import javax.swing.JTextArea; -import javax.swing.JScrollPane; - -public class HeaderInfoDialog extends JDialog implements ActionListener -{ - - /** - * - */ - private static final long serialVersionUID = 1L; - private final JPanel contentPanel = new JPanel(); - private JButton closeButton; - private JScrollPane scrollPane; - private JTextArea textArea; - - /** - * Create the dialog. - */ - public HeaderInfoDialog(JFrame parent, MetaInfoProvider infoProvider) - { - super(parent, "Header Info", true); - setBounds(100, 100, 450, 300); - getContentPane().setLayout(new BorderLayout()); - contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); - getContentPane().add(contentPanel, BorderLayout.CENTER); - contentPanel.setLayout(new BorderLayout(0, 0)); - { - scrollPane = new JScrollPane(); - contentPanel.add(scrollPane, BorderLayout.CENTER); - { - textArea = new JTextArea(infoProvider.getMetaInfo()); - textArea.setEditable(false); - scrollPane.setViewportView(textArea); - } - } - { - JPanel buttonPane = new JPanel(); - buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); - getContentPane().add(buttonPane, BorderLayout.SOUTH); - { - closeButton = new JButton("Close"); - closeButton.addActionListener(this); - closeButton.setActionCommand("Cancel"); - buttonPane.add(closeButton); - } - } - } - - protected JButton getCloseButton() { - return closeButton; - } - - public void actionPerformed(ActionEvent e) - { - if (e.getSource() == closeButton) - { - setVisible(false); - dispose(); - } - } -} diff --git a/src/gui/LanguageCodes.java b/src/gui/LanguageCodes.java deleted file mode 100644 index 4e96dad..0000000 --- a/src/gui/LanguageCodes.java +++ /dev/null @@ -1,76 +0,0 @@ -package gui; - -import java.io.IOException; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Properties; -import java.util.Vector; - -public class LanguageCodes -{ - public final static String PROP_FILENAME = "languagecodes.properties"; - - private HashMap codeHash; - private HashMap descriptionHash; - private String[] descriptions; - - public LanguageCodes() - { - Properties props = new Properties(); - try - { - props.load(ClassLoader.getSystemClassLoader().getResourceAsStream(PROP_FILENAME)); - } - catch (IOException e) - { - // we really have to find a better way to handle this - } - - codeHash = new HashMap(); - descriptionHash = new HashMap(); - Vector vec = new Vector(); - Enumeration keys = props.keys(); - while (keys.hasMoreElements()) - { - String key = (String)keys.nextElement(); - String description = props.getProperty(key) + " (" + key + ")"; - - try - { - Integer code = Integer.valueOf(key); - codeHash.put(code, description); - descriptionHash.put(description, code); - vec.add(description); - } - catch (NumberFormatException e) - { - } - Collections.sort(vec); - descriptions = vec.toArray(new String[vec.size()]); - } - } - - public String[] getDescriptions() - { - return descriptions; - } - - public boolean codeExists(int code) - { - return (codeToDescription(code) != null); - } - - public int descriptionToCode(String description) - { - Integer code = descriptionHash.get(description); - if (code == null) return -1; - - return code.intValue(); - } - - public String codeToDescription(int code) - { - return codeHash.get (Integer.valueOf(code)); - } -} diff --git a/src/gui/LanguageDialog.java b/src/gui/LanguageDialog.java deleted file mode 100644 index 085def7..0000000 --- a/src/gui/LanguageDialog.java +++ /dev/null @@ -1,249 +0,0 @@ -package gui; - -import java.awt.BorderLayout; -import java.awt.FlowLayout; - -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; -import java.awt.GridBagLayout; -import java.awt.Component; -import javax.swing.Box; -import javax.swing.JLabel; -import java.awt.GridBagConstraints; -import java.awt.Font; -import javax.swing.SwingConstants; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JComboBox; - -public class LanguageDialog extends JDialog implements ActionListener -{ - /** - * - */ - private static final long serialVersionUID = 1L; - - private final JPanel contentPanel = new JPanel(); - - private JButton okButton; - private JButton cancelButton; - private JComboBox cbLanguage; - private JComboBox cbDictInput; - private JComboBox cbDictOutput; - - // store original values here - private int locale; - private int dictInput; - private int dictOutput; - - // these values indicate if they are known values - private boolean localeExists; - private boolean dictInputExists; - private boolean dictOutputExists; - - private LanguageModel model; - private LanguageCodes langCodes; - - /** - * Create the dialog. - */ - public LanguageDialog(JFrame parent, LanguageModel model) - { - super(parent, true); - this.model = model; - locale = model.getLocale(); - dictInput = model.getDictInput(); - dictOutput = model.getDictOutput(); - langCodes = new LanguageCodes(); - localeExists = langCodes.codeExists(locale); - dictInputExists = langCodes.codeExists(dictInput); - dictOutputExists = langCodes.codeExists(dictOutput); - - // assemble choices for combo boxes - // - String[] localeChoices = buildChoices(locale); - String[] dictInputChoices = buildChoices(dictInput); - String[] dictOutputChoices = buildChoices(dictOutput); - - - setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - setBounds(100, 100, 450, 300); - getContentPane().setLayout(new BorderLayout()); - contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); - getContentPane().add(contentPanel, BorderLayout.CENTER); - contentPanel.setLayout(new BorderLayout(0, 0)); - { - Component verticalStrut = Box.createVerticalStrut(20); - contentPanel.add(verticalStrut, BorderLayout.NORTH); - } - { - Component verticalStrut = Box.createVerticalStrut(20); - contentPanel.add(verticalStrut, BorderLayout.SOUTH); - } - { - Component horizontalStrut = Box.createHorizontalStrut(20); - contentPanel.add(horizontalStrut, BorderLayout.WEST); - } - { - Component horizontalStrut = Box.createHorizontalStrut(20); - contentPanel.add(horizontalStrut, BorderLayout.EAST); - } - { - JPanel panel = new JPanel(); - contentPanel.add(panel, BorderLayout.CENTER); - GridBagLayout gbl_panel = new GridBagLayout(); - gbl_panel.columnWidths = new int[] - { 0, 0, 0 }; - gbl_panel.rowHeights = new int[] - { 0, 0, 0, 0 }; - gbl_panel.columnWeights = new double[] - { 0.0, 1.0, Double.MIN_VALUE }; - gbl_panel.rowWeights = new double[] - { 0.0, 0.0, 0.0, Double.MIN_VALUE }; - panel.setLayout(gbl_panel); - { - JLabel lblLanguage = new JLabel("Language"); - lblLanguage.setHorizontalAlignment(SwingConstants.RIGHT); - lblLanguage.setFont(new Font("Lucida Grande", Font.BOLD, 13)); - GridBagConstraints gbc_lblLanguage = new GridBagConstraints(); - gbc_lblLanguage.anchor = GridBagConstraints.EAST; - gbc_lblLanguage.insets = new Insets(0, 0, 5, 5); - gbc_lblLanguage.gridx = 0; - gbc_lblLanguage.gridy = 0; - panel.add(lblLanguage, gbc_lblLanguage); - } - { - cbLanguage = new JComboBox(localeChoices); - if (localeExists) - cbLanguage.setSelectedItem(langCodes.codeToDescription(locale)); - else - cbLanguage.setSelectedIndex(localeChoices.length - 1); - - GridBagConstraints gbc_cbLanguage = new GridBagConstraints(); - gbc_cbLanguage.insets = new Insets(0, 0, 5, 0); - gbc_cbLanguage.fill = GridBagConstraints.HORIZONTAL; - gbc_cbLanguage.gridx = 1; - gbc_cbLanguage.gridy = 0; - panel.add(cbLanguage, gbc_cbLanguage); - } - { - JLabel lblDictionaryInput = new JLabel("Dictionary Input"); - lblDictionaryInput.setHorizontalAlignment(SwingConstants.RIGHT); - lblDictionaryInput.setFont(new Font("Lucida Grande", Font.BOLD, - 13)); - GridBagConstraints gbc_lblDictionaryInput = new GridBagConstraints(); - gbc_lblDictionaryInput.anchor = GridBagConstraints.EAST; - gbc_lblDictionaryInput.insets = new Insets(0, 0, 5, 5); - gbc_lblDictionaryInput.gridx = 0; - gbc_lblDictionaryInput.gridy = 1; - panel.add(lblDictionaryInput, gbc_lblDictionaryInput); - } - { - cbDictInput = new JComboBox(dictInputChoices); - if (dictInputExists) - cbDictInput.setSelectedItem(langCodes.codeToDescription(dictInput)); - else - cbDictInput.setSelectedIndex(dictInputChoices.length - 1); - - GridBagConstraints gbc_cbDictInput = new GridBagConstraints(); - gbc_cbDictInput.insets = new Insets(0, 0, 5, 0); - gbc_cbDictInput.fill = GridBagConstraints.HORIZONTAL; - gbc_cbDictInput.gridx = 1; - gbc_cbDictInput.gridy = 1; - panel.add(cbDictInput, gbc_cbDictInput); - } - { - JLabel lblDictionaryOutput = new JLabel("Dictionary Output"); - lblDictionaryOutput - .setHorizontalAlignment(SwingConstants.RIGHT); - lblDictionaryOutput.setFont(new Font("Lucida Grande", - Font.BOLD, 13)); - GridBagConstraints gbc_lblDictionaryOutput = new GridBagConstraints(); - gbc_lblDictionaryOutput.anchor = GridBagConstraints.EAST; - gbc_lblDictionaryOutput.insets = new Insets(0, 0, 0, 5); - gbc_lblDictionaryOutput.gridx = 0; - gbc_lblDictionaryOutput.gridy = 2; - panel.add(lblDictionaryOutput, gbc_lblDictionaryOutput); - } - { - cbDictOutput = new JComboBox(dictOutputChoices); - if (dictOutputExists) - cbDictOutput.setSelectedItem(langCodes.codeToDescription(dictOutput)); - else - cbDictOutput.setSelectedIndex(dictOutputChoices.length - 1); - - GridBagConstraints gbc_cbDictOutput = new GridBagConstraints(); - gbc_cbDictOutput.fill = GridBagConstraints.HORIZONTAL; - gbc_cbDictOutput.gridx = 1; - gbc_cbDictOutput.gridy = 2; - panel.add(cbDictOutput, gbc_cbDictOutput); - } - } - { - JPanel buttonPane = new JPanel(); - buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); - getContentPane().add(buttonPane, BorderLayout.SOUTH); - { - okButton = new JButton("OK"); - okButton.addActionListener(this); - buttonPane.add(okButton); - getRootPane().setDefaultButton(okButton); - } - { - cancelButton = new JButton("Cancel"); - cancelButton.addActionListener(this); - buttonPane.add(cancelButton); - } - } - } - - public void actionPerformed(ActionEvent event) - { - Object source = event.getSource(); - - if (source == okButton) - { - int mappedCode; - - mappedCode = langCodes.descriptionToCode((String)cbLanguage.getSelectedItem()); - if (mappedCode != -1) locale = mappedCode; - - mappedCode = langCodes.descriptionToCode((String)cbDictInput.getSelectedItem()); - if (mappedCode != -1) dictInput = mappedCode; - - mappedCode = langCodes.descriptionToCode((String)cbDictOutput.getSelectedItem()); - if (mappedCode != -1) dictOutput = mappedCode; - - model.setLanguages(locale, dictInput, dictOutput); - - setVisible(false); - dispose(); - } - else if (source == cancelButton) - { - setVisible(false); - dispose(); - } - } - - private String[] buildChoices(int code) - { - if (langCodes.codeExists(code)) - return langCodes.getDescriptions(); - else - { - String[] descriptions = langCodes.getDescriptions(); - String[] choices = new String[descriptions.length + 1]; - System.arraycopy(descriptions, 0, choices, 0, - descriptions.length); - choices[choices.length - 1] = "Unknown (" + code - + ")"; - return choices; - } - } -} diff --git a/src/gui/LanguageModel.java b/src/gui/LanguageModel.java deleted file mode 100644 index 94ca6de..0000000 --- a/src/gui/LanguageModel.java +++ /dev/null @@ -1,12 +0,0 @@ -package gui; - -public interface LanguageModel -{ - public int getLocale(); - - public int getDictInput(); - - public int getDictOutput(); - - public void setLanguages(int locale, int dictInput, int dictOutput); -} diff --git a/src/gui/Main.java b/src/gui/Main.java deleted file mode 100644 index 6810422..0000000 --- a/src/gui/Main.java +++ /dev/null @@ -1,708 +0,0 @@ -package gui; - -import java.io.*; -import java.util.HashSet; -import java.util.prefs.Preferences; -import java.awt.EventQueue; - -import javax.swing.JFrame; -import javax.swing.JOptionPane; - -import java.awt.GridBagLayout; -import javax.swing.JLabel; - -import java.awt.GridBagConstraints; -import java.awt.Insets; -import java.awt.Rectangle; - -import javax.swing.JSeparator; -import javax.swing.JPanel; -import java.awt.BorderLayout; -import java.awt.Component; -import javax.swing.Box; -import javax.swing.SwingConstants; -import java.awt.Font; -import javax.swing.JTextField; -import java.awt.Color; -import javax.swing.JScrollPane; -import java.awt.FlowLayout; -import javax.swing.JButton; -import javax.swing.JFileChooser; -import javax.swing.JTable; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import javax.swing.filechooser.FileFilter; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import javax.swing.JTextArea; - -import mobimeta.MobiCommon; -import javax.swing.JMenuBar; -import javax.swing.JMenu; -import javax.swing.JMenuItem; - -public class Main implements ListSelectionListener, ActionListener, - TableModelListener, LanguageModel -{ - private JFileChooser openFileChooser = null; - private JFileChooser saveFileChooser = null; - private Preferences prefs = null; - private JFrame frame; - private JTextArea lblInputFilename; - private JTextArea lblOutputFilename; - private JTextField tfFullName; - private JTable table; - private JButton buttonRemove; - private JButton buttonAdd; - private JButton buttonSave; - private JButton btnLanguage; - private JButton btnHeaderInfo; - private GuiModel model; - private File outputFile; - private boolean packHeader = false; - private JMenuItem mntmOpen; - private JMenuItem mntmSave; - - /** - * Launch the application. - */ - public static void main(String[] args) - { - System.setProperty("apple.laf.useScreenMenuBar", "true"); - System.setProperty("com.apple.mrj.application.apple.menu.about.name", - "Mobi Meta Editor"); - - HashSet optionsSet = new HashSet(); - File inputFile = null; - for (int i=0; i row) - { - select = true; - } - else if (numRows > 0) - { - select = true; - row = numRows - 1; - } - if (select) - { - table.getSelectionModel().setSelectionInterval(row, row); - table.scrollRectToVisible(new Rectangle(table.getCellRect(row, - 0, true))); - } - packHeader = true; - setWindowChangedStatus(true); - } - else if (eventType == TableModelEvent.UPDATE) - { - packHeader = true; - setWindowChangedStatus(true); - } - } - - protected void setWindowChangedStatus(boolean status) - { - frame.getRootPane().putClientProperty("Window.documentModified", - Boolean.valueOf(status)); - - // Make sure the table component is updated - table.repaint(); - table.revalidate(); - } - - // we implement the LanguageModel interface because we want to intercept the - // setLanguages() call so that we can set the window status changed flag - // - public int getLocale() - { - return model.getLocale(); - } - - // we implement the LanguageModel interface because we want to intercept the - // setLanguages() call so that we can set the window status changed flag - // - public int getDictInput() - { - return model.getDictInput(); - } - - // we implement the LanguageModel interface because we want to intercept the - // setLanguages() call so that we can set the window status changed flag - // - public int getDictOutput() - { - return model.getDictOutput(); - } - - // we implement the LanguageModel interface because we want to intercept the - // setLanguages() call so that we can set the window status changed flag - // - public void setLanguages(int locale, int dictInput, int dictOutput) - { - model.setLanguages(locale, dictInput, dictOutput); - setWindowChangedStatus(true); - } - protected JMenuItem getMntmOpen() { - return mntmOpen; - } - protected JMenuItem getMntmSave() { - return mntmSave; - } -} diff --git a/src/gui/MetaInfoProvider.java b/src/gui/MetaInfoProvider.java deleted file mode 100644 index da0c8e0..0000000 --- a/src/gui/MetaInfoProvider.java +++ /dev/null @@ -1,6 +0,0 @@ -package gui; - -public interface MetaInfoProvider -{ - public String getMetaInfo(); -} diff --git a/src/gui/NewRecordDialog.java b/src/gui/NewRecordDialog.java deleted file mode 100644 index 00e027d..0000000 --- a/src/gui/NewRecordDialog.java +++ /dev/null @@ -1,175 +0,0 @@ -package gui; - -import java.awt.BorderLayout; -import java.awt.FlowLayout; - -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; -import javax.swing.JLabel; -import java.awt.GridBagLayout; -import java.awt.GridBagConstraints; -import javax.swing.JComboBox; -import java.awt.Insets; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JTextField; - -import mobimeta.EXTHRecord; - -public class NewRecordDialog extends JDialog implements ActionListener -{ - - /** - * - */ - private static final long serialVersionUID = 1L; - private final JPanel contentPanel = new JPanel(); - private JTextField tfValue; - private JComboBox typeCombo; - private EXTHAddRecordListener listener; - private JButton addButton; - private JButton cancelButton; - - - /** - * Create the dialog. - */ - public NewRecordDialog(JFrame parent, EXTHAddRecordListener listener) - { - super(parent, true); - - this.listener = listener; - String[] comboValues = new String[EXTHRecord.knownTypes.length]; - for (int i=0; i