private void disposeAndUpdate(boolean update) {
   if (myView != null) {
     boolean visible = myView.isVisible();
     myView.setVisible(false);
     Container container = myContent.getParent();
     if (container != null) {
       container.remove(myContent);
     }
     if (myView instanceof Window) {
       myViewBounds = myView.getBounds();
       Window window = (Window) myView;
       if (!push(UIUtil.getWindow(myOwner), window)) {
         window.dispose();
       }
     } else {
       Container parent = myView.getParent();
       if (parent == null) {
         myViewBounds = new Rectangle(myContent.getPreferredSize());
       } else {
         myViewBounds = new Rectangle(myView.getBounds());
         parent.remove(myView);
         Point point = new Point(myViewBounds.x, myViewBounds.y);
         SwingUtilities.convertPointToScreen(point, parent);
         myViewBounds.x = point.x;
         myViewBounds.y = point.y;
       }
     }
     myView = null;
     if (update && visible) {
       setVisible(true);
     }
   }
 }
    /**
     * Returns true if popup can fit the screen and the owner's top parent. It determines can popup
     * be lightweight or mediumweight.
     */
    boolean fitsOnScreen() {
      boolean result = false;
      Component component = getComponent();
      if (owner != null && component != null) {
        int popupWidth = component.getWidth();
        int popupHeight = component.getHeight();

        Container parent = (Container) SwingUtilities.getRoot(owner);
        if (parent instanceof JFrame || parent instanceof JDialog || parent instanceof JWindow) {

          Rectangle parentBounds = parent.getBounds();
          Insets i = parent.getInsets();
          parentBounds.x += i.left;
          parentBounds.y += i.top;
          parentBounds.width -= i.left + i.right;
          parentBounds.height -= i.top + i.bottom;

          if (JPopupMenu.canPopupOverlapTaskBar()) {
            GraphicsConfiguration gc = parent.getGraphicsConfiguration();
            Rectangle popupArea = getContainerPopupArea(gc);
            result = parentBounds.intersection(popupArea).contains(x, y, popupWidth, popupHeight);
          } else {
            result = parentBounds.contains(x, y, popupWidth, popupHeight);
          }
        } else if (parent instanceof JApplet) {
          Rectangle parentBounds = parent.getBounds();
          Point p = parent.getLocationOnScreen();
          parentBounds.x = p.x;
          parentBounds.y = p.y;
          result = parentBounds.contains(x, y, popupWidth, popupHeight);
        }
      }
      return result;
    }
 /**
  * Removes the desktopIcon from its parent and adds its frame to the parent.
  *
  * @param f the <code>JInternalFrame</code> to be de-iconified
  */
 public void deiconifyFrame(JInternalFrame f) {
   JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
   Container c = desktopIcon.getParent();
   JDesktopPane d = f.getDesktopPane();
   if (c != null && d != null) {
     c.add(f);
     // If the frame is to be restored to a maximized state make
     // sure it still fills the whole desktop.
     if (f.isMaximum()) {
       Rectangle desktopBounds = c.getBounds();
       if (f.getWidth() != desktopBounds.width || f.getHeight() != desktopBounds.height) {
         setBoundsForFrame(f, 0, 0, desktopBounds.width, desktopBounds.height);
       }
     }
     removeIconFor(f);
     if (f.isSelected()) {
       f.moveToFront();
       f.restoreSubcomponentFocus();
     } else {
       try {
         f.setSelected(true);
       } catch (PropertyVetoException e2) {
       }
     }
   }
 }
