示例#1
0
  /*
      public String getWindowTitle ()
      {

          return "What's new in this version - " + Environment.getQuollWriterVersion ();

      }

      public String getHeaderTitle ()
      {

          return this.getWindowTitle ();

      }

      public String getHeaderIconType ()
      {

          return null;//"whatsnew";

      }
  */
  public String getFirstHelpText() {

    return String.format(
        "Welcome to version <b>%s</b>.  This window describes the various changes that have been made since the last version and lets you setup new features.  You can also see the <a href='help://version-changes/%s'>full list of changes online</a>.",
        Environment.getQuollWriterVersion().getVersion(),
        Environment.getQuollWriterVersion().getVersion().replace('.', '_'));
  }
 // paints the player, items, and rooms
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Environment Layout = new Environment();
   Layout.drawRoom(mapX, mapY, g);
   Player PlayerSprite = new Player();
   PlayerSprite.drawPlayer(x, y, g);
   Layout.items(x, y, g, getItem);
 }
 // creates the JFrame, and puts first room onto panel
 public static void main(String[] s) throws IOException {
   JFrame f = new JFrame();
   f.getContentPane().add(new Adventure());
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   f.pack();
   f.setVisible(true);
   Environment Layout = new Environment();
   wallLayout = Layout.walls(mapX, mapY);
 }
示例#4
0
  public void init() {

    super.init();

    try {

      Environment.setUserProperty(
          Constants.WHATS_NEW_VERSION_VIEWED_PROPERTY_NAME,
          new StringProperty(
              Constants.WHATS_NEW_VERSION_VIEWED_PROPERTY_NAME,
              Environment.getQuollWriterVersion().getVersion()));

    } catch (Exception e) {

      Environment.logError("Unable to set the whats new version viewed property", e);
    }
  }
