import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
+import java.io.IOException;
import java.util.Date;
+import java.util.Properties;
+
import javax.swing.*;
-import osm.jp.gpx.ImportPicture;
+
+import osm.jp.gpx.*;
+import org.apache.commons.imaging.ImageReadException;
+import org.apache.commons.imaging.ImageWriteException;
+import org.apache.commons.imaging.Imaging;
+import org.apache.commons.imaging.common.ImageMetadata;
+import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
+import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
+import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
+import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory;
+import org.apache.commons.imaging.formats.tiff.write.TiffOutputField;
+import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet;
+
+
/**
* 本プログラムのメインクラス
JPanel argsPanel; // パラメータ設定パネル (上部)
JScrollPane imageSPane; // スクロールパネル
JLabel imageLabel; // 基準時刻画像表示
+ JCheckBox exifBase; // EXIF日時を基準にする/ !(ファイル更新日時を基準にする)
JTextArea textArea; // 実行結果表示領域
//ImagePreview imagePane; // 基準時刻画像表示
- ParameterPanelFolder arg1Panel_1;
- ParameterPanelImageFile arg1Panel_2;
- ParameterPanel arg1Panel_3;
- JRadioButton exifON; // EXIF 書き出しモード
- ParameterPanelFolder arg1Panel_4; // EXIF 書き出しフォルダ
- ParameterPanelFolder arg1Panel_5; // GPXファイル・フォルダ
+ ParameterPanelFolder arg1_srcFolder;
+ ParameterPanelImageFile arg2_baseTimeImg;
+ ParameterPanel arg3_basetiome;
+ JCheckBox exifON; // EXIF 書き出しモード / !(EXIFの書き換えはしない)
+ ParameterPanelFolder arg5_outputFolder; // EXIF 書き出しフォルダ
+ ParameterPanelFolder arg4_gpxFolder; // GPXファイル・フォルダ
JPanel buttonPanel; // ボタンパネル (下部)
JButton openButton; // [Fit]ボタン
else if (object == zoomOutButton) {
zoomout_Action(event);
}
- else if (object == arg1Panel_2.argField) {
+ else if (object == arg2_baseTimeImg.argField) {
imageView_Action(event);
}
- else if (object == arg1Panel_2.openButton) {
+ else if (object == arg2_baseTimeImg.openButton) {
selectImage_Action(event);
imageView_Action(event);
}
+ else if (object == exifON) {
+ exifON_Action(event);
+ }
else if (object == doButton) {
doButton_Action(event);
}
}
}
}
+
+ Properties config;
/**
* データベース内のテーブルを一覧で表示するFrame
+ * @throws IOException
*/
- public AdjustTime()
+ public AdjustTime() throws IOException
{
// INIT_CONTROLS
Container container = getContentPane();
setSize(getInsets().left + getInsets().right + 960,getInsets().top + getInsets().bottom + 480);
setTitle(AdjustTime.PROGRAM_NAME +" v"+ AdjustTime.PROGRAM_VARSION);
+ config = Config.getProperties();
+
//---------------------------------------------------------------------
cardPanel = new JPanel();
cardPanel.setLayout(new CardLayout());
argsPanel = new JPanel();
argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
- arg1Panel_1 = new ParameterPanelFolder("対象フォルダ: ", (new File(".")).getAbsolutePath());
- argsPanel.add(arg1Panel_1);
+ arg1_srcFolder = new ParameterPanelFolder("対象フォルダ: ", (new File(".")).getAbsolutePath());
+ argsPanel.add(arg1_srcFolder);
cards[cardNo].add(argsPanel, BorderLayout.CENTER);
//---------------------------------------------------------------------
argsPanel = new JPanel();
argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
- arg1Panel_2 = new ParameterPanelImageFile("基準時刻画像: ", "", arg1Panel_1);
- argsPanel.add(arg1Panel_2);
+ arg2_baseTimeImg = new ParameterPanelImageFile("基準時刻画像: ", "", arg1_srcFolder);
+ argsPanel.add(arg2_baseTimeImg);
+
+ exifBase = new JCheckBox("EXIFの日時を基準にする", false);
+ exifBase.setEnabled(false);
+ argsPanel.add(exifBase);
cards[cardNo].add(argsPanel, BorderLayout.CENTER);
//---------------------------------------------------------------------
JLabel label3 = new JLabel();
label3.setText("<html><p>正確な撮影時刻を入力してください。</p><ul><li>カメラの時計が正確ならば、設定を変更する必要はありません。</li></ul>");
argsPanel.add(label3);
- arg1Panel_3 = new ParameterPanel(" 基準時刻: ", ImportPicture.TIME_FORMAT_STRING);
- argsPanel.add(arg1Panel_3);
+ arg3_basetiome = new ParameterPanel(" 基準時刻: ", ImportPicture.TIME_FORMAT_STRING);
+ argsPanel.add(arg3_basetiome);
cards[cardNo].add(argsPanel, BorderLayout.NORTH);
// 参考画像
JPanel tmpPanel4 = new JPanel();
tmpPanel4.setLayout(new BoxLayout(tmpPanel4, BoxLayout.Y_AXIS));
File gpxDir = new File(".");
- arg1Panel_5 = new ParameterPanelFolder("GPXフォルダ: ", gpxDir.getAbsolutePath());
- tmpPanel4.add(arg1Panel_5);
+ arg4_gpxFolder = new ParameterPanelFolder("GPXフォルダ: ", gpxDir.getAbsolutePath());
+ tmpPanel4.add(arg4_gpxFolder);
cards[cardNo].add(tmpPanel4, BorderLayout.CENTER);
//---------------------------------------------------------------------
JPanel tmpPanel5 = new JPanel();
tmpPanel5.setLayout(new BoxLayout(tmpPanel5, BoxLayout.Y_AXIS));
- exifON = new JRadioButton("EXIFの変換をする");
- JRadioButton exifOFF = new JRadioButton("EXIFの変換をしない", true);
- ButtonGroup group = new ButtonGroup();
- group.add(exifON);
- group.add(exifOFF);
- tmpPanel5.add(exifOFF);
+ exifON = new JCheckBox("EXIFの変換をする", false);
tmpPanel5.add(exifON);
File outputDir = new File(".");
- arg1Panel_4 = new ParameterPanelFolder("書き出しフォルダ: ", outputDir.getAbsolutePath());
- tmpPanel5.add(arg1Panel_4);
+ arg5_outputFolder = new ParameterPanelFolder("書き出しフォルダ: ", outputDir.getAbsolutePath());
+ tmpPanel5.add(arg5_outputFolder);
cards[cardNo].add(tmpPanel5, BorderLayout.CENTER);
doButton = new JButton("処理実行", AdjustTime.createImageIcon("images/media_playback_start.png"));
openButton.addActionListener(lSymAction);
zoomOutButton.addActionListener(lSymAction);
zoomInButton.addActionListener(lSymAction);
- arg1Panel_2.argField.addActionListener(lSymAction);
- arg1Panel_2.openButton.addActionListener(lSymAction);
+ arg2_baseTimeImg.argField.addActionListener(lSymAction);
+ arg2_baseTimeImg.openButton.addActionListener(lSymAction);
doButton.addActionListener(lSymAction);
+ exifON.addActionListener(lSymAction);
//arg1Panel_4.field.addActionListener(lSymAction);
nextButton.addActionListener(lSymAction);
backButton.addActionListener(lSymAction);
*/
static public void main(String args[]) {
SwingUtilities.invokeLater(() -> {
- createAndShowGUI();
+ try {
+ createAndShowGUI();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
});
}
- private static void createAndShowGUI() {
+ private static void createAndShowGUI() throws IOException {
(new AdjustTime()).setVisible(true);
}
* 選択された画像ファイルを表示する
* 基準画像ボタンがクリックされた時に、基準時刻フィールドに基準画像の作成日時を設定する。
* @param ev
+ * @throws ImageReadException
+ * @throws ImageWriteException
*/
public void imageView_Action(ActionEvent ev) {
- String path = (new File(arg1Panel_1.getText(), arg1Panel_2.getText())).getPath();
+ String path = (new File(arg1_srcFolder.getText(), arg2_baseTimeImg.getText())).getPath();
File timeFile = new File(path);
long lastModifyTime = timeFile.lastModified();
- arg1Panel_3.argField.setText(ImportPicture.dfjp.format(new Date(lastModifyTime)));
+ arg3_basetiome.argField.setText(ImportPicture.dfjp.format(new Date(lastModifyTime)));
+
+ try {
+ ImageMetadata meta = Imaging.getMetadata(timeFile);
+ if (!(meta instanceof JpegImageMetadata)) {
+ TiffImageMetadata exif = ((JpegImageMetadata)meta).getExif();
+ if (exif != null) {
+ TiffOutputSet outputSet = exif.getOutputSet();
+ TiffOutputDirectory exifDir = outputSet.getOrCreateExifDirectory();
+ TiffOutputField field = exifDir.findField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
+ arg3_basetiome.argField.setText(field.toString());
+ }
+ }
+ }
+ catch (Exception e) {}
int size_x = imageSPane.getWidth() - 8;
ImageIcon tmpIcon = new ImageIcon(path);
public void zoomin_Action(ActionEvent ev) {
if (refImage != null) {
int size_x = imageLabel.getWidth();
- String path = (new File(arg1Panel_1.getText(), arg1Panel_2.getText())).getPath();
+ String path = (new File(arg1_srcFolder.getText(), arg2_baseTimeImg.getText())).getPath();
ImageIcon tmpIcon = new ImageIcon(path);
refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x * 2, -1, Image.SCALE_DEFAULT));
imageLabel.setIcon(refImage);
repaint();
}
}
-
+
+ /**
+ * ソースディレクトリが選択された時のアクション
+ * → AdjustTime.ini に書き込む
+ * @param ev
+ */
+ public void selectSource_Action(ActionEvent ev) {
+ }
+
public void selectImage_Action(ActionEvent ev) {
JFileChooser fc;
//Set up the file chooser.
- File sdir = new File(arg1Panel_1.getText());
+ File sdir = new File(arg1_srcFolder.getText());
System.out.println(sdir.getPath());
if (sdir.isDirectory()) {
fc = new JFileChooser(sdir);
//Process the results.
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
- arg1Panel_2.argField.setText(file.getName());
+ arg2_baseTimeImg.argField.setText(file.getName());
}
//Reset the file chooser for the next time it's shown.
}
/**
+ * checkbox[EXIF書き出し]を変更した場合のアクション
+ * ON ー> EXIF変換先フォルダのフィールドを有効にする
+ * OFF -> EXIF変換先フォルダのフィールドを無効にする
+ * @param event
+ */
+ void exifON_Action (ActionEvent event) {
+ arg5_outputFolder.setEnabled(exifON.isEnabled());
+ }
+
+ /**
* [実行]ボタンをクリックしたときの動作
* @param event
*/
doButton.setEnabled(false);
String[] argv = new String[5];
- argv[0] = arg1Panel_1.getText();
- argv[1] = arg1Panel_2.getText();
- argv[2] = arg1Panel_3.getText();
- argv[3] = (exifON.isSelected() ? arg1Panel_4.getText() : "noEXIF");
- argv[4] = arg1Panel_5.getText();
+ argv[0] = arg1_srcFolder.getText();
+ argv[1] = arg2_baseTimeImg.getText();
+ argv[2] = arg3_basetiome.getText();
+ argv[3] = (exifON.isSelected() ? arg5_outputFolder.getText() : "noEXIF");
+ argv[4] = arg4_gpxFolder.getText();
(new DoDialog(this, argv)).setVisible(true);