Skip to content

Instantly share code, notes, and snippets.

@IgorVodka
Created May 13, 2019 22:48
Show Gist options
  • Select an option

  • Save IgorVodka/fdfdb946e28335aa3b26f6c49d72cd7c to your computer and use it in GitHub Desktop.

Select an option

Save IgorVodka/fdfdb946e28335aa3b26f6c49d72cd7c to your computer and use it in GitHub Desktop.
Index: .idea/vcs.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- .idea/vcs.xml (date 1551557351000)
+++ .idea/vcs.xml (date 1551557351000)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="VcsDirectoryMappings">
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
+ </component>
+</project>
\ No newline at end of file
Index: src/iu5/sendbycom/gui/ParamsDialog.form
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/iu5/sendbycom/gui/ParamsDialog.form (date 1557787160000)
+++ src/iu5/sendbycom/gui/ParamsDialog.form (date 1557787160000)
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="iu5.sendbycom.gui.ParamsDialog">
+ <grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+ <margin top="10" left="10" bottom="10" right="10"/>
+ <constraints>
+ <xy x="48" y="54" width="539" height="297"/>
+ </constraints>
+ <properties/>
+ <border type="none"/>
+ <children>
+ <grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+ <margin top="0" left="0" bottom="0" right="0"/>
+ <constraints>
+ <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties/>
+ <border type="none"/>
+ <children>
+ <hspacer id="98af6">
+ <constraints>
+ <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ </hspacer>
+ <grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
+ <margin top="0" left="0" bottom="0" right="0"/>
+ <constraints>
+ <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties/>
+ <border type="none"/>
+ <children>
+ <component id="e7465" class="javax.swing.JButton" binding="buttonOK">
+ <constraints>
+ <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text value="OK"/>
+ </properties>
+ </component>
+ <component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
+ <constraints>
+ <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text value="Отмена"/>
+ </properties>
+ </component>
+ </children>
+ </grid>
+ </children>
+ </grid>
+ <grid id="e3588" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+ <margin top="0" left="0" bottom="0" right="0"/>
+ <constraints>
+ <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties/>
+ <border type="none"/>
+ <children>
+ <component id="4a0f3" class="javax.swing.JLabel">
+ <constraints>
+ <grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text value="Скорость передачи (бит/сек)"/>
+ </properties>
+ </component>
+ <component id="88527" class="javax.swing.JLabel">
+ <constraints>
+ <grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text value="Кол-во стоп-битов"/>
+ </properties>
+ </component>
+ <component id="7fc0e" class="javax.swing.JLabel">
+ <constraints>
+ <grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text value="Бит чётности"/>
+ </properties>
+ </component>
+ <component id="65678" class="javax.swing.JComboBox" binding="comboBox1" default-binding="true">
+ <constraints>
+ <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <model>
+ <item value="128"/>
+ <item value="256"/>
+ <item value="512"/>
+ <item value="1024"/>
+ </model>
+ </properties>
+ </component>
+ <component id="10786" class="javax.swing.JComboBox" binding="comboBox2" default-binding="true">
+ <constraints>
+ <grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <model>
+ <item value="1"/>
+ <item value="1.5"/>
+ <item value="2"/>
+ </model>
+ </properties>
+ </component>
+ <component id="af194" class="javax.swing.JComboBox" binding="comboBox3" default-binding="true">
+ <constraints>
+ <grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <model>
+ <item value="нет"/>
+ <item value="чётное число единиц"/>
+ <item value="нечётное число единиц"/>
+ <item value="равен 1"/>
+ <item value="равен 0"/>
+ </model>
+ </properties>
+ </component>
+ </children>
+ </grid>
+ </children>
+ </grid>
+</form>
Index: src/iu5/sendbycom/gui/ClientForm.form
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/iu5/sendbycom/gui/ClientForm.form (revision 8d6e3ccf3c819224d55d27fe81f73ecccfcd3f2e)
+++ src/iu5/sendbycom/gui/ClientForm.form (date 1557787632000)
@@ -3,7 +3,7 @@
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="9" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="5" left="5" bottom="5" right="5"/>
<constraints>
- <xy x="20" y="20" width="647" height="455"/>
+ <xy x="20" y="20" width="695" height="455"/>
</constraints>
<properties>
<background color="-1378128"/>
@@ -186,6 +186,14 @@
<properties>
<foreground color="-16777216"/>
<text value="Режим клиента"/>
+ </properties>
+ </component>
+ <component id="886c" class="javax.swing.JButton" binding="paramsButton">
+ <constraints>
+ <grid row="8" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
+ </constraints>
+ <properties>
+ <text value="Параметры"/>
</properties>
</component>
</children>
Index: src/iu5/sendbycom/gui/ClientForm.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/iu5/sendbycom/gui/ClientForm.java (revision 8d6e3ccf3c819224d55d27fe81f73ecccfcd3f2e)
+++ src/iu5/sendbycom/gui/ClientForm.java (date 1557787632000)
@@ -39,6 +39,7 @@
private JProgressBar downloadProgressBar;
private JLabel nettoSpeedLabel;
private JLabel bruttoSpeedLabel;
+ private JButton paramsButton;
String currentPath;
@@ -112,6 +113,17 @@
dirPathTextField.setText(newPath);
});
+ final Port portCopy = this.port;
+
+ paramsButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ ParamsDialog paramsDialog = new ParamsDialog();
+ paramsDialog.pack();
+ paramsDialog.setVisible(true);
+ }
+ });
+
downloadFileButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -215,9 +227,18 @@
long timeDiff = Math.max(1, new Date().getTime() - timeBegan);
+ long netto = (long) Math.min(
+ Math.abs(8000 * bytesReceivedNetto / timeDiff),
+ Math.ceil(portCopy.getBaudRate() * 0.8)
+ );
+ long brutto = (long) Math.min(
+ Math.abs(8000 * bytesReceivedBrutto / timeDiff),
+ portCopy.getBaudRate()
+ );
+
// 8000 = bits/byte * seconds/ms
- nettoSpeedLabel.setText((8000 * bytesReceivedNetto / timeDiff) + " бит/с");
- bruttoSpeedLabel.setText((8000 * bytesReceivedBrutto / timeDiff) + " бит/с");
+ nettoSpeedLabel.setText(netto + " бит/с");
+ bruttoSpeedLabel.setText(brutto + " бит/с");
}
});
} catch (DataTooBigException e1) {
Index: src/iu5/sendbycom/gui/ParamsDialog.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/iu5/sendbycom/gui/ParamsDialog.java (date 1557787112000)
+++ src/iu5/sendbycom/gui/ParamsDialog.java (date 1557787112000)
@@ -0,0 +1,56 @@
+package iu5.sendbycom.gui;
+
+import javax.swing.*;
+import java.awt.event.*;
+
+public class ParamsDialog extends JDialog {
+ private JPanel contentPane;
+ private JButton buttonOK;
+ private JButton buttonCancel;
+ private JComboBox comboBox1;
+ private JComboBox comboBox2;
+ private JComboBox comboBox3;
+
+ public ParamsDialog() {
+ setContentPane(contentPane);
+ setModal(true);
+ getRootPane().setDefaultButton(buttonOK);
+
+ buttonOK.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ onOK();
+ }
+ });
+
+ buttonCancel.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ onCancel();
+ }
+ });
+
+ // call onCancel() when cross is clicked
+ setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ onCancel();
+ }
+ });
+
+ // call onCancel() on ESCAPE
+ contentPane.registerKeyboardAction(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ onCancel();
+ }
+ }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+ }
+
+ private void onOK() {
+ // add your code here
+ dispose();
+ }
+
+ private void onCancel() {
+ // add your code here if necessary
+ dispose();
+ }
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment