Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewauclair committed Aug 17, 2024
1 parent 97a7ec1 commit 23a93e9
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions docking-api/src/ModernDocking/floating/FloatUtilsFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ public class FloatUtilsFrame extends JFrame implements DragSourceMotionListener,
private DockableHandles dockableHandles;

BufferStrategy bs; //create an strategy for multi-buffering.
JPanel renderPanel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
rootHandles.paint(g2);

if (dockableHandles != null) {
dockableHandles.paint(g2);
}

overlay.paint(g);
g2.dispose();
}
};

public FloatUtilsFrame(DockingAPI docking, Window referenceDockingWindow, InternalRootDockingPanel root) {
this.referenceDockingWindow = referenceDockingWindow;
Expand All @@ -72,6 +86,14 @@ public FloatUtilsFrame(DockingAPI docking, Window referenceDockingWindow, Intern
getRootPane().setBackground(new Color(0, 0, 0, 0)); // don't want a background for the root pane either. Workaround for a FlatLaf macOS issue.
getContentPane().setBackground(new Color(0, 0, 0, 0)); // don't want a background for the content frame either.

GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
BufferCapabilities bufferCapabilities = gc.getBufferCapabilities();

if (bufferCapabilities.isMultiBufferAvailable()) {
add(renderPanel);
renderPanel.setOpaque(false);
}

try {
if (getContentPane() instanceof JComponent) {
((JComponent) getContentPane()).setOpaque(false);
Expand All @@ -98,8 +120,14 @@ public void activate(FloatListener floatListener, JFrame floatingFrame, DragSour

setVisible(true);

createBufferStrategy(2);
bs = this.getBufferStrategy();
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
BufferCapabilities bufferCapabilities = gc.getBufferCapabilities();

if (!bufferCapabilities.isMultiBufferAvailable()) {
createBufferStrategy(2);
bs = this.getBufferStrategy();
}

orderFrames();
}

Expand Down Expand Up @@ -210,19 +238,27 @@ private void orderFrames() {
}

@Override
public void paint(Graphics gf) {
if (bs == null) return;
Graphics g = bs.getDrawGraphics();
public void paint(Graphics g) {
if (bs == null) {
super.paint(g);
return;
}

g = bs.getDrawGraphics();
Graphics2D g2 = (Graphics2D) bs.getDrawGraphics();

g2.clearRect(0, 0, getWidth(), getHeight());

rootHandles.paint(g2);

if (dockableHandles != null) {
dockableHandles.paint(g2);
}

overlay.paint(g);

g2.dispose();

bs.show();
}

Expand Down Expand Up @@ -298,6 +334,8 @@ private void setSizeAndLocation() {
setLocation(location);
setSize(size);

renderPanel.setSize(size);

rootHandles.updateHandlePositions();

revalidate();
Expand Down

0 comments on commit 23a93e9

Please sign in to comment.