001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2015 the original author or authors. 004// 005// This library is free software; you can redistribute it and/or 006// modify it under the terms of the GNU Lesser General Public 007// License as published by the Free Software Foundation; either 008// version 2.1 of the License, or (at your option) any later version. 009// 010// This library is distributed in the hope that it will be useful, 011// but WITHOUT ANY WARRANTY; without even the implied warranty of 012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013// Lesser General Public License for more details. 014// 015// You should have received a copy of the GNU Lesser General Public 016// License along with this library; if not, write to the Free Software 017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018//////////////////////////////////////////////////////////////////////////////// 019 020package com.puppycrawl.tools.checkstyle.gui; 021 022import java.awt.EventQueue; 023import java.io.File; 024 025import javax.swing.JFrame; 026import javax.swing.WindowConstants; 027 028import com.puppycrawl.tools.checkstyle.api.DetailAST; 029 030/** 031 * Entry point for starting the checkstyle GUI. 032 * 033 * @author unknown 034 */ 035public final class Main { 036 037 /** Frame's name. */ 038 private static final String FRAME_NAME = "CheckStyle"; 039 040 /** Main frame. */ 041 private static JFrame frame; 042 043 /** Hidden constructor of the current utility class. */ 044 private Main() { 045 // no code 046 } 047 048 /** 049 * Entry point. 050 * @param args the command line arguments. 051 */ 052 public static void main(String... args) { 053 frame = new JFrame(FRAME_NAME); 054 final ParseTreeInfoPanel panel = new ParseTreeInfoPanel(); 055 frame.getContentPane().add(panel); 056 if (args.length >= 1) { 057 final File file = new File(args[0]); 058 panel.openFile(file, frame); 059 } 060 frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 061 062 final Runnable runner = new FrameShower(frame); 063 EventQueue.invokeLater(runner); 064 } 065 066 /** 067 * Method is used for testing in the past. 068 * @param ast tree to display 069 */ 070 public static void displayAst(DetailAST ast) { 071 final JFrame testFrame = new JFrame(FRAME_NAME); 072 final ParseTreeInfoPanel panel = new ParseTreeInfoPanel(); 073 testFrame.getContentPane().add(panel); 074 panel.openAst(ast); 075 testFrame.setSize(1500, 800); 076 testFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 077 testFrame.setVisible(true); 078 } 079 080 /** 081 * @return Main GUI's frame. 082 */ 083 static JFrame getFrame() { 084 return frame; 085 } 086 087 /** 088 * Http://findbugs.sourceforge.net/bugDescriptions.html#SW_SWING_METHODS_INVOKED_IN_SWING_THREAD 089 */ 090 private static class FrameShower implements Runnable { 091 /** 092 * Frame. 093 */ 094 private final JFrame frame; 095 096 /** 097 * @param frame JFrame component. 098 */ 099 FrameShower(JFrame frame) { 100 this.frame = frame; 101 } 102 103 /** 104 * Display a frame. 105 */ 106 @Override 107 public void run() { 108 frame.pack(); 109 frame.setVisible(true); 110 } 111 } 112}