Esempio n. 1
1
 public int getTitleHeight(Component c) {
   int th = 21;
   int fh = getBorderInsets(c).top + getBorderInsets(c).bottom;
   if (c instanceof JDialog) {
     JDialog dialog = (JDialog) c;
     th = dialog.getSize().height - dialog.getContentPane().getSize().height - fh - 1;
     if (dialog.getJMenuBar() != null) {
       th -= dialog.getJMenuBar().getSize().height;
     }
   } else if (c instanceof JInternalFrame) {
     JInternalFrame frame = (JInternalFrame) c;
     th = frame.getSize().height - frame.getRootPane().getSize().height - fh - 1;
     if (frame.getJMenuBar() != null) {
       th -= frame.getJMenuBar().getSize().height;
     }
   } else if (c instanceof JRootPane) {
     JRootPane jp = (JRootPane) c;
     if (jp.getParent() instanceof JFrame) {
       JFrame frame = (JFrame) c.getParent();
       th = frame.getSize().height - frame.getContentPane().getSize().height - fh - 1;
       if (frame.getJMenuBar() != null) {
         th -= frame.getJMenuBar().getSize().height;
       }
     } else if (jp.getParent() instanceof JDialog) {
       JDialog dialog = (JDialog) c.getParent();
       th = dialog.getSize().height - dialog.getContentPane().getSize().height - fh - 1;
       if (dialog.getJMenuBar() != null) {
         th -= dialog.getJMenuBar().getSize().height;
       }
     }
   }
   return th;
 }
 private void menuItemNuevoActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_menuItemNuevoActionPerformed
   // TODO add your handling code here:
   JInternalFrame truck = new truckWindow();
   truck.setLocation(
       (this.getSize().width - truck.getSize().width) / 2,
       (this.getSize().height - truck.getSize().height) / 2);
   this.add(truck);
   truck.setVisible(true);
 } // GEN-LAST:event_menuItemNuevoActionPerformed
 private void mItemUserActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_mItemUserActionPerformed
   // TODO add your handling code here:
   JInternalFrame user = new userWindow();
   user.setLocation(
       (this.getSize().width - user.getSize().width) / 2,
       (this.getSize().height - user.getSize().height) / 2);
   this.add(user);
   user.setVisible(true);
 } // GEN-LAST:event_mItemUserActionPerformed
 private void mItemReportHistoryActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_mItemReportHistoryActionPerformed
   // TODO add your handling code here:
   JInternalFrame reportHistory = new reportHistoryWindow();
   reportHistory.setLocation(
       (this.getSize().width - reportHistory.getSize().width) / 2,
       (this.getSize().height - reportHistory.getSize().height) / 2);
   this.add(reportHistory);
   reportHistory.setVisible(true);
 } // GEN-LAST:event_mItemReportHistoryActionPerformed
 private void mItemProductActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_mItemProductActionPerformed
   // TODO add your handling code here:
   JInternalFrame product = new productWindow();
   product.setLocation(
       (this.getSize().width - product.getSize().width) / 2,
       (this.getSize().height - product.getSize().height) / 2);
   this.add(product);
   product.setVisible(true);
 } // GEN-LAST:event_mItemProductActionPerformed
 private void mItemGasPriceReportActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_mItemGasPriceReportActionPerformed
   // TODO add your handling code here:
   JInternalFrame gasPriceReport = new gasPriceReportWindow();
   gasPriceReport.setLocation(
       (this.getSize().width - gasPriceReport.getSize().width) / 2,
       (this.getSize().height - gasPriceReport.getSize().height) / 2);
   this.add(gasPriceReport);
   gasPriceReport.setVisible(true);
 } // GEN-LAST:event_mItemGasPriceReportActionPerformed
 private void mItemEditUsersActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_mItemEditUsersActionPerformed
   // TODO add your handling code here:
   JInternalFrame editUsers = new editUsersPassWindow();
   editUsers.setLocation(
       (this.getSize().width - editUsers.getSize().width) / 2,
       (this.getSize().height - editUsers.getSize().height) / 2);
   this.add(editUsers);
   editUsers.setVisible(true);
 } // GEN-LAST:event_mItemEditUsersActionPerformed
 private void mItemClenteActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_mItemClenteActionPerformed
   // TODO add your handling code here:
   JInternalFrame clientView = new clientWindow("Clientes");
   clientView.setLocation(
       (this.getSize().width - clientView.getSize().width) / 2,
       (this.getSize().height - clientView.getSize().height) / 2);
   this.add(clientView);
   clientView.setVisible(true);
 } // GEN-LAST:event_mItemClenteActionPerformed
 private void mItemRealTimeActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_mItemRealTimeActionPerformed
   // TODO add your handling code here:
   JInternalFrame mapView = new realTimeMapWindow();
   mapView.setLocation(
       (this.getSize().width - mapView.getSize().width) / 2,
       (this.getSize().height - mapView.getSize().height) / 2);
   this.add(mapView);
   mapView.setVisible(true);
 } // GEN-LAST:event_mItemRealTimeActionPerformed
  private void mItemCargaDatosActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_mItemCargaDatosActionPerformed
    // TODO add your handling code here:
    JInternalFrame batchLoad = new loadWindow("Nueva Carga de Datos");

    batchLoad.setLocation(
        (this.getSize().width - batchLoad.getSize().width) / 2,
        (this.getSize().height - batchLoad.getSize().height) / 2);
    this.add(batchLoad);
    batchLoad.setVisible(true);
  } // GEN-LAST:event_mItemCargaDatosActionPerformed
