View Javadoc

1   package com.explosion.utilities.preferences.groups.dialogs;
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.BorderLayout;
24  import java.awt.Dialog;
25  import java.awt.Dimension;
26  import java.awt.Frame;
27  import java.util.Vector;
28  
29  import javax.swing.JScrollPane;
30  
31  import com.explosion.utilities.preferences.dialogs.PreferencesTable;
32  import com.explosion.utilities.preferences.dialogs.TableBasedPreferenceEditorDialog;
33  import com.explosion.utilities.preferences.groups.PreferenceGroup;
34  
35  /***
36   * @author Stephen Cowx Date created:@25-Jan-2003
37   * This displays all of the preferences in the group in a table, ready for editing
38   */
39  public class PreferenceGroupEditDialog extends TableBasedPreferenceEditorDialog
40  {
41  
42      private PreferenceGroup preferenceGroup;
43  
44      private PreferencesTable table;
45      
46      public static Dimension editorDimension = new Dimension(400, 250);
47  
48      public PreferenceGroupEditDialog(Dialog owner, String title, boolean editable)
49      {
50          super(owner, title, false, editable);
51          super.setLocationRelativeTo(owner);
52      }
53  
54      public PreferenceGroupEditDialog(Frame owner, String title, boolean editable)
55      {
56          super(owner, title, false, editable);
57          super.setLocationRelativeTo(owner);
58      }
59  
60      public void loadPreferences(Object preferences)
61      {
62          try
63          {
64              this.preferenceGroup = (PreferenceGroup) preferences;
65              Vector dataTables = new Vector();
66              JScrollPane scrollPane = new JScrollPane();
67              this.configPanel.add(scrollPane, BorderLayout.CENTER);
68              table = new PreferencesTable(preferenceGroup.getPreferencesVector(), this, this);
69              
70              dataTables.addElement(table);
71              scrollPane.getViewport().add(table);
72              table.setTableHeader(null);
73              
74              this.setDataTables(dataTables);
75          } catch (Exception e)
76          {
77              com.explosion.utilities.exception.ExceptionManagerFactory.getExceptionManager().manageException(e, null);
78          }
79      }
80  
81      public PreferenceGroup getPersistentDescriptor()
82      {
83          return this.preferenceGroup;
84      }
85  
86      /***
87       * This method saves the properties to persistent storage and calls the
88       * application.applyPreferences method
89       */
90      public void apply()
91      {
92          try
93          {
94              preferenceGroup.commit();
95          } catch (Exception e)
96          {
97              com.explosion.utilities.exception.ExceptionManagerFactory.getExceptionManager().manageException(e, null);
98          }
99      }
100 
101 }
102