Package gps.garmin.gui

Source Code of gps.garmin.gui.IMGViewer

/*
* IMGViewer.java
*
* Created on 21 de junio de 2007, 15:50
*/

package gps.garmin.gui;

import gps.garmin.img.FileParser;
import gps.garmin.img.ParseException;
import gps.garmin.img.Parser;
import gps.garmin.img.structure.Header;
import gps.garmin.img.structure.IMG;
import gps.garmin.img.structure.data.Subdivision;
import gps.garmin.img.structure.data.Subfile;
import gps.garmin.img.structure.data.SubfileTRE;
import java.io.File;
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

/**
*
* @author  aranzuglia
*/
public class IMGViewer extends javax.swing.JFrame {
   
    private DefaultTreeModel treeModel;
    private DefaultMutableTreeNode rootNode;
   
    /** Creates new form IMGViewer */
    public IMGViewer() {
        initComponents();
       
        rootNode = new DefaultMutableTreeNode("First subdivision");
        treeModel = new DefaultTreeModel(rootNode);
        subdivisions.setModel(treeModel);
    }
   
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jFileChooser1 = new javax.swing.JFileChooser();
        jLabel1 = new javax.swing.JLabel();
        imgPath = new javax.swing.JTextField();
        imgButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        imgName = new javax.swing.JTextField();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        xored = new javax.swing.JCheckBox();
        jLabel3 = new javax.swing.JLabel();
        xorByte = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jscrollPane1 = new javax.swing.JScrollPane();
        subdivisions = new javax.swing.JTree();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("IMG Viewer");
        jLabel1.setText("Select IMG file");

        imgButton.setText("Parse");
        imgButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                imgButtonActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("IMG's contents"));
        jLabel2.setText("IMG name");

        imgName.setEditable(false);

        xored.setText("XOR'ed?");
        xored.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        xored.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        xored.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jLabel3.setText("XOR byte");

        xorByte.setEditable(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(xored)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(xorByte, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(184, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(xored)
                    .addComponent(jLabel3)
                    .addComponent(xorByte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(241, Short.MAX_VALUE))
        );
        jTabbedPane1.addTab("Header", jPanel2);

        subdivisions.setShowsRootHandles(true);
        jscrollPane1.setViewportView(subdivisions);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jscrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jscrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE)
                .addContainerGap())
        );
        jTabbedPane1.addTab("Subdivisions", jPanel3);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(imgName, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(imgName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(imgPath, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(imgButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(imgButton)
                    .addComponent(imgPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void imgButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imgButtonActionPerformed
        try {
            Parser parser = new FileParser(new File(imgPath.getText()));
            parser.parse();
            IMG img = parser.getIMG();
           
            imgName.setText(img.getName());
           
            Header header = img.getImgHeader();
           
            xored.setSelected(header.isXorEd());
            xorByte.setText("0x" + Integer.toHexString(header.getXorByte()));
           
            for (Subfile subfile : img.getSubfiles()) {
                switch (subfile.getCommonHeader().getType()) {
                    case TRE:
                        SubfileTRE treSubfile = (SubfileTRE) subfile;

                        addSubdivision(rootNode, treSubfile.getFirstSubdivision());
                       
                        //showSubdivision();
                        break;
                }
            }
        } catch (ParseException ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_imgButtonActionPerformed

    private void addSubdivision(DefaultMutableTreeNode parent, Subdivision subdivision) {
        parent.add(new DefaultMutableTreeNode("Number: " + subdivision.getNumber()));
        parent.add(new DefaultMutableTreeNode("Level: " + subdivision.getLevel().getNumber()));
       
        if (!subdivision.isTerminatingFlag()) {
            DefaultMutableTreeNode contiguousNode =
                new DefaultMutableTreeNode("Contiguos subdivision");
           
            parent.add(contiguousNode);
           
            addSubdivision(contiguousNode, subdivision.getContiguousSubdivision());
        } else {
            DefaultMutableTreeNode nextLevelNode =
                new DefaultMutableTreeNode("Next Level");
           
            parent.add(nextLevelNode);
           
            addSubdivision(nextLevelNode, subdivision.getNextLevelSubdivision());
        }
    }
   
    /*private static void showSubdivision(Subdivision subdivision) {
        System.out.println("              Subdivision " + subdivision.getNumber() + " level " + subdivision.getLevel().getNumber());
        System.out.println("              RGN offset " + subdivision.getOffsetInRGNSubfile());
        for (ObjectType type : subdivision.getObjectTypes()) {
            System.out.println("                " + type);
        }
        System.out.println("              Longitude center " + subdivision.getLongitudeCenter());
        System.out.println("              Latitude center " + subdivision.getLatitudeCenter());
        System.out.println("              Width " + subdivision.getWidth());
        System.out.println("              Height " + subdivision.getHeight());
        System.out.println("              Terminating " + subdivision.isTerminatingFlag());
        System.out.println("              Total width " + subdivision.getTotalWidth());
        System.out.println("              Total height " + subdivision.getTotalHeight());
       
        if (subdivision.getContiguousSubdivision() != null) {
            System.out.println("--> Contiguous:");
            showSubdivision(subdivision.getContiguousSubdivision());
        }
       
        if (subdivision.getNextLevelSubdivision() != null) {
            System.out.println("--> Next level:");
            showSubdivision(subdivision.getNextLevelSubdivision());
        }
    }*/

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new IMGViewer().setVisible(true);
            }
        });
    }
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton imgButton;
    private javax.swing.JTextField imgName;
    private javax.swing.JTextField imgPath;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JScrollPane jscrollPane1;
    private javax.swing.JTree subdivisions;
    private javax.swing.JTextField xorByte;
    private javax.swing.JCheckBox xored;
    // End of variables declaration//GEN-END:variables
   
}
TOP

Related Classes of gps.garmin.gui.IMGViewer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.