private void adjustWindowSize(ContainerWrapper paramContainerWrapper) {
   BoundSize localBoundSize1 = this.lc.getPackWidth();
   BoundSize localBoundSize2 = this.lc.getPackHeight();
   if ((localBoundSize1 == null) && (localBoundSize2 == null)) return;
   Window localWindow =
       (Window)
           SwingUtilities.getAncestorOfClass(
               Window.class, (Component) paramContainerWrapper.getComponent());
   if (localWindow == null) return;
   Dimension localDimension = localWindow.getPreferredSize();
   int i =
       constrain(
           checkParent(localWindow),
           localWindow.getWidth(),
           localDimension.width,
           localBoundSize1);
   int j =
       constrain(
           checkParent(localWindow),
           localWindow.getHeight(),
           localDimension.height,
           localBoundSize2);
   int k =
       Math.round(
           localWindow.getX()
               - (i - localWindow.getWidth()) * (1.0F - this.lc.getPackWidthAlign()));
   int m =
       Math.round(
           localWindow.getY()
               - (j - localWindow.getHeight()) * (1.0F - this.lc.getPackHeightAlign()));
   localWindow.setBounds(k, m, i, j);
 }
Exemplo n.º 2
0
 public void mouseDragged(MouseEvent e) {
   Point newPos = e.getPoint();
   SwingUtilities.convertPointToScreen(newPos, SizeGrip.this);
   int xDelta = newPos.x - origPos.x;
   int yDelta = newPos.y - origPos.y;
   Window wind = SwingUtilities.getWindowAncestor(SizeGrip.this);
   if (wind != null) { // Should always be true
     if (getComponentOrientation().isLeftToRight()) {
       int w = wind.getWidth();
       if (newPos.x >= wind.getX()) {
         w += xDelta;
       }
       int h = wind.getHeight();
       if (newPos.y >= wind.getY()) {
         h += yDelta;
       }
       wind.setSize(w, h);
     } else { // RTL
       int newW = Math.max(1, wind.getWidth() - xDelta);
       int newH = Math.max(1, wind.getHeight() + yDelta);
       wind.setBounds(newPos.x, wind.getY(), newW, newH);
     }
     // invalidate()/validate() needed pre-1.6.
     wind.invalidate();
     wind.validate();
   }
   origPos.setLocation(newPos);
 }
Exemplo n.º 3
0
  /**
   * Keskitä ikkuna toiseen nähden.
   *
   * @param child Keskitettävä ikkuna.
   * @param parent Ikkuna, jonka suhteen keskitetään.
   */
  public static void centerChild(Window child, Window parent) {
    Point parentCorner = parent.getLocation();
    double x = parentCorner.getX();
    double y = parentCorner.getY();
    x += (parent.getWidth() - child.getWidth()) / 2;
    y += (parent.getHeight() - child.getHeight()) / 2;
    Point newLocation = new Point((int) x, (int) y);

    child.setLocation(newLocation);
  }
Exemplo n.º 4
0
  public static void main(final String[] args) throws AWTException {
    final boolean dump = Boolean.parseBoolean(args[0]);
    final Window w =
        new Frame() {
          @Override
          public void list(final PrintStream out, final int indent) {
            super.list(out, indent);
            dumped = true;
          }
        };
    w.setSize(200, 200);
    w.setLocationRelativeTo(null);
    w.setVisible(true);

    final Robot robot = new Robot();
    robot.setAutoDelay(50);
    robot.setAutoWaitForIdle(true);
    robot.mouseMove(w.getX() + w.getWidth() / 2, w.getY() + w.getHeight() / 2);
    robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_F1);
    robot.keyRelease(KeyEvent.VK_F1);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.keyRelease(KeyEvent.VK_CONTROL);

    w.dispose();
    if (dumped != dump) {
      throw new RuntimeException("Exp:" + dump + ", actual:" + dumped);
    }
  }
