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 PreferencePositionRecorder implements ComponentListener
34 {
35
36 private static Logger log = LogManager.getLogger(PreferencePositionRecorder.class);
37
38 private Preference xpos = null;
39
40 private Preference ypos = null;
41
42 private Component component = null;
43
44 public PreferencePositionRecorder(Preference xpos, Preference ypos, Component component)
45 {
46 if (xpos == null || ypos == null)
47 throw new IllegalArgumentException("X position and Y position must both not be null");
48
49 this.xpos = xpos;
50 this.ypos = ypos;
51 this.component = component;
52 }
53
54 public void componentResized(ComponentEvent e)
55 {
56 }
57
58
59 public void componentMoved(ComponentEvent e)
60 {
61 try
62 {
63 log.debug("Setting X and Y of component " + component);
64 xpos.setValue(new Integer((int) component.getX()));
65 xpos.save();
66 ypos.setValue(new Integer((int) component.getY()));
67 ypos.save();
68 } catch (Exception ex)
69 {
70 ExceptionManagerFactory.getExceptionManager().manageException(ex, "Exception caught while saving size settings.");
71 }
72 }
73
74 public void componentShown(ComponentEvent e)
75 {}
76
77 public void componentHidden(ComponentEvent e)
78 {}
79
80 }