Search in sources :

Example 1 with MemoryContents

use of jmri.jmrit.MemoryContents in project JMRI by JMRI.

the class AbstractLoaderPane method initComponents.

@Override
public void initComponents() throws Exception {
    super.initComponents();
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    {
        /* Create panels for displaying a filename and for providing a file 
             * seleciton pushbutton
             */
        inputFileNamePanel = new JPanel();
        inputFileNamePanel.setLayout(new FlowLayout());
        JLabel l = new JLabel(Bundle.getMessage("LabelInpFile"));
        inputFileLabelWidth = l.getMinimumSize().width;
        l.setAlignmentX(java.awt.Component.CENTER_ALIGNMENT);
        inputFileNamePanel.add(l);
        inputFileNamePanel.add(new Box.Filler(new java.awt.Dimension(5, 20), new java.awt.Dimension(5, 20), new java.awt.Dimension(5, 20)));
        inputFileNamePanel.add(inputFileName);
        add(inputFileNamePanel);
        JPanel p = new JPanel();
        p.setLayout(new FlowLayout());
        JButton selectButton = new JButton(Bundle.getMessage("ButtonSelect"));
        selectButton.addActionListener((ActionEvent e) -> {
            inputContent = new MemoryContents();
            setDefaultFieldValues();
            updateDownloadVerifyButtons();
            selectInputFile();
            doRead(chooser);
        });
        p.add(selectButton);
        add(p);
    }
    {
        // Create a panel for displaying the addressing type, via radio buttons
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        JLabel l = new JLabel(Bundle.getMessage("LabelBitMode") + " ");
        l.setEnabled(false);
        p.add(l);
        p.add(address16bit);
        p.add(address24bit);
        addressSizeButtonGroup.add(address16bit);
        addressSizeButtonGroup.add(address24bit);
        addressSizeButtonGroup.clearSelection();
        address16bit.setEnabled(false);
        address24bit.setEnabled(false);
        add(p);
    }
    setDefaultFieldValues();
    add(new JSeparator());
    addOptionsPanel();
    {
        // create a panel for the upload, verify, and abort buttons
        JPanel p = new JPanel();
        p.setLayout(new FlowLayout());
        loadButton = new JButton(Bundle.getMessage("ButtonLoad"));
        loadButton.setEnabled(false);
        loadButton.setToolTipText(Bundle.getMessage("TipLoadDisabled"));
        p.add(loadButton);
        loadButton.addActionListener((java.awt.event.ActionEvent e) -> {
            doLoad();
        });
        verifyButton = new JButton(Bundle.getMessage("ButtonVerify"));
        verifyButton.setEnabled(false);
        verifyButton.setToolTipText(Bundle.getMessage("TipVerifyDisabled"));
        p.add(verifyButton);
        verifyButton.addActionListener((java.awt.event.ActionEvent e) -> {
            doVerify();
        });
        add(p);
        abortButton = new JButton(Bundle.getMessage("ButtonAbort"));
        abortButton.setEnabled(false);
        abortButton.setToolTipText(Bundle.getMessage("TipAbortDisabled"));
        p.add(abortButton);
        abortButton.addActionListener((java.awt.event.ActionEvent e) -> {
            setOperationAborted(true);
        });
        add(p);
        add(new JSeparator());
        // create progress bar
        bar = new JProgressBar(0, 100);
        bar.setStringPainted(true);
        add(bar);
        add(new JSeparator());
        {
            // create a panel for displaying a status message
            p = new JPanel();
            p.setLayout(new FlowLayout());
            status.setText(Bundle.getMessage("StatusSelectFile"));
            status.setAlignmentX(JLabel.LEFT_ALIGNMENT);
            p.add(status);
            add(p);
        }
    }
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JProgressBar(javax.swing.JProgressBar) JLabel(javax.swing.JLabel) ActionEvent(java.awt.event.ActionEvent) JSeparator(javax.swing.JSeparator) MemoryContents(jmri.jmrit.MemoryContents)

Example 2 with MemoryContents

use of jmri.jmrit.MemoryContents in project JMRI by JMRI.

the class AbstractLoaderPane method doRead.

/**
     * Read file into local memory.
     *
     * @param chooser chooser to select the file to read from
     */
protected void doRead(JFileChooser chooser) {
    if (inputFileName.getText().equals("")) {
        JOptionPane.showMessageDialog(this, Bundle.getMessage("ErrorNoInputFile"), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    // force load, verify disabled in case read fails
    loadButton.setEnabled(false);
    loadButton.setToolTipText(Bundle.getMessage("TipLoadDisabled"));
    verifyButton.setEnabled(false);
    verifyButton.setToolTipText(Bundle.getMessage("TipVerifyDisabled"));
    abortButton.setEnabled(false);
    abortButton.setToolTipText(Bundle.getMessage("TipAbortDisabled"));
    // clear the existing memory contents
    inputContent = new MemoryContents();
    bar.setValue(0);
    // load
    try {
        inputContent.readHex(new File(chooser.getSelectedFile().getPath()));
    } catch (FileNotFoundException f) {
        log.error(f.getLocalizedMessage());
        JOptionPane.showMessageDialog(this, Bundle.getMessage("ErrorFileNotFound"), Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE);
        status.setText(Bundle.getMessage("StatusFileNotFound"));
        this.disableDownloadVerifyButtons();
        return;
    } catch (MemoryContents.MemoryFileRecordLengthException | MemoryContents.MemoryFileChecksumException | MemoryContents.MemoryFileUnknownRecordType | MemoryContents.MemoryFileRecordContentException | MemoryContents.MemoryFileAddressingRangeException | MemoryContents.MemoryFileNoDataRecordsException | MemoryContents.MemoryFileNoEOFRecordException | MemoryContents.MemoryFileRecordFoundAfterEOFRecord f) {
        log.error(f.getLocalizedMessage());
        status.setText(Bundle.getMessage("ErrorFileContentsError"));
        this.disableDownloadVerifyButtons();
        return;
    } catch (IOException e) {
        log.error(e.getLocalizedMessage());
        status.setText(Bundle.getMessage("ErrorFileReadError"));
        this.disableDownloadVerifyButtons();
        return;
    }
    log.debug("Read complete: {}", inputContent.toString());
    loadButton.setEnabled(true);
    loadButton.setToolTipText(Bundle.getMessage("TipLoadEnabled"));
    verifyButton.setEnabled(true);
    verifyButton.setToolTipText(Bundle.getMessage("TipVerifyEnabled"));
    status.setText(Bundle.getMessage("StatusDoDownload"));
    handleOptionsInFileContent(inputContent);
    MemoryContents.LoadOffsetFieldType addresstype = inputContent.getCurrentAddressFormat();
    if (addresstype == MemoryContents.LoadOffsetFieldType.ADDRESSFIELDSIZE16BITS) {
        address16bit.setSelected(true);
        address24bit.setSelected(false);
    } else if (addresstype == MemoryContents.LoadOffsetFieldType.ADDRESSFIELDSIZE24BITS) {
        address16bit.setSelected(false);
        address24bit.setSelected(true);
    }
    if (!parametersAreValid()) {
        status.setText(Bundle.getMessage("ErrorInvalidParameter"));
        disableDownloadVerifyButtons();
    } else if (!inputContent.isEmpty()) {
        enableDownloadVerifyButtons();
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) MemoryContents(jmri.jmrit.MemoryContents) File(java.io.File)

Aggregations

MemoryContents (jmri.jmrit.MemoryContents)2 FlowLayout (java.awt.FlowLayout)1 ActionEvent (java.awt.event.ActionEvent)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 BoxLayout (javax.swing.BoxLayout)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JProgressBar (javax.swing.JProgressBar)1 JSeparator (javax.swing.JSeparator)1