示例#5
0
  public StackTraceTool(Environment env) {

    super(new BorderLayout());

    this.env = env;
    this.runtime = env.getExecutionManager();
    this.context = env.getContextManager();

    stackModel = new DefaultListModel(); // empty

    list = new JList(stackModel);
    list.setCellRenderer(new StackFrameRenderer());

    JScrollPane listView = new JScrollPane(list);
    add(listView);

    // Create listener.
    StackTraceToolListener listener = new StackTraceToolListener();
    context.addContextListener(listener);
    list.addListSelectionListener(listener);

    // ### remove listeners on exit!
  }
 // takes keyboard input to move player around, and to different rooms
 public void keyTyped(KeyEvent e) {
   c = e.getKeyChar();
   repaint();
   g = this.getGraphics();
   Environment Layout = new Environment();
   if (Layout.isWall(x, y, c, wallLayout)) {
   } else {
     if (c == 'a') {
       x = x - 3;
     } else if (c == 'w') {
       y = y - 3;
     } else if (c == 's') {
       y = y + 3;
     } else if (c == 'd') {
       x = x + 3;
     } else if (c == 'e') {
       getItem = !getItem;
     }
     int yDoor = Layout.isDoor(x, y, c, 'y', wallLayout);
     int xDoor = Layout.isDoor(x, y, c, 'x', wallLayout);
     if (xDoor != 0 || yDoor != 0) {
       mapY = mapY + yDoor;
       mapX = mapX + xDoor;
       wallLayout = Layout.walls(mapX, mapY);
       Layout.drawRoom(mapX, mapY, g);
       if (xDoor == -1) {
         x = 760;
       } else if (xDoor == 1) {
         x = 40;
       } else if (yDoor == -1) {
         y = 460;
       } else if (yDoor == 1) {
         y = 40;
       }
     }
   }
 }
    /*
     * Completely erases the current state of the Simulation
     */
    public void reset() {
      e.purgeAgents();
      paint.clearHistory();
      children.clear();
      fillWithAgents();

      Agent a = new Agent();
      a.setName("My Agent");
      a.setChrome("000 000 000 000 000 000 000 011 011 011 011 011 100 101 101 101");
      children.add(a);

      cur_gen = 0;
      current_elite = null;
      prev_elite_total = 0;
      running = true;
    }
  public BizSimMain(int numThreads, int numAgents, int numGenerations) {

    // configure our main window which will contain all the other elements
    JFrame control_window = new JFrame();
    control_window.setTitle("Control Suite");
    control_window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    control_window.setSize(new Dimension(800, 480));
    // control_window.setAlwaysOnTop(true);
    control_window.setLayout(new BorderLayout());

    JPanel species_control = new JPanel();
    JLabel species_list_l = new JLabel("Species Running");
    DefaultListModel species_list = new DefaultListModel();

    // create our Environment
    Environment e = new Environment();

    // create all our threads
    for (int kittehsex = 0; kittehsex < numThreads; ++kittehsex) {

      // create some test agents
      ArrayList<Agent> agents = new ArrayList<Agent>();
      for (int i = 0; i < numAgents; ++i) {
        agents.add(new Agent());
      }

      // create our new thread and pass in some control variables
      ProcessSimulator ps = new ProcessSimulator(agents, numGenerations, kittehsex, e, this);
      Thread t = new Thread(ps);
      species.add(ps);

      // update our current species list
      species_list.addElement("Species #" + kittehsex);

      // set the thread to a high priority, and then start it
      t.setPriority(9);
      t.start();
    }

    // create a selectable list of all the different species we have
    JList species_select_list = new JList(species_list);
    species_select_list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    species_select_list.setLayoutOrientation(JList.VERTICAL);
    species_select_list.setVisibleRowCount(3);

    // start listening to all buttons
    start_stop.addActionListener(this);
    reset.addActionListener(this);
    reconfigure.addActionListener(this);

    // add mnemonics to some buttons
    start_stop.setMnemonic('s');
    reset.setMnemonic('r');
    reconfigure.setMnemonic('e');

    // create a panel for all our environment variables
    JPanel environment_controls = new JPanel();
    environment_controls.setBorder(BorderFactory.createTitledBorder("Modify Finished Good Values"));
    environment_controls.setLayout(new GridLayout(3, 4));
    environment_controls.add(new JLabel("High Rate:"));
    environment_controls.add(high_rate);
    environment_controls.add(new JLabel("High Sale:"));
    environment_controls.add(high_sale);
    environment_controls.add(new JLabel("Med Rate:"));
    environment_controls.add(med_rate);
    environment_controls.add(new JLabel("Med Sale:"));
    environment_controls.add(med_sale);
    environment_controls.add(new JLabel("Low Rate:"));
    environment_controls.add(low_rate);
    environment_controls.add(new JLabel("Low Sale:"));
    environment_controls.add(low_sale);

    // create a panel for all our simulation variables
    JPanel simulation_controls = new JPanel();
    simulation_controls.setBorder(BorderFactory.createTitledBorder("Modify Simulation Controls"));
    simulation_controls.setLayout(new GridLayout(6, 2));
    simulation_controls.add(new JLabel("Agent Count:"));
    simulation_controls.add(agent_count);
    simulation_controls.add(new JLabel("Generation Count:"));
    simulation_controls.add(generation_count);
    simulation_controls.add(new JLabel("Elite Percent"));
    simulation_controls.add(elite_percent);
    simulation_controls.add(new JLabel("Parent Percent"));
    simulation_controls.add(parent_percent);
    simulation_controls.add(new JLabel("Agent Performance"));
    simulation_controls.add(agent_performance);

    // create a panel for displaying information about the current elite
    // agent
    JPanel elite_panel = new JPanel();
    elite_panel.setBorder(BorderFactory.createTitledBorder("Current Elite Agent Performance"));
    elite_panel.setLayout(new GridLayout(2, 2));
    elite_panel.add(new JLabel("Total: "));
    elite_panel.add(cur_elite_total);
    elite_panel.add(new JLabel("Genome: "));
    JScrollPane genome_scroll = new JScrollPane(cur_elite_genome);
    elite_panel.add(genome_scroll);

    // this panel encompasses the different panels for altering and showing
    // the current state of the simulation
    JPanel field_controls = new JPanel();
    field_controls.setLayout(new GridLayout(2, 2));
    field_controls.add(environment_controls);
    field_controls.add(simulation_controls);
    field_controls.add(elite_panel);

    // set some attributes on misc. GUI stuff
    cur_elite_genome.setWrapStyleWord(true);
    cur_elite_genome.setEditable(false);
    cur_elite_genome.setLineWrap(true);

    // set the size of the button to just 3 characters
    high_rate.setColumns(3);
    high_sale.setColumns(3);
    med_rate.setColumns(3);
    med_sale.setColumns(3);
    low_rate.setColumns(3);
    low_sale.setColumns(3);

    // set the current value of our fields to the current environment value
    high_rate.setText(e.getHQRate() + "");
    high_sale.setText(e.getHQSale() + "");
    med_rate.setText(e.getMQRate() + "");
    med_sale.setText(e.getMQSale() + "");
    low_rate.setText(e.getLQRate() + "");
    low_sale.setText(e.getLQSale() + "");

    // set the default value of our fields to the current simulation values
    day_count.setText("100");
    generation_count.setText(numGenerations + "");
    elite_percent.setText(".05");
    parent_percent.setText(".8");
    agent_count.setText(numAgents + "");
    agent_performance.setText(e.getIncomeRatioThreshold() + "");

    // create a panel for all our flow control buttons
    JPanel control_flow_buttons = new JPanel();
    control_flow_buttons.setLayout(new GridLayout(1, 6));
    control_flow_buttons.add(start_stop);
    control_flow_buttons.add(reset);
    control_flow_buttons.add(reconfigure);

    // add our components to the window
    species_control.add(species_list_l);
    species_control.add(species_select_list);
    control_window.add(species_control, BorderLayout.WEST);
    control_window.add(field_controls, BorderLayout.CENTER);
    control_window.add(control_flow_buttons, BorderLayout.SOUTH);
    control_window.setLocation(620, 0);
    control_window.setVisible(true);
  }
    public void run() {

      // keep the thread alive
      while (true) {

        // wait for a signal to re-continue processing agents
        if (!running) {
          synchronized (this) {
            try {
              wait();
            } catch (InterruptedException ie) {
              System.err.println("ERROR: wait() call failed" + ie);
            }
          }
        }

        // run for the number of generations specified
        while (cur_gen < generations && running) {

          // create our list of agents
          e.purgeAgents();
          e.addAgents(children);

          // Process 100-days
          for (int i = 0; i < day_count; i++) {
            e.simulateDay();
          }

          // record this generation
          history.addGeneration(children);

          // sort the results by money, descending
          Collections.sort(children);
          Collections.reverse(children);

          // if the elite total changed, alert the main class
          int elite_most_money = children.get(0).getMoney();
          if (elite_most_money > prev_elite_total) {

            // cache the new elite total
            prev_elite_total = elite_most_money;
            current_elite = children.get(0);

            ep.setNewElite(current_elite);
            ep.repaint();

            // fire an event to the main class
            listener.actionPerformed(
                new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "elite_total"));
          }

          // now we need to select agents for crossover, mutation,
          // and elites for elites, keep the first x%
          List<Agent> elites = children.subList(0, (int) (children.size() * elite_percent));

          // for parents to keep, simply choose the top y%
          // (including the elites)
          List<Agent> parents = children.subList(0, (int) (children.size() * parent_percent));

          // create some children, and perform mutations
          children = evo.performCrossover(parents);
          children = evo.performMutation(children);

          // add the elite agents into the pool
          children.addAll(elites);

          // System.out.println(elites.get(0) + ": " + elites.get(0).getMoney());

          // reset the elites for the next generation
          for (Agent elitea : elites) elitea.reset();

          // repopulate the next generation with new Agents
          fillWithAgents();

          cur_gen++;
        }
        running = false;
      }
    }
  public void actionPerformed(ActionEvent e) {

    // dump ActionEvent information
    Object src = e.getSource();
    String msg = e.getActionCommand();

    if (src == start_stop) {

      // tell all threads to continue/resume operation
      for (ProcessSimulator ps : species)
        if (ps.toggleRunning())
          synchronized (ps) {
            ps.notify();
          }
      System.out.println("Started/Stopped Simulator...");
    } else if (src == reset) {
      for (ProcessSimulator ps : species) {
        if (!ps.isRunning()) {
          ps.reset();
          synchronized (ps) {
            ps.notify();
          }
        }
      }

      // clear the Elite Agent data
      cur_elite_genome.setText("");
      cur_elite_total.setText("");

      System.out.println("Simulation Reset...");
    } else if (src == reconfigure) {

      // create a new environment with the new parameters
      Environment environment = new Environment();

      // override existing values
      environment.setHQSale(Integer.parseInt(high_sale.getText()));
      environment.setHQRate(Integer.parseInt(high_rate.getText()));
      environment.setMQRate(Integer.parseInt(med_rate.getText()));
      environment.setMQSale(Integer.parseInt(med_sale.getText()));
      environment.setLQRate(Integer.parseInt(low_rate.getText()));
      environment.setLQSale(Integer.parseInt(low_sale.getText()));
      environment.setIncomeRatioThreshold(Double.parseDouble(agent_performance.getText()));

      for (ProcessSimulator ps : species) {
        if (!ps.isRunning()) {
          ps.replaceEnvironment(environment);

          // replace simulation values
          ps.setAgentCount(Integer.parseInt(agent_count.getText()));
          ps.setDayCount(Integer.parseInt(day_count.getText()));
          ps.setElitePercent(Double.parseDouble(elite_percent.getText()));
          ps.setGenerationCount(Integer.parseInt(generation_count.getText()));
          ps.setParentPercent(Double.parseDouble(parent_percent.getText()));
        }
      }
      System.out.println("Species Reconfigured...");
    } else if (msg == "elite_total") {

      // one of the threads has a new elite
      // TODO: Later, we are going to want to differentiate between the
      // TODO: different threads
      current_elite = ((ProcessSimulator) src).getCurrentElite();

      // update our GUI
      cur_elite_total.setText("$" + current_elite.getMoney());
      cur_elite_genome.setText(current_elite.toString());
    }
  }
