public void mousePressed(java.awt.event.MouseEvent e) {
      isClick = true;
      JButton b = (JButton) e.getSource();
      // check to see if the target button can be moved
      if (!solved && check(buttons.indexOf(b))) {
        // hide the target button
        b.setVisible(false);

        // Figure out the bounds of the areas where source
        // and target buttons are located
        int menuOffset = getJMenuBar().getHeight();
        dragSourceArea = b.getBounds();
        dragTargetArea = ((JButton) buttons.get(hiddenIndex)).getBounds();
        dragSourceArea.translate(0, menuOffset);
        dragTargetArea.translate(0, menuOffset);

        // setup the bounds of the panel to limit the locations on the drag
        // layer
        panelArea = new Rectangle(0, menuOffset, getJPanel().getWidth(), getJPanel().getHeight());

        // Setup and show the drag button on the upper layer
        getDragButton().setText(b.getText());
        getDragButton().setBounds(dragSourceArea);
        getDragButton().setVisible(true);

        // Offset when repositioning the drag button later
        cursorOffset = new Point(e.getX(), e.getY());
      }
    }
Example #2
0
    @Override
    public void actionPerformed(ActionEvent e) {
      JPopupMenu menu = new JPopupMenu();
      for (HideableButton b : buttons) {
        final HideableButton t = b;
        menu.add(
            new JCheckBoxMenuItem(
                new AbstractAction() {
                  {
                    putValue(NAME, t.getActionName());
                    putValue(SMALL_ICON, t.getIcon());
                    putValue(SELECTED_KEY, t.isButtonVisible());
                    putValue(SHORT_DESCRIPTION, tr("Hide or show this toggle button"));
                  }

                  @Override
                  public void actionPerformed(ActionEvent e) {
                    if ((Boolean) getValue(SELECTED_KEY)) {
                      t.showButton();
                    } else {
                      t.hideButton();
                    }
                    validateToolBarsVisibility();
                  }
                }));
      }
      Rectangle bounds = button.getBounds();
      menu.show(button, bounds.x + bounds.width, 0);
    }
Example #3
0
 private void moveMousePointerOnButton(final JButton button) {
   Application application = ApplicationManager.getApplication();
   if (application != null && application.hasComponent(UISettings.class)) {
     if (button != null && UISettings.getInstance().MOVE_MOUSE_ON_DEFAULT_BUTTON) {
       Point p = button.getLocationOnScreen();
       Rectangle r = button.getBounds();
       try {
         Robot robot = new Robot();
         robot.mouseMove(p.x + r.width / 2, p.y + r.height / 2);
       } catch (AWTException e) {
         LOG.warn(e);
       }
     }
   }
 }
 static void repaintTest() {
   try {
     SwingUtilities.invokeAndWait(
         new Runnable() {
           public void run() {
             test = new JButton();
             test.setSize(100, 100);
           }
         });
   } catch (Exception e) {
     e.printStackTrace();
   }
   // repaint(Rectangle) should be ok
   test.repaint(test.getBounds());
   test.repaint(0, 0, 100, 100);
   test.repaint();
 }
  /**
   * Show the popup under the button
   *
   * @param prev if true, the popup is show under the previous button
   */
  private void showPopup(boolean prev) {
    popup.removeAll();
    if (prev) {
      for (int i = position - 1; i >= 0; i--) {
        JMenuItem item = new JMenuItem(history.get(i));
        final int j = i;
        item.addActionListener(
            new CommonCallBack(null) {
              @Override
              public void callBack() {
                ScilabFileBrowserHistory.this.stt.setBaseDir(history.get(j), false);
                chDir(history.get(j));
                setPositionInHistory(j);
              }
            });
        popup.add(item);
      }
    } else {
      for (int i = position + 1; i < history.size(); i++) {
        JMenuItem item = new JMenuItem(history.get(i));
        final int j = i;
        item.addActionListener(
            new CommonCallBack(null) {
              @Override
              public void callBack() {
                ScilabFileBrowserHistory.this.stt.setBaseDir(history.get(j), false);
                chDir(history.get(j));
                setPositionInHistory(j);
              }
            });
        popup.add(item);
      }
    }
    popup.pack();

    JButton button;
    if (prev) {
      button = previous;
    } else {
      button = next;
    }

    popup.show(button, 0, button.getBounds(null).height);
  }
