Beispiel #1
0
 private void componentAdded(Component comp) {
   comp.addKeyListener(keyHandler);
   if (comp instanceof Container) {
     Container cont = (Container) comp;
     cont.addContainerListener(this);
     Component[] comps = cont.getComponents();
     for (Component comp1 : comps) componentAdded(comp1);
   }
 }
Beispiel #2
0
 private Dimension getLayoutSize(Container parent, int hGap, boolean layout) {
   Insets insets = parent.getInsets();
   int lineMaxX = 0;
   int lineY = 0;
   int currentY = 0;
   int currentX = 0;
   int maxY = 0;
   int maxX = 0;
   int topMargin = 0;
   int leftMargin = 0;
   Dimension d;
   Component[] components = parent.getComponents();
   for (int i = 0; i < components.length; i++) {
     if (components[i] instanceof CPLabel) {
       topMargin = 20;
       leftMargin = 0;
       currentY = lineY;
       currentX = lineMaxX + hGap;
       lineMaxX = currentX;
     } else if (components[i] instanceof CPCheckBox) {
       topMargin = 0;
       leftMargin = 0;
     }
     if (components[i] instanceof CRLF) {
       lineY = maxY;
       lineMaxX = 0;
     } else {
       // It's not a CRLF, lay it out.
       d = components[i].getPreferredSize();
       if (layout) {
         components[i].setBounds(
             insets.left + leftMargin + currentX,
             insets.top + topMargin + currentY,
             d.width,
             d.height);
       }
       currentY += topMargin + d.height;
       lineMaxX = Math.max(lineMaxX, leftMargin + currentX + d.width);
       maxX = Math.max(maxX, lineMaxX);
       maxY = Math.max(maxY, topMargin + currentY + d.height);
     }
   }
   return new Dimension(insets.left + maxX + insets.right, insets.top + maxY + insets.bottom);
 }
    public Dimension minimumLayoutSize(Container c) {
      if (c != null) {
        Component[] children = c.getComponents();

        if (children != null && children.length > 0) {
          Dimension aSize;
          int numChildren = children.length;
          int height = 0;
          Insets cInsets = c.getInsets();
          int extraHeight = cInsets.top + cInsets.bottom;
          int extraWidth = cInsets.left + cInsets.right;

          if (syncAllWidths) {
            int maxWidth = 0;

            for (int counter = 0; counter < numChildren; counter++) {
              aSize = children[counter].getPreferredSize();
              height = Math.max(height, aSize.height);
              maxWidth = Math.max(maxWidth, aSize.width);
            }
            return new Dimension(
                extraWidth + (maxWidth * numChildren) + (numChildren - 1) * padding,
                extraHeight + height);
          } else {
            int totalWidth = 0;

            for (int counter = 0; counter < numChildren; counter++) {
              aSize = children[counter].getPreferredSize();
              height = Math.max(height, aSize.height);
              totalWidth += aSize.width;
            }
            totalWidth += ((numChildren - 1) * padding);
            return new Dimension(extraWidth + totalWidth, extraHeight + height);
          }
        }
      }
      return new Dimension(0, 0);
    }
    public void layoutContainer(Container container) {
      Component[] children = container.getComponents();

      if (children != null && children.length > 0) {
        int numChildren = children.length;
        Insets insets = container.getInsets();
        int maxWidth = 0;
        int maxHeight = 0;
        int totalButtonWidth = 0;
        int x = 0;
        int xOffset = 0;
        boolean ltr = container.getComponentOrientation().isLeftToRight();
        boolean reverse = (ltr) ? reverseButtons : !reverseButtons;

        for (int counter = 0; counter < numChildren; counter++) {
          Dimension pref = children[counter].getPreferredSize();
          maxWidth = Math.max(maxWidth, pref.width);
          maxHeight = Math.max(maxHeight, pref.height);
          totalButtonWidth += pref.width;
        }
        if (getSyncAllWidths()) {
          totalButtonWidth = maxWidth * numChildren;
        }
        totalButtonWidth += (numChildren - 1) * padding;

        switch (getOrientation(container)) {
          case SwingConstants.LEFT:
            x = insets.left;
            break;
          case SwingConstants.RIGHT:
            x = container.getWidth() - insets.right - totalButtonWidth;
            break;
          case SwingConstants.CENTER:
            if (getCentersChildren() || numChildren < 2) {
              x = (container.getWidth() - totalButtonWidth) / 2;
            } else {
              x = insets.left;
              if (getSyncAllWidths()) {
                xOffset =
                    (container.getWidth() - insets.left - insets.right - totalButtonWidth)
                            / (numChildren - 1)
                        + maxWidth;
              } else {
                xOffset =
                    (container.getWidth() - insets.left - insets.right - totalButtonWidth)
                        / (numChildren - 1);
              }
            }
            break;
        }

        for (int counter = 0; counter < numChildren; counter++) {
          int index = (reverse) ? numChildren - counter - 1 : counter;
          Dimension pref = children[index].getPreferredSize();

          if (getSyncAllWidths()) {
            children[index].setBounds(x, insets.top, maxWidth, maxHeight);
          } else {
            children[index].setBounds(x, insets.top, pref.width, pref.height);
          }
          if (xOffset != 0) {
            x += xOffset;
          } else {
            x += children[index].getWidth() + padding;
          }
        }
      }
    }