示例#11
0
  public WhatsNew(AbstractProjectViewer pv, boolean onlyShowCurrentVersion)
      throws GeneralException {

    super(pv);

    String wn = Environment.getProperty(Constants.WHATS_NEW_VERSION_VIEWED_PROPERTY_NAME);

    if (wn == null) {

      wn = "0";
    }

    // Get the current whats new version (i.e. old).
    Version lastWhatsNewVersion = new Version(wn);

    boolean betasAllowed =
        Environment.getUserProperties()
            .getPropertyAsBoolean(Constants.OPTIN_TO_BETA_VERSIONS_PROPERTY_NAME);

    try {

      String whatsNew = Environment.getResourceFileAsString(Constants.WHATS_NEW_FILE);

      // Load up all the whats new for greater versions.
      Element root = JDOMUtils.getStringAsElement(whatsNew);

      java.util.List verEls = JDOMUtils.getChildElements(root, XMLConstants.version, false);

      // Assume they are in the right order
      // TODO: Enforce the order and/or sort.
      for (int i = 0; i < verEls.size(); i++) {

        Element vEl = (Element) verEls.get(i);

        String id = JDOMUtils.getAttributeValue(vEl, XMLConstants.id, true);

        Version v = new Version(id);
        /*
                      if ((v.isBeta ())
                          &&
                          (!betasAllowed)
                         )
                      {

                          // Ignore, the user isn't interested in betas.
                          continue;

                      }
        */
        if ((lastWhatsNewVersion.isNewer(v))
            || ((onlyShowCurrentVersion) && (v.isSame(Environment.getQuollWriterVersion())))) {

          String c = WhatsNewComponentProvider.class.getName();

          int ind = c.lastIndexOf(".");

          if (ind > 0) {

            c = c.substring(0, ind);
          }

          WhatsNewComponentProvider compProv = null;

          String cl = JDOMUtils.getAttributeValue(vEl, XMLConstants.clazz, false);

          if (!cl.equals("")) {

            Class clz = null;

            try {

              clz = Class.forName(cl);

              if (WhatsNewComponentProvider.class.isAssignableFrom(clz)) {

                compProv = (WhatsNewComponentProvider) clz.newInstance();
              }

            } catch (Exception e) {

            }
          }

          // This is a version we are interested in.
          java.util.List itemEls =
              JDOMUtils.getChildElements(vEl, WhatsNewItem.XMLConstants.root, true);

          java.util.List<WhatsNewItem> its = new ArrayList();

          for (int j = 0; j < itemEls.size(); j++) {

            Element itEl = (Element) itemEls.get(j);

            WhatsNewItem it = new WhatsNewItem(itEl, compProv, pv);

            if (it.onlyIfCurrentVersion) {

              if (!Environment.getQuollWriterVersion().isSame(v)) {

                continue;
              }
            }

            if ((it.description == null) && (it.component == null)) {

              Environment.logMessage(
                  "Whats new item has no description or component, referenced by: "
                      + JDOMUtils.getPath(itEl));

              continue;
            }

            its.add(it);
          }

          if (its.size() > 0) {

            this.items.put(v, its);
          }
        }
      }

    } catch (Exception e) {

      throw new GeneralException("Unable to init whats new", e);
    }
  }
