Search in sources :

Example 86 with Component

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

the class VTabbedPane method setSelectedIndex.

/**
	 * 	Set Selected Index.
	 * 	Register/Unregister Mnemonics
	 *	@param index index
	 */
public void setSelectedIndex(int index) {
    Component newC = getComponentAt(index);
    GridController newGC = null;
    if (newC instanceof GridController)
        newGC = (GridController) newC;
    //	Display
    if (newGC != null) {
        //hengsin, bug [ 1637763 ]
        if (isDisplay(newGC) == false)
            return;
    }
    //
    int oldIndex = getSelectedIndex();
    if (newGC != null && oldIndex >= 0 && index != oldIndex) {
        Component oldC = getComponentAt(oldIndex);
        if (oldC != null && oldC instanceof GridController) {
            GridController oldGC = (GridController) oldC;
            if (newGC.getTabLevel() > oldGC.getTabLevel() + 1) {
                //  validate
                //	Search for right tab
                GridController rightGC = null;
                boolean canJump = true;
                int currentLevel = newGC.getTabLevel();
                for (int i = index - 1; i >= 0; i--) {
                    Component rightC = getComponentAt(i);
                    if (rightC instanceof GridController) {
                        GridController gc = (GridController) rightC;
                        //can only skip level if all parent data are not stale
                        if (gc.getTabLevel() < currentLevel) {
                            if (gc.getTabLevel() == oldGC.getTabLevel() + 1) {
                                rightGC = gc;
                            }
                            if (!gc.isCurrent())
                                canJump = false;
                            currentLevel = gc.getTabLevel();
                        }
                    }
                }
                if (canJump == false) {
                    if (rightGC != null)
                        ADialog.warn(0, this, "TabSwitchJumpGo", rightGC.getTitle());
                    else
                        ADialog.warn(0, this, "TabSwitchJump");
                    return;
                }
            }
            oldGC.setMnemonics(false);
        }
    }
    //	Switch
    super.setSelectedIndex(index);
    if (newGC != null)
        newGC.setMnemonics(true);
}
Also used : Component(java.awt.Component)

Example 87 with Component

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

the class WFLayoutManager method layoutContainer.

//	minimumLayoutSize
/**************************************************************************
	 *	Lays out the specified container.
	 *	@param parent the container to be laid out
	 * @see java.awt.LayoutManager#layoutContainer(Container)
	 */
public void layoutContainer(Container parent) {
    Insets insets = parent.getInsets();
    //
    int width = insets.left;
    int height = insets.top;
    //	We need to layout
    if (needLayout(parent)) {
        int x = 5;
        int y = 5;
        //	Go through all components
        for (int i = 0; i < parent.getComponentCount(); i++) {
            Component comp = parent.getComponent(i);
            if (comp.isVisible() && comp instanceof WFNode) {
                Dimension ps = comp.getPreferredSize();
                comp.setLocation(x, y);
                comp.setBounds(x, y, ps.width, ps.height);
                //
                width = x + ps.width;
                height = y + ps.height;
                //	next pos
                if (x == 5)
                    x = 230;
                else {
                    x = 5;
                    y += 100;
                }
            //	x += ps.width-20;
            //	y += ps.height+20;
            }
        }
    } else //	we have an Layout
    {
        //	Go through all components
        for (int i = 0; i < parent.getComponentCount(); i++) {
            Component comp = parent.getComponent(i);
            if (comp.isVisible() && comp instanceof WFNode) {
                Dimension ps = comp.getPreferredSize();
                Point loc = comp.getLocation();
                int maxWidth = comp.getX() + ps.width;
                int maxHeight = comp.getY() + ps.height;
                if (width < maxWidth)
                    width = maxWidth;
                if (height < maxHeight)
                    height = maxHeight;
                comp.setBounds(loc.x, loc.y, ps.width, ps.height);
            }
        }
    //	for all components
    }
    //	have layout
    //	Create Lines
    WFContentPanel panel = (WFContentPanel) parent;
    panel.createLines();
    //	Calculate size
    width += insets.right;
    height += insets.bottom;
    //	return size
    m_size = new Dimension(width, height);
    log.finer("Size=" + m_size);
}
Also used : Insets(java.awt.Insets) Dimension(java.awt.Dimension) Point(java.awt.Point) Component(java.awt.Component) Point(java.awt.Point)

