Browse Source

Project finished

main
Jesus 2 years ago
commit
85ec5e0160
11 changed files with 227 additions and 0 deletions
  1. +12
    -0
      .classpath
  2. +17
    -0
      .project
  3. +2
    -0
      .settings/org.eclipse.core.resources.prefs
  4. +14
    -0
      .settings/org.eclipse.jdt.core.prefs
  5. BIN
      bin/com/jesuspinar/Windowbuild$1.class
  6. BIN
      bin/com/jesuspinar/Windowbuild.class
  7. BIN
      jgoodies-forms-1.8.0-sources.jar
  8. BIN
      jgoodies-forms-1.8.0.jar
  9. BIN
      miglayout-src.zip
  10. BIN
      miglayout15-swing.jar
  11. +182
    -0
      src/com/jesuspinar/Windowbuild.java

+ 12
- 0
.classpath View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="jgoodies-forms-1.8.0.jar" sourcepath="jgoodies-forms-1.8.0-sources.jar"/>
<classpathentry kind="lib" path="miglayout15-swing.jar" sourcepath="miglayout-src.zip"/>
<classpathentry kind="output" path="bin"/>
</classpath>

+ 17
- 0
.project View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MyWindow</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

+ 2
- 0
.settings/org.eclipse.core.resources.prefs View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

+ 14
- 0
.settings/org.eclipse.jdt.core.prefs View File

@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17

BIN
bin/com/jesuspinar/Windowbuild$1.class View File


BIN
bin/com/jesuspinar/Windowbuild.class View File


BIN
jgoodies-forms-1.8.0-sources.jar View File


BIN
jgoodies-forms-1.8.0.jar View File


BIN
miglayout-src.zip View File


BIN
miglayout15-swing.jar View File


+ 182
- 0
src/com/jesuspinar/Windowbuild.java View File

@ -0,0 +1,182 @@
package com.jesuspinar;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.Color;
import javax.swing.JEditorPane;
import java.awt.BorderLayout;
import javax.swing.JToggleButton;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JProgressBar;
import java.awt.FlowLayout;
import java.awt.Button;
import java.awt.GridLayout;
import javax.swing.JTextPane;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.layout.FormSpecs;
import javax.swing.JTextField;
import net.miginfocom.swing.MigLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
public class Windowbuild implements ActionListener{
private JFrame frame;
private JTextField tfInputFile;
private JTextField tfNewName;
private static JButton btnCopy ;
private JProgressBar progressBar;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Windowbuild window = new Windowbuild();
window.frame.setVisible(true);
//Creating event on button click-tap
btnCopy.addActionListener(window);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Windowbuild() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane();
frame.setResizable(false);
frame.getContentPane().setLayout(null);
JLabel lbInput = new JLabel("File path");
lbInput.setBounds(116, 30, 130, 16);
frame.getContentPane().add(lbInput);
tfInputFile = new JTextField();
tfInputFile.setBounds(116, 47, 232, 26);
frame.getContentPane().add(tfInputFile);
tfInputFile.setColumns(10);
JLabel lbNewName = new JLabel("New name");
lbNewName.setBounds(119, 90, 127, 16);
frame.getContentPane().add(lbNewName);
tfNewName = new JTextField();
tfNewName.setColumns(10);
tfNewName.setBounds(116, 105, 232, 26);
frame.getContentPane().add(tfNewName);
btnCopy = new JButton("Copy");
btnCopy.setBounds(116, 168, 232, 47);
frame.getContentPane().add(btnCopy);
progressBar = new JProgressBar(0,100);
progressBar.setBounds(116, 143, 232, 20);
frame.getContentPane().add(progressBar);
}
/**
* This method copies the input file in the same directory and adds the name
* @return true copied
*/
private boolean copyFile() {
String inputPath = tfInputFile.getText().toString();
String newName = tfNewName.getText().toString();
if ( inputPath != "" && newName != "") {
File inputFile = new File(inputPath);
File outputFile = new File(inputFile.getParent(),newName + getExtension(inputFile));
try (FileInputStream fis = new FileInputStream(inputFile);
FileOutputStream fos =
new FileOutputStream(outputFile)
){
byte[] content = fis.readAllBytes(); fis.close();
double pctLoad = 0.01; // 1 = 100%
double loadFraction = (pctLoad * content.length);
int loadIndex = 1;
int i = 0;
for (int j = 0 ; j <= content.length - 1; j++){
if (loadIndex >= (int) loadFraction){
loadIndex = 0;
if (i < progressBar.getMaximum()){
progressBar.setValue(++i);
progressBar.update(progressBar.getGraphics());
}
}
//Action of copy
loadIndex++;
fos.write(content[j]);
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
catch (IOException e) {
throw new RuntimeException(e);
}
//Action complete
progressBar.setValue(progressBar.getMaximum());
progressBar.update(progressBar.getGraphics());
return true;
}
return false;
}
private static String getExtension(File file){
String fileName = file.getName();
return "." + fileName.substring(fileName.lastIndexOf('.') + 1);
}
@Override
public void actionPerformed(ActionEvent e) {
boolean isCopied = copyFile();
if (isCopied){
//TODO : dialog - Done!
}
else {
//TODO : dialog - one fields are empty !
}
}
}

Loading…
Cancel
Save