* Images download: added threads settings in download dialog;

This commit is contained in:
Oleg Agafonov 2020-08-07 12:41:17 +04:00
parent 401d468494
commit 450646ca5e
5 changed files with 108 additions and 35 deletions

View file

@ -20,7 +20,7 @@
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,73,0,0,2,65"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,73,0,0,2,-52"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
@ -223,14 +223,14 @@
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="panelSourceRight">
<Container class="javax.swing.JPanel" name="panelSourceCenter">
<Properties>
<Property name="alignmentX" type="float" value="0.0"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[130, 32767]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[130, 30]"/>
<Dimension value="[130, 10]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[130, 100]"/>
@ -258,7 +258,47 @@
</StringArray>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[90, 25]"/>
<Dimension value="[110, 25]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="panelSourceRight">
<Properties>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[150, 30]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[150, 35]"/>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
<Property name="alignment" type="int" value="3"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="labelDownloadThreads">
<Properties>
<Property name="text" type="java.lang.String" value="Download threads:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="comboDownloadThreads">
<Properties>
<Property name="maximumRowCount" type="int" value="15"/>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
</StringArray>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[110, 25]"/>
</Property>
</Properties>
<AuxValues>
@ -368,10 +408,10 @@
<Dimension value="[130, 32767]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[130, 30]"/>
<Dimension value="[280, 30]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[130, 100]"/>
<Dimension value="[280, 100]"/>
</Property>
</Properties>
@ -379,7 +419,7 @@
<SubComponents>
<Component class="javax.swing.JCheckBox" name="checkboxRedownload">
<Properties>
<Property name="text" type="java.lang.String" value="&lt;html&gt;Re-download selected images"/>
<Property name="text" type="java.lang.String" value="&lt;html&gt;Re-download all images"/>
<Property name="verticalAlignment" type="int" value="3"/>
</Properties>
<Constraints>

View file