Example 88 with Component

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

the class AFocusTraversalPolicy method getDefaultComponent.

/**
	 * 	Get Default Component
	 *	@param aContainer container
	 *	@return default or null
	 */
public Component getDefaultComponent(Container aContainer) {
    //	info ("Root: ", aContainer);
    m_default = true;
    Component c = super.getDefaultComponent(aContainer);
    //	info ("  Default: ", c);
    m_default = false;
    return c;
}
Also used : Component(java.awt.Component)

Example 89 with Component

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

the class APanel method initPanel.

/**************************************************************************
	 *	Dynamic Panel Initialization - either single window or workbench.
	 *  <pre>
	 *  either
	 *  - Workbench tabPanel    (VTabbedPane)
	 *      - Tab               (GridController)
	 *  or
	 *  - Workbench tabPanel    (VTabbedPane)
	 *      - Window            (VTabbedPane)
	 *          - Tab           (GridController)
	 *  </pre>
	 *  tabPanel
	 *  @param AD_Workbench_ID  if > 0 this is a workbench, AD_Window_ID ignored
	 *  @param AD_Window_ID     if not a workbench, Window ID
	 *  @param query			if not a Workbench, Zoom Query - additional SQL where clause
	 *  @return true if Panel is initialized successfully
	 */
public boolean initPanel(int AD_Workbench_ID, int AD_Window_ID, MQuery query) {
    log.info("WB=" + AD_Workbench_ID + ", Win=" + AD_Window_ID + ", Query=" + query);
    this.setName("APanel" + AD_Window_ID);
    //  Single Window
    if (AD_Workbench_ID == 0)
        m_mWorkbench = new GridWorkbench(m_ctx, AD_Window_ID);
    else //  Workbench
    {
        //	m_mWorkbench = new MWorkbench(m_ctx);
        //	if (!m_mWorkbench.initWorkbench (AD_Workbench_ID))
        //	{
        //		log.log(Level.SEVERE, "APanel.initWindow - No Workbench Model");
        //		return false;
        //	}
        //	tabPanel.setWorkbench(true);
        //	tabPanel.addChangeListener(this);
        log.warning("Workbench Not implemented yet [" + this + "]");
        loadError = "Workbench Not implemented yet";
        return false;
    }
    Dimension windowSize = m_mWorkbench.getWindowSize();
    MQuery detailQuery = null;
    /**
		 *  WorkBench Loop
		 */
    for (int wb = 0; wb < m_mWorkbench.getWindowCount(); wb++) {
        //  Get/set WindowNo
        //  Timing: ca. 1.5 sec
        m_curWindowNo = Env.createWindowNo(this);
        m_mWorkbench.setWindowNo(wb, m_curWindowNo);
        //  Set AutoCommit for this Window
        Env.setAutoCommit(m_ctx, m_curWindowNo, Env.isAutoCommit(m_ctx));
        boolean autoNew = Env.isAutoNew(m_ctx);
        Env.setAutoNew(m_ctx, m_curWindowNo, autoNew);
        //  Workbench Window
        VTabbedPane window = null;
        //  just one window
        if (m_mWorkbench.getWindowCount() == 1) {
            window = tabPanel;
            window.setWorkbench(false);
        } else {
            VTabbedPane tp = new VTabbedPane(false);
            window = tp;
        }
        //  Window Init
        window.addChangeListener(this);
        /**
			 *  Init Model
			 */
        int wbType = m_mWorkbench.getWindowType(wb);
        /**
			 *  Window
			 */
        if (wbType == GridWorkbench.TYPE_WINDOW) {
            includedMap = new HashMap<Integer, GridController>(4);
            //
            GridWindowVO wVO = AEnv.getMWindowVO(m_curWindowNo, m_mWorkbench.getWindowID(wb), 0);
            if (wVO == null) {
                log.warning("AccessTableNoView for [" + this + "]");
                loadError = "AccessTableNoView";
                return false;
            }
            //  Timing: ca. 0.3-1 sec
            GridWindow mWindow = new GridWindow(wVO, true);
            //	Set SO/AutoNew for Window
            Env.setContext(m_ctx, m_curWindowNo, "IsSOTrx", mWindow.isSOTrx());
            if (!autoNew && mWindow.isTransaction())
                Env.setAutoNew(m_ctx, m_curWindowNo, true);
            m_mWorkbench.setMWindow(wb, mWindow);
            if (wb == 0)
                //	default = only current
                m_onlyCurrentRows = mWindow.isTransaction();
            if (windowSize == null)
                windowSize = mWindow.getWindowSize();
            /**
				 *  Window Tabs
				 */
            int tabSize = mWindow.getTabCount();
            //	Zoom Query
            boolean goSingleRow = query != null;
            for (int tab = 0; tab < tabSize; tab++) {
                boolean included = false;
                //  MTab
                if (tab == 0)
                    mWindow.initTab(0);
                GridTab gTab = mWindow.getTab(tab);
                Env.setContext(m_ctx, m_curWindowNo, tab, GridTab.CTX_TabLevel, Integer.toString(gTab.getTabLevel()));
                //  Query first tab
                if (tab == 0) {
                    //  initial user query for single workbench tab
                    if (m_mWorkbench.getWindowCount() == 1) {
                        if (query != null && query.getZoomTableName() != null && query.getZoomColumnName() != null && query.getZoomValue() instanceof Integer && (Integer) query.getZoomValue() > 0) {
                            if (!query.getZoomTableName().equalsIgnoreCase(gTab.getTableName())) {
                                detailQuery = query;
                                query = new MQuery();
                                query.addRestriction("1=2");
                            }
                        }
                        //Goodwill
                        isCancel = false;
                        query = initialQuery(query, gTab);
                        if (isCancel)
                            //Cancel opening window
                            return false;
                        if (query != null && query.getRecordCount() <= 1)
                            goSingleRow = true;
                    } else if (wb != 0) //  workbench dynamic query for dependent windows
                    {
                        query = m_mWorkbench.getQuery();
                    }
                    //	Set initial Query on first tab
                    if (query != null) {
                        //  Query might involve history
                        m_onlyCurrentRows = false;
                        gTab.setQuery(query);
                    }
                    if (wb == 0)
                        m_curTab = gTab;
                }
                //	query on first tab
                Component tabElement = null;
                //  GridController
                if (gTab.isSortTab()) {
                    VSortTab st = new VSortTab(m_curWindowNo, gTab.getAD_Table_ID(), gTab.getAD_ColumnSortOrder_ID(), gTab.getAD_ColumnSortYesNo_ID());
                    st.setTabLevel(gTab.getTabLevel());
                    tabElement = st;
                } else //	normal tab
                {
                    //  Timing: ca. .1 sec
                    GridController gc = new GridController();
                    CompiereColor cc = mWindow.getColor();
                    if (cc != null)
                        //  set color on Window level
                        gc.setBackgroundColor(cc);
                    //  will set color on Tab level
                    gc.initGrid(gTab, false, m_curWindowNo, this, mWindow, (tab != 0));
                    //  Timing: ca. 6-7 sec for first .2 for next
                    gc.addDataStatusListener(this);
                    //  register Escape Key
                    gc.registerESCAction(aIgnore);
                    //	Set First Tab
                    if (wb == 0 && tab == 0) {
                        m_curGC = gc;
                        //  Screen Sizing
                        Dimension size = gc.getPreferredSize();
                        size.width += 4;
                        size.height += 4;
                        gc.setPreferredSize(size);
                    }
                    tabElement = gc;
                    //	If we have a zoom query, switch to single row
                    if (tab == 0 && goSingleRow)
                        gc.switchSingleRow();
                    // FR [ 1757088 ]
                    GridField[] fields = gc.getMTab().getFields();
                    int m_tab_id = 0;
                    for (int f = 0; f < fields.length; f++) {
                        m_tab_id = fields[f].getIncluded_Tab_ID();
                        if (m_tab_id != 0) {
                            includedMap.put(m_tab_id, gc);
                        }
                    }
                    //	Is this tab included?
                    if (includedMap.size() > 0) {
                        GridController parent = (GridController) includedMap.get(new Integer(gTab.getAD_Tab_ID()));
                        if (parent != null) {
                            // FR [ 1757088 ]
                            gc.removeDataStatusListener(this);
                            GridSynchronizer synchronizer = new GridSynchronizer(mWindow, parent, gc);
                            if (parent == m_curGC)
                                synchronizer.activateChild();
                            included = parent.includeTab(gc, this, synchronizer);
                        }
                    }
                    initSwitchLineAction();
                }
                if (//  Add to TabbedPane
                !included) {
                    StringBuffer tabName = new StringBuffer();
                    tabName.append("<html>");
                    if (gTab.isReadOnly())
                        tabName.append("<i>");
                    int pos = gTab.getName().indexOf(" ");
                    if (pos == -1)
                        tabName.append(gTab.getName()).append("<br>&nbsp;");
                    else {
                        tabName.append(gTab.getName().substring(0, pos)).append("<br>").append(gTab.getName().substring(pos + 1));
                    }
                    if (gTab.isReadOnly())
                        tabName.append("</i>");
                    tabName.append("</html>");
                    //	Add Tab - sets ALT-<number> and Shift-ALT-<x>
                    window.addTab(tabName.toString(), gTab, tabElement);
                }
            }
        //  Tab Loop
        //  Tab background
        //	window.setBackgroundColor(new AdempiereColor(Color.magenta, Color.green));
        }
        //  Single Workbench Window Tab
        if (m_mWorkbench.getWindowCount() == 1) {
            window.setToolTipText(m_mWorkbench.getDescription(wb));
        } else //  Add Workbench Window Tab
        {
            tabPanel.addTab(m_mWorkbench.getName(wb), m_mWorkbench.getIcon(wb), window, m_mWorkbench.getDescription(wb));
        }
        //  Used for Env.getHeader
        Env.setContext(m_ctx, m_curWindowNo, "WindowName", m_mWorkbench.getName(wb));
    }
    //  Workbench Loop
    //  stateChanged (<->) triggered
    toolBar.setName(getTitle());
    m_curTab.getTableModel().setChanged(false);
    //	Set Detail Button
    aDetail.setEnabled(0 != m_curWinTab.getTabCount() - 1);
    //	Enable/Disable Tabs dynamically
    if (m_curWinTab instanceof VTabbedPane)
        ((VTabbedPane) m_curWinTab).evaluate(null);
    //	Size
    if (windowSize != null)
        setPreferredSize(windowSize);
    else
        revalidate();
    if (detailQuery != null && zoomToDetailTab(detailQuery)) {
        return true;
    }
    Dimension size = getPreferredSize();
    log.info("fini - " + size);
    m_curWinTab.requestFocusInWindow();
    return true;
}
Also used : GridWindow(org.compiere.model.GridWindow) MQuery(org.compiere.model.MQuery) Dimension(java.awt.Dimension) GridField(org.compiere.model.GridField) Point(java.awt.Point) VSortTab(org.compiere.grid.VSortTab) GridTab(org.compiere.model.GridTab) GridSynchronizer(org.compiere.grid.GridSynchronizer) GridWindowVO(org.compiere.model.GridWindowVO) CompiereColor(org.compiere.plaf.CompiereColor) VTabbedPane(org.compiere.grid.VTabbedPane) GridWorkbench(org.compiere.model.GridWorkbench) GridController(org.compiere.grid.GridController) Component(java.awt.Component)

Example 90 with Component

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

the class AEnv method updateUI.

//  cacheReset
/**
	 * Update all windows after look and feel changes.
	 * @since 2006-11-27 
	 */
public static void updateUI() {
    Set<Window> updated = Env.updateUI();
    JFrame top = Env.getWindow(0);
    if (top instanceof AMenu) {
        CFrame[] frames = ((AMenu) top).getWindowManager().getWindows();
        for (CFrame f : frames) {
            if (updated.contains(f))
                continue;
            SwingUtilities.updateComponentTreeUI(f);
            f.validate();
            RepaintManager mgr = RepaintManager.currentManager(f);
            Component[] childs = f.getComponents();
            for (Component c : childs) {
                if (c instanceof JComponent)
                    mgr.markCompletelyDirty((JComponent) c);
            }
            f.repaint();
            updated.add(f);
        }
    }
}
Also used : Window(java.awt.Window) JFrame(javax.swing.JFrame) JComponent(javax.swing.JComponent) JComponent(javax.swing.JComponent) Component(java.awt.Component) CFrame(org.compiere.swing.CFrame) RepaintManager(javax.swing.RepaintManager)

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