Ejemplo n.º 1
0
  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;

        if (syncAllWidths) {
          int maxWidth = getMinimumButtonWidth();

          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(
              maxWidth * numChildren + (numChildren - 1) * padding, extraHeight + height);
        }
        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(totalWidth, extraHeight + height);
      }
    }
    return new Dimension(0, 0);
  }
Ejemplo n.º 2
0
  /** Lays out the components. */
  public void layoutContainer(Container parent) {
    // get parent's components
    Component[] c = parent.getComponents();
    if (c.length < NumCols * NumRows) c = fillOut(c);

    // get preferred widths
    int[] pw = new int[NumCols];
    for (int i = 0; i < NumCols; i++) {
      pw[i] = c[i].getPreferredSize().width;
    }

    // get preferred heights
    int[] ph = new int[NumRows];
    for (int j = 0; j < NumRows; j++) {
      ph[j] = c[NumCols * j].getPreferredSize().height;
    }

    // lay out all components
    int sy = 0;
    for (int j = 0; j < NumRows; j++) {
      int sx = 0;
      for (int i = 0; i < NumCols; i++) {
        c[NumCols * j + i].setBounds(sx, sy, pw[i], ph[j]);
        sx += pw[i] + ColSpace;
      }
      sy += ph[j] + RowSpace;
    }
  }
 public void validacamposobrigatorio(Container container, String tabela) {
   conecta_oracle.executeSQL("select * from" + tabela + "where rownum = 1");
   Component components[] = container.getComponents();
   for (Component component : components) {
     if (component instanceof JTextField) {
       JTextField field = (JTextField) component;
       String nome = field.getName();
       String conteudo = field.getText();
       String text = field.getToolTipText();
       int chave = field.getColumns();
       try {
         int numcols = conecta_oracle.metaData.getColumnCount();
         for (int conta = 1; conta <= numcols; conta++) {
           String colsname = conecta_oracle.metaData.getColumnName(conta);
           int obrigatorio = conecta_oracle.metaData.isNullable(conta);
           if (conteudo.equals("") && obrigatorio == 0) {
             if (chave != 1) {
               JOptionPane.showMessageDialog(null, "Campo " + text + " Obrigatório");
               field.grabFocus();
               retorno = 1;
               return;
             }
           }
         }
       } catch (SQLException erro) {
         JOptionPane.showMessageDialog(null, erro);
       }
     }
   }
 }
Ejemplo n.º 4
0
 public Dimension preferredLayoutSize(Container parent) {
   return LayoutUtil.add(
       useSelectedComponentSize
           ? component == null ? new Dimension(0, 0) : component.getPreferredSize()
           : LayoutUtil.getMaxPreferredSize(parent.getComponents()),
       parent.getInsets());
 }
  public void habilitarCampo(Container cont, boolean ToF) {
    for (Object campo : cont.getComponents()) {
      if (campo instanceof JFormattedTextField) {
        ((JFormattedTextField) campo).setEnabled(ToF);
      }
      if (campo instanceof JComboBox) {
        if (((JComboBox) campo).getName() != "cbTipoBanco") {
          ((JComboBox) campo).setEnabled(ToF);
        }
      }
      if (campo instanceof JTextField) {
        if (((JTextField) campo).getName() != "tfCodigo") {
          ((JTextField) campo).setEnabled(ToF);
        }
      }

      //            if (campo instanceof JButton) {
      //                if (((JButton) campo).getText() != "Novo" || ((JButton) campo).getText() !=
      // "Fechar") {
      //                    ((JTextField) campo).setEnabled(ToF);
      //                }
      //
      //
      //
      //            }
    }
  }
Ejemplo n.º 6
0
 public static void setStarkRed(Container container) {
   Component[] components = container.getComponents();
   for (Component component : components) {
     if (component instanceof JLabel) {
       JLabel l = (JLabel) component;
       String text = l.getText();
       if (!text.endsWith("*")) {
         continue;
       }
       text =
           "<html>" + text.substring(0, text.length() - 1) + "<font color='red' size='5'>*</font>";
       l.setText(text);
     } else if (component instanceof Container) {
       if (component instanceof JPanel) {
         Border b = ((JPanel) component).getBorder();
         if (b instanceof TitledBorder) {
           TitledBorder tb = (TitledBorder) b;
           String text = tb.getTitle();
           if (text.endsWith("*")) {
             text =
                 "<html>"
                     + text.substring(0, text.length() - 1)
                     + "<font color='red' size='5'>*</font>";
             tb.setTitle(text);
           }
         }
       }
       setStarkRed((Container) component);
     }
   }
 }
Ejemplo n.º 7
0
 private void detachFromHierarchyOf(Container container) {
   container.removeContainerListener(this);
   Component[] components = container.getComponents();
   for (int i = 0; i < components.length; i++) {
     detachFrom(components[i]); // Will callback recursively any nested JPanels
   }
 }