Beispiel #4
0
 public Dimension preferredLayoutSize(Container target) {
   Insets insets = target.getInsets();
   Dimension compMax = new Dimension(0, 0);
   int maxheight = target.getBounds().height - (insets.top + insets.bottom + vgap * 2);
   int nmembers = target.getComponentCount();
   int visiblecount = 0;
   for (int i = 0; i < nmembers; i++) {
     Component m = target.getComponent(i);
     if (m.isVisible()) {
       ++visiblecount;
       Dimension d = m.getPreferredSize();
       compMax.width = Math.max(compMax.width, d.width);
       compMax.height = Math.max(compMax.height, d.height);
     }
   }
   if (visiblecount > 0) {
     int nrows = Math.max(1, (maxheight + compMax.height / 4) / compMax.height);
     int ncols = (visiblecount + nrows - 1) / nrows;
     compMax.height = compMax.height * nrows + vgap * (nrows - 1);
     compMax.width = compMax.width * ncols + hgap * (ncols - 1);
   }
   compMax.height += insets.top + insets.bottom + vgap * 2;
   compMax.width += insets.left + insets.right + hgap * 2;
   return compMax;
 }
    @Override
    public void layoutContainer(final Container parent) {
      final int componentCount = parent.getComponentCount();
      if (componentCount == 0) return;
      final EditorEx history = myHistoryViewer;
      final EditorEx editor = componentCount == 2 ? myConsoleEditor : null;

      if (editor == null) {
        parent.getComponent(0).setBounds(parent.getBounds());
        return;
      }

      final Dimension panelSize = parent.getSize();
      if (panelSize.getHeight() <= 0) return;
      final Dimension historySize = history.getContentSize();
      final Dimension editorSize = editor.getContentSize();
      final Dimension newEditorSize = new Dimension();

      // deal with width
      final int width = Math.max(editorSize.width, historySize.width);
      newEditorSize.width = width + editor.getScrollPane().getHorizontalScrollBar().getHeight();
      history.getSoftWrapModel().forceAdditionalColumnsUsage();
      editor
          .getSettings()
          .setAdditionalColumnsCount(
              2 + (width - editorSize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, editor));
      history
          .getSettings()
          .setAdditionalColumnsCount(
              2 + (width - historySize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, history));

      // deal with height
      if (historySize.width == 0) historySize.height = 0;
      final int minHistorySize =
          historySize.height > 0
              ? 2 * history.getLineHeight() + (myShowSeparatorLine ? SEPARATOR_THICKNESS : 0)
              : 0;
      final int minEditorSize = editor.isViewer() ? 0 : editor.getLineHeight();
      final int editorPreferred =
          editor.isViewer() ? 0 : Math.max(minEditorSize, editorSize.height);
      final int historyPreferred = Math.max(minHistorySize, historySize.height);
      if (panelSize.height < minEditorSize) {
        newEditorSize.height = panelSize.height;
      } else if (panelSize.height < editorPreferred) {
        newEditorSize.height = panelSize.height - minHistorySize;
      } else if (panelSize.height < editorPreferred + historyPreferred) {
        newEditorSize.height = editorPreferred;
      } else {
        newEditorSize.height = editorPreferred == 0 ? 0 : panelSize.height - historyPreferred;
      }
      final Dimension newHistorySize =
          new Dimension(width, panelSize.height - newEditorSize.height);

      // apply
      editor
          .getComponent()
          .setBounds(0, newHistorySize.height, panelSize.width, newEditorSize.height);
      myForceScrollToEnd.compareAndSet(false, shouldScrollHistoryToEnd());
      history.getComponent().setBounds(0, 0, panelSize.width, newHistorySize.height);
    }
 /**
  * This gets called automatically to adapt position and size of all components.
  *
  * @param parent Container to layout.
  */
 @Override
 public void layoutContainer(Container parent) {
   Rectangle parentBounds = parent.getBounds();
   for (TotalScaleComponent comp : comps) {
     comp.comp.setBounds(
         (int) (comp.x * parentBounds.width),
         (int) (comp.y * parentBounds.height),
         (int) (comp.width * parentBounds.width),
         (int) (comp.height * parentBounds.height));
   }
 }
 private boolean fitsInBounds(final Rectangle rect) {
   final Container container = getParent();
   if (container instanceof JViewport) {
     final Container scrollPane = container.getParent();
     if (scrollPane instanceof JScrollPane) {
       final Rectangle rectangle =
           SwingUtilities.convertRectangle(this, rect, scrollPane.getParent());
       return scrollPane.getBounds().contains(rectangle);
     }
   }
   return true;
 }
