Skip to content

Commit

Permalink
New Feature: Hide subpile tree
Browse files Browse the repository at this point in the history
Merge Feature
  • Loading branch information
GoldenGnu committed May 3, 2024
2 parents f03de4f + 14c1874 commit 0bf01e1
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 19 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 @@ -101,7 +101,8 @@ public static enum SettingFlag {
FLAG_MANUFACTURING_DEFAULT,
FLAG_EASY_CHART_COLORS,
FLAG_CONTAINERS_SHOW_ITEM_ID,
FLAG_LOCK_TOOLS
FLAG_LOCK_TOOLS,
FLAG_SHOW_SUBPILE_TREE
}

public static enum TransactionProfitPrice {
Expand Down Expand Up @@ -299,6 +300,7 @@ protected Settings() {
flags.put(SettingFlag.FLAG_EASY_CHART_COLORS, false);
flags.put(SettingFlag.FLAG_CONTAINERS_SHOW_ITEM_ID, true);
flags.put(SettingFlag.FLAG_LOCK_TOOLS, false);
flags.put(SettingFlag.FLAG_SHOW_SUBPILE_TREE, true);
cacheFlags();
//Default Filters
List<Filter> filter;
Expand Down Expand Up @@ -866,6 +868,14 @@ public void setToolsLocked(final boolean toolsLocked) {
flags.put(SettingFlag.FLAG_LOCK_TOOLS, toolsLocked);
}

public boolean isShowSubpileTree() {
return flags.get(SettingFlag.FLAG_SHOW_SUBPILE_TREE);
}

public void setShowSubpileTree(final boolean showSubpileTree) {
flags.put(SettingFlag.FLAG_SHOW_SUBPILE_TREE, showSubpileTree);
}

public boolean isContainersShowItemID() {
return containersShowItemID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public class Stockpile implements Comparable<Stockpile>, LocationsType, OwnersTy
private final IgnoreItem ignoreItem = new IgnoreItem(this);
private final Map<Stockpile, Double> subpiles = new HashMap<>();
private final List<Stockpile> subpileLinks = new ArrayList<>();
private final List<SubpileItem> subpileAll = new ArrayList<>();
private final List<SubpileItem> subpileItems = new ArrayList<>();
private final List<SubpileStock> subpileStocks = new ArrayList<>();
private double percentFull;
private double multiplier;
private boolean contractsMatchAll;
Expand Down Expand Up @@ -193,7 +195,34 @@ public Map<Stockpile, Double> getSubpiles() {
}

public List<SubpileItem> getSubpileItems() {
return subpileItems;
return subpileAll;
}

public List<SubpileStock> getSubpileStocks() {
return subpileStocks;
}

public List<SubpileItem> getSubpileTableItems() {
if (Settings.get().isShowSubpileTree()) {
return subpileAll;
} else {
return subpileItems;
}
}

public void clearSubpileItems() {
subpileAll.clear();
subpileItems.clear();
subpileStocks.clear();
}

public void addSubpileItem(SubpileItem subpileItem) {
subpileAll.add(subpileItem);
subpileItems.add(subpileItem);
}
public void addSubpileStock(SubpileStock subpileStock) {
subpileAll.add(subpileStock);
subpileStocks.add(subpileStock);
}

private void createLocationName() {
Expand Down Expand Up @@ -428,7 +457,7 @@ public IgnoreItem getIgnoreItem() {
public List<StockpileItem> getClaims() {
List<StockpileItem> list = new ArrayList<>();
list.addAll(items);
list.addAll(subpileItems);
list.addAll(subpileAll);
return list;
}

Expand Down Expand Up @@ -479,9 +508,6 @@ public void updateTotal() {
}
//SubpileItem (Overwrites StockpileItem items)
for (SubpileItem item : subpileItems) {
if (item instanceof SubpileStock) {
continue;
}
map.put(item.getItemTypeID(), item);
}
//For each item type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private void updateSubpile(List<StockpileItem> updated, List<StockpileItem> remo
//Save old items (for them to be removed)
List<SubpileItem> subpileItems = new ArrayList<>(parent.getSubpileItems());
//Clear old items
parent.getSubpileItems().clear();
parent.clearSubpileItems();
for (SubpileItem subpileItem : subpileItems) {
subpileItem.clearItemLinks();
}
Expand All @@ -497,7 +497,7 @@ private void updateSubpile(List<StockpileItem> updated, List<StockpileItem> remo
if (profileManager.getStockpileIDs().isShown(parent.getStockpileID())) {
String group = Settings.get().getStockpileGroupSettings().getGroup(parent);
if (Settings.get().getStockpileGroupSettings().isGroupExpanded(group)) { //Stockpile group expanded or not in group
updated.addAll(parent.getSubpileItems());
updated.addAll(parent.getSubpileTableItems());
}
}
}
Expand Down Expand Up @@ -533,7 +533,7 @@ private static void updateSubpileClaims(Stockpile topStockpile, Stockpile parent
String path = parentPath + currentStockpile.getName() + "\r\n";
int level = parentLevel + 1;
SubpileStock subpileStock = new SubpileStock(topStockpile, currentStockpile, parentStockpile, parentStock, value, parentLevel, path);
topStockpile.getSubpileItems().add(subpileStock);
topStockpile.addSubpileStock(subpileStock);
for (StockpileItem stockpileItem : currentStockpile.getItems()) {
//For each StockpileItem
if (stockpileItem.isTotal()) {
Expand All @@ -553,7 +553,7 @@ private static void updateSubpileClaims(Stockpile topStockpile, Stockpile parent
linkItem.setLevel(level);
}
} else { //Add new item (Simple)
topStockpile.getSubpileItems().add(subpileItem);
topStockpile.addSubpileItem(subpileItem);
}
}
updateSubpileClaims(topStockpile, currentStockpile, topItems, subpileStock, level, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ private enum StockpileAction {
COLLAPSE,
EXPAND,
COLLAPSE_GROUPS,
EXPAND_GROUPS
EXPAND_GROUPS,
SUBPILE_TREE
}

public enum ImportOptions implements OptionEnum {
Expand Down Expand Up @@ -270,6 +271,7 @@ public void setAll(boolean all) {

//Toolbar
private final JFixedToolBar jToolBar;
private final JCheckBoxMenuItem jShowSubpileTree;
private final JDropDownButton jCollapse;
private final JButton jCollapseGroup;
private final JButton jExpandGroup;
Expand Down Expand Up @@ -374,10 +376,19 @@ public void componentHidden(ComponentEvent e) { }

jToolBar.addSeparator();

JButton jShowHide = new JButton(TabsStockpile.get().showHide(), Images.EDIT_SHOW.getIcon());
jShowHide.setActionCommand(StockpileAction.SHOW_HIDE.name());
jShowHide.addActionListener(listener);
jToolBar.addButton(jShowHide);
JDropDownButton jShow = new JDropDownButton(TabsStockpile.get().showHide(), Images.EDIT_SHOW.getIcon());
jToolBar.addButton(jShow);

JMenuItem jShowStockpiles = new JMenuItem(TabsStockpile.get().showStockpiles(), Images.TOOL_STOCKPILE.getIcon());
jShowStockpiles.setActionCommand(StockpileAction.SHOW_HIDE.name());
jShowStockpiles.addActionListener(listener);
jShow.add(jShowStockpiles);

jShowSubpileTree = new JCheckBoxMenuItem(TabsStockpile.get().showSubpileTree());
jShowSubpileTree.setSelected(Settings.get().isShowSubpileTree());
jShowSubpileTree.setActionCommand(StockpileAction.SUBPILE_TREE.name());
jShowSubpileTree.addActionListener(listener);
jShow.add(jShowSubpileTree);

jToolBar.addSeparator();

Expand Down Expand Up @@ -706,7 +717,7 @@ private void updateToolbar() {
jToolBar.addButton(jExpandGroup);
jToolBar.addButton(jCollapseStockpile);
jToolBar.addButton(jExpandStockpile);
toolBarMinWidth = jToolBar.getMinimumSize().width;
toolBarMinWidth = jToolBar.getPreferredSize().width;
collapsed = false;
}
int width = jToolBar.getVisibleRect().width;
Expand Down Expand Up @@ -867,7 +878,7 @@ private void expandGroups(boolean expand, GroupMatching match) {
String group = Settings.get().getStockpileGroupSettings().getGroup(stockpile);
if (match.matches(group) && Settings.get().getStockpileGroupSettings().isGroupExpanded(group) != expand) { //Match group + is changed
stockpileItems.addAll(stockpile.getItems());
stockpileItems.addAll(stockpile.getSubpileItems());
stockpileItems.addAll(stockpile.getSubpileTableItems());
if (Settings.get().getStockpileGroupSettings().isGroupFirst(stockpile)) {
ignoreItems.add(stockpile.getIgnoreItem());
}
Expand Down Expand Up @@ -981,13 +992,13 @@ private void updateGroups(String group, List<Stockpile> removeStockpiles, List<S
List<StockpileItem> addStockpileItems = new ArrayList<>();
for (Stockpile stockpile : addStockiples) {
addStockpileItems.addAll(stockpile.getItems());
addStockpileItems.addAll(stockpile.getSubpileItems());
addStockpileItems.addAll(stockpile.getSubpileTableItems());
}
//Remove StockpileItems
List<StockpileItem> removeStockpileItems = new ArrayList<>();
for (Stockpile stockpile : removeStockpiles) {
removeStockpileItems.addAll(stockpile.getItems());
removeStockpileItems.addAll(stockpile.getSubpileItems());
removeStockpileItems.addAll(stockpile.getSubpileTableItems());
}
//All Stockpile Items
List<Stockpile> stockpiles = new ArrayList<>();
Expand Down Expand Up @@ -1613,6 +1624,28 @@ public void actionPerformed(final ActionEvent e) {
} //Else: Not changed
}
}
} else if (StockpileAction.SUBPILE_TREE.name().equals(e.getActionCommand())) {
List<StockpileItem> updated = new ArrayList<>();
for (Stockpile stockpile : getShownStockpiles()) {
String group = Settings.get().getStockpileGroupSettings().getGroup(stockpile);
if (Settings.get().getStockpileGroupSettings().isGroupExpanded(group)) { //Stockpile group expanded or not in group
updated.addAll(stockpile.getSubpileStocks());
}
}
try {
eventList.getReadWriteLock().writeLock().lock();
if (jShowSubpileTree.isSelected()) {
eventList.addAll(updated);
} else {
eventList.removeAll(updated);
}
} finally {
eventList.getReadWriteLock().writeLock().unlock();
}
Settings.lock("Show Subpile Tree");
Settings.get().setShowSubpileTree(jShowSubpileTree.isSelected());
Settings.unlock("Show Subpile Tree");
program.saveSettings("Show Subpile Tree");
} else if (StockpileAction.COLLAPSE.name().equals(e.getActionCommand())) { //Collapse all
jTable.expandSeparators(false);
} else if (StockpileAction.EXPAND.name().equals(e.getActionCommand())) { //Expand all
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/nikr/eve/jeveasset/i18n/TabsStockpile.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ public TabsStockpile(final Locale locale) {
public abstract String shoppingList();
public abstract String showHidden();
public abstract String showHide();
public abstract String showStockpiles();
public abstract String showSubpileTree();
public abstract String shownValueNeeded();
public abstract String shownValueNow();
public abstract String shownVolumeNeeded();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ selectStockpiles=Select Stockpiles
shoppingList=Shopping List
showHidden=Show Hidden
showHide=Show/Hide
showStockpiles=Stockpiles
showSubpileTree=Show Subpile Tree
shownValueNeeded=Total surplus value of shown items
shownValueNow=Total stock value of shown items
shownVolumeNeeded=Total surplus volume of shown items
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/net/nikr/eve/jeveasset/tests/mocks/FakeSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -757,4 +757,14 @@ public void setToolsLocked(boolean toolsLocked) {
public boolean isToolsLocked() {
throw new UnsupportedOperationException("not implemented");
}

@Override
public void setShowSubpileTree(boolean showSubpileTree) {
throw new UnsupportedOperationException("not implemented");
}

@Override
public boolean isShowSubpileTree() {
throw new UnsupportedOperationException("not implemented");
}
}

0 comments on commit 0bf01e1

Please sign in to comment.