Beispiel #5
0
  private void jbInit() throws Exception {
    confirm = new JButton(ls.getString(16));
    cancel = new JButton(ls.getString(18));
    pauseRB = new JRadioButton(ls.getString(22));
    leftRB = new JRadioButton(ls.getString(13));
    rightRB = new JRadioButton(ls.getString(14));

    Container container = this.getContentPane();
    titledBorder1 = new TitledBorder(ls.getString(11));
    container.setLayout(null);
    leftL.setEditable(false);
    leftL.setBounds(new Rectangle(116, 24, 84, 20));
    leftL.setText(
        gameconfigure.getLeftKeyCode() + " " + KeyEvent.getKeyText(gameconfigure.getLeftKeyCode()));
    leftRB.setBounds(new Rectangle(5, 23, 97, 20));
    leftRB.addActionListener(new KeyOptionDialog_leftRB_actionAdapter(this));

    rightRB.setBounds(new Rectangle(5, 48, 97, 20));
    rightRB.addActionListener(new KeyOptionDialog_rightRB_actionAdapter(this));

    rightL.setText(
        gameconfigure.getRightKeyCode()
            + " "
            + KeyEvent.getKeyText(gameconfigure.getRightKeyCode()));
    rightL.setEditable(false);
    rightL.setBounds(new Rectangle(116, 49, 84, 20));

    confirm.setBounds(new Rectangle(110, 114, 85, 20));

    confirm.addActionListener(new KeyOptionDialog_confirm_actionAdapter(this));
    cancel.setBounds(new Rectangle(18, 114, 85, 20));
    cancel.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            cancel_actionPerformed(e);
          }
        });

    pauseRB.setBounds(new Rectangle(6, 74, 97, 20));
    pauseRB.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            pauseRB_actionPerformed(e);
          }
        });
    pauseL.setText(
        gameconfigure.getPausekeyCode()
            + " "
            + KeyEvent.getKeyText(gameconfigure.getPausekeyCode()));
    pauseL.setBounds(new Rectangle(117, 75, 84, 20));
    pauseL.setEditable(false);
    container.add(leftL, null);
    container.add(rightL, null);
    container.add(rightRB, null);
    container.add(leftRB, null);
    container.add(pauseL, null);
    container.add(confirm, null);
    container.add(cancel, null);
    container.add(pauseRB, null);
    keylistener =
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {

            switch (KeyOptionDialog.this.selecti) {
              case 1:
                leftL.setText(e.getKeyCode() + " " + e.getKeyText(e.getKeyCode()));
                gameconfigure.setLeftKeyCode(e.getKeyCode());
                break;
              case 2:
                rightL.setText(e.getKeyCode() + " " + e.getKeyText(e.getKeyCode()));
                gameconfigure.setRightKeyCode(e.getKeyCode());
                break;

              case 6:
                pauseL.setText(e.getKeyCode() + " " + e.getKeyText(e.getKeyCode()));
                gameconfigure.setPausekeyCode(e.getKeyCode());
                break;
            }
          }
        };

    Component[] com = container.getComponents();
    for (int i = 0; i < com.length; i++) {
      com[i].addKeyListener(keylistener);
    }
    buttonGroup.add(leftRB);
    buttonGroup.add(rightRB);
    buttonGroup.add(pauseRB);
  }