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 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      /* Whenever it gets resized remember */
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  }