Package jexifviewer

Source Code of jexifviewer.JExifDataComparator

/*
*  JExifDataModel.java
*
*  Created on 10. April 2006, 23:30
*
*  Copyright (C) 10. April 2006  <Reiner>

*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/


package jexifviewer;

import javax.swing.table.AbstractTableModel;

import javax.swing.ImageIcon;
import javax.swing.Icon;
import java.net.URL;

import java.text.DateFormat;
import java.text.FieldPosition;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import shared.cvshelper.Cvs;
import shared.table.JTableColSortData;

/**
*
* @author reiner
*/


@Cvs
(
    header = "$Header: /home/reiner/cvs/Java/JExifViewer/src/jexifviewer/JExifDataModel.java,v 1.9 2010/04/02 12:12:13 reiner Exp $"
)
public final class JExifDataModel extends AbstractTableModel
{
    private ResourceBundle m_resBundle;
    private ArrayList<JIfdData> m_data;
    public JTableColSortData[] m_sortData;
    public static final int[] m_colTag =
    {
        JExifTag.EXIFTAG_TAG_NAME, JExifTag.EXIFTAG_TAG_SIZE,
        JExifTag.EXIFTAG_TAG_MAKE, JExifTag.EXIFTAG_TAG_MODEL, JExifTag.EXIFTAG_TAG_ORIENTATION,
        JExifTag.EXIFTAG_TAG_RESOLUTION,
        JExifTag.EXIFTAG_TAG_SOFTWARE, JExifTag.EXIFTAG_TAG_CHANGEDATETIME, JExifTag.EXIFTAG_TAG_ARTIST, JExifTag.EXIFTAG_TAG_YCBCRPOSITION,
        JExifTag.EXIFTAG_TAG_COPYRIGHT, JExifTag.EXIFTAG_TAG_EXPOSURETIME, JExifTag.EXIFTAG_TAG_FNUMBER,
        JExifTag.EXIFTAG_TAG_EXPOSUREPROGRAM, JExifTag.EXIFTAG_TAG_ISOSPEEDRATINGS, JExifTag.EXIFTAG_TAG_EXIFVERSION,
        JExifTag.EXIFTAG_TAG_ORIGINALDATETIME, JExifTag.EXIFTAG_TAG_DIGITIZEDDATETIME, JExifTag.EXIFTAG_TAG_COMPONENTSCCONFIG,
        JExifTag.EXIFTAG_TAG_COMPRESSEDPITSPERPIXEL, JExifTag.EXIFTAG_TAG_SHUTERSPEEDVALUE, JExifTag.EXIFTAG_TAG_APERTUREVALUE,
        JExifTag.EXIFTAG_TAG_BRIGHTNESSVALUE, JExifTag.EXIFTAG_TAG_EXPOSUREBIASVALUE, JExifTag.EXIFTAG_TAG_MAXAPERTUREVALUE,
        JExifTag.EXIFTAG_TAG_METERINGMODE, JExifTag.EXIFTAG_TAG_LIGHTSOURCE, JExifTag.EXIFTAG_TAG_FLASH,
        JExifTag.EXIFTAG_TAG_FOCALLENGTH, JExifTag.EXIFTAG_TAG_COLORSPACE,
        JExifTag.EXIFTAG_TAG_FOCALPLANERESOLUTION,
        JExifTag.EXIFTAG_TAG_SENSINGMODE, JExifTag.EXIFTAG_TAG_CUSTOMRENDERED,
        JExifTag.EXIFTAG_TAG_EXPOSUREMODE, JExifTag.EXIFTAG_TAG_WHITEBALANCE, JExifTag.EXIFTAG_TAG_DIGITALZOOMRATIO,
        JExifTag.EXIFTAG_TAG_FOCALLENGTH35MM, JExifTag.EXIFTAG_TAG_SCENECAPTURETYPE, JExifTag.EXIFTAG_TAG_GAINCONTROL,
        JExifTag.EXIFTAG_TAG_CONTRAST, JExifTag.EXIFTAG_TAG_SATURATION, JExifTag.EXIFTAG_TAG_SHARPNESS,
        JExifTag.EXIFTAG_TAG_SUBJECTDISTANCERANGE,
        JExifTag.EXIFTAG_TAG_FILESIZE, JExifTag.EXIFTAG_TAG_FILEDATETIME,
        JExifTag.EXIFTAG_TAG_DESCRIPTION, JExifTag.EXIFTAG_TAG_SCENETYPE, JExifTag.EXIFTAG_TAG_FILESOURCE,
        JExifTag.GPSTAG_TAG_VERSIONID,
        JExifTag.GPSTAG_TAG_LATITUDE, JExifTag.GPSTAG_TAG_LONGITUDE, JExifTag.GPSTAG_TAG_ALTITUDE,
        JExifTag.GPSTAG_TAG_MAPLINK
        // JExifTag.GPSTAG_TAG_TIMESTAMP, JExifTag.GPSTAG_TAG_SATELLITES, JExifTag.GPSTAG_TAG_STATUS, JExifTag.GPSTAG_TAG_MEASUREMODE,
    };
   
