Search in sources :

Example 81 with Component

use of java.awt.Component in project adempiere by adempiere.

the class VPanel method addGroup.

//	addField
/**
	 *	Add Group
	 *  @param fieldGroup field group
	 *  @param fieldGroupType 
	 *  @return true if group added
	 */
private boolean addGroup(String fieldGroup, String fieldGroupType) {
    //	First time - add top
    if (m_oldFieldGroup == null) {
        m_oldFieldGroup = "";
        m_oldFieldGroupType = "";
    }
    if (fieldGroup == null || fieldGroup.length() == 0 || fieldGroup.equals(m_oldFieldGroup))
        return false;
    //[ 1757088 ]
    if (m_tablist.get(fieldGroup) != null) {
        return false;
    }
    //[ 1757088 ]
    if (fieldGroupType.equals(X_AD_FieldGroup.FIELDGROUPTYPE_Tab)) {
        CPanel m_tab = new CPanel();
        m_tab.setBackground(AdempierePLAF.getFormBackground());
        String tpConstraints = defaultLayoutConstraints;
        MigLayout layout = new MigLayout(tpConstraints);
        layout.addLayoutCallback(callback);
        m_tab.setLayout(layout);
        m_tab.setName(fieldGroup);
        CPanel dummy = new CPanel();
        dummy.setLayout(new BorderLayout());
        dummy.add(m_tab, BorderLayout.NORTH);
        dummy.setName(m_tab.getName());
        dummy.setBorder(BorderFactory.createEmptyBorder(10, 12, 0, 12));
        this.add(dummy);
        m_tablist.put(fieldGroup, m_tab);
    } else if (fieldGroupType.equals(X_AD_FieldGroup.FIELDGROUPTYPE_Collapse)) {
        CollapsiblePanel collapsibleSection = new CollapsiblePanel(fieldGroup);
        JXCollapsiblePane m_tab = collapsibleSection.getCollapsiblePane();
        m_tab.setAnimated(false);
        m_tab.getContentPane().setBackground(AdempierePLAF.getFormBackground());
        String cpConstraints = defaultLayoutConstraints;
        // 0 inset left and right as this is a nested panel
        // 0 inset top because of the struts added below
        cpConstraints += ", ins 0 0 n 0";
        MigLayout layout = new MigLayout(cpConstraints);
        layout.addLayoutCallback(callback);
        collapsibleSection.setName(fieldGroup);
        m_main.add(collapsibleSection, "newline, spanx, growx");
        m_tab.setLayout(layout);
        /* for compatibility with old layout, force collapsible field groups
			 *  to have a minimum of two columns by inserting invisible components
			 */
        Component strut1 = Box.createVerticalStrut(1);
        strut1.setName("vstrut1" + fieldGroup);
        Component strut2 = Box.createVerticalStrut(1);
        strut2.setName("vstrut2" + fieldGroup);
        m_tab.add(new CLabel(""), "gap 0 0 0 0");
        m_tab.add(strut1, "pushx, growx, gap 0 0 0 0");
        m_tab.add(new CLabel(""), "");
        m_tab.add(strut2, "pushx, growx, gap 0 0 0 0, wrap");
        m_tablist.put(fieldGroup, collapsibleSection);
    } else // Label or null
    {
        CLabel label = new CLabel(fieldGroup, CLabel.LEADING);
        label.setFont(AdempierePLAF.getFont_Label().deriveFont(Font.BOLDITALIC, AdempierePLAF.getFont_Label().getSize2D()));
        //	BR [ 359 ]
        //	Show label completely
        m_main.add(label, "newline, alignx leading, spanx, growx");
        m_main.add(new JSeparator(), "newline, spanx, growx");
    //	reset
    }
    m_oldFieldGroup = fieldGroup;
    m_oldFieldGroupType = fieldGroupType;
    return true;
}
Also used : CLabel(org.compiere.swing.CLabel) BorderLayout(java.awt.BorderLayout) MigLayout(net.miginfocom.swing.MigLayout) JXCollapsiblePane(org.jdesktop.swingx.JXCollapsiblePane) CPanel(org.compiere.swing.CPanel) Component(java.awt.Component) CollapsiblePanel(org.compiere.swing.CollapsiblePanel) JSeparator(javax.swing.JSeparator)

Example 82 with Component

use of java.awt.Component in project adempiere by adempiere.

the class VPanel method setMnemonics.

/**
	 * 	Set Window level Mnemonics
	 *	@param set true if set otherwise unregister
	 */
public void setMnemonics(boolean set) {
    int size = m_fields.size();
    for (int i = 0; i < size; i++) {
        Component c = m_fields.get(i);
        if (c instanceof CLabel) {
            CLabel l = (CLabel) c;
            if (set)
                l.setDisplayedMnemonic(l.getSavedMnemonic());
            else
                l.setDisplayedMnemonic(0);
        } else if (c instanceof VCheckBox) {
            VCheckBox cb = (VCheckBox) c;
            if (set)
                cb.setMnemonic(cb.getSavedMnemonic());
            else
                cb.setMnemonic(0);
        } else if (c instanceof VButton) {
            VButton b = (VButton) c;
            if (set)
                b.setMnemonic(b.getSavedMnemonic());
            else
                b.setMnemonic(0);
        }
    }
}
Also used : CLabel(org.compiere.swing.CLabel) VButton(org.compiere.grid.ed.VButton) VCheckBox(org.compiere.grid.ed.VCheckBox) Component(java.awt.Component)

