Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currently refactoring and making changes to interface. Doing bug fixes. #3

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 99 additions & 108 deletions Parallel_Fiji_Visualizer/src/main/java/edu/abc/berkeley/PWZGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,51 @@
import java.io.File;

/*
* PREVIOUS MEETING DISCUSSION
* - Implement constructor that takes in this many arguments. (As shown below)
* ** PWZGUI(string, long, long, long, long, long, long, long, long, long, string) // filepath: string, Starting XYZ: long, ending XYZ: long, chunkSize: long, compressor: string
* CHANGES NEEDED TO BE MADE TO THE INTERFACE
* 1.) Crop Button. By brinding down the crop box, and positioning the widgets similarily to what is being shown in the XML diagrams that we discussed and promptly designed in diagrams.io
* --> Purpose: Cropping the file size of the zarr file we are trying to load by clicking the browse widget.
* 2.) Bring Down and adjust crop widget. Crop widget adjust to the XML formatting. (near/in front of starting and ending XYZ)
* 3.) Make Starting and ending XYZ, with chunk and default compressor seperate from each other

* SIDE NOTE: (Describing by thought process.)
* 1. table for starting & ending XYZ
* 2. another for chunk and compressor.
* NOTE: Dont actually write default, just put compressor.
* NOTES
* 1.) Fix interface to look similarily to the wxWidget diagram from diagram.io [DONE]
* 2.) [IMPORTANT] Integrate the JFileChooser to being used by this interface. [DONE]
* 3.) Seperate Chunk Size and Compressor into their own rows and cols fields. [DONE]
* SOMETHING TO NOTE: Dont actually write default, just put compressor. [DONE]
* 4.) Re-adjusting the crop file size widget to a similar position referenced to the diagrams.io design. [DONE]
* 5.) Once implemented. Refactor and clean up code. Debugging and troubleshooting, so there is no unecessary code not being used. [DONE]
*/

/*
* NOTES
* 1.) Fix interface to look similarily to the wxWidget diagram from diagram.io (DONE)
* 2.) [IMPORTANT] Integrate the JFileChooser to being used by this interface. (DONE)
* 3.) Seperate Chunk Size and Compressor into their own rows and cols fields. (DONE)
* SOMETHING TO NOTE: Dont actually write default, just put compressor.
* 4.) Re-adjusting the crop file size widget to a similar position referenced to the diagrams.io design. (DONE)
* 5.) Once implemented. Refactor and clean up code. Debugging and troubleshooting, so there is no unecessary code not being used. (DONE)
*
* IN-MEETING DISCUSSION
* - Proposing there be a coordinates class. So, instead of passing in 6 variables, we can pass two objects. Also for better readability to the programmer.
* - Easier to handly the X,Y, and Z coordinates.
* - Or we can keep both implementation, in case we may need to edit the specific values directly, possibly.
* HOW TO RESIZES WIDGETS (MEETING NOTES)
* --> Using custom grid layouts. (For future ref, for resizeable widgets)
* FLow should work (Refactor)

What should the interface do actually do?

TASKS [Current]
* - Remove crop button. (Should use coordinates) [DONE]
* 1.) Should be able to browse even without typing the filepath [DONE]
* 2.) Filepath taking in the value from file.getPath(). [???]
* 3.) Update text area and this.filepath when browsing to a file. [DONE]
* 4.) Keep in mind: lz4 should be an editable text box (like the filepath text area) [DONE]
* 5.) Save changes to submit, and set location to be at the bottom of the window. [DONE]
* 6.) Submit button clicked, then should quit out of the form. (Close this JFrame only, not the entire software) [DONE]
*/

/*
* WRAP UP NOTES FOR THIS PROJECT
* - Constructor chnage variable names (like start_x to startX)
* - Change default_x to chunkX
* - Submit button to make changes.
* - Compressor default is lz4 not iz4.
*/

/*
C++ MAIN PROJECT.
C++ MAIN PROJECT.
* 1.) Release and get matlab working with C++ Qt (version, 6.2.4)
*/