    public JExifDataModel(ResourceBundle resBundle, JTableColSortData[] sortData)
    {
        m_data = new ArrayList<JIfdData>();
        m_resBundle = resBundle;
        m_sortData = sortData;
    }
   
    public int getSortCol()
    {
      return m_sortData[0].getSortCol();
    }

    public boolean getSortUp()
    {
        return m_sortData[0].getSortUp();
    }
   
    private void shiftSortArray()
    {
        for (int i=m_sortData.length-1; i >  0; i--)
        {
            m_sortData[i].setData(m_sortData[i-1]);
        }
    }
   
    public void setSortCol(int col)
    {
        shiftSortArray();
        m_sortData[0].setSortCol(col);
    }

    public void setSortUp(boolean bUp)
    {
        // shiftSortArray();
        m_sortData[0].setSortUp(bUp);
    }

    public Icon getColIcon(int col)
    {
        ImageIcon icon = null;
        String str = getColIconStr(col);
//        if (str != null && !str.isEmpty())
        if (str != null && str.length() > 0)
            icon = new ImageIcon(str);
        return icon;
    }

    public String getColIconStr(int col)
    {
        String str = null;
        if (col == m_sortData[0].getSortCol())
        {
            URL imgURL = JMainFrame.class.getResource(m_sortData[0].getSortUp() ? "down.gif" : "up.gif");
            str = imgURL.toExternalForm();
        }
        return str;
    }

    public void addData(JIfdData data)
    {
        m_data.add(data);
        fireTableRowsInserted(m_data.size() - 1, m_data.size() - 1);
    }

    public void addData(ArrayList<JIfdData> arrayList)
    {
        m_data.addAll(arrayList);
        fireTableRowsInserted(m_data.size() - arrayList.size(), m_data.size() - 1);
    }
   
    public void removeAll()
    {
        int rows = m_data.size();
        m_data.clear();
        fireTableRowsDeleted(0, rows);
    }

    public void removeRow(int row)
    {
      if (row >= 0 && row < m_data.size())
        {
            m_data.remove(row);
            fireTableRowsDeleted(row, row);
        }
    }

    public int getRowCount()
    {
      return m_data.size();
    }
       
    public int getColumnCount()
    {
        return m_colTag.length;
    }
   
    public JIfdData getRowData(int row)
    {
      return m_data.get(row);
    }

    public int findRow(JIfdData data)
    {
        int row = 0, i=0;
        for (JIfdData item : m_data)
        {
            if (data == item)
            return i;
            i++;
        }
        return row;
    }
   
    public int findRow(String path)
    {
        int row = -1, i=0;
        for (JIfdData item : m_data)
        {
            if (item.getFilePath().equals(path))
            return i;
            i++;
        }
        return row;
    }

