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 d5d84a6..dc207f5 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/AdjustTerra.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/AdjustTerra.java @@ -2,6 +2,8 @@ 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.ResourceBundle; @@ -91,6 +93,28 @@ } /** + * Action : Changed 'arg1' + * + */ + class Arg1ChangedAction implements java.awt.event.ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + toEnable(0, arg1_srcFolder.isEnable()); + } + } + + /** + * Action : Changed 'arg2' + * + */ + class Arg2ChangedAction implements java.awt.event.ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + toEnable(1, arg2_basetime.isEnable()); + } + } + + /** * データベース内のテーブルを一覧で表示するFrame * @throws IOException */ @@ -139,17 +163,21 @@ i18n.getString("label.110") +": ", params.getProperty(AppParameters.IMG_SOURCE_FOLDER) ); - arg1_srcFolder.argField - .getDocument() - .addDocumentListener( - new SimpleDocumentListener() { - @Override - public void update(DocumentEvent e) { + arg1_srcFolder.argField.getDocument().addDocumentListener( + new SimpleDocumentListener() { + @Override + public void update(DocumentEvent e) { + try { + File f = arg1_srcFolder.getDirectory(); + String text = f.getAbsolutePath(); + arg1_srcFolder.firePropertyChange(text); toEnable(0, arg1_srcFolder.isEnable()); - } + } + catch (Exception ex) {} } - ); - + } + ); + Card card = new CardSourceFolder(cardPanel, arg1_srcFolder); cardPanel.addTab(card.getTitle(), card); cardPanel.setEnabledAt(cardNo, true); diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ImageFileFilter.java b/src/main/java/osm/jp/gpx/matchtime/gui/ImageFileFilter.java new file mode 100644 index 0000000..09c8db8 --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ImageFileFilter.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Oracle or the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package osm.jp.gpx.matchtime.gui; + +import java.io.File; +import java.io.FileFilter; + +public class ImageFileFilter implements FileFilter { + + //Accept all directories and all gif, jpg, tiff, or png files. + @Override + public boolean accept(File f) { + if (f.isFile()) { + String extension = Utils.getExtension(f); + if (extension != null) { + return extension.equals(Utils.TIFF) || + extension.equals(Utils.TIF) || + extension.equals(Utils.GIF) || + extension.equals(Utils.JPEG) || + extension.equals(Utils.JPG) || + extension.equals(Utils.PNG); + } + } + return false; + } +} diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ImageFilter.java b/src/main/java/osm/jp/gpx/matchtime/gui/ImageFilter.java index 012eeb6..0964aaf 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ImageFilter.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ImageFilter.java @@ -59,6 +59,6 @@ //The description of this filter @Override public String getDescription() { - return "Just Images"; + return "Just Images and Directory"; } } diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ParamAction.java b/src/main/java/osm/jp/gpx/matchtime/gui/ParamAction.java index d09db2e..558fb4c 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParamAction.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ParamAction.java @@ -4,4 +4,6 @@ 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 index d26be5e..1831e81 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanel.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanel.java @@ -1,6 +1,8 @@ package osm.jp.gpx.matchtime.gui; import java.awt.Dimension; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeListener; import java.util.ResourceBundle; import javax.swing.BoxLayout; @@ -20,8 +22,8 @@ public ParameterPanel(String label, String text) { this(); - this.argLabel.setText(label); - this.argField.setText(text); + this.setName(label); + this.setText(text); } public ParameterPanel() { @@ -35,13 +37,31 @@ this.add(argLabel); this.add(argField); } - + public ParameterPanel setLabel(String label) { - this.argLabel.setText(label); + this.setName(label); return this; } + + public void addActionListener(ActionListener l) { + this.argField.addActionListener(l); + } + + public abstract void addPropertyChangeListener(PropertyChangeListener listener); + + public abstract void removePropertyChangeListener(PropertyChangeListener listener); @Override + public void setName(String name) { + this.argLabel.setText(name); + } + + @Override + public String getName() { + return this.argLabel.getText(); + } + + @Override public void setText(String text) { this.argField.setText(text); } diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java index b6dae01..77d2220 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java @@ -2,6 +2,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; import java.io.File; import java.io.FileNotFoundException; import javax.swing.JButton; @@ -13,7 +15,8 @@ JFileChooser fc; JButton selectButton; int chooser; - + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + /** * コンストラクタ * ディレクトリのみ選択可能なダイアログ @@ -38,7 +41,7 @@ selectButton.addActionListener(this); this.add(selectButton); } - + public void setEnable(boolean f) { super.setEnabled(f); selectButton.setEnabled(f); @@ -81,7 +84,9 @@ if (returnVal == JFileChooser.APPROVE_OPTION) { File file = this.fc.getSelectedFile(); - this.argField.setText(file.getAbsolutePath()); + String text = file.getAbsolutePath(); + this.argField.setText(text); + //firePropertyChange(text); } } } @@ -104,4 +109,18 @@ return false; } } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + this.pcs.addPropertyChangeListener(listener); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + this.pcs.removePropertyChangeListener(listener); + } + + void firePropertyChange(String text) { + this.pcs.firePropertyChange(getName(), "", 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 index ddb975e..b1bdc2a 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelGpx.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelGpx.java @@ -2,6 +2,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.beans.PropertyChangeListener; import java.io.File; import javax.swing.JButton; @@ -104,4 +105,16 @@ } return false; } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + // 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 index 829a8a1..e4b4e9a 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java @@ -1,8 +1,14 @@ package osm.jp.gpx.matchtime.gui; 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.FileNotFoundException; +import java.util.Arrays; +import java.util.Comparator; + import javax.swing.JButton; import javax.swing.JFileChooser; @@ -26,6 +32,70 @@ //Create a file chooser this.paramDir = paramDir; + this.paramDir.argField.addActionListener(new BaseTimeImgUpdateAction()); + 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) {} + } + fc = new JFileChooser(); + fc.setSelectedFile(null); + } + } + + /** + * Action : Update 'arg2_baseTimeImg' + * + */ + class BaseTimeImgUpdateAction implements ActionListener { + @Override + public void actionPerformed(ActionEvent 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) {} + } + fc = new JFileChooser(); + fc.setSelectedFile(null); + } } class SelectButtonAction implements java.awt.event.ActionListener @@ -56,7 +126,9 @@ File file = fc.getSelectedFile(); this.argField.setText(file.getName()); } - fc.setSelectedFile(null); + else { + fc.setSelectedFile(null); + } } public File getImageFile() { @@ -104,4 +176,16 @@ } return false; } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + // TODO Auto-generated method stub + + } } \ 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 index 1202e7e..f70bb8c 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelTime.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelTime.java @@ -2,6 +2,9 @@ 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; @@ -26,7 +29,7 @@ * パラメータを設定する為のパネル。 * この1インスタンスで、1パラメータをあらわす。 */ -public class ParameterPanelTime extends ParameterPanel { +public class ParameterPanelTime extends ParameterPanel implements PropertyChangeListener { private static final long serialVersionUID = 1683226418990348336L; SimpleDateFormat sdf = (SimpleDateFormat)DateFormat.getDateTimeInstance(); ParameterPanelImageFile imageFile; // 基準時刻画像 @@ -100,6 +103,16 @@ return this.imageFile; } + /** + * Action : Update 'arg2_baseTime' + * + */ + class BaseTimeImgUpdateAction implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + setText(getTimeStr()); + } + } /** * [変更...]ボタンのアクション @@ -140,36 +153,44 @@ * @param param */ void fileSelect_Action(ParameterPanelTime param) { - if (imageFile.isEnable()) { - File timeFile = imageFile.getImageFile(); + param.argField.setText(getTimeStr()); + } + + String getTimeStr() { + if (!imageFile.isEnable()) { + return "Error : ImageFile is not selected."; + } + + File timeFile = imageFile.getImageFile(); - // Radio Selecter - 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(); - param.argField.setText(dfjp.format(new Date(lastModifyTime))); - } - else { - param.argField.setText("exif == null"); - } + // 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!'"); } } - catch (IOException | ParseException | ImageReadException ex) {} + else { + return "Error : "; + } } - else { - long lastModified = timeFile.lastModified(); - param.argField.setText(sdf.format(new Date(lastModified))); + catch (IOException | ParseException | ImageReadException ex) { + return "Error : "+ ex.toString(); } } else { - param.argField.setText(""); + long lastModified = timeFile.lastModified(); + return (sdf.format(new Date(lastModified))); } } @@ -190,4 +211,26 @@ } return false; } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + Object eventTriggerObject = evt.getSource(); + String propertyName = evt.getPropertyName(); + String newValue = (String) evt.getNewValue(); + + // TODO Auto-generated method stub + + } }