Exemplo n.º 5
0
 // get height of window
 public int getHeight() {
   Window w = vc.getFullScreenWindow();
   if (w != null) {
     return w.getHeight();
   } else {
     return 0;
   }
 }
Exemplo n.º 6
0
  public static void centerWindow(Window window) {
    Preconditions.checkArgument(window != null);

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int x = ((int) screenSize.getWidth() - window.getWidth()) >> 1;
    int y = ((int) screenSize.getHeight() - window.getHeight()) >> 1;
    window.setLocation(x, y);
  }
Exemplo n.º 7
0
    /**
     * Returns the corner that contains the point <code>x</code>, <code>y</code>, or -1 if the
     * position doesn't match a corner.
     */
    private int calculateCorner(Window w, int x, int y) {
      Insets insets = w.getInsets();
      int xPosition = calculatePosition(x - insets.left, w.getWidth() - insets.left - insets.right);
      int yPosition = calculatePosition(y - insets.top, w.getHeight() - insets.top - insets.bottom);

      if (xPosition == -1 || yPosition == -1) {
        return -1;
      }
      return yPosition * 5 + xPosition;
    }
Exemplo n.º 8
0
  // recenter the mouse using the robot
  public synchronized void recenterMouse() {
    Window w = s.getFullScreenWindow();

    if (robot != null && w.isShowing()) {
      center.x = w.getWidth() / 2;
      center.y = w.getHeight() / 2;

      SwingUtilities.convertPointToScreen(center, w);
      centering = true;
      robot.mouseMove(center.x, center.y);
    }
  }
Exemplo n.º 9
0
  public D80ReportView(Window parent, Study study) {
    super(parent, "Summary of Efficacy Table");
    setModal(false);
    d_study = study;
    setMinimumSize(new Dimension(parent.getWidth() / 4 * 3, parent.getHeight() / 4 * 3));
    // setResizable(false);
    setLocationRelativeTo(parent);

    d_d80Report = D80TableGenerator.getHtml(d_study);

    buildPanel();
  }
Exemplo n.º 10
0
  public static void locateCenter(Window pWin) {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension d = tk.getScreenSize();

    int screenHeight = d.height;
    int screenWidth = d.width;

    int curHeight = pWin.getHeight();
    int curWidth = pWin.getWidth();

    pWin.setLocation((screenWidth - curWidth) / 2, (screenHeight - curHeight) / 2);
  }
Exemplo n.º 11
0
 private void updateWindow(boolean repaint) {
   Window w = (Window) target;
   synchronized (getStateLock()) {
     if (isOpaque || !w.isVisible() || (w.getWidth() <= 0) || (w.getHeight() <= 0)) {
       return;
     }
     TranslucentWindowPainter currentPainter = painter;
     if (currentPainter != null) {
       currentPainter.updateWindow(repaint);
     } else if (log.isLoggable(PlatformLogger.Level.FINER)) {
       log.finer("Translucent window painter is null in updateWindow");
     }
   }
 }
