Пример #1
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);
    }
  }
 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);
 }
Пример #3
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);
 }
 private boolean noIntersections(Rectangle bounds) {
   Window owner = SwingUtilities.getWindowAncestor(myComponent);
   Window popup = SwingUtilities.getWindowAncestor(myTipComponent);
   Window focus = WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow();
   if (focus == owner.getOwner()) {
     focus = null; // do not check intersection with parent
   }
   boolean focused = SystemInfo.isWindows || owner.isFocused();
   for (Window other : owner.getOwnedWindows()) {
     if (!focused && !SystemInfo.isWindows) {
       focused = other.isFocused();
     }
     if (popup != other
         && other.isVisible()
         && bounds.x + 10 >= other.getX()
         && bounds.intersects(other.getBounds())) {
       return false;
     }
     if (focus == other) {
       focus = null; // already checked
     }
   }
   return focused
       && (focus == owner || focus == null || !owner.getBounds().intersects(focus.getBounds()));
 }
Пример #5
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);
  }
Пример #6
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;
    }
  }
Пример #7
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();
  }
Пример #8
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);
 }
Пример #9
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);
  }
Пример #10
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();
    //        }
  }