Ejemplo n.º 8
0
  private void recursiveButtonSearch(Container container) {
    for (Component component : container.getComponents()) {
      if (component instanceof Container) {
        recursiveButtonSearch((Container) component);
      }
      if (component instanceof JButton) {
        JButton button = (JButton) component;
        String buttonText = button.getText();

        // Using end of button text to determine whether button shouild be disabled
        // then disable it.  This is because JEditorPane does not disable buttons
        // disabled in the form html
        if (buttonText.endsWith(":disabled")) {
          buttonText = buttonText.substring(0, buttonText.lastIndexOf(":disabled"));
          button.setText(buttonText);
          button.setEnabled(false);
        }

        String extension = FileUtils.getFileExtension(buttonText);
        if (!extension.isEmpty()) {
          Icon icon = iconManager.get().getIconForExtension(extension);
          button.setIcon(icon);
        }
      }
    }
  }
Ejemplo n.º 9
0
 private Dimension calcSizeWithRestriction(int width, Container target) {
   int h = 0;
   for (Component c : target.getComponents()) {
     ((PgmPanel) c).setWidth(width);
     h += c.getPreferredSize().height + SEPARATOR_THICKNESS;
   }
   return new Dimension(width, h);
 }
Ejemplo n.º 10
0
 protected boolean containerHasComponent(Container container, Component comp) {
   for (Component _comp : container.getComponents()) {
     if (_comp == comp) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 11
0
 private static void setEnabled(Container container, boolean enabled) {
   for (Component component : container.getComponents()) {
     component.setEnabled(enabled);
     if (component instanceof Container) {
       setEnabled((Container) component, enabled);
     }
   }
 }
 public static void habilitarPanel(Container panel, boolean valor) {
   panel.setEnabled(valor);
   for (Component componente : panel.getComponents()) {
     if (componente instanceof Container) {
       habilitarPanel((Container) componente, valor);
     }
   }
 }
Ejemplo n.º 13
0
 private Dimension calcSizeNoRestriction(Container target) {
   int w = 0;
   int h = 0;
   for (Component c : target.getComponents()) {
     w += c.getPreferredSize().width;
     h += c.getPreferredSize().height + SEPARATOR_THICKNESS;
   }
   return new Dimension(w, h);
 }
Ejemplo n.º 14
0
 void attachToHierarchyOf(Container container) {
   if (!Arrays.asList(container.getContainerListeners()).contains(this)) {
     container.addContainerListener(this);
   }
   Component[] components = container.getComponents();
   for (int i = 0; i < components.length; i++) {
     attachTo(components[i]); // Will recursively add any child components in
   }
 }
Ejemplo n.º 15
0
 public static void setContainerEnabled(Container container, boolean aFlag) {
   Component[] components = container.getComponents();
   for (Component component : components) {
     component.setEnabled(aFlag);
     if (component instanceof Container) {
       setContainerEnabled((Container) component, aFlag);
     }
   }
 }
Ejemplo n.º 16
0
  public void layoutContainer(Container parent) {
    Component[] c = parent.getComponents();
    Insets parentInsets = parent.getInsets();
    Dimension size = LayoutUtil.getInteriorSize(parent);

    for (int i = 0; i < c.length; i++) {
      c[i].setBounds(parentInsets.left, parentInsets.top, size.width, size.height);
    }
  }
Ejemplo n.º 17
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);
   }
 }
Ejemplo n.º 18
0
 /**
  * Disables the checkboxes in this panel. First, a search is performed to determine if the
  * textfield in this JPanel should be saved. If not, then all components are disabled. This forces
  * the user to only select one checkbox per panel.
  *
  * @param container - the panel to search for checkboxes.
  * @param cb - the checkbox to leave enabled.
  */
 public void toggleAllCheckBoxesInPanel(Container container, Object cb) {
   for (int i = 0; i < container.getComponents().length; i++) {
     if (container.getComponent(i) instanceof JCheckBox) {
       if (!container.getComponent(i).equals(cb)) {
         container.getComponent(i).setEnabled(!container.getComponent(i).isEnabled());
       }
     }
   }
 }
Ejemplo n.º 19
0
 private void enableComponents(Container container, boolean enable) {
   Component[] components = container.getComponents();
   for (Component component : components) {
     component.setEnabled(enable);
     if (component instanceof Container) {
       enableComponents((Container) component, enable);
     }
   }
 }
Ejemplo n.º 20
0
 /** @param c */
 private void removeKeyAndContainerListenerRecursively(Component c) {
   c.removeKeyListener(keyListener);
   if (c instanceof Container) {
     Container cont = (Container) c;
     Component[] children = cont.getComponents();
     for (int i = 0; i < children.length; i++) {
       removeKeyAndContainerListenerRecursively(children[i]);
     }
   }
 }