Example #6
0
  public void focusGained(FocusEvent e) {
    JButton trigger = null;

    try {
      trigger = (JButton) e.getSource();
    } catch (ClassCastException ex) {
      return;
    }

    if (expanded) {
      vp.scrollRectToVisible(trigger.getBounds());
    } else {
      vp.scrollRectToVisible(this.getBounds());
    }

    trigger.setBorderPainted(true);
    trigger.invalidate();
    repaint();
  }
  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);
  }
Example #8
0
  @Override
  public void actionPerformed(ActionEvent ae) {
    ViajesEnt ViajesE = new ViajesEnt();
    ViajesNg ViajesN = new ViajesNg();
    if (ae.getSource() == jbtnListar) {
      LimpiarCampos();
      pnDatos.setVisible(true);
      jpBotones.setVisible(false);
      jpError.setVisible(false);
      vaciar();
      llenarDatos();
    }
    if (ae.getSource() == jbtnBuscar) {
      LimpiarCampos();
      String Codigo;
      Codigo = jtxtCodigo.getText();
      if (Codigo.trim().length() != 0) {
        ViajesE = ViajesN.buscarViajeCodigo(Codigo);
        if (ViajesE != null) {
          jtxtCodigo.setText(ViajesE.getCodigo());
          jcbDestino.setSelectedItem(ViajesE.getDestino());
          jcbOrigen.setSelectedItem(ViajesE.getOrigen());
          jtxtPrecio.setText(ViajesE.getPrecio());
          jcbEstado.setSelectedItem(ViajesE.getEstado());
          jtxtCodigo.setFocusable(false);
          jbtnBuscar.setVisible(false);
          jbtnActualizar.setVisible(true);
          if (jbtnActualizar.getBounds().x == 0) {
            jbtnListar.setBounds(0, 0, 350, 60);
            jbtnLimpiar.setBounds(350, 0, 350, 60);
          }
        } else {
          Toolkit.getDefaultToolkit().beep();
          jpError.setBackground(new Color(237, 28, 36));
          jlbValidar.setText("El viaje no se ha encontrado");
        }
      } else {
        Toolkit.getDefaultToolkit().beep();
        jpError.setBackground(new Color(237, 28, 36));
        jlbValidar.setText("Ingrese el Código");
        jtxtCodigo.setBorder(BorderFactory.createLineBorder(Color.RED, 1));
      }
    }

    if (ae.getSource() == jbtnActualizar) {
      if (jtxtPrecio.getText().trim().length() == 0) {
        Toolkit.getDefaultToolkit().beep();
        jpError.setBackground(new Color(237, 28, 36));
        jlbValidar.setText("Ingrese los campos en rojo");
        jtxtPrecio.setBorder(BorderFactory.createLineBorder(Color.RED, 1));
        return;
      } else {
        jtxtPrecio.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
      }
      try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
      } catch (Exception ex) {
        System.err.println(ex);
      }
      int option =
          JOptionPane.showConfirmDialog(
              this,
              "¿Está seguro que desea actualizar el viaje?",
              "Airline Travel",
              JOptionPane.YES_NO_OPTION,
              JOptionPane.QUESTION_MESSAGE);
      try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
      } catch (Exception ex) {
        ex.printStackTrace();
      }
      if (option == JOptionPane.YES_OPTION) {
        if (jtxtCodigo.getText().trim().length() > 0) {
          ViajesE.setCodigo(jtxtCodigo.getText());
        }

        ViajesE.setOrigen((String) jcbOrigen.getSelectedItem());
        ViajesE.setDestino((String) jcbDestino.getSelectedItem());

        if (jtxtPrecio.getText().trim().length() > 0) {
          ViajesE.setPrecio(jtxtPrecio.getText());
        }

        ViajesE.setEstado((String) jcbEstado.getSelectedItem());

        boolean respuestau = ViajesN.modificarViaje(ViajesE);
        if (respuestau) {
          LimpiarCampos();
          jpError.setBackground(new Color(0, 154, 225));
          jlbValidar.setText("Se ha actualizado el viaje");
        }
      }
    }

    if (ae.getSource() == jbtnLimpiar) {
      LimpiarCampos();
      VaciarCampos();
      jtxtCodigo.setFocusable(true);
      jbtnBuscar.setVisible(true);
      jbtnActualizar.setVisible(false);
      if (jbtnActualizar.getBounds().x == 0) {
        jbtnListar.setBounds(0, 0, 233, 60);
        jbtnLimpiar.setBounds(467, 0, 233, 60);
      }
    }
  }