Esempio n. 11
0
 /**
  * Resets the triangle graphic to the fixed default location
  *
  * @author susiefu
  */
 protected void resetTriangleToDefault() {
   int tribase =
       (Math.round((Math.min(editFrame.getSize().width, editFrame.getSize().height))) / 10 > 15)
           ? Math.round((Math.min(editFrame.getSize().width, editFrame.getSize().height))) / 10
           : 15; // How wide
   // the base
   // of the
   // triangle
   // is
   triangleFrame.setSize(tribase, TRIANGLE_DEFAULT_HEIGHT);
   ((Triangle) triangleFrame.getContentPane())
       .setGeometry("SE", 0, tribase, TRIANGLE_DEFAULT_HEIGHT, tribase);
 }
Esempio n. 12
0
 public void saveFrameConfiguration() {
   String frameTitle = jif.getTitle();
   pref.putInt(frameTitle + posXPreferenceKey, jif.getX());
   pref.putInt(frameTitle + posYPreferenceKey, jif.getY());
   pref.putInt(frameTitle + sizeXPreferenceKey, jif.getSize().width);
   pref.putInt(frameTitle + sizeYPreferenceKey, jif.getSize().height);
   pref.putBoolean(frameTitle + isVisiblePreferenceKey, jif.isVisible());
 }
 private void agregarAPanel(JInternalFrame internal, int ancho, int largo) {
   if (!this.desktopPane.isAncestorOf(internal)) {
     this.desktopPane.add(internal);
     internal.setSize(ancho, largo);
     internal.setVisible(true);
     Dimension desktopSize = desktopPane.getSize();
     Dimension jInternalFrameSize = internal.getSize();
     internal.setLocation(
         (desktopSize.width - jInternalFrameSize.width) / 2,
         (desktopSize.height - jInternalFrameSize.height) / 2);
   }
 }