Example 83 with Component

use of java.awt.Component in project adempiere by adempiere.

the class VPanel method findChildComponents.

//  setBackground
private void findChildComponents(CPanel container, List<Component> list) {
    Component[] comp = container.getComponents();
    for (int c = 0; c < comp.length; c++) {
        list.add(comp[c]);
        if (comp[c] instanceof CollapsiblePanel) {
            CollapsiblePanel collapsiblePanel = (CollapsiblePanel) comp[c];
            Component[] nestedComps = collapsiblePanel.getCollapsiblePane().getContentPane().getComponents();
            for (int y = 0; y < nestedComps.length; y++) {
                if (nestedComps[y] instanceof CPanel) {
                    CPanel nestedPanel = (CPanel) nestedComps[y];
                    Component[] nestedPanelComps = nestedPanel.getComponents();
                    for (int x = 0; x < nestedPanelComps.length; x++) {
                        list.add(nestedPanelComps[x]);
                    }
                } else {
                    list.add(nestedComps[y]);
                }
            }
        } else if (comp[c] instanceof CPanel) {
            findChildComponents((CPanel) comp[c], list);
        }
    }
}
Also used : CPanel(org.compiere.swing.CPanel) Component(java.awt.Component) CollapsiblePanel(org.compiere.swing.CollapsiblePanel)

Example 84 with Component

use of java.awt.Component in project adempiere by adempiere.

the class GridController method dynamicDisplay.

//  propertyChange
/**
	 *  Dynamic Display.
	 *  - Single Row Screen layout and update of dynamic Lookups
	 *  <p>
	 *  Single Row layout:
	 *  the components's name is the ColumnName; if it matches, the
	 *  MField.isDisplayed(true) is used to determine if it is visible
	 *  if the component is a VEditor, setEnabled is set from the MField
	 *  <p>
	 *  Multi Row layout is not changed:
	 *  VCellRenderer calls JTable.isCellEditable -> checks MField.isEditable (Active, isDisplayed)
	 *  VCellEditor.isCellEditable calls MField.isEditable(true) <br>
	 *  If a column is not displayed, the width is set to 0 in dynInit
	 *  <p>
	 *  Dynamic update of data is handeled in VLookup.focusGained/Lost.
	 *  When focus is gained the model is temporarily updated with the
	 *  specific validated data, if lost, it is switched back to the
	 *  unvalidated data (i.e. everything). This allows that the display
	 *  methods have a lookup to display. <br>
	 *  Here: if the changed field has dependents and the dependent
	 *  is a Lookup and this lookup has a dynamic dependence of the changed field,
	 *  the value of that field is set to null (in MTab.processDependencies -
	 *  otherwise it would show an invalid value).
	 *  As Editors listen for value changed of their MField, the display is updated.
	 *  <p>
	 *  Called from GridController.valueChanged/dataStatusChanged, APane;.stateChanged/unlock/cmd_...
	 *  @param col selective column number or 0 if all
	 */
