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

Multiple instance events anim develop #230

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
import java.awt.event.KeyEvent;
import java.time.Instant;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class ArchivedQuakeUI extends JDialog {

private boolean animationPanelOpen = false;

public ArchivedQuakeUI(Frame parent, ArchivedQuake quake) {
super(parent);
Expand Down Expand Up @@ -42,7 +47,26 @@ public ArchivedQuakeUI(Frame parent, ArchivedQuake quake) {
animButton.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
new ArchivedQuakeAnimation(parent, quake).setVisible(true);
if (!animationPanelOpen) { // if animation panel is not already open then create new one on event
ArchivedQuakeAnimation animUi = new ArchivedQuakeAnimation(parent, quake);
// set panel to visible
animUi.setVisible(true);
// set class tracking boolean to true because the panel is open
animationPanelOpen = true;

//listen for animation window closing
animUi.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// set anim traking boolean to false as pane has now closed
animationPanelOpen = false;
}
public void windowClosed(WindowEvent e) {
// set anim traking boolean to false as pane has now closed
animationPanelOpen = false;
}
});
}
}
});

Expand Down Expand Up @@ -72,4 +96,4 @@ public void keyPressed(KeyEvent e) {
setLocationRelativeTo(parent);
setResizable(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@
import java.util.Locale;
import java.util.stream.Collectors;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.UUID;

public class EarthquakeListPanel extends JPanel {
private double scroll = 0;
protected int mouseY = -999;

// Holds the list of currently opened archived quakes
private ArrayList<UUID> openedQuakes = new ArrayList<UUID>();

public static final DecimalFormat f1d = new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.ENGLISH));
private static final int cell_height = 50;

Expand Down Expand Up @@ -65,6 +73,8 @@ public EarthquakeListPanel(Frame parent, List<ArchivedQuake> archivedQuakes) {
}
});



addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
Expand All @@ -77,15 +87,34 @@ public void mousePressed(MouseEvent e) {

ArchivedQuake quake = filtered.get(i);

UUID quakeUuid = quake.getUuid();

if (quake != null && e.getButton() == MouseEvent.BUTTON3 && !isMouseInGoUpRect) {
quake.setWrong(!quake.isWrong());
}

if(e.getButton() == MouseEvent.BUTTON1) {
if(isMouseInGoUpRect) {
scroll = 0;
}else if (quake != null ) {
new ArchivedQuakeUI(parent, quake).setVisible(true);
}
else if (quake != null && !openedQuakes.contains(quakeUuid) ) {
// Create Instance of quakeUi panel
ArchivedQuakeUI quakeUi = new ArchivedQuakeUI(parent, quake);
// set the panel to be visible
quakeUi.setVisible(true);
// add the quake to the list of opened panels
openedQuakes.add(quakeUuid);

// When quake panel is closed, remove quake from the ArrayList of openedQuakes
quakeUi.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
openedQuakes.remove(quakeUuid);
}
public void windowClosed(WindowEvent e) {
openedQuakes.remove(quakeUuid);

Choose a reason for hiding this comment

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

Do we need to remove the uuid twice on closing and closed event?
is there a case where 1 of these events doesnt do what it is supposed to?

Copy link
Contributor Author

@ChrisEberleSchool ChrisEberleSchool Feb 27, 2024

Choose a reason for hiding this comment

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

This is pretty much for redundancy, I did research and I found it is best to include both! Essentially I could just use windowClosing and it would pretty much cover all cases but I'm pretty sure there are some cases that it wont cover that windowClosed will cover

Choose a reason for hiding this comment

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

All good, just wanted to know the reason around it.

}
});
}
}

Expand Down Expand Up @@ -237,4 +266,4 @@ public void paint(Graphics gr) {
}
}

}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ It's important to review and adhere to these additional licenses when using or d

<a href="https://github.com/xspanger3770/GlobalQuake/graphs/contributors">
<img src="https://contrib.rocks/image?repo=xspanger3770/GlobalQuake" />
</a>
</a>
Loading