Skip to content

Commit

Permalink
Fixed UI not showing on Windows and added basic error message display
Browse files Browse the repository at this point in the history
  • Loading branch information
danwardvs committed Jan 20, 2020
1 parent 0a51132 commit 23110a7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
40 changes: 25 additions & 15 deletions src/pkg/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ public class Menu{
JFileChooser fileChooser;
JLabel sourceLocation;
JLabel destLocation;
JLabel errorMsg;

String sourcePath = "";
String destPath = "";


public static void main(String[] args) {

if(args.length == 0) {
Menu mainMenu = new Menu();
MenuListener.setMenuReference(mainMenu);
Expand All @@ -42,39 +43,38 @@ public static void main(String[] args) {

} catch (IOException e) {
// TODO Auto-generated catch block

System.out.println("Failed to view image at path " + args[1]);
}
}

}
}




}
private void showMessage(String newError) {
errorMsg.setText(newError);
}

public Menu() {
// TODO Auto-generated method stub


JFrame frame = new JFrame("Danpression");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(700,400);
frame.setVisible(true);

JPanel mainPanel = new JPanel(new GridLayout(1,2));

frame.add(mainPanel);

JPanel decodePanel = new JPanel(new GridLayout(5,1));
JPanel decodePanel = new JPanel(new GridLayout(6,1));
mainPanel.add(decodePanel);

viewButton = new JButton("View .dan image");
viewButton.addActionListener(new MenuListener("viewButton"));

decodePanel.add(viewButton);

decodePanel.add(viewButton);



JPanel encodePanel = new JPanel(new GridLayout(5,1));
JPanel encodePanel = new JPanel(new GridLayout(6,1));
mainPanel.add(encodePanel);


Expand All @@ -89,15 +89,21 @@ public Menu() {

sourceLocation = new JLabel("No file loaded.");
destLocation = new JLabel("No destination set.");
errorMsg = new JLabel("");


encodePanel.add(sourceButton);
encodePanel.add(sourceLocation);
encodePanel.add(destButton);
encodePanel.add(destLocation);
encodePanel.add(encodeButton);
encodePanel.add(errorMsg);

fileChooser = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());


frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(700,400);
frame.setVisible(true);

}

Expand Down Expand Up @@ -142,9 +148,12 @@ public void encodeFile() {
}else {
try {
Saver.Write(sourcePath,destPath);
} catch (IOException e) {
showMessage("Successfully encoded file");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
showMessage(e.getMessage());

}
}
}
Expand All @@ -163,6 +172,7 @@ public void viewImage() {
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
showMessage(e.getMessage());
}
}

Expand Down
18 changes: 12 additions & 6 deletions src/pkg/Saver.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class Saver {

public static void Write(String sourcePath, String destPath) throws IOException {
public static void Write(String sourcePath, String destPath) throws Exception {
CompressArchive.compress(destPath,Saver.processData(sourcePath));

}
Expand Down Expand Up @@ -45,17 +45,23 @@ public static byte[] convertHeader(int width, int height, Pixel[] samples) {
return header_data;
}

public static byte[] processData(String sourcePath) throws IOException {
public static byte[] processData(String sourcePath) throws Exception {

final int SAMPLE_SIZE = 7;

BufferedImage img = null;

img = ImageIO.read(new File(sourcePath));

int height = img.getHeight();
int width = img.getWidth();


int width, height;

if(img != null) {
height = img.getHeight();
width = img.getWidth();
}else {
throw new Exception("Invalid image file");
}

Coordinate[] sample_locs = new Coordinate[SAMPLE_SIZE];

int width_3 = width/3;
Expand Down

0 comments on commit 23110a7

Please sign in to comment.