1 | // Jomic - a viewer for comic book archives. |
2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
3 | // |
4 | // This program is free software: you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by |
6 | // the Free Software Foundation, either version 3 of the License, or |
7 | // (at your option) any later version. |
8 | // |
9 | // This program is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // GNU General Public License for more details. |
13 | // |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | package net.sf.jomic.ui; |
17 | |
18 | import java.awt.Component; |
19 | import java.awt.event.ComponentEvent; |
20 | import java.awt.event.ComponentListener; |
21 | |
22 | import javax.swing.JDialog; |
23 | import javax.swing.JFileChooser; |
24 | |
25 | import net.sf.jomic.tools.BasicSettings; |
26 | |
27 | /** |
28 | * JFileChooser that remembers own location and dimension. |
29 | * |
30 | * @author Thomas Aglassinger |
31 | */ |
32 | public class SnapableJFileChooser extends JFileChooser implements ComponentListener |
33 | { |
34 | private String areaProperty; |
35 | private BasicSettings settings; |
36 | |
37 | /** |
38 | * Create a new JFileChooser that remembers location and dimension in <code>newSettings</code> |
39 | * using the property <code>newAreaProperty</code>. |
40 | * |
41 | * @param newSettings Description of the parameter |
42 | * @param newAreaProperty Description of the parameter |
43 | */ |
44 | public SnapableJFileChooser(BasicSettings newSettings, String newAreaProperty) { |
45 | super(); |
46 | assert newSettings != null; |
47 | assert newAreaProperty != null; |
48 | settings = newSettings; |
49 | areaProperty = newAreaProperty; |
50 | } |
51 | |
52 | public void componentHidden(ComponentEvent event) { |
53 | // Do nothing. |
54 | } |
55 | |
56 | public void componentMoved(ComponentEvent event) { |
57 | // Do nothing. |
58 | } |
59 | |
60 | public void componentResized(ComponentEvent event) { |
61 | settings.setComponentAreaProperty(areaProperty, event.getComponent()); |
62 | } |
63 | |
64 | public void componentShown(ComponentEvent event) { |
65 | // Do nothing. |
66 | } |
67 | |
68 | protected JDialog createDialog(Component component) { |
69 | JDialog result = super.createDialog(component); |
70 | |
71 | settings.applyComponentAreaProperty(areaProperty, result); |
72 | result.addComponentListener(this); |
73 | return result; |
74 | } |
75 | } |