Home | History | Annotate | Download | only in hierarchyviewer
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      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 com.android.hierarchyviewer;
     18 
     19 import com.android.hierarchyviewer.ui.Workspace;
     20 import com.android.hierarchyviewer.device.DeviceBridge;
     21 
     22 import javax.swing.SwingUtilities;
     23 import javax.swing.UIManager;
     24 import javax.swing.UnsupportedLookAndFeelException;
     25 
     26 public class HierarchyViewer {
     27     private static final CharSequence OS_WINDOWS = "Windows";
     28     private static final CharSequence OS_MACOSX = "Mac OS X";
     29 
     30     private static boolean sProfilingEnabled = true;
     31 
     32     public static boolean isProfilingEnabled() {
     33         return sProfilingEnabled;
     34     }
     35 
     36     private static void initUserInterface() {
     37         System.setProperty("apple.laf.useScreenMenuBar", "true");
     38         System.setProperty("apple.awt.brushMetalLook", "true");
     39         System.setProperty("com.apple.mrj.application.apple.menu.about.name", "HierarchyViewer");
     40 
     41         final String os = System.getProperty("os.name");
     42 
     43         try {
     44             if (os.contains(OS_WINDOWS) || os.contains(OS_MACOSX)) {
     45                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
     46             } else {
     47                 UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
     48             }
     49         } catch (ClassNotFoundException e) {
     50             e.printStackTrace();
     51         } catch (InstantiationException e) {
     52             e.printStackTrace();
     53         } catch (IllegalAccessException e) {
     54             e.printStackTrace();
     55         } catch (UnsupportedLookAndFeelException e) {
     56             e.printStackTrace();
     57         }
     58     }
     59 
     60     public static void main(String[] args) {
     61         if (args.length > 0) {
     62             sProfilingEnabled = !args[0].equalsIgnoreCase("-profiling=false");
     63         }
     64 
     65         initUserInterface();
     66         DeviceBridge.initDebugBridge();
     67 
     68         SwingUtilities.invokeLater(new Runnable() {
     69             public void run() {
     70                 Workspace workspace = new Workspace();
     71                 workspace.setDefaultCloseOperation(Workspace.EXIT_ON_CLOSE);
     72                 workspace.setLocationRelativeTo(null);
     73                 workspace.setVisible(true);
     74             }
     75         });
     76     }
     77 }
     78