/**
   * Shows the given error message.
   *
   * @param text the text of the error
   */
  private void showErrorMessage(String text) {
    errorPane.setText(text);

    if (errorPane.getParent() == null) add(errorPane, BorderLayout.NORTH);

    SwingUtilities.getWindowAncestor(CreateSip2SipAccountForm.this).pack();
  }
示例#2
0
 private boolean checkRightMargin(int w) {
   // Make sure rightMargin has at least 2 pixels over
   if (w + 2 > rightMargin) {
     rightMargin = (w + 2);
     // Repaint from top (above any cell renderers)
     SwingUtilities.getWindowAncestor(this).repaint();
     return true;
   }
   return false;
 }
示例#3
0
 private boolean checkLeftMargin(int x) {
   // Make sure leftMargin has at least 2 pixels over
   if (x < 2) {
     leftMargin += (2 - x);
     // Repaint from top (above any cell renderers)
     SwingUtilities.getWindowAncestor(this).repaint();
     return true;
   }
   return false;
 }
示例#4
0
  /**
   * Tries to find the owning window for the given component.
   *
   * @param aComponent the AWT event to find the owning window for, may be <code>null</code>.
   * @return the owning window, or <code>null</code> if no such window could be found, or a <code>
   *     null</code> component was given.
   */
  public static final Window getOwningWindow(final Component aComponent) {
    if (aComponent == null) {
      return null;
    }

    Window owner = SwingUtilities.getWindowAncestor(aComponent);
    if (owner == null) {
      owner = getCurrentWindow();
    }
    return owner;
  }
 /**
  * Installs the necessary Listeners on the parent <code>Window</code>, if there is one.
  *
  * <p>This takes the parent so that cleanup can be done from <code>removeNotify</code>, at which
  * point the parent hasn't been reset yet.
  *
  * @param parent The parent of the JRootPane
  */
 private void installWindowListeners(JRootPane root, Component parent) {
   if (parent instanceof Window) {
     window = (Window) parent;
   } else {
     window = SwingUtilities.getWindowAncestor(parent);
   }
   if (window != null) {
     if (mouseInputListener == null) {
       mouseInputListener = createWindowMouseInputListener(root);
     }
     window.addMouseListener(mouseInputListener);
     window.addMouseMotionListener(mouseInputListener);
   }
 }
示例#6
0
    public void actionPerformed(ActionEvent e) {
      int tempW = mapWidth;
      int tempH = mapHeight;
      int targetW;
      int targetH;
      try {
        targetW = Integer.parseInt(widthField.getText());
        targetH = Integer.parseInt(heightField.getText());

        if (targetH <= 0 || targetW <= 0) {
          JOptionPane.showMessageDialog(null, "Both x and y must be above 0.");
        } else {

          // shrink width if necessary
          while (targetW < mapWidth) {
            for (int i = mapHeight * mapWidth - 1; i >= 0; i -= mapWidth) {
              map.remove(i);
            }
            mapWidth--;
            mapScroll.revalidate();
            map.repaint();

            backEnd.removeColumn(backEnd.getWidth() - 1);
          }

          // shrink height if necessary
          while (targetH < mapHeight) {
            for (int i = 1; i <= mapWidth; i++) {
              map.remove(mapHeight * mapWidth - i);
            }
            mapHeight--;
            // map.setLayout(new GridLayout(mapHeight,mapWidth));
            map.repaint();
            backEnd.removeRow(backEnd.getHeight() - 1);
          }

          // Grow if necessary
          if (targetW > mapWidth || targetH > mapHeight) {
            // add new rows and columns, then rebuild and re-add display
            int[] mov = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
            while (targetW > mapWidth) {
              // add new column to backEnd
              List<Tile> tList = new ArrayList<Tile>();
              for (int i = 0; i < mapHeight; i++) {
                Tile t = new Tile(currTileImg, "Test", 0, 0, mov, "none", true, currTileLoc);
                t.setPreferredSize(
                    new Dimension(TILE_SIZE * DISPLAY_SCALE, TILE_SIZE * DISPLAY_SCALE));
                t.addMouseListener(new MapButtonListener());
                tList.add(t);
              }
              backEnd.addColumn(tList);
              mapWidth++;
            }
            while (targetH > mapHeight) {
              // add new row to backEnd
              List<Tile> tList = new ArrayList<Tile>();
              for (int i = 0; i < mapWidth; i++) {
                Tile t = new Tile(currTileImg, "Test", 0, 0, mov, "none", true, currTileLoc);
                t.setPreferredSize(
                    new Dimension(TILE_SIZE * DISPLAY_SCALE, TILE_SIZE * DISPLAY_SCALE));
                t.addMouseListener(new MapButtonListener());
                tList.add(t);
              }
              backEnd.addRow(tList);
              mapHeight++;
            }

            GridBagConstraints gbc = new GridBagConstraints();

            for (int i = 0; i < mapHeight; i++) {
              gbc.gridy = i;
              for (int j = 0; j < mapWidth; j++) {
                gbc.gridx = j;
                map.add(backEnd.getTile(j, i), gbc);
              }
            }
            map.revalidate();
            map.repaint();
            parentPanel.revalidate();
            parentPanel.repaint();
            ((MapBuilder) SwingUtilities.getWindowAncestor(parentPanel)).pack();
          }
        }
      } catch (NumberFormatException f) {
        JOptionPane.showMessageDialog(null, "Both x and y must be valid integers.");
      }
    }