forked from SmartBear/soapui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StandaloneDesktop.java
723 lines (606 loc) · 28.4 KB
/
StandaloneDesktop.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
/*
* SoapUI, Copyright (C) 2004-2016 SmartBear Software
*
* Licensed under the EUPL, Version 1.1 or - as soon as they will be approved by the European Commission - subsequent
* versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl
*
* Unless required by applicable law or agreed to in writing, software distributed under the Licence is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the Licence for the specific language governing permissions and limitations
* under the Licence.
*/
package com.eviware.soapui.ui.desktop.standalone;
import com.eviware.soapui.SoapUI;
import com.eviware.soapui.model.ModelItem;
import com.eviware.soapui.model.PanelBuilder;
import com.eviware.soapui.model.util.PanelBuilderRegistry;
import com.eviware.soapui.model.workspace.Workspace;
import com.eviware.soapui.settings.UISettings;
import com.eviware.soapui.support.UISupport;
import com.eviware.soapui.support.action.swing.ActionList;
import com.eviware.soapui.support.action.swing.DefaultActionList;
import com.eviware.soapui.support.components.JComponentInspector;
import com.eviware.soapui.support.components.JInspectorPanel;
import com.eviware.soapui.support.components.JInspectorPanelFactory;
import com.eviware.soapui.ui.desktop.AbstractSoapUIDesktop;
import com.eviware.soapui.ui.desktop.DesktopPanel;
import com.eviware.soapui.ui.desktop.SoapUIDesktop;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.DesktopManager;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* The default standalone SoapUI desktop using a JDesktopPane
*
* @author Ole.Matzura
*/
public class StandaloneDesktop extends AbstractSoapUIDesktop {
private JDesktopPane desktop;
private Map<ModelItem, JInternalFrame> modelItemToInternalFrameMap = new HashMap<ModelItem, JInternalFrame>();
private Map<JInternalFrame, DesktopPanel> internalFrameToDesktopPanelMap = new HashMap<JInternalFrame, DesktopPanel>();
private DesktopPanelPropertyChangeListener desktopPanelPropertyChangeListener = new DesktopPanelPropertyChangeListener();
private InternalDesktopFrameListener internalFrameListener = new InternalDesktopFrameListener();
private ActionList actions;
private DesktopPanel currentPanel;
private CloseCurrentAction closeCurrentAction = new CloseCurrentAction();
private CloseOtherAction closeOtherAction = new CloseOtherAction();
private CloseAllAction closeAllAction = new CloseAllAction();
private static final int xOffset = 30, yOffset = 30;
private boolean transferring;
private List<DesktopPanel> deferredDesktopPanels = new LinkedList<DesktopPanel>();
private JInspectorPanel inspector;
private JPanel inspectorPanel;
public StandaloneDesktop(Workspace workspace) {
super(workspace);
buildUI();
actions = new DefaultActionList("Desktop");
actions.addAction(closeCurrentAction);
actions.addAction(closeOtherAction);
actions.addAction(closeAllAction);
// Setting Mac-like color for all platforms pending
desktop.setBackground(UISupport.MAC_BACKGROUND_COLOR);
enableWindowActions();
desktop.addComponentListener(new DesktopResizeListener());
DesktopManager originalDesktopManager = desktop.getDesktopManager();
boolean mruSelectionChosen = SoapUI.isSelectingMostRecentlyUsedDesktopPanelOnClose();
DesktopManager delegate = mruSelectionChosen ? new MostRecentlyUsedOrderDesktopManager(originalDesktopManager) :
originalDesktopManager;
desktop.setDesktopManager(new BoundsAwareDesktopManager(delegate));
}
private void enableWindowActions() {
closeCurrentAction.setEnabled(currentPanel != null && internalFrameToDesktopPanelMap.size() > 0);
closeOtherAction.setEnabled(currentPanel != null && internalFrameToDesktopPanelMap.size() > 1);
closeAllAction.setEnabled(internalFrameToDesktopPanelMap.size() > 0);
}
private void buildUI() {
desktop = new SoapUIDesktopPane();
JScrollPane scrollPane = new JScrollPane(desktop);
scrollPane.setBorder(BorderFactory.createEmptyBorder());
inspector = JInspectorPanelFactory.build(scrollPane, SwingConstants.RIGHT);
inspectorPanel = new JPanel( new BorderLayout());
inspector.addInspector(new JComponentInspector<JComponent>(inspectorPanel, "Inspector",
"Object Inspector", true));
inspector.setDefaultDividerLocation(0.75f);
}
public JComponent getDesktopComponent() {
return inspector.getComponent();
}
@Override
public void showInspector(JComponent component) {
inspectorPanel.removeAll();
inspectorPanel.add( component, BorderLayout.CENTER );
inspectorPanel.repaint();
inspector.setCurrentInspector( "Inspector" );
}
public boolean closeDesktopPanel(DesktopPanel desktopPanel) {
try {
if (desktopPanel.getModelItem() != null) {
return closeDesktopPanel(desktopPanel.getModelItem());
} else {
JInternalFrame frame = getFrameForDesktopPanel(desktopPanel);
if (frame != null) {
frame.doDefaultCloseAction();
return frame.isClosed();
}
// else
// throw new RuntimeException( "Cannot close unkown DesktopPanel: "
// + desktopPanel.getTitle() );
return false;
}
} finally {
enableWindowActions();
}
}
private JInternalFrame getFrameForDesktopPanel(DesktopPanel desktopPanel) {
for (JInternalFrame frame : internalFrameToDesktopPanelMap.keySet()) {
if (internalFrameToDesktopPanelMap.get(frame) == desktopPanel) {
return frame;
}
}
return null;
}
public boolean hasDesktopPanel(ModelItem modelItem) {
return modelItemToInternalFrameMap.containsKey(modelItem);
}
public DesktopPanel showDesktopPanel(ModelItem modelItem) {
PanelBuilder<ModelItem> panelBuilder = PanelBuilderRegistry.getPanelBuilder(modelItem);
if (modelItemToInternalFrameMap.containsKey(modelItem)) {
JInternalFrame frame = modelItemToInternalFrameMap.get(modelItem);
try {
desktop.getDesktopManager().deiconifyFrame(frame);
frame.setSelected(true);
frame.moveToFront();
currentPanel = internalFrameToDesktopPanelMap.get(frame);
} catch (PropertyVetoException e) {
SoapUI.logError(e);
}
} else if (panelBuilder != null && panelBuilder.hasDesktopPanel()) {
DesktopPanel desktopPanel = panelBuilder.buildDesktopPanel(modelItem);
if (desktopPanel == null)
return null;
JInternalFrame frame = createContentFrame(desktopPanel);
desktop.add(frame);
try {
frame.setSelected(true);
} catch (PropertyVetoException e) {
SoapUI.logError(e);
}
modelItemToInternalFrameMap.put(modelItem, frame);
internalFrameToDesktopPanelMap.put(frame, desktopPanel);
fireDesktopPanelCreated(desktopPanel);
currentPanel = desktopPanel;
desktopPanel.getComponent().requestFocusInWindow();
} else
Toolkit.getDefaultToolkit().beep();
enableWindowActions();
return currentPanel;
}
private JInternalFrame createContentFrame(DesktopPanel desktopPanel) {
desktopPanel.addPropertyChangeListener(desktopPanelPropertyChangeListener);
JComponent panel = desktopPanel.getComponent();
panel.setOpaque(true);
String title = desktopPanel.getTitle();
JInternalFrame frame = new JInternalFrame(title, true, true, true, true);
frame.addInternalFrameListener(internalFrameListener);
frame.setContentPane(panel);
frame.setLocation(xOffset * (desktop.getComponentCount() % 10), yOffset * (desktop.getComponentCount() % 10));
Point location = frame.getLocation();
Dimension frameSize = calculateDesktopPanelSize(panel, location);
frame.setSize(frameSize);
frame.setVisible(true);
frame.setFrameIcon(desktopPanel.getIcon());
frame.setToolTipText(desktopPanel.getDescription());
frame.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
if (!SoapUI.getSettings().getBoolean(UISettings.NATIVE_LAF)) {
// This creates an empty frame on Mac OS X native L&F.
frame.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(),
BorderFactory.createEmptyBorder(4, 4, 4, 4)));
} else if (!UISupport.isMac()) {
frame.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
}
return frame;
}
private Dimension calculateDesktopPanelSize(JComponent panel, Point location) {
Dimension frameSize;
Dimension preferredSize = panel.getPreferredSize();
if (desktop.getBounds().contains(new Rectangle(location, preferredSize))) {
frameSize = preferredSize;
} else {
frameSize = new Dimension((int) ((desktop.getWidth() - location.x) * .95),
(int) ((desktop.getHeight() - location.y) * .95));
}
return frameSize;
}
public boolean closeDesktopPanel(ModelItem modelItem) {
try {
if (modelItemToInternalFrameMap.containsKey(modelItem)) {
JInternalFrame frame = modelItemToInternalFrameMap.get(modelItem);
frame.doDefaultCloseAction();
return frame.isClosed();
}
return false;
} finally {
enableWindowActions();
}
}
private class InternalDesktopFrameListener extends InternalFrameAdapter {
public void internalFrameClosing(InternalFrameEvent e) {
DesktopPanel desktopPanel = internalFrameToDesktopPanelMap.get(e.getInternalFrame());
if (!transferring && !desktopPanel.onClose(true)) {
return;
}
desktopPanel.removePropertyChangeListener(desktopPanelPropertyChangeListener);
modelItemToInternalFrameMap.remove(desktopPanel.getModelItem());
internalFrameToDesktopPanelMap.remove(e.getInternalFrame());
// replace content frame to make sure it is released
e.getInternalFrame().setContentPane(new JPanel());
e.getInternalFrame().dispose();
if (!transferring)
fireDesktopPanelClosed(desktopPanel);
if (currentPanel == desktopPanel)
currentPanel = null;
}
public void internalFrameActivated(InternalFrameEvent e) {
currentPanel = internalFrameToDesktopPanelMap.get(e.getInternalFrame());
if (currentPanel != null) {
fireDesktopPanelSelected(currentPanel);
}
enableWindowActions();
}
public void internalFrameDeactivated(InternalFrameEvent e) {
currentPanel = null;
enableWindowActions();
}
}
public class CloseCurrentAction extends AbstractAction {
public CloseCurrentAction() {
super("Close Current");
putValue(Action.SHORT_DESCRIPTION, "Closes the current window");
putValue(Action.ACCELERATOR_KEY, UISupport.getKeyStroke("menu F4"));
}
public void actionPerformed(ActionEvent e) {
JInternalFrame frame = desktop.getSelectedFrame();
if (frame != null)
closeDesktopPanel(internalFrameToDesktopPanelMap.get(frame));
}
}
public class CloseOtherAction extends AbstractAction {
public CloseOtherAction() {
super("Close Others");
putValue(Action.SHORT_DESCRIPTION, "Closes all windows except the current one");
putValue(Action.ACCELERATOR_KEY, UISupport.getKeyStroke("menu alt O"));
}
public void actionPerformed(ActionEvent e) {
JInternalFrame frame = desktop.getSelectedFrame();
if (frame == null)
return;
JInternalFrame[] frames = internalFrameToDesktopPanelMap.keySet().toArray(
new JInternalFrame[internalFrameToDesktopPanelMap.size()]);
for (JInternalFrame f : frames) {
if (f != frame) {
closeDesktopPanel(internalFrameToDesktopPanelMap.get(f));
}
}
}
}
public class CloseAllAction extends AbstractAction {
public CloseAllAction() {
super("Close All");
putValue(Action.SHORT_DESCRIPTION, "Closes all windows");
putValue(Action.ACCELERATOR_KEY, UISupport.getKeyStroke("menu alt L"));
}
public void actionPerformed(ActionEvent e) {
closeAll();
}
}
public ActionList getActions() {
return actions;
}
private class DesktopPanelPropertyChangeListener implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent evt) {
DesktopPanel desktopPanel = (DesktopPanel) evt.getSource();
JInternalFrame frame = getFrameForDesktopPanel(desktopPanel);
if (frame != null) {
if (evt.getPropertyName().equals(DesktopPanel.TITLE_PROPERTY)) {
frame.setTitle(desktopPanel.getTitle());
} else if (evt.getPropertyName().equals(DesktopPanel.ICON_PROPERTY)) {
frame.setFrameIcon(desktopPanel.getIcon());
}
}
}
}
public DesktopPanel[] getDesktopPanels() {
return internalFrameToDesktopPanelMap.values().toArray(new DesktopPanel[internalFrameToDesktopPanelMap.size()]);
}
public DesktopPanel getDesktopPanel(ModelItem modelItem) {
for (DesktopPanel panel : internalFrameToDesktopPanelMap.values()) {
if (panel.getModelItem() == modelItem) {
return panel;
}
}
return null;
}
public DesktopPanel showDesktopPanel(DesktopPanel desktopPanel) {
if (desktop.getBounds().width == 0) {
deferredDesktopPanels.add(desktopPanel);
return desktopPanel;
}
JInternalFrame frame = getFrameForDesktopPanel(desktopPanel);
if (frame != null) {
try {
desktop.getDesktopManager().deiconifyFrame(frame);
frame.setSelected(true);
frame.moveToFront();
} catch (Exception e) {
SoapUI.logError(e);
}
} else {
frame = createContentFrame(desktopPanel);
desktop.add(frame);
if (desktopPanel.getModelItem() != null)
modelItemToInternalFrameMap.put(desktopPanel.getModelItem(), frame);
internalFrameToDesktopPanelMap.put(frame, desktopPanel);
fireDesktopPanelCreated(desktopPanel);
frame.moveToFront();
desktopPanel.getComponent().requestFocusInWindow();
}
currentPanel = desktopPanel;
enableWindowActions();
return desktopPanel;
}
class SoapUIDesktopPane extends JDesktopPane {
Image img;
private int imageWidth;
private int imageHeight;
public SoapUIDesktopPane() {
try {
File file = new File("soapui-background.gif");
if (!file.exists())
file = new File("soapui-background.jpg");
if (!file.exists())
file = new File("/soapui-background.png");
if (file.exists()) {
img = javax.imageio.ImageIO.read(file);
imageWidth = img.getWidth(this);
imageHeight = img.getHeight(this);
}
} catch (Exception e) {
SoapUI.logError(e, "Could not load graphics for desktop");
}
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (img == null)
return;
int x = (this.getWidth() - imageWidth) / 2;
int y = (this.getHeight() - imageHeight) / 2;
g.drawImage(img, x, y, imageWidth, imageHeight, this);
}
}
public void transferTo(SoapUIDesktop newDesktop) {
transferring = true;
List<DesktopPanel> values = new ArrayList<DesktopPanel>(internalFrameToDesktopPanelMap.values());
for (DesktopPanel desktopPanel : values) {
closeDesktopPanel(desktopPanel);
newDesktop.showDesktopPanel(desktopPanel);
}
transferring = false;
}
public boolean closeAll() {
while (internalFrameToDesktopPanelMap.size() > 0) {
Iterator<JInternalFrame> i = internalFrameToDesktopPanelMap.keySet().iterator();
try {
i.next().setClosed(true);
} catch (PropertyVetoException e1) {
SoapUI.logError(e1);
}
}
internalFrameToDesktopPanelMap.clear();
modelItemToInternalFrameMap.clear();
JInternalFrame[] allFrames = desktop.getAllFrames();
for (JInternalFrame frame : allFrames) {
frame.doDefaultCloseAction();
}
enableWindowActions();
return true;
}
public void minimize(DesktopPanel desktopPanel) {
try {
getFrameForDesktopPanel(desktopPanel).setIcon(true);
} catch (PropertyVetoException e) {
SoapUI.logError(e);
}
}
public void maximize(DesktopPanel desktopPanel) {
desktop.getDesktopManager().maximizeFrame(getFrameForDesktopPanel(desktopPanel));
}
/**
* Helper class that ensures that desktop panels are displayed after a change from Tabbed to Standalone desktop.
*/
private class DesktopResizeListener implements ComponentListener {
@Override
public void componentResized(ComponentEvent e) {
Iterator<DesktopPanel> iterator = deferredDesktopPanels.iterator();
while (iterator.hasNext()) {
DesktopPanel nextPanel = iterator.next();
showDesktopPanel(nextPanel);
iterator.remove();
}
}
@Override
public void componentMoved(ComponentEvent e) {
}
@Override
public void componentShown(ComponentEvent e) {
}
@Override
public void componentHidden(ComponentEvent e) {
}
}
/**
* Helper class that decorates the standard desktop manager and prevents it from moving desktop panels outside
* the desktop.
* <p>
* <emp>Implementation note</emp> : the width of internal frames includes their borders. The size of borders
* is obtained with <code>panel.getInsets()</code>. Depending on the look and feel installed, the space occupied
* by borders may not be selectable. Furthermore, with Aqua l&f for example, there is an extra inside area on
* the right of panel where mouse clicks are ignored and thus the panel cannot be dragged by a click in there.
* Also, it is very difficult for us humans to notice a region on the screen that can be selected with the mouse
* if that region is only a couple of pixels wide or tall. For all these reasons, it is better to leave a
* minimum of selectable-draggable portion of the panel visible in the desktop so the user does not loose its
* panel outside the desktop. That is the purpose of <code>horizontalInsetFactor</code> and <code>verticalInsetFactor</code>
* fields of <code>BoundsAwareDesktopManager</code> : on windows and linux default l&f, the insets are small and
* trial and error lead to a factor of 6 for computing the <emp>comfortable</emp> minimal space to leave visible
* on the desktop. On Aqua l&f (i.e. on Mac), the insets are bigger, leading to a factor of 3 as a <emp>comfortable</emp>
* minimal space horizontally and a factor of 1 vertically, because the underlying UI implementation prevents
* dragging the title bar beyond the desktop panel highest Y-boundaries..
* </p>
*/
private class BoundsAwareDesktopManager implements DesktopManager {
private DesktopManager delegate;
private int horizontalInsetFactor = 6;
private int verticalInsetFactor = 6;
private Dimension desktopSize;
private BoundsAwareDesktopManager(DesktopManager delegate) {
this.delegate = delegate;
desktopSize = desktop.getSize();
if (UISupport.isMac()) {
horizontalInsetFactor = 3;
verticalInsetFactor = 1;
}
}
/* Methods enhancing the delegate with awareness of bounds */
@Override
public void dragFrame(JComponent f, int newX, int newY) {
if (outsideDesktop(f, newX, newY)) {
Point positionWherePanelReachable = findPositionWherePanelReachable(f, newX, newY);
delegate.dragFrame(f, positionWherePanelReachable.x, positionWherePanelReachable.y);
} else {
delegate.dragFrame(f, newX, newY);
}
}
@Override
public void setBoundsForFrame(JComponent desktopPanel, int newX, int newY, int newWidth, int newHeight) {
if (outsideDesktop(desktopPanel, newX, newY)) {
Point pointInsideDesktop = findPositionInsideDesktop(desktopPanel, newX, newY);
delegate.setBoundsForFrame(desktopPanel, pointInsideDesktop.x, pointInsideDesktop.y, newWidth, newHeight);
} else {
delegate.setBoundsForFrame(desktopPanel, newX, newY, newWidth, newHeight);
}
}
/* Methods only delegating to the encapsulated delegate */
@Override
public void openFrame(JInternalFrame f) {
delegate.openFrame(f);
}
@Override
public void closeFrame(JInternalFrame f) {
delegate.closeFrame(f);
}
@Override
public void maximizeFrame(JInternalFrame f) {
delegate.maximizeFrame(f);
}
@Override
public void minimizeFrame(JInternalFrame f) {
delegate.minimizeFrame(f);
}
@Override
public void iconifyFrame(JInternalFrame f) {
delegate.iconifyFrame(f);
}
@Override
public void deiconifyFrame(JInternalFrame f) {
delegate.deiconifyFrame(f);
}
@Override
public void activateFrame(JInternalFrame f) {
delegate.activateFrame(f);
}
@Override
public void deactivateFrame(JInternalFrame f) {
delegate.deactivateFrame(f);
}
@Override
public void beginDraggingFrame(JComponent f) {
desktopSize = desktop.getSize();
delegate.beginDraggingFrame(f);
}
@Override
public void endDraggingFrame(JComponent f) {
delegate.endDraggingFrame(f);
}
@Override
public void beginResizingFrame(JComponent f, int direction) {
delegate.beginResizingFrame(f, direction);
}
@Override
public void resizeFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
delegate.resizeFrame(f, newX, newY, newWidth, newHeight);
}
@Override
public void endResizingFrame(JComponent f) {
delegate.endResizingFrame(f);
}
/**
* <p>
* True if the coordinates (newX, newY) would put the panel outside the desktop in a manner that would make it
* unreachable, false otherwise.
* </p>
* <p>
* Parameters <code>newX</code> and <code>newY</code> are assumed to be the (left, top) origin coordinates of
* <code>desktopPanel</code>, which is the <code>JInternalFrame</code> being dragged. The panel's width includes
* borders, which means that on implementations where the borders are not selectable (Mac Aqua look&feel for
* example), the borders must be taken into account otherwise one can drag a panel into a position where it
* would no longer be selectable, thus impossible to bring back to the visible area of the parent desktop.
* </p>
*
* @param panel the panel being dragged
* @param newX target X-coordinate of leftmost window of desktopPanel
* @param newY target Y-coordinate of topmost window of desktopPanel
* @return true if target coordinates would put desktopPanel out of reach, false otherwise
*/
private boolean outsideDesktop(JComponent panel, int newX, int newY) {
int smallestReachableX = -(panel.getWidth() - horizontalInsetFactor * panel.getInsets().right);
int biggestReachableX = ((int) desktopSize.getWidth() - horizontalInsetFactor * panel.getInsets().left);
int biggestReachableY = ((int) desktopSize.getHeight() - verticalInsetFactor * panel.getInsets().top);
boolean xCoordinateOutside = newX > biggestReachableX || newX < smallestReachableX;
boolean yCoordinateOutside = newY < 0 || newY > biggestReachableY;
return xCoordinateOutside || yCoordinateOutside;
}
private Point findPositionWherePanelReachable(JComponent panel, int newX, int newY) {
// at left, smallest X is a function of panel width
// at right, highest X is a funtion of desktop width
// at top, smalest Y is 0 (we always want to see the title bar)
// at bottom, highest Y is a function of desktop height
int smallestReachableX = -(panel.getWidth() - horizontalInsetFactor * panel.getInsets().right);
int biggestReachableX = ((int) desktopSize.getWidth() - horizontalInsetFactor * panel.getInsets().left);
int biggestReachableY = ((int) desktopSize.getHeight() - verticalInsetFactor * panel.getInsets().top);
int boundedX, boundedY;
boundedX = ((newX <= 0) ? Math.max(smallestReachableX, newX) : Math.min(biggestReachableX, newX));
boundedY = ((newY <= 0) ? 0 : Math.min(biggestReachableY, newY));
return new Point(boundedX, boundedY);
}
private Point findPositionInsideDesktop(JComponent f, int newX, int newY) {
Container desktop = f.getParent();
Dimension desktopSize = desktop.getSize();
int boundedX = (int) Math.min(Math.max(0, newX), desktopSize.getWidth());
int boundedY = (int) Math.min(Math.max(0, newY), desktopSize.getHeight());
return new Point(boundedX, boundedY);
}
}
}