ClassSpaceChecker::ClassSpaceChecker(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags), prevJdProcessId_(0), initJarFileComboFlag_(false), freezeSearchClassNameFlag_(false), srcViewer_(NULL)
{
	gSettingManager.setIniPath(qApp->applicationDirPath() + QDir::separator() + "data.ini");

	ui.setupUi(this);
	ui.tableWidgetResult->horizontalHeader()->setResizeMode( QHeaderView::Interactive );

	ui.tableWidgetResult->setColumnCount(5);
	ui.tableWidgetResult->setHorizontalHeaderLabels(QString("Class Name;File Size;Uncrypted Name;Method Count;Referenced Count;").split(";"));  
	ui.tableWidgetResult->horizontalHeader()->setResizeMode( QHeaderView::Interactive );

	ui.tableWidgetPackageReport->setColumnCount(6);
	ui.tableWidgetPackageReport->setHorizontalHeaderLabels(QString("Package Name;All Class Count;Unique Count;Anonymous Count;Diff Count;File Size").split(";"));  
	ui.tableWidgetPackageReport->horizontalHeader()->setResizeMode( QHeaderView::Interactive );

	ui.tableWidgetInnerClassReport->setColumnCount(4);
	ui.tableWidgetInnerClassReport->setHorizontalHeaderLabels(QString("Class Name;Inner Count;Anonymous Count;File Size").split(";"));  
	ui.tableWidgetInnerClassReport->horizontalHeader()->setResizeMode( QHeaderView::Interactive );

	ui.comboBox_JarFile->lineEdit()->setPlaceholderText("Jar File (Drag&Drop supported)");
	ui.comboBox_JarFile->installEventFilter( this );
	ui.lineEdit_MapFile->setDragEnabled(true);
	ui.lineEdit_MapFile->installEventFilter( this );
	ui.tableWidgetResult->installEventFilter( this );

	ui.lineEdit_Result->setText("Press Analysis button first.");

	updateWindowTitle();

	loadPresetList(gSettingManager.getLastPresetId());

	loadPreset(gSettingManager.getLastPresetId());

	if(ui.comboBox_JarFile->currentText().isEmpty() && ui.lineEdit_MapFile->text().isEmpty())
	{
		// To show placeholder text at initial launch time
		ui.pushButtonStart->setFocus();
	}

	buildStatusBar();
}
/**
 * cbSimulatorGUI contructor.
 */
