diff --git a/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/StockpileShoppingListDialog.java b/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/StockpileShoppingListDialog.java index 07de0e747..d70ce2ecb 100644 --- a/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/StockpileShoppingListDialog.java +++ b/src/main/java/net/nikr/eve/jeveasset/gui/tabs/stockpile/StockpileShoppingListDialog.java @@ -27,6 +27,7 @@ import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collections; +import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -77,21 +78,16 @@ private enum StockpileShoppingListAction { FORMAT_CHANGED } - private final DecimalFormat number = new DecimalFormat("0"); + private static final DecimalFormat NUMBER = new DecimalFormat("0"); private final JTextArea jText; private final JButton jClose; private final JTextField jPercentFull; private final JTextField jPercentIgnore; - private final JComboBox jFormat; + private final JComboBox jFormat; private final JComboBox jOutput; - private String missingShoppingList = ""; - private String missingEveMultibuy = ""; - private String requiredShoppingList = ""; - private String requiredEveMultibuy = ""; - private String ownedShoppingList = ""; - private String ownedEveMultibuy = ""; + private Map outputData = new EnumMap<>(ShoppingListType.class); private List stockpiles; private boolean updating = false; @@ -106,12 +102,8 @@ private enum StockpileShoppingListAction { jCopyToClipboard.setActionCommand(StockpileShoppingListAction.CLIPBOARD_STOCKPILE.name()); jCopyToClipboard.addActionListener(listener); - String[] formats = {TabsStockpile.get().shoppingList(), TabsStockpile.get().eveMultibuy()}; - jFormat = new JComboBox<>(formats); - IconListCellRendererRenderer renderer = new IconListCellRendererRenderer(); - renderer.add(TabsStockpile.get().shoppingList(), Images.STOCKPILE_SHOPPING_LIST.getIcon()); - renderer.add(TabsStockpile.get().eveMultibuy(), Images.MISC_EVE.getIcon()); - jFormat.setRenderer(renderer); + jFormat = new JComboBox<>(ShoppingListType.values()); + jFormat.setRenderer(new IconListCellRendererRenderer()); jFormat.setActionCommand(StockpileShoppingListAction.FORMAT_CHANGED.name()); jFormat.addActionListener(listener); @@ -227,7 +219,10 @@ private void updateList() { } catch (NumberFormatException e) { hide = 100; } - + outputData.clear(); + for (ShoppingListType type : ShoppingListType.values()) { + outputData.put(type, new ShoppingListData(type)); + } //All claims Map> claims = new HashMap<>(); Map subpiles = new HashMap<>(); @@ -263,8 +258,17 @@ private void updateList() { } } } - - //All items + StringBuilder subpileNamesBuilder = new StringBuilder(); + for (Map.Entry entry : subpiles.entrySet()) { + subpileNamesBuilder.append(Formatter.copyFormat(entry.getValue())); + subpileNamesBuilder.append("x "); + subpileNamesBuilder.append(entry.getKey()); + subpileNamesBuilder.append("\r\n"); + } + for (ShoppingListData data : outputData.values()) { + data.printHeader(stockpileNamesBuilder, subpileNamesBuilder, subpiles, percent); + } + //All items Map> items = new HashMap<>(); //Assets for (MyAsset asset : program.getAssetsList()) { @@ -303,8 +307,6 @@ private void updateList() { } //Owned before claming - StringBuilder ownedShoppingListBuilder = new StringBuilder(); - StringBuilder ownedEveMultibuyBuilder = new StringBuilder(); double ownedVolume = 0; double ownedValue = 0; for (Map.Entry> entry : items.entrySet()) { @@ -339,7 +341,9 @@ private void updateList() { //Required value ownedValue = ownedValue + (count.getCount() * price); } - printItem(ownedEveMultibuyBuilder, ownedShoppingListBuilder, ownedCount, item, bpc, bpo, runs); + for (ShoppingListData data : outputData.values()) { + data.printOwned(ownedCount, item, bpc, bpo, runs); + } } //Claim items for (Map.Entry> entry : items.entrySet()) { @@ -348,10 +352,6 @@ private void updateList() { } } //Show missing - StringBuilder missingShoppingListBuilder = new StringBuilder(); - StringBuilder missingEveMultibuyBuilder = new StringBuilder(); - StringBuilder requiredShoppingListBuilder = new StringBuilder(); - StringBuilder requiredEveMultibuyBuilder = new StringBuilder(); double missingVolume = 0; double missingValue = 0; double requiredVolume = 0; @@ -388,91 +388,20 @@ private void updateList() { //Required value requiredValue = requiredValue + (stockClaim.getTotalNeed() * stockClaim.getDynamicPrice()); } - printItem(missingEveMultibuyBuilder, missingShoppingListBuilder, missingCount, item, bpc, bpo, runs); - printItem(requiredEveMultibuyBuilder, requiredShoppingListBuilder, requiredCount, item, bpc, bpo, runs); + for (ShoppingListData data : outputData.values()) { + data.printMissing(missingCount, item, bpc, bpo, runs); + data.printRequired(requiredCount, item, bpc, bpo, runs); + } } - StringBuilder subpileNamesBuilder = new StringBuilder(); - for (Map.Entry entry : subpiles.entrySet()) { - subpileNamesBuilder.append(Formatter.copyFormat(entry.getValue())); - subpileNamesBuilder.append("x "); - subpileNamesBuilder.append(entry.getKey()); - subpileNamesBuilder.append("\r\n"); + for (ShoppingListData data : outputData.values()) { + data.printFooterMissing(missingVolume, missingValue); + data.printFooterRequired(requiredVolume, requiredValue); + data.printFooterOwned(ownedVolume, ownedValue); } - printTotals(ownedShoppingListBuilder, ownedVolume, ownedValue); - printTotals(missingShoppingListBuilder, missingVolume, missingValue); - printTotals(requiredShoppingListBuilder, requiredVolume, requiredValue); - - missingShoppingList = printResult(stockpileNamesBuilder, subpileNamesBuilder, missingShoppingListBuilder, subpiles, percent); - missingEveMultibuy = missingEveMultibuyBuilder.toString(); - requiredShoppingList = printResult(stockpileNamesBuilder, subpileNamesBuilder, requiredShoppingListBuilder, subpiles, percent); - requiredEveMultibuy = requiredEveMultibuyBuilder.toString(); - ownedShoppingList = printResult(stockpileNamesBuilder, subpileNamesBuilder, ownedShoppingListBuilder, subpiles, percent); - ownedEveMultibuy = ownedEveMultibuyBuilder.toString(); setText(); } - private void printItem(StringBuilder eveMultibuyBuilder, StringBuilder shoppingListBuilder, long count, Item item, boolean bpc, boolean bpo, boolean runs) { - if (count > 0) { //Add type string (if anything is needed) - //Multibuy - eveMultibuyBuilder.append(item.getTypeName()); - eveMultibuyBuilder.append(" "); - eveMultibuyBuilder.append(number.format(count)); - eveMultibuyBuilder.append("\r\n"); - //Shopping List - shoppingListBuilder.append(Formatter.longFormat(count)); - shoppingListBuilder.append("x "); - shoppingListBuilder.append(item.getTypeName()); - if (bpc) { - if (runs) { - shoppingListBuilder.append(" (Runs)"); - } else { - shoppingListBuilder.append(" (BPC)"); - } - } else if (bpo) { - shoppingListBuilder.append(" (BPO)"); - } - shoppingListBuilder.append("\r\n"); - } - } - private void printTotals(StringBuilder shoppingListBuilder, double volume, double value) { - if (shoppingListBuilder.length() == 0) { //if string is empty, nothing is needed - shoppingListBuilder.append(TabsStockpile.get().nothingNeeded()); - } else { //Add total volume and value - shoppingListBuilder.append("\r\n"); - shoppingListBuilder.append(TabsStockpile.get().totalToHaul()); - shoppingListBuilder.append(Formatter.doubleFormat(Math.abs(volume))); - shoppingListBuilder.append("\r\n"); - shoppingListBuilder.append(TabsStockpile.get().estimatedMarketValue()); - shoppingListBuilder.append(Formatter.iskFormat(Math.abs(value))); - } - } - - private String printResult(StringBuilder stockpileNames, StringBuilder subpileNames, StringBuilder shoppingList, Map subpiles, long percent) { - StringBuilder resultBuilder = new StringBuilder(); - //Add stockpile - resultBuilder.append(TabsStockpile.get().stockpileShoppingList()); - if (percent != 100) { //adds percent if it's not 100% - resultBuilder.append(" ("); - resultBuilder.append(percent); - resultBuilder.append(TabsStockpile.get().percent()); - resultBuilder.append(")"); - } - resultBuilder.append(":\r\n"); - resultBuilder.append(stockpileNames.toString()); - resultBuilder.append("\r\n"); - //Add subpiles - if (!subpiles.isEmpty()) { - resultBuilder.append(TabsStockpile.get().subpileShoppingList()); - resultBuilder.append("\r\n"); - resultBuilder.append(subpileNames.toString()); - resultBuilder.append("\r\n"); - } - resultBuilder.append(TabsStockpile.get().itemsShoppingList()); - resultBuilder.append("\r\n"); - resultBuilder.append(shoppingList.toString()); - return resultBuilder.toString(); - } //Add claims to item private void add(final TypeIdentifier typeID, final Object object, final Map> claims, final Map> items) { @@ -509,24 +438,11 @@ private void add(final TypeIdentifier typeID, final Object object, final Map { - DefaultListCellRenderer renderer = new DefaultListCellRenderer(); - Map icons = new HashMap<>(); + private static enum ShoppingListType { + SHOPPING_LIST(TabsStockpile.get().shoppingList(), Images.STOCKPILE_SHOPPING_LIST.getIcon()){ + @Override + public void printHeader(StringBuilder stockpileNames, StringBuilder subpileNames, StringBuilder builder, Map subpiles, long percent) { + //Add stockpile + builder.append(TabsStockpile.get().stockpileShoppingList()); + if (percent != 100) { //adds percent if it's not 100% + builder.append(" ("); + builder.append(percent); + builder.append(TabsStockpile.get().percent()); + builder.append(")"); + } + builder.append(":\r\n"); + builder.append(stockpileNames.toString()); + builder.append("\r\n"); + //Add subpiles + if (!subpiles.isEmpty()) { + builder.append(TabsStockpile.get().subpileShoppingList()); + builder.append("\r\n"); + builder.append(subpileNames.toString()); + builder.append("\r\n"); + } + builder.append(TabsStockpile.get().itemsShoppingList()); + builder.append("\r\n"); + } + @Override + public void printItem(StringBuilder builder, long count, Item item, boolean bpc, boolean bpo, boolean runs) { + //Shopping List + builder.append(Formatter.longFormat(count)); + builder.append("x "); + builder.append(item.getTypeName()); + if (bpc) { + if (runs) { + builder.append(" (Runs)"); + } else { + builder.append(" (BPC)"); + } + } else if (bpo) { + builder.append(" (BPO)"); + } + builder.append("\r\n"); + } + @Override + public void printFooter(StringBuilder builder, double volume, double value, boolean empty) { + if (empty) { //if string is empty, nothing is needed + builder.append(TabsStockpile.get().nothingNeeded()); + } else { //Add total volume and value + builder.append("\r\n"); + builder.append(TabsStockpile.get().totalToHaul()); + builder.append(Formatter.doubleFormat(Math.abs(volume))); + builder.append("\r\n"); + builder.append(TabsStockpile.get().estimatedMarketValue()); + builder.append(Formatter.iskFormat(Math.abs(value))); + } + } + }, + EVE_MULTIBUY(TabsStockpile.get().eveMultibuy(), Images.MISC_EVE.getIcon()){ + @Override + public void printItem(StringBuilder builder, long count, Item item, boolean bpc, boolean bpo, boolean runs) { + //Multibuy + builder.append(item.getTypeName()); + builder.append(" "); + builder.append(NUMBER.format(count)); + builder.append("\r\n"); + } + }, + CSV(TabsStockpile.get().csv(), Images.TABLE_COLUMN_RESIZE.getIcon()){ + @Override + public void printItem(StringBuilder builder, long count, Item item, boolean bpc, boolean bpo, boolean runs) { + //CSV + if (item.getTypeName().contains("\"") + || item.getTypeName().contains(",")) { + builder.append("\""); + builder.append(item.getTypeName().replace("\"", "\"\"")); + builder.append("\""); + } else { + builder.append(item.getTypeName()); + } + builder.append(","); + builder.append(NUMBER.format(count)); + builder.append("\r\n"); + } + }, + SPREADSHEET(TabsStockpile.get().spreadsheet(), Images.TABLE_COLUMN_SHOW.getIcon()){ + @Override + public void printItem(StringBuilder builder, long count, Item item, boolean bpc, boolean bpo, boolean runs) { + //CSV + builder.append(item.getTypeName()); + builder.append("\t"); + builder.append(NUMBER.format(count)); + builder.append("\r\n"); + } + }; + + private final String name; + private final Icon icon; + + private ShoppingListType(String name, Icon icon) { + this.name = name; + this.icon = icon; + } + + public Icon getIcon() { + return icon; + } @Override - public Component getListCellRendererComponent(JList list, String value, int index, boolean isSelected, boolean cellHasFocus) { - Component component = renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (component instanceof JLabel) { - JLabel jLabel = (JLabel) component; - jLabel.setIcon(icons.get(value)); + public String toString() { + return name; + } + + public void printHeader(StringBuilder stockpileNames, StringBuilder subpileNames, StringBuilder builder, Map subpiles, long percent) { } + public abstract void printItem(StringBuilder builder, long count, Item item, boolean bpc, boolean bpo, boolean runs); + public void printFooter(StringBuilder builder, double volume, double value, boolean empty) { } + } + + private static class ShoppingListData { + private final ShoppingListType type; + private final StringBuilder missingBuilder = new StringBuilder(); + private final StringBuilder requiredBuilder = new StringBuilder(); + private final StringBuilder ownedBuilder = new StringBuilder(); + private boolean missingEmpty = true; + private boolean requiredEmpty = true; + private boolean ownedEmpty = true; + + public ShoppingListData(ShoppingListType type) { + this.type = type; + } + + public String get(Object output) { + if (TabsStockpile.get().itemsMissing().equals(output)) { + return missingBuilder.toString(); + } else if (TabsStockpile.get().itemsOwned().equals(output)) { + return ownedBuilder.toString(); + } else { + return requiredBuilder.toString(); + } + } + + private void printOwned(long count, Item item, boolean bpc, boolean bpo, boolean runs) { + if (count > 0) { + ownedEmpty = false; + type.printItem(ownedBuilder, count, item, bpc, bpo, runs); } - return component; } - public void add(String text, Icon icon) { - icons.put(text, icon); + private void printRequired(long count, Item item, boolean bpc, boolean bpo, boolean runs) { + if (count > 0) { + requiredEmpty = false; + type.printItem(requiredBuilder, count, item, bpc, bpo, runs); + } } - public void remove(String text) { - icons.remove(text); + private void printMissing(long count, Item item, boolean bpc, boolean bpo, boolean runs) { + if (count > 0) { + missingEmpty = false; + type.printItem(missingBuilder, count, item, bpc, bpo, runs); + } + } + + private void printFooterOwned(double volume, double value) { + type.printFooter(ownedBuilder, volume, value, ownedEmpty); + } + private void printFooterRequired(double volume, double value) { + type.printFooter(requiredBuilder, volume, value, requiredEmpty); + } + private void printFooterMissing(double volume, double value) { + type.printFooter(missingBuilder, volume, value, missingEmpty); } - public void clear() { - icons.clear(); + private void printHeader(StringBuilder stockpileNamesBuilder, StringBuilder subpileNamesBuilder, Map subpiles, long percent) { + type.printHeader(stockpileNamesBuilder, subpileNamesBuilder, ownedBuilder, subpiles, percent); + type.printHeader(stockpileNamesBuilder, subpileNamesBuilder, requiredBuilder, subpiles, percent); + type.printHeader(stockpileNamesBuilder, subpileNamesBuilder, missingBuilder, subpiles, percent); + } + } + + private static class IconListCellRendererRenderer implements ListCellRenderer { + DefaultListCellRenderer renderer = new DefaultListCellRenderer(); + + @Override + public Component getListCellRendererComponent(JList list, ShoppingListType value, int index, boolean isSelected, boolean cellHasFocus) { + Component component = renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if (component instanceof JLabel) { + JLabel jLabel = (JLabel) component; + jLabel.setIcon(value.getIcon()); + } + return component; } } } diff --git a/src/main/java/net/nikr/eve/jeveasset/i18n/TabsStockpile.java b/src/main/java/net/nikr/eve/jeveasset/i18n/TabsStockpile.java index af5f1b139..19ad9fcdf 100644 --- a/src/main/java/net/nikr/eve/jeveasset/i18n/TabsStockpile.java +++ b/src/main/java/net/nikr/eve/jeveasset/i18n/TabsStockpile.java @@ -68,6 +68,7 @@ public TabsStockpile(final Locale locale) { public abstract String contractsMatchAllTip(); public abstract String copy(); public abstract String countMinimum(); + public abstract String csv(); public abstract String delete(); public abstract String deleteItem(); public abstract String deleteItemTitle(); @@ -212,6 +213,7 @@ public TabsStockpile(final Locale locale) { public abstract String shownVolumeNow(); public abstract String singleton(); public abstract String source(); + public abstract String spreadsheet(); public abstract String station(); public abstract String stockpile(); public abstract String stockpileAvailable(); diff --git a/src/main/resources/net/nikr/eve/jeveasset/i18n/TabsStockpile.properties b/src/main/resources/net/nikr/eve/jeveasset/i18n/TabsStockpile.properties index 2b6d5ab0c..014836f9c 100644 --- a/src/main/resources/net/nikr/eve/jeveasset/i18n/TabsStockpile.properties +++ b/src/main/resources/net/nikr/eve/jeveasset/i18n/TabsStockpile.properties @@ -31,6 +31,7 @@ contractsMatchAll=Matching All contractsMatchAllTip=Only include contract that have all the stockpile items copy=Blueprint Copy countMinimum=Minimum Count +csv=CSV delete=Delete deleteItem=Delete Item deleteItemTitle=Delete Item @@ -175,6 +176,7 @@ shownVolumeNeeded=Total surplus volume of shown items shownVolumeNow=Total stock volume of shown items singleton=Singleton source=Source +spreadsheet=Spreadsheet station=Station stockpile=Stockpile stockpileAvailable=Available: