Example #1
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);
       }
     }
   }
 }
  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 #3
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);
      }
    }
  }