Skip to content

Commit

Permalink
Improve panels and windows
Browse files Browse the repository at this point in the history
07.21.2024

- change: show unit name and its current container unit as title in
          its UnitWindow
- change: show the tab name in Monitor Tool as title
- change: parse location better for vehicle in VehicleTableModel
- change: rename a dialog and panel for Mission Tool
  • Loading branch information
mokun committed Jul 22, 2024
1 parent ccd731a commit 2ed77a7
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import com.mars_sim.ui.swing.MainDesktopPane;
import com.mars_sim.ui.swing.StyleManager;
import com.mars_sim.ui.swing.tool.mission.create.CreateMissionWizard;
import com.mars_sim.ui.swing.tool.mission.edit.EditMissionDialog;
import com.mars_sim.ui.swing.tool.mission.edit.ModifyMissionDialog;
import com.mars_sim.ui.swing.tool.navigator.NavigatorWindow;
import com.mars_sim.ui.swing.tool_window.ToolWindow;

Expand Down Expand Up @@ -319,7 +319,7 @@ private void reviewMission(Mission mission, boolean approved) {
* @param mission the mission to edit.
*/
private void editMission(Mission mission) {
new EditMissionDialog(desktop, mission, this);
new ModifyMissionDialog(desktop, mission, this);
}

public CreateMissionWizard getCreateMissionWizard() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
/*
* Mars Simulation Project
* InfoPanel.java
* @date 2021-10-21
* EditPanel.java
* @date 2024-07-21
* @author Scott Davis
*/

Expand Down Expand Up @@ -49,12 +49,11 @@
import com.mars_sim.ui.swing.MainDesktopPane;
import com.mars_sim.ui.swing.MarsPanelBorder;


/**
* The mission info panel for the edit mission dialog.
* The mission edit panel of a dialog.
*/
@SuppressWarnings("serial")
public class InfoPanel extends JPanel {
public class EditPanel extends JPanel {

/** action text. */
final static String ACTION_NONE = "None";
Expand All @@ -78,10 +77,11 @@ public class InfoPanel extends JPanel {

/**
* Constructor.
*
* @param mission {@link Mission} the mission to edit.
* @param parent {@link Dialog} the parent dialog.
*/
public InfoPanel(Mission mission, MainDesktopPane desktop, JInternalFrame parent) {
public EditPanel(Mission mission, MainDesktopPane desktop, JInternalFrame parent) {

// Data members
this.mission = mission;
Expand All @@ -95,7 +95,7 @@ public InfoPanel(Mission mission, MainDesktopPane desktop, JInternalFrame parent
setBorder(new MarsPanelBorder());

// Create the description panel.
JPanel descriptionPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel descriptionPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
descriptionPane.setAlignmentX(Component.LEFT_ALIGNMENT);
add(descriptionPane);

Expand All @@ -108,7 +108,7 @@ public InfoPanel(Mission mission, MainDesktopPane desktop, JInternalFrame parent
descriptionPane.add(descriptionField);

// Create the action panel.
JPanel actionPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel actionPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
actionPane.setAlignmentX(Component.LEFT_ALIGNMENT);
add(actionPane);

Expand All @@ -133,12 +133,12 @@ public InfoPanel(Mission mission, MainDesktopPane desktop, JInternalFrame parent
membersPane.add(membersLabel, BorderLayout.WEST);

// Create the member list panel.
JPanel memberListPane = new JPanel(new BorderLayout(0, 0));
JPanel memberListPane = new JPanel(new BorderLayout(5, 5));
membersPane.add(memberListPane, BorderLayout.CENTER);

// Create scroll panel for member list.
JScrollPane memberScrollPane = new JScrollPane();
memberScrollPane.setPreferredSize(new Dimension(100, 100));
memberScrollPane.setPreferredSize(new Dimension(80, 100));
memberListPane.add(memberScrollPane, BorderLayout.CENTER);

// Create member list model
Expand All @@ -153,7 +153,7 @@ public InfoPanel(Mission mission, MainDesktopPane desktop, JInternalFrame parent
@Override
public void valueChanged(ListSelectionEvent e) {
// Enable remove members button if there are members in the list.
removeMembersButton.setEnabled(memberList.getSelectedValuesList().size() > 0);
removeMembersButton.setEnabled(!memberList.getSelectedValuesList().isEmpty());
}
}
);
Expand Down Expand Up @@ -191,6 +191,7 @@ public void actionPerformed(ActionEvent e) {

/**
* Checks if members can be added to the mission.
*
* @return true if members can be added.
*/
private boolean canAddMembers() {
Expand All @@ -200,15 +201,15 @@ private boolean canAddMembers() {
}

/**
* Open the add members dialog.
* Opens the add members dialog.
*/
private void addMembers() {
new AddMembersDialog(frame, desktop, mission, memberListModel, getAvailableMembers());
addMembersButton.setEnabled(canAddMembers());
}

/**
* Remove selected members from the list.
* Removes selected members from the list.
*/
private void removeMembers() {
int[] selectedIndexes = memberList.getSelectedIndices();
Expand All @@ -224,6 +225,7 @@ private void removeMembers() {

/**
* Gets a vector of possible actions for the mission.
*
* @param mission {@link Mission} the mission
* @return vector of actions.
*/
Expand Down Expand Up @@ -258,6 +260,7 @@ private Vector<String> getActions(Mission mission) {

/**
* Gets a collection of people and robots available to be added to the mission.
*
* @return collection of available members.
*/
private Collection<Worker> getAvailableMembers() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
/*
* Mars Simulation Project
* EditMissionDialog.java
* @date 2022-03-17
* ModifyMissionDialog.java
* @date 2024-07-21
* @author Scott Davis
*/

Expand All @@ -27,16 +27,16 @@


/**
* The edit mission dialog for the mission tool.
* The modify mission dialog for the mission tool.
*/
public class EditMissionDialog extends ModalInternalFrame {
public class ModifyMissionDialog extends ModalInternalFrame {

/** default serial id. */
private static final long serialVersionUID = 1L;

// Private members
private Mission mission;
private InfoPanel infoPane;
private EditPanel editPane;
protected MainDesktopPane desktop;
private MissionWindow missionWindow;

Expand All @@ -45,9 +45,9 @@ public class EditMissionDialog extends ModalInternalFrame {
* @param owner the owner frame.
* @param mission the mission to edit.
*/
public EditMissionDialog(MainDesktopPane desktop, Mission mission, MissionWindow missionWindow) {
public ModifyMissionDialog(MainDesktopPane desktop, Mission mission, MissionWindow missionWindow) {
// Use ModalInternalFrame constructor
super("Edit Mission");
super("Modify Mission");
this.missionWindow = missionWindow;

// Initialize data members.
Expand All @@ -60,12 +60,12 @@ public EditMissionDialog(MainDesktopPane desktop, Mission mission, MissionWindow
// Set the border.
((JComponent) getContentPane()).setBorder(new MarsPanelBorder());

// Create the info panel.
infoPane = new InfoPanel(mission, desktop, this);
add(infoPane, BorderLayout.CENTER);
// Create the edit panel.
editPane = new EditPanel(mission, desktop, this);
add(editPane, BorderLayout.CENTER);

// Create the button panel.
JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 5));
JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10));
add(buttonPane, BorderLayout.SOUTH);

// Create the modify button.
Expand Down Expand Up @@ -94,11 +94,11 @@ public void actionPerformed(ActionEvent e) {
// Finish and display dialog.
//pack();
//setLocationRelativeTo(owner);

setResizable(false);

desktop.add(this);


setSize(new Dimension(400, 400));
Dimension desktopSize = desktop.getParent().getSize();
Dimension jInternalFrameSize = this.getSize();
Expand All @@ -115,10 +115,10 @@ public void actionPerformed(ActionEvent e) {
*/
private void modifyMission() {
// Set the mission description.
mission.setName(infoPane.descriptionField.getText());
mission.setName(editPane.descriptionField.getText());

// Change the mission's action.
setAction((String) infoPane.actionDropDown.getSelectedItem());
setAction((String) editPane.actionDropDown.getSelectedItem());

// Set mission members.
setWorkers();
Expand All @@ -130,8 +130,8 @@ private void modifyMission() {
* @param action the action string.
*/
private void setAction(String action) {
if (action.equals(InfoPanel.ACTION_CONTINUE)) endEVAPhase();
else if (action.equals(InfoPanel.ACTION_HOME)) returnHome();
if (action.equals(EditPanel.ACTION_CONTINUE)) endEVAPhase();
else if (action.equals(EditPanel.ACTION_HOME)) returnHome();
}

/**
Expand All @@ -144,7 +144,7 @@ private void endEVAPhase() {
}

/**
* Have the mission return home and end collection phase if necessary.
* Aborts the mission and have everyone return home and end collection phase if necessary.
*/
private void returnHome() {
if (mission != null) {
Expand All @@ -158,8 +158,8 @@ private void returnHome() {
*/
private void setWorkers() {
// Add new members.
for (int x = 0; x < infoPane.memberListModel.size(); x++) {
Worker member = (Worker) infoPane.memberListModel.elementAt(x);
for (int x = 0; x < editPane.memberListModel.size(); x++) {
Worker member = (Worker) editPane.memberListModel.elementAt(x);
if (!mission.getMembers().contains(member)) {
member.setMission(mission);
}
Expand All @@ -169,14 +169,14 @@ private void setWorkers() {
Iterator<Worker> i = mission.getMembers().iterator();
while (i.hasNext()) {
Worker member = i.next();
if (!infoPane.memberListModel.contains(member)) {
if (!editPane.memberListModel.contains(member)) {
member.setMission(null);
}
}
}

public InfoPanel getInfoPanel() {
return infoPane;
public EditPanel getInfoPanel() {
return editPane;
}

public MissionWindow getMissionWindow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,10 @@ private void selectNewTab(MonitorTab selectedTab) {

MonitorModel tabTableModel = selectedTab.getModel();

String title = tabTableModel.getName();

super.setTitle(NAME + " - " + title);

// Disable all buttons
boolean enableMap = selectedTab.isNavigatable();
boolean enableDetails = selectedTab.isEntityDriven();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Mars Simulation Project
* VehicleTableModel.java
* @date 2021-10-23
* @date 2024-07-21
* @author Barry Evans
*/
package com.mars_sim.ui.swing.tool.monitor;
Expand All @@ -10,6 +10,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.mars_sim.core.CollectionUtils;
import com.mars_sim.core.Simulation;
import com.mars_sim.core.Unit;
import com.mars_sim.core.UnitEvent;
Expand Down Expand Up @@ -126,7 +128,7 @@ public VehicleTableModel() {
}

/**
* Filter the vehicles to a settlement
* Filters the vehicles to a settlement.
*/
@Override
public boolean setSettlementFilter(Set<Settlement> filter) {
Expand Down Expand Up @@ -155,7 +157,7 @@ protected Object getEntityValue(Vehicle vehicle, int columnIndex) {
break;

case TYPE :
result = vehicle.getVehicleType().getName();
result = vehicle.getVehicleSpec().getName();
break;

case MODEL :
Expand All @@ -168,7 +170,21 @@ protected Object getEntityValue(Vehicle vehicle, int columnIndex) {
result = settle.getName();
}
else {
result = vehicle.getCoordinates().getFormattedString();
settle = CollectionUtils.findSettlement(vehicle.getCoordinates());
if (settle != null) {
result = settle.getName();
}
else {
Mission mission = vehicle.getMission();
if (mission instanceof VehicleMission vm) {
NavPoint destination = vm.getCurrentDestination();
if (destination.isSettlementAtNavpoint())
result = destination.getSettlement().getName();
else
result = destination.getDescription();
}
}
// For now, not using result = vehicle.getCoordinates().getFormattedString();
}
} break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public abstract class ToolWindow extends JInternalFrame {

// Data members
private static final String SPACE = " ";
private static final String SPACE = " ";

/** True if window is open. */
protected boolean opened;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ protected void buildUI(JPanel content) {

settlementLabel = containerPanel.addRow("Settlement", "");
containerLabel = containerPanel.addRow("Container Unit", "");
buildingLabel = containerPanel.addRow("Building", "");
locationStateLabel = containerPanel.addRow("Location State", "");
buildingLabel = containerPanel.addRow("Building", "");
vicinityLabel = containerPanel.addRow("Vicinity", "");
}

Expand All @@ -236,21 +236,19 @@ else if (isVehicle) {

settlementLabel = containerPanel.addRow("Settlement", "");
containerLabel = containerPanel.addRow("Container Unit", "");
buildingLabel = containerPanel.addRow("Building", "");
locationStateLabel = containerPanel.addRow("Location State", "");
buildingLabel = containerPanel.addRow("Building", "");
vicinityLabel = containerPanel.addRow("Vicinity", "");
}

else if (isEquipment) {

AttributePanel containerPanel = new AttributePanel(5);
AttributePanel containerPanel = new AttributePanel(3);
dataPanel.add(containerPanel, BorderLayout.NORTH);

settlementLabel = containerPanel.addRow("Settlement", "");
containerLabel = containerPanel.addRow("Container Unit", "");
buildingLabel = containerPanel.addRow("Building", "");
locationStateLabel = containerPanel.addRow("Location State", "");
vicinityLabel = containerPanel.addRow("Vicinity", "");
}

else if (isSettlement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class EquipmentUnitWindow extends UnitWindow {
*/
public EquipmentUnitWindow(MainDesktopPane desktop, Equipment equipment) {
// Use UnitWindow constructor
super(desktop, equipment, equipment.getAssociatedSettlement().getName() + " - " + equipment.getName(), false);
super(desktop, equipment, equipment.getName() + " - " + equipment.getContainerUnit(), false);
this.equipment = equipment;

if (equipment instanceof EVASuit suit) {
Expand Down
Loading

0 comments on commit 2ed77a7

Please sign in to comment.