public void dynamicDisplay(int col) {
    //	Don't update if multi-row
    if (!isSingleRow() || m_onlyMultiRow)
        return;
    if (!m_mTab.isOpen())
        return;
    //  Selective
    if (col > 0) {
        GridField changedField = m_mTab.getField(col);
        String columnName = changedField.getColumnName();
        ArrayList<GridField> dependants = m_mTab.getDependantFields(columnName);
        log.config("(" + m_mTab.toString() + ") " + columnName + " - Dependents=" + dependants.size());
        //	No Dependents and no Callout - Set just Background
        if (dependants.size() == 0 && changedField.getCallout().length() == 0) {
            Component[] comp = vPanel.getComponentsRecursive();
            for (int i = 0; i < comp.length; i++) {
                if (columnName.equals(comp[i].getName()) && comp[i] instanceof VEditor) {
                    VEditor ve = (VEditor) comp[i];
                    boolean manMissing = false;
                    boolean noValue = changedField.getValue() == null || changedField.getValue().toString().length() == 0;
                    if (//  check context
                    noValue && changedField.isEditable(true) && changedField.isMandatory(true))
                        manMissing = true;
                    ve.setBackground(manMissing || changedField.isError());
                    break;
                }
            }
            return;
        }
    }
    //  selective
    //  complete single row re-display
    boolean noData = m_mTab.getRowCount() == 0;
    log.config(m_mTab.toString() + " - Rows=" + m_mTab.getRowCount());
    //  All Components in vPanel (Single Row)
    Set<String> hiddens = new HashSet<String>();
    Component[] comps = vPanel.getComponentsRecursive();
    for (int i = 0; i < comps.length; i++) {
        Component comp = comps[i];
        String columnName = comp.getName();
        if (comp instanceof VChart && isSingleRow()) {
            ((VChart) comp).createChart();
        }
        if (columnName != null && columnName.length() > 0) {
            GridField mField = m_mTab.getField(columnName);
            if (mField != null) {
                if (//  check context
                mField.isDisplayed(true)) {
                    if (!comp.isVisible())
                        //  visibility
                        comp.setVisible(true);
                    /**
						 * Feature Request [1707462]
						 * Enable runtime change of VFormat
						 * @author fer_luck
						 */
                    if (comp instanceof VString) {
                        VString vs = (VString) comp;
                        if ((vs.getVFormat() != null && vs.getVFormat().length() > 0 && mField.getVFormat() == null) || (vs.getVFormat() == null && mField.getVFormat() != null && mField.getVFormat().length() > 0) || (vs.getVFormat() != null && mField.getVFormat() != null && !vs.getVFormat().equals(mField.getVFormat()))) {
                            vs.setVFormat(mField.getVFormat());
                        }
                    }
                    //End Feature Request [1707462]
                    if (comp instanceof VEditor) {
                        VEditor ve = (VEditor) comp;
                        if (noData)
                            ve.setReadWrite(false);
                        else {
                            //  r/w - check Context
                            boolean rw = mField.isEditable(true);
                            ve.setReadWrite(rw);
                            //	log.log(Level.FINEST, "RW=" + rw + " " + mField);
                            boolean manMissing = false;
                            //  least expensive operations first        //  missing mandatory
                            if (rw && (mField.getValue() == null || mField.getValue().toString().isEmpty()) && //  check context. Some fields can return "" instead of null
                            mField.isMandatory(true))
                                manMissing = true;
                            ve.setBackground(manMissing || mField.isError());
                        }
                    }
                } else {
                    if (comp.isVisible())
                        comp.setVisible(false);
                    hiddens.add(columnName);
                }
            }
        }
    }
    // hide empty field group based on the environment
    for (int i = 0; i < comps.length; i++) {
        Component comp = comps[i];
        if (comp instanceof CollapsiblePanel) {
            if (comp.getName() == null || comp.getName().startsWith("IncludedTab#"))
                continue;
            else {
                boolean hasVisible = false;
                Component[] childs = ((CollapsiblePanel) comp).getCollapsiblePane().getContentPane().getComponents();
                for (int j = 0; j < childs.length; j++) {
                    if (childs[j].isVisible()) {
                        String columnName = childs[j].getName();
                        if (columnName != null && columnName.length() > 0) {
                            GridField mField = m_mTab.getField(columnName);
                            if (mField != null) {
                                hasVisible = true;
                                break;
                            }
                        }
                    }
                }
                if (comp.isVisible() != hasVisible)
                    comp.setVisible(hasVisible);
            }
        }
    }
    //
    log.config(m_mTab.toString() + " - fini - " + (col <= 0 ? "complete" : "seletive"));
}
Also used : VChart(org.compiere.grid.ed.VChart) GridField(org.compiere.model.GridField) VString(org.compiere.grid.ed.VString) VEditor(org.compiere.grid.ed.VEditor) CollapsiblePanel(org.compiere.swing.CollapsiblePanel) VString(org.compiere.grid.ed.VString) Component(java.awt.Component) HashSet(java.util.HashSet)

Example 85 with Component

use of java.awt.Component in project adempiere by adempiere.

the class VTabbedPane method isEnabledAt.

//  dispose
@Override
public //hengsin, bug [ 1637763 ]
boolean isEnabledAt(int index) {
    boolean enabled = super.isEnabledAt(index);
    if (!enabled)
        return enabled;
    Component comp = getComponentAt(index);
    GridController gc = null;
    if (comp instanceof GridController)
        gc = (GridController) comp;
    //	Display
    if (gc != null) {
        enabled = isDisplay(gc);
    }
    return enabled;
}
Also used : Component(java.awt.Component)

Aggregations

Component (java.awt.Component)645 JComponent (javax.swing.JComponent)163 Dimension (java.awt.Dimension)81 JLabel (javax.swing.JLabel)65 JPanel (javax.swing.JPanel)60 Insets (java.awt.Insets)55 Point (java.awt.Point)55 TableCellRenderer (javax.swing.table.TableCellRenderer)47 Container (java.awt.Container)46 JScrollPane (javax.swing.JScrollPane)42 JTable (javax.swing.JTable)36 JButton (javax.swing.JButton)35 BorderLayout (java.awt.BorderLayout)34 GridBagConstraints (java.awt.GridBagConstraints)34 JTextComponent (javax.swing.text.JTextComponent)34 GridBagLayout (java.awt.GridBagLayout)33 Color (java.awt.Color)32 JList (javax.swing.JList)31 TableColumn (javax.swing.table.TableColumn)31 MouseEvent (java.awt.event.MouseEvent)27