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);
 }
Exemple #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);
 }
Exemple #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);
  }
Exemple #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);
    }
  }
Exemple #5
0
 // get width of window
 public int getWidth() {
   Window w = vc.getFullScreenWindow();
   if (w != null) {
     return w.getWidth();
   } else {
     return 0;
   }
 }
Exemple #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);
  }
Exemple #7
0
 private void setPositionRelativeToParent() {
   int width = myParent.getWidth();
   myWindow.setBounds(
       width / 2 - myController.SHEET_NC_WIDTH / 2 + myParent.getLocation().x,
       myParent.getInsets().top + myParent.getLocation().y,
       myController.SHEET_NC_WIDTH,
       myController.SHEET_NC_HEIGHT);
 }
    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));
      }
    }
    /**
     * 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;
    }
Exemple #10
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);
    }
  }
Exemple #11
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();
  }
Exemple #12
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);
  }
 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");
     }
   }
 }
  /**
   * 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);
  }
  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;
    }
  }
  @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();
  }
  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)));
  }
  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("");
    }
  }
Exemple #19
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();
   }
 }
 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);
 }
  /** 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());
  }
Exemple #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;
    }
  }
  public void paintComponent(Graphics g) {
    if (getFrame() != null) {
      setState(getFrame().getExtendedState());
    }
    JRootPane rootPane = getRootPane();
    Window window = getWindow();
    boolean leftToRight =
        (window == null)
            ? rootPane.getComponentOrientation().isLeftToRight()
            : window.getComponentOrientation().isLeftToRight();
    boolean isSelected = (window == null) ? true : window.isActive();
    int width = getWidth();
    int height = getHeight();

    Color background;
    Color foreground;
    Color darkShadow;

    if (isSelected) {
      background = UIUtil.getPanelBackground(); // myActiveBackground;
      foreground = myActiveForeground;
      darkShadow = Gray._73; // myActiveShadow;
    } else {
      background = UIUtil.getPanelBackground(); // myInactiveBackground;
      foreground = myInactiveForeground;
      darkShadow = myInactiveShadow;
    }

    g.setColor(background);
    g.fillRect(0, 0, width, height);

    // g.setColor(darkShadow);
    // g.drawLine(0, height - 1, width, height - 1);
    // g.drawLine(0, 0, 0, 0);
    // g.drawLine(width - 1, 0, width - 1, 0);

    int xOffset = leftToRight ? 5 : width - 5;

    if (getWindowDecorationStyle() == JRootPane.FRAME) {
      xOffset += leftToRight ? IMAGE_WIDTH + 5 : -IMAGE_WIDTH - 5;
    }

    String theTitle = getTitle();
    if (theTitle != null) {
      FontMetrics fm = SwingUtilities2.getFontMetrics(rootPane, g);

      g.setColor(foreground);

      int yOffset = ((height - fm.getHeight()) / 2) + fm.getAscent();

      Rectangle rect = new Rectangle(0, 0, 0, 0);
      if (myIconifyButton != null && myIconifyButton.getParent() != null) {
        rect = myIconifyButton.getBounds();
      }
      int titleW;

      if (leftToRight) {
        if (rect.x == 0) {
          rect.x = window.getWidth() - window.getInsets().right - 2;
        }
        titleW = rect.x - xOffset - 4;
        theTitle = SwingUtilities2.clipStringIfNecessary(rootPane, fm, theTitle, titleW);
      } else {
        titleW = xOffset - rect.x - rect.width - 4;
        theTitle = SwingUtilities2.clipStringIfNecessary(rootPane, fm, theTitle, titleW);
        xOffset -= SwingUtilities2.stringWidth(rootPane, fm, theTitle);
      }
      int titleLength = SwingUtilities2.stringWidth(rootPane, fm, theTitle);
      if (myIdeMenu == null) {
        SwingUtilities2.drawString(rootPane, g, theTitle, xOffset, yOffset);
        xOffset += leftToRight ? titleLength + 5 : -5;
      }
    }

    int w = width;
    int h = height;
    h--;
    g.setColor(UIManager.getColor("MenuBar.darcula.borderColor"));
    g.drawLine(0, h, w, h);
    h--;
    g.setColor(UIManager.getColor("MenuBar.darcula.borderShadowColor"));
    g.drawLine(0, h, w, h);
  }
Exemple #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);
  }
  /*
   * (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);
    // }

  }
Exemple #27
0
 /*      */ public void paintComponent(Graphics paramGraphics) /*      */ {
   /*  687 */ if (getFrame() != null) {
     /*  688 */ setState(getFrame().getExtendedState());
     /*      */ }
   /*  690 */ JRootPane localJRootPane = getRootPane();
   /*  691 */ Window localWindow = getWindow();
   /*  692 */ boolean bool1 =
       localWindow == null
           ? localJRootPane.getComponentOrientation().isLeftToRight()
           : localWindow.getComponentOrientation().isLeftToRight();
   /*      */
   /*  695 */ boolean bool2 = localWindow == null ? true : localWindow.isActive();
   /*  696 */ int i = getWidth();
   /*  697 */ int j = getHeight();
   /*      */ Color localColor1;
   /*      */ Color localColor2;
   /*      */ Color localColor3;
   /*      */ MetalBumps localMetalBumps;
   /*  705 */ if (bool2) {
     /*  706 */ localColor1 = this.activeBackground;
     /*  707 */ localColor2 = this.activeForeground;
     /*  708 */ localColor3 = this.activeShadow;
     /*  709 */ localMetalBumps = this.activeBumps;
     /*      */ } else {
     /*  711 */ localColor1 = this.inactiveBackground;
     /*  712 */ localColor2 = this.inactiveForeground;
     /*  713 */ localColor3 = this.inactiveShadow;
     /*  714 */ localMetalBumps = this.inactiveBumps;
     /*      */ }
   /*      */
   /*  717 */ paramGraphics.setColor(localColor1);
   /*  718 */ paramGraphics.fillRect(0, 0, i, j);
   /*      */
   /*  720 */ paramGraphics.setColor(localColor3);
   /*  721 */ paramGraphics.drawLine(0, j - 1, i, j - 1);
   /*  722 */ paramGraphics.drawLine(0, 0, 0, 0);
   /*  723 */ paramGraphics.drawLine(i - 1, 0, i - 1, 0);
   /*      */
   /*  725 */ FontMetrics localFontMetrics1 = bool1 ? 5 : i - 5;
   /*      */
   /*  727 */ if (getWindowDecorationStyle() == 1) {
     /*  728 */ localFontMetrics1 += (bool1 ? 21 : -21);
     /*      */ }
   /*      */
   /*  731 */ String str = getTitle();
   /*      */ FontMetrics localFontMetrics2;
   /*      */ int m;
   /*  732 */ if (str != null) {
     /*  733 */ localFontMetrics2 = SwingUtilities2.getFontMetrics(localJRootPane, paramGraphics);
     /*      */
     /*  735 */ paramGraphics.setColor(localColor2);
     /*      */
     /*  737 */ m = (j - localFontMetrics2.getHeight()) / 2 + localFontMetrics2.getAscent();
     /*      */
     /*  739 */ Rectangle localRectangle = new Rectangle(0, 0, 0, 0);
     /*  740 */ if ((this.iconifyButton != null) && (this.iconifyButton.getParent() != null)) {
       /*  741 */ localRectangle = this.iconifyButton.getBounds();
       /*      */ }
     /*      */
     /*  745 */ if (bool1) {
       /*  746 */ if (localRectangle.x == 0) {
         /*  747 */ localRectangle.x =
             (localWindow.getWidth() - localWindow.getInsets().right - 2);
         /*      */ }
       /*  749 */ i1 = localRectangle.x - localFontMetrics1 - 4;
       /*  750 */ str =
           SwingUtilities2.clipStringIfNecessary(localJRootPane, localFontMetrics2, str, i1);
       /*      */ }
     /*      */ else {
       /*  753 */ i1 = localFontMetrics1 - localRectangle.x - localRectangle.width - 4;
       /*  754 */ str =
           SwingUtilities2.clipStringIfNecessary(localJRootPane, localFontMetrics2, str, i1);
       /*      */
       /*  756 */ localFontMetrics1 -=
           SwingUtilities2.stringWidth(localJRootPane, localFontMetrics2, str);
       /*      */ }
     /*      */
     /*  759 */ int i2 = SwingUtilities2.stringWidth(localJRootPane, localFontMetrics2, str);
     /*      */
     /*  761 */ SwingUtilities2.drawString(
         localJRootPane, paramGraphics, str, localFontMetrics1, m);
     /*      */
     /*  763 */ localFontMetrics1 += (bool1 ? i2 + 5 : -5);
     /*      */ }
   /*      */ int k;
   /*  768 */ if (bool1) {
     /*  769 */ m = i - this.buttonsWidth - localFontMetrics1 - 5;
     /*  770 */ localFontMetrics2 = localFontMetrics1;
     /*      */ } else {
     /*  772 */ m = localFontMetrics1 - this.buttonsWidth - 5;
     /*  773 */ k = this.buttonsWidth + 5;
     /*      */ }
   /*  775 */ int n = 3;
   /*  776 */ int i1 = getHeight() - 2 * n;
   /*  777 */ localMetalBumps.setBumpArea(m, i1);
   /*  778 */ localMetalBumps.paintIcon(this, paramGraphics, k, n);
   /*      */ }
  /**
   * @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();
    //        }
  }
 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);
 }