    public static Object getTagValue(JIfdData data, int tag)
    {
        Object obj = null;
        String str[] = new String[1];
        int h;
        Date date;
        StringBuffer strBuf;
        try
        {
            switch (tag)
            {
                case JExifTag.EXIFTAG_TAG_NAME:
                    obj = data.getFileName();
                    break;
                case JExifTag.EXIFTAG_TAG_MAKE:
                    obj = data.getMake();
                    break;
                case JExifTag.EXIFTAG_TAG_MODEL:
                    obj = data.getModel();
                    break;
                case JExifTag.EXIFTAG_TAG_ORIENTATION:
                    obj = Main.getString(String.format("data_orientation_0x%1$04X", data.getOrientation()));
                    break;
                case JExifTag.EXIFTAG_TAG_RESOLUTION:
                    obj = String.format("%1$.1f/%3$s x %2$.1f/%3$s", data.getXResolution(), data.getYResolution(), Main.getString(String.format("data_unit_0x%1$04X", data.getResolutionUnit())));
                    break;
                    /*
                case JExifTag.EXIFTAG_TAG_CANON_SERIAL:
                    obj = data.getCanonCameraSerial();
                    break;
                     */
                case JExifTag.EXIFTAG_TAG_SOFTWARE:
                    obj = data.getSoftware();
                    break;
                case JExifTag.EXIFTAG_TAG_CHANGEDATETIME:
                    if ((date = JIfdData.getDateFromString(data.getChangeDateTime())) != null)
                    {
                        strBuf = new StringBuffer();
                        Main.m_shortDayOfWeekFormat.format(date, strBuf, new FieldPosition(0));
                        obj = strBuf + ", " + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date);
                    }
                    else obj = "";
                    break;
                case JExifTag.EXIFTAG_TAG_ARTIST:
                    obj = data.getArtist();
                    break;
                case JExifTag.EXIFTAG_TAG_DESCRIPTION:
                    obj = data.getDescription();
                    break;
                case JExifTag.EXIFTAG_TAG_YCBCRPOSITION:
                    obj = Main.getString(String.format("data_ycbcrposition_0x%1$04X", data.getYCbCrPosition()));
                    break;
                case JExifTag.EXIFTAG_TAG_COPYRIGHT:
                    obj = data.getCopyright();
                    break;
                case JExifTag.EXIFTAG_TAG_EXPOSURETIME:
                    data.getExposureTime(str);
                    obj = str[0];
                    break;
                case JExifTag.EXIFTAG_TAG_FNUMBER:
                    data.getFNumber(str);
                    obj = str[0];
                    break;
                case JExifTag.EXIFTAG_TAG_EXPOSUREPROGRAM:
                    try
                    {
                        obj = Main.getString(String.format("data_exposureprogram_0x%1$04X", data.getExposureProgram()));
                    }
                    catch(MissingResourceException ex)
                    {
                        obj = Main.getString("data_exposureprogram_reserved");
                    }
                    break;
                case JExifTag.EXIFTAG_TAG_ISOSPEEDRATINGS:
                    obj = data.getISOSpeedRatings();
                    break;
                case JExifTag.EXIFTAG_TAG_EXIFVERSION:
                    obj = data.getExifVersion();
                    break;
                case JExifTag.EXIFTAG_TAG_ORIGINALDATETIME:
                    if ((date = JIfdData.getDateFromString(data.getOriginalDateTime())) != null)
                    {
                        strBuf = new StringBuffer();
                        Main.m_shortDayOfWeekFormat.format(date, strBuf, new FieldPosition(0));
                        obj = strBuf + ", " + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date);
                    }
                    else obj = "";
                    break;
                case JExifTag.EXIFTAG_TAG_DIGITIZEDDATETIME:
                    if ((date = JIfdData.getDateFromString(data.getDigitizedDateTime())) != null)
                    {
                        strBuf = new StringBuffer();
                        Main.m_shortDayOfWeekFormat.format(date, strBuf, new FieldPosition(0));
                        obj = strBuf + ", " + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date);
                    }
                    else obj = "";
                    break;
                case JExifTag.EXIFTAG_TAG_COMPONENTSCCONFIG:
                    obj = data.getComponentsConfig();
                    break;
                case JExifTag.EXIFTAG_TAG_COMPRESSEDPITSPERPIXEL:
                    obj = data.getCompressedBitsPerPixel();
                    break;
                case JExifTag.EXIFTAG_TAG_SHUTERSPEEDVALUE:
                    obj = data.getShuterSpeedValue();
                    break;
                case JExifTag.EXIFTAG_TAG_APERTUREVALUE:
                    obj = data.getApertureValue();
                    break;
                case JExifTag.EXIFTAG_TAG_BRIGHTNESSVALUE:
                    obj = data.getBrightnessValue();
                    break;
                case JExifTag.EXIFTAG_TAG_EXPOSUREBIASVALUE:
                    obj = data.getExposureBiasValue();
                    break;
                case JExifTag.EXIFTAG_TAG_MAXAPERTUREVALUE:
                    obj = data.getMaxApertureValue();
                    break;
                case JExifTag.EXIFTAG_TAG_METERINGMODE:
                    try
                    {
                        obj = Main.getString(String.format("data_meteringmode_0x%1$04X", data.getMeteringMode()));
                    }
                    catch(MissingResourceException ex)
                    {
                        obj = Main.getString("data_meteringmode_reserved");
                    }
                    break;
                case JExifTag.EXIFTAG_TAG_LIGHTSOURCE:
                    try
                    {
                        obj = Main.getString(String.format("data_lightsource_0x%1$04X", data.getLightSource()));
                    }
                    catch(MissingResourceException ex)
                    {
                        obj = Main.getString("data_lightsource_reserved");
                    }