Exemplo n.º 12
0
  /**
   * A very basic dialogue creator. This allows for greater customization like setting modality.
   *
   * @param owner The owner
   * @param minSize The minimum size
   * @param title The title
   * @param message The message to display
   * @param option The options - i.e. the buttons added defined by {@link JDialog} option types.
   *     Currently only {@link JOptionPane#OK_OPTION} is supported.
   * @param icon The icon to display
   * @param modalityType The modality type @see ModalityType
   */
  private void showDialouge(
      Window owner,
      Dimension minSize,
      String title,
      String message,
      int option,
      Icon icon,
      ModalityType modalityType) {
    final JDialog d = new JDialog(owner, title, modalityType);
    d.setLayout(new BorderLayout());
    d.setSize(minSize);
    d.setMinimumSize(minSize);
    // set the dialouge's location to be centred at the centre of it's owner
    d.setLocation(
        ((owner.getX() + owner.getWidth()) / 2) - d.getWidth() / 2,
        ((owner.getY() + owner.getHeight()) / 2) - d.getHeight() / 2);
    JLabel l = new JLabel(message, icon, SwingConstants.CENTER);
    // Add dialogue's text containing children for text recolouring
    l.setForeground(survivor.getCurrentColourScheme().getReadableText());
    complementaryAmenableForegroundColourableComponents.add(l);
    d.add(l, BorderLayout.CENTER);

    if (option == JOptionPane.OK_OPTION) {
      JButton ok = new JButton("OK");
      // make the button respond when ENTER is pressed
      ok.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "pressed");
      ok.getInputMap().put(KeyStroke.getKeyStroke("released ENTER"), "released");
      // Add dialogue's text containing children for text recolouring
      complementaryAmenableForegroundColourableComponents.add(ok);
      ok.setForeground(survivor.getCurrentColourScheme().getReadableText());
      ok.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
              d.dispose();
            }
          });

      d.add(ok, BorderLayout.PAGE_END);
    }

    //		d.setBackground(hangman.currentColourScheme.getC3());
    // The dialogue is included in the below sets for proper colouring
    backgroundColourableComponents.add(d);

    d.setVisible(true);
  }
Exemplo n.º 13
0
  protected synchronized Dialog createGotoDialog() {
    if (gotoDialog == null) {
      gotoDialog =
          DialogSupport.createDialog(
              NbBundle.getBundle(org.netbeans.editor.BaseKit.class)
                  .getString("goto-title"), // NOI18N
              gotoPanel,
              false, // non-modal
              gotoButtons,
              false, // sidebuttons,
              0, // defaultIndex = 0 => gotoButton
              1, // cancelIndex = 1 => cancelButton
              this // listener
              );

      gotoDialog.pack();

      // Position the dialog according to the history
      Rectangle lastBounds = (Rectangle) EditorState.get(BOUNDS_KEY);
      if (lastBounds != null) {
        gotoDialog.setBounds(lastBounds);
      } else { // no history, center it on the screen
        Dimension dim = gotoDialog.getPreferredSize();
        int x;
        int y;
        JTextComponent c = EditorRegistry.lastFocusedComponent();
        Window w = c != null ? SwingUtilities.getWindowAncestor(c) : null;
        if (w != null) {
          x = Math.max(0, w.getX() + (w.getWidth() - dim.width) / 2);
          y = Math.max(0, w.getY() + (w.getHeight() - dim.height) / 2);
        } else {
          Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
          x = Math.max(0, (screen.width - dim.width) / 2);
          y = Math.max(0, (screen.height - dim.height) / 2);
        }
        gotoDialog.setLocation(x, y);
      }

      return gotoDialog;
    } else {
      gotoDialog.setVisible(true);
      gotoDialog.toFront();
      return null;
    }
  }
Exemplo n.º 14
0
  @Override
  public void start(Question t, JButton sourceButton) {
    JDialog dialog = new JDialog(windowParent, "Question Editor");

    QuestionEditorPanel questionEditorPanel = new QuestionEditorPanel(t, dialog, sourceButton);
    dialog.add(questionEditorPanel);

    dialog.setModalityType(ModalityType.APPLICATION_MODAL);
    dialog.pack();

    // Centers inside the application frame
    int x = windowParent.getX() + (windowParent.getWidth() - dialog.getWidth()) / 2;
    int y = windowParent.getY() + (windowParent.getHeight() - dialog.getHeight()) / 2;
    dialog.setLocation(x, y);

    // Shows the modal dialog and waits
    dialog.setVisible(true);
    dialog.toFront();
  }
