View Javadoc

1   package com.explosion.expf.preferences.Utils;
2   
3   /*
4    * =============================================================================
5    * 
6    * Copyright 2004 Stephen Cowx
7    * 
8    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
9    * use this file except in compliance with the License. You may obtain a copy of
10   * the License at
11   * 
12   * http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
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      /* Whenever it gets moved remember */
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  }