Skip to content

Commit

Permalink
Merge pull request #5 from m1kc/project-cleanup
Browse files Browse the repository at this point in the history
Cleanup project
  • Loading branch information
m1kc committed Jan 20, 2020
2 parents c9c09a7 + 30ea879 commit 2541529
Show file tree
Hide file tree
Showing 22 changed files with 824 additions and 2,608 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@
# NetBeans folders #
build/
dist/

# IDE files
*.iml
.idea/
out/
nbproject/
1,400 changes: 0 additions & 1,400 deletions nbproject/build-impl.xml

This file was deleted.

8 changes: 0 additions & 8 deletions nbproject/genfiles.properties

This file was deleted.

Empty file.
7 changes: 0 additions & 7 deletions nbproject/private/private.properties

This file was deleted.

5 changes: 0 additions & 5 deletions nbproject/private/private.xml

This file was deleted.

73 changes: 0 additions & 73 deletions nbproject/project.properties

This file was deleted.

15 changes: 0 additions & 15 deletions nbproject/project.xml

This file was deleted.

191 changes: 97 additions & 94 deletions src/ui/ConnectFrame.java

Large diffs are not rendered by default.

60 changes: 20 additions & 40 deletions src/ui/Main.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package ui;

import javax.swing.UIManager;

/**
*
* @author m1kc
*/
public class Main {
Expand All @@ -22,63 +16,49 @@ public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
for (int i=0; i<args.length; i++)
{
if (args[i].hashCode()=="--developer".hashCode()) developer = true;
if (args[i].hashCode()=="-d".hashCode()) developer = true;
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
if (args[i].hashCode() == "--developer".hashCode()) developer = true;
if (args[i].hashCode() == "-d".hashCode()) developer = true;
}

setLookAndFeel();

cf = new ConnectFrame();
if (!developer) cf.jButton3.setVisible(false);
cf.setVisible(true);
od = new OpenDialog();
}

private static void setLookAndFeel()
{

private static void setLookAndFeel() {
// Well, let's try to set Nimbus explicitly first.
try
{
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
System.out.println("LaF: com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
return; // success
}
catch(Throwable ex)
{
} catch (Throwable ex) {
// do nothing
}

// No? Let's try to find proper class name from the installed LookAndFeel's.
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
{
if ("Nimbus".equals(info.getName()))
{
try
{
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
try {
UIManager.setLookAndFeel(info.getClassName());
System.out.println("LaF: "+info.getClassName()+" (found)");
System.out.println("LaF: " + info.getClassName() + " (found)");
return; // success
}
catch (Throwable ex)
{
} catch (Throwable ex) {
// do nothing
}
}
}

// Still no? Let's just use the system one.
try
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
System.out.println("LaF: "+UIManager.getSystemLookAndFeelClassName()+" (system)");
System.out.println("LaF: " + UIManager.getSystemLookAndFeelClassName() + " (system)");
return; // success
}
catch (Throwable ex2)
{
} catch (Throwable ex2) {
System.out.println("LaF: everything failed, leaving default one");
// Sadly.
}
Expand Down
54 changes: 23 additions & 31 deletions src/ui/Notation.java
Original file line number Diff line number Diff line change
@@ -1,67 +1,59 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package ui;

/**
*
* @author m1kc
*/
public class Notation
{
public class Notation {
/**
* Представляет размер в удобном для чтения человеком виде.
*
* @param sizeInBytes размер в байтах
* @return Размер в удобном для чтения человеком виде (например, "20 байт", "260 Гб")
*/
public static String bestSize(long sizeInBytes)
{
if (sizeInBytes<1024L*10L) return ""+sizeInBytes+" байт";
if (sizeInBytes>=1024L*1024L*1024L*10L) return ""+sizeInBytes/(1024L*1024L*1024L)+" Гб";
if (sizeInBytes>=1024L*1024L*10L) return ""+sizeInBytes/(1024L*1024L)+" Мб";
return ""+sizeInBytes/1024L+" Кб";
public static String bestSize(long sizeInBytes) {
if (sizeInBytes < 1024L * 10L) return "" + sizeInBytes + " байт";
if (sizeInBytes >= 1024L * 1024L * 1024L * 10L) return "" + sizeInBytes / (1024L * 1024L * 1024L) + " Гб";
if (sizeInBytes >= 1024L * 1024L * 10L) return "" + sizeInBytes / (1024L * 1024L) + " Мб";
return "" + sizeInBytes / 1024L + " Кб";
}

/**
* Представляет скорость в удобном для чтения человеком виде.
*
* @param speedInBytesPerSecond скорость в байт/сек
* @return Скорость в удобном для чтения человеком виде (например, "10 байт/cек", "50 Кб/сек")
*/
public static String bestSpeed(long speedInBytesPerSecond)
{
if (speedInBytesPerSecond<1024L*10L) return ""+speedInBytesPerSecond+" байт/сек";
return ""+speedInBytesPerSecond/1024L+" Кб/сек";
public static String bestSpeed(long speedInBytesPerSecond) {
if (speedInBytesPerSecond < 1024L * 10L) return "" + speedInBytesPerSecond + " байт/сек";
return "" + speedInBytesPerSecond / 1024L + " Кб/сек";
}

private static String oNumber(long num)
{
return num<10 ? "0"+num : ""+num;
private static String oNumber(long num) {
return num < 10 ? "0" + num : "" + num;
}

/**
* Представляет время в удобном для чтения человеком виде.
*
* @param timeInMs время в мс
* @return Время в удобном для чтения человеком виде (например, "10:54")
*/
public static String bestTime(long timeInMs)
{
public static String bestTime(long timeInMs) {
//if (timeInMs < 10000L) return ""+timeInMs+" мс";
return ""+(timeInMs/1000L/60)+":"+oNumber(timeInMs/1000L%60);
return "" + (timeInMs / 1000L / 60) + ":" + oNumber(timeInMs / 1000L % 60);
}

/**
* Предоставляет данные в виде, угодном XSP.
*
* @param prefix префикс
* @param curr текущее значение размера
* @param size общее значение размера
* @param speed скорость
* @param curr текущее значение размера
* @param size общее значение размера
* @param speed скорость
* @return Строка, содержащая все аргументы в удобном для чтения человеком виде.
*/
public static String formatAll(String prefix, long curr, long size, long speed, long rest)
{
return prefix+Notation.bestSize(curr)+"/"+Notation.bestSize(size)
+" ("+Notation.bestSpeed(speed)+"), осталось "+bestTime(rest);
public static String formatAll(String prefix, long curr, long size, long speed, long rest) {
return prefix + Notation.bestSize(curr) + "/" + Notation.bestSize(size)
+ " (" + Notation.bestSpeed(speed) + "), осталось " + bestTime(rest);
}
}

0 comments on commit 2541529

Please sign in to comment.