Skip to content

Commit

Permalink
New Feature: Moved stockpile and reprocessing import format selecting…
Browse files Browse the repository at this point in the history
… to the import dialog

Merge develop
  • Loading branch information
GoldenGnu committed Sep 17, 2024
2 parents 67a7ff4 + f7255ca commit bdf0bc5
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 106 deletions.
25 changes: 14 additions & 11 deletions src/main/java/net/nikr/eve/jeveasset/gui/shared/TextImport.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.swing.JOptionPane;
import net.nikr.eve.jeveasset.Program;
import net.nikr.eve.jeveasset.gui.shared.components.JTextDialog;
import net.nikr.eve.jeveasset.gui.shared.components.JTextDialog.TextReturn;
import net.nikr.eve.jeveasset.i18n.GuiShared;
import net.nikr.eve.jeveasset.io.local.text.TextImportType;

Expand All @@ -39,36 +40,38 @@ public TextImport(Program program) {
jTextDialog = new JTextDialog(program.getMainWindow().getFrame());
}

public void importText(TextImportType type, TextImportHandler handler) {
importText("", type, handler);
public void importText(TextImportType[] types, TextImportHandler handler) {
importText("", types, null, handler);
}

private void importText(String text, TextImportType type, TextImportHandler handler) {
private void importText(String text, TextImportType[] types, TextImportType selected, TextImportHandler handler) {
//Get string from clipboard
text = jTextDialog.importText(text, type.getExample());
if (text == null) {
TextReturn<TextImportType> textReturn = jTextDialog.importText(text, types, selected);
String importText = textReturn.getText();
TextImportType importType = textReturn.getType();
if (importText == null || importType == null) {
return; //Cancelled
}

//Validate Input
text = text.trim();
if (text.isEmpty()) { //Empty sting
importText = importText.trim();
if (importText.isEmpty()) { //Empty sting
JOptionPane.showMessageDialog(program.getMainWindow().getFrame(), GuiShared.get().textEmpty(), GuiShared.get().textImport(), JOptionPane.PLAIN_MESSAGE);
return;
}

Map<Integer, Double> data = type.importText(text);
Map<Integer, Double> data = importType.importText(importText);
//Validate Output
if (data == null || data.isEmpty()) {
JOptionPane.showMessageDialog(program.getMainWindow().getFrame(), GuiShared.get().textInvalid(), GuiShared.get().textImport(), JOptionPane.PLAIN_MESSAGE);
importText(text, type, handler); //Again!
importText(importText, types, importType, handler); //Again!
return;
}
//Add items
handler.addItems(data);
handler.addItems(data, importType);
}

public static interface TextImportHandler {
public void addItems(Map<Integer, Double> data);
public void addItems(Map<Integer, Double> data, TextImportType type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
Expand All @@ -53,7 +52,6 @@
import net.nikr.eve.jeveasset.gui.images.Images;
import net.nikr.eve.jeveasset.gui.shared.TextImport;
import net.nikr.eve.jeveasset.gui.shared.TextImport.TextImportHandler;
import net.nikr.eve.jeveasset.gui.shared.components.JDropDownButton;
import net.nikr.eve.jeveasset.gui.shared.components.JFixedToolBar;
import net.nikr.eve.jeveasset.gui.shared.components.JMainTabSecondary;
import net.nikr.eve.jeveasset.gui.shared.filter.FilterControl;
Expand All @@ -79,10 +77,7 @@ private enum ReprocessedAction {
EXPAND,
CLEAR,
ADD_ITEM,
IMPORT_EFT,
IMPORT_ISK_PER_HOUR,
IMPORT_MULTIBUY,
IMPORT_STOCKPILE_SHOPPING_LIST,
IMPORT_TEXT_FORMATS,
}

//GUI
Expand Down Expand Up @@ -139,29 +134,11 @@ public ReprocessedTab(final Program program) {
jClear.addActionListener(listener);
jToolBar.addButton(jClear);

JDropDownButton jImport = new JDropDownButton(TabsReprocessed.get().importButton(), Images.EDIT_IMPORT.getIcon());
JButton jImport = new JButton(TabsReprocessed.get().importButton(), Images.EDIT_IMPORT.getIcon());
jImport.setActionCommand(ReprocessedAction.IMPORT_TEXT_FORMATS.name());
jImport.addActionListener(listener);
jToolBar.addButton(jImport);

JMenuItem jImportEFT = new JMenuItem(TabsReprocessed.get().importEft(), Images.TOOL_SHIP_LOADOUTS.getIcon());
jImportEFT.setActionCommand(ReprocessedAction.IMPORT_EFT.name());
jImportEFT.addActionListener(listener);
jImport.add(jImportEFT);

JMenuItem jImportIskPerHour = new JMenuItem(TabsReprocessed.get().importIskPerHour(), Images.TOOL_VALUES.getIcon());
jImportIskPerHour.setActionCommand(ReprocessedAction.IMPORT_ISK_PER_HOUR.name());
jImportIskPerHour.addActionListener(listener);
jImport.add(jImportIskPerHour);

JMenuItem jImportEve = new JMenuItem(TabsReprocessed.get().importEveMultibuy(), Images.MISC_EVE.getIcon());
jImportEve.setActionCommand(ReprocessedAction.IMPORT_MULTIBUY.name());
jImportEve.addActionListener(listener);
jImport.add(jImportEve);

JMenuItem jImportShoppingList = new JMenuItem(TabsReprocessed.get().importStockpilesShoppingList(), Images.STOCKPILE_SHOPPING_LIST.getIcon());
jImportShoppingList.setActionCommand(ReprocessedAction.IMPORT_STOCKPILE_SHOPPING_LIST.name());
jImportShoppingList.addActionListener(listener);
jImport.add(jImportShoppingList);

jToolBar.addGlue();

JButton jCollapse = new JButton(TabsReprocessed.get().collapse(), Images.MISC_COLLAPSED.getIcon());
Expand Down Expand Up @@ -315,10 +292,10 @@ public void show() {
program.getMainWindow().addTab(this);
}

private void importText(TextImportType type) {
textImport.importText(type, new TextImportHandler() {
private void importText() {
textImport.importText(TextImportType.values(), new TextImportHandler() {
@Override
public void addItems(Map<Integer, Double> data) {
public void addItems(Map<Integer, Double> data, TextImportType type) {
Map<Item, Long> newItems = new HashMap<>();
for (Map.Entry<Integer, Double> entry : data.entrySet()) {
Item item = ApiIdConverter.getItemUpdate(entry.getKey());
Expand Down Expand Up @@ -377,14 +354,8 @@ public void actionPerformed(final ActionEvent e) {
items.put(selectedItem, 1L);
reprocessedData.addItem(eventList, selectedItem, 1L);
}
} else if (ReprocessedAction.IMPORT_EFT.name().equals(e.getActionCommand())) { //Add stockpile (EFT Import)
importText(TextImportType.EFT);
} else if (ReprocessedAction.IMPORT_ISK_PER_HOUR.name().equals(e.getActionCommand())) { //Add stockpile (Isk Per Hour)
importText(TextImportType.ISK_PER_HOUR);
} else if (ReprocessedAction.IMPORT_MULTIBUY.name().equals(e.getActionCommand())) { //Add stockpile (Eve Multibuy)
importText(TextImportType.EVE_MULTIBUY);
} else if (ReprocessedAction.IMPORT_STOCKPILE_SHOPPING_LIST.name().equals(e.getActionCommand())) { //Add stockpile (Shopping List)
importText(TextImportType.STCOKPILE_SHOPPING_LIST);
} else if (ReprocessedAction.IMPORT_TEXT_FORMATS.name().equals(e.getActionCommand())) { //Add stockpile (EFT Import)
importText();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,8 @@ private enum StockpileAction {
EDIT_GROUPS,
SHOPPING_LIST_MULTI,
SHOW_HIDE,
IMPORT_EFT,
IMPORT_ISK_PER_HOUR,
IMPORT_MULTIBUY,
IMPORT_SHOPPING_LIST,
IMPORT_TEXT,
IMPORT_XML_TEXT,
IMPORT_XML,
IMPORT_EVE_XML_FIT,
EXPORT_TEXT,
Expand Down Expand Up @@ -400,38 +397,23 @@ public void componentHidden(ComponentEvent e) { }
JDropDownButton jImport = new JDropDownButton(TabsStockpile.get().importButton(), Images.EDIT_IMPORT.getIcon());
jToolBar.addButton(jImport);

JMenuItem jImportEFT = new JMenuItem(TabsStockpile.get().importEft(), Images.TOOL_SHIP_LOADOUTS.getIcon());
jImportEFT.setActionCommand(StockpileAction.IMPORT_EFT.name());
jImportEFT.addActionListener(listener);
jImport.add(jImportEFT);

JMenuItem jImportIskPerHour = new JMenuItem(TabsStockpile.get().importIskPerHour(), Images.TOOL_VALUES.getIcon());
jImportIskPerHour.setActionCommand(StockpileAction.IMPORT_ISK_PER_HOUR.name());
jImportIskPerHour.addActionListener(listener);
jImport.add(jImportIskPerHour);

JMenuItem jImportEveMultibuy = new JMenuItem(TabsStockpile.get().importEveMultibuy(), Images.MISC_EVE.getIcon());
jImportEveMultibuy.setActionCommand(StockpileAction.IMPORT_MULTIBUY.name());
jImportEveMultibuy.addActionListener(listener);
jImport.add(jImportEveMultibuy);
JMenuItem jImportTextFormats = new JMenuItem(TabsStockpile.get().importText(), Images.STOCKPILE_SHOPPING_LIST.getIcon());
jImportTextFormats.setActionCommand(StockpileAction.IMPORT_TEXT.name());
jImportTextFormats.addActionListener(listener);
jImport.add(jImportTextFormats);

JMenuItem jImportEveXmlFit = new JMenuItem(TabsStockpile.get().importEveXml(), Images.MISC_XML.getIcon());
jImportEveXmlFit.setActionCommand(StockpileAction.IMPORT_EVE_XML_FIT.name());
jImportEveXmlFit.addActionListener(listener);
jImport.add(jImportEveXmlFit);

JMenuItem jImportShoppingList = new JMenuItem(TabsStockpile.get().importShoppingList(), Images.STOCKPILE_SHOPPING_LIST.getIcon());
jImportShoppingList.setActionCommand(StockpileAction.IMPORT_SHOPPING_LIST.name());
jImportShoppingList.addActionListener(listener);
jImport.add(jImportShoppingList);

JMenuItem jImportXml = new JMenuItem(TabsStockpile.get().importStockpilesXml(), Images.TOOL_STOCKPILE.getIcon());
jImportXml.setActionCommand(StockpileAction.IMPORT_XML.name());
jImportXml.addActionListener(listener);
jImport.add(jImportXml);

JMenuItem jImportText = new JMenuItem(TabsStockpile.get().importStockpilesText(), Images.EDIT_COPY.getIcon());
jImportText.setActionCommand(StockpileAction.IMPORT_TEXT.name());
jImportText.setActionCommand(StockpileAction.IMPORT_XML_TEXT.name());
jImportText.addActionListener(listener);
jImport.add(jImportText);

Expand Down Expand Up @@ -1198,10 +1180,10 @@ private void importEveXml() {
}
}

private void importText(TextImportType type) {
textImport.importText(type, new TextImportHandler() {
private void importText() {
textImport.importText(TextImportType.values(), new TextImportHandler() {
@Override
public void addItems(Map<Integer, Double> data) {
public void addItems(Map<Integer, Double> data, TextImportType type) {
importStockpileItems(data, type.getName());
}
});
Expand Down Expand Up @@ -1316,7 +1298,7 @@ private void importXml() {
}
}

private void importText() {
private void importXmlText() {
jTextDialog.setLineWrap(true);
String importText = jTextDialog.importText();
jTextDialog.setLineWrap(false);
Expand Down Expand Up @@ -1656,20 +1638,14 @@ public void actionPerformed(final ActionEvent e) {
jTable.expandSeparators(false);
} else if (StockpileAction.EXPAND.name().equals(e.getActionCommand())) { //Expand all
jTable.expandSeparators(true);
} else if (StockpileAction.IMPORT_EFT.name().equals(e.getActionCommand())) { //Add stockpile (EFT Import)
importText(TextImportType.EFT);
} else if (StockpileAction.IMPORT_ISK_PER_HOUR.name().equals(e.getActionCommand())) { //Add stockpile (Isk Per Hour)
importText(TextImportType.ISK_PER_HOUR);
} else if (StockpileAction.IMPORT_MULTIBUY.name().equals(e.getActionCommand())) { //Add stockpile (Eve Multibuy)
importText(TextImportType.EVE_MULTIBUY);
} else if (StockpileAction.IMPORT_SHOPPING_LIST.name().equals(e.getActionCommand())) { //Add stockpile (Shopping List)
importText(TextImportType.STCOKPILE_SHOPPING_LIST);
} else if (StockpileAction.IMPORT_TEXT.name().equals(e.getActionCommand())) { //Add stockpile (EFT Import)
importText();
} else if (StockpileAction.IMPORT_XML.name().equals(e.getActionCommand())) { //Add stockpile (Xml)
importXml();
} else if (StockpileAction.IMPORT_EVE_XML_FIT.name().equals(e.getActionCommand())) { //Add stockpile (Xml)
importEveXml();
} else if (StockpileAction.IMPORT_TEXT.name().equals(e.getActionCommand())) { //Add stockpile (Xml)
importText();
} else if (StockpileAction.IMPORT_XML_TEXT.name().equals(e.getActionCommand())) { //Add stockpile (Xml)
importXmlText();
} else if (StockpileAction.EXPORT_XML.name().equals(e.getActionCommand())) { //Export XML
exportXml();
} else if (StockpileAction.EXPORT_TEXT.name().equals(e.getActionCommand())) { //Export XML
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/nikr/eve/jeveasset/i18n/GuiShared.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ public GuiShared(final Locale locale) {
public abstract String helpStockpile();
public abstract String helpOpenManual(String title);
public abstract String helpOpenManualTitle();
public abstract String importEft();
public abstract String importEveMultibuy();
public abstract String importIskPerHour();
public abstract String importOptions();
public abstract String importOptionsMerge();
public abstract String importOptionsOverwrite();
public abstract String importOptionsRename();
public abstract String importOptionsSkip();
public abstract String importStockpilesShoppingList();
public abstract String industry();
public abstract String invalidMsg();
public abstract String invalidTitle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public TabsReprocessed(final Locale locale) {
public abstract String expand();
public abstract String grandTotal();
public abstract String importButton();
public abstract String importEft();
public abstract String importEveMultibuy();
public abstract String importIskPerHour();
public abstract String importStockpilesShoppingList();
public abstract String multiplierSign();
public abstract String price();
public abstract String remove();
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/net/nikr/eve/jeveasset/i18n/TabsStockpile.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,9 @@ public TabsStockpile(final Locale locale) {
public abstract String groups();
public abstract String hideStockpile();
public abstract String importButton();
public abstract String importEft();
public abstract String importEveMultibuy();
public abstract String importEveXml();
public abstract String importIskPerHour();
public abstract String importShoppingList();
public abstract String importStockpilesText();
public abstract String importText();
public abstract String importTextFailedMsg();
public abstract String importStockpilesXml();
public abstract String importOptionsAll(int count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

import java.util.HashMap;
import java.util.Map;
import javax.swing.Icon;
import net.nikr.eve.jeveasset.data.sde.Item;
import net.nikr.eve.jeveasset.data.sde.StaticData;
import net.nikr.eve.jeveasset.gui.shared.components.JTextDialog.TextImport;


public abstract class AbstractTextImport {
Expand Down Expand Up @@ -51,6 +53,8 @@ public Map<Integer, Double> importText(String text) {

protected abstract Map<String, Double> doImport(String data);
public abstract String getExample();
public abstract Icon getIcon();
public abstract String getType();

public String getName() {
return name;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/net/nikr/eve/jeveasset/io/local/text/ImportEft.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.Icon;
import net.nikr.eve.jeveasset.data.sde.Item;
import net.nikr.eve.jeveasset.data.sde.StaticData;
import net.nikr.eve.jeveasset.gui.images.Images;
import net.nikr.eve.jeveasset.i18n.GuiShared;


public class ImportEft extends AbstractTextImport {
Expand Down Expand Up @@ -59,6 +62,16 @@ public String getExample() {
;
}

@Override
public Icon getIcon() {
return Images.TOOL_SHIP_LOADOUTS.getIcon();
}

@Override
public String getType() {
return GuiShared.get().importEft();
}

@Override
protected Map<String, Double> doImport(String data) {
//Format and split
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.Icon;
import net.nikr.eve.jeveasset.gui.images.Images;
import net.nikr.eve.jeveasset.i18n.GuiShared;


public class ImportEveMultibuy extends AbstractTextImport {
Expand All @@ -49,6 +52,16 @@ public String getExample() {
;
}

@Override
public Icon getIcon() {
return Images.MISC_EVE.getIcon();
}

@Override
public String getType() {
return GuiShared.get().importEveMultibuy();
}

@Override
protected Map<String, Double> doImport(String data) {
List<String> lines = new ArrayList<>(Arrays.asList(data.split("[\r\n]+")));
Expand Down
Loading

0 comments on commit bdf0bc5

Please sign in to comment.