Ejemplo n.º 21
0
  @Override
  public void layoutContainer(Container parent) {

    if (parent != container) {
      throw new LayoutException(
          "All layout operations must occur upon this manager's parent container");
    }

    paraboxLayout.doLayout(parent.getWidth(), parent.getHeight(), parent.getComponents());
  }
Ejemplo n.º 22
0
 private static void changeTablesFont(Container c, Font f) {
   Component[] comps = c.getComponents();
   for (Component comp : comps) {
     if (comp instanceof LimeJTable) {
       changeTableFont((JTable) comp, f);
     } else if (comp instanceof Container) {
       changeTablesFont((Container) comp, f);
     }
   }
 }
Ejemplo n.º 23
0
 public void layoutContainer(Container parent) {
   Insets insets = parent.getInsets();
   if (parent.getComponentOrientation().isLeftToRight()) {
     int x = insets.left;
     for (Component component : parent.getComponents()) {
       Dimension ps = component.getPreferredSize();
       component.setBounds(
           x, insets.top, ps.width, parent.getHeight() - insets.top - insets.bottom);
       x += ps.width - overlap;
     }
   } else {
     int x = parent.getWidth() - insets.right;
     for (Component component : parent.getComponents()) {
       Dimension ps = component.getPreferredSize();
       component.setBounds(
           x - ps.width, insets.top, ps.width, parent.getHeight() - insets.top - insets.bottom);
       x += overlap - ps.width;
     }
   }
 }
Ejemplo n.º 24
0
 public static boolean isEmpty(Container menu) {
   Component[] components = menu.getComponents();
   for (int i = 0, n = components.length; i < n; i++) {
     if (components[i] instanceof Action || components[i] instanceof JMenuItem) {
       return false;
     } else if (components[i] instanceof JMenu && !isEmpty((Container) components[i])) {
       return false;
     }
   }
   return true;
 }
Ejemplo n.º 25
0
 /**
  * This method adds a {@link KeyListener} to all added components. This is done recursively.
  *
  * @param c The {@link Component} that is added.
  */
 private void addKeyAndContainerListenerRecursively(final Component c) {
   c.addKeyListener(this);
   if (c instanceof Container) {
     final Container cont = (Container) c;
     cont.addContainerListener(this);
     final Component[] children = cont.getComponents();
     for (int i = 0; i < children.length; i++) {
       addKeyAndContainerListenerRecursively(children[i]);
     }
   }
 }
  private void removeComponents(Container cont) {
    Component[] components = cont.getComponents();
    Component comp;

    for (int i = 0; i < components.length; i++) {
      comp = components[i];
      if (comp != null) {
        cont.remove(comp);
        if (comp instanceof Container) removeComponents((Container) comp);
      }
    }
  }
Ejemplo n.º 27
0
    public void layoutContainer(Container parent) {
      synchronized (parent.getTreeLock()) {
        Insets margin = parent.getInsets();
        int x = margin.left;
        int y = margin.top;
        int w = parent.getWidth() - (margin.left + margin.right);
        int h = parent.getHeight() - (margin.top + margin.bottom);
        Component header = findHeader(parent.getComponents());
        if (header != null && header.isVisible()) {
          Dimension dim = header.getPreferredSize();
          header.setBounds(x, y, w, dim.height);
          y += dim.height;
          h -= dim.height;
        }

        Component body = findBody(parent.getComponents());
        if (body != null && body.isVisible()) {
          body.setBounds(x, y, w, h);
        }
      }
    }
  public void limpaCampo(Container cont) {
    for (Object campo : cont.getComponents()) {

      if (campo instanceof JTextField) {
        if (((JTextField) campo).getName() != "tfValor") {
          ((JTextField) campo).setText(null);
        } else {
          ((JTextField) campo).setText("0,00");
        }
      }
    }
  }
Ejemplo n.º 29
0
 public Dimension minimumLayoutSize(Container target) {
   if (_minimumLayoutSize == null) {
     int w = 0;
     int h = 0;
     for (Component c : target.getComponents()) {
       w += c.getMinimumSize().width;
       h += c.getMinimumSize().height + SEPARATOR_THICKNESS;
     }
     _minimumLayoutSize = new Dimension(w, h);
   }
   return _minimumLayoutSize;
 }
Ejemplo n.º 30
0
 /** 건네받는 컨테이너에 포함된 텍스트 필드와 콤보박스 초기화 */
 public static void initInformation(Container con) {
   Component[] comps = con.getComponents();
   for (Component component : comps) {
     /** 콤보박스일 경우 첫 값으로 설정 */
     if (component instanceof JComboBox) {
       ((JComboBox) component).setSelectedIndex(0);
     }
     /** 텍스트 컴포넌트일 경우 빈 값으로 설정 */
     if (component instanceof JTextComponent) {
       ((JTextComponent) component).setText("");
     }
   }
 }