Esempio n. 14
0
  /**
   * Sets the location for the 3 internal frames
   *
   * @author susiefu
   * @param direction
   * @param tilt
   * @param x
   * @param y
   */
  protected void setFrameGeometry(String direction, int tilt, int x, int y) {

    Dimension editwindowsize = editFrame.getSize();
    Dimension trisize = triangleFrame.getSize();
    int tribase =
        (Math.round((Math.min(editwindowsize.width, editwindowsize.height))) / 10 > 15)
            ? Math.round((Math.min(editwindowsize.width, editwindowsize.height))) / 10
            : 15; // How
    // wide
    // the
    // base
    // of
    // the
    // triangle
    // is
    int fudge = 1;

    // For the different directions
    if (direction == "SE") { // Default location
      if (tilt == 0) {
        triangleFrame.setLocation(x + tribase - trisize.width, y + 24 - trisize.height + fudge);
      } else {
        triangleFrame.setLocation(x, y + 24 - trisize.height + fudge);
      }

    } else if (direction == "S") { // SAME AS "SE" DIRECTION
      if (tilt == 0) {
        triangleFrame.setLocation(x + tribase - trisize.width, y + 24 - trisize.height + fudge);
      } else {
        triangleFrame.setLocation(x, y + 24 - trisize.height + fudge);
      }

    } else if (direction == "W") {
      if (tilt == 0) {
        triangleFrame.setLocation(
            x + editwindowsize.width - fudge, y + 24 - trisize.height + tribase);
      } else {
        triangleFrame.setLocation(x + editwindowsize.width - fudge, y + 24);
      }

    } else if (direction == "NW") {
      if (tilt == 0) {
        triangleFrame.setLocation(
            x + editwindowsize.width - trisize.width, y + 24 + editwindowsize.height - 2 * fudge);
      } else {
        triangleFrame.setLocation(
            x + editwindowsize.width - tribase, y + 25 + editwindowsize.height - 2 * fudge);
      }

    } else if (direction == "N") {
      if (tilt == 0) {
        triangleFrame.setLocation(
            x - trisize.width + tribase, y + 24 + editwindowsize.height - 2 * fudge);
      } else {
        triangleFrame.setLocation(x, y + 24 + editwindowsize.height - 2 * fudge);
      }

    } else if (direction == "E") {
      if (tilt == 0) { // Pointing up
        triangleFrame.setLocation(x - trisize.width + fudge, y + 24 - trisize.height + tribase);
      } else {
        triangleFrame.setLocation(x - trisize.width + fudge, y + 24);
      }

    } else if (direction == "NONE") {
      if (tilt == 0) {
        triangleFrame.setLocation(x + tribase - trisize.width, y + 24 - trisize.height + fudge);
      } else {
        triangleFrame.setLocation(x, y + 24 - trisize.height + fudge);
      }
    }
    editFrame.setLocation(x, y + 24);
    buttonFrame.setLocation(
        x + editwindowsize.width - buttonFrame.getWidth() + fudge,
        y + buttonFrame.getHeight() / 2 + fudge * 2);
  }