Exemplo n.º 15
0
    public void mousePressed(MouseEvent ev) {
      JRootPane rootPane = getRootPane();

      if (rootPane.getWindowDecorationStyle() == JRootPane.NONE) {
        return;
      }
      Point dragWindowOffset = ev.getPoint();
      Window w = (Window) ev.getSource();
      if (w != null) {
        w.toFront();
      }
      Point convertedDragWindowOffset =
          SwingUtilities.convertPoint(w, dragWindowOffset, getTitlePane());

      Frame f = null;
      Dialog d = null;

      if (w instanceof Frame) {
        f = (Frame) w;
      } else if (w instanceof Dialog) {
        d = (Dialog) w;
      }

      int frameState = (f != null) ? f.getExtendedState() : 0;

      if (getTitlePane() != null && getTitlePane().contains(convertedDragWindowOffset)) {
        if ((f != null && ((frameState & Frame.MAXIMIZED_BOTH) == 0) || (d != null))
            && dragWindowOffset.y >= BORDER_DRAG_THICKNESS
            && dragWindowOffset.x >= BORDER_DRAG_THICKNESS
            && dragWindowOffset.x < w.getWidth() - BORDER_DRAG_THICKNESS) {
          isMovingWindow = true;
          dragOffsetX = dragWindowOffset.x;
          dragOffsetY = dragWindowOffset.y;
        }
      } else if (f != null && f.isResizable() && ((frameState & Frame.MAXIMIZED_BOTH) == 0)
          || (d != null && d.isResizable())) {
        dragOffsetX = dragWindowOffset.x;
        dragOffsetY = dragWindowOffset.y;
        dragWidth = w.getWidth();
        dragHeight = w.getHeight();
        dragCursor = getCursor(calculateCorner(w, dragWindowOffset.x, dragWindowOffset.y));
      }
    }
  public static void dumpRedsFromImage(Window w) {
    Point offset = w.getLocationOnScreen();

    System.err.println("");
    System.err.println("");
    System.err.println("");

    for (int y = 0; y < w.getHeight(); y++) {
      System.err.print("  ");
      for (int x = 0; x < w.getWidth(); x++) {
        Color rgb = kRobot.getPixelColor(offset.x + x, offset.y + y);
        int r = rgb.getRed();
        String c = (r == 0xff ? "X" : (r == 0 ? "." : "?"));
        System.err.print(c + " ");
        // System.err.print( r + " ");
      }
      System.err.println("");
    }
  }
Exemplo n.º 17
0
  public static void centerDialog(final Window dialog) {
    final GraphicsConfiguration config =
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration();

    final Rectangle screenBounds = config.getBounds();
    final Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(config);

    screenBounds.x = screenBounds.x + insets.left;
    screenBounds.y = screenBounds.y + insets.top;
    screenBounds.width = screenBounds.width - (insets.left + insets.right);
    screenBounds.height = screenBounds.height - (insets.top + insets.bottom);

    // remember that casting doubles to int's always rounds down.
    dialog.setLocation(
        ((screenBounds.width / 2) + screenBounds.x - (dialog.getWidth() / 2)),
        ((screenBounds.height / 2) + screenBounds.y - (dialog.getHeight() / 2)));
  }