Beispiel #8
0
    /**
     * Instructs the layout manager to perform the layout for the specified container.
     *
     * @param parent the Container for which this layout manager is being used
     */
    public void layoutContainer(Container parent) {
      Rectangle b = parent.getBounds();
      Insets i = getInsets();
      int contentY = 0;
      int w = b.width - i.right - i.left;
      int h = b.height - i.top - i.bottom;

      if (layeredPane != null) {
        layeredPane.setBounds(i.left, i.top, w, h);
      }
      if (glassPane != null) {
        glassPane.setBounds(i.left, i.top, w, h);
      }
      // Note: This is laying out the children in the layeredPane,
      // technically, these are not our children.
      if (menuBar != null && menuBar.isVisible()) {
        Dimension mbd = menuBar.getPreferredSize();
        menuBar.setBounds(0, 0, w, mbd.height);
        contentY += mbd.height;
      }
      if (contentPane != null) {
        contentPane.setBounds(0, contentY, w, h - contentY);
      }
    }
  /** The iconifyFrame() code calls this to determine the proper bounds for the desktopIcon. */
  protected Rectangle getBoundsForIconOf(JInternalFrame f) {
    //
    // Get the icon for this internal frame and its preferred size
    //

    JInternalFrame.JDesktopIcon icon = f.getDesktopIcon();
    Dimension prefSize = icon.getPreferredSize();
    //
    // Get the parent bounds and child components.
    //

    Container c = f.getParent();
    if (c == null) {
      c = f.getDesktopIcon().getParent();
    }

    if (c == null) {
      /* the frame has not yet been added to the parent; how about (0,0) ?*/
      return new Rectangle(0, 0, prefSize.width, prefSize.height);
    }

    Rectangle parentBounds = c.getBounds();
    Component[] components = c.getComponents();

    //
    // Iterate through valid default icon locations and return the
    // first one that does not intersect any other icons.
    //

    Rectangle availableRectangle = null;
    JInternalFrame.JDesktopIcon currentIcon = null;

    int x = 0;
    int y = parentBounds.height - prefSize.height;
    int w = prefSize.width;
    int h = prefSize.height;

    boolean found = false;

    while (!found) {

      availableRectangle = new Rectangle(x, y, w, h);

      found = true;

      for (int i = 0; i < components.length; i++) {

        //
        // Get the icon for this component
        //

        if (components[i] instanceof JInternalFrame) {
          currentIcon = ((JInternalFrame) components[i]).getDesktopIcon();
        } else if (components[i] instanceof JInternalFrame.JDesktopIcon) {
          currentIcon = (JInternalFrame.JDesktopIcon) components[i];
        } else
          /* found a child that's neither an internal frame nor
          an icon. I don't believe this should happen, but at
          present it does and causes a null pointer exception.
          Even when that gets fixed, this code protects against
          the npe. hania */
          continue;

        //
        // If this icon intersects the current location, get next location.
        //

        if (!currentIcon.equals(icon)) {
          if (availableRectangle.intersects(currentIcon.getBounds())) {
            found = false;
            break;
          }
        }
      }

      if (currentIcon == null)
        /* didn't find any useful children above. This probably shouldn't
        happen, but this check protects against an npe if it ever does
        (and it's happening now) */
        return availableRectangle;

      x += currentIcon.getBounds().width;

      if (x + w > parentBounds.width) {
        x = 0;
        y -= h;
      }
    }

    return (availableRectangle);
  }
