Exemplo n.º 1
0
  /**
   * Constructor.
   *
   * @param unit the unit to display.
   * @param desktop the main desktop.
   */
  public TabPanelFavorite(Unit unit, MainDesktopPane desktop) {
    // Use the TabPanel constructor
    super(
        Msg.getString("TabPanelFavorite.title"), // $NON-NLS-1$
        null,
        Msg.getString("TabPanelFavorite.tooltip"), // $NON-NLS-1$
        unit,
        desktop);

    Person person = (Person) unit;

    // Create Favorite label panel.
    JPanel favoriteLabelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    topContentPanel.add(favoriteLabelPanel);

    // Prepare  Favorite label
    JLabel favoriteLabel =
        new JLabel(Msg.getString("TabPanelFavorite.label"), JLabel.CENTER); // $NON-NLS-1$
    favoriteLabelPanel.add(favoriteLabel);

    // Prepare info panel.
    JPanel infoPanel = new JPanel(new GridLayout(4, 2, 0, 0));
    infoPanel.setBorder(new MarsPanelBorder());
    topContentPanel.add(infoPanel, BorderLayout.NORTH);

    // Prepare main dish name label
    JLabel mainDishNameLabel =
        new JLabel(Msg.getString("TabPanelFavorite.mainDish"), JLabel.RIGHT); // $NON-NLS-1$
    infoPanel.add(mainDishNameLabel);

    // Prepare main dish label
    String mainDish = person.getFavorite().getFavoriteMainDish();
    // JLabel mainDishLabel = new JLabel(mainDish, JLabel.RIGHT);
    // infoPanel.add(mainDishLabel);
    JTextField mainDishTF = new JTextField(WordUtils.capitalize(mainDish));
    mainDishTF.setEditable(false);
    mainDishTF.setColumns(20);
    infoPanel.add(mainDishTF);

    // Prepare side dish name label
    JLabel sideDishNameLabel =
        new JLabel(Msg.getString("TabPanelFavorite.sideDish"), JLabel.RIGHT); // $NON-NLS-1$
    infoPanel.add(sideDishNameLabel);

    // Prepare side dish label
    String sideDish = person.getFavorite().getFavoriteSideDish();
    // JLabel sideDishLabel = new JLabel(sideDish, JLabel.RIGHT);
    // infoPanel.add(sideDishLabel);
    JTextField sideDishTF = new JTextField(WordUtils.capitalize(sideDish));
    sideDishTF.setEditable(false);
    sideDishTF.setColumns(20);
    infoPanel.add(sideDishTF);

    // Prepare dessert name label
    JLabel dessertNameLabel =
        new JLabel(Msg.getString("TabPanelFavorite.dessert"), JLabel.RIGHT); // $NON-NLS-1$
    infoPanel.add(dessertNameLabel);

    // Prepare dessert label
    String dessert = person.getFavorite().getFavoriteDessert();
    // JLabel dessertLabel = new JLabel(WordUtils.capitalize(dessert), JLabel.RIGHT);
    // infoPanel.add(dessertLabel);
    JTextField dessertTF = new JTextField(WordUtils.capitalize(dessert));
    dessertTF.setEditable(false);
    dessertTF.setColumns(20);
    infoPanel.add(dessertTF);

    // Prepare activity name label
    JLabel activityNameLabel =
        new JLabel(Msg.getString("TabPanelFavorite.activity"), JLabel.RIGHT); // $NON-NLS-1$
    infoPanel.add(activityNameLabel);

    // Prepare activity label
    String activity = person.getFavorite().getFavoriteActivity();
    JTextField activityTF = new JTextField(WordUtils.capitalize(activity));
    activityTF.setEditable(false);
    activityTF.setColumns(20);
    infoPanel.add(activityTF);
    // JLabel activityLabel = new JLabel(WordUtils.capitalize(activity), JLabel.RIGHT);
    // infoPanel.add(activityLabel);

    // Create label panel.
    JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    centerContentPanel.add(labelPanel, BorderLayout.NORTH);

    // Create preference label
    JLabel label = new JLabel("Preferences");
    labelPanel.add(label);

    // Create scroll panel
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBorder(new MarsPanelBorder());
    scrollPane.getVerticalScrollBar().setUnitIncrement(10);
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    centerContentPanel.add(scrollPane, BorderLayout.CENTER);

    // Create skill table
    tableModel = new PreferenceTableModel(person);
    JTable table = new JTable(tableModel);
    table.setPreferredScrollableViewportSize(new Dimension(225, 100));
    table.getColumnModel().getColumn(0).setPreferredWidth(100);
    table.getColumnModel().getColumn(1).setPreferredWidth(30);
    table.setCellSelectionEnabled(false);
    table.setDefaultRenderer(Integer.class, new NumberCellRenderer());

    // 2015-06-08 Added sorting
    table.setAutoCreateRowSorter(true);
    table.getTableHeader().setDefaultRenderer(new MultisortTableHeaderCellRenderer());

    // 2015-06-08 Added setTableStyle()
    TableStyle.setTableStyle(table);

    scrollPane.setViewportView(table);
  }
Exemplo n.º 2
0
  @Override
  public double getProbability(Person person) {

    double result = 0D;

    if (person.getLocationSituation() == LocationSituation.IN_SETTLEMENT) {
      boolean isEVA = false;

      Settlement settlement = person.getSettlement();

      // Check if settlement has resource process override set.
      if (!settlement.getResourceProcessOverride()) {
        try {
          Building building = ToggleResourceProcess.getResourceProcessingBuilding(person);
          if (building != null) {
            ResourceProcess process = ToggleResourceProcess.getResourceProcess(building);
            isEVA = !building.hasFunction(BuildingFunction.LIFE_SUPPORT);
            double diff = ToggleResourceProcess.getResourcesValueDiff(settlement, process);
            double baseProb = diff * 10000D;
            if (baseProb > 100D) {
              baseProb = 100D;
            }
            result += baseProb;

            if (!isEVA) {
              // Factor in building crowding and relationship factors.
              result *= TaskProbabilityUtil.getCrowdingProbabilityModifier(person, building);
              result *= TaskProbabilityUtil.getRelationshipModifier(person, building);
            }
          }
        } catch (Exception e) {
          e.printStackTrace(System.err);
        }
      }

      if (isEVA) {
        // Check if an airlock is available
        if (EVAOperation.getWalkableAvailableAirlock(person) == null) {
          result = 0D;
        }

        // Check if it is night time.
        SurfaceFeatures surface = Simulation.instance().getMars().getSurfaceFeatures();
        if (surface.getSolarIrradiance(person.getCoordinates()) == 0D) {
          if (!surface.inDarkPolarRegion(person.getCoordinates())) {
            result = 0D;
          }
        }

        // Crowded settlement modifier
        if (person.getLocationSituation() == LocationSituation.IN_SETTLEMENT) {
          if (settlement.getCurrentPopulationNum() > settlement.getPopulationCapacity()) {
            result *= 2D;
          }
        }
      }

      // Effort-driven task modifier.
      result *= person.getPerformanceRating();

      // Job modifier.
      Job job = person.getMind().getJob();
      if (job != null) {
        result *= job.getStartTaskProbabilityModifier(ToggleResourceProcess.class);
      }

      // Modify if tinkering is the person's favorite activity.
      if (person.getFavorite().getFavoriteActivity().equalsIgnoreCase("Tinkering")) {
        result *= 2D;
      }

      // 2015-06-07 Added Preference modifier
      if (result > 0) result += person.getPreference().getPreferenceScore(this);
      if (result < 0) result = 0;
    }

    return result;
  }