Exemplo n.º 18
0
 public void screeny() {
   try {
     Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
     Point point = window.getLocationOnScreen();
     int x = (int) point.getX();
     int y = (int) point.getY();
     int w = window.getWidth();
     int h = window.getHeight();
     Robot robot = new Robot(window.getGraphicsConfiguration().getDevice());
     Rectangle captureSize = new Rectangle(x, y, w, h);
     java.awt.image.BufferedImage bufferedimage = robot.createScreenCapture(captureSize);
     String fileExtension = "Elysium";
     for (int i = 1; i <= 1000; i++) {
       File file = new File("Screenshots/" + fileExtension + " " + i + ".png");
       if (!file.exists()) {
         screenshot = i;
         takeScreeny = true;
         break;
       }
     }
     File file =
         new File(
             (new StringBuilder())
                 .append("Screenshots/" + fileExtension + " ")
                 .append(screenshot)
                 .append(".png")
                 .toString());
     if (takeScreeny == true) {
       // client.pushMessage("A picture has been saved in your screenshots folder.", 0, "");
       ImageIO.write(bufferedimage, "png", file);
     } else {
       // client.pushMessage("@red@Uh oh! Your screeny folder is full!", 0, "");
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 19
0
 public ReflectToolPanel(Window frame) {
   dialog = new JDialog(frame);
   dialog.setContentPane(this);
   initComponents();
   // this.setPreferredSize(new Dimension(WIDTH,HEIGHT));
   // Insets inset=dialog.getInsets();
   // dialog.setSize(new Dimension(WIDTH+inset.left+inset.right,HEIGHT+inset.top+inset.bottom));
   dialog.setLocationByPlatform(true);
   dialog.setResizable(false);
   dialog.getRootPane().setDefaultButton(okButton);
   dialog.setDefaultCloseOperation(dialog.DISPOSE_ON_CLOSE);
   dialog.setModal(true);
   dialog.setTitle("対称移動");
   angle.addChangeListener(this);
   angleSlider.addChangeListener(this);
   angle.setValue(JEnvironment.DEFAULT_REFLECT_AXIS);
   angleSlider.setValue(-JEnvironment.DEFAULT_REFLECT_AXIS);
   dialog.pack();
   int centerX = frame.getX() + (frame.getWidth() - dialog.getWidth()) / 2;
   int centerY = frame.getY() + (frame.getHeight() - dialog.getHeight()) / 2;
   dialog.setLocation(centerX, centerY);
   okButton.requestFocus();
   dialog.setVisible(true);
 }
Exemplo n.º 20
0
  /** Create the dialog. */
  public CallbackCreationDialog(
      Window parrent, final Project project, final PCallback callback, final boolean newMode) {
    super(parrent, ModalityType.APPLICATION_MODAL);
    // super(parrent, true);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    if (newMode) setTitle("New callback");
    else setTitle("Callback settings");

    setResizable(false);
    setBounds(
        parrent.getX() + (parrent.getWidth() / 2) - (436 / 2),
        parrent.getY() + (parrent.getHeight() / 2) - (101 / 2),
        436,
        101);

    getContentPane().setLayout(null);

    textName = new JTextField();
    textName.setBounds(10, 21, 414, 24);
    getContentPane().add(textName);
    textName.setColumns(10);

    if (newMode) btnCreate = new JButton("Create");
    else btnCreate = new JButton("Save");

    btnCreate.setEnabled(false);
    btnCreate.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            if (newMode) project.newCallback(textName.getText());
            else callback.setName(textName.getText());

            dispose();
          }
        });
    btnCreate.setBounds(335, 48, 89, 23);
    getContentPane().add(btnCreate);

    JLabel lblEnterSequenceName = new JLabel("Callback name:");
    lblEnterSequenceName.setBounds(10, 6, 414, 14);
    getContentPane().add(lblEnterSequenceName);

    JButton btnCancel = new JButton("Cancel");
    btnCancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });
    btnCancel.setBounds(236, 48, 89, 23);
    getContentPane().add(btnCancel);

    lblErrorLabel = new JLabel("Enter callback name.");
    lblErrorLabel.setForeground(Color.RED);
    lblErrorLabel.setBounds(10, 52, 216, 14);
    getContentPane().add(lblErrorLabel);

    ChangeListener changeListener = new ChangeListener();

    textName.getDocument().addDocumentListener(changeListener);

    if (newMode == false) {
      textName.setText(callback.getName());
      checkConditions();
    }

    setVisible(true);
  }
  public static void iniciarVentana(Window ventana) {

    IniciadorDeVentanas.iniciarVentana(ventana, ventana.getWidth(), ventana.getHeight());
  }
Exemplo n.º 22
0
 public static void centreWindow(Window frame) {
   Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
   int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2);
   int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2);
   frame.setLocation(x, y);
 }
