|
@@ -10,6 +10,7 @@ import javax.swing.*;
|
|
|
import java.awt.*;
|
|
|
import java.awt.event.MouseEvent;
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.TimerTask;
|
|
|
|
|
@@ -37,6 +38,7 @@ public abstract class AbstractCanvas extends JPanel {
|
|
|
final JMenuItem itemTrack = new JMenuItem(Languages.getLanguage()[101]);
|
|
|
final JMenuItem itemUntrack = new JMenuItem(Languages.getLanguage()[102]);
|
|
|
final JMenuItem itemCreateTemplate = new JMenuItem(Languages.getLanguage()[Languages.right_click_create_template]);
|
|
|
+ final JMenuItem itemAlignAll = new JMenuItem("AlignAll");
|
|
|
final int ANIMTIME = 500; // animation Time
|
|
|
private final int animFPS = 60;
|
|
|
final int animDelay = 1000 / animFPS; // animation Delay
|
|
@@ -626,4 +628,35 @@ public abstract class AbstractCanvas extends JPanel {
|
|
|
(int) (controller.getScale() + ((scalediv20 + 5) * 2)));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Align alle Objects on the Canvas to a Grid with objects every 10 pixels
|
|
|
+ */
|
|
|
+ public abstract void tryToAlignObjects();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Aligns the Object the a grid
|
|
|
+ * @param cps Object that should be aligned
|
|
|
+ * @param distance distance between the AlignmentGrid Lines. (objects every 'distance' pixels
|
|
|
+ */
|
|
|
+ protected void align(AbstractCpsObject cps, int distance) {
|
|
|
+ /** Position of the AbstractCpsObject which should be aligned */
|
|
|
+ Position p = cps.getPosition();
|
|
|
+
|
|
|
+ //calculate how many pixels the cps should be decreased to align
|
|
|
+ /** x offset relative to a grid with lines every distance pixels */
|
|
|
+ int x_off = cps.getPosition().x % distance;
|
|
|
+
|
|
|
+ /** y offset relative to a grid with lines every distance pixels */
|
|
|
+ int y_off = cps.getPosition().y % distance;
|
|
|
+
|
|
|
+ //align to the other Line, if it is nearer
|
|
|
+ if(x_off > distance/2)
|
|
|
+ x_off -= distance;
|
|
|
+ if(y_off > distance/2)
|
|
|
+ y_off -= distance;
|
|
|
+
|
|
|
+ /** set new Position */
|
|
|
+ cps.setPosition(p.x-x_off, p.y-y_off);
|
|
|
+ }
|
|
|
}
|