diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/AdjustTerra.java b/src/main/java/osm/jp/gpx/matchtime/gui/AdjustTerra.java index d7f45df..71851be 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/AdjustTerra.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/AdjustTerra.java @@ -7,6 +7,11 @@ import java.util.TimeZone; import javax.swing.*; import osm.jp.gpx.*; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelGpx; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelImageFile; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelOutput; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelSourceFolder; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelTime; /** * 本プログラムのメインクラス @@ -211,21 +216,6 @@ new SimpleCardListener(cards, cardPanel, 3, arg4_output) ); - // "IMGの変換をする" - arg4_output.addCheckChangeImage(i18n.getString("label.510"), params); - - // "GPXファイル時間外のファイルもコピーする" - arg4_output.addCheckOutofGpxTime(i18n.getString("label.520"), params); - - // "EXIFの変換をする" - arg4_output.addCheckOutputExif(i18n.getString("label.540"), params); - - // "ソースGPXのを無視する" - arg4_output.addCheckIgnoreMagvar(i18n.getString("label.560"), params); - - // "出力GPXに[SPEED]を上書きする" - arg4_output.addCheckOutputSpeed(i18n.getString("label.570"), params); - // パネル表示 CardExifPerform card = new CardExifPerform( cardPanel, diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/CardExifPerform.java b/src/main/java/osm/jp/gpx/matchtime/gui/CardExifPerform.java index 2c79270..a094c77 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/CardExifPerform.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/CardExifPerform.java @@ -1,7 +1,6 @@ package osm.jp.gpx.matchtime.gui; import java.awt.BorderLayout; -import java.awt.event.ActionEvent; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JLabel; @@ -9,6 +8,13 @@ import javax.swing.JTabbedPane; import osm.jp.gpx.AppParameters; import osm.jp.gpx.ImportPicture; +import osm.jp.gpx.matchtime.gui.parameters.PanelAction; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelFolder; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelGpx; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelImageFile; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelOutput; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelTime; + import static osm.jp.gpx.matchtime.gui.AdjustTerra.dfjp; import static osm.jp.gpx.matchtime.gui.AdjustTerra.i18n; @@ -16,7 +22,7 @@ * 実行パネル * @author yuu */ -public class CardExifPerform extends Card implements PanelAction { +public class CardExifPerform extends Card implements PanelAction { private static final long serialVersionUID = 8902284630791931118L; ParameterPanelTime arg_basetime; // 画像の基準時刻: ParameterPanelGpx arg_gpxFile; // GPX file or Folder @@ -65,34 +71,12 @@ argsPanel.add(packLine(label5, new JPanel())); // 出力フォルダ - //argsPanel.add(packLine(new JLabel(i18n.getString("label.530")), new JPanel())); argsPanel.add(arg_output); - - // チェックボックス "IMGの変換をする" - if (arg_output.outputIMG != null) { - arg_output.outputIMG.addActionListener(lSymAction); - argsPanel.add(arg_output.outputIMG); - } - - // チェックボックス "IMGの変換をする" - if (arg_output.outputIMG_all != null) { - argsPanel.add(arg_output.outputIMG_all); - } - - // チェックボックス "EXIFの変換をする" - if (arg_output.exifON != null) { - argsPanel.add(arg_output.exifON); - } - - // チェックボックス "ソースGPXのを無視する" - if (arg_output.gpxOverwriteMagvar != null) { - argsPanel.add(arg_output.gpxOverwriteMagvar); - } - - // チェックボックス "出力GPXに[SPEED]を上書きする" - if (arg_output.gpxOutputSpeed != null) { - argsPanel.add(arg_output.gpxOutputSpeed); - } + argsPanel.add(arg_output.outputIMG); + argsPanel.add(arg_output.outputIMG_all); + argsPanel.add(arg_output.exifON); + argsPanel.add(arg_output.gpxOverwriteMagvar); + argsPanel.add(arg_output.gpxOutputSpeed); // [処理実行]ボタン doButton = new JButton( @@ -115,30 +99,17 @@ if (object == doButton) { doButton_Action(event); } - else if (object == arg_output.outputIMG) { - outputIMG_Action(event); - } } } /** - * checkbox[IMG変換]を変更した場合のアクション - * ON ー> IMG出力フォルダのフィールドを有効にする - * OFF -> IMG出力フォルダのフィールドを無効にする - * @param event - */ - void outputIMG_Action (ActionEvent event) { - setEnabled(isEnabled()); - } - - /** * [実行]ボタンをクリックしたときの動作 * @param event */ void doButton_Action(java.awt.event.ActionEvent event) { doButton.setEnabled(false); - ParameterPanelImageFile arg_baseTimeImg = arg_basetime.imageFile; // 基準時刻画像 + ParameterPanelImageFile arg_baseTimeImg = arg_basetime.getImageFile(); // 基準時刻画像 ParameterPanelFolder arg_srcFolder = arg_baseTimeImg.paramDir; try { @@ -156,13 +127,13 @@ params.setProperty(AppParameters.IMG_BASE_FILE, arg_baseTimeImg.getText()); params.setProperty(AppParameters.IMG_TIME, ImportPicture.toUTCString(dfjp.parse(arg_basetime.getText()))); - params.setProperty(AppParameters.IMG_OUTPUT, String.valueOf(arg_output.outputIMG.isSelected())); - params.setProperty(AppParameters.IMG_OUTPUT_ALL, String.valueOf(arg_output.outputIMG_all.isSelected())); + params.setProperty(AppParameters.IMG_OUTPUT, String.valueOf(arg_output.isUpdateImages())); + params.setProperty(AppParameters.IMG_OUTPUT_ALL, String.valueOf(arg_output.isUpdateImagesAtAll())); params.setProperty(AppParameters.IMG_OUTPUT_FOLDER, arg_output.getText()); - params.setProperty(AppParameters.IMG_OUTPUT_EXIF, String.valueOf(arg_output.exifON.isSelected())); - params.setProperty(AppParameters.GPX_OVERWRITE_MAGVAR, String.valueOf(arg_output.gpxOverwriteMagvar.isSelected())); - params.setProperty(AppParameters.GPX_OUTPUT_SPEED, String.valueOf(arg_output.gpxOutputSpeed.isSelected())); + params.setProperty(AppParameters.IMG_OUTPUT_EXIF, String.valueOf(arg_output.isUpdateExif())); + params.setProperty(AppParameters.GPX_OVERWRITE_MAGVAR, String.valueOf(arg_output.isUpdateMagvar())); + params.setProperty(AppParameters.GPX_OUTPUT_SPEED, String.valueOf(arg_output.isUpdateSpeed())); params.store(); } catch(Exception e) { diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/CardGpxFile.java b/src/main/java/osm/jp/gpx/matchtime/gui/CardGpxFile.java index 64d825b..1969d92 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/CardGpxFile.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/CardGpxFile.java @@ -6,6 +6,10 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; + +import osm.jp.gpx.matchtime.gui.parameters.PanelAction; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelGpx; + import static osm.jp.gpx.matchtime.gui.AdjustTerra.i18n; /** diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/CardImageFile.java b/src/main/java/osm/jp/gpx/matchtime/gui/CardImageFile.java index bedf12b..942e08a 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/CardImageFile.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/CardImageFile.java @@ -7,6 +7,11 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; + +import osm.jp.gpx.matchtime.gui.parameters.PanelAction; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelImageFile; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelTime; + import static osm.jp.gpx.matchtime.gui.AdjustTerra.i18n; /** diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/CardSourceFolder.java b/src/main/java/osm/jp/gpx/matchtime/gui/CardSourceFolder.java index a7ee4c5..52e7a20 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/CardSourceFolder.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/CardSourceFolder.java @@ -6,6 +6,9 @@ import javax.swing.JPanel; import javax.swing.JTabbedPane; +import osm.jp.gpx.matchtime.gui.parameters.PanelAction; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelFolder; + import static osm.jp.gpx.matchtime.gui.AdjustTerra.i18n; /** diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/DialogCorectTime.java b/src/main/java/osm/jp/gpx/matchtime/gui/DialogCorectTime.java deleted file mode 100644 index edab498..0000000 --- a/src/main/java/osm/jp/gpx/matchtime/gui/DialogCorectTime.java +++ /dev/null @@ -1,229 +0,0 @@ -package osm.jp.gpx.matchtime.gui; - -import java.awt.BorderLayout; -import java.awt.Dialog; -import java.awt.GridLayout; -import java.awt.Image; -import java.awt.Rectangle; -import java.awt.Window; -import javax.swing.BoxLayout; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; - -import osm.jp.gpx.AppParameters; - -import static osm.jp.gpx.matchtime.gui.AdjustTerra.createImageIcon; -import static osm.jp.gpx.matchtime.gui.AdjustTerra.i18n; - -/** - * [基準画像(開始)]選択パネル - * @author yuu - */ -public class DialogCorectTime extends JDialog implements PanelAction { - private static final long serialVersionUID = -3573167730473345932L; - public JPanel mainPanel; - ParameterPanelTime arg_basetime; // 開始画像の基準時刻(parent) - ParameterPanelTime basetime; // 開始画像の基準時刻(tempolarry) - java.awt.Button closeButton; - JButton expandButton; - JButton zoomInButton; - JButton zoomOutButton; - JLabel imageLabel; // 開始画像の基準時刻画像表示 - JScrollPane imageSPane; // スクロールパネル - - /** - * コンストラクタ - * @param arg3_basetime 開始画像の基準時刻: - * @param owner - */ - public DialogCorectTime(ParameterPanelTime arg3_basetime, Window owner) { - super(owner, AdjustTerra.i18n.getString("tab.restamp.300"), Dialog.ModalityType.DOCUMENT_MODAL); - this.arg_basetime = arg3_basetime; - - // INIT_CONTROLS - setLayout(new BorderLayout()); - setSize( - getInsets().left + getInsets().right + 720, - getInsets().top + getInsets().bottom + 480 - ); - - //---- CENTER ----- - JPanel centerPanel = new JPanel(); - centerPanel.setLayout(new BorderLayout()); - add(centerPanel, BorderLayout.CENTER); - - //---- CENTER.NORTH ----- - JPanel argsPanel; // パラメータ設定パネル (上部) - argsPanel = new JPanel(); - argsPanel.setLayout(new GridLayout(2, 1)); - - // 3. 正確な撮影時刻を入力してください。 - // カメラの時計が正確ならば、設定を変更する必要はありません。 - JLabel label3 = new JLabel(); - label3.setText(i18n.getString("label.300")); - argsPanel.add(label3); - - basetime = new ParameterPanelTime( - AppParameters.IMG_TIME, - arg_basetime.argLabel.getText(), - "", - arg_basetime.getImageFile() - ); - basetime.updateButton.setVisible(false); - basetime.resetButton.setVisible(true); - argsPanel.add(basetime); - centerPanel.add(argsPanel, BorderLayout.NORTH); - - //---- CENTER.CENTER ----- - // 参考画像 - imageLabel = new JLabel(); - imageSPane = new JScrollPane(imageLabel); - centerPanel.add(imageSPane, BorderLayout.CENTER); - - //---- CENTER.SOUTH ----- - // 画像ファイル選択ダイアログを起動するボタン - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); - expandButton = new JButton(createImageIcon("/images/Fit16.gif")); - buttonPanel.add(expandButton); - zoomInButton = new JButton(createImageIcon("/images/ZoomIn16.gif")); - buttonPanel.add(zoomInButton); - zoomOutButton = new JButton(createImageIcon("/images/ZoomOut16.gif")); - buttonPanel.add(zoomOutButton); - centerPanel.add(buttonPanel, BorderLayout.SOUTH); - - //---- SOUTH ----- - closeButton = new java.awt.Button(); - closeButton.setLabel(i18n.getString("button.close") ); - closeButton.setBounds(145,65,66,27); - add(closeButton, BorderLayout.SOUTH); - - // 選択された画像ファイルを表示する - imageView_Action(); - - //{{REGISTER_LISTENERS - SymWindow aSymWindow = new SymWindow(); - this.addWindowListener(aSymWindow); - SymAction lSymAction = new SymAction(); - closeButton.addActionListener(lSymAction); - expandButton.addActionListener(lSymAction); - zoomInButton.addActionListener(lSymAction); - zoomOutButton.addActionListener(lSymAction); - //}} - } - - class SymWindow extends java.awt.event.WindowAdapter - { - @Override - public void windowClosing(java.awt.event.WindowEvent event) { - Object object = event.getSource(); - if (object == DialogCorectTime.this) { - dialog_WindowClosing(); - } - } - } - - class SymAction implements java.awt.event.ActionListener - { - @Override - public void actionPerformed(java.awt.event.ActionEvent event) { - Object object = event.getSource(); - if (object == closeButton) { - dialog_WindowClosing(); - } - else if (object == expandButton) { - imageView_Action(); - } - else if (object == zoomInButton) { - zoomin_Action(); - } - else if (object == zoomOutButton) { - zoomout_Action(); - } - } - } - - ImageIcon refImage; - - /** - * 選択された画像ファイルを表示する - * 基準画像ボタンがクリックされた時に、基準時刻フィールドに基準画像の作成日時を設定する。 - */ - public void imageView_Action() { - try { - String path = basetime.getImageFile().getImageFile().getAbsolutePath(); - - // View Image File - 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); - } - catch(NullPointerException e) { - // 何もしない - } - repaint(); - } - - public void zoomin_Action() { - if (refImage != null) { - int size_x = imageLabel.getWidth(); - String path = basetime.getImageFile().getImageFile().getAbsolutePath(); - 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() { - 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(); - } - } - - /** - * ダイアログが閉じられるときのアクション - */ - void dialog_WindowClosing() { - String workStr = basetime.getText(); - arg_basetime.setText(workStr); - dispose(); - } - - @Override - public void setVisible(boolean b) { - if(b) { - Rectangle bounds = getParent().getBounds(); - Rectangle abounds = getBounds(); - setLocation(bounds.x + (bounds.width - abounds.width)/ 2, - bounds.y + (bounds.height - abounds.height)/2); - } - super.setVisible(b); - } - - @Override - public void openAction() { - ; // 何もしない - } - - /** - * 入力条件が満たされているかどうか - * @return - */ - @Override - public boolean isEnable() { - return this.basetime.isEnable(); - } -} diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/PanelAction.java b/src/main/java/osm/jp/gpx/matchtime/gui/PanelAction.java deleted file mode 100644 index 88085dc..0000000 --- a/src/main/java/osm/jp/gpx/matchtime/gui/PanelAction.java +++ /dev/null @@ -1,11 +0,0 @@ -package osm.jp.gpx.matchtime.gui; - -public interface PanelAction { - void openAction(); - - /** - * 入力条件が満たされているかどうか - * @return - */ - boolean isEnable(); -} diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ParamAction.java b/src/main/java/osm/jp/gpx/matchtime/gui/ParamAction.java deleted file mode 100644 index 558fb4c..0000000 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParamAction.java +++ /dev/null @@ -1,9 +0,0 @@ -package osm.jp.gpx.matchtime.gui; - -public interface ParamAction { - boolean isEnable(); - void setText(String text); - String getText(); - void setName(String name); - String getName(); -} diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanel.java b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanel.java deleted file mode 100644 index 13ed4fe..0000000 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanel.java +++ /dev/null @@ -1,101 +0,0 @@ -package osm.jp.gpx.matchtime.gui; - -import java.awt.Dimension; -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.ResourceBundle; - -import javax.swing.BoxLayout; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.event.DocumentEvent; - -/** - * パラメータを設定する為のパネル。 - * この1インスタンスで、1パラメータをあらわす。 - */ -public abstract class ParameterPanel extends JPanel implements PropertyChangeListener { - private static final long serialVersionUID = 4629824800747170556L; - public String propertyName; - public JTextField argField; - public JLabel argLabel; - public ResourceBundle i18n = ResourceBundle.getBundle("i18n"); - private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - - public ParameterPanel(String name, String label, String text) { - this(); - this.setName(name); - this.setLabel(label); - this.setText(text); - } - - ParameterPanel() { - super(); - propertyName = ""; - argLabel = new JLabel(); - argField = new JTextField(); - - this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); - this.setMaximumSize(new Dimension(1920, 40)); - this.add(argLabel); - this.add(argField); - - // 'argField' ’が変更されたら、「update イベントを発火させる - this.argField.getDocument().addDocumentListener( - new SimpleDocumentListener() { - @Override - public void update(DocumentEvent e) { - pcs.firePropertyChange(getName(), "", argField.getText()); - } - } - ); - } - - public ParameterPanel setLabel(String label) { - this.argLabel.setText(label); - return this; - } - - public void addActionListener(ActionListener l) { - this.argField.addActionListener(l); - } - - @Override - public void addPropertyChangeListener(PropertyChangeListener listener) { - this.pcs.addPropertyChangeListener(listener); - } - - @Override - public void removePropertyChangeListener(PropertyChangeListener listener) { - this.pcs.removePropertyChangeListener(listener); - } - - public abstract boolean isEnable(); - - @Override - public void setName(String name) { - this.propertyName = name; - } - - @Override - public String getName() { - return this.propertyName; - } - - public void setText(String text) { - this.argField.setText(text); - } - - public String getText() { - return this.argField.getText(); - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - // TODO Auto-generated method stub - - } -} diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java deleted file mode 100644 index 52721dd..0000000 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java +++ /dev/null @@ -1,116 +0,0 @@ -package osm.jp.gpx.matchtime.gui; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.io.File; -import java.io.FileNotFoundException; -import javax.swing.JButton; -import javax.swing.JFileChooser; - -@SuppressWarnings("serial") -public abstract class ParameterPanelFolder extends ParameterPanel implements ActionListener -{ - JFileChooser fc; - JButton selectButton; - int chooser; - - /** - * コンストラクタ - * ディレクトリのみ選択可能なダイアログ - * @param label - * @param text - */ - public ParameterPanelFolder(String name, String label, String text) { - this(name, label, text, JFileChooser.DIRECTORIES_ONLY); - } - - public ParameterPanelFolder(String name, String label, String text, int chooser) { - super(name, label, text); - - // Create a file chooser - this.chooser = chooser; - - // "選択..." - selectButton = new JButton( - i18n.getString("button.select"), - AdjustTerra.createImageIcon("/images/Open16.gif") - ); - selectButton.addActionListener(this); - this.add(selectButton); - } - - public void setEnable(boolean f) { - super.setEnabled(f); - selectButton.setEnabled(f); - } - - public File getDirectory() throws FileNotFoundException { - String path = this.argField.getText(); - if (path == null) { - throw new FileNotFoundException("Folder is Not specifiyed yet."); - } - File sdir = new File(path); - if (!sdir.exists()) { - throw new FileNotFoundException(String.format("Folder '%s' is Not exists.", path)); - } - if (!sdir.isDirectory()) { - throw new FileNotFoundException(String.format("Folder '%s' is Not directory.", path)); - } - return sdir; - } - - /** - * 有効な値が設定されているかどうか - * - * @return [folder.text=有効なディレクトリを示している] - */ - @Override - public boolean isEnable() { - String text = this.argField.getText(); - if (text == null) { - return false; - } - try { - getDirectory(); - return true; - } - catch (Exception e) { - return false; - } - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - // TODO Auto-generated method stub - - } - - @Override - public void actionPerformed(ActionEvent e) { - if (e.getSource() == selectButton){ - File sdir; - try { - sdir = getDirectory(); - } catch (FileNotFoundException ex) { - sdir = new File("."); - this.argField.setText(sdir.getAbsolutePath()); - } - if (sdir.exists()) { - this.fc = new JFileChooser(sdir); - } - else { - this.fc = new JFileChooser(); - } - this.fc.setFileSelectionMode(this.chooser); - - int returnVal = this.fc.showOpenDialog(ParameterPanelFolder.this); - - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = this.fc.getSelectedFile(); - String text = file.getAbsolutePath(); - this.argField.setText(text); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelGpx.java b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelGpx.java deleted file mode 100644 index f51b730..0000000 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelGpx.java +++ /dev/null @@ -1,117 +0,0 @@ -package osm.jp.gpx.matchtime.gui; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.io.File; - -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JFileChooser; -import osm.jp.gpx.AppParameters; - -@SuppressWarnings("serial") -public class ParameterPanelGpx extends ParameterPanel implements ActionListener -{ - JFileChooser fc; - JButton selectButton; - public JCheckBox noFirstNode; // CheckBox: "セグメント'trkseg'の最初の1ノードは無視する。" - - /** - * コンストラクタ - * @param label - * @param text - */ - public ParameterPanelGpx(String name, String label, String text) { - super(name, label, text); - - // "選択..." - selectButton = new JButton( - i18n.getString("button.select"), - AdjustTerra.createImageIcon("/images/Open16.gif") - ); - selectButton.addActionListener(this); - this.add(selectButton); - } - - @Override - public void actionPerformed(ActionEvent e) { - if (e.getSource() == selectButton){ - System.out.println("ParameterPanelGpx.actionPerformed(openButton)"); - File sdir = new File(this.argField.getText()); - if (sdir.exists()) { - this.fc = new JFileChooser(sdir); - } - else { - this.fc = new JFileChooser(); - } - this.fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); - this.fc.addChoosableFileFilter(new GpxAndFolderFilter()); - this.fc.setAcceptAllFileFilterUsed(false); - - int returnVal = this.fc.showOpenDialog(ParameterPanelGpx.this); - - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = this.fc.getSelectedFile(); - this.argField.setText(file.getAbsolutePath()); - } - } - } - - public File getGpxFile() { - if (isEnable()) { - return new File(getText()); - } - return null; - } - - /** - * "セグメント'trkseg'の最初の1ノードは無視する。" - * @param label テキスト - * @param params プロパティ - */ - public void addNoFirstNode(String label, AppParameters params) { - boolean selected = false; - if (params.getProperty(AppParameters.GPX_NO_FIRST_NODE).equals("true")) { - selected = true; - } - noFirstNode = new JCheckBox(label, selected); - } - - public boolean isNoFirstNodeSelected() { - return (noFirstNode != null) && noFirstNode.isSelected(); - } - - /** - * このフィールドに有効な値が設定されているかどうか - * [ - * () - * ] - * @return - */ - @Override - public boolean isEnable() { - String text = this.argField.getText(); - if (text != null) { - File file = new File(text); - if (file.exists()) { - if (file.isFile()) { - String name = file.getName().toUpperCase(); - if (name.endsWith(".GPX")) { - return true; - } - } - else if (file.isDirectory()) { - return true; - } - } - } - return false; - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - // TODO Auto-generated method stub - - } -} diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java deleted file mode 100644 index a8d0847..0000000 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java +++ /dev/null @@ -1,139 +0,0 @@ -package osm.jp.gpx.matchtime.gui; - -import java.awt.event.ActionEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.io.FileNotFoundException; -import java.util.Arrays; -import java.util.Comparator; - -import javax.swing.JButton; -import javax.swing.JFileChooser; - -@SuppressWarnings("serial") -public class ParameterPanelImageFile extends ParameterPanel { - JFileChooser fc; - public JButton openButton; - public ParameterPanelSourceFolder paramDir; - - public ParameterPanelImageFile( - String name, String label, String text, - ParameterPanelSourceFolder paramDir - ) { - super(name, label, text); - - // "選択..." - SelectButtonAction buttonAction = new SelectButtonAction(); - openButton = new JButton(i18n.getString("button.select")); - openButton.addActionListener(buttonAction); - this.add(openButton); - - //Create a file chooser - this.paramDir = paramDir; - this.paramDir.addPropertyChangeListener(new SourceFolderChangeListener()); - } - - /** - * Action : Update 'arg2_baseTimeImg' - * - */ - class SourceFolderChangeListener implements PropertyChangeListener { - @Override - public void propertyChange(PropertyChangeEvent arg0) { - if (paramDir.isEnable()) { - try { - File dir = paramDir.getDirectory(); - File[] files = dir.listFiles(new ImageFileFilter()); - if (files != null) { - Arrays.sort(files, new Comparator() { - public int compare(File file1, File file2){ - return file1.getName().compareTo(file2.getName()); - } - }); - if (files.length > 0) { - argField.setText(files[0].getName()); - fc = new JFileChooser(dir); - fc.setSelectedFile(files[0]); - return; - } - } - } catch (FileNotFoundException e) {} - } - argField.setText(""); - fc = new JFileChooser(); - fc.setSelectedFile(null); - } - } - - class SelectButtonAction implements java.awt.event.ActionListener - { - public void actionPerformed(ActionEvent e) { - File sdir = new File(paramDir.getText()); - System.out.println(sdir.toPath()); - if (sdir.isDirectory()) { - fc = new JFileChooser(sdir); - } - else { - fc = new JFileChooser(); - } - - fc.addChoosableFileFilter(new ImageFilter()); - fc.setAcceptAllFileFilterUsed(false); - fc.setFileView(new ImageFileView()); - fc.setAccessory(new ImagePreview(fc)); - - //Show it. "選択" - int returnVal = fc.showDialog(ParameterPanelImageFile.this, i18n.getString("dialog.select")); - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = fc.getSelectedFile(); - argField.setText(file.getName()); - } - else { - fc.setSelectedFile(null); - } - } - } - - public File getImageFile() { - if (this.paramDir.isEnable()) { - String text = this.argField.getText(); - if (text != null) { - try { - File dir = this.paramDir.getDirectory(); - File file = new File(dir, text); - if (file.exists() && file.isFile()) { - return file; - } - } - catch (FileNotFoundException e) { - return null; - } - } - } - return null; - } - - @Override - public boolean isEnable() { - if (this.paramDir.isEnable()) { - String text = this.argField.getText(); - if (text != null) { - try { - File dir = this.paramDir.getDirectory(); - File file = new File(dir, text); - if (file.exists() && file.isFile()) { - String name = file.getName().toUpperCase(); - if (name.endsWith(".JPG") || name.endsWith(".JPEG")) { - return true; - } - } - } - catch (FileNotFoundException e) { - return false; - } - } - } - return false; - } -} \ No newline at end of file diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelOutput.java b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelOutput.java deleted file mode 100644 index 33baf6e..0000000 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelOutput.java +++ /dev/null @@ -1,108 +0,0 @@ -package osm.jp.gpx.matchtime.gui; - -import javax.swing.JCheckBox; -import javax.swing.JFileChooser; -import osm.jp.gpx.AppParameters; - -@SuppressWarnings("serial") -public class ParameterPanelOutput extends ParameterPanelFolder -{ - JCheckBox outputIMG; // IMGの変換 する/しない - JCheckBox outputIMG_all; // 'out of GPX time'でもIMGの変換をする {ON | OFF} - JCheckBox exifON; // EXIF 書き出しモード / !(EXIFの書き換えはしない) - JCheckBox gpxOverwriteMagvar; // ソースGPXのを無視する - JCheckBox gpxOutputSpeed; // GPXにを書き出す - - /** - * コンストラクタ - * ディレクトリのみ選択可能なダイアログ - * @param label - * @param text - */ - public ParameterPanelOutput(String name, String label, String text) { - super(name, label, text, JFileChooser.DIRECTORIES_ONLY); - } - - /** - * チェックボックス "IMGの変換をする" - * @param label テキスト - * @param params プロパティ - */ - public void addCheckChangeImage(String label, AppParameters params) { - boolean selected = false; - if (params.getProperty(AppParameters.IMG_OUTPUT).equals("true")) { - selected = true; - } - outputIMG = new JCheckBox(label, selected); - } - - /** - * チェックボックス "GPXファイル時間外のファイルもコピーする" - * @param label - * @param params - */ - public void addCheckOutofGpxTime(String label, AppParameters params) { - boolean selected = false; - if (params.getProperty(AppParameters.IMG_OUTPUT_ALL).equals("true")) { - selected = true; - } - outputIMG_all = new JCheckBox(label, selected); - } - - /** - * チェックボックス "EXIFの変換をする" - * @param label - * @param params - */ - public void addCheckOutputExif(String label, AppParameters params) { - boolean selected = false; - if (params.getProperty(AppParameters.IMG_OUTPUT_EXIF).equals("true")) { - selected = true; - } - exifON = new JCheckBox(label, selected); - } - - /** - * チェックボックス "ソースGPXの<MAGVAR>を無視する" - * @param label - * @param params - */ - public void addCheckIgnoreMagvar(String label, AppParameters params) { - boolean selected = false; - if (params.getProperty(AppParameters.GPX_OVERWRITE_MAGVAR).equals("true")) { - selected = true; - } - gpxOverwriteMagvar = new JCheckBox(label, selected); - gpxOverwriteMagvar.setEnabled(true); - } - - /** - * チェックボックス "出力GPXに[SPEED]を上書きする" - * @param label - * @param params - */ - public void addCheckOutputSpeed(String label, AppParameters params) { - boolean selected = false; - if (params.getProperty(AppParameters.GPX_OUTPUT_SPEED).equals("true")) { - selected = true; - } - gpxOutputSpeed = new JCheckBox(label, selected); - gpxOutputSpeed.setEnabled(true); - } - - /** - * checkbox[IMG変換]を変更した場合のアクション - * ON ー> IMG出力フォルダのフィールドを有効にする - * OFF -> IMG出力フォルダのフィールドを無効にする - * @param event - */ - class ChangeImageAction implements java.awt.event.ActionListener { - @Override - public void actionPerformed(java.awt.event.ActionEvent event) { - Object object = event.getSource(); - if (object == outputIMG) { - setEnabled(outputIMG.isEnabled()); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelSelecter.java b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelSelecter.java deleted file mode 100644 index 251710f..0000000 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelSelecter.java +++ /dev/null @@ -1,44 +0,0 @@ -package osm.jp.gpx.matchtime.gui; - -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; - -@SuppressWarnings("serial") -public class ParameterPanelSelecter extends JPanel implements ActionListener { - public static final int ITEM_WIDTH_1 = 160; - public static final int ITEM_WIDTH_2 = 240; - public static final int LINE_WIDTH = ITEM_WIDTH_1 + ITEM_WIDTH_2; - public static final int LINE_HEIGHT = 18; - public JLabel label; - public JComboBox field; - public String value; - - public ParameterPanelSelecter(String title, String[] items) { - super(null); - this.value = items[0]; - - this.label = new JLabel(title, JLabel.RIGHT); - this.label.setBounds(0, 0, ITEM_WIDTH_1 - 6, LINE_HEIGHT); - add(this.label); - - this.field = new JComboBox<>(); - this.field.addActionListener(this); - for (String item : items) { - this.field.addItem(item); - } - this.field.setBounds(ITEM_WIDTH_1, 0, ITEM_WIDTH_2, LINE_HEIGHT); - add(this.field); - - setPreferredSize(new Dimension(ITEM_WIDTH_1, LINE_HEIGHT)); - } - - @Override - public void actionPerformed(ActionEvent e) { - this.value = (String)this.field.getSelectedItem(); - } -} \ No newline at end of file diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelSourceFolder.java b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelSourceFolder.java deleted file mode 100644 index 0f5cbfa..0000000 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelSourceFolder.java +++ /dev/null @@ -1,49 +0,0 @@ -package osm.jp.gpx.matchtime.gui; - -import java.io.File; -import java.io.FileNotFoundException; - -@SuppressWarnings("serial") -public class ParameterPanelSourceFolder extends ParameterPanelFolder -{ - /** - * コンストラクタ - * ディレクトリのみ選択可能なダイアログ - * @param label - * @param text - */ - public ParameterPanelSourceFolder(String name, String label, String text) { - super(name, label, text); - } - - /** - * 有効な値が設定されているかどうか - * [argField.getText() = 有効なディレクトリを示している] - * AND [folder is not empty.] - * AND [Image file exist in the folder.] - * @return - */ - @Override - public boolean isEnable() { - try { - File dir = super.getDirectory(); - File[] files = dir.listFiles(new ImageFileFilter()); - if ((files == null) || (files.length < 1)) { - return false; - } - return true; - } - catch (Exception e) { - return false; - } - } - - @Override - public File getDirectory() throws FileNotFoundException { - File dir = super.getDirectory(); - if (dir.exists() && dir.isDirectory()) { - return dir; - } - throw new FileNotFoundException(); - } -} \ No newline at end of file diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelTime.java b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelTime.java deleted file mode 100644 index b77d3cf..0000000 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelTime.java +++ /dev/null @@ -1,236 +0,0 @@ -package osm.jp.gpx.matchtime.gui; - -import java.awt.Window; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.io.IOException; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JRadioButton; - -import org.apache.commons.imaging.ImageReadException; -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.AppParameters; -import osm.jp.gpx.Restamp; -import static osm.jp.gpx.matchtime.gui.AdjustTerra.dfjp; - -/** - * パラメータを設定する為のパネル。 - * この1インスタンスで、1パラメータをあらわす。 - */ -public class ParameterPanelTime extends ParameterPanel implements ActionListener { - private static final long serialVersionUID = 1683226418990348336L; - SimpleDateFormat sdf = (SimpleDateFormat)DateFormat.getDateTimeInstance(); - ParameterPanelImageFile imageFile; // 基準時刻画像 - - - // 基準時刻の指定グループ (排他選択) - public ButtonGroup baseTimeGroup = new ButtonGroup(); - public JRadioButton exifBase = null; // EXIF日時を基準にする/ !(ファイル更新日時を基準にする) - public JRadioButton fupdateBase = null; // File更新日時を基準にする/ !(EXIF日時を基準にする) - - public JButton updateButton; - public JButton resetButton; - Window owner; - - public ParameterPanelTime( - String name, - String label, - String text, - ParameterPanelImageFile imageFile - ) { - super(name, label, text); - this.imageFile = imageFile; - this.imageFile.addPropertyChangeListener(new BaseTimeImgUpdateAction()); - - // "ボタン[変更...]" - UpdateButtonAction buttonAction = new UpdateButtonAction(this); - updateButton = new JButton(i18n.getString("button.update")); - updateButton.addActionListener(buttonAction); - this.add(updateButton); - - // "ボタン[再設定...]" - ResetButtonAction resetAction = new ResetButtonAction(this); - resetButton = new JButton(i18n.getString("button.reset")); - resetButton.addActionListener(resetAction); - resetButton.setVisible(false); - this.add(resetButton); - } - - public ParameterPanelTime setOwner(Window owner) { - this.owner = owner; - return this; - } - - /** - * 「EXIFの日時を基準にする」 - * @param label テキスト - * @param params プロパティ - */ - public void addExifBase(String label, AppParameters params) { - boolean selected = false; - if (params.getProperty(AppParameters.GPX_BASETIME).equals("EXIF_TIME")) { - selected = true; - } - exifBase = new JRadioButton(label, selected); - baseTimeGroup.add(exifBase); - } - - /** - * 「File更新日時を基準にする」 - * @param label テキスト - * @param params プロパティ - */ - public void addFileUpdate(String label, AppParameters params) { - boolean selected = false; - if (params.getProperty(AppParameters.GPX_BASETIME).equals("FILE_UPDATE")) { - selected = true; - } - fupdateBase = new JRadioButton(label, selected); - baseTimeGroup.add(fupdateBase); - } - - public ParameterPanelImageFile getImageFile() { - return this.imageFile; - } - - /** - * Action : Update 'arg2_baseTimeImg' - * - */ - class BaseTimeImgUpdateAction implements PropertyChangeListener { - @Override - public void propertyChange(PropertyChangeEvent arg0) { - try { - String timeStr = getTimeStr(); - argField.setText(timeStr); - } catch (Exception e) { - argField.setText("Error : "+ e.toString()); - } - } - } - - /** - * [変更...]ボタンのアクション - */ - class UpdateButtonAction implements java.awt.event.ActionListener - { - ParameterPanelTime param; - - public UpdateButtonAction(ParameterPanelTime param) { - this.param = param; - } - - public void actionPerformed(ActionEvent e) { - fileSelect_Action(param); - (new DialogCorectTime(param, owner)).setVisible(true); - } - } - - /** - * [再設定...]ボタンのアクション - */ - class ResetButtonAction implements java.awt.event.ActionListener - { - ParameterPanelTime paramPanelTime; - - public ResetButtonAction(ParameterPanelTime param) { - this.paramPanelTime = param; - } - - public void actionPerformed(ActionEvent e) { - fileSelect_Action(paramPanelTime); - } - } - - /** - * 画像ファイルが選択されたときのアクション - * 1.ラジオボタンの選択を参照してTEXTフィールドにファイルの「日時」を設定する - * @param param - */ - void fileSelect_Action(ParameterPanelTime param) { - param.argField.setText(getTimeStr()); - } - - String getTimeStr() { - if (!imageFile.isEnable()) { - return "Error : ImageFile is not selected."; - } - - File timeFile = imageFile.getImageFile(); - - // Radio Selector - sdf.applyPattern(Restamp.TIME_PATTERN); - if ((exifBase != null) && 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 = sdf.parse(dateTimeOriginal).getTime(); - return (dfjp.format(new Date(lastModifyTime))); - } - else { - return ("Error : 'ExIF is null!'"); - } - } - else { - return "Error : "; - } - } - catch (IOException | ParseException | ImageReadException ex) { - return "Error : "+ ex.toString(); - } - } - else { - long lastModified = timeFile.lastModified(); - return (sdf.format(new Date(lastModified))); - } - } - - @Override - public boolean isEnable() { - if (!this.imageFile.isEnable()) { - return false; - } - - String text = this.argField.getText(); - if (text == null) { - return false; - } - - try { - sdf.applyPattern(Restamp.TIME_PATTERN); - sdf.parse(text); - return true; - } - catch (ParseException e) { - return false; - } - } - - @Override - public void actionPerformed(ActionEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - // TODO Auto-generated method stub - - } -} diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/SimpleCardListener.java b/src/main/java/osm/jp/gpx/matchtime/gui/SimpleCardListener.java index f04db02..ac80b9b 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/SimpleCardListener.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/SimpleCardListener.java @@ -6,6 +6,7 @@ import javax.swing.JTabbedPane; import osm.jp.gpx.AppParameters; +import osm.jp.gpx.matchtime.gui.parameters.ParameterPanel; public class SimpleCardListener implements PropertyChangeListener { int cardNo; diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/SimpleDocumentListener.java b/src/main/java/osm/jp/gpx/matchtime/gui/SimpleDocumentListener.java deleted file mode 100644 index 735c6ee..0000000 --- a/src/main/java/osm/jp/gpx/matchtime/gui/SimpleDocumentListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package osm.jp.gpx.matchtime.gui; - -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; - -@FunctionalInterface -public interface SimpleDocumentListener extends DocumentListener { - void update(DocumentEvent e); - - @Override - default void insertUpdate(DocumentEvent e) { - update(e); - } - - @Override - default void removeUpdate(DocumentEvent e) { - update(e); - } - - @Override - default void changedUpdate(DocumentEvent e) { - update(e); - } -} - diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/parameters/DialogCorectTime.java b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/DialogCorectTime.java new file mode 100644 index 0000000..fc7169d --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/DialogCorectTime.java @@ -0,0 +1,230 @@ +package osm.jp.gpx.matchtime.gui.parameters; + +import java.awt.BorderLayout; +import java.awt.Dialog; +import java.awt.GridLayout; +import java.awt.Image; +import java.awt.Rectangle; +import java.awt.Window; +import javax.swing.BoxLayout; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +import osm.jp.gpx.AppParameters; +import osm.jp.gpx.matchtime.gui.AdjustTerra; + +import static osm.jp.gpx.matchtime.gui.AdjustTerra.createImageIcon; +import static osm.jp.gpx.matchtime.gui.AdjustTerra.i18n; + +/** + * [基準画像(開始)]選択パネル + * @author yuu + */ +public class DialogCorectTime extends JDialog implements PanelAction { + private static final long serialVersionUID = -3573167730473345932L; + public JPanel mainPanel; + ParameterPanelTime arg_basetime; // 開始画像の基準時刻(parent) + ParameterPanelTime basetime; // 開始画像の基準時刻(tempolarry) + java.awt.Button closeButton; + JButton expandButton; + JButton zoomInButton; + JButton zoomOutButton; + JLabel imageLabel; // 開始画像の基準時刻画像表示 + JScrollPane imageSPane; // スクロールパネル + + /** + * コンストラクタ + * @param arg3_basetime 開始画像の基準時刻: + * @param owner + */ + public DialogCorectTime(ParameterPanelTime arg3_basetime, Window owner) { + super(owner, AdjustTerra.i18n.getString("tab.restamp.300"), Dialog.ModalityType.DOCUMENT_MODAL); + this.arg_basetime = arg3_basetime; + + // INIT_CONTROLS + setLayout(new BorderLayout()); + setSize( + getInsets().left + getInsets().right + 720, + getInsets().top + getInsets().bottom + 480 + ); + + //---- CENTER ----- + JPanel centerPanel = new JPanel(); + centerPanel.setLayout(new BorderLayout()); + add(centerPanel, BorderLayout.CENTER); + + //---- CENTER.NORTH ----- + JPanel argsPanel; // パラメータ設定パネル (上部) + argsPanel = new JPanel(); + argsPanel.setLayout(new GridLayout(2, 1)); + + // 3. 正確な撮影時刻を入力してください。 + // カメラの時計が正確ならば、設定を変更する必要はありません。 + JLabel label3 = new JLabel(); + label3.setText(i18n.getString("label.300")); + argsPanel.add(label3); + + basetime = new ParameterPanelTime( + AppParameters.IMG_TIME, + arg_basetime.argLabel.getText(), + "", + arg_basetime.getImageFile() + ); + basetime.updateButton.setVisible(false); + basetime.resetButton.setVisible(true); + argsPanel.add(basetime); + centerPanel.add(argsPanel, BorderLayout.NORTH); + + //---- CENTER.CENTER ----- + // 参考画像 + imageLabel = new JLabel(); + imageSPane = new JScrollPane(imageLabel); + centerPanel.add(imageSPane, BorderLayout.CENTER); + + //---- CENTER.SOUTH ----- + // 画像ファイル選択ダイアログを起動するボタン + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); + expandButton = new JButton(createImageIcon("/images/Fit16.gif")); + buttonPanel.add(expandButton); + zoomInButton = new JButton(createImageIcon("/images/ZoomIn16.gif")); + buttonPanel.add(zoomInButton); + zoomOutButton = new JButton(createImageIcon("/images/ZoomOut16.gif")); + buttonPanel.add(zoomOutButton); + centerPanel.add(buttonPanel, BorderLayout.SOUTH); + + //---- SOUTH ----- + closeButton = new java.awt.Button(); + closeButton.setLabel(i18n.getString("button.close") ); + closeButton.setBounds(145,65,66,27); + add(closeButton, BorderLayout.SOUTH); + + // 選択された画像ファイルを表示する + imageView_Action(); + + //{{REGISTER_LISTENERS + SymWindow aSymWindow = new SymWindow(); + this.addWindowListener(aSymWindow); + SymAction lSymAction = new SymAction(); + closeButton.addActionListener(lSymAction); + expandButton.addActionListener(lSymAction); + zoomInButton.addActionListener(lSymAction); + zoomOutButton.addActionListener(lSymAction); + //}} + } + + class SymWindow extends java.awt.event.WindowAdapter + { + @Override + public void windowClosing(java.awt.event.WindowEvent event) { + Object object = event.getSource(); + if (object == DialogCorectTime.this) { + dialog_WindowClosing(); + } + } + } + + class SymAction implements java.awt.event.ActionListener + { + @Override + public void actionPerformed(java.awt.event.ActionEvent event) { + Object object = event.getSource(); + if (object == closeButton) { + dialog_WindowClosing(); + } + else if (object == expandButton) { + imageView_Action(); + } + else if (object == zoomInButton) { + zoomin_Action(); + } + else if (object == zoomOutButton) { + zoomout_Action(); + } + } + } + + ImageIcon refImage; + + /** + * 選択された画像ファイルを表示する + * 基準画像ボタンがクリックされた時に、基準時刻フィールドに基準画像の作成日時を設定する。 + */ + public void imageView_Action() { + try { + String path = basetime.getImageFile().getImageFile().getAbsolutePath(); + + // View Image File + 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); + } + catch(NullPointerException e) { + // 何もしない + } + repaint(); + } + + public void zoomin_Action() { + if (refImage != null) { + int size_x = imageLabel.getWidth(); + String path = basetime.getImageFile().getImageFile().getAbsolutePath(); + 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() { + 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(); + } + } + + /** + * ダイアログが閉じられるときのアクション + */ + void dialog_WindowClosing() { + String workStr = basetime.getText(); + arg_basetime.setText(workStr); + dispose(); + } + + @Override + public void setVisible(boolean b) { + if(b) { + Rectangle bounds = getParent().getBounds(); + Rectangle abounds = getBounds(); + setLocation(bounds.x + (bounds.width - abounds.width)/ 2, + bounds.y + (bounds.height - abounds.height)/2); + } + super.setVisible(b); + } + + @Override + public void openAction() { + ; // 何もしない + } + + /** + * 入力条件が満たされているかどうか + * @return + */ + @Override + public boolean isEnable() { + return this.basetime.isEnable(); + } +} diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/parameters/PanelAction.java b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/PanelAction.java new file mode 100644 index 0000000..a29550e --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/PanelAction.java @@ -0,0 +1,11 @@ +package osm.jp.gpx.matchtime.gui.parameters; + +public interface PanelAction { + void openAction(); + + /** + * 入力条件が満たされているかどうか + * @return + */ + boolean isEnable(); +} diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParamAction.java b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParamAction.java new file mode 100644 index 0000000..7713ded --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParamAction.java @@ -0,0 +1,9 @@ +package osm.jp.gpx.matchtime.gui.parameters; + +public interface ParamAction { + boolean isEnable(); + void setText(String text); + String getText(); + void setName(String name); + String getName(); +} diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanel.java b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanel.java new file mode 100644 index 0000000..0fc497e --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanel.java @@ -0,0 +1,101 @@ +package osm.jp.gpx.matchtime.gui.parameters; + +import java.awt.Dimension; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.ResourceBundle; + +import javax.swing.BoxLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; + +/** + * パラメータを設定する為のパネル。 + * この1インスタンスで、1パラメータをあらわす。 + */ +public abstract class ParameterPanel extends JPanel implements PropertyChangeListener { + private static final long serialVersionUID = 4629824800747170556L; + public String propertyName; + public JTextField argField; + public JLabel argLabel; + public ResourceBundle i18n = ResourceBundle.getBundle("i18n"); + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + + public ParameterPanel(String propertyName, String label, String text) { + this(); + this.setName(propertyName); + this.setLabel(label); + this.setText(text); + } + + ParameterPanel() { + super(); + propertyName = ""; + argLabel = new JLabel(); + argField = new JTextField(); + + this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); + this.setMaximumSize(new Dimension(1920, 40)); + this.add(argLabel); + this.add(argField); + + // 'argField' ’が変更されたら、「update イベントを発火させる + this.argField.getDocument().addDocumentListener( + new SimpleDocumentListener() { + @Override + public void update(DocumentEvent e) { + pcs.firePropertyChange(getName(), "", argField.getText()); + } + } + ); + } + + public ParameterPanel setLabel(String label) { + this.argLabel.setText(label); + return this; + } + + public void addActionListener(ActionListener l) { + this.argField.addActionListener(l); + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + this.pcs.addPropertyChangeListener(listener); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + this.pcs.removePropertyChangeListener(listener); + } + + public abstract boolean isEnable(); + + @Override + public void setName(String name) { + this.propertyName = name; + } + + @Override + public String getName() { + return this.propertyName; + } + + public void setText(String text) { + this.argField.setText(text); + } + + public String getText() { + return this.argField.getText(); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + // TODO Auto-generated method stub + + } +} diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelCheckbox.java b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelCheckbox.java new file mode 100644 index 0000000..c217d51 --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelCheckbox.java @@ -0,0 +1,14 @@ +package osm.jp.gpx.matchtime.gui.parameters; + +import javax.swing.JCheckBox; + +@SuppressWarnings("serial") +public class ParameterPanelCheckbox extends JCheckBox +{ + String paramname; + + public ParameterPanelCheckbox(String paramname, String label, boolean enable) { + super(label, enable); + this.paramname = paramname; + } +} \ No newline at end of file diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelFolder.java b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelFolder.java new file mode 100644 index 0000000..c9218db --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelFolder.java @@ -0,0 +1,118 @@ +package osm.jp.gpx.matchtime.gui.parameters; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.io.File; +import java.io.FileNotFoundException; +import javax.swing.JButton; +import javax.swing.JFileChooser; + +import osm.jp.gpx.matchtime.gui.AdjustTerra; + +@SuppressWarnings("serial") +public abstract class ParameterPanelFolder extends ParameterPanel implements ActionListener +{ + JFileChooser fc; + JButton selectButton; + int chooser; + + /** + * コンストラクタ + * ディレクトリのみ選択可能なダイアログ + * @param label + * @param text + */ + public ParameterPanelFolder(String name, String label, String text) { + this(name, label, text, JFileChooser.DIRECTORIES_ONLY); + } + + public ParameterPanelFolder(String name, String label, String text, int chooser) { + super(name, label, text); + + // Create a file chooser + this.chooser = chooser; + + // "選択..." + selectButton = new JButton( + i18n.getString("button.select"), + AdjustTerra.createImageIcon("/images/Open16.gif") + ); + selectButton.addActionListener(this); + this.add(selectButton); + } + + public void setEnable(boolean f) { + super.setEnabled(f); + selectButton.setEnabled(f); + } + + public File getDirectory() throws FileNotFoundException { + String path = this.argField.getText(); + if (path == null) { + throw new FileNotFoundException("Folder is Not specifiyed yet."); + } + File sdir = new File(path); + if (!sdir.exists()) { + throw new FileNotFoundException(String.format("Folder '%s' is Not exists.", path)); + } + if (!sdir.isDirectory()) { + throw new FileNotFoundException(String.format("Folder '%s' is Not directory.", path)); + } + return sdir; + } + + /** + * 有効な値が設定されているかどうか + * + * @return [folder.text=有効なディレクトリを示している] + */ + @Override + public boolean isEnable() { + String text = this.argField.getText(); + if (text == null) { + return false; + } + try { + getDirectory(); + return true; + } + catch (Exception e) { + return false; + } + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + // TODO Auto-generated method stub + + } + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == selectButton){ + File sdir; + try { + sdir = getDirectory(); + } catch (FileNotFoundException ex) { + sdir = new File("."); + this.argField.setText(sdir.getAbsolutePath()); + } + if (sdir.exists()) { + this.fc = new JFileChooser(sdir); + } + else { + this.fc = new JFileChooser(); + } + this.fc.setFileSelectionMode(this.chooser); + + int returnVal = this.fc.showOpenDialog(ParameterPanelFolder.this); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = this.fc.getSelectedFile(); + String text = file.getAbsolutePath(); + this.argField.setText(text); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelGpx.java b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelGpx.java new file mode 100644 index 0000000..e73dfde --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelGpx.java @@ -0,0 +1,119 @@ +package osm.jp.gpx.matchtime.gui.parameters; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.io.File; + +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JFileChooser; +import osm.jp.gpx.AppParameters; +import osm.jp.gpx.matchtime.gui.AdjustTerra; +import osm.jp.gpx.matchtime.gui.GpxAndFolderFilter; + +@SuppressWarnings("serial") +public class ParameterPanelGpx extends ParameterPanel implements ActionListener +{ + JFileChooser fc; + JButton selectButton; + public JCheckBox noFirstNode; // CheckBox: "セグメント'trkseg'の最初の1ノードは無視する。" + + /** + * コンストラクタ + * @param label + * @param text + */ + public ParameterPanelGpx(String name, String label, String text) { + super(name, label, text); + + // "選択..." + selectButton = new JButton( + i18n.getString("button.select"), + AdjustTerra.createImageIcon("/images/Open16.gif") + ); + selectButton.addActionListener(this); + this.add(selectButton); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == selectButton){ + System.out.println("ParameterPanelGpx.actionPerformed(openButton)"); + File sdir = new File(this.argField.getText()); + if (sdir.exists()) { + this.fc = new JFileChooser(sdir); + } + else { + this.fc = new JFileChooser(); + } + this.fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + this.fc.addChoosableFileFilter(new GpxAndFolderFilter()); + this.fc.setAcceptAllFileFilterUsed(false); + + int returnVal = this.fc.showOpenDialog(ParameterPanelGpx.this); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = this.fc.getSelectedFile(); + this.argField.setText(file.getAbsolutePath()); + } + } + } + + public File getGpxFile() { + if (isEnable()) { + return new File(getText()); + } + return null; + } + + /** + * "セグメント'trkseg'の最初の1ノードは無視する。" + * @param label テキスト + * @param params プロパティ + */ + public void addNoFirstNode(String label, AppParameters params) { + boolean selected = false; + if (params.getProperty(AppParameters.GPX_NO_FIRST_NODE).equals("true")) { + selected = true; + } + noFirstNode = new JCheckBox(label, selected); + } + + public boolean isNoFirstNodeSelected() { + return (noFirstNode != null) && noFirstNode.isSelected(); + } + + /** + * このフィールドに有効な値が設定されているかどうか + * [ + * () + * ] + * @return + */ + @Override + public boolean isEnable() { + String text = this.argField.getText(); + if (text != null) { + File file = new File(text); + if (file.exists()) { + if (file.isFile()) { + String name = file.getName().toUpperCase(); + if (name.endsWith(".GPX")) { + return true; + } + } + else if (file.isDirectory()) { + return true; + } + } + } + return false; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + // TODO Auto-generated method stub + + } +} diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelImageFile.java b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelImageFile.java new file mode 100644 index 0000000..fc7ee87 --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelImageFile.java @@ -0,0 +1,144 @@ +package osm.jp.gpx.matchtime.gui.parameters; + +import java.awt.event.ActionEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Arrays; +import java.util.Comparator; + +import javax.swing.JButton; +import javax.swing.JFileChooser; + +import osm.jp.gpx.matchtime.gui.ImageFileFilter; +import osm.jp.gpx.matchtime.gui.ImageFileView; +import osm.jp.gpx.matchtime.gui.ImageFilter; +import osm.jp.gpx.matchtime.gui.ImagePreview; + +@SuppressWarnings("serial") +public class ParameterPanelImageFile extends ParameterPanel { + JFileChooser fc; + public JButton openButton; + public ParameterPanelSourceFolder paramDir; + + public ParameterPanelImageFile( + String name, String label, String text, + ParameterPanelSourceFolder paramDir + ) { + super(name, label, text); + + // "選択..." + SelectButtonAction buttonAction = new SelectButtonAction(); + openButton = new JButton(i18n.getString("button.select")); + openButton.addActionListener(buttonAction); + this.add(openButton); + + //Create a file chooser + this.paramDir = paramDir; + this.paramDir.addPropertyChangeListener(new SourceFolderChangeListener()); + } + + /** + * Action : Update 'arg2_baseTimeImg' + * + */ + class SourceFolderChangeListener implements PropertyChangeListener { + @Override + public void propertyChange(PropertyChangeEvent arg0) { + if (paramDir.isEnable()) { + try { + File dir = paramDir.getDirectory(); + File[] files = dir.listFiles(new ImageFileFilter()); + if (files != null) { + Arrays.sort(files, new Comparator() { + public int compare(File file1, File file2){ + return file1.getName().compareTo(file2.getName()); + } + }); + if (files.length > 0) { + argField.setText(files[0].getName()); + fc = new JFileChooser(dir); + fc.setSelectedFile(files[0]); + return; + } + } + } catch (FileNotFoundException e) {} + } + argField.setText(""); + fc = new JFileChooser(); + fc.setSelectedFile(null); + } + } + + class SelectButtonAction implements java.awt.event.ActionListener + { + public void actionPerformed(ActionEvent e) { + File sdir = new File(paramDir.getText()); + System.out.println(sdir.toPath()); + if (sdir.isDirectory()) { + fc = new JFileChooser(sdir); + } + else { + fc = new JFileChooser(); + } + + fc.addChoosableFileFilter(new ImageFilter()); + fc.setAcceptAllFileFilterUsed(false); + fc.setFileView(new ImageFileView()); + fc.setAccessory(new ImagePreview(fc)); + + //Show it. "選択" + int returnVal = fc.showDialog(ParameterPanelImageFile.this, i18n.getString("dialog.select")); + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + argField.setText(file.getName()); + } + else { + fc.setSelectedFile(null); + } + } + } + + public File getImageFile() { + if (this.paramDir.isEnable()) { + String text = this.argField.getText(); + if (text != null) { + try { + File dir = this.paramDir.getDirectory(); + File file = new File(dir, text); + if (file.exists() && file.isFile()) { + return file; + } + } + catch (FileNotFoundException e) { + return null; + } + } + } + return null; + } + + @Override + public boolean isEnable() { + if (this.paramDir.isEnable()) { + String text = this.argField.getText(); + if (text != null) { + try { + File dir = this.paramDir.getDirectory(); + File file = new File(dir, text); + if (file.exists() && file.isFile()) { + String name = file.getName().toUpperCase(); + if (name.endsWith(".JPG") || name.endsWith(".JPEG")) { + return true; + } + } + } + catch (FileNotFoundException e) { + return false; + } + } + } + return false; + } +} \ No newline at end of file diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelOutput.java b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelOutput.java new file mode 100644 index 0000000..38b21cf --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelOutput.java @@ -0,0 +1,88 @@ +package osm.jp.gpx.matchtime.gui.parameters; + +import java.io.FileNotFoundException; +import java.io.IOException; +import javax.swing.JCheckBox; +import javax.swing.JFileChooser; +import javax.swing.JPanel; +import osm.jp.gpx.AppParameters; +import osm.jp.gpx.matchtime.gui.Card; + +@SuppressWarnings("serial") +public class ParameterPanelOutput extends ParameterPanelFolder +{ + public JCheckBox outputIMG; // IMGの変換 する/しない + public JCheckBox outputIMG_all; // 'out of GPX time'でもIMGの変換をする {ON | OFF} + public JCheckBox exifON; // EXIF 書き出しモード / !(EXIFの書き換えはしない) + public JCheckBox gpxOverwriteMagvar; // ソースGPXのを無視する + public JCheckBox gpxOutputSpeed; // GPXにを書き出す + + /** + * コンストラクタ + * ディレクトリのみ選択可能なダイアログ + * @param label + * @param text + * @throws IOException + * @throws FileNotFoundException + */ + public ParameterPanelOutput(String name, String label, String text) { + super(name, label, text, JFileChooser.DIRECTORIES_ONLY); + + //---- CENTER ----- + this.outputIMG = new JCheckBox(i18n.getString("label.510"), false); + this.outputIMG_all = new JCheckBox(i18n.getString("label.520"), false); + this.exifON = new JCheckBox(i18n.getString("label.540"), false); + this.gpxOverwriteMagvar = new JCheckBox(i18n.getString("label.560"), false); + this.gpxOutputSpeed = new JCheckBox(i18n.getString("label.570"), false); + + try { + AppParameters params = new AppParameters(); + + // チェックボックス "IMGの変換をする" + if (params.getProperty(AppParameters.IMG_OUTPUT).equals("true")) { + this.outputIMG.setEnabled(true); + } + + // チェックボックス "IMGの変換をする" + if (params.getProperty(AppParameters.IMG_OUTPUT_ALL).equals("true")) { + this.outputIMG_all.setEnabled(true); + } + + // チェックボックス "EXIFの変換をする" + if (params.getProperty(AppParameters.IMG_OUTPUT_EXIF).equals("true")) { + this.exifON.setEnabled(true); + } + + // チェックボックス "ソースGPXのを無視する" + if (params.getProperty(AppParameters.GPX_OVERWRITE_MAGVAR).equals("true")) { + this.gpxOverwriteMagvar.setEnabled(true); + } + + // チェックボックス "出力GPXに[SPEED]を上書きする" + if (params.getProperty(AppParameters.GPX_OUTPUT_SPEED).equals("true")) { + this.gpxOutputSpeed.setEnabled(true); + } + } + catch (Exception e) {} + } + + public boolean isUpdateImages() { + return outputIMG.isSelected(); + } + + public boolean isUpdateImagesAtAll() { + return outputIMG_all.isSelected(); + } + + public boolean isUpdateExif() { + return exifON.isSelected(); + } + + public boolean isUpdateMagvar() { + return gpxOverwriteMagvar.isSelected(); + } + + public boolean isUpdateSpeed() { + return gpxOutputSpeed.isSelected(); + } +} \ No newline at end of file diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelSelecter.java b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelSelecter.java new file mode 100644 index 0000000..1290515 --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelSelecter.java @@ -0,0 +1,44 @@ +package osm.jp.gpx.matchtime.gui.parameters; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; + +@SuppressWarnings("serial") +public class ParameterPanelSelecter extends JPanel implements ActionListener { + public static final int ITEM_WIDTH_1 = 160; + public static final int ITEM_WIDTH_2 = 240; + public static final int LINE_WIDTH = ITEM_WIDTH_1 + ITEM_WIDTH_2; + public static final int LINE_HEIGHT = 18; + public JLabel label; + public JComboBox field; + public String value; + + public ParameterPanelSelecter(String title, String[] items) { + super(null); + this.value = items[0]; + + this.label = new JLabel(title, JLabel.RIGHT); + this.label.setBounds(0, 0, ITEM_WIDTH_1 - 6, LINE_HEIGHT); + add(this.label); + + this.field = new JComboBox<>(); + this.field.addActionListener(this); + for (String item : items) { + this.field.addItem(item); + } + this.field.setBounds(ITEM_WIDTH_1, 0, ITEM_WIDTH_2, LINE_HEIGHT); + add(this.field); + + setPreferredSize(new Dimension(ITEM_WIDTH_1, LINE_HEIGHT)); + } + + @Override + public void actionPerformed(ActionEvent e) { + this.value = (String)this.field.getSelectedItem(); + } +} \ No newline at end of file diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelSourceFolder.java b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelSourceFolder.java new file mode 100644 index 0000000..63288d3 --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelSourceFolder.java @@ -0,0 +1,51 @@ +package osm.jp.gpx.matchtime.gui.parameters; + +import java.io.File; +import java.io.FileNotFoundException; + +import osm.jp.gpx.matchtime.gui.ImageFileFilter; + +@SuppressWarnings("serial") +public class ParameterPanelSourceFolder extends ParameterPanelFolder +{ + /** + * コンストラクタ + * ディレクトリのみ選択可能なダイアログ + * @param label + * @param text + */ + public ParameterPanelSourceFolder(String name, String label, String text) { + super(name, label, text); + } + + /** + * 有効な値が設定されているかどうか + * [argField.getText() = 有効なディレクトリを示している] + * AND [folder is not empty.] + * AND [Image file exist in the folder.] + * @return + */ + @Override + public boolean isEnable() { + try { + File dir = super.getDirectory(); + File[] files = dir.listFiles(new ImageFileFilter()); + if ((files == null) || (files.length < 1)) { + return false; + } + return true; + } + catch (Exception e) { + return false; + } + } + + @Override + public File getDirectory() throws FileNotFoundException { + File dir = super.getDirectory(); + if (dir.exists() && dir.isDirectory()) { + return dir; + } + throw new FileNotFoundException(); + } +} \ No newline at end of file diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelTime.java b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelTime.java new file mode 100644 index 0000000..806071a --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/ParameterPanelTime.java @@ -0,0 +1,237 @@ +package osm.jp.gpx.matchtime.gui.parameters; + +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.io.IOException; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JRadioButton; + +import org.apache.commons.imaging.ImageReadException; +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.AppParameters; +import osm.jp.gpx.Restamp; + +import static osm.jp.gpx.matchtime.gui.AdjustTerra.dfjp; + +/** + * パラメータを設定する為のパネル。 + * この1インスタンスで、1パラメータをあらわす。 + */ +public class ParameterPanelTime extends ParameterPanel implements ActionListener { + private static final long serialVersionUID = 1683226418990348336L; + SimpleDateFormat sdf = (SimpleDateFormat)DateFormat.getDateTimeInstance(); + ParameterPanelImageFile imageFile; // 基準時刻画像 + + + // 基準時刻の指定グループ (排他選択) + public ButtonGroup baseTimeGroup = new ButtonGroup(); + public JRadioButton exifBase = null; // EXIF日時を基準にする/ !(ファイル更新日時を基準にする) + public JRadioButton fupdateBase = null; // File更新日時を基準にする/ !(EXIF日時を基準にする) + + public JButton updateButton; + public JButton resetButton; + Window owner; + + public ParameterPanelTime( + String name, + String label, + String text, + ParameterPanelImageFile imageFile + ) { + super(name, label, text); + this.imageFile = imageFile; + this.imageFile.addPropertyChangeListener(new BaseTimeImgUpdateAction()); + + // "ボタン[変更...]" + UpdateButtonAction buttonAction = new UpdateButtonAction(this); + updateButton = new JButton(i18n.getString("button.update")); + updateButton.addActionListener(buttonAction); + this.add(updateButton); + + // "ボタン[再設定...]" + ResetButtonAction resetAction = new ResetButtonAction(this); + resetButton = new JButton(i18n.getString("button.reset")); + resetButton.addActionListener(resetAction); + resetButton.setVisible(false); + this.add(resetButton); + } + + public ParameterPanelTime setOwner(Window owner) { + this.owner = owner; + return this; + } + + /** + * 「EXIFの日時を基準にする」 + * @param label テキスト + * @param params プロパティ + */ + public void addExifBase(String label, AppParameters params) { + boolean selected = false; + if (params.getProperty(AppParameters.GPX_BASETIME).equals("EXIF_TIME")) { + selected = true; + } + exifBase = new JRadioButton(label, selected); + baseTimeGroup.add(exifBase); + } + + /** + * 「File更新日時を基準にする」 + * @param label テキスト + * @param params プロパティ + */ + public void addFileUpdate(String label, AppParameters params) { + boolean selected = false; + if (params.getProperty(AppParameters.GPX_BASETIME).equals("FILE_UPDATE")) { + selected = true; + } + fupdateBase = new JRadioButton(label, selected); + baseTimeGroup.add(fupdateBase); + } + + public ParameterPanelImageFile getImageFile() { + return this.imageFile; + } + + /** + * Action : Update 'arg2_baseTimeImg' + * + */ + class BaseTimeImgUpdateAction implements PropertyChangeListener { + @Override + public void propertyChange(PropertyChangeEvent arg0) { + try { + String timeStr = getTimeStr(); + argField.setText(timeStr); + } catch (Exception e) { + argField.setText("Error : "+ e.toString()); + } + } + } + + /** + * [変更...]ボタンのアクション + */ + class UpdateButtonAction implements java.awt.event.ActionListener + { + ParameterPanelTime param; + + public UpdateButtonAction(ParameterPanelTime param) { + this.param = param; + } + + public void actionPerformed(ActionEvent e) { + fileSelect_Action(param); + (new DialogCorectTime(param, owner)).setVisible(true); + } + } + + /** + * [再設定...]ボタンのアクション + */ + class ResetButtonAction implements java.awt.event.ActionListener + { + ParameterPanelTime paramPanelTime; + + public ResetButtonAction(ParameterPanelTime param) { + this.paramPanelTime = param; + } + + public void actionPerformed(ActionEvent e) { + fileSelect_Action(paramPanelTime); + } + } + + /** + * 画像ファイルが選択されたときのアクション + * 1.ラジオボタンの選択を参照してTEXTフィールドにファイルの「日時」を設定する + * @param param + */ + void fileSelect_Action(ParameterPanelTime param) { + param.argField.setText(getTimeStr()); + } + + String getTimeStr() { + if (!imageFile.isEnable()) { + return "Error : ImageFile is not selected."; + } + + File timeFile = imageFile.getImageFile(); + + // Radio Selector + sdf.applyPattern(Restamp.TIME_PATTERN); + if ((exifBase != null) && 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 = sdf.parse(dateTimeOriginal).getTime(); + return (dfjp.format(new Date(lastModifyTime))); + } + else { + return ("Error : 'ExIF is null!'"); + } + } + else { + return "Error : "; + } + } + catch (IOException | ParseException | ImageReadException ex) { + return "Error : "+ ex.toString(); + } + } + else { + long lastModified = timeFile.lastModified(); + return (sdf.format(new Date(lastModified))); + } + } + + @Override + public boolean isEnable() { + if (!this.imageFile.isEnable()) { + return false; + } + + String text = this.argField.getText(); + if (text == null) { + return false; + } + + try { + sdf.applyPattern(Restamp.TIME_PATTERN); + sdf.parse(text); + return true; + } + catch (ParseException e) { + return false; + } + } + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + // TODO Auto-generated method stub + + } +} diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/parameters/SimpleDocumentListener.java b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/SimpleDocumentListener.java new file mode 100644 index 0000000..19a6717 --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/parameters/SimpleDocumentListener.java @@ -0,0 +1,25 @@ +package osm.jp.gpx.matchtime.gui.parameters; + +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +@FunctionalInterface +public interface SimpleDocumentListener extends DocumentListener { + void update(DocumentEvent e); + + @Override + default void insertUpdate(DocumentEvent e) { + update(e); + } + + @Override + default void removeUpdate(DocumentEvent e) { + update(e); + } + + @Override + default void changedUpdate(DocumentEvent e) { + update(e); + } +} +