View Javadoc

1   /*
2    *   Copyright 2004 The Apache Software Foundation
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
15   *
16   */
17  package org.apache.ldap.server.partition.impl.btree.gui ;
18  
19  
20  import java.awt.Dimension;
21  import java.awt.Toolkit;
22  
23  import javax.naming.NamingException;
24  
25  import org.apache.ldap.server.partition.impl.btree.BTreeContextPartition;
26  import org.apache.ldap.server.partition.impl.btree.SearchEngine;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  
31  /***
32   * A partition database viewer.
33   * 
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   * @version $Rev: 264732 $
36   */
37  public class PartitionViewer
38  {
39      private static final Logger log = LoggerFactory.getLogger(PartitionViewer.class);
40  
41      /*** A handle on the atomic partition */
42      private BTreeContextPartition partition;
43      private SearchEngine eng;
44  
45  
46      public PartitionViewer( BTreeContextPartition db, SearchEngine eng )
47      {
48          this.partition = db;
49          this.eng = eng;
50      }
51  
52  
53  //    /***
54  //     * Viewer main is not really used.
55  //     *
56  //     * @param argv the var args
57  //     */
58  //    public static void main( String [] argv )
59  //    {
60  //        // set up system Look&Feel
61  //        try
62  //        {
63  //            UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() ) ;
64  //        }
65  //        catch ( Exception e )
66  //        {
67  //            System.out.println( "Could not set look and feel to use " +
68  //                UIManager.getSystemLookAndFeelClassName() + "." ) ;
69  //            e.printStackTrace() ;
70  //        }
71  //
72  //        PartitionViewer viewer = new PartitionViewer(  ) ;
73  //
74  //        try
75  //        {
76  //            viewer.execute() ;
77  //        }
78  //        catch ( Exception e )
79  //        {
80  //            e.printStackTrace() ;
81  //            System.exit( -1 ) ;
82  //        }
83  //    }
84      
85  
86      public void execute() throws NamingException
87      {
88          MainFrame frame = new MainFrame( partition, eng ) ;
89  
90          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize() ;
91          Dimension frameSize = frame.getSize() ;
92          frameSize.height = ( ( frameSize.height > screenSize.height )
93              ? screenSize.height : frameSize.height) ;
94          frameSize.width = ( ( frameSize.width > screenSize.width )
95              ? screenSize.width : frameSize.width ) ;
96          frame.setLocation( ( screenSize.width - frameSize.width ) / 2,
97              ( screenSize.height - frameSize.height ) / 2) ;
98  
99          frame.setVisible( true );
100         log.debug( frameSize + "") ;
101     }
102 }