Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed Jul 23, 2024
1 parent 41d9ec4 commit 0c1ff80
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 32 deletions.
54 changes: 32 additions & 22 deletions src/main/java/com/github/creme332/controller/FrameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;

import javax.swing.*;

Expand Down Expand Up @@ -158,7 +159,7 @@ public void actionPerformed(ActionEvent e) {

// Open help center
rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.ALT_DOWN_MASK), "openHelpCenter");
.put(KeyStroke.getKeyStroke(KeyEvent.VK_H, java.awt.event.InputEvent.ALT_DOWN_MASK), "openHelpCenter");
rootPane.getActionMap().put("openHelpCenter", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Expand All @@ -168,7 +169,8 @@ public void actionPerformed(ActionEvent e) {

// Toggle sidebar visibility
rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK),
KeyStroke.getKeyStroke(KeyEvent.VK_S,
java.awt.event.InputEvent.CTRL_DOWN_MASK | java.awt.event.InputEvent.SHIFT_DOWN_MASK),
"toggleSidebar");
rootPane.getActionMap().put("toggleSidebar", new AbstractAction() {
@Override
Expand Down Expand Up @@ -241,7 +243,7 @@ private void resizeEverything() {

frame.repaint();
frame.revalidate();

/**
* sync toolkit to prevent frame rate issues on linux.
*
Expand All @@ -251,26 +253,34 @@ private void resizeEverything() {
Toolkit.getDefaultToolkit().sync();
}

public void playStartAnimation() {
final long animationDuration = 800; // ms
private class Task extends SwingWorker<Void, Integer> {
static final long ANIMATION_DURATION = 800; // ms

Thread th = new Thread() {
@Override
public void run() {
// Display the splash screen for 1 second
frame.setMenuBarVisibility(false);
frame.showScreen(Screen.SPLASH_SCREEN);

try {
Thread.sleep(animationDuration);
} catch (InterruptedException e) {
e.printStackTrace();
System.exit(0);
}
frame.showScreen(app.getCurrentScreen());
}
};
th.start();
@Override
protected Void doInBackground() throws Exception {
// Display the splash screen for some time
frame.setMenuBarVisibility(false);
frame.showScreen(Screen.SPLASH_SCREEN);
Thread.sleep(ANIMATION_DURATION);
return null;
}

@Override
protected void process(List<Integer> chunks) {
// do nothing
}

@Override
protected void done() {
// Close splash screen and proceed to main application
frame.showScreen(app.getCurrentScreen());
}
}

public void playStartAnimation() {
// Perform background loading task
Task task = new Task();
task.execute();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ public void mouseReleased(MouseEvent arg0) {
ShapeManager manager = model.getShapeManager();

// check if a shape was being dragged previously
if (app.getMode() == Mode.MOVE_CANVAS && model.getSelectedShapeIndex() > -1) {
if (app.getMode() == Mode.MOVE_CANVAS &&
model.getSelectedShapeIndex() > -1 &&
manager.getShapePreview() != null) {
// edit previous shape with shape preview

if (manager.getShapePreview() != null) {
manager.editShape(model.getSelectedShapeIndex(), manager.getShapePreview());
manager.setShapePreview(null);
model.setSelectedShape(-1);
canvas.repaint();
}
manager.editShape(model.getSelectedShapeIndex(), manager.getShapePreview());
manager.setShapePreview(null);
model.setSelectedShape(-1);
canvas.repaint();
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/creme332/model/ShapeWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public ShapeWrapper(ShapeWrapper wrapper) {
}

/**
* Finds the center of a given shape.
* Finds the center of the shape.
*
* @param shape the shape to find the center of
* @return a Point2D representing the center of the shape
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/creme332/model/TutorialModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.Set;

/**
* Information about a particular tutorialdraw.
* Information about a particular tutorial.
*/
public class TutorialModel {
/**
Expand Down

0 comments on commit 0c1ff80

Please sign in to comment.