Esempio n. 15
0
  /**
   * Will update the triangle given the absolute location of the center of the moveButton.
   *
   * @author achang, adapted from code by susiefu
   */
  public void updateTriangle(int x, int y) {

    Point realLocation = new Point(x, y);
    Dimension editFrameSize = editFrame.getSize();
    Point editFrameLocation = editFrame.getLocation();
    //        new Point(realLocation.x - editFrameSize.width + buttonFrame.getWidth()*3/4,
    //        realLocation.y + buttonFrame.getHeight()/2);
    int X_FUDGE = 15;
    int Y_FUDGE = 5;
    int tribase =
        (Math.round((Math.min(editFrameSize.width, editFrameSize.height))) / 10 > TRIANGLE_BASE)
            ? Math.round((Math.min(editFrameSize.width, editFrameSize.height))) / 10
            : TRIANGLE_BASE;
    int tilt = -1;
    int cellX = getCellCenter().x;
    int cellY = getCellCenter().y;
    //    System.out.println("kCW >> updateTriangle >> cellCenter="+getCellCenter());
    int width, height;

    if (editFrameLocation.x + editFrameSize.width / 2 >= cellX
        && editFrameLocation.x - X_FUDGE <= cellX
        && editFrameLocation.y >= cellY) { // Right , bottom (DEFAULT)
      direction = "SE";
      height = editFrameLocation.y - cellY;
      if (editFrameLocation.x >= cellX) {
        tilt = 0; // Pointing left
        width = Math.abs(editFrameLocation.x - cellX) + tribase;
      } else {
        tilt = 1; // Pointing right
        if (Math.abs(editFrameLocation.x - cellX) > tribase) {
          width = Math.abs(editFrameLocation.x - cellX);
        } else {
          width = tribase;
        }
      }
    } else if (editFrameLocation.x + editFrameSize.width / 2 < cellX
        && editFrameLocation.x + editFrameSize.width > cellX
        && editFrameLocation.y >= cellY + Y_FUDGE) { // Middle,
      // bottom
      direction = "S"; // SAME CODE AS "SE" DIRECTION BECAUSE OF OVERLAPPING
      // OF BUTTONS AND TRIANGLE
      height = editFrameLocation.y - cellY;
      if (editFrameLocation.x >= cellX) {
        tilt = 0; // Pointing left
        width = Math.abs(editFrameLocation.x - cellX) + tribase;
      } else {
        tilt = 1; // Pointing right
        if (Math.abs(editFrameLocation.x - cellX) > tribase) {
          width = Math.abs(editFrameLocation.x - cellX);
        } else {
          width = tribase;
        }
      }

    } else if (editFrameLocation.x + editFrameSize.width <= cellX
            && editFrameLocation.y + editFrameSize.height + 3 * Y_FUDGE >= cellY
        || editFrameLocation.x + 3 * editFrameSize.width / 2 < cellX
            && editFrameLocation.y + editFrameSize.height < cellY) { // Left, middle

      direction = "W";
      width = Math.abs(editFrameLocation.x + editFrameSize.width - cellX);
      if (editFrameLocation.y >= cellY) {
        tilt = 0; // Pointing up
        height = Math.abs(editFrameLocation.y - cellY) + tribase;
      } else {
        tilt = 1; // Pointing down
        if (Math.abs(editFrameLocation.y - cellY) > tribase) {
          height = Math.abs(editFrameLocation.y - cellY);
        } else {
          height = tribase;
        }
      }

    } else if (editFrameLocation.x + editFrameSize.width / 2 <= cellX
        && editFrameLocation.x + 3 * editFrameSize.width / 2 >= cellX
        && editFrameLocation.y + editFrameSize.height + 3 * Y_FUDGE < cellY) { // Left,
      // top
      direction = "NW";
      height = Math.abs(editFrameLocation.y + editFrameSize.height - cellY);
      if (editFrameLocation.x + editFrameSize.width > cellX) {
        tilt = 0; // Pointing left
        if (Math.abs(editFrameLocation.x + editFrameSize.width - cellX) > tribase) {
          width = Math.abs(editFrameLocation.x + editFrameSize.width - cellX);
        } else {
          width = tribase;
        }

      } else {
        tilt = 1; // Pointing right
        width = Math.abs(editFrameLocation.x + editFrameSize.width - cellX) + tribase;
      }

    } else if (editFrameLocation.x + editFrameSize.width / 2 > cellX
        && editFrameLocation.x - editFrameSize.width / 2 <= cellX
        && editFrameLocation.y + editFrameSize.height + Y_FUDGE < cellY) { // Middle,
      // top
      direction = "N";
      height = Math.abs(editFrameLocation.y + editFrameSize.height - cellY);
      if (editFrameLocation.x >= cellX) {
        tilt = 0; // Pointing left
        width = Math.abs(editFrameLocation.x - cellX) + tribase;
      } else {
        tilt = 1; // Pointing right
        if (Math.abs(editFrameLocation.x - cellX) > tribase) {
          width = Math.abs(editFrameLocation.x - cellX);
        } else {
          width = tribase;
        }
      }

    } else if (editFrameLocation.x - X_FUDGE > cellX
        || editFrameLocation.y - editFrameSize.height / 2 >= cellY
            && editFrameLocation.x - X_FUDGE <= cellX) { // Right, middle
      direction = "E";
      width = Math.abs(editFrameLocation.x - cellX);
      if (editFrameLocation.y >= cellY) {
        tilt = 0; // Pointing up
        height = Math.abs(editFrameLocation.y - cellY) + tribase;
      } else {
        tilt = 1; // Pointing down
        if (Math.abs(editFrameLocation.y - cellY) > tribase) {
          height = Math.abs(editFrameLocation.y - cellY);
        } else {
          height = tribase;
        }
      }

    } else {
      direction = "NONE";
      height = editFrameLocation.y - cellY;
      if (editFrameLocation.x >= cellX) {
        tilt = 0;
        width = Math.abs(editFrameLocation.x - cellX) + tribase;
      } else {
        tilt = 1;
        if (Math.abs(editFrameLocation.x - cellX) > tribase) {
          width = Math.abs(editFrameLocation.x - cellX);
        } else {
          width = tribase;
        }
      }
    }
    triangleFrame.setSize(width, height);
    ((Triangle) triangleFrame.getContentPane())
        .setGeometry(direction, tilt, width, height, tribase);
    setFrameGeometry(
        direction,
        tilt,
        realLocation.x - editFrameSize.width + buttonFrame.getWidth() * 3 / 4,
        realLocation.y - buttonFrame.getWidth() / 2);
  }
    public void actionPerformed(ActionEvent e) {
      JDesktopPane dp = (JDesktopPane) e.getSource();
      String key = getName();

      if (CLOSE == key || MAXIMIZE == key || MINIMIZE == key || RESTORE == key) {
        setState(dp, key);
      } else if (ESCAPE == key) {
        if (sourceFrame == dp.getSelectedFrame() && focusOwner != null) {
          focusOwner.requestFocus();
        }
        moving = false;
        resizing = false;
        sourceFrame = null;
        focusOwner = null;
      } else if (MOVE == key || RESIZE == key) {
        sourceFrame = dp.getSelectedFrame();
        if (sourceFrame == null) {
          return;
        }
        moving = (key == MOVE) ? true : false;
        resizing = (key == RESIZE) ? true : false;

        focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        if (!SwingUtilities.isDescendingFrom(focusOwner, sourceFrame)) {
          focusOwner = null;
        }
        sourceFrame.requestFocus();
      } else if (LEFT == key
          || RIGHT == key
          || UP == key
          || DOWN == key
          || SHRINK_RIGHT == key
          || SHRINK_LEFT == key
          || SHRINK_UP == key
          || SHRINK_DOWN == key) {
        JInternalFrame c = dp.getSelectedFrame();
        if (sourceFrame == null
            || c != sourceFrame
            || KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()
                != sourceFrame) {
          return;
        }
        Insets minOnScreenInsets = UIManager.getInsets("Desktop.minOnScreenInsets");
        Dimension size = c.getSize();
        Dimension minSize = c.getMinimumSize();
        int dpWidth = dp.getWidth();
        int dpHeight = dp.getHeight();
        int delta;
        Point loc = c.getLocation();
        if (LEFT == key) {
          if (moving) {
            c.setLocation(
                loc.x + size.width - MOVE_RESIZE_INCREMENT < minOnScreenInsets.right
                    ? -size.width + minOnScreenInsets.right
                    : loc.x - MOVE_RESIZE_INCREMENT,
                loc.y);
          } else if (resizing) {
            c.setLocation(loc.x - MOVE_RESIZE_INCREMENT, loc.y);
            c.setSize(size.width + MOVE_RESIZE_INCREMENT, size.height);
          }
        } else if (RIGHT == key) {
          if (moving) {
            c.setLocation(
                loc.x + MOVE_RESIZE_INCREMENT > dpWidth - minOnScreenInsets.left
                    ? dpWidth - minOnScreenInsets.left
                    : loc.x + MOVE_RESIZE_INCREMENT,
                loc.y);
          } else if (resizing) {
            c.setSize(size.width + MOVE_RESIZE_INCREMENT, size.height);
          }
        } else if (UP == key) {
          if (moving) {
            c.setLocation(
                loc.x,
                loc.y + size.height - MOVE_RESIZE_INCREMENT < minOnScreenInsets.bottom
                    ? -size.height + minOnScreenInsets.bottom
                    : loc.y - MOVE_RESIZE_INCREMENT);
          } else if (resizing) {
            c.setLocation(loc.x, loc.y - MOVE_RESIZE_INCREMENT);
            c.setSize(size.width, size.height + MOVE_RESIZE_INCREMENT);
          }
        } else if (DOWN == key) {
          if (moving) {
            c.setLocation(
                loc.x,
                loc.y + MOVE_RESIZE_INCREMENT > dpHeight - minOnScreenInsets.top
                    ? dpHeight - minOnScreenInsets.top
                    : loc.y + MOVE_RESIZE_INCREMENT);
          } else if (resizing) {
            c.setSize(size.width, size.height + MOVE_RESIZE_INCREMENT);
          }
        } else if (SHRINK_LEFT == key && resizing) {
          // Make sure we don't resize less than minimum size.
          if (minSize.width < (size.width - MOVE_RESIZE_INCREMENT)) {
            delta = MOVE_RESIZE_INCREMENT;
          } else {
            delta = size.width - minSize.width;
          }

          // Ensure that we keep the internal frame on the desktop.
          if (loc.x + size.width - delta < minOnScreenInsets.left) {
            delta = loc.x + size.width - minOnScreenInsets.left;
          }
          c.setSize(size.width - delta, size.height);
        } else if (SHRINK_RIGHT == key && resizing) {
          // Make sure we don't resize less than minimum size.
          if (minSize.width < (size.width - MOVE_RESIZE_INCREMENT)) {
            delta = MOVE_RESIZE_INCREMENT;
          } else {
            delta = size.width - minSize.width;
          }

          // Ensure that we keep the internal frame on the desktop.
          if (loc.x + delta > dpWidth - minOnScreenInsets.right) {
            delta = (dpWidth - minOnScreenInsets.right) - loc.x;
          }

          c.setLocation(loc.x + delta, loc.y);
          c.setSize(size.width - delta, size.height);
        } else if (SHRINK_UP == key && resizing) {
          // Make sure we don't resize less than minimum size.
          if (minSize.height < (size.height - MOVE_RESIZE_INCREMENT)) {
            delta = MOVE_RESIZE_INCREMENT;
          } else {
            delta = size.height - minSize.height;
          }

          // Ensure that we keep the internal frame on the desktop.
          if (loc.y + size.height - delta < minOnScreenInsets.bottom) {
            delta = loc.y + size.height - minOnScreenInsets.bottom;
          }

          c.setSize(size.width, size.height - delta);
        } else if (SHRINK_DOWN == key && resizing) {
          // Make sure we don't resize less than minimum size.
          if (minSize.height < (size.height - MOVE_RESIZE_INCREMENT)) {
            delta = MOVE_RESIZE_INCREMENT;
          } else {
            delta = size.height - minSize.height;
          }

          // Ensure that we keep the internal frame on the desktop.
          if (loc.y + delta > dpHeight - minOnScreenInsets.top) {
            delta = (dpHeight - minOnScreenInsets.top) - loc.y;
          }

          c.setLocation(loc.x, loc.y + delta);
          c.setSize(size.width, size.height - delta);
        }
      } else if (NEXT_FRAME == key || PREVIOUS_FRAME == key) {
        dp.selectFrame((key == NEXT_FRAME) ? true : false);
      } else if (NAVIGATE_NEXT == key || NAVIGATE_PREVIOUS == key) {
        boolean moveForward = true;
        if (NAVIGATE_PREVIOUS == key) {
          moveForward = false;
        }
        Container cycleRoot = dp.getFocusCycleRootAncestor();

        if (cycleRoot != null) {
          FocusTraversalPolicy policy = cycleRoot.getFocusTraversalPolicy();
          if (policy != null && policy instanceof SortingFocusTraversalPolicy) {
            SortingFocusTraversalPolicy sPolicy = (SortingFocusTraversalPolicy) policy;
            boolean idc = sPolicy.getImplicitDownCycleTraversal();
            try {
              sPolicy.setImplicitDownCycleTraversal(false);
              if (moveForward) {
                KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent(dp);
              } else {
                KeyboardFocusManager.getCurrentKeyboardFocusManager().focusPreviousComponent(dp);
              }
            } finally {
              sPolicy.setImplicitDownCycleTraversal(idc);
            }
          }
        }
      }
    }