Skip to content

Commit

Permalink
New ways to open a new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbraginskiy committed Jan 4, 2025
1 parent b2de7dc commit 8a84d55
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 8 deletions.
95 changes: 88 additions & 7 deletions megameklab/src/megameklab/ui/MegaMekLabTabbedUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,98 @@ public MenuBar getMMLMenuBar() {
private class NewTabButton extends JPanel {
public NewTabButton() {
setOpaque(false);
var button = new JButton("➕");
button.setForeground(Color.GREEN);
button.setFont(Font.getFont("Symbola"));
button.setFocusable(false);
button.setBorder(BorderFactory.createEmptyBorder());
var newUnitButton = new JButton("➕");
newUnitButton.setForeground(Color.GREEN);
newUnitButton.setFont(Font.getFont("Symbola"));
newUnitButton.setFocusable(false);
newUnitButton.setBorder(BorderFactory.createEmptyBorder());
newUnitButton.setToolTipText("<html>New Blank Mek<br>Right Click: Select Unit Type");

newUnitButton.addActionListener(e -> newTab());
newUnitButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
MouseAdapter.mousePressed
; it is advisable to add an Override annotation.
if (e.isPopupTrigger()) {
newUnitPopupMenu().show(e.getComponent(), e.getX(), e.getY());
}
}

public void mouseReleased(MouseEvent e) {

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
MouseAdapter.mouseReleased
; it is advisable to add an Override annotation.
if (e.isPopupTrigger()) {
newUnitPopupMenu().show(e.getComponent(), e.getX(), e.getY());
}
}
});

add(newUnitButton);

var loadUnitButton = new JButton("⌸");
loadUnitButton.setFont(Font.getFont("Symbola"));
loadUnitButton.setForeground(Color.CYAN);
loadUnitButton.setFocusable(false);
loadUnitButton.setBorder(BorderFactory.createEmptyBorder());
loadUnitButton.setToolTipText("<html>Load unit from cache<br>Right Click: Load Unit Menu");

loadUnitButton.addActionListener(e -> StartupGUI.selectAndLoadUnitFromCache(MegaMekLabTabbedUI.this));
loadUnitButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
MouseAdapter.mousePressed
; it is advisable to add an Override annotation.
if (e.isPopupTrigger()) {
loadUnitMenu().show(e.getComponent(), e.getX(), e.getY());
}
}
public void mouseReleased(MouseEvent e) {

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
MouseAdapter.mouseReleased
; it is advisable to add an Override annotation.
if (e.isPopupTrigger()) {
loadUnitMenu().show(e.getComponent(), e.getX(), e.getY());
}
}
});

button.addActionListener(e -> {
add(loadUnitButton);
}

private JPopupMenu newUnitPopupMenu() {
var menu = new JPopupMenu();
menu.add(newUnitItem("New Mek", Entity.ETYPE_MEK, false));
menu.add(newUnitItem("New Fighter", Entity.ETYPE_AERO, false));
menu.add(newUnitItem("New DropShip/Small Craft", Entity.ETYPE_DROPSHIP, false));
menu.add(newUnitItem("New Advanced Aerospace", Entity.ETYPE_JUMPSHIP, false));
menu.add(newUnitItem("New Tank", Entity.ETYPE_TANK, false));
menu.add(newUnitItem("New Support Vehicle", Entity.ETYPE_SUPPORT_TANK, false));
menu.add(newUnitItem("New Battle Armor", Entity.ETYPE_BATTLEARMOR, false));
menu.add(newUnitItem("New Conventional Infantry", Entity.ETYPE_INFANTRY, false));
menu.add(newUnitItem("New ProtoMek", Entity.ETYPE_PROTOMEK, false));

var primitive = new JMenu("New Primitive...");
primitive.add(newUnitItem("New Mek", Entity.ETYPE_MEK, true));
primitive.add(newUnitItem("New Fighter", Entity.ETYPE_AERO, true));
primitive.add(newUnitItem("New DropShip/Small Craft", Entity.ETYPE_DROPSHIP, true));
primitive.add(newUnitItem("New JumpShip", Entity.ETYPE_JUMPSHIP, true));

menu.add(primitive);

return menu;
}

private JMenuItem newUnitItem(String name, long entityType, boolean primitive) {
var item = new JMenuItem(name);
item.addActionListener(e -> {
newTab();
newUnit(entityType, primitive);
});
return item;
}

private JPopupMenu loadUnitMenu() {
var menu = new JPopupMenu();

var fromCache = new JMenuItem("Load from cache");
fromCache.addActionListener(e -> StartupGUI.selectAndLoadUnitFromCache(MegaMekLabTabbedUI.this));
menu.add(fromCache);

var fromFile = new JMenuItem("Load from file");
fromFile.addActionListener(e -> getMMLMenuBar().loadUnitFromFile(-1));
menu.add(fromFile);

add(button);
return menu;
}
}

Expand Down
2 changes: 1 addition & 1 deletion megameklab/src/megameklab/ui/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ private void exportSummary(ViewFormatting formatting) {
}
}

private void loadUnitFromFile(int fileNumber) {
public void loadUnitFromFile(int fileNumber) {
File unitFile;
if (fileNumber > 0) {
String recentFileName = CConfig.getRecentFile(fileNumber);
Expand Down

0 comments on commit 8a84d55

Please sign in to comment.