Beispiel #10
0
  public CBIR(String uname) {
    // super("CBIR");

    super();
    uid = uname;
    // initialize(uname);

    content = getContentPane();
    content.setBackground(Color.LIGHT_GRAY);
    Rectangle d = content.getBounds();
    content.setBounds((int) d.getX(), (int) d.getY(), 2000, 150);
    content.setLayout(new BorderLayout());
    bar = new JMenuBar();
    setJMenuBar(bar);
    // 1
    user = new JMenu("User");
    fileMenu = new JMenu("File");
    newM = new JMenu("New");
    histogram = new JMenu("Color Histogram");

    shape = new JMenu("Shape");
    // 2
    bar.add(user);
    bar.add(fileMenu);
    bar.add(histogram);

    bar.add(newM);

    averageRGB = new JMenuItem("AverageRGB");

    global = new JMenuItem("Global color Histogram");
    localColor = new JMenuItem("Local color Histogram");

    geometricMoment = new JMenuItem("Geometric Moment");
    // zernike = new JMenuItem("Zernike Moment");
    open = new JMenuItem("Open");

    // 3
    addUser = new JMenuItem("Add New User");
    // 4
    deleteUser = new JMenuItem("Delete User");

    addNew = new JMenuItem("Add New Image");
    addNewFolder = new JMenuItem("Add New Folder");

    averageRGB.addActionListener(this);

    global.addActionListener(this);
    open.addActionListener(this);
    addNew.addActionListener(this);
    // 5
    addUser.addActionListener(this);
    // 6
    deleteUser.addActionListener(this);
    localColor.addActionListener(this);
    // zernike.addActionListener(this);
    addNewFolder.addActionListener(this);

    // 7
    user.add(addUser);
    // 8
    user.add(deleteUser);

    newM.add(addNew);
    newM.add(addNewFolder);

    fileMenu.add(open);
    histogram.add(averageRGB);
    histogram.add(localColor);
    histogram.add(global);

    JPanel jp = new JPanel();
    jp.setBackground(Color.LIGHT_GRAY);
    jp.setLayout(new FlowLayout());
    JPanel jp1 = new JPanel();
    jp1.setBackground(Color.LIGHT_GRAY);
    jp1.setLayout(new FlowLayout());
    ImageIcon icon = new ImageIcon("CBIR.jpg");

    l1 = new JLabel(icon);
    l2 = new JLabel();
    l3 = new JLabel();
    /*pbQuery.setBounds(jp.getWidth()-127,60,500,500);
    pbQuery.setTitle("QueryImage");
    pbQuery.setSelectionEnabled(false);
    jp.add(pbQuery);*/
    // scr.setBounds(5,5,470,400);

    l2.setBounds(new java.awt.Rectangle(74, 0, 106, 26));
    l2.setFont(new java.awt.Font("TimesNewRoman", java.awt.Font.BOLD, 18));
    l3.setBackground(Color.pink);
    l3.setBounds(new java.awt.Rectangle(109, 500, 106, 109));
    l3.setFont(new java.awt.Font("TimesNewRoman", java.awt.Font.BOLD, 18));

    jp.add(l2);
    jp.add(l1);
    jp1.add(l3);

    content.add("West", jp1);
    content.add("North", jp);
    view = new Viewer2();
    content.add("Center", view);

    lblNewLabel = new JLabel("New label");
    view.add(lblNewLabel);
    bottom = new JPanel();

    bottom.add(next = new JButton("Next"));
    bottom.add(previous = new JButton("Previous"));
    next.addActionListener(this);
    previous.addActionListener(this);
    geometricMoment.addActionListener(this);
    previous.setEnabled(false);
    next.setEnabled(false);
    content.add("South", bottom);

    label = new JLabel("");
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.setBackground(Color.GRAY);
    getContentPane().add(label, BorderLayout.CENTER);
    label.setIcon(new ImageIcon("C:\\Users\\bilel\\Desktop\\aa.PNG"));
    setSize(650, 500);
    setVisible(true);
    // setResizable(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
  @Override
  public void layoutContainer(Container parent) {
    Rectangle b = parent.getBounds();
    DimenInfo info = computeDimens(parent, PREFERRED);

    // adjust the bounds width and height to account for the insets
    Insets insets = parent.getInsets();
    b.width -= (insets.left + insets.right);
    b.height -= (insets.top + insets.bottom);

    int nk = parent.getComponentCount();
    int sx, sy;
    int tothei, totgap = _gap * (info.count - 1);
    int freecount = info.count - info.numfix;

    // when stretching, there is the possibility that a pixel or more
    // will be lost to rounding error. we account for that here and
    // assign the extra space to the first free component
    int freefrac = 0;

    // do the on-axis policy calculations
    int defhei = 0;
    if (_policy == STRETCH) {
      if (freecount > 0) {
        int freehei = b.height - info.fixhei - totgap;
        defhei = freehei / info.totweight;
        freefrac = freehei % info.totweight;
        tothei = b.height;
      } else {
        tothei = info.fixhei + totgap;
      }

    } else if (_policy == EQUALIZE) {
      defhei = info.maxhei;
      tothei = info.fixhei + defhei * freecount + totgap;

    } else {
      tothei = info.tothei + totgap;
    }

    // do the off-axis policy calculations
    int defwid = 0;
    if (_offpolicy == STRETCH) {
      defwid = b.width;
    } else if (_offpolicy == EQUALIZE) {
      defwid = info.maxwid;
    }

    // do the justification-related calculations
    if (_justification == LEFT || _justification == TOP) {
      sy = insets.top;
    } else if (_justification == CENTER) {
      sy = insets.top + (b.height - tothei) / 2;
    } else { // RIGHT or BOTTOM
      sy = insets.top + b.height - tothei;
    }

    // do the layout
    for (int i = 0; i < nk; i++) {
      // skip non-visible kids
      if (info.dimens[i] == null) {
        continue;
      }

      Component child = parent.getComponent(i);
      Constraints c = getConstraints(child);
      int newwid, newhei;

      if (_policy == NONE || c.isFixed()) {
        newhei = info.dimens[i].height;
      } else {
        newhei = freefrac + ((_policy == STRETCH) ? defhei * c.getWeight() : defhei);
        // clear out the extra pixels the first time they're used
        freefrac = 0;
      }

      if (_offpolicy == NONE) {
        newwid = info.dimens[i].width;
      } else if (_offpolicy == CONSTRAIN) {
        newwid = Math.min(info.dimens[i].width, b.width);
      } else {
        newwid = defwid;
      }

      // determine our off-axis position
      if (_offjust == LEFT || _offjust == TOP) {
        sx = insets.left;
      } else if (_offjust == RIGHT || _offjust == BOTTOM) {
        sx = insets.left + b.width - newwid;
      } else { // CENTER
        sx = insets.left + (b.width - newwid) / 2;
      }

      child.setBounds(sx, sy, newwid, newhei);
      sy += child.getSize().height + _gap;
    }
  }