/*
   *  This method is called every time:
   *  - to make sure the viewport is returned to its default position
   *  - to remove the horizontal scrollbar when it is not wanted
   */
  private void checkHorizontalScrollBar(BasicComboPopup popup) {
    //  Reset the viewport to the left

    JViewport viewport = scrollPane.getViewport();
    Point p = viewport.getViewPosition();
    p.x = 0;
    viewport.setViewPosition(p);

    //  Remove the scrollbar so it is never painted

    if (!scrollBarRequired) {
      scrollPane.setHorizontalScrollBar(null);
      return;
    }

    //	Make sure a horizontal scrollbar exists in the scrollpane

    JScrollBar horizontal = scrollPane.getHorizontalScrollBar();

    if (horizontal == null) {
      horizontal = new JScrollBar(JScrollBar.HORIZONTAL);
      scrollPane.setHorizontalScrollBar(horizontal);
      scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    }

    //	Potentially increase height of scroll pane to display the scrollbar

    if (horizontalScrollBarWillBeVisible(popup, scrollPane)) {
      Dimension scrollPaneSize = scrollPane.getPreferredSize();
      scrollPaneSize.height += horizontal.getPreferredSize().height;
      scrollPane.setPreferredSize(scrollPaneSize);
      scrollPane.setMaximumSize(scrollPaneSize);
      scrollPane.revalidate();
    }
  }
示例#2
0
  /** Write file with position and size of the login box */
  public static void writePersistence() {

    Messages.postDebug("LoginBox", "LoginBox.writePersistence");
    // If the panel has not been created, don't try to write a file
    if (position == null) return;

    String filepath = FileUtil.savePath("USER/PERSISTENCE/LoginPanel");

    FileWriter fw;
    PrintWriter os;
    try {
      File file = new File(filepath);
      fw = new FileWriter(file);
      os = new PrintWriter(fw);
      os.println("Login Panel");

      os.println(height);
      os.println(width);
      double xd = position.getX();
      int xi = (int) xd;
      os.println(xi);
      double yd = position.getY();
      int yi = (int) yd;
      os.println(yi);

      os.close();
    } catch (Exception er) {
      Messages.postError("Problem creating  " + filepath);
      Messages.writeStackTrace(er);
    }
  }
示例#3
0
 @SuppressWarnings("unchecked")
 private static JButton getButton(JList list, Point pt, int index) {
   Container c =
       (Container)
           list.getCellRenderer().getListCellRendererComponent(list, "", index, false, false);
   Rectangle r = list.getCellBounds(index, index);
   c.setBounds(r);
   // c.doLayout(); //may be needed for mone LayoutManager
   pt.translate(-r.x, -r.y);
   Component b = SwingUtilities.getDeepestComponentAt(c, pt.x, pt.y);
   if (b instanceof JButton) {
     return (JButton) b;
   } else {
     return null;
   }
 }
    public void mouseDragged(MouseEvent ev) {
      Window w = (Window) ev.getSource();
      Point pt = ev.getPoint();

      if (isMovingWindow) {
        Point windowPt;
        try {
          windowPt = (Point) AccessController.doPrivileged(getLocationAction);
          windowPt.x = windowPt.x - dragOffsetX;
          windowPt.y = windowPt.y - dragOffsetY;
          w.setLocation(windowPt);
        } catch (PrivilegedActionException e) {
        }
      } else if (dragCursor != 0) {
        Rectangle r = w.getBounds();
        Rectangle startBounds = new Rectangle(r);
        Dimension min = w.getMinimumSize();

        switch (dragCursor) {
          case Cursor.E_RESIZE_CURSOR:
            adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0);
            break;
          case Cursor.S_RESIZE_CURSOR:
            adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height);
            break;
          case Cursor.N_RESIZE_CURSOR:
            adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY));
            break;
          case Cursor.W_RESIZE_CURSOR:
            adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0);
            break;
          case Cursor.NE_RESIZE_CURSOR:
            adjust(
                r,
                min,
                0,
                pt.y - dragOffsetY,
                pt.x + (dragWidth - dragOffsetX) - r.width,
                -(pt.y - dragOffsetY));
            break;
          case Cursor.SE_RESIZE_CURSOR:
            adjust(
                r,
                min,
                0,
                0,
                pt.x + (dragWidth - dragOffsetX) - r.width,
                pt.y + (dragHeight - dragOffsetY) - r.height);
            break;
          case Cursor.NW_RESIZE_CURSOR:
            adjust(
                r,
                min,
                pt.x - dragOffsetX,
                pt.y - dragOffsetY,
                -(pt.x - dragOffsetX),
                -(pt.y - dragOffsetY));
            break;
          case Cursor.SW_RESIZE_CURSOR:
            adjust(
                r,
                min,
                pt.x - dragOffsetX,
                0,
                -(pt.x - dragOffsetX),
                pt.y + (dragHeight - dragOffsetY) - r.height);
            break;
          default:
            break;
        }
        if (!r.equals(startBounds)) {
          w.setBounds(r);
          // Defer repaint/validate on mouseReleased unless dynamic
          // layout is active.
          if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) {
            w.validate();
            getRootPane().repaint();
          }
        }
      }
    }