OSDN Git Service

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