View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.core.partition.impl.btree.gui;
21  
22  
23  import java.awt.Dimension;
24  import java.awt.Toolkit;
25  
26  import org.apache.directory.server.core.partition.impl.btree.BTreePartition;
27  import org.apache.directory.server.schema.registries.Registries;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  
32  /**
33   * A partition database viewer.
34   * 
35   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
36   * @version $Rev: 690042 $
37   */
38  public class PartitionViewer
39  {
40      private static final Logger LOG = LoggerFactory.getLogger( PartitionViewer.class );
41  
42      /** A handle on the atomic partition */
43      private BTreePartition partition;
44      
45      /** A handle on the global registries */
46      private Registries registries;
47  
48  
49      public PartitionViewer( BTreePartition db, Registries registries )
50      {
51          this.partition = db;
52          this.registries = registries;
53      }
54  
55  
56      // added return value so expressions in debugger does not freak with void
57      public int execute() throws Exception
58      {
59          Thread t = new Thread( new Runnable() {
60              public void run()
61              {
62                  PartitionFrame frame = null;
63                  try
64                  {
65                      frame = new PartitionFrame( PartitionViewer.this.partition, registries );
66                  }
67                  catch ( Exception e )
68                  {
69                      e.printStackTrace();
70                      return;
71                  }
72                  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
73                  Dimension frameSize = frame.getSize();
74                  frameSize.height = ( ( frameSize.height > screenSize.height ) ? screenSize.height : frameSize.height );
75                  frameSize.width = ( ( frameSize.width > screenSize.width ) ? screenSize.width : frameSize.width );
76                  frame.setLocation( ( screenSize.width - frameSize.width ) / 2, ( screenSize.height - frameSize.height ) / 2 );
77  
78                  frame.setVisible( true );
79                  LOG.debug( frameSize + "" );
80              }
81          });
82  
83          t.run();
84          return 0;
85      }
86  }