package osm.jp.gpx.matchtime.gui;
+import osm.jp.gpx.matchtime.gui.restamp.RestampDialog;
import java.awt.*;
import java.awt.event.ActionEvent;
-import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
-import java.util.Date;
import java.util.ResourceBundle;
import java.util.TimeZone;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.swing.*;
+import javax.swing.event.DocumentEvent;
import osm.jp.gpx.*;
-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 osm.jp.gpx.matchtime.gui.restamp.CardImageFile;
+import osm.jp.gpx.matchtime.gui.restamp.CardSourceFolder;
/**
* 本プログラムのメインクラス
{
public static final String PROGRAM_NAME = "AdjustTime for JOSM";
public static final String PROGRAM_VARSION = "5.01";
- public static final String PROGRAM_UPDATE = "2019/08/25";
+ public static final String PROGRAM_UPDATE = "2019/09/11";
AppParameters params;
- SimpleDateFormat dfjp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
+ public static SimpleDateFormat dfjp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
// Used for addNotify check.
boolean fComponentsAdjusted = false;
- public ResourceBundle i18n = ResourceBundle.getBundle("i18n");
+ public static ResourceBundle i18n = ResourceBundle.getBundle("i18n");
//{{DECLARE_CONTROLS
JTabbedPane cardPanel; // ウィザード形式パネル(タブ型)
- JPanel[] cards;
+ Card[] cards;
int cardPanelNo = 0;
JPanel argsPanel; // パラメータ設定パネル (上部)
JScrollPane imageSPane; // スクロールパネル
JLabel imageLabel; // 基準時刻画像表示
- ButtonGroup baseTimeGroup; // 基準時刻の指定グループ
- JRadioButton exifBase; // EXIF日時を基準にする/ !(ファイル更新日時を基準にする)
- JRadioButton fupdateBase; // File更新日時を基準にする/ !(EXIF日時を基準にする)
JCheckBox noFirstNode; // GPX: <trkseg>セグメントの最初の1ノードは無視する。 {ON | OFF}
JCheckBox gpxReuse; // 生成されたGPXファイル(ファイル名が'_.gpx'で終わるもの)も対象にする。 {ON | OFF}
JTextArea textArea; // 実行結果表示領域
- ParameterPanelFolder arg1_srcFolder;
- ParameterPanelImageFile arg2_baseTimeImg;
+
ParameterPanel arg3_basetime; // 基準時刻:
JCheckBox outputIMG; // IMGの変換 する/しない
JCheckBox outputIMG_all; // 'out of GPX time'でもIMGの変換をする {ON | OFF}
ParameterPanelGpx arg4_gpxFolder; // GPXファイル・フォルダ
JPanel buttonPanel; // ボタンパネル (下部)
- JButton openButton; // [Fit]ボタン
- JButton zoomInButton; // [Zoom in]ボタン
- JButton zoomOutButton; // [Zoom out]ボタン
JButton doButton; // [処理実行]ボタン
//}}
+ //---入力フィールド----------------------------------------------------
+ ParameterPanelFolder arg1_srcFolder; // 対象フォルダ
+ ParameterPanelImageFile arg2_baseTimeImg; // 開始画像ファイルパス
+ ParameterPanelTime arg2_basetime; // 開始画像の基準時刻:
+
//{{DECLARE_MENUS
java.awt.MenuBar mainMenuBar;
java.awt.Menu menu1;
java.awt.MenuItem miDoDirSize;
java.awt.MenuItem miDoReadXML;
java.awt.MenuItem miExit;
+ java.awt.Menu menu2;
+ java.awt.MenuItem miRestamp;
java.awt.Menu menu3;
java.awt.MenuItem miAbout;
//}}
if (object == miAbout) {
miAbout_Action(event);
}
+ else if (object == miRestamp) {
+ try {
+ miRestamp_Action(event);
+ } catch (IOException ex) {
+ Logger.getLogger(AdjustTime.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
else if (object == miExit) {
miExit_Action(event);
}
- else if (object == openButton) {
- imageView_Action(event);
- }
- else if (object == zoomInButton) {
- zoomin_Action(event);
- }
- else if (object == zoomOutButton) {
- zoomout_Action(event);
- }
- else if (object == arg2_baseTimeImg.argField) {
- imageView_Action(event);
- }
- else if (object == arg2_baseTimeImg.openButton) {
- selectImage_Action(event);
- imageView_Action(event);
- }
else if (object == outputIMG) {
outputIMG_Action(event);
}
cardPanel = new JTabbedPane(JTabbedPane.LEFT);
mainPanel.add(cardPanel, BorderLayout.CENTER);
- cards = new JPanel[5];
- cardPanelNo = 0;
+ cards = new Card[5];
+ int cardNo = 0;
//---------------------------------------------------------------------
// 1.[対象フォルダ]設定パネル
- int cardNo = 0;
{
- Card card = new Card(cardPanel, i18n.getString("tab.100"), -1, 1);
+ arg1_srcFolder = new ParameterPanelFolder(
+ i18n.getString("label.110") +": ",
+ params.getProperty(AppParameters.IMG_SOURCE_FOLDER)
+ );
+ arg1_srcFolder.argField
+ .getDocument()
+ .addDocumentListener(
+ new SimpleDocumentListener() {
+ @Override
+ public void update(DocumentEvent e) {
+ toEnable(0, arg1_srcFolder.isEnable());
+ }
+ }
+ );
+
+ Card card = new CardSourceFolder(cardPanel, arg1_srcFolder);
cardPanel.addTab(card.getTitle(), card);
+ cardPanel.setEnabledAt(cardNo, true);
cards[cardNo] = card;
-
- JLabel label1 = new JLabel();
- label1.setText(i18n.getString("label.100"));
- card.mainPanel.add(label1, BorderLayout.NORTH);
-
- argsPanel = new JPanel();
- argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
- arg1_srcFolder = new ParameterPanelFolder(i18n.getString("label.110") +": ", params.getProperty(AppParameters.IMG_SOURCE_FOLDER));
- argsPanel.add(arg1_srcFolder);
- card.mainPanel.add(argsPanel, BorderLayout.CENTER);
+ cardNo++;
}
//---------------------------------------------------------------------
// 2.[基準時刻画像]設定パネル
- cardNo++;
+ // 2a.基準時刻の入力画面
{
- Card card = new Card(cardPanel, i18n.getString("tab.200"), 0, 2);
- cardPanel.addTab(card.getTitle(), card);
- cards[cardNo] = card;
-
- JLabel label2 = new JLabel();
- label2.setText(i18n.getString("label.200"));
- card.mainPanel.add(label2, BorderLayout.NORTH);
-
- argsPanel = new JPanel();
-
// 基準時刻画像
- argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
- arg2_baseTimeImg = new ParameterPanelImageFile(i18n.getString("label.210") +": ", params.getProperty(AppParameters.IMG_BASE_FILE), arg1_srcFolder);
- argsPanel.add(arg2_baseTimeImg);
-
- baseTimeGroup = new ButtonGroup();
+ arg2_baseTimeImg = new ParameterPanelImageFile(
+ i18n.getString("label.210") +": ",
+ null,
+ arg1_srcFolder
+ );
+ // 2a. 基準時刻:
+ arg2_basetime = new ParameterPanelTime(
+ i18n.getString("label.310"),
+ null,
+ arg2_baseTimeImg
+ );
+ arg2_basetime.argField.getDocument().addDocumentListener(
+ new SimpleDocumentListener() {
+ @Override
+ public void update(DocumentEvent e) {
+ toEnable(1, arg2_basetime.isEnable());
+ }
+ }
+ );
+
// EXIFの日時を基準にする
- exifBase = new JRadioButton(i18n.getString("label.220"));
+ arg2_basetime.addExifBase(i18n.getString("label.220"), params);
// ファイル更新日時を基準にする
- fupdateBase = new JRadioButton(i18n.getString("label.230"));
- baseTimeGroup.add(exifBase);
- baseTimeGroup.add(fupdateBase);
- argsPanel.add(exifBase);
- argsPanel.add(fupdateBase);
- if (params.getProperty(AppParameters.GPX_BASETIME).equals("EXIF_TIME")) {
- fupdateBase.setSelected(false);
- exifBase.setSelected(true);
- }
- else {
- fupdateBase.setSelected(true);
- exifBase.setSelected(false);
- }
- card.mainPanel.add(argsPanel, BorderLayout.CENTER);
- }
-
- //---------------------------------------------------------------------
- // 2a.基準時刻の入力画面
- cardNo++;
- {
- Card card = new Card(cardPanel, i18n.getString("tab.300"), 1, 3);
+ arg2_basetime.addFileUpdate(i18n.getString("label.230"), params);
+
+ CardImageFile card = new CardImageFile(
+ cardPanel, arg2_basetime, (Window)this,
+ AdjustTime.i18n.getString("tab.300"), 0, 2);
cardPanel.addTab(card.getTitle(), card);
+ cardPanel.setEnabledAt(cardNo, false);
cards[cardNo] = card;
-
- argsPanel = new JPanel();
- argsPanel.setLayout(new GridLayout(2, 1));
-
- // 3. 正確な撮影時刻を入力してください。
- // カメラの時計が正確ならば、設定を変更する必要はありません。
- JLabel label3 = new JLabel();
- label3.setText(i18n.getString("label.300"));
- argsPanel.add(label3);
-
- // 基準時刻:
- String str310 = String.format(" %s: ", i18n.getString("label.310"));
- arg3_basetime = new ParameterPanel(str310, ImportPicture.TIME_FORMAT_STRING);
- argsPanel.add(arg3_basetime);
- card.mainPanel.add(argsPanel, BorderLayout.NORTH);
-
- // 参考画像
- imageLabel = new JLabel();
- imageSPane = new JScrollPane(imageLabel);
- card.mainPanel.add(imageSPane, BorderLayout.CENTER);
-
- // 画像ファイル選択ダイアログを起動するボタン
- buttonPanel = new JPanel();
- buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
- openButton = new JButton(createImageIcon("images/Fit16.gif"));
- buttonPanel.add(openButton);
- zoomInButton = new JButton(createImageIcon("images/ZoomIn16.gif"));
- buttonPanel.add(zoomInButton);
- zoomOutButton = new JButton(createImageIcon("images/ZoomOut16.gif"));
- buttonPanel.add(zoomOutButton);
- card.mainPanel.add(buttonPanel, BorderLayout.SOUTH);
+ cardNo++;
}
//---------------------------------------------------------------------
// 3.GPXファイル設定画面
- cardNo++;
{
+ // 3. GPXファイルを選択
Card card = new Card(cardPanel, i18n.getString("tab.400"), 2, 4);
cardPanel.addTab(card.getTitle(), card);
cards[cardNo] = card;
gpxReuse.setEnabled(true);
tmpPanel4a.add(gpxReuse);
card.mainPanel.add(tmpPanel4a, BorderLayout.CENTER);
+ cardNo++;
}
//---------------------------------------------------------------------
// 4.EXIF更新設定画面
- cardNo++;
{
Card card = new Card(cardPanel, i18n.getString("tab.500"), 3, -1);
cardPanel.addTab(card.getTitle(), card);
AdjustTime.createImageIcon("images/media_playback_start.png")
);
card.mainPanel.add(doButton, BorderLayout.SOUTH);
+ cardNo++;
}
//---------------------------------------------------------------------
miExit.setFont(new Font("Dialog", Font.PLAIN, 12));
menu1.add(miExit);
+ miRestamp = new java.awt.MenuItem(i18n.getString("menu.restamp") + "...");
+ miRestamp.setFont(new Font("Dialog", Font.PLAIN, 12));
+
+ menu2 = new java.awt.Menu(i18n.getString("menu.tools"));
+ menu2.setFont(new Font("Dialog", Font.PLAIN, 12));
+ menu2.add(miRestamp);
+
miAbout = new java.awt.MenuItem("About...");
miAbout.setFont(new Font("Dialog", Font.PLAIN, 12));
mainMenuBar = new java.awt.MenuBar();
mainMenuBar.setHelpMenu(menu3);
mainMenuBar.add(menu1);
+ mainMenuBar.add(menu2);
mainMenuBar.add(menu3);
setMenuBar(mainMenuBar);
this.addWindowListener(aSymWindow);
SymAction lSymAction = new SymAction();
miAbout.addActionListener(lSymAction);
+ miRestamp.addActionListener(lSymAction);
miExit.addActionListener(lSymAction);
- openButton.addActionListener(lSymAction);
- zoomOutButton.addActionListener(lSymAction);
- zoomInButton.addActionListener(lSymAction);
- arg2_baseTimeImg.argField.addActionListener(lSymAction);
arg2_baseTimeImg.openButton.addActionListener(lSymAction);
doButton.addActionListener(lSymAction);
outputIMG_all.addActionListener(lSymAction);
(new AboutDialog(this, true)).setVisible(true);
}
+ void miRestamp_Action(java.awt.event.ActionEvent event) throws IOException {
+ (new RestampDialog(this, false)).setVisible(true);
+ }
+
void miExit_Action(java.awt.event.ActionEvent event) {
// Action from Exit Create and show as modal
//(new hayashi.yuu.tools.gui.QuitDialog(this, true)).setVisible(true);
(new QuitDialog(this, true)).setVisible(true);
}
-
- ImageIcon refImage;
- /**
- * 選択された画像ファイルを表示する
- * 基準画像ボタンがクリックされた時に、基準時刻フィールドに基準画像の作成日時を設定する。
- * @param ev
- */
- @SuppressWarnings("UseSpecificCatch")
- public void imageView_Action(ActionEvent ev) {
- String path = (new File(arg1_srcFolder.getText(), arg2_baseTimeImg.getText())).getPath();
-
- File timeFile = new File(path);
- if (exifBase.isSelected()) {
- try {
- ImageMetadata meta = Imaging.getMetadata(timeFile);
- JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta;
- if (jpegMetadata != null) {
- TiffImageMetadata exif = jpegMetadata.getExif();
- if (exif != null) {
- String dateTimeOriginal = exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0];
- long lastModifyTime = (new SimpleDateFormat("yyyy:MM:dd HH:mm:ss")).parse(dateTimeOriginal).getTime();
- arg3_basetime.argField.setText(dfjp.format(new Date(lastModifyTime)));
- }
- else {
- arg3_basetime.argField.setText("exif == null");
- }
- }
+ void toEnable(final int cardNo, final boolean enable) {
+ if ((cardNo >= 0) && (cardNo < cards.length)) {
+ cardPanel.setEnabledAt(cardNo, enable);
+ if ((cardNo -1) >= 0) {
+ cards[cardNo -1].nextButton.setEnabled(enable);
+ }
+ if ((cardNo +1) < cards.length) {
+ cardPanel.setEnabledAt(cardNo+1, enable);
+ cards[cardNo +1].backButton.setEnabled(enable);
+ cards[cardNo].nextButton.setEnabled(enable);
}
- catch (Exception e) {}
- }
- else {
- long lastModifyTime = timeFile.lastModified();
- arg3_basetime.argField.setText(dfjp.format(new Date(lastModifyTime)));
- }
-
- int size_x = imageSPane.getWidth() - 8;
- ImageIcon tmpIcon = new ImageIcon(path);
- refImage = tmpIcon;
- if (tmpIcon.getIconWidth() > size_x) {
- refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x, -1, Image.SCALE_DEFAULT));
}
- imageLabel.setIcon(refImage);
- repaint();
- }
-
- public void zoomin_Action(ActionEvent ev) {
- if (refImage != null) {
- int size_x = imageLabel.getWidth();
- 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();
- }
}
- public void zoomout_Action(ActionEvent ev) {
- if (refImage != null) {
- int size_x = imageLabel.getWidth();
- ImageIcon tmpIcon = refImage;
- refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x / 2, -1, Image.SCALE_DEFAULT));
- imageLabel.setIcon(refImage);
- repaint();
- }
- }
+ ImageIcon refImage;
/**
* ソースディレクトリが選択された時のアクション
public void selectSource_Action(ActionEvent ev) {
}
- public void selectImage_Action(ActionEvent ev) {
- JFileChooser fc;
-
- //Set up the file chooser.
- File sdir = new File(arg1_srcFolder.getText());
- System.out.println(sdir.getPath());
- if (sdir.isDirectory()) {
- fc = new JFileChooser(sdir);
- }
- else {
- fc = new JFileChooser();
- }
-
- //Add a custom file filter and disable the default
- //(Accept All) file filter.
- fc.addChoosableFileFilter(new ImageFilter());
- fc.setAcceptAllFileFilterUsed(false);
-
- //Add custom icons for file types.
- fc.setFileView(new ImageFileView());
-
- //Add the preview pane.
- fc.setAccessory(new ImagePreview(fc));
-
- //Show it. "選択"
- int returnVal = fc.showDialog(this, i18n.getString("dialog.select"));
-
- //Process the results.
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- File file = fc.getSelectedFile();
- arg2_baseTimeImg.argField.setText(file.getName());
- }
-
- //Reset the file chooser for the next time it's shown.
- fc.setSelectedFile(null);
- }
-
/** Returns an ImageIcon, or null if the path was invalid.
* @param path
* @return */
doButton.setEnabled(false);
String[] argv = new String[0];
- /*
- argv[0] = arg1_srcFolder.getText();
- argv[1] = arg2_baseTimeImg.getText();
- argv[2] = arg3_basetiome.getText();
- argv[3] = arg5_outputFolder.getText();
- argv[4] = arg4_gpxFolder.getText();
- */
this.params.setProperty(AppParameters.GPX_NO_FIRST_NODE, String.valueOf(noFirstNode.isSelected()));
this.params.setProperty(AppParameters.GPX_REUSE, String.valueOf(gpxReuse.isSelected()));
this.params.setProperty(AppParameters.GPX_SOURCE_FOLDER, arg4_gpxFolder.getText());
-
+ /*
if (exifBase.isSelected()) {
this.params.setProperty(AppParameters.GPX_BASETIME, "EXIF_TIME");
}
else {
this.params.setProperty(AppParameters.GPX_BASETIME, "FILE_UPDATE");
}
+ */
try {
this.params.setProperty(AppParameters.IMG_SOURCE_FOLDER, arg1_srcFolder.getText());
this.params.setProperty(AppParameters.IMG_BASE_FILE, arg2_baseTimeImg.getText());
e.printStackTrace();
}
- (new DoDialog(this, argv)).setVisible(true);
+ (new DoDialog(argv)).setVisible(true);
doButton.setEnabled(true);
}