1 package com.explosion.expf.preferences.Utils;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.awt.Component;
24 import java.awt.event.ComponentEvent;
25 import java.awt.event.ComponentListener;
26
27 import org.apache.log4j.LogManager;
28 import org.apache.log4j.Logger;
29
30 import com.explosion.utilities.exception.ExceptionManagerFactory;
31 import com.explosion.utilities.preferences.Preference;
32
33 public class PreferenceResizeRecorder implements ComponentListener
34 {
35
36 private static Logger log = LogManager.getLogger(PreferenceResizeRecorder.class);
37
38 private Preference height = null;
39
40 private Preference width = null;
41
42 private Component component = null;
43
44 public PreferenceResizeRecorder(Preference height, Preference width, Component component)
45 {
46 if (height == null || width == null)
47 throw new IllegalArgumentException("Height and width must both not be null");
48
49 this.height = height;
50 this.width = width;
51 this.component = component;
52 }
53
54
55 public void componentResized(ComponentEvent e)
56 {
57 try
58 {
59 log.debug("Setting height and width of component " + component);
60 height.setValue(new Integer((int) component.getSize().getHeight()));
61 height.save();
62 width.setValue(new Integer((int) component.getSize().getWidth()));
63 width.save();
64 } catch (Exception ex)
65 {
66 ExceptionManagerFactory.getExceptionManager().manageException(ex, "Exception caught while saving size settings.");
67 }
68 }
69
70 public void componentMoved(ComponentEvent e)
71 {}
72
73 public void componentShown(ComponentEvent e)
74 {}
75
76 public void componentHidden(ComponentEvent e)
77 {}
78
79 }