Exemplo n.º 23
0
  /** Installs the sheet on the owner. This method is invoked just before the JSheet is shown. */
  protected void installSheet() {
    if (!isNativeSheetSupported() && !isInstalled && isExperimentalSheet()) {
      Window owner = getOwner();
      if (owner != null) {
        owner.addWindowListener(windowEventHandler);
      }
      isInstalled = true;
    } else {
      Window owner = getOwner();
      if (owner != null) {

        // Determine the location for the sheet and its owner while
        // the sheet will be visible.
        // In case we have to shift the owner to fully display the
        // dialog, we remember the shift back position.
        Point ownerLoc = owner.getLocation();
        Point sheetLoc;
        if (isShowAsSheet()) {
          if (owner instanceof JFrame) {
            sheetLoc =
                new Point(
                    ownerLoc.x + (owner.getWidth() - getWidth()) / 2,
                    ownerLoc.y
                        + owner.getInsets().top
                        + ((JFrame) owner).getRootPane().getContentPane().getY());
          } else if (owner instanceof JDialog) {
            sheetLoc =
                new Point(
                    ownerLoc.x + (owner.getWidth() - getWidth()) / 2,
                    ownerLoc.y
                        + owner.getInsets().top
                        + ((JDialog) owner).getRootPane().getContentPane().getY());
          } else {
            sheetLoc =
                new Point(
                    ownerLoc.x + (owner.getWidth() - getWidth()) / 2,
                    ownerLoc.y + owner.getInsets().top);
          }

          if (sheetLoc.x < 0) {
            owner.setLocation(ownerLoc.x - sheetLoc.x, ownerLoc.y);
            sheetLoc.x = 0;
            shiftBackLocation = ownerLoc;
            oldLocation = owner.getLocation();
          } else {
            shiftBackLocation = null;
            oldLocation = ownerLoc;
          }
        } else {
          sheetLoc =
              new Point(
                  ownerLoc.x + (owner.getWidth() - getWidth()) / 2,
                  ownerLoc.y + (owner.getHeight() - getHeight()) / 2);
        }
        setLocation(sheetLoc);

        oldFocusOwner = owner.getFocusOwner();

        // Note: We mustn't change the windows focusable state because
        // this also affects the focusable state of the JSheet.
        // owner.setFocusableWindowState(false);
        owner.setEnabled(false);
        // ((JFrame) owner).setResizable(false);
        if (isShowAsSheet()) {
          owner.addComponentListener(ownerMovementHandler);
        } else {
          if (owner instanceof Frame) {
            setTitle(((Frame) owner).getTitle());
          }
        }
      }
      isInstalled = true;
    }
  }
