OSDN Git Service

doing: AdjustTime - 1〜2パネル
[importpicture/importpicture.git] / src / osm / jp / gpx / matchtime / gui / restamp / RestampDialog.java
1 package osm.jp.gpx.matchtime.gui.restamp;
2 import java.awt.*;
3 import java.io.IOException;
4 import java.util.Observable;
5 import java.util.Observer;
6 import javax.swing.*;
7 import javax.swing.event.DocumentEvent;
8 import osm.jp.gpx.AppParameters;
9 import osm.jp.gpx.matchtime.gui.AdjustTime;
10 import osm.jp.gpx.matchtime.gui.Card;
11 import osm.jp.gpx.matchtime.gui.ParameterPanelFolder;
12 import osm.jp.gpx.matchtime.gui.ParameterPanelImageFile;
13 import static osm.jp.gpx.matchtime.gui.AdjustTime.i18n;
14 import osm.jp.gpx.matchtime.gui.ParameterPanelTime;
15 import osm.jp.gpx.matchtime.gui.SimpleDocumentListener;
16
17 @SuppressWarnings("serial")
18 public class RestampDialog extends JDialog implements Observer
19 {
20     //{{DECLARE_CONTROLS
21     java.awt.Button closeButton;
22     JTabbedPane cardPanel;       // ウィザード形式パネル(タブ型)
23     Card[] cards;
24     ParameterPanelFolder arg1_srcFolder;    // 対象フォルダ
25     ParameterPanelImageFile arg2_baseTimeImg;   // 開始画像ファイルパス
26     ParameterPanelTime arg2_basetime;   // 開始画像の基準時刻:
27     ParameterPanelImageFile arg3_baseTimeImg;   // 終了画像ファイルパス
28     ParameterPanelTime arg3_basetime;   // 終了画像の基準時刻:
29     AppParameters params;
30     //}}
31
32     /**
33      * 
34      * @param arg0
35      * @param arg1 
36      */
37     @Override
38     public void update(Observable arg0, Object arg1) {
39         String str = (String) arg1;
40         System.out.println("私はAです。観察対象の通知を検知したよ。" + str);
41     }
42
43     class SymWindow extends java.awt.event.WindowAdapter
44     {
45         @Override
46         public void windowClosing(java.awt.event.WindowEvent event) {
47             Object object = event.getSource();
48             if (object == RestampDialog.this) {
49                 dispose();
50             }
51         }
52     }
53
54     class SymAction implements java.awt.event.ActionListener
55     {
56         @Override
57         public void actionPerformed(java.awt.event.ActionEvent event) {
58             Object object = event.getSource();
59             if (object == closeButton) {
60                 dispose();
61             }
62         }
63     }
64
65     @SuppressWarnings("OverridableMethodCallInConstructor")
66     public RestampDialog(Frame parent, boolean modal) throws IOException {
67         super(parent, modal);
68
69         // INIT_CONTROLS
70         setLayout(new BorderLayout());
71         setSize(
72             getInsets().left + getInsets().right + 720,
73             getInsets().top + getInsets().bottom + 480
74         );
75         setTitle(i18n.getString("menu.restamp") + "... ");
76         
77         //---- CENTER -----
78         JPanel mainPanel = new JPanel();
79         mainPanel.setLayout(new BorderLayout());
80         add(mainPanel, BorderLayout.CENTER);
81         
82         //---- SOUTH -----
83         JPanel southPanel = new JPanel(new BorderLayout());
84         southPanel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH);
85         southPanel.add(Box.createVerticalStrut(10), BorderLayout.NORTH);
86         add(southPanel, BorderLayout.SOUTH);
87         
88         //---- SPACE -----
89         add(Box.createVerticalStrut(30), BorderLayout.NORTH);
90         add(Box.createHorizontalStrut(10), BorderLayout.WEST);
91         add(Box.createHorizontalStrut(10), BorderLayout.EAST);
92         
93         closeButton = new java.awt.Button();
94         closeButton.setLabel(i18n.getString("button.close") );
95         closeButton.setBounds(145,65,66,27);
96         southPanel.add(closeButton);
97         //}}
98         
99         //---------------------------------------------------------------------
100         params = new AppParameters();
101         cards = new Card[4];
102         cardPanel = new JTabbedPane(JTabbedPane.LEFT);
103         mainPanel.add(cardPanel, BorderLayout.CENTER);
104         int cardNo = 0;
105         
106         //---------------------------------------------------------------------
107         // 1.[対象フォルダ]設定パネル
108         {
109             arg1_srcFolder = new ParameterPanelFolder(
110                     i18n.getString("label.110") +": ", 
111                     params.getProperty(AppParameters.IMG_SOURCE_FOLDER)
112             );
113             arg1_srcFolder.argField
114                 .getDocument()
115                 .addDocumentListener(
116                     new SimpleDocumentListener() {
117                         @Override
118                         public void update(DocumentEvent e) {
119                             toEnable(0, arg1_srcFolder.isEnable());
120                         }
121                     }
122                 );
123    
124             Card card = new CardSourceFolder(cardPanel, arg1_srcFolder);
125             cardPanel.addTab(card.getTitle(), card);
126             cardPanel.setEnabledAt(cardNo, true);
127             cards[cardNo] = card;
128             cardNo++;
129         }
130
131         //---------------------------------------------------------------------
132         // 2. [基準画像(開始)]選択パネル
133         {
134             // 基準時刻画像
135             arg2_baseTimeImg = new ParameterPanelImageFile(
136                 i18n.getString("label.210") +": ", 
137                 null, 
138                 arg1_srcFolder
139             );
140             
141             // 2a. 基準時刻:
142             arg2_basetime = new ParameterPanelTime(
143                     i18n.getString("label.310"), 
144                     null, 
145                     arg2_baseTimeImg
146             );
147             arg2_basetime.argField.getDocument().addDocumentListener(
148                 new SimpleDocumentListener() {
149                     @Override
150                     public void update(DocumentEvent e) {
151                         toEnable(1, arg2_basetime.isEnable());
152                     }
153                 }
154             );
155             
156             CardImageFile card = new CardImageFile(
157                     cardPanel, arg2_basetime, (Window)this, 
158                     AdjustTime.i18n.getString("tab.restamp.200"), 0, 2);
159             cardPanel.addTab(card.getTitle(), card);
160             cardPanel.setEnabledAt(cardNo, false);
161             cards[cardNo] = card;
162             cardNo++;
163         }
164
165         //---------------------------------------------------------------------
166         // 3. 最終画像の本当の時刻を設定の入力画面
167         {
168             // 基準時刻画像
169             arg3_baseTimeImg = new ParameterPanelImageFile(
170                 i18n.getString("label.210") +": ", 
171                 null, 
172                 arg1_srcFolder
173             );
174             
175             // 3a. 基準時刻:
176             arg3_basetime = new ParameterPanelTime(
177                     i18n.getString("label.310"), 
178                     null, 
179                     arg3_baseTimeImg
180             );
181             arg3_basetime.argField.getDocument().addDocumentListener(
182                 new SimpleDocumentListener() {
183                     @Override
184                     public void update(DocumentEvent e) {
185                         toEnable(2, arg3_basetime.isEnable());
186                     }
187                 }
188             );
189             
190             CardImageFile card = new CardImageFile(
191                 cardPanel, arg3_basetime, (Window)this, 
192                 AdjustTime.i18n.getString("tab.restamp.250"), 1, 3
193             );
194             cardPanel.addTab(card.getTitle(), card);
195             cardPanel.setEnabledAt(cardNo, false);
196             cards[cardNo] = card;
197             cardNo++;
198         }
199         
200         //---------------------------------------------------------------------
201         // 4. 実行画面
202         {
203             CardPerformFile card = new CardPerformFile(
204                     cardPanel, 
205                     arg2_basetime,
206                     arg3_basetime
207             );
208             cardPanel.addTab(card.getTitle(), card);
209             cardPanel.setEnabledAt(cardNo, false);
210             cards[cardNo] = card;
211             cardNo++;
212         }
213         
214         //{{REGISTER_LISTENERS
215         SymWindow aSymWindow = new SymWindow();
216         this.addWindowListener(aSymWindow);
217         SymAction lSymAction = new SymAction();
218         closeButton.addActionListener(lSymAction);
219         //}}
220     }
221     
222     
223     void toEnable(final int cardNo, final boolean enable) {
224         if ((cardNo >= 0) && (cardNo < cards.length)) {
225             cardPanel.setEnabledAt(cardNo, enable);
226             if ((cardNo -1) >= 0) {
227                 cards[cardNo -1].nextButton.setEnabled(enable);
228             }
229             if ((cardNo +1) < cards.length) {
230                 cardPanel.setEnabledAt(cardNo+1, enable);
231                 cards[cardNo +1].backButton.setEnabled(enable);
232                 cards[cardNo].nextButton.setEnabled(enable);
233             }
234         }
235     }
236
237     @SuppressWarnings("OverridableMethodCallInConstructor")
238     public RestampDialog(Frame parent, String title, boolean modal) throws IOException {
239         this(parent, modal);
240         setTitle(title);
241     }
242
243     // Used for addNotify redundency check.
244     boolean fComponentsAdjusted = false;
245
246     @Override
247     public void addNotify() {
248         // Record the size of the window prior to calling parents addNotify.
249         super.addNotify();
250
251         // Only do this once.
252         if (fComponentsAdjusted) {
253             return;
254         }
255
256         // Adjust components according to the insets
257         setSize(getInsets().left + getInsets().right + getSize().width, getInsets().top + getInsets().bottom + getSize().height);
258         Component components[] = getComponents();
259         for (Component component : components) {
260             Point p = component.getLocation();
261             p.translate(getInsets().left, getInsets().top);
262             component.setLocation(p);
263         }
264
265         // Used for addNotify check.
266         fComponentsAdjusted = true;
267     }
268
269     /**
270     * Shows or hides the component depending on the boolean flag b.
271     * @param b  if true, show the component; otherwise, hide the component.
272     * @see java.awt.Component#isVisible
273     */
274     @Override
275     public void setVisible(boolean b) {
276         if(b) {
277             Rectangle bounds = getParent().getBounds();
278             Rectangle abounds = getBounds();
279             setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
280             bounds.y + (bounds.height - abounds.height)/2);
281         }
282         super.setVisible(b);
283     }
284 }