cbSimulatorGUI::cbSimulatorGUI( cbSimulator *sim, QWidget* parent, Qt::WFlags fl ) :
    QMainWindow(parent, fl), simulator (sim),
    ui(new Ui::cbSimulatorGUI)
{
    ui->setupUi(this);

    this->tabifyDockWidget(ui->dockWidget_Score, ui->dockWidget_Mailbox);
    ui->dockWidget_Score->raise();

    buildStatusBar();

    simTime = simulator->simTime();
    ui->lcdNumber_TimeRemain->display(simTime);
    connect(simulator, SIGNAL(simTimeChanged(int)), SLOT(setSimTime(int)));
    connect(simulator, SIGNAL(curTimeChanged(int)), SLOT(setRemainTime(int)));

    ui->actionGPS_Enabled->setChecked(cbRobot::GPSOn);
    ui->actionScore_Sensor_Enabled->setChecked(simulator->getScoreSensor());
    ui->actionTime_Enabled->setChecked(simulator->isTimed());
    ui->actionRegistrations_Open->setChecked(simulator->isRegistrationAllowed());
    ui->actionCollisions_Enabled->setChecked(!simulator->collisionsIgnored());

    connect(simulator, SIGNAL(toggleGPS(bool)), ui->actionGPS_Enabled, SLOT(setChecked(bool)));
    connect(simulator, SIGNAL(toggleScoreSensor(bool)), ui->actionScore_Sensor_Enabled, SLOT(setChecked(bool)));
    connect(simulator, SIGNAL(toggleTime(bool)), ui->actionTime_Enabled, SLOT(setChecked(bool)));
    connect(simulator, SIGNAL(toggleRegistrations(bool)), ui->actionRegistrations_Open, SLOT(setChecked(bool)));
    connect(simulator, SIGNAL(toggleCollisions(bool)), ui->actionCollisions_Enabled, SLOT(setChecked(bool)));

    this->startNext = true;
    connect(simulator, SIGNAL(simReady(bool)), ui->actionStartStop, SLOT(setEnabled(bool)));
    connect(simulator, SIGNAL(simRunning(bool)), SLOT(setStartStopButton(bool)));

    connect(simulator, SIGNAL(simReset(bool)), ui->actionRegistrations_Open, SLOT(setDisabled(bool)));
    connect(simulator, SIGNAL(simReset(bool)), ui->actionRegistrations_Open, SLOT(setChecked(bool)));

    actionStart = new QAction(this);
    actionStop = new QAction(this);
    connect(actionStart, SIGNAL(triggered()), simulator, SLOT(start()));
    connect(actionStop, SIGNAL(triggered()), simulator, SLOT(stop()));
    connect(ui->actionReset, SIGNAL(triggered()), simulator, SLOT(reset()));

    connect(ui->actionGPS_Enabled, SIGNAL(toggled(bool)), simulator, SLOT(setGPS(bool)));
    connect(ui->actionScore_Sensor_Enabled, SIGNAL(toggled(bool)), simulator, SLOT(setScoreSensor(bool)));
    connect(ui->actionRegistrations_Open, SIGNAL(toggled(bool)), simulator, SLOT(setRegistrations(bool)));
    connect(ui->actionTime_Enabled, SIGNAL(toggled(bool)), simulator, SLOT(setTime(bool)));
    connect(ui->actionCollisions_Enabled, SIGNAL(toggled(bool)), simulator, SLOT(setCollisions(bool)));

    connect( ui->actionExit, SIGNAL( triggered() ), qApp, SLOT( closeAllWindows() ) );

    connect(&viewerProc, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processViewerError(QProcess::ProcessError)));
    connect(&viewerProc, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(handleViewerExit(int,QProcess::ExitStatus)));

    agentModel = new QStringListModel(this);
    manRobDialog = new cbManageRobots (simulator, agentModel, this, Qt::Dialog);
    connect(ui->actionManageRobots, SIGNAL(toggled(bool)), manRobDialog, SLOT(setVisible(bool)));
    connect(manRobDialog, SIGNAL(closed()), ui->actionManageRobots, SLOT(toggle()));
    controlPanel = new cbControlPanel(simulator, agentModel, 0, Qt::Tool | Qt::WindowStaysOnTopHint | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint);
    connect(ui->actionControl_Panel, SIGNAL(toggled(bool)), controlPanel, SLOT(setVisible(bool)));
    connect(controlPanel, SIGNAL(closed()), ui->actionControl_Panel, SLOT(toggle()));

    nRobots = simulator->Robots().size();
    robotScores.resize(nRobots);
    resetRobWidgets(nRobots);
    connect(simulator, SIGNAL(gridChanged(int)), SLOT(resetRobWidgets(int)));
    connect(simulator, SIGNAL(robotRegistered(int)), SLOT(addRobWidget(int)));
    connect(simulator, SIGNAL(robotDeleted(int)), SLOT(removeRobWidget(int)));

    connect(ui->checkBox_Actions, SIGNAL(toggled(bool)), simulator, SLOT(setShowActions(bool)));
    connect(ui->checkBox_Measures, SIGNAL(toggled(bool)), simulator, SLOT(setShowMeasures(bool)));
    connect(ui->checkBox_Positions, SIGNAL(toggled(bool)), simulator, SLOT(setShowPositions(bool)));


    connect(ui->pushButton_ClearMailBox, SIGNAL(clicked()), ui->textEdit_Mailbox, SLOT(clear()));

    appendMessage("Welcome, " + QDir::home().dirName());

    labDialog = new cbLabDialog(simulator, this);

    this->adjustSize();

}