                    break;
                case JExifTag.EXIFTAG_TAG_FLASH:
                    h = data.getFlash();
                    if ((h & 0x01) != 0)
                    {
                        str[0] = Main.getString(String.format("data_flash_yes"));
                        if (((h & 0x06) >> 1) == 0x02)
                            str[0] += ", " + Main.getString("data_flash_strobereturnnotdetected");
                        else if (((h & 0x06) >> 1) == 0x03)
                            str[0] += ", " + Main.getString("data_flash_strobereturndetected");

                        if (((h & 0x18) >> 3) == 0)
                            str[0] += ", " + Main.getString("data_flash_modeunknown");
                        else if (((h & 0x18) >> 3) == 0x01)
                            str[0] += ", " + Main.getString("data_flash_modecompulsory");
                        else if (((h & 0x18) >> 3) == 0x03)
                            str[0] += ", " + Main.getString("data_flash_modeauto");

                        if ((h & 0x40) != 0)
                            str[0] += ", " + Main.getString("data_flash_moderedeyereduction");
                    }
                    else
                    {
                        if ((h & 0x20) != 0)
                        {
                            str[0] = Main.getString(String.format("data_flash_notavailable"));
                        }
                        else
                        {
                            str[0] = Main.getString(String.format("data_flash_no"));
                            if (((h & 0x18) >> 3) == 0x01)
                            str[0] += ", " + Main.getString("data_flash_modecompulsorysuppression");
                        }
                    }
                    obj = str[0];
                    break;
                case JExifTag.EXIFTAG_TAG_FOCALLENGTH:
                    obj = data.getFocalLength();
                    break;
                case JExifTag.EXIFTAG_TAG_COLORSPACE:
                    obj = Main.getString(String.format("data_colorspace_0x%1$04X", data.getColorSpace()));
                    break;
                case JExifTag.EXIFTAG_TAG_SIZE:
                    obj = String.format("%1$dx%2$d", data.getPixelXDimension(), data.getPixelYDimension());
                    break;
                case JExifTag.EXIFTAG_TAG_FOCALPLANERESOLUTION:
                    obj = String.format("%1$.1f/%3$s x %2$.1f/%3$s", data.getFocalPlaneXResolution(), data.getFocalPlaneYResolution(), Main.getString(String.format("data_unit_0x%1$04X", data.getFocalPlaneResolutionUnit())));
                    break;
                case JExifTag.EXIFTAG_TAG_SENSINGMODE:
                    obj = Main.getString(String.format("data_sensingmode_0x%1$04X", data.getSensingMode()));
                    break;
                case JExifTag.EXIFTAG_TAG_CUSTOMRENDERED:
                    obj = Main.getString(String.format("data_customrendered_0x%1$04X", data.getCustomRendered()));
                    break;
                case JExifTag.EXIFTAG_TAG_EXPOSUREMODE:
                    obj = Main.getString(String.format("data_exposuremode_0x%1$04X", data.getExposureMode()));
                    break;
                case JExifTag.EXIFTAG_TAG_WHITEBALANCE:
                    obj = Main.getString(String.format("data_whitebalance_0x%1$04X", data.getWhiteBalance()));
                    break;
                case JExifTag.EXIFTAG_TAG_DIGITALZOOMRATIO:
                    obj = data.getDigitalZoomRatio();
                    break;
                case JExifTag.EXIFTAG_TAG_FOCALLENGTH35MM:
                    obj = data.getFocalLength35mm();
                    break;
                case JExifTag.EXIFTAG_TAG_SCENECAPTURETYPE:
                    obj = Main.getString(String.format("data_scenecapturetype_0x%1$04X", data.getSceneCaptureType()));
                    break;
                case JExifTag.EXIFTAG_TAG_SCENETYPE:
                    obj = Main.getString(String.format("data_scenetype_0x%1$04X", data.getSceneType()));
                    break;
                case JExifTag.EXIFTAG_TAG_GAINCONTROL:
                    obj = Main.getString(String.format("data_gaincontrol_0x%1$04X", data.getGainControl()));
                    break;
                case JExifTag.EXIFTAG_TAG_CONTRAST:
                    obj = Main.getString(String.format("data_contrast_0x%1$04X", data.getContrast()));
                    break;
                case JExifTag.EXIFTAG_TAG_SATURATION:
                    obj = Main.getString(String.format("data_saturation_0x%1$04X", data.getSaturation()));
                    break;
                case JExifTag.EXIFTAG_TAG_SHARPNESS:
                    obj = Main.getString(String.format("data_sharpness_0x%1$04X", data.getSharpness()));
                    break;
                case JExifTag.EXIFTAG_TAG_SUBJECTDISTANCERANGE:
                    obj = Main.getString(String.format("data_subjectdistancerange_0x%1$04X", data.getSubjectDistanceRange()));
                    break;
                case JExifTag.EXIFTAG_TAG_FILESIZE:
                    StringBuilder strBuilder = new StringBuilder();
                    if (data.getFileSize() < 1024)
                    strBuilder.append(Long.toString(data.getFileSize()));
                    else if (data.getFileSize() < 1024*1024)
                    {
                        strBuilder.append(String.format("%1$.1f ", (float)data.getFileSize()/1024.0f));
                        strBuilder.append(Main.getString("KByte"));
                    }
                    else if (data.getFileSize() < 1024*1024*1024)
                    {
                        strBuilder.append(String.format("%1$.2f ", (float)data.getFileSize()/(1024.0f*1024.0f)));
                        strBuilder.append(Main.getString("MByte"));
                    }
                    obj = strBuilder.toString();
                    break;
                case JExifTag.EXIFTAG_TAG_FILEDATETIME:
                    if ((date = data.getFileDate()) != null)
                    {
                        strBuf = new StringBuffer();
                        Main.m_shortDayOfWeekFormat.format(date, strBuf, new FieldPosition(0));
                        obj = strBuf + ", " + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date);
                    }
                    else obj = "";
                    break;
                case JExifTag.EXIFTAG_TAG_FILESOURCE:
                    obj = Main.getString(String.format("data_filesource_0x%1$04X", data.getFileSource()));
                    break;
                // GPS stuff
                case JExifTag.GPSTAG_TAG_VERSIONID:
                    obj = data.getGPSVersionID();
                    break;
                case JExifTag.GPSTAG_TAG_LATITUDE:
                    obj = String.format("%.6f° %s", data.getGPSLatitude(), Main.getString(String.format("data_gps_latituderef_%s", data.getGPSLatitudeRef())));
                    break;
                case JExifTag.GPSTAG_TAG_LONGITUDE:
                    obj = String.format("%.6f° %s", data.getGPSLongitude(), Main.getString(String.format("data_gps_longituderef_%s", data.getGPSLongitudeRef())));
                    break;
                case JExifTag.GPSTAG_TAG_ALTITUDE:
                    int ref = data.getGPSAltitudeRef();
                    if (ref>=0)
                        ref = ref != 0 ? -1 : 1;
                    else throw new MissingResourceException(null, null, null);
                    float f = data.getGPSAltitude();
                    if (Float.isNaN(f))
                        throw new MissingResourceException(null, null, null);
                    else
                        obj = String.format("%.1f m", ref*f, Main.getString("data_gps_altitude_unit"));
                    break;
                case JExifTag.GPSTAG_TAG_TIMESTAMP:
                    strBuf = new StringBuffer();
                    date = data.getGPSTimestamp();
                    if (date != null)
                    {
                        Main.m_shortDayOfWeekFormat.format(date, strBuf, new FieldPosition(0));
                        obj = strBuf + ", " + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date);
                    }
                    else obj = null;
                case JExifTag.GPSTAG_TAG_SATELLITES:
                    obj = data.getGPSSatellites();
                    break;
                case JExifTag.GPSTAG_TAG_STATUS:
                    obj = Main.getString(String.format("data_gps_status_%s", data.getGPSStatus()));
                    break;
                case JExifTag.GPSTAG_TAG_MEASUREMODE:
                    obj = data.getGPSMeasureMode();
                    break;
                case JExifTag.GPSTAG_TAG_MAPLINK:
                    if (data.isTagPresent(JExifTag.GPSTAG_TAG_MAPLINK))
                        obj = String.format(Main.getString("data_gps_maplink"), Main.m_url_map.toString());
                    else obj = new String("");
                    break;
            }
        }
        catch (MissingResourceException ex)
        {
            obj = Main.getString("data_unknown");
        }
        return obj;
    }
   
    public Object getValueAt(int row, int col)
    {
        assert col >= 0 && col < m_colTag.length;
        JIfdData data = m_data.get(row);
        Object obj = getTagValue(data, m_colTag[col]);
        return obj;
    }

    public String getColumnName(int col)
    {
        String str = null;
      assert col >= 0 && col < m_colTag.length;
        if (col >= 0 && col < m_colTag.length)
      str = m_resBundle.getString(String.format("colheader_tag_0x%1$04X", m_colTag[col]));
        return str;
    }
   
    public void sort()
    {
        Collections.sort(m_data, new JExifDataComparator(m_sortData));
        fireTableDataChanged();
    }
}

