diff --git a/src/osm/jp/gpx/matchtime/gui/AdjustTime.java b/src/osm/jp/gpx/matchtime/gui/AdjustTime.java index 3029c3a..9dd5872 100644 --- a/src/osm/jp/gpx/matchtime/gui/AdjustTime.java +++ b/src/osm/jp/gpx/matchtime/gui/AdjustTime.java @@ -276,7 +276,11 @@ // 基準時刻: String str310 = String.format("  %s: ", i18n.getString("label.310")); - arg3_basetime = new ParameterPanel(str310, ImportPicture.TIME_FORMAT_STRING); + arg3_basetime = new ParameterPanelTime( + str310, + ImportPicture.TIME_FORMAT_STRING, + arg2_baseTimeImg + ); argsPanel.add(arg3_basetime); card.mainPanel.add(argsPanel, BorderLayout.NORTH); @@ -463,7 +467,7 @@ openButton.addActionListener(lSymAction); zoomOutButton.addActionListener(lSymAction); zoomInButton.addActionListener(lSymAction); - arg2_baseTimeImg.argField.addActionListener(lSymAction); + //arg2_baseTimeImg.argField.addActionListener(lSymAction); arg2_baseTimeImg.openButton.addActionListener(lSymAction); doButton.addActionListener(lSymAction); outputIMG_all.addActionListener(lSymAction); diff --git a/src/osm/jp/gpx/matchtime/gui/PanelAction.java b/src/osm/jp/gpx/matchtime/gui/PanelAction.java index facc908..88085dc 100644 --- a/src/osm/jp/gpx/matchtime/gui/PanelAction.java +++ b/src/osm/jp/gpx/matchtime/gui/PanelAction.java @@ -2,4 +2,10 @@ public interface PanelAction { void openAction(); + + /** + * 入力条件が満たされているかどうか + * @return + */ + boolean isEnable(); } diff --git a/src/osm/jp/gpx/matchtime/gui/ParamAction.java b/src/osm/jp/gpx/matchtime/gui/ParamAction.java index ffd0bcf..d09db2e 100644 --- a/src/osm/jp/gpx/matchtime/gui/ParamAction.java +++ b/src/osm/jp/gpx/matchtime/gui/ParamAction.java @@ -2,4 +2,6 @@ public interface ParamAction { boolean isEnable(); + void setText(String text); + String getText(); } diff --git a/src/osm/jp/gpx/matchtime/gui/ParameterData.java b/src/osm/jp/gpx/matchtime/gui/ParameterData.java new file mode 100644 index 0000000..76eb082 --- /dev/null +++ b/src/osm/jp/gpx/matchtime/gui/ParameterData.java @@ -0,0 +1,23 @@ +package osm.jp.gpx.matchtime.gui; + +import java.util.Observable; + +public class ParameterData extends Observable { + String content = ""; + + String getContent() { + return content; + } + + void setContent(String content) { + this.content = content; + setChanged(); + super.notifyObservers(content); + clearChanged(); + } + + @Override + public void notifyObservers(Object arg) { + setContent(arg.toString()); + } +} diff --git a/src/osm/jp/gpx/matchtime/gui/ParameterPanel.java b/src/osm/jp/gpx/matchtime/gui/ParameterPanel.java index 80de385..00f1418 100644 --- a/src/osm/jp/gpx/matchtime/gui/ParameterPanel.java +++ b/src/osm/jp/gpx/matchtime/gui/ParameterPanel.java @@ -1,7 +1,6 @@ package osm.jp.gpx.matchtime.gui; import java.awt.Dimension; -import java.awt.event.ActionListener; import java.util.ResourceBundle; import javax.swing.BoxLayout; @@ -13,7 +12,7 @@ * パラメータを設定する為のパネル。 * この1インスタンスで、1パラメータをあらわす。 */ -public abstract class ParameterPanel extends JPanel implements ActionListener,ParamAction { +public abstract class ParameterPanel extends JPanel implements ParamAction { private static final long serialVersionUID = 4629824800747170556L; public JTextField argField; public JLabel argLabel; @@ -43,11 +42,12 @@ return this; } - public ParameterPanel setText(String text) { + @Override + public void setText(String text) { this.argField.setText(text); - return this; } + @Override public String getText() { return this.argField.getText(); } diff --git a/src/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java b/src/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java index bc92217..4169cc8 100644 --- a/src/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java +++ b/src/osm/jp/gpx/matchtime/gui/ParameterPanelFolder.java @@ -1,13 +1,14 @@ package osm.jp.gpx.matchtime.gui; import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import javax.swing.JButton; import javax.swing.JFileChooser; @SuppressWarnings("serial") -public class ParameterPanelFolder extends ParameterPanel +public class ParameterPanelFolder extends ParameterPanel implements ActionListener { JFileChooser fc; JButton openButton; @@ -37,7 +38,7 @@ super.setEnabled(f); openButton.setEnabled(f); } - + public File getDirectory() throws FileNotFoundException { String path = this.argField.getText(); if (path == null) { @@ -79,8 +80,22 @@ } } + /** + * 有効な値が設定されているかどうか + * @return + */ @Override public boolean isEnable() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + String text = this.argField.getText(); + if (text == null) { + return false; + } + try { + File dir = new File(text); + return (dir.exists() && dir.isDirectory()); + } + catch (Exception e) { + return false; + } } } \ No newline at end of file diff --git a/src/osm/jp/gpx/matchtime/gui/ParameterPanelGpx.java b/src/osm/jp/gpx/matchtime/gui/ParameterPanelGpx.java index c2ebba5..d160126 100644 --- a/src/osm/jp/gpx/matchtime/gui/ParameterPanelGpx.java +++ b/src/osm/jp/gpx/matchtime/gui/ParameterPanelGpx.java @@ -54,4 +54,13 @@ } } } + + /** + * このフィールドに有効な値が設定されているかどうか + * @return + */ + @Override + public boolean isEnable() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } } diff --git a/src/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java b/src/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java index ea2db23..ac417c0 100644 --- a/src/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java +++ b/src/osm/jp/gpx/matchtime/gui/ParameterPanelImageFile.java @@ -1,12 +1,14 @@ package osm.jp.gpx.matchtime.gui; import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.File; +import java.io.FileNotFoundException; import javax.swing.JButton; import javax.swing.JFileChooser; @SuppressWarnings("serial") -public class ParameterPanelImageFile extends ParameterPanel { +public class ParameterPanelImageFile extends ParameterPanel implements ActionListener { JFileChooser fc; public JButton openButton; public ParameterPanelFolder paramDir; @@ -66,6 +68,24 @@ */ @Override public boolean isEnable() { - throw new UnsupportedOperationException("Not supported yet."); + 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/osm/jp/gpx/matchtime/gui/ParameterPanelTime.java b/src/osm/jp/gpx/matchtime/gui/ParameterPanelTime.java index bb01845..4c2e967 100644 --- a/src/osm/jp/gpx/matchtime/gui/ParameterPanelTime.java +++ b/src/osm/jp/gpx/matchtime/gui/ParameterPanelTime.java @@ -2,33 +2,47 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import javax.swing.JButton; -import javax.swing.JFileChooser; +import java.text.DateFormat; +import java.text.SimpleDateFormat; -@SuppressWarnings("serial") +/** + * パラメータを設定する為のパネル。 + * この1インスタンスで、1パラメータをあらわす。 + */ public class ParameterPanelTime extends ParameterPanel implements ActionListener { - JFileChooser fc; - public JButton doButton; + SimpleDateFormat sdf = (SimpleDateFormat)DateFormat.getDateTimeInstance(); + ParameterPanelImageFile imageFile; - @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) - public ParameterPanelTime(String label, String text) { + @SuppressWarnings("OverridableMethodCallInConstructor") + public ParameterPanelTime( + String label, + String text, + ParameterPanelImageFile imageFile + ) { super(label, text); - - doButton = new JButton("処理実行", AdjustTime.createImageIcon("images/media_playback_start.png")); - doButton.addActionListener(this); - this.add(doButton); - } - - @Override - public void actionPerformed(ActionEvent e) { + this.imageFile = imageFile; } - /** - * このフィールドに有効な値が設定されているかどうか - * @return - */ @Override - public boolean isEnable() { + public void actionPerformed(ActionEvent arg0) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } -} \ No newline at end of file + + @Override + public boolean isEnable() { + if (this.imageFile.isEnable()) { + String text = this.argField.getText(); + if (text != null) { + try { + sdf.applyPattern("yyyy.MM.dd HH:mm:ss z"); + sdf.parse(text); + return true; + } + catch (Exception e) { + return false; + } + } + } + return false; + } +} diff --git a/src/osm/jp/gpx/matchtime/gui/SimpleDocumentListener.java b/src/osm/jp/gpx/matchtime/gui/SimpleDocumentListener.java new file mode 100644 index 0000000..735c6ee --- /dev/null +++ b/src/osm/jp/gpx/matchtime/gui/SimpleDocumentListener.java @@ -0,0 +1,25 @@ +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/osm/jp/gpx/matchtime/gui/restamp/CardCorectTime.java b/src/osm/jp/gpx/matchtime/gui/restamp/CardCorectTime.java index 9b5f30d..e0c4160 100644 --- a/src/osm/jp/gpx/matchtime/gui/restamp/CardCorectTime.java +++ b/src/osm/jp/gpx/matchtime/gui/restamp/CardCorectTime.java @@ -14,22 +14,22 @@ import static osm.jp.gpx.matchtime.gui.AdjustTime.i18n; import osm.jp.gpx.matchtime.gui.Card; import osm.jp.gpx.matchtime.gui.PanelAction; -import osm.jp.gpx.matchtime.gui.ParameterPanel; +import osm.jp.gpx.matchtime.gui.ParameterPanelTime; /** * [基準画像(開始)]選択パネル * @author yuu */ -public class CardCorectTime extends Card { +public class CardCorectTime extends Card implements PanelAction { JPanel argsPanel; // パラメータ設定パネル (上部) - ParameterPanel arg3_basetime; // 基準時刻: + ParameterPanelTime arg_basetime; // 開始画像の基準時刻: /** * コンストラクタ * @param tabbe parent panel - * @param arg3_basetime + * @param arg3_basetime 開始画像の基準時刻: */ - public CardCorectTime(JTabbedPane tabbe, ParameterPanel arg3_basetime) { + public CardCorectTime(JTabbedPane tabbe, ParameterPanelTime arg3_basetime) { super(tabbe, AdjustTime.i18n.getString("tab.restamp.300"), 1, 3); argsPanel = new JPanel(); @@ -46,7 +46,7 @@ argsPanel.add(label3); // 基準時刻: - this.arg3_basetime = arg3_basetime; + this.arg_basetime = arg3_basetime; arg3_basetime.setLabel(String.format("  %s: ", i18n.getString("label.310"))); arg3_basetime.setLabel(ImportPicture.TIME_FORMAT_STRING); argsPanel.add(arg3_basetime); @@ -68,4 +68,19 @@ buttonPanel.add(zoomOutButton); this.mainPanel.add(buttonPanel, BorderLayout.SOUTH); } + + @Override + @SuppressWarnings("empty-statement") + public void openAction() { + ; // 何もしない + } + + /** + * 入力条件が満たされているかどうか + * @return + */ + @Override + public boolean isEnable() { + return this.arg_basetime.isEnable(); + } } diff --git a/src/osm/jp/gpx/matchtime/gui/restamp/CardFirstFile.java b/src/osm/jp/gpx/matchtime/gui/restamp/CardFirstFile.java index f542caa..8a7f4ca 100644 --- a/src/osm/jp/gpx/matchtime/gui/restamp/CardFirstFile.java +++ b/src/osm/jp/gpx/matchtime/gui/restamp/CardFirstFile.java @@ -19,17 +19,19 @@ */ public class CardFirstFile extends Card implements PanelAction { JPanel argsPanel; // パラメータ設定パネル (上部) - ParameterPanelImageFile arg2_baseTimeImg; - + ParameterPanelImageFile arg_baseTimeImg; + /** * コンストラクタ * @param tabbe parent panel * @param arg2_baseTimeImg */ - public CardFirstFile(JTabbedPane tabbe, ParameterPanelImageFile arg2_baseTimeImg) { + public CardFirstFile( + JTabbedPane tabbe, + ParameterPanelImageFile arg2_baseTimeImg + ) { super(tabbe, AdjustTime.i18n.getString("tab.restamp.200"), 0, 2); - this.arg2_baseTimeImg = arg2_baseTimeImg; - + this.arg_baseTimeImg = arg2_baseTimeImg; this.mainPanel.add(new JLabel(i18n.getString("label.200")), BorderLayout.NORTH); argsPanel = new JPanel(); @@ -38,15 +40,18 @@ this.mainPanel.add(argsPanel, BorderLayout.CENTER); } + /** + * 入力条件が満たされているかどうか + * @return + */ @Override + public boolean isEnable() { + return this.arg_baseTimeImg.isEnable(); + } + + @Override + @SuppressWarnings("empty-statement") public void openAction() { - try { - File dir = arg2_baseTimeImg.paramDir.getDirectory(); - } catch (FileNotFoundException ex) { - arg2_baseTimeImg.setText(null); - } - if (arg2_baseTimeImg.getText() == null) { - } - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + ; // 何もしない } } diff --git a/src/osm/jp/gpx/matchtime/gui/restamp/CardSourceFolder.java b/src/osm/jp/gpx/matchtime/gui/restamp/CardSourceFolder.java index 799d1de..0250271 100644 --- a/src/osm/jp/gpx/matchtime/gui/restamp/CardSourceFolder.java +++ b/src/osm/jp/gpx/matchtime/gui/restamp/CardSourceFolder.java @@ -16,22 +16,33 @@ * @author yuu */ public class CardSourceFolder extends Card implements PanelAction { + ParameterPanelFolder arg_srcFolder; // 対象フォルダ /** * コンストラクタ * @param tabbe parent panel - * @param arg1_srcFolder 対象フォルダ + * @param arg_srcFolder 対象フォルダ */ - public CardSourceFolder(JTabbedPane tabbe, ParameterPanelFolder arg1_srcFolder) { + public CardSourceFolder(JTabbedPane tabbe, ParameterPanelFolder arg_srcFolder) { super(tabbe, AdjustTime.i18n.getString("tab.100"), -1, 1); + this.arg_srcFolder = arg_srcFolder; this.mainPanel.add(new JLabel(i18n.getString("label.100")), BorderLayout.NORTH); JPanel argsPanel = new JPanel(); // パラメータ設定パネル (上部) argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS)); - argsPanel.add(arg1_srcFolder); + argsPanel.add(arg_srcFolder); this.mainPanel.add(argsPanel, BorderLayout.CENTER); } + /** + * 入力条件が満たされているかどうか + * @return + */ + @Override + public boolean isEnable() { + return this.arg_srcFolder.isEnable(); + } + @Override @SuppressWarnings("empty-statement") public void openAction() { diff --git a/src/osm/jp/gpx/matchtime/gui/restamp/RestampDialog.java b/src/osm/jp/gpx/matchtime/gui/restamp/RestampDialog.java index 7e4cee2..64477cb 100644 --- a/src/osm/jp/gpx/matchtime/gui/restamp/RestampDialog.java +++ b/src/osm/jp/gpx/matchtime/gui/restamp/RestampDialog.java @@ -4,20 +4,24 @@ import java.io.File; import java.io.IOException; import java.util.Date; +import java.util.Observable; +import java.util.Observer; import javax.swing.*; +import javax.swing.event.DocumentEvent; import osm.jp.gpx.AppParameters; import osm.jp.gpx.matchtime.gui.AdjustTime; import osm.jp.gpx.matchtime.gui.Card; import osm.jp.gpx.matchtime.gui.ImageFileView; import osm.jp.gpx.matchtime.gui.ImageFilter; import osm.jp.gpx.matchtime.gui.ImagePreview; -import osm.jp.gpx.matchtime.gui.ParameterPanel; import osm.jp.gpx.matchtime.gui.ParameterPanelFolder; import osm.jp.gpx.matchtime.gui.ParameterPanelImageFile; import static osm.jp.gpx.matchtime.gui.AdjustTime.i18n; +import osm.jp.gpx.matchtime.gui.ParameterPanelTime; +import osm.jp.gpx.matchtime.gui.SimpleDocumentListener; @SuppressWarnings("serial") -public class RestampDialog extends Dialog +public class RestampDialog extends Dialog implements Observer { //{{DECLARE_CONTROLS java.awt.Label label1; @@ -26,16 +30,27 @@ JLabel imageLabel; // 開始画像の基準時刻画像表示 JTabbedPane cardPanel; // ウィザード形式パネル(タブ型) JScrollPane imageSPane; // スクロールパネル - JPanel[] cards; + Card[] cards; ParameterPanelFolder arg1_srcFolder; // 対象フォルダ ParameterPanelImageFile arg2_baseTimeImg; // 開始画像ファイルパス - ParameterPanel arg3_basetime; // 開始画像の基準時刻: + ParameterPanelTime arg2_basetime; // 開始画像の基準時刻: AppParameters params; //}} // Used for addNotify redundency check. boolean fComponentsAdjusted = false; + /** + * + * @param arg0 + * @param arg1 + */ + @Override + public void update(Observable arg0, Object arg1) { + String str = (String) arg1; + System.out.println("私はAです。観察対象の通知を検知したよ。" + str); + } + class SymWindow extends java.awt.event.WindowAdapter { @Override @@ -101,7 +116,7 @@ //--------------------------------------------------------------------- params = new AppParameters(); - cards = new JPanel[3]; + cards = new Card[3]; cardPanel = new JTabbedPane(JTabbedPane.LEFT); mainPanel.add(cardPanel, BorderLayout.CENTER); int cardNo = 0; @@ -113,6 +128,16 @@ i18n.getString("label.110") +": ", params.getProperty(AppParameters.IMG_SOURCE_FOLDER) ); + arg1_srcFolder.argField + .getDocument() + .addDocumentListener( + new SimpleDocumentListener() { + @Override + public void update(DocumentEvent e) { + toEnable(0, arg1_srcFolder.isEnable()); + } + } + ); Card card = new CardSourceFolder(cardPanel, arg1_srcFolder); cardPanel.addTab(card.getTitle(), card); @@ -130,6 +155,16 @@ null, arg1_srcFolder ); + arg2_baseTimeImg.argField + .getDocument() + .addDocumentListener( + new SimpleDocumentListener() { + @Override + public void update(DocumentEvent e) { + toEnable(1, arg2_baseTimeImg.isEnable()); + } + } + ); CardFirstFile card = new CardFirstFile(cardPanel, arg2_baseTimeImg); cardPanel.addTab(card.getTitle(), card); @@ -142,9 +177,23 @@ // 2a. 開始画像の本当の時刻を設定の入力画面 { // 2a. 基準時刻: - arg3_basetime = new ParameterPanel(); + arg2_basetime = new ParameterPanelTime( + i18n.getString("label.310"), + null, + arg2_baseTimeImg + ); + arg2_basetime.argField + .getDocument() + .addDocumentListener( + new SimpleDocumentListener() { + @Override + public void update(DocumentEvent e) { + toEnable(2, arg2_basetime.isEnable()); + } + } + ); - CardCorectTime card = new CardCorectTime(cardPanel, arg3_basetime); + CardCorectTime card = new CardCorectTime(cardPanel, arg2_basetime); cardPanel.addTab(card.getTitle(), card); cardPanel.setEnabledAt(cardNo, false); cards[cardNo] = card; @@ -158,6 +207,21 @@ closeButton.addActionListener(lSymAction); //}} } + + + void toEnable(final int cardNo, final boolean enable) { + if ((cardNo >= 0) && (cardNo < cards.length)) { + cardPanel.setEnabledAt(cardNo, enable); + if ((cardNo -1) >= 0) { + cards[cardNo -1].nextButton.setEnabled(enable); + } + if ((cardNo +1) < cards.length) { + cardPanel.setEnabledAt(cardNo+1, enable); + cards[cardNo +1].backButton.setEnabled(enable); + cards[cardNo].nextButton.setEnabled(enable); + } + } + } @SuppressWarnings("OverridableMethodCallInConstructor") public RestampDialog(Frame parent, String title, boolean modal) throws IOException { @@ -229,7 +293,7 @@ File timeFile = new File(path); long lastModifyTime = timeFile.lastModified(); - arg3_basetime.argField.setText(AdjustTime.dfjp.format(new Date(lastModifyTime))); + arg2_basetime.argField.setText(AdjustTime.dfjp.format(new Date(lastModifyTime))); int size_x = imageSPane.getWidth() - 8; ImageIcon tmpIcon = new ImageIcon(path);