-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52e94d8
commit cc02a54
Showing
7 changed files
with
300 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright (c) 2020 The MegaMek Team. | ||
* | ||
* This file is part of MekHQ. | ||
* | ||
* MekHQ is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* MekHQ is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with MekHQ. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package mekhq.gui; | ||
|
||
import java.awt.GridBagConstraints; | ||
import java.awt.GridBagLayout; | ||
import java.awt.GridLayout; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.ResourceBundle; | ||
|
||
import javax.swing.BorderFactory; | ||
import javax.swing.JPanel; | ||
import javax.swing.JScrollPane; | ||
import javax.swing.JSplitPane; | ||
import javax.swing.JTable; | ||
|
||
import megamek.common.event.Subscribe; | ||
import megamek.common.util.EncodeControl; | ||
import mekhq.MekHQ; | ||
import mekhq.campaign.CampaignController; | ||
import mekhq.campaign.RemoteCampaign; | ||
import mekhq.gui.model.OnlineCampaignsTableModel; | ||
import mekhq.online.events.CampaignListUpdatedEvent; | ||
import mekhq.preferences.PreferencesNode; | ||
|
||
public final class OnlineTab extends CampaignGuiTab implements ActionListener { | ||
|
||
private static final long serialVersionUID = 4133071018441878778L; | ||
|
||
private ResourceBundle resourceMap; | ||
|
||
private OnlineCampaignsTableModel hostCampaignTableModel; | ||
private JTable hostCampaignTable; | ||
private OnlineCampaignsTableModel campaignsTableModel; | ||
private JTable campaignsTable; | ||
|
||
OnlineTab(CampaignGUI gui, String name) { | ||
super(gui, name); | ||
MekHQ.registerHandler(this); | ||
setUserPreferences(); | ||
} | ||
|
||
private void setUserPreferences() { | ||
PreferencesNode preferences = MekHQ.getPreferences().forClass(OnlineTab.class); | ||
|
||
// TODO: manage preferences | ||
} | ||
|
||
private CampaignController getCampaignController() { | ||
return getCampaignGui().getCampaignController(); | ||
} | ||
|
||
@Override | ||
public void initTab() { | ||
resourceMap = ResourceBundle.getBundle("mekhq.resources.CampaignGUI", //$NON-NLS-1$ | ||
new EncodeControl()); | ||
|
||
setName("panelOnline"); //$NON-NLS-1$ | ||
setLayout(new GridBagLayout()); | ||
|
||
hostCampaignTableModel = new OnlineCampaignsTableModel(getHostCampaignAsList()); | ||
hostCampaignTable = new JTable(hostCampaignTableModel); | ||
|
||
JScrollPane hostCampaignScrollPane = new JScrollPane(hostCampaignTable); | ||
JPanel hostCampaignTablePanel = new JPanel(new GridLayout(0, 1)); | ||
hostCampaignTablePanel.setBorder(BorderFactory.createTitledBorder("Host Campaign")); | ||
hostCampaignTablePanel.add(hostCampaignScrollPane); | ||
|
||
campaignsTableModel = new OnlineCampaignsTableModel(getCampaignController().getRemoteCampaigns()); | ||
campaignsTable = new JTable(campaignsTableModel); | ||
|
||
JScrollPane campaignsTableScrollPane = new JScrollPane(campaignsTable); | ||
JPanel campaignsTablePanel = new JPanel(new GridLayout(0, 1)); | ||
campaignsTablePanel.setBorder(BorderFactory.createTitledBorder("Remote Campaigns")); | ||
campaignsTablePanel.add(campaignsTableScrollPane); | ||
|
||
JPanel topPanel = new JPanel(new GridLayout(0, 1)); | ||
if (!getCampaignController().isHost()) { | ||
topPanel.add(hostCampaignTablePanel); | ||
} | ||
topPanel.add(campaignsTablePanel); | ||
|
||
JPanel campaignDetailsPanel = new JPanel(); | ||
|
||
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, | ||
campaignDetailsPanel); | ||
splitPane.setOneTouchExpandable(true); | ||
splitPane.setResizeWeight(1.0); | ||
|
||
GridBagConstraints gbc= new java.awt.GridBagConstraints(); | ||
gbc.gridx = 0; | ||
gbc.gridy = 1; | ||
gbc.gridwidth = 6; | ||
gbc.fill = java.awt.GridBagConstraints.BOTH; | ||
gbc.weightx = 1.0; | ||
gbc.weighty = 1.0; | ||
add(splitPane, gbc); | ||
} | ||
|
||
@Override | ||
public void refreshAll() { | ||
hostCampaignTableModel.setData(getHostCampaignAsList()); | ||
campaignsTableModel.setData(new ArrayList<>(getCampaignController().getRemoteCampaigns())); | ||
} | ||
|
||
private List<RemoteCampaign> getHostCampaignAsList() { | ||
List<RemoteCampaign> list = new ArrayList<>(); | ||
|
||
list.add(new RemoteCampaign(getCampaignController().getHost(), | ||
getCampaignController().getHostName(), getCampaignController().getHostDate(), | ||
getCampaignController().getHostLocation(), getCampaignController().getHostIsGMMode())); | ||
|
||
return list; | ||
} | ||
|
||
@Override | ||
public GuiTabType tabType() { | ||
return GuiTabType.ONLINE; | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Subscribe | ||
public void handle(CampaignListUpdatedEvent e) { | ||
refreshAll(); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
MekHQ/src/mekhq/gui/model/OnlineCampaignsTableModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright (c) 2020 The MegaMek Team. | ||
* | ||
* This file is part of MekHQ. | ||
* | ||
* MekHQ is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* MekHQ is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with MekHQ. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package mekhq.gui.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
import org.joda.time.format.DateTimeFormatter; | ||
import org.joda.time.format.ISODateTimeFormat; | ||
|
||
import mekhq.campaign.RemoteCampaign; | ||
|
||
public class OnlineCampaignsTableModel extends DataTableModel { | ||
|
||
private static final long serialVersionUID = 5792881778901299604L; | ||
|
||
public final static int COL_ID = 0; | ||
public final static int COL_NAME = 1; | ||
public final static int COL_DATE = 2; | ||
public final static int COL_LOCATION = 3; | ||
public final static int COL_IS_GM = 4; | ||
public final static int COL_IS_ACTIVE = 5; | ||
public final static int N_COL = 6; | ||
|
||
private final DateTimeFormatter dateFormatter = ISODateTimeFormat.date(); | ||
|
||
public OnlineCampaignsTableModel() { | ||
setData(Collections.emptyList()); | ||
} | ||
|
||
public OnlineCampaignsTableModel(Collection<RemoteCampaign> remoteCampaigns) { | ||
setData(new ArrayList<>(remoteCampaigns)); | ||
} | ||
|
||
public int getRowCount() { | ||
return data.size(); | ||
} | ||
|
||
@Override | ||
public int getColumnCount() { | ||
return N_COL; | ||
} | ||
|
||
@Override | ||
public String getColumnName(int column) { | ||
switch(column) { | ||
case COL_ID: | ||
return "ID"; | ||
case COL_NAME: | ||
return "Name"; | ||
case COL_DATE: | ||
return "Date"; | ||
case COL_LOCATION: | ||
return "Current Location"; | ||
case COL_IS_GM: | ||
return "GM?"; | ||
case COL_IS_ACTIVE: | ||
return "Active?"; | ||
default: | ||
return "?"; | ||
} | ||
} | ||
|
||
@Override | ||
public Object getValueAt(int rowIndex, int columnIndex) { | ||
RemoteCampaign row = (RemoteCampaign)data.get(rowIndex); | ||
switch (columnIndex) | ||
{ | ||
case COL_ID: | ||
return row.getId(); | ||
case COL_NAME: | ||
return row.getName(); | ||
case COL_DATE: | ||
return dateFormatter.print(row.getDate()); | ||
case COL_LOCATION: | ||
return row.getLocation().getName(row.getDate()); | ||
case COL_IS_GM: | ||
return row.isGMMode() ? "Yes" : "No"; | ||
case COL_IS_ACTIVE: | ||
return "Yes"; | ||
default: | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.