class JExifDataComparator implements Comparator<JIfdData>
{
    private JTableColSortData[] m_sortData;
    private int m_index = 0;
   
    public JExifDataComparator(JTableColSortData[] sortData)
    {
      m_sortData = sortData;
    }
   
    public int compare(JIfdData data1, JIfdData data2)
    {
        int h = 0;
        double d, d1, d2;
        long l1, l2;
        Date date1, date2;
        switch(JExifDataModel.m_colTag[m_sortData[m_index].getSortCol()])
        {
            case JExifTag.EXIFTAG_TAG_NAME:
                h = data1.getFileName().compareTo(data2.getFileName());
                break;
            case JExifTag.EXIFTAG_TAG_MAKE:
                h = data1.getMake().compareTo(data2.getMake());
                break;
            case JExifTag.EXIFTAG_TAG_DESCRIPTION:
                h = data1.getDescription().compareTo(data2.getDescription());
                break;
            case JExifTag.EXIFTAG_TAG_MODEL:
                h = data1.getModel().compareTo(data2.getModel());
                break;
            case JExifTag.EXIFTAG_TAG_ORIENTATION:
                h = data1.getOrientation() - data2.getOrientation();
                break;
            case JExifTag.EXIFTAG_TAG_RESOLUTION:
                d = 1.0;
                if (data1.getResolutionUnit() != data2.getResolutionUnit())
                    d = data1.getResolutionUnit() == 2 ? 6.4516 : 1/6.4516;
                d = data1.getXResolution() * data1.getYResolution() * d - data2.getXResolution() * data2.getYResolution();
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.EXIFTAG_TAG_SOFTWARE:
                h = data1.getSoftware().compareTo(data2.getSoftware());
                break;
            case JExifTag.EXIFTAG_TAG_CHANGEDATETIME:
                h = data1.getChangeDateTime().compareTo(data2.getChangeDateTime());
                break;
            case JExifTag.EXIFTAG_TAG_ARTIST:
                h = data1.getArtist().compareTo(data2.getArtist());
                break;
            case JExifTag.EXIFTAG_TAG_YCBCRPOSITION:
                h = data1.getYCbCrPosition() - data2.getYCbCrPosition();
                break;
            case JExifTag.EXIFTAG_TAG_COPYRIGHT:
                h = data1.getCopyright().compareTo(data2.getCopyright());
                break;
            case JExifTag.EXIFTAG_TAG_EXPOSURETIME:
                h = data1.getExposureTime(null) - data2.getExposureTime(null);
                break;
            case JExifTag.EXIFTAG_TAG_FNUMBER:
                d = data1.getFNumber(null) - data2.getFNumber(null);
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.EXIFTAG_TAG_EXPOSUREPROGRAM:
                h = data1.getExposureProgram() - data2.getExposureProgram();
                break;
            case JExifTag.EXIFTAG_TAG_ISOSPEEDRATINGS:
                h = data1.getISOSpeedRatings() - data2.getISOSpeedRatings();
                break;
            case JExifTag.EXIFTAG_TAG_EXIFVERSION:
                h = data1.getExifVersion().compareTo(data2.getExifVersion());
                break;
            case JExifTag.EXIFTAG_TAG_ORIGINALDATETIME:
                h = data1.getOriginalDateTime().compareTo(data2.getOriginalDateTime());
                break;
            case JExifTag.EXIFTAG_TAG_DIGITIZEDDATETIME:
                h = data1.getDigitizedDateTime().compareTo(data2.getDigitizedDateTime());
                break;
            case JExifTag.EXIFTAG_TAG_COMPONENTSCCONFIG:
                h = data1.getComponentsConfig().compareTo(data2.getComponentsConfig());
                break;
            case JExifTag.EXIFTAG_TAG_COMPRESSEDPITSPERPIXEL:
                d = data1.getCompressedBitsPerPixel() - data2.getCompressedBitsPerPixel();
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.EXIFTAG_TAG_SHUTERSPEEDVALUE:
                d = data1.getShuterSpeedValue() - data2.getShuterSpeedValue();
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.EXIFTAG_TAG_APERTUREVALUE:
                d = data1.getApertureValue() - data2.getApertureValue();
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.EXIFTAG_TAG_BRIGHTNESSVALUE:
                d = data1.getBrightnessValue() - data2.getBrightnessValue();
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.EXIFTAG_TAG_EXPOSUREBIASVALUE:
                d = data1.getExposureBiasValue() - data2.getExposureBiasValue();
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.EXIFTAG_TAG_MAXAPERTUREVALUE:
                d = data1.getMaxApertureValue() - data2.getMaxApertureValue();
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.EXIFTAG_TAG_METERINGMODE:
                h = data1.getMeteringMode() - data2.getMeteringMode();
                break;
            case JExifTag.EXIFTAG_TAG_LIGHTSOURCE:
                h = data1.getLightSource() - data2.getLightSource();
                break;
            case JExifTag.EXIFTAG_TAG_FLASH:
                h = data1.getFlash() - data2.getFlash();
                break;
            case JExifTag.EXIFTAG_TAG_FOCALLENGTH:
                d = data1.getFocalLength() - data2.getFocalLength();
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.EXIFTAG_TAG_COLORSPACE:
                h = data1.getColorSpace() - data2.getColorSpace();
                break;
            case JExifTag.EXIFTAG_TAG_SIZE:
                d = data1.getPixelXDimension() * data1.getPixelYDimension() - data2.getPixelXDimension() * data2.getPixelYDimension();
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.EXIFTAG_TAG_FOCALPLANERESOLUTION:
                d = 1.0;
                if (data1.getFocalPlaneResolutionUnit() != data2.getFocalPlaneResolutionUnit())
                    d = data1.getResolutionUnit() == 2 ? 6.4516 : 1/6.4516;
                d = data1.getFocalPlaneXResolution() * data1.getFocalPlaneYResolution() * d - data2.getFocalPlaneXResolution() * data2.getFocalPlaneYResolution();
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.EXIFTAG_TAG_SENSINGMODE:
                h = data1.getSensingMode() - data2.getSensingMode();
                break;
            case JExifTag.EXIFTAG_TAG_CUSTOMRENDERED:
                h = data1.getCustomRendered() - data2.getCustomRendered();
                break;
            case JExifTag.EXIFTAG_TAG_EXPOSUREMODE:
                h = data1.getExposureMode() - data2.getExposureMode();
                break;
            case JExifTag.EXIFTAG_TAG_WHITEBALANCE:
                h = data1.getWhiteBalance() - data2.getWhiteBalance();
                break;
            case JExifTag.EXIFTAG_TAG_DIGITALZOOMRATIO:
                d = data1.getDigitalZoomRatio() - data2.getDigitalZoomRatio();
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.EXIFTAG_TAG_FOCALLENGTH35MM:
                h = data1.getFocalLength35mm() - data2.getFocalLength35mm();
                break;
            case JExifTag.EXIFTAG_TAG_SCENECAPTURETYPE:
                h = data1.getSceneCaptureType() - data2.getSceneCaptureType();
                break;
            case JExifTag.EXIFTAG_TAG_SCENETYPE:
                h = data1.getSceneType() - data2.getSceneType();
                break;
            case JExifTag.EXIFTAG_TAG_GAINCONTROL:
                h = data1.getGainControl() - data2.getGainControl();
                break;
            case JExifTag.EXIFTAG_TAG_CONTRAST:
                h = data1.getContrast() - data2.getContrast();
                break;
            case JExifTag.EXIFTAG_TAG_SATURATION:
                h = data1.getSaturation() - data2.getSaturation();
                break;
            case JExifTag.EXIFTAG_TAG_SHARPNESS:
                h = data1.getSharpness() - data2.getSharpness();
                break;
            case JExifTag.EXIFTAG_TAG_SUBJECTDISTANCERANGE:
                h = data1.getSubjectDistanceRange() - data2.getSubjectDistanceRange();
                break;
            case JExifTag.EXIFTAG_TAG_FILESIZE:
                h = (int)(data1.getFileSize() - data2.getFileSize());
                break;
            case JExifTag.EXIFTAG_TAG_FILEDATETIME:
                h = data1.getFileDate().compareTo(data2.getFileDate());
                break;
            case JExifTag.EXIFTAG_TAG_FILESOURCE:
                h = (int)(data1.getFileSource() - data2.getFileSource());
                break;
            // GPS stuff
            case JExifTag.GPSTAG_TAG_VERSIONID:
                h = data1.getGPSVersionID().compareTo(data2.getGPSVersionID());
                break;
            case JExifTag.GPSTAG_TAG_LATITUDE:
                d1 = data1.getGPSLatitude()*(data1.getGPSLatitudeRef().equals("N") ? 1 : -1);
                d2 = data2.getGPSLatitude()*(data2.getGPSLatitudeRef().equals("N") ? 1 : -1);
                d = d1 - d2;
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.GPSTAG_TAG_LONGITUDE:
                d1 = data1.getGPSLongitude()*(data1.getGPSLongitudeRef().equals("E") ? 1 : -1);
                d2 = data2.getGPSLongitude()*(data2.getGPSLongitudeRef().equals("E") ? 1 : -1);
                d = d1 - d2;
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.GPSTAG_TAG_ALTITUDE:
                d1 = data1.getGPSAltitude()*(data1.getGPSAltitudeRef()> 0 ? -1 : 1);
                d2 = data2.getGPSAltitude()*(data2.getGPSAltitudeRef()> 0 ? -1 : 1);
                d = d1 - d2;
                if (d < 0) h = -1;
                else if (d >  0) h = 1;
                else h = 0;
                break;
            case JExifTag.GPSTAG_TAG_TIMESTAMP:
                date1 = data1.getGPSTimestamp();
                date2 = data2.getGPSTimestamp();
                if (date1 != null && date2 != null)
                {
                    l1 = date1.getTime();
                    l2 = date2.getTime();
                    if (l1 < l2) h = -1;
                    else if (l1 > l2) h = 1;
                    else h= 0;
                }
                else if (date1 != null) h = -1;
                else if (date2 != null) h = 1;
                else h= 0;
                d2 = data2.getGPSAltitude()*(data2.getGPSAltitudeRef()> 0 ? -1 : 1);
            case JExifTag.GPSTAG_TAG_SATELLITES:
                h = data1.getGPSSatellites().compareTo(data2.getGPSSatellites());
                break;
            case JExifTag.GPSTAG_TAG_STATUS:
                h = data1.getGPSStatus().compareTo(data2.getGPSStatus());
                break;
            case JExifTag.GPSTAG_TAG_MEASUREMODE:
                h = data1.getGPSMeasureMode().compareTo(data2.getGPSMeasureMode());
                break;
            case JExifTag.GPSTAG_TAG_MAPLINK:
                if (data1.isTagPresent(JExifTag.GPSTAG_TAG_MAPLINK) && !data2.isTagPresent(JExifTag.GPSTAG_TAG_MAPLINK))
                    h = 1;
                else if (!data1.isTagPresent(JExifTag.GPSTAG_TAG_MAPLINK) && data2.isTagPresent(JExifTag.GPSTAG_TAG_MAPLINK))
                    h = -1;
                break;

        }
        if (h == 0)
        {
            if (++m_index < m_sortData.length)
            h = compare(data1, data2);
            m_index--;
        }
        else if (!m_sortData[m_index].getSortUp())
            h = -h;
        return h;
    }
   
    public boolean equals(Object obj)
    {
        boolean flag = false;

        if (obj instanceof JExifDataComparator)
        {
            JExifDataComparator comp = (JExifDataComparator)obj;
            if (comp.m_sortData.equals(comp.m_sortData))
            flag = true;
        }
        return flag;
    }
}
TOP

Related Classes of jexifviewer.JExifDataComparator

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.