public class PWZGUI implements ActionListener{
JFrame window;
JPanel textAreaPanel;

JButton browse;

// Crop check box
JLabel checkboxLabel;
JCheckBox checkBox;
JButton browse; // Browse specific filepath.

// Text box
JLabel textAreaLabel;
JTextArea textArea;

// For compressor lz4
JTextArea compressTextArea;// Compressor Text Area
JLabel compressorLabel; // Default Compressor

// Starting and ending XYZ
JTable table;
JScrollPane scrollPane;
Expand All @@ -89,17 +77,23 @@ public class PWZGUI implements ActionListener{
// Also, not reusing other starting and ending, so doesnt alter those variables.
public long chunkSizeX=256, chunkSizeY=256, chunkSizeZ=256;

public ImageStack imageStack;

public Object[] cImageObj;

public long bits;

JTable chunkTable; // Displaying the chunk sizes that are the default XYZ coords. (Though not expected to be changed.)
JScrollPane chunkScrollPane; // Scroll pane, to help display the default values of the chunk size.

// Default Compressor
JLabel compressorLabel;


JButton saveChangesButton; // To save changes when
JButton submitButton; // To submit changes, then close this specific interface. (Not the entire software.)

public PWZGUI() {
filepath = "";
compressor = "lz4"; // Compressor is lz4. (NOTE, this value does not change by default whatsoever)
imageStack = null;

// Starting coords
// Starting and ending coordinates are the expected values to be changed by user using the intercface.
Expand All @@ -117,6 +111,8 @@ public PWZGUI() {
chunkSizeY = 256;
chunkSizeZ = 256;

bits = 0;

// Creates a thread. Lets be called and execute object in its own instance.
// Basically like its own thread.
Runnable r = new Runnable() {
Expand All @@ -133,9 +129,11 @@ public void run(){

// This commented constructor was just an idea (will deleted, if this implementation may not be needed.)
// public PWZGUI(String filepath, Coords starting, Coords ending, String compressor){
public PWZGUI(String filepath, long startX, long startY, long startZ, long endX, long endY, long endZ, long chunkSizeX, long chunkSizeY, long chunkSizeZ, String compressor){
public PWZGUI(String filepath, ImageStack imageStack, long startX, long startY, long startZ, long endX, long endY, long endZ, long chunkSizeX, long chunkSizeY, long chunkSizeZ, String compressor, long bits){
this.filepath = filepath;
this.compressor = compressor;
this.imageStack = imageStack;
this.cImageObj = imageStack.getImageArray(); // Is this how we want to pass in an array

// Starting coords
this.startX = startX;
Expand All @@ -150,6 +148,8 @@ public PWZGUI(String filepath, long startX, long startY, long startZ, long endX,
this.chunkSizeY = chunkSizeY;
this.chunkSizeZ = chunkSizeZ;

this.bits = bits;

// Creates a thread. Lets be called and execute object in its own instance.
// Basically like its own thread.
Runnable r = new Runnable(){
Expand All @@ -167,14 +167,14 @@ private void init(){
window = new JFrame("Write Zarr");
textAreaPanel = new JPanel(); // Main Panel
compressorLabel = new JLabel();
compressTextArea = new JTextArea();



setupTextProperties(); // Handling button widget
setupCropProperties(); // User type text label, and text box field.
grabCoordinates();
chunkAndCompressorProperties();
saveChangesButton(); // update the table changes.
submitButton(); // Submit button: What this does is submit the given changes, then close this specific interface.
show(); // Handling adding all the widgets into the panel, while panel is being referred by the JFrame.

// Setting window/jframe properties
Expand All @@ -197,23 +197,17 @@ private void setupTextProperties(){
textArea.setLayout(new FlowLayout());

}

// Setup cropping properties and JLabels corresponding to given check box widget.
private void setupCropProperties(){
// User type text label, and text box field.
checkBox = new JCheckBox("Crop");
checkBox.setBounds(160, 110, 75, 15); // Higher x is more to the right we go, lower value y is the more we go upwards.
checkBox.addActionListener(this);
}

private void grabCoordinates(){
// Labels allowing the user using the interface to know
startCoordsLabel = new JLabel("Start");
endCoordsLabel = new JLabel("End");

startCoordsLabel.setBounds(115, 90, 150, 150);
endCoordsLabel.setBounds(115, 110, 150, 150);

// startCoordsLabel.setBounds(115, 90, 150, 150);
// endCoordsLabel.setBounds(115, 110, 150, 150);
startCoordsLabel.setBounds(140, 5, 150, 150);
endCoordsLabel.setBounds(145, 20, 150, 150);

Object[][] data = {
{startX, startY, startZ},
{endX, endY, endZ},
Expand All @@ -228,7 +222,8 @@ public boolean isCellEditable(int row, int col) {
};

table = new JTable(tableModel);
table.setBounds(30, 30, 950, 950);
// table.setBounds(30, 30, 950, 950);
table.setBounds(235, 55, 115, 25);

// Adding columns to the table
tableModel.addColumn("X");
Expand All @@ -240,7 +235,8 @@ public boolean isCellEditable(int row, int col) {

scrollPane = new JScrollPane(table);
scrollPane.setPreferredSize(new Dimension(250, 100)); // Actually setting how large the scroll pane is.
scrollPane.setBounds(172, 145, 250, 53); // Set where we want the JTable to be located in the JFrame. (Actually adjusts X and Y coords, and width and height)
// scrollPane.setBounds(172, 145, 250, 53); // Set where we want the JTable to be located in the JFrame. (Actually adjusts X and Y coords, and width and height)
scrollPane.setBounds(195, 55, 230, 53);
scrollPane.setVisible(true);
}

Expand All @@ -261,20 +257,33 @@ private void chunkAndCompressorProperties(){
chunkScrollPane = new JScrollPane(chunkTable);
// Original width = 210, height = 75
chunkScrollPane.setPreferredSize(new Dimension(200, 100)); // Actually setting how large the scroll pane is.
chunkScrollPane.setBounds(170, 205, 255, 40); // Set where we want the JTable to be located in the JFrame. (This line is what updates the X, Y coordinates of widget)
// chunkScrollPane.setBounds(170, 205, 255, 40); // Set where we want the JTable to be located in the JFrame. (This line is what updates the X, Y coordinates of widget)
chunkScrollPane.setBounds(195, 125, 230, 53); // Set where we want the JTable to be located in the JFrame. (This line is what updates the X, Y coordinates of widget)
chunkScrollPane.setVisible(true);

compressorLabel.setText("Compressor: " + compressor);
compressorLabel.setBounds(180, 245, 130, 20); // NOTE: Higher the Y-axis lower widgets are positioned. Higher X axis, more to right the widgets positioned at.
// Compressor = default is lz4 (though the user, should also be able to change the default as an option as well)
compressorLabel.setText("Compressor: ");
compressorLabel.setBounds(180, 195, 130, 20); // NOTE: Higher the Y-axis lower widgets are positioned. Higher X axis, more to right the widgets positioned at.

compressTextArea.setText(compressor);
// compressTextArea.setBounds(265,245, 65, 19);
compressTextArea.setBounds(265,195, 65, 19);
}

// Function to help organize the widget that handles the saving changes button.
private void saveChangesButton() {
saveChangesButton = new JButton("Save Changes");
private void submitButton() {
submitButton = new JButton("Save Changes");
MattHazard marked this conversation as resolved.
Show resolved Hide resolved
// saveChangesButton.setBounds(230, 55, 115, 25);
saveChangesButton.setBounds(235, 55, 115, 25);
// submitButton.setBounds(212, 55, 115, 25);
submitButton.setBounds(175, 225, 115, 25);
submitButton.addActionListener(this);
}

saveChangesButton.addActionListener(this);
// Display error message window, if the file is not a zarr file.
private void errorMessage(){
String message = "File must be a zarr file";
// JOptionPane.showInputDialog(message);
JOptionPane.showMessageDialog(window, message);
}

// show function, has keeps track of all the added components into JFrame -> going to -> JPanel -> widgets/checkboxes/etc.
Expand All @@ -289,51 +298,39 @@ private void show(){
textAreaPanel.setSize(50, 50);

// Adds the other widgets into the JFrame window themselves.
window.add(checkBox); // UPDATE: Add this into the window frame. So we can move this widget however we see fit.
window.add(startCoordsLabel);
window.add(endCoordsLabel);
window.add(scrollPane);
window.add(chunkScrollPane);
window.add(compressorLabel);
window.add(compressTextArea);


window.add(saveChangesButton);
window.add(submitButton);




// Setting window/jframe properties
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.add(textAreaPanel, BorderLayout.CENTER); // This is how the TextArea and Labels, are being centered to the TOP of the interface.
window.pack();
window.setLocation(new Point(900, 250)); // Hopefully puts the screen in the center of the monitor (vary depending on monitoring)
window.setVisible(true);
// window.setResizable(false);
}

// Handling events happening with the interface.
@Override
public void actionPerformed(ActionEvent e){
String filepath = textArea.getText();
boolean emptyString = filepath.equals(""); // We dont want to browse anything that isn't a string. (Don't assume, everyone will type the right input. Just precautionary)

// Just add this just in case, we do not want empty characters
if(emptyString) return;

if(e.getSource() == browse){
// We want to check if the checkbox is clicked before we compress that file.
if(checkBox.isSelected()) checkboxClicked();
if(!emptyString) loadfile(filepath);
}

if(e.getSource() == browse) loadfile(); // We want to check if the checkbox is clicked before we compress that file.
// Updates and clears the table.
if(e.getSource() == saveChangesButton) updateTable();
if(e.getSource() == submitButton) updateTable(); // Updates the table when we submit the changes, and then is the function that quits out the JFrame for this specific interface.
}

// Loading filepath given.
private void loadfile(String filepath){
private void loadfile(){
// File Handling stuff. (Referenced PWZ.java)
// PWZC pwzc = new PWZC();
// PWZC pwzc = new PWZC(); // This code is only used to call the C-functionality... (Wont work on mac, so comment out in the meantime.)
JFileChooser chooser = new JFileChooser();
chooser.setApproveButtonText("Save");
chooser.setDialogTitle("Save as Zarr");
Expand All @@ -348,36 +345,28 @@ private void loadfile(String filepath){

if(cImagePlus == null) return;

ImageStack cImageStack = cImagePlus.getImageStack();
Object[] cImageObj = cImageStack.getImageArray();
// pwzc.parallelWriteZarr(this.filepath, this.cImageObj, this.startX, this.startY, this.startZ, this.endX, this.endY, this.endZ, this.chunkSizeX, this.chunkSizeY, this.chunkSizeZ, 1, this.compressor, 1, this.bits);
}

private boolean checkExtension(String path){
String extension = "";
int i = path.lastIndexOf('.');

if(i != -1) extension = path.substring(i+1);

// System.out.println("LOGGER: " + extension + ", i = " + i); // For debugging purposes.

int bits = cImageStack.getBitDepth(); // May need to get bits another way
String fileName = file.getPath();
int x = cImageStack.getWidth();
int y = cImageStack.getHeight();
int z = cImageStack.getSize();
if(extension.equals("zarr")) return true;

// pwzc.parallelWriteZarr(fileName, cImageObj, 0, 0, 0, y, x, z, 256, 256, 256, 1, "lz4", 1, bits);
return false;
}


private void checkboxClicked(){ System.out.println("[DEBUGGING]: Check Box Clicked!"); } // Does smthing when this check box is clicked.

// When "Save Changes" button is clicked, the given inputted information is updated
// Little redundant, for now was trying to get interface working with updating the JTable.
// When "Submit changes" button is clicked, the given inputted information is updated
private void updateTable(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should call my function but I can write that in myself when I pull this since I'll be testing it.

startX = 123;
startY = 456;
startZ = 890;

endX = 1024;
endY = 1036;
endZ = 1048;

chunkSizeX = 256;
chunkSizeY = 256;
chunkSizeZ = 256;
// Checks if the text area box is a zarr file, or the filepath we load in from the browser button are a zarr file. If not display error message.
if(!checkExtension(this.filepath) && !checkExtension(textArea.getText())) errorMessage();
textArea.setText(this.filepath);

table.getModel().setValueAt(startX, 0, 0);
table.getModel().setValueAt(startY, 0, 1);
Expand All @@ -389,8 +378,10 @@ private void updateTable(){
chunkTable.getModel().setValueAt(chunkSizeX, 0, 0);
chunkTable.getModel().setValueAt(chunkSizeY, 0, 1);
chunkTable.getModel().setValueAt(chunkSizeZ, 0, 2);

window.dispose(); // Dispose() is how we will exit, once the submit changes have been made.
}

// For testing and debugging the interface with a main method.
// public static void main(String[] args) { new PWZGUI(); }
// public static void main(String[] args) { new PWZGUI(); }
}