Skip to content

Commit

Permalink
New Feature: Lock tool tabs
Browse files Browse the repository at this point in the history
Merge Feature
  • Loading branch information
GoldenGnu committed May 3, 2024
2 parents 69b4dbd + 50ba178 commit 554f8e2
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 23 deletions.
12 changes: 11 additions & 1 deletion src/main/java/net/nikr/eve/jeveasset/data/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public static enum SettingFlag {
FLAG_SAVE_MINING_HISTORY,
FLAG_MANUFACTURING_DEFAULT,
FLAG_EASY_CHART_COLORS,
FLAG_CONTAINERS_SHOW_ITEM_ID
FLAG_CONTAINERS_SHOW_ITEM_ID,
FLAG_LOCK_TOOLS
}

public static enum TransactionProfitPrice {
Expand Down Expand Up @@ -297,6 +298,7 @@ protected Settings() {
flags.put(SettingFlag.FLAG_MANUFACTURING_DEFAULT, true);
flags.put(SettingFlag.FLAG_EASY_CHART_COLORS, false);
flags.put(SettingFlag.FLAG_CONTAINERS_SHOW_ITEM_ID, true);
flags.put(SettingFlag.FLAG_LOCK_TOOLS, false);
cacheFlags();
//Default Filters
List<Filter> filter;
Expand Down Expand Up @@ -856,6 +858,14 @@ public void setEasyChartColors(final boolean easyChartColors) {
flags.put(SettingFlag.FLAG_EASY_CHART_COLORS, easyChartColors);
}

public boolean isToolsLocked() {
return flags.get(SettingFlag.FLAG_LOCK_TOOLS);
}

public void setToolsLocked(final boolean toolsLocked) {
flags.put(SettingFlag.FLAG_LOCK_TOOLS, toolsLocked);
}

public boolean isContainersShowItemID() {
return containersShowItemID;
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/net/nikr/eve/jeveasset/gui/frame/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.concurrent.ExecutionException;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import net.nikr.eve.jeveasset.CliOptions;
import net.nikr.eve.jeveasset.Program;
import net.nikr.eve.jeveasset.data.settings.Settings;
import net.nikr.eve.jeveasset.gui.images.Images;
import net.nikr.eve.jeveasset.i18n.GuiFrame;

Expand Down Expand Up @@ -85,6 +87,7 @@ public MainMenu(final Program program) {
JMenu menu;
JMenu submenu;
JMenuItem menuItem;
JCheckBoxMenuItem checkBoxMenuItem;

//FILE
menu = new JMenu(GuiFrame.get().file());
Expand Down Expand Up @@ -268,6 +271,22 @@ public MainMenu(final Program program) {
menuItem.addActionListener(program);
submenu.add(menuItem);

menu.addSeparator();

checkBoxMenuItem = new JCheckBoxMenuItem(GuiFrame.get().lock());
checkBoxMenuItem.setSelected(Settings.get().isToolsLocked());
checkBoxMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Settings.lock("Lock Tools");
Settings.get().setToolsLocked(checkBoxMenuItem.isSelected());
Settings.unlock("Lock Tools");
program.saveSettings("Lock Tools");
program.getMainWindow().updateTabCloseButtons();
}
});
menu.add(checkBoxMenuItem);

//UPDATE
menu = new JMenu(GuiFrame.get().update());
menu.setMnemonic(KeyEvent.VK_U);
Expand Down
71 changes: 49 additions & 22 deletions src/main/java/net/nikr/eve/jeveasset/gui/frame/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void mousePressed(final MouseEvent e) {
return;
}
JMainTab jMainTab = tabs.get(index);
if (jMainTab.isCloseable()) {
if (isCloseable(jMainTab)) {
removeTab(jMainTab);
}
}
Expand Down Expand Up @@ -286,6 +286,16 @@ public void updateSettings() {
}
}

public void updateTabCloseButtons() {
for (int i = 0; i < jTabbedPane.getTabCount(); i++) {
Component component = jTabbedPane.getTabComponentAt(i);
if (component instanceof TabCloseButton) {
TabCloseButton tabCloseButton = (TabCloseButton) component;
tabCloseButton.updateCloseButton();
}
}
}

private boolean isMaximized() {
return ((jFrame.getExtendedState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH);
}
Expand Down Expand Up @@ -374,41 +384,58 @@ public void tabMoved(int from, int to) {
}
}

private static boolean isCloseable(final JMainTab jMainTab) {
return jMainTab.isCloseable() && !Settings.get().isToolsLocked();
}

private class TabCloseButton extends JPanel {

private final JButton jClose;
private final JMainTab jMainTab;

public TabCloseButton(final JMainTab jMainTab) {
super(new FlowLayout(FlowLayout.LEFT, 0, 0));
this.jMainTab = jMainTab;
this.setOpaque(false);
JLabel jTitle = new JLabel(jMainTab.getTitle(), jMainTab.getIcon(), SwingConstants.LEFT);
add(jTitle);
if (jMainTab.isCloseable()) {
JButton jClose = new JButton();
jClose.setToolTipText(GuiFrame.get().close());
jClose.setIcon(Images.TAB_CLOSE.getIcon());
jClose.setRolloverIcon(Images.TAB_CLOSE_ACTIVE.getIcon());
jClose.setUI(new BasicButtonUI());
jClose.setPreferredSize(new Dimension(16, 16));
jClose.setOpaque(false);
jClose.setContentAreaFilled(false);
jClose.setFocusable(false);
jClose.setBorderPainted(false);
jClose.setRolloverEnabled(true);
jClose.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON2) {
jClose = new JButton();
jClose.setToolTipText(GuiFrame.get().close());
jClose.setIcon(Images.TAB_CLOSE.getIcon());
jClose.setRolloverIcon(Images.TAB_CLOSE_ACTIVE.getIcon());
jClose.setUI(new BasicButtonUI());
jClose.setPreferredSize(new Dimension(16, 16));
jClose.setOpaque(false);
jClose.setContentAreaFilled(false);
jClose.setFocusable(false);
jClose.setBorderPainted(false);
jClose.setRolloverEnabled(true);
jClose.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON2) {
if (isCloseable(jMainTab)) {
removeTab(jMainTab);
}
}
});
jClose.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
}
});
jClose.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (isCloseable(jMainTab)) {
removeTab(jMainTab);
}
});
}
});
if (jMainTab.isCloseable()) {
add(jClose);
}
jClose.setEnabled(isCloseable(jMainTab));
}

private void updateCloseButton() {
jClose.setEnabled(isCloseable(jMainTab));
}
}
}
1 change: 1 addition & 0 deletions src/main/java/net/nikr/eve/jeveasset/i18n/GuiFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public GuiFrame(final Locale locale) {
public abstract String license();
public abstract String linkFeedbackAndHelp();
public abstract String linkWiki();
public abstract String lock();
public abstract String market();
public abstract String materials();
public abstract String mining();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ journal=Journal
license=License
linkFeedbackAndHelp=Feedback & Help
linkWiki=Wiki
lock=Lock Tabs
market=Market Orders
materials=Materials
mining=Mining
Expand Down

0 comments on commit 554f8e2

Please sign in to comment.