File Source: StatusbarPopupWindow.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
     3   *
     4   * Permission is hereby granted, free of charge, to any person obtaining a copy
     5   * of this software and associated documentation files (the "Software"), to deal
     6   * in the Software without restriction, including without limitation the rights
     7   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   * copies of the Software, and to permit persons to whom the Software is
     9   * furnished to do so, subject to the following conditions:
    10   *
    11   * The above copyright notice and this permission notice shall be included in
    12   * all copies or substantial portions of the Software.
    13   *
    14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    20   * SOFTWARE.
    21   */
    22  
    23  package com.dmdirc.addons.ui_swing.components.statusbar;
    24  
    25  import com.dmdirc.addons.ui_swing.components.StandardDialog;
    26  
    27  import java.awt.Component;
    28  import java.awt.Graphics;
    29  import java.awt.Point;
    30  import java.awt.Window;
    31  
    32  import javax.swing.JDialog;
    33  import javax.swing.JPanel;
    34  import javax.swing.UIManager;
    35  import javax.swing.border.EtchedBorder;
    36  
    37  import net.miginfocom.swing.MigLayout;
    38  
    39  
    40      /**
    41   * A popup window which is shown above a status bar component to provide more
    42   * detailed information.
    43   *
    44   * @since 0.6.3m1
    45   * @author chris
    46   */
         /* 
    P/P   *  Method: JPanel access$100(StatusbarPopupWindow)
          * 
          *  Preconditions:
          *    x0 != null
          * 
          *  Postconditions:
          *    return_value == x0.parent
          *    init'ed(return_value)
          */
    47  public abstract class StatusbarPopupWindow extends StandardDialog {
    48  
    49      /**
    50       * A version number for this class. It should be changed whenever the class
    51       * structure is changed (or anything else that would prevent serialized
    52       * objects being unserialized with the new class).
    53       */
    54      private static final long serialVersionUID = 1;
    55  
    56      /** The parent JPanel. */
    57      private final JPanel parent;
    58      /** Parent window. */
    59      private Window parentWindow;
    60  
    61      /**
    62       * Creates a new status bar popup window.
    63       *
    64       * @param parent The {@link JPanel} to use for positioning
    65       * @param parentWindow Parent window
    66       */
    67      public StatusbarPopupWindow(final JPanel parent, final Window parentWindow) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow(JPanel, Window)
                  * 
                  *  Presumptions:
                  *    init'ed(java.awt.Dialog$ModalityType.MODELESS)
                  * 
                  *  Postconditions:
                  *    this.parent == parent
                  *    init'ed(this.parent)
                  *    this.parentWindow == parentWindow
                  *    init'ed(this.parentWindow)
                  */
    68          super(parentWindow, ModalityType.MODELESS);
    69  
    70          this.parent = parent;
    71          this.parentWindow = parentWindow;
    72  
    73          setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    74      }
    75  
    76      /** {@inheritDoc} */
    77      @Override
    78      public void setVisible(boolean b) {
                 /* 
    P/P           *  Method: void setVisible(bool)
                  * 
                  *  Preconditions:
                  *    (soft) this.parent != null
                  *    (soft) this.parentWindow != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow:getHeight(...)@99 <= 231
                  *    com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow:getWidth(...)@100 - (java.awt.Window:getWidth(...)@100 + java.awt.Window:getLocationOnScreen(...).x@100) in {-4_294_967_305..2_147_483_638}
                  *    javax.swing.JPanel:getWidth(...)@100 + javax.swing.JPanel:getLocationOnScreen(...).x@100 <= com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow:getWidth(...)@100 + 232
                  *    com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow:getWidth(...)@99/2 - javax.swing.JPanel:getWidth(...)@99/2 in {-3_221_225_471..231}
                  *    java.awt.Window:getLocationOnScreen(...)@100 != null
                  *    ...
                  * 
                  *  Test Vectors:
                  *    b: {0}, {1}
                  */
    79          if (b) {
    80              final JPanel panel = new JPanel();
    81  
    82              panel.setLayout(new MigLayout("ins 3 5 6 10, gap 10 5"));
    83  
    84              panel.setBackground(UIManager.getColor("ToolTip.background"));
    85              panel.setForeground(UIManager.getColor("ToolTip.foreground"));
    86  
    87              initContent(panel);
    88  
    89              add(panel);
    90  
    91              setUndecorated(true);
    92              setFocusableWindowState(false);
    93              setFocusable(false);
    94              setResizable(false);
    95  
    96              pack();
    97  
    98              final Point point = parent.getLocationOnScreen();
    99              point.translate(parent.getWidth() / 2 - this.getWidth() / 2, - this.getHeight());
   100              final int maxX = Math.max(parentWindow.getLocationOnScreen().x
   101                      + parentWindow.getWidth() - 10 - getWidth(),
   102                      parent.getLocationOnScreen().x + parent.getWidth() - 1 - getWidth());
   103              point.x = Math.min(maxX, point.x);
   104              setLocation(point);
   105  
   106              panel.setBorder(new GappedEtchedBorder());
   107          }
   108  
   109          super.setVisible(b);
   110      }
   111  
   112      /**
   113       * Initialises the content of the popup window.
   114       *
   115       * @param panel The {@link JPanel} to which content should be added
   116       */
   117      protected abstract void initContent(final JPanel panel);
   118  
   119      /**
   120       * An {@link EtchedBorder} that leaves a gap in the bottom where the
   121       * lag display panel is.
   122       */
             /* 
    P/P       *  Method: void com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow$GappedEtchedBorder(StatusbarPopupWindow, StatusbarPopupWindow$1)
              */
   123      private class GappedEtchedBorder extends EtchedBorder {
   124  
   125          /**
   126           * A version number for this class. It should be changed whenever the class
   127           * structure is changed (or anything else that would prevent serialized
   128           * objects being unserialized with the new class).
   129           */
   130          private static final long serialVersionUID = 1;
   131  
   132          /** {@inheritDoc} */
   133          @Override
   134          public void paintBorder(final Component c, final Graphics g,
   135                  final int x, final int y, final int width, final int height) {
                     /* 
    P/P               *  Method: void paintBorder(Component, Graphics, int, int, int, int)
                      * 
                      *  Preconditions:
                      *    g != null
                      *    height >= -231+1
                      *    init'ed(this.etchType)
                      *    this.parent != null
                      *    width >= -231+1
                      *    x <= 231
                      *    y <= 231
                      * 
                      *  Presumptions:
                      *    com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow:getLocationOnScreen(...).x@143 - javax.swing.JPanel:getLocationOnScreen(...).x@143 in range
                      *    com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow:getLocationOnScreen(...).x@145 - (javax.swing.JPanel:getWidth(...)@145 + javax.swing.JPanel:getLocationOnScreen(...).x@145) in range
                      *    com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow:getLocationOnScreen(...).x@145 - (javax.swing.JPanel:getWidth(...)@145 + javax.swing.JPanel:getLocationOnScreen(...).x@145) in {-232-1..231-2}
                      *    com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow:getLocationOnScreen(...)@143 != null
                      *    com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow:getLocationOnScreen(...)@145 != null
                      *    ...
                      * 
                      *  Test Vectors:
                      *    this.etchType: {-231..0, 2..232-1}, {1}
                      */
   136              int w = width;
   137              int h = height;
   138  
   139              g.translate(x, y);
   140  
   141              g.setColor(etchType == LOWERED? getShadowColor(c) : getHighlightColor(c));
   142              g.drawLine(0, 0, w-1, 0);
   143              g.drawLine(0, h-1, parent.getLocationOnScreen().x
   144                      - getLocationOnScreen().x, h-1);
   145              g.drawLine(parent.getWidth() + parent.getLocationOnScreen().x
   146                      - getLocationOnScreen().x - 2, h-1, w-1, h-1);
   147              g.drawLine(0, 0, 0, h-1);
   148              g.drawLine(w-1, 0, w-1, h-1);
   149  
   150              g.translate(-x, -y);
   151          }
   152  
   153      }
   154  
   155  }








SofCheck Inspector Build Version : 2.17854
StatusbarPopupWindow.java 2009-Jun-25 01:54:24
StatusbarPopupWindow.class 2009-Sep-02 17:04:14
StatusbarPopupWindow$1.class 2009-Sep-02 17:04:14
StatusbarPopupWindow$GappedEtchedBorder.class 2009-Sep-02 17:04:14