@ -19,9 +19,9 @@ public class DownloadImagesDialog extends MageDialog {
public static final int RET_CANCEL = 0;
public static final int RET_OK = 1;
private Dimension sizeModeMessageOnly;
private Dimension sizeModeMessageAndControls;
private Map<Component, Boolean> actionsControlStates = new HashMap<>();
private final Dimension sizeModeMessageOnly;
private final Dimension sizeModeMessageAndControls;
private final Map<Component, Boolean> actionsControlStates = new HashMap<>();
/**
@ -34,9 +34,9 @@ public class DownloadImagesDialog extends MageDialog {
// fix for panelInfo (it's resets aligmentX after netbeans designer opened)
panelInfo.setAlignmentX(CENTER_ALIGNMENT);
// save default sizes
// save default sizes (WARNING, you must sync it manually with designer sizes)
//
this.sizeModeMessageAndControls = new Dimension(580, 330); // dialog -> properties -> designer size
this.sizeModeMessageAndControls = new Dimension(716, 329); // dialog -> properties -> code tab -> designer size
//
this.sizeModeMessageOnly = new Dimension(this.sizeModeMessageAndControls.getSize());
sizeModeMessageOnly.height = 25 * 4;
@ -95,6 +95,10 @@ public class DownloadImagesDialog extends MageDialog {
return this.comboLanguage;
}
public JComboBox getDownloadThreadsCombo() {
return this.comboDownloadThreads;
}
public JComboBox getSetsCombo() {
return this.comboSets;
}
@ -142,6 +146,7 @@ public class DownloadImagesDialog extends MageDialog {
enableActionControl(enable, comboSets);
enableActionControl(enable, buttonSearchSet);
enableActionControl(enable, comboLanguage);
enableActionControl(enable, comboDownloadThreads);
enableActionControl(enable, checkboxRedownload);
}
@ -214,9 +219,12 @@ public class DownloadImagesDialog extends MageDialog {
panelSourceLeft = new javax.swing.JPanel();
labelSource = new javax.swing.JLabel();
comboSource = new javax.swing.JComboBox<>();
panelSourceRight = new javax.swing.JPanel();
panelSourceCenter = new javax.swing.JPanel();
labelLanguage = new javax.swing.JLabel();
comboLanguage = new javax.swing.JComboBox<>();
panelSourceRight = new javax.swing.JPanel();
labelDownloadThreads = new javax.swing.JLabel();
comboDownloadThreads = new javax.swing.JComboBox<>();
panelMode = new javax.swing.JPanel();
panelModeInner = new javax.swing.JPanel();
labelMode = new javax.swing.JLabel();
@ -295,19 +303,33 @@ public class DownloadImagesDialog extends MageDialog {
panelSource.add(panelSourceLeft);
panelSourceRight.setAlignmentX(0.0F);
panelSourceRight.setMaximumSize(new java.awt.Dimension(130, 32767));
panelSourceRight.setMinimumSize(new java.awt.Dimension(130, 30));
panelSourceRight.setPreferredSize(new java.awt.Dimension(130, 100));
panelSourceRight.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEADING));
panelSourceCenter.setAlignmentX(0.0F);
panelSourceCenter.setMaximumSize(new java.awt.Dimension(130, 32767));
panelSourceCenter.setMinimumSize(new java.awt.Dimension(130, 10));
panelSourceCenter.setPreferredSize(new java.awt.Dimension(130, 100));
panelSourceCenter.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEADING));
labelLanguage.setText("Language:");
panelSourceRight.add(labelLanguage);
panelSourceCenter.add(labelLanguage);
comboLanguage.setMaximumRowCount(15);
comboLanguage.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"}));
comboLanguage.setPreferredSize(new java.awt.Dimension(90, 25));
panelSourceRight.add(comboLanguage);
comboLanguage.setPreferredSize(new java.awt.Dimension(110, 25));
panelSourceCenter.add(comboLanguage);
panelSource.add(panelSourceCenter);
panelSourceRight.setMinimumSize(new java.awt.Dimension(150, 30));
panelSourceRight.setPreferredSize(new java.awt.Dimension(150, 35));
panelSourceRight.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEADING));
labelDownloadThreads.setText("Download threads:");
panelSourceRight.add(labelDownloadThreads);
comboDownloadThreads.setMaximumRowCount(15);
comboDownloadThreads.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"}));
comboDownloadThreads.setPreferredSize(new java.awt.Dimension(110, 25));
panelSourceRight.add(comboDownloadThreads);
panelSource.add(panelSourceRight);
@ -350,11 +372,11 @@ public class DownloadImagesDialog extends MageDialog {
panelRedownload.setAlignmentX(0.0F);
panelRedownload.setMaximumSize(new java.awt.Dimension(130, 32767));
panelRedownload.setMinimumSize(new java.awt.Dimension(130, 30));
panelRedownload.setPreferredSize(new java.awt.Dimension(130, 100));
panelRedownload.setMinimumSize(new java.awt.Dimension(280, 30));
panelRedownload.setPreferredSize(new java.awt.Dimension(280, 100));
panelRedownload.setLayout(new java.awt.BorderLayout());
checkboxRedownload.setText("<html>Re-download selected images");
checkboxRedownload.setText("<html>Re-download all images");
checkboxRedownload.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
panelRedownload.add(checkboxRedownload, java.awt.BorderLayout.CENTER);
panelRedownload.add(filler1, java.awt.BorderLayout.PAGE_END);
@ -431,6 +453,7 @@ public class DownloadImagesDialog extends MageDialog {
private javax.swing.JButton buttonSearchSet;
private javax.swing.JButton buttonStop;
private javax.swing.JCheckBox checkboxRedownload;
private javax.swing.JComboBox<String> comboDownloadThreads;
private javax.swing.JComboBox<String> comboLanguage;
private javax.swing.JComboBox<String> comboSets;
private javax.swing.JComboBox<String> comboSource;
@ -444,6 +467,7 @@ public class DownloadImagesDialog extends MageDialog {
private javax.swing.Box.Filler fillerProgress1;
private javax.swing.Box.Filler fillerProgress2;
private javax.swing.Box.Filler fillerglobal2;
private javax.swing.JLabel labelDownloadThreads;
private javax.swing.JLabel labelGlobal;
private javax.swing.JLabel labelInfo;
private javax.swing.JLabel labelLanguage;
@ -458,6 +482,7 @@ public class DownloadImagesDialog extends MageDialog {
private javax.swing.JPanel panelProgress;
private javax.swing.JPanel panelRedownload;
private javax.swing.JPanel panelSource;
private javax.swing.JPanel panelSourceCenter;
private javax.swing.JPanel panelSourceLeft;
private javax.swing.JPanel panelSourceRight;
private javax.swing.JProgressBar progress;

View file

@ -4425,7 +4425,7 @@
</Component>
<Component class="javax.swing.JLabel" name="labelNumberOfDownloadThreads">
<Properties>
<Property name="text" type="java.lang.String" value="Number of download threads:"/>
<Property name="text" type="java.lang.String" value="Default download threads:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cbNumberOfDownloadThreads">

View file

@ -344,6 +344,10 @@ public class PreferencesDialog extends javax.swing.JDialog {
return CardLanguage.valueByCode(getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PREF_LANGUAGE, CardLanguage.ENGLISH.getCode()));
}
public static Integer getPrefDownloadThreads() {
return Integer.parseInt(getCachedValue(KEY_CARD_IMAGES_THREADS, KEY_CARD_IMAGES_THREADS_DEFAULT));
}
private static class ImageFileFilter extends FileFilter {
@Override
@ -487,7 +491,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
txtImageFolderPath = new javax.swing.JTextField();
btnBrowseImageLocation = new javax.swing.JButton();
cbSaveToZipFiles = new javax.swing.JCheckBox();
cbPreferedImageLanguage = new javax.swing.JComboBox<String>();
cbPreferedImageLanguage = new javax.swing.JComboBox<>();
labelPreferedImageLanguage = new javax.swing.JLabel();
labelNumberOfDownloadThreads = new javax.swing.JLabel();
cbNumberOfDownloadThreads = new javax.swing.JComboBox();
@ -548,7 +552,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
txtURLServerList = new javax.swing.JTextField();
jLabel17 = new javax.swing.JLabel();
lblProxyType = new javax.swing.JLabel();
cbProxyType = new javax.swing.JComboBox<ProxyType>();
cbProxyType = new javax.swing.JComboBox<>();
pnlProxySettings = new javax.swing.JPanel();
pnlProxy = new javax.swing.JPanel();
lblProxyServer = new javax.swing.JLabel();
@ -589,7 +593,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
tabThemes = new javax.swing.JPanel();
themesCategory = new javax.swing.JPanel();
lbSelectLabel = new javax.swing.JLabel();
cbTheme = new javax.swing.JComboBox<ThemeType>();
cbTheme = new javax.swing.JComboBox<>();
lbThemeHint = new javax.swing.JLabel();
saveButton = new javax.swing.JButton();
exitButton = new javax.swing.JButton();
@ -1557,12 +1561,12 @@ public class PreferencesDialog extends javax.swing.JDialog {
});
cbPreferedImageLanguage.setMaximumRowCount(20);
cbPreferedImageLanguage.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"}));
cbPreferedImageLanguage.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"}));
labelPreferedImageLanguage.setText("Default images language:");
labelPreferedImageLanguage.setFocusable(false);
labelNumberOfDownloadThreads.setText("Number of download threads:");
labelNumberOfDownloadThreads.setText("Default download threads:");
cbNumberOfDownloadThreads.setMaximumRowCount(20);
cbNumberOfDownloadThreads.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"}));

View file

@ -164,11 +164,14 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
uiDialog.getLaunguagesCombo().setSelectedItem(PreferencesDialog.getPrefImagesLanguage());
reloadLanguagesForSelectedSource();
// DOWNLOAD THREADS
uiDialog.getDownloadThreadsCombo().setModel(new DefaultComboBoxModel<>(new String[]{"10", "9", "8", "7", "6", "5", "4", "3", "2", "1"}));
uiDialog.getDownloadThreadsCombo().setSelectedItem(PreferencesDialog.getPrefDownloadThreads().toString());
// REDOWNLOAD
uiDialog.getRedownloadCheckbox().setSelected(false);
uiDialog.getRedownloadCheckbox().addItemListener(this::checkboxRedowloadChanged);
// SETS (fills after source and language select)
//uiDialog.getSetsCombo().setModel(new DefaultComboBoxModel(DownloadSources.values()));
uiDialog.getSetsCombo().addItemListener((ItemEvent event) -> {
@ -585,7 +588,6 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
}
Connection.ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None"));
Proxy.Type type = Proxy.Type.DIRECT;
switch (configProxyType) {
case HTTP:
@ -610,15 +612,17 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
}
}
int downloadThreadsAmount = Integer.parseInt((String) uiDialog.getDownloadThreadsCombo().getSelectedItem());
if (proxy != null) {
logger.info("Started download of " + cardsDownloadQueue.size() + " images"
+ " from source: " + selectedSource.getSourceName()
+ ", language: " + selectedSource.getCurrentLanguage().getCode());
+ ", language: " + selectedSource.getCurrentLanguage().getCode()
+ ", threads: " + downloadThreadsAmount);
uiDialog.getProgressBar().setString("Preparing download list...");
if (selectedSource.prepareDownloadList(this, cardsDownloadQueue)) {
update(0, cardsDownloadQueue.size());
int numberOfThreads = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_THREADS, PreferencesDialog.KEY_CARD_IMAGES_THREADS_DEFAULT));
ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);
ExecutorService executor = Executors.newFixedThreadPool(downloadThreadsAmount);
for (int i = 0; i < cardsDownloadQueue.size() && !this.isNeedCancel(); i++) {
try {
CardDownloadData card = cardsDownloadQueue.get(i);