示例#12
0
  public TextArea(String placeholder, int rows, int maxChars) {

    super(BoxLayout.Y_AXIS);

    this.text = UIUtils.createTextArea(rows);

    if (placeholder != null) {

      this.placeholder = Environment.replaceObjectNames(placeholder);
      this.text.setText(this.placeholder);
      this.text.setForeground(UIUtils.getHintTextColor());
    }

    this.maxChars = maxChars;

    final TextArea _this = this;

    final JLabel maxText = new JLabel("Max " + Environment.formatNumber(maxChars) + " characters");
    maxText.setForeground(UIUtils.getHintTextColor());

    this.scrollPane = UIUtils.createScrollPane((JComponent) this.text);

    this.text.addKeyListener(
        new KeyAdapter() {

          public void keyPressed(KeyEvent ev) {

            if (_this.text.getForeground() != Color.BLACK) {

              _this.text.setText("");
            }

            _this.text.setForeground(Color.BLACK);

            if (_this.maxChars <= 0) {

              return;
            }

            maxText.setForeground(UIUtils.getHintTextColor());

            int l = _this.text.getText().trim().length();

            String t = "Max " + Environment.formatNumber(_this.maxChars) + " characters";

            if (l > 0) {

              if (l > 5000) {

                t += ", over " + Environment.formatNumber(_this.maxChars) + " characters";
                maxText.setForeground(Color.RED);

              } else {

                t += ", " + Environment.formatNumber((5000 - l)) + " remaining";
              }
            }

            maxText.setText(t);
          }
        });

    this.text.addMouseListener(
        new MouseEventHandler() {

          @Override
          public void mouseEntered(MouseEvent ev) {

            if ((!_this.text.getText().equals("")) && (_this.text.getForeground() != Color.BLACK)) {

              _this.text.getCaret().setDot(0);
            }

            if (_this.isAutoGrabFocus()) {

              _this.text.grabFocus();
            }
          }

          @Override
          public void handlePress(MouseEvent ev) {

            if ((!_this.text.getText().equals("")) && (_this.text.getForeground() == Color.BLACK)) {

              return;
            }

            _this.text.setText("");
            _this.text.setForeground(Color.BLACK);
          }
        });

    this.add(this.scrollPane);

    this.add(maxText);

    if (this.maxChars <= 0) {

      maxText.setVisible(false);
    }
  }