Skip to content

Commit 125dfd8

Browse files
fix(ci): skip drag-and-drop init in headless mode
Allows unit tests that construct Struktogramm to pass on GitHub Actions without a display. Still version 1.2.1. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent a618bc8 commit 125dfd8

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

src/main/java/de/visustruct/control/Struktogramm.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.awt.Font;
55
import java.awt.Graphics;
66
import java.awt.Graphics2D;
7+
import java.awt.GraphicsEnvironment;
78
import java.awt.Point;
89
import java.awt.Rectangle;
910
import java.awt.RenderingHints;
@@ -166,15 +167,12 @@ public Struktogramm(StrTabbedPane tabbedpane){
166167
addMouseMotionListener(this);
167168

168169

169-
/*Drag & Drop aktivieren, siehe
170-
http://www.java2s.com/Code/Java/Swing-JFC/MakingaComponentDraggable.htm
171-
und
172-
http://www.java2s.com/Code/Java/Swing-JFC/PanelDropTarget.htm
173-
*/
174-
dragSource = new DragSource();
175-
dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
176-
177-
new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, this, true, null);
170+
/* Drag & Drop nur mit Display (GitHub CI / headless: Tests ohne X11). */
171+
if (!GraphicsEnvironment.isHeadless()) {
172+
dragSource = new DragSource();
173+
dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
174+
new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, this, true, null);
175+
}
178176

179177

180178

@@ -1431,7 +1429,8 @@ public void dragGestureRecognized(DragGestureEvent evt) {//ein Element aus dem S
14311429

14321430
dragZwischenlagerElement = (StruktogrammElement)dragZwischenlagerListe.gibElementAnPos(mausPos.x,mausPos.y,false);//das gezogene Element wird gespeichert
14331431

1434-
if ((dragZwischenlagerElement != null) && !(dragZwischenlagerElement instanceof LeerElement)){//wenn das Element nicht null ist und kein LeerElement ist...
1432+
if ((dragZwischenlagerElement != null) && !(dragZwischenlagerElement instanceof LeerElement)
1433+
&& dragSource != null) {//wenn das Element nicht null ist und kein LeerElement ist...
14351434
Transferable t = new StringSelection("z");//z für Element aus dem Zwischenlager
14361435

14371436
dragSource.startDrag(evt, DragSource.DefaultCopyDrop, t, this);//...wird ein Drag ausgelöst

0 commit comments

Comments
 (0)