    001    package calhoun.analysis.crf.executables.viewer;
    002
    003    import java.awt.event.WindowAdapter;
    004    import java.awt.event.WindowEvent;
    005    import java.io.IOException;
    006    import java.util.List;
    007
    008    import javax.swing.JFrame;
    009    import javax.swing.JScrollPane;
    010    import javax.swing.JTable;
    011
    012    import calhoun.analysis.crf.Conrad;
    013    import calhoun.analysis.crf.io.TrainingSequence;
    014
    015    public class ViterbiViewerApp extends JFrame {
    016            private static final long serialVersionUID = -5564046976928448201L;
    017            private static final int WINDOW_WIDTH = 800;
    018            private static final int WINDOW_HEIGHT = 600;
    019            ViterbiViewer recordViewer;
    020
    021            public ViterbiViewerApp(String model, String data) throws IOException {
    022                    super("Viterbi Path Viewer");
    023                    addWindowListener(new WindowAdapter() {
    024                            @Override
    025                            public void windowClosing(WindowEvent e) {
    026                                    System.exit(0);
    027                            }
    028                    });
    029
    030                    Conrad r = Conrad.read(model);
    031                    List<? extends TrainingSequence<?>> trainingData = r.getInputHandler().readTrainingData(data);
    032
    033                    recordViewer = new ViterbiViewer(r, trainingData.get(0));
    034                    JScrollPane scrollPane = new JScrollPane(recordViewer);
    035                    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    036                    setContentPane(scrollPane);
    037                    //initializeMenuBar();
    038                    setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    039            }
    040
    041            public static void main(String[] args) throws Exception {
    042                    String model = "";
    043                    String data = "";
    044                    if(args.length == 2){
    045                            model = args[0];
    046                            data = args[1];
    047                    }
    048                    final ViterbiViewerApp app = new ViterbiViewerApp(model, data);
    049                    app.pack();
    050                    app.setVisible(true);
    051            }
    052
    053            static class ViterbiViewer extends JTable {
    054                    private static final long serialVersionUID = 7592581578644968579L;
    055                    ViterbiTableModel model;
    056
    057                    public ViterbiViewer(Conrad crfModel, TrainingSequence seq) throws IOException {
    058                            model = new ViterbiTableModel(crfModel, seq);
    059                    setModel(model);
    060                    setDefaultRenderer(String.class, model.new ViterbiCellRenderer());
    061                    //setShowGrid(true);
    062                    //setAutoCreateColumnsFromModel(true);
    063                    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    064                    }
    065            }
    066    }