All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.rinde.rinsim.examples.demo.Demo Maven / Gradle / Ivy

/*
 * Copyright (C) 2011-2017 Rinde van Lon, imec-DistriNet, KU Leuven
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.rinde.rinsim.examples.demo;

import static com.google.common.base.Verify.verifyNotNull;
import static com.google.common.collect.Lists.newArrayList;

import java.io.IOException;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nullable;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.github.rinde.rinsim.core.Simulator;
import com.github.rinde.rinsim.examples.core.taxi.TaxiExample;
import com.github.rinde.rinsim.examples.demo.factory.FactoryExample;
import com.google.common.collect.ImmutableList;
import com.google.common.math.DoubleMath;

/**
 * @author Rinde van Lon
 *
 */
public final class Demo {

  static final int TIME_TEXT_WIDTH = 40;
  static final int RUN_BUTTON_W = 300;
  static final int RUN_BUTTON_H = 100;
  static final int START_BUTTON_FONT_SIZE = 60;
  static final int NEXT_BUTTON_FONT_SIZE = 40;
  static final String START_DEMO_TEXT = "Start demo";

  private Demo() {}

  /**
   * Runs the demo.
   * @param args Ignored.
   * @throws IOException Should not happen.
   * @throws InterruptedException Should not happen.
   */
  public static void main(String[] args) throws IOException,
      InterruptedException {

    Display.setAppName("RinSim");
    final Display d = new Display();

    final List demoRunners = newArrayList();

    final Shell shell = new Shell(d, SWT.TITLE | SWT.CLOSE | SWT.RESIZE);
    shell.setText("AgentWise Demo Control Center™");
    shell.setLayout(new RowLayout(SWT.VERTICAL));

    final Monitor primary = d.getPrimaryMonitor();
    shell.setLocation(primary.getClientArea().x, primary.getClientArea().y);
    shell.setSize(primary.getClientArea().width,
      primary.getClientArea().height);

    final Composite controlsComposite = new Composite(shell, SWT.NONE);
    controlsComposite.setLayout(new RowLayout(SWT.HORIZONTAL));

    final Label timeLabel = new Label(controlsComposite, SWT.NONE);
    timeLabel.setText("End simulation time (in hours): ");

    final Text timeText = new Text(controlsComposite, SWT.NONE);
    timeText.setText("6.0");
    timeText.setLayoutData(new RowData(TIME_TEXT_WIDTH, SWT.DEFAULT));

    timeText.addListener(SWT.Verify, new TimeTextVerifier(demoRunners));
    final List




© 2015 - 2025 Weber Informatics LLC | Privacy Policy