Exemplo n.º 24
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.appwork.utils.swing.dialog.Locator#getLocationOnScreen(javax.swing
   * .JDialog)
   */
  @Override
  public Point getLocationOnScreen(final Window dialog) {

    if (dialog.getParent() == null
        || !dialog.getParent().isDisplayable()
        || !dialog.getParent().isVisible()) {
      final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

      return correct(
          new Point(
              (int) (screenSize.getWidth() - dialog.getWidth()) / 2,
              (int) (screenSize.getHeight() - dialog.getHeight()) / 2),
          dialog);

    } else if (dialog.getParent() instanceof Frame
        && ((Frame) dialog.getParent()).getExtendedState() == Frame.ICONIFIED) {
      // dock dialog at bottom right if mainframe is not visible

      final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      final GraphicsDevice[] screens = ge.getScreenDevices();

      for (final GraphicsDevice screen : screens) {
        final Rectangle bounds = screen.getDefaultConfiguration().getBounds();
        screen.getDefaultConfiguration().getDevice();

        final Insets insets =
            Toolkit.getDefaultToolkit().getScreenInsets(screen.getDefaultConfiguration());
        if (bounds.contains(MouseInfo.getPointerInfo().getLocation())) {

          return correct(
              new Point(
                  (int) (bounds.x + bounds.getWidth() - dialog.getWidth() - 20 - insets.right),
                  (int) (bounds.y + bounds.getHeight() - dialog.getHeight() - 20 - insets.bottom)),
              dialog);
        }
      }
      final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      return correct(
          new Point(
              (int) (screenSize.getWidth() - dialog.getWidth() - 20),
              (int) (screenSize.getHeight() - dialog.getHeight() - 60)),
          dialog);
    } else {
      final Point ret = SwingUtils.getCenter(dialog.getParent(), dialog);

      return correct(ret, dialog);
    }

    // if (frame.getParent() == null || !frame.getParent().isDisplayable()
    // || !frame.getParent().isVisible()) {
    // final Dimension screenSize =
    // Toolkit.getDefaultToolkit().getScreenSize();
    //
    // return (new Point((int) (screenSize.getWidth() - frame.getWidth()) /
    // 2, (int) (screenSize.getHeight() - frame.getHeight()) / 2));
    //
    // } else if (frame.getParent() instanceof Frame && ((Frame)
    // frame.getParent()).getExtendedState() == Frame.ICONIFIED) {
    // // dock dialog at bottom right if mainframe is not visible
    //
    // final GraphicsEnvironment ge =
    // GraphicsEnvironment.getLocalGraphicsEnvironment();
    // final GraphicsDevice[] screens = ge.getScreenDevices();
    //
    // for (final GraphicsDevice screen : screens) {
    // final Rectangle bounds =
    // screen.getDefaultConfiguration().getBounds();
    // screen.getDefaultConfiguration().getDevice();
    //
    // Insets insets =
    // Toolkit.getDefaultToolkit().getScreenInsets(screen.getDefaultConfiguration());
    // if (bounds.contains(MouseInfo.getPointerInfo().getLocation())) {
    // return (new Point((int) (bounds.x + bounds.getWidth() -
    // frame.getWidth() - 20 - insets.right), (int) (bounds.y +
    // bounds.getHeight() - frame.getHeight() - 20 - insets.bottom))); }
    //
    // }
    // final Dimension screenSize =
    // Toolkit.getDefaultToolkit().getScreenSize();
    // return (new Point((int) (screenSize.getWidth() - frame.getWidth() -
    // 20), (int) (screenSize.getHeight() - frame.getHeight() - 60)));
    // } else {
    // return SwingUtils.getCenter(frame.getParent(), frame);
    // }

  }
Exemplo n.º 25
0
  public static void setToplevelLocation(
      Window toplevel, Component component, int relativePosition) {

    Rectangle compBounds = component.getBounds();

    // Convert component location to screen coordinates
    Point p = new Point();
    SwingUtilities.convertPointToScreen(p, component);

    int x;
    int y;

    // Set frame location to be centered on panel
    switch (relativePosition) {
      case SwingConstants.NORTH:
        {
          x = (p.x + (compBounds.width / 2)) - (toplevel.getWidth() / 2);
          y = p.y - toplevel.getHeight();
          break;
        }
      case SwingConstants.EAST:
        {
          x = p.x + compBounds.width;
          y = (p.y + (compBounds.height / 2)) - (toplevel.getHeight() / 2);
          break;
        }
      case SwingConstants.SOUTH:
        {
          x = (p.x + (compBounds.width / 2)) - (toplevel.getWidth() / 2);
          y = p.y + compBounds.height;
          break;
        }
      case SwingConstants.WEST:
        {
          x = p.x - toplevel.getWidth();
          y = (p.y + (compBounds.height / 2)) - (toplevel.getHeight() / 2);
          break;
        }
      case SwingConstants.NORTH_EAST:
        {
          x = p.x + compBounds.width;
          y = p.y - toplevel.getHeight();
          break;
        }
      case SwingConstants.NORTH_WEST:
        {
          x = p.x - toplevel.getWidth();
          y = p.y - toplevel.getHeight();
          break;
        }
      case SwingConstants.SOUTH_EAST:
        {
          x = p.x + compBounds.width;
          y = p.y + compBounds.height;
          break;
        }
      case SwingConstants.SOUTH_WEST:
        {
          x = p.x - toplevel.getWidth();
          y = p.y + compBounds.height;
          break;
        }
      default:
      case SwingConstants.CENTER:
        {
          x = (p.x + (compBounds.width / 2)) - (toplevel.getWidth() / 2);
          y = (p.y + (compBounds.height / 2)) - (toplevel.getHeight() / 2);
        }
    }
    toplevel.setLocation(x, y);
  }
