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 dc207f5..2c761fb 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/AdjustTerra.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/AdjustTerra.java @@ -2,8 +2,8 @@ import osm.jp.gpx.matchtime.gui.restamp.RestampDialog; import java.awt.*; -import java.awt.event.ActionEvent; -import java.io.File; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ResourceBundle; @@ -39,7 +39,7 @@ //}} //---入力フィールド---------------------------------------------------- - ParameterPanelFolder arg1_srcFolder; // 対象フォルダ + ParameterPanelSourceFolder arg1_srcFolder; // 対象フォルダ ParameterPanelImageFile arg2_baseTimeImg; // 開始画像ファイルパス ParameterPanelTime arg2_basetime; // 開始画像の基準時刻: ParameterPanelGpx arg3_gpxFile; // GPX file or Folder @@ -91,26 +91,25 @@ } } } - - /** - * Action : Changed 'arg1' - * - */ - class Arg1ChangedAction implements java.awt.event.ActionListener { + + class SimpleCardListener implements PropertyChangeListener { + int cardNo; + ParameterPanel param; + + SimpleCardListener(int cardNo, ParameterPanel param) { + this.cardNo = cardNo; + this.param = param; + } + @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()); + public void propertyChange(PropertyChangeEvent evt) { + String propertyName = evt.getPropertyName(); + if (propertyName.equals(AppParameters.IMG_SOURCE_FOLDER)) { + toEnable(cardNo, param.isEnable()); + } + else { + toEnable(cardNo, param.isEnable()); + } } } @@ -159,24 +158,12 @@ //--------------------------------------------------------------------- // 1.[対象フォルダ]設定パネル { - arg1_srcFolder = new ParameterPanelFolder( + arg1_srcFolder = new ParameterPanelSourceFolder( + AppParameters.IMG_SOURCE_FOLDER, i18n.getString("label.110") +": ", params.getProperty(AppParameters.IMG_SOURCE_FOLDER) ); - 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) {} - } - } - ); + arg1_srcFolder.addPropertyChangeListener(new SimpleCardListener(0, arg1_srcFolder)); Card card = new CardSourceFolder(cardPanel, arg1_srcFolder); cardPanel.addTab(card.getTitle(), card); @@ -186,11 +173,13 @@ } //--------------------------------------------------------------------- - // 2.[基準時刻画像]設定パネル - // 2a.基準時刻の入力画面 + // 2.[基準時刻]パネル + // 2a.基準画像を選択フィールド + // 2b.基準時刻の入力フィールド { - // 基準時刻画像 + // 2a. 基準時刻画像 arg2_baseTimeImg = new ParameterPanelImageFile( + AppParameters.IMG_BASE_FILE, i18n.getString("label.210") +": ", null, arg1_srcFolder @@ -198,18 +187,12 @@ // 2a. 基準時刻: arg2_basetime = new ParameterPanelTime( + AppParameters.GPX_BASETIME, 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()); - } - } - ); + arg2_basetime.addPropertyChangeListener(new SimpleCardListener(1, arg2_basetime)); // EXIFの日時を基準にする arg2_basetime.addExifBase(i18n.getString("label.220"), params); @@ -231,6 +214,7 @@ { // 3. GPXファイル選択パラメータ arg3_gpxFile = new ParameterPanelGpx( + AppParameters.GPX_SOURCE_FOLDER, i18n.getString("label.410") + ": ", params.getProperty(AppParameters.GPX_SOURCE_FOLDER) ); @@ -262,6 +246,7 @@ // 4. ファイル変換・実行パラメータ // "出力フォルダ: " arg4_output = new ParameterPanelOutput( + AppParameters.IMG_OUTPUT_FOLDER, i18n.getString("label.530") + ": ", params.getProperty(AppParameters.IMG_OUTPUT_FOLDER) ); 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 1831e81..9f28907 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanel.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanel.java @@ -16,19 +16,21 @@ */ public abstract class ParameterPanel extends JPanel implements ParamAction { private static final long serialVersionUID = 4629824800747170556L; + public String propertyName; public JTextField argField; public JLabel argLabel; public ResourceBundle i18n = ResourceBundle.getBundle("i18n"); - public ParameterPanel(String label, String text) { + public ParameterPanel(String name, String label, String text) { this(); - this.setName(label); + this.setName(name); + this.setLabel(label); this.setText(text); } - public ParameterPanel() { + ParameterPanel() { super(); - + propertyName = ""; argLabel = new JLabel(); argField = new JTextField(); @@ -39,7 +41,7 @@ } public ParameterPanel setLabel(String label) { - this.setName(label); + this.argLabel.setText(label); return this; } @@ -53,12 +55,12 @@ @Override public void setName(String name) { - this.argLabel.setText(name); + this.propertyName = name; } @Override public String getName() { - return this.argLabel.getText(); + return this.propertyName; } @Override 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 77d2220..182cf83 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java @@ -8,9 +8,10 @@ import java.io.FileNotFoundException; import javax.swing.JButton; import javax.swing.JFileChooser; +import javax.swing.event.DocumentEvent; @SuppressWarnings("serial") -public class ParameterPanelFolder extends ParameterPanel implements ActionListener +public abstract class ParameterPanelFolder extends ParameterPanel implements ActionListener { JFileChooser fc; JButton selectButton; @@ -23,12 +24,12 @@ * @param label * @param text */ - public ParameterPanelFolder(String label, String text) { - this(label, text, JFileChooser.DIRECTORIES_ONLY); + public ParameterPanelFolder(String name, String label, String text) { + this(name, label, text, JFileChooser.DIRECTORIES_ONLY); } - public ParameterPanelFolder(String label, String text, int chooser) { - super(label, text); + public ParameterPanelFolder(String name, String label, String text, int chooser) { + super(name, label, text); // Create a file chooser this.chooser = chooser; @@ -40,6 +41,16 @@ ); selectButton.addActionListener(this); this.add(selectButton); + + // 'argField' ’が変更されたら、「update イベントを発火させる + this.argField.getDocument().addDocumentListener( + new SimpleDocumentListener() { + @Override + public void update(DocumentEvent e) { + pcs.firePropertyChange(getName(), "", argField.getText()); + } + } + ); } public void setEnable(boolean f) { @@ -86,7 +97,6 @@ File file = this.fc.getSelectedFile(); String text = file.getAbsolutePath(); this.argField.setText(text); - //firePropertyChange(text); } } } 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 b1bdc2a..9ca322c 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelGpx.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelGpx.java @@ -22,8 +22,8 @@ * @param label * @param text */ - public ParameterPanelGpx(String label, String text) { - super(label, text); + public ParameterPanelGpx(String name, String label, String text) { + super(name, label, text); // "選択..." selectButton = new JButton( 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 e4b4e9a..1956433 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java @@ -1,9 +1,9 @@ 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.beans.PropertyChangeSupport; import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; @@ -11,18 +11,21 @@ import javax.swing.JButton; import javax.swing.JFileChooser; +import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; @SuppressWarnings("serial") -public class ParameterPanelImageFile extends ParameterPanel { +public class ParameterPanelImageFile extends ParameterPanel implements PropertyChangeListener { JFileChooser fc; public JButton openButton; public ParameterPanelFolder paramDir; + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); public ParameterPanelImageFile( - String label, String text, + String name, String label, String text, ParameterPanelFolder paramDir ) { - super(label, text); + super(name, label, text); // "選択..." SelectButtonAction buttonAction = new SelectButtonAction(); @@ -32,8 +35,17 @@ //Create a file chooser this.paramDir = paramDir; - this.paramDir.argField.addActionListener(new BaseTimeImgUpdateAction()); this.paramDir.addPropertyChangeListener(new SourceFolderChangeListener()); + + // 'argField' ’が変更されたら、「update イベントを発火させる + this.argField.getDocument().addDocumentListener( + new SimpleDocumentListener() { + @Override + public void update(DocumentEvent e) { + pcs.firePropertyChange(getName(), "", argField.getText()); + } + } + ); } /** @@ -62,37 +74,7 @@ } } 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) {} - } + argField.setText(""); fc = new JFileChooser(); fc.setSelectedFile(null); } @@ -101,36 +83,32 @@ class SelectButtonAction implements java.awt.event.ActionListener { public void actionPerformed(ActionEvent e) { - selectImage_Action(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 void selectImage_Action(ActionEvent ev) { - 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(); - this.argField.setText(file.getName()); - } - else { - fc.setSelectedFile(null); - } - } - public File getImageFile() { if (this.paramDir.isEnable()) { String text = this.argField.getText(); @@ -150,10 +128,6 @@ return null; } - /** - * - * @return - */ @Override public boolean isEnable() { if (this.paramDir.isEnable()) { @@ -179,13 +153,26 @@ @Override public void addPropertyChangeListener(PropertyChangeListener listener) { - // TODO Auto-generated method stub - + this.pcs.addPropertyChangeListener(listener); } @Override public void removePropertyChangeListener(PropertyChangeListener listener) { - // TODO Auto-generated method stub + this.pcs.removePropertyChangeListener(listener); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + // TODO Nothing to do. + + Object eventTriggerObject = evt.getSource(); + String propertyName = evt.getPropertyName(); + if (JTextField.class.isInstance(eventTriggerObject)) { + if (propertyName.equals(getName())) { + String newValue = (String) evt.getNewValue(); + System.out.println("["+ propertyName +"] propertyChanged() newValue:" + newValue); + } + } } } \ 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 index 07059b2..33baf6e 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelOutput.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelOutput.java @@ -19,8 +19,8 @@ * @param label * @param text */ - public ParameterPanelOutput(String label, String text) { - super(label, text, JFileChooser.DIRECTORIES_ONLY); + public ParameterPanelOutput(String name, String label, String text) { + super(name, label, text, JFileChooser.DIRECTORIES_ONLY); } /** diff --git a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelSourceFolder.java b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelSourceFolder.java new file mode 100644 index 0000000..1230af8 --- /dev/null +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelSourceFolder.java @@ -0,0 +1,47 @@ +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); + } + + /** + * 有効な値が設定されているかどうか + * @return + */ + @Override + public boolean isEnable() { + String text = this.argField.getText(); + if (text == null) { + return false; + } + try { + File dir = super.getDirectory(); + return (dir.exists() && dir.isDirectory()); + } + catch (Exception e) { + return false; + } + } + + @Override + public File getDirectory() throws FileNotFoundException { + File dir = super.getDirectory(); + if (dir.exists() && dir.isDirectory()) { + + } + return dir; + } + +} \ 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 f70bb8c..f34f194 100644 --- a/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelTime.java +++ b/src/main/java/osm/jp/gpx/matchtime/gui/ParameterPanelTime.java @@ -2,9 +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.beans.PropertyChangeSupport; import java.io.File; import java.io.IOException; import java.text.DateFormat; @@ -14,6 +14,8 @@ import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JRadioButton; +import javax.swing.event.DocumentEvent; + import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.Imaging; import org.apache.commons.imaging.common.ImageMetadata; @@ -23,14 +25,16 @@ import osm.jp.gpx.AppParameters; import osm.jp.gpx.Restamp; import static osm.jp.gpx.matchtime.gui.AdjustTerra.dfjp; + import osm.jp.gpx.matchtime.gui.restamp.DialogCorectTime; /** * パラメータを設定する為のパネル。 * この1インスタンスで、1パラメータをあらわす。 */ -public class ParameterPanelTime extends ParameterPanel implements PropertyChangeListener { +public class ParameterPanelTime extends ParameterPanel { private static final long serialVersionUID = 1683226418990348336L; + private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); SimpleDateFormat sdf = (SimpleDateFormat)DateFormat.getDateTimeInstance(); ParameterPanelImageFile imageFile; // 基準時刻画像 @@ -45,12 +49,14 @@ Window owner; public ParameterPanelTime( + String name, String label, String text, ParameterPanelImageFile imageFile ) { - super(label, text); + super(name, label, text); this.imageFile = imageFile; + this.imageFile.addPropertyChangeListener(new BaseTimeImgUpdateAction()); // "ボタン[変更...]" UpdateButtonAction buttonAction = new UpdateButtonAction(this); @@ -64,13 +70,23 @@ resetButton.addActionListener(resetAction); resetButton.setVisible(false); this.add(resetButton); + + // 'argField' ’が変更されたら、「update イベントを発火させる + this.argField.getDocument().addDocumentListener( + new SimpleDocumentListener() { + @Override + public void update(DocumentEvent e) { + pcs.firePropertyChange(getName(), "", argField.getText()); + } + } + ); } public ParameterPanelTime setOwner(Window owner) { this.owner = owner; return this; } - + /** * 「EXIFの日時を基準にする」 * @param label テキスト @@ -104,13 +120,18 @@ } /** - * Action : Update 'arg2_baseTime' + * Action : Update 'arg2_baseTimeImg' * */ - class BaseTimeImgUpdateAction implements ActionListener { + class BaseTimeImgUpdateAction implements PropertyChangeListener { @Override - public void actionPerformed(ActionEvent e) { - setText(getTimeStr()); + public void propertyChange(PropertyChangeEvent arg0) { + try { + String timeStr = getTimeStr(); + argField.setText(timeStr); + } catch (Exception e) { + argField.setText("Error : "+ e.toString()); + } } } @@ -196,41 +217,32 @@ @Override public boolean isEnable() { - if (this.imageFile.isEnable()) { - String text = this.argField.getText(); - if (text != null) { - try { - sdf.applyPattern(Restamp.TIME_PATTERN); - sdf.parse(text); - return true; - } - catch (ParseException e) { - return false; - } - } + if (!this.imageFile.isEnable()) { + return false; + } + + String text = this.argField.getText(); + if (text == null) { + return false; } - return false; + + try { + sdf.applyPattern(Restamp.TIME_PATTERN); + sdf.parse(text); + return true; + } + catch (ParseException e) { + return false; + } } @Override public void addPropertyChangeListener(PropertyChangeListener listener) { - // TODO Auto-generated method stub - + this.pcs.addPropertyChangeListener(listener); } @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 - + this.pcs.removePropertyChangeListener(listener); } }