1 19 package org.netbeans.modules.versioning.diff; 20 21 import org.netbeans.api.diff.Difference; 22 23 import javax.swing.*; 24 import java.awt.*; 25 import java.awt.event.AWTEventListener ; 26 import java.awt.event.MouseEvent ; 27 28 31 class DiffActionTooltipWindow implements AWTEventListener { 32 33 private static final int SCREEN_BORDER = 20; 34 35 private JWindow actionsWindow; 36 private JWindow contentWindow; 37 38 private final DiffSidebar master; 39 private final Difference diff; 40 41 public DiffActionTooltipWindow(DiffSidebar master, Difference diff) { 42 this.master = master; 43 this.diff = diff; 44 Window w = SwingUtilities.windowForComponent(master.getTextComponent()); 45 actionsWindow = new JWindow(w); 46 if (diff.getType() != Difference.ADD) { 47 contentWindow = new JWindow(w); 48 } 49 } 50 51 DiffSidebar getMaster() { 52 return master; 53 } 54 55 public void show(Point location) { 56 DiffTooltipActionsPanel tp = new DiffTooltipActionsPanel(this, diff); 57 actionsWindow.add(tp); 58 actionsWindow.pack(); 59 actionsWindow.setLocation(location); 60 61 if (contentWindow != null) { 62 DiffTooltipContentPanel cp = new DiffTooltipContentPanel(master.getTextComponent(), master.getMimeType(), diff); 63 contentWindow.add(cp); 64 contentWindow.pack(); 65 Dimension dim = contentWindow.getSize(); 66 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 67 68 if (location.y + actionsWindow.getHeight() + dim.height + SCREEN_BORDER > screenSize.height) { 69 dim.height = screenSize.height - (location.y + actionsWindow.getHeight() + SCREEN_BORDER); 70 } 71 if (location.x + dim.width + SCREEN_BORDER > screenSize.width) { 72 dim.width = screenSize.width - (location.x + SCREEN_BORDER); 73 } 74 contentWindow.setSize(dim); 75 76 contentWindow.setLocation(location.x, location.y + actionsWindow.getHeight() - 1); contentWindow.setVisible(true); 78 } 79 80 actionsWindow.setVisible(true); 81 82 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK); 83 } 84 85 public void eventDispatched(AWTEvent event) { 86 if (event.getID() == MouseEvent.MOUSE_PRESSED) { 87 onClick(event); 88 94 } 95 } 96 97 private void onClick(AWTEvent event) { 98 Component component = (Component) event.getSource(); 99 Window w = SwingUtilities.windowForComponent(component); 100 if (w != actionsWindow && (contentWindow == null || w != contentWindow)) shutdown(); 101 } 102 103 void shutdown() { 104 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 105 actionsWindow.dispose(); 106 if (contentWindow != null) contentWindow.dispose(); 107 } 108 } 109 | Popular Tags |