Exemplo n.º 26
0
  /**
   * @param isLotsOfFastOutput use 'true' if you expect millions of lines of quickly produced
   *     output, ex. CLI -> "locate /"
   * @param dialogTitle non-HTML
   * @param cliable the port command thread to .start()
   * @param resultCodeListenable permits intelligence regarding failed port CLI commands, can be
   *     'null'
   */
  private JDialog_ProcessStream(
      final boolean isLotsOfFastOutput,
      final String dialogTitle,
      final Cliable cliable,
      final OneArgumentListenable<Integer> resultCodeListenable) {
    super(
        TheUiHolder.INSTANCE.getMainFrame() // stay on top
        ,
        dialogTitle,
        ModalityType.APPLICATION_MODAL);

    this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); // required
    this.setUndecorated(_IS_UI_IMMOBILE);
    this.setResizable(_IS_UI_IMMOBILE == false);
    ((JPanel) this.getContentPane())
        .setBorder(BorderFactory.createEmptyBorder(10, 10, 5, 10)); // T L B R

    final Window parent = this.getOwner();
    this.setLocation(parent.getX(), parent.getY());
    this.setSize(parent.getWidth(), parent.getHeight());

    final JList jList = new JList();
    jList.setFont(new Font(Font.MONOSPACED, Font.BOLD, 12));
    jList.setForeground(Color.GREEN.brighter());
    jList.setBackground(Color.BLACK);
    jList.setLayoutOrientation(JList.VERTICAL);
    jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jList.setVisibleRowCount(-1); // all

    final AbstractButton ab_Cancel = FocusedButtonFactory.create("Cancel", "");
    ab_Cancel.setEnabled(false);

    final JProgressBar jProgress = new JProgressBar();
    jProgress.setIndeterminate(true);

    // console
    final Listener listener =
        (isLotsOfFastOutput == true)
            ? new LateListening(this, jList, jProgress, ab_Cancel, resultCodeListenable)
            : new LiveListening(this, jList, jProgress, ab_Cancel, resultCodeListenable);

    //        try
    //        {   // try-catch to keep AWT thread alive for proper UI recovery

    final Thread runningThread = cliable.provideExecutingCommandLineInterfaceThread(listener);
    if (runningThread != null) {
      final JPanel southPanel = new JPanel(new GridLayout(1, 0));
      southPanel.add(jProgress);
      southPanel.add(ab_Cancel);

      final JScrollPane jsp =
          JScrollPaneFactory_.create(jList, EScrollPolicy.VERT_AS_NEEDED__HORIZ_NONE);

      // assemble rest of gui in this AWT thread
      this.add(Box.createHorizontalStrut(800), BorderLayout.NORTH);
      this.add(Box.createVerticalStrut(600), BorderLayout.EAST);
      this.add(jsp, BorderLayout.CENTER);
      this.add(southPanel, BorderLayout.SOUTH);

      // not working correctly to Cancel cli
      //        ab.addActionListener( new ActionListener() // anonymous class
      //                {   @Override public void actionPerformed( ActionEvent e )
      //                    {   thread.interrupt();
      //                        try
      //                        {   // Cancel
      //                            thread.join( 2000 );
      //                        }
      //                        catch( InterruptedException ex )
      //                        {}
      //                    }
      //                } );
    } else { // no Ports binary to run
      this.dispose();
    }

    //        }
    //        catch( Exception ex )
    //        {
    //            ex.printStackTrace();
    //        }
  }