Skip to content

Commit

Permalink
filenames properly added
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamDman committed Nov 24, 2016
1 parent 2601264 commit 5daf384
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 23 deletions.
Binary file added PhotoLayout-2016-11-23.exe
Binary file not shown.
Binary file added PhotoLayout.jar
Binary file not shown.
53 changes: 38 additions & 15 deletions src/FormPrompt.form
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormPrompt">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="5" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="7" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
Expand All @@ -18,7 +18,7 @@
</component>
<component id="955b2" class="javax.swing.JTextField" binding="path_save_field">
<constraints>
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="0" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
Expand All @@ -34,7 +34,7 @@
</component>
<scrollpane id="ff455">
<constraints>
<grid row="1" column="1" row-span="2" col-span="3" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="1" column="1" row-span="4" col-span="4" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
Expand All @@ -53,41 +53,64 @@
<text value="CLEAR"/>
</properties>
</component>
<component id="df2d6" class="javax.swing.JButton" binding="addFilesButton" default-binding="true">
<constraints>
<grid row="3" 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="Add Files"/>
</properties>
</component>
<component id="4dab1" class="javax.swing.JButton" binding="beginButton" default-binding="true">
<constraints>
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="5" column="4" 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="Begin"/>
</properties>
</component>
<hspacer id="4c58e">
<constraints>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="29f99" class="javax.swing.JButton" binding="path_save_prompt">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="0" column="4" 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>
<component id="ac677" class="javax.swing.JProgressBar" binding="prog">
<constraints>
<grid row="4" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="6" column="0" row-span="1" col-span="5" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="df2d6" class="javax.swing.JButton" binding="addFilesButton" default-binding="true">
<constraints>
<grid row="4" 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="Add Files"/>
</properties>
</component>
<vspacer id="bddc6">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="dbd86" class="javax.swing.JLabel">
<constraints>
<grid row="5" 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="Text between names:"/>
</properties>
</component>
<component id="67be2" class="javax.swing.JTextField" binding="nameField">
<constraints>
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="+"/>
</properties>
</component>
</children>
</grid>
</form>
5 changes: 4 additions & 1 deletion src/FormPrompt.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
Expand All @@ -18,6 +19,7 @@ public class FormPrompt {
private JButton addFilesButton;
private JButton CLEARButton;
private JProgressBar prog;
private JTextField nameField;

private File path_open_dir = new File("./");
private File path_save_dir = new File("./");
Expand Down Expand Up @@ -105,7 +107,7 @@ public void mouseClicked(MouseEvent e) {
beginButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
PhotoLayout.beginParse();
PhotoLayout.beginParse(nameField.getText());
}
});
CLEARButton.addMouseListener(new MouseAdapter() {
Expand All @@ -114,5 +116,6 @@ public void mouseClicked(MouseEvent e) {
clearList();
}
});

}
}
34 changes: 27 additions & 7 deletions src/PhotoLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;

Expand Down Expand Up @@ -38,19 +39,19 @@ public static void main(String[] args) {
FormPrompt.main(args);
}

public static void beginParse() {
public static void beginParse(String splitText) {
if (path_save == null) {
JPanel gui = new JPanel(new BorderLayout(3, 3));
JLabel label = new JLabel();
label.setText("You did not set a save path!");
gui.add(label);
JOptionPane.showMessageDialog(null, gui);
} else {
stitchImages();
stitchImages(splitText);
}
}

private static void stitchImages() {
private static void stitchImages(String splitText) {
Thread thread = new Thread() {
@Override
public void run() {
Expand All @@ -70,10 +71,14 @@ public void run() {
drawCentered(graphics, imgB);
graphics.dispose();

String name = imagePair.fileA.getName().substring(0, 5) + imagePair.fileB.getName().substring(0, 5);
File output = new File(PhotoLayout.getSavePath().getAbsoluteFile() + File.separator + name + ".jpg");

ImageIO.write(imgBuffer, "JPEG", output);
String name = buildName(imagePair.fileA,imagePair.fileB,splitText);
try {
File output = new File(PhotoLayout.getSavePath().getAbsoluteFile() + File.separator + name + ".jpg");
ImageIO.write(imgBuffer, "JPEG", output);
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Files failed to save, check that the split text is valid");
break;
}


if (index > 0) {
Expand All @@ -88,6 +93,20 @@ public void run() {
}
};
thread.start();
try {
Runtime.getRuntime().exec("explorer.exe " + PhotoLayout.getSavePath().getAbsoluteFile());
} catch (Exception e) {
e.printStackTrace();
}
}

private static String buildName(File A, File B,String splitText) {
return chopExtension(A.getName())+ splitText + chopExtension(B.getName());
}

private static String chopExtension(String name) {
int i = name.lastIndexOf(".");
return i==-1?name:name.substring(0,i);
}

private static void drawCentered(Graphics2D graphics, BufferedImage image) {
Expand All @@ -113,6 +132,7 @@ private static void drawCentered(Graphics2D graphics, BufferedImage image) {
height = (int) (height * scale);
int dx = (width - 1200) / 2;
int dy = (height - 900) / 2;
graphics.setClip(0,0,1200,900);
graphics.translate(-dx, -dy);
graphics.drawImage(image, trans, null);
graphics.translate(dx, -dy);
Expand Down

0 comments on commit 5daf384

Please sign in to comment.