Search in sources :

Example 56 with FocusEvent

use of java.awt.event.FocusEvent in project adempiere by adempiere.

the class APanel method stateChanged.

//	set Busy
/**************************************************************************
	 *	Change Listener - (tab change)			<->
	 *  @param e event
	 */
public void stateChanged(ChangeEvent e) {
    //Run LostFocus Event when change tab			
    if (m_curWinTab != null) {
        Component cp = m_window.getFocusOwner();
        if (cp != null) {
            m_window.dispatchEvent(new FocusEvent(cp, FocusEvent.FOCUS_LOST));
        }
    }
    if (m_disposing)
        return;
    log.info(e.toString());
    setBusy(true, true);
    VTabbedPane tp = (VTabbedPane) e.getSource();
    boolean back = false;
    boolean isAPanelTab = false;
    //  Workbench Tab Change
    if (tp.isWorkbench()) {
        int WBIndex = tabPanel.getSelectedIndex();
        m_curWindowNo = m_mWorkbench.getWindowNo(WBIndex);
        //  Window Change
        log.info("curWin=" + m_curWindowNo + " - Win=" + tp);
        if (tp.getSelectedComponent() instanceof JTabbedPane)
            m_curWinTab = (JTabbedPane) tp.getSelectedComponent();
        else
            throw new java.lang.IllegalArgumentException("Window does not contain Tabs");
        if (m_curWinTab.getSelectedComponent() instanceof GridController) {
            m_curGC = (GridController) m_curWinTab.getSelectedComponent();
            initSwitchLineAction();
        } else
            throw new java.lang.IllegalArgumentException("Window-Tab does not contain GridControler");
        //  change pointers
        m_curTabIndex = m_curWinTab.getSelectedIndex();
    } else {
        //  Just a Tab Change
        log.info("Tab=" + tp);
        m_curWinTab = tp;
        int tpIndex = m_curWinTab.getSelectedIndex();
        //	detect no tab change
        if (tpIndex == m_curTabIndex)
            return;
        back = tpIndex < m_curTabIndex;
        GridController gc = null;
        if (m_curWinTab.getSelectedComponent() instanceof GridController)
            gc = (GridController) m_curWinTab.getSelectedComponent();
        else if (m_curWinTab.getSelectedComponent() instanceof APanelTab)
            isAPanelTab = true;
        else
            throw new java.lang.IllegalArgumentException("Tab does not contain GridControler");
        //  Save old Tab
        if (m_curGC != null) {
            m_curGC.stopEditor(true);
            //  has anything changed?
            if (m_curTab.needSave(true, false)) {
                //  do we have real change
                if (m_curTab.needSave(true, true)) {
                    //	Automatic Save
                    if (Env.isAutoCommit(m_ctx, m_curWindowNo)) {
                        if (!m_curTab.dataSave(true)) {
                            //  there is a problem, so we go back
                            showLastError();
                            m_curWinTab.setSelectedIndex(m_curTabIndex);
                            setBusy(false, true);
                            return;
                        }
                    } else //  explicitly ask when changing tabs
                    if (ADialog.ask(m_curWindowNo, this, "SaveChanges?", m_curTab.getCommitWarning())) {
                        //  yes we want to save
                        if (!m_curTab.dataSave(true)) {
                            //  there is a problem, so we go back
                            showLastError();
                            m_curWinTab.setSelectedIndex(m_curTabIndex);
                            setBusy(false, true);
                            return;
                        }
                    } else //  Don't save
                    {
                        //VOSS COM
                        int newRecord = m_curTab.getTableModel().getNewRow();
                        if (newRecord == -1)
                            m_curTab.dataIgnore();
                        else {
                            m_curWinTab.setSelectedIndex(m_curTabIndex);
                            setBusy(false, true);
                            return;
                        }
                    }
                } else
                    //  new record, but nothing changed
                    m_curTab.dataIgnore();
            }
        //  there is a change
        }
        if (m_curAPanelTab != null) {
            m_curAPanelTab.saveData();
            m_curAPanelTab.unregisterPanel();
            m_curAPanelTab = null;
        }
        //	new tab
        //	if (m_curTabIndex >= 0)
        //		m_curWinTab.setForegroundAt(m_curTabIndex, AdempierePLAF.getTextColor_Normal());
        //	m_curWinTab.setForegroundAt(tpIndex, AdempierePLAF.getTextColor_OK());
        //	previousIndex = m_curTabIndex;
        m_curTabIndex = tpIndex;
        if (!isAPanelTab) {
            m_curGC = gc;
            initSwitchLineAction();
        }
    }
    //	Sort Tab Handling
    if (isAPanelTab) {
        m_curAPanelTab = (APanelTab) m_curWinTab.getSelectedComponent();
        m_curAPanelTab.registerAPanel(this);
        m_curAPanelTab.loadData();
        // Consider that APanelTab (e.g. VSortTab) is not navigable - teo_sarca [ 1705444 ]
        aFirst.setEnabled(false);
        aPrevious.setEnabled(false);
        aNext.setEnabled(false);
        aLast.setEnabled(false);
    } else //	Cur Tab Setting
    {
        int gwTabIndex = m_mWorkbench.getMWindow(0).getTabIndex(m_curGC.getMTab());
        //boolean needValidate = false;
        if (m_mWorkbench.getMWindow(0).isTabInitialized(gwTabIndex) == false) {
            m_mWorkbench.getMWindow(0).initTab(gwTabIndex);
        //needValidate = true;
        }
        m_curGC.activate();
        m_curTab = m_curGC.getMTab();
        //	Refresh only current row when tab is current
        if (back && m_curTab.isCurrent())
            m_curTab.dataRefresh();
        else //	Requery & autoSize
        {
            MRole role = MRole.getDefault();
            m_curGC.query(m_onlyCurrentRows, m_onlyCurrentDays, role.getMaxQueryRecords());
        /*
				if (m_curGC.isNeedToSaveParent())
				{
					// there is a problem, so we go back
					ADialog.error(m_curWindowNo, this, "SaveParentFirst");
					m_curWinTab.setSelectedIndex(previousIndex);
					setBusy(false, true);
					return;
				}*/
        }
        //  Set initial record
        if (m_curTab.getRowCount() == 0) {
            //	Automatically create New Record, if none & tab not RO
            if (!m_curTab.isReadOnly() && (Env.isAutoNew(m_ctx, m_curWindowNo) || m_curTab.isQueryNewRecord())) {
                log.config("No record - New - AutoNew=" + Env.isAutoNew(m_ctx, m_curWindowNo) + " - QueryNew=" + m_curTab.isQueryNewRecord());
                m_curTab.dataNew(false);
            } else //	No Records found
            {
                aSave.setEnabled(false);
                aDelete.setEnabled(false);
                aDeleteSelection.setEnabled(false);
            }
            //  updates counter
            m_curTab.navigateCurrent();
            m_curGC.dynamicDisplay(0);
        }
    /*
			if (needValidate)
			{
				JFrame frame = Env.getFrame(APanel.this);
				if (frame != null)
				{
					//not sure why, the following lines is needed to make dynamic resize work
					//tested on jdk1.5, 1.6 using jgoodies look and feel
					frame.getPreferredSize();

					if (frame.getExtendedState() != JFrame.MAXIMIZED_BOTH)
					{
						frame.setMinimumSize(frame.getSize());
						revalidate();
						SwingUtilities.invokeLater(new Runnable() {

							public void run() {
								JFrame frame = Env.getFrame(APanel.this);
								frame.validate();
								AEnv.showCenterScreen(frame);
								frame.setMinimumSize(null);
							}

						});
					}
				}
			}*/
    //	else		##CHANGE
    //		m_curTab.navigateCurrent();
    }
    //	Update <-> Navigation
    aDetail.setEnabled(m_curTabIndex != m_curWinTab.getTabCount() - 1);
    aParent.setEnabled(m_curTabIndex != 0 && m_curWinTab.getTabCount() > 1);
    //	History (on first tab only)
    if (m_mWorkbench.getMWindow(getWindowIndex()).isTransaction())
        aHistory.setEnabled(isFirstTab());
    else {
        aHistory.setPressed(false);
        aHistory.setEnabled(false);
    }
    //	Document Print
    aPrint.setEnabled(m_curTab.isPrinted());
    aPrintPreview.setEnabled(m_curTab.isPrinted());
    //	Query
    aFind.setPressed(m_curTab.isQueryActive());
    //	Order Tab
    if (isAPanelTab) {
        aMulti.setPressed(false);
        aMulti.setEnabled(false);
        aNew.setEnabled(false);
        aDelete.setEnabled(false);
        aDeleteSelection.setEnabled(false);
        aFind.setEnabled(false);
        aRefresh.setEnabled(false);
        aAttachment.setEnabled(false);
        aChat.setEnabled(false);
    } else //	Grid Tab
    {
        aMulti.setEnabled(true);
        aMulti.setPressed(!m_curGC.isSingleRow());
        aFind.setEnabled(true);
        aRefresh.setEnabled(true);
        aAttachment.setEnabled(true);
        aChat.setEnabled(true);
    }
    //
    m_curWinTab.requestFocusInWindow();
    setBusy(false, true);
    log.config("fini");
}
Also used : APanelTab(org.compiere.grid.APanelTab) JTabbedPane(javax.swing.JTabbedPane) MRole(org.compiere.model.MRole) FocusEvent(java.awt.event.FocusEvent) Point(java.awt.Point) VTabbedPane(org.compiere.grid.VTabbedPane) Component(java.awt.Component) GridController(org.compiere.grid.GridController)

Example 57 with FocusEvent

use of java.awt.event.FocusEvent in project adempiere by adempiere.

the class CComboBox method init.

/**
	 *  Common Init
	 */
private void init() {
    FIELD_HIGHT = getPreferredSize().height;
    setEditable(true);
    setAutoReducible(true);
    addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent me) {
            if (SwingUtilities.isLeftMouseButton(me) && isAutoReducible())
                updateReducibleModel(false);
        }
    });
    // when auto-reducing, the focus listener will ensure all data choices
    // are shown on initial focus, and that a valid selection is in place
    // when focus is lost
    final JTextComponent textComponent = (JTextComponent) getEditor().getEditorComponent();
    textComponent.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent fe) {
            if (isEditable())
                textComponent.selectAll();
            textComponent.repaint();
        }

        public void focusLost(FocusEvent fe) {
            if (isAutoReducible()) {
                Object item = m_reducibleModel.getSelectedItem();
                item = (item == null && m_reducibleModel.getSize() != 0) ? m_reducibleModel.getElementAt(0) : item;
                if (item == null) {
                    updateReducibleModel(false);
                    if (m_reducibleModel.getSize() != 0)
                        item = m_reducibleModel.getElementAt(0);
                    else
                        return;
                }
                m_reducibleModel.setSelectedItem(item);
            }
            textComponent.setCaretPosition(0);
            hidePopup();
            textComponent.repaint();
        }
    });
    textComponent.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent me) {
            if (SwingUtilities.isLeftMouseButton(me) && isAutoReducible() && !isPopupVisible()) {
                updateReducibleModel(false);
                showPopup();
            }
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JTextComponent(javax.swing.text.JTextComponent) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 58 with FocusEvent

use of java.awt.event.FocusEvent in project adempiere by adempiere.

the class ADempiereAutoCompleteDecorator method decorate.

/**
     * Decorates a given text component for automatic completion using the
     * given AutoCompleteDocument and AbstractAutoCompleteAdaptor.
     * 
     * 
     * @param textComponent a text component that should be decorated
     * @param document the AutoCompleteDocument to be installed on the text component
     * @param adaptor the AbstractAutoCompleteAdaptor to be used
     */
public static void decorate(JTextComponent textComponent, AutoCompleteDocument document, final AbstractAutoCompleteAdaptor adaptor) {
    // install the document on the text component
    textComponent.setDocument(document);
    // mark entire text when the text component gains focus
    // otherwise the last mark would have been retained which is quiet confusing
    textComponent.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent e) {
            JTextComponent textComponent = (JTextComponent) e.getSource();
            adaptor.markEntireText();
        }
    });
    // Tweak some key bindings
    InputMap editorInputMap = textComponent.getInputMap();
    if (document.isStrictMatching()) {
        // move the selection to the left on VK_BACK_SPACE
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_BACK_SPACE, 0), DefaultEditorKit.selectionBackwardAction);
        // ignore VK_DELETE and CTRL+VK_X and beep instead when strict matching
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, 0), errorFeedbackAction);
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_DOWN_MASK), errorFeedbackAction);
    } else {
        ActionMap editorActionMap = textComponent.getActionMap();
        // leave VK_DELETE and CTRL+VK_X as is
        // VK_BACKSPACE will move the selection to the left if the selected item is in the list
        // it will delete the previous character otherwise
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_BACK_SPACE, 0), "nonstrict-backspace");
        editorActionMap.put("nonstrict-backspace", new NonStrictBackspaceAction(editorActionMap.get(DefaultEditorKit.deletePrevCharAction), editorActionMap.get(DefaultEditorKit.selectionBackwardAction), adaptor));
        editorInputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_TAB, java.awt.event.KeyEvent.CTRL_DOWN_MASK), "NextMatchAction");
        editorActionMap.put("NextMatchAction", new NextMatchAction(textComponent, document, adaptor));
    }
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) ActionMap(javax.swing.ActionMap) JTextComponent(javax.swing.text.JTextComponent) InputMap(javax.swing.InputMap) FocusEvent(java.awt.event.FocusEvent)

Example 59 with FocusEvent

use of java.awt.event.FocusEvent in project ChatGameFontificator by GlitchCog.

the class ControlPanelIrc method build.

@Override
protected void build() {
    userInput = new LabeledInput("Username", 11);
    authInput = new LabeledInput("OAuth Token", true, 25);
    authHelpButton = new JButton("Get OAuth Token");
    chanInput = new LabeledInput("Channel", 11);
    hostInput = new LabeledInput("Host", 7);
    portInput = new LabeledInput("Port", 3);
    FocusListener fl = new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
        }

        @Override
        public void focusLost(FocusEvent e) {
            // the configuration
            try {
                fillConfigFromInput();
            } catch (Exception ex) {
                logger.trace(ex.toString(), ex);
            }
        }
    };
    userInput.addFocusListener(fl);
    authInput.addFocusListener(fl);
    chanInput.addFocusListener(fl);
    hostInput.addFocusListener(fl);
    portInput.addFocusListener(fl);
    authHelpButton.addActionListener(new ActionListener() {

        final String url = "http://www.twitchapps.com/tmi/";

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop().browse(URI.create(url));
            } catch (java.io.IOException ex) {
                ChatWindow.popup.handleProblem("Unable to open website at URL: " + url);
            }
        }
    });
    connectButton = new JButton(BUTTON_TEXT_CONNECT);
    connectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JButton source = (JButton) e.getSource();
            // Reset it just in case
            source.setText(bot.isConnected() ? BUTTON_TEXT_DISCONNECT : BUTTON_TEXT_CONNECT);
            if (bot.isConnected()) {
                bot.setDisconnectExpected(true);
                bot.disconnect();
            } else {
                try {
                    LoadConfigReport report = validateInputForConnect();
                    if (report.isErrorFree()) {
                        // Connect to the IRC channel
                        connect();
                        emojiControl.loadAndRunEmojiWork();
                    } else {
                        ChatWindow.popup.handleProblem(report);
                    }
                } catch (NumberFormatException ex) {
                    ChatWindow.popup.handleProblem("Invalid login port value", ex);
                } catch (NickAlreadyInUseException ex) {
                    ChatWindow.popup.handleProblem("Nickname already in use", ex);
                } catch (IOException ex) {
                    ChatWindow.popup.handleProblem("Error connecting to the IRC server. Verify the Internet connection and then the host and port values.", ex);
                } catch (IrcException ex) {
                    ChatWindow.popup.handleProblem("The host IRC server rejected the connection", ex);
                } catch (Exception ex) {
                    ChatWindow.popup.handleProblem("Unanticipated error connecting", ex);
                }
            }
        }
    });
    clearChatButton = new JButton("Clear Chat");
    clearChatButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            chat.clearChat();
            chat.repaint();
        }
    });
    autoReconnectBox = new JCheckBox("Automatically attempt to reconnect if connection is lost");
    autoReconnectBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            config.setAutoReconnect(autoReconnectBox.isSelected());
        }
    });
    JPanel everything = new JPanel(new GridBagLayout());
    everything.setBorder(new TitledBorder(baseBorder, "IRC Connection Properties / Clear Chat", TitledBorder.CENTER, TitledBorder.TOP));
    JPanel topRow = new JPanel(new GridBagLayout());
    JPanel midRow = new JPanel(new GridBagLayout());
    JPanel botRow = new JPanel(new GridBagLayout());
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    topRow.add(userInput, gbc);
    gbc.gridx++;
    topRow.add(chanInput, gbc);
    gbc.gridx++;
    gbc.gridx = 0;
    midRow.add(authInput, gbc);
    gbc.gridx++;
    gbc.weightx = 0.0;
    gbc.fill = GridBagConstraints.NONE;
    midRow.add(authHelpButton, gbc);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.gridx = 0;
    botRow.add(hostInput, gbc);
    gbc.gridx++;
    botRow.add(portInput, gbc);
    gbc.gridx++;
    gbc.anchor = GridBagConstraints.NORTHEAST;
    botRow.add(connectButton, gbc);
    gbc.gridx++;
    botRow.add(clearChatButton, gbc);
    gbc.gridx++;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 0;
    everything.add(topRow, gbc);
    gbc.gridy++;
    everything.add(midRow, gbc);
    gbc.gridy++;
    everything.add(botRow, gbc);
    gbc.gridy++;
    everything.add(autoReconnectBox, gbc);
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.anchor = GridBagConstraints.NORTH;
    add(everything, gbc);
    gbc.gridy++;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.SOUTH;
    gbc.fill = GridBagConstraints.BOTH;
    add(logBox, gbc);
}
Also used : JPanel(javax.swing.JPanel) LabeledInput(com.glitchcog.fontificator.gui.component.LabeledInput) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) NickAlreadyInUseException(org.jibble.pircbot.NickAlreadyInUseException) JButton(javax.swing.JButton) IOException(java.io.IOException) TitledBorder(javax.swing.border.TitledBorder) FocusEvent(java.awt.event.FocusEvent) LoadConfigReport(com.glitchcog.fontificator.config.loadreport.LoadConfigReport) IOException(java.io.IOException) NickAlreadyInUseException(org.jibble.pircbot.NickAlreadyInUseException) IrcException(org.jibble.pircbot.IrcException) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) FocusListener(java.awt.event.FocusListener) IrcException(org.jibble.pircbot.IrcException)

Example 60 with FocusEvent

use of java.awt.event.FocusEvent in project jdk8u_jdk by JetBrains.

the class XWindowPeer method handleFocusEvent.

public void handleFocusEvent(XEvent xev) {
    XFocusChangeEvent xfe = xev.get_xfocus();
    FocusEvent fe;
    if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
        focusLog.fine("{0}", xfe);
    }
    if (isEventDisabled(xev)) {
        return;
    }
    if (xev.get_type() == XConstants.FocusIn) {
        // If this window is non-focusable don't post any java focus event
        if (focusAllowedFor()) {
            if (// Normal notify
            xfe.get_mode() == XConstants.NotifyNormal || // Alt-Tab notify
            xfe.get_mode() == XConstants.NotifyWhileGrabbed) {
                handleWindowFocusIn(xfe.get_serial());
            }
        }
    } else {
        if (// Normal notify
        xfe.get_mode() == XConstants.NotifyNormal || // Alt-Tab notify
        xfe.get_mode() == XConstants.NotifyWhileGrabbed) {
            // If this window is non-focusable don't post any java focus event
            if (!isNativelyNonFocusableWindow()) {
                XWindowPeer oppositeXWindow = getNativeFocusedWindowPeer();
                Object oppositeTarget = (oppositeXWindow != null) ? oppositeXWindow.getTarget() : null;
                Window oppositeWindow = null;
                if (oppositeTarget instanceof Window) {
                    oppositeWindow = (Window) oppositeTarget;
                }
                // post any event.
                if (oppositeXWindow != null && oppositeXWindow.isNativelyNonFocusableWindow()) {
                    return;
                }
                if (this == oppositeXWindow) {
                    oppositeWindow = null;
                } else if (oppositeXWindow instanceof XDecoratedPeer) {
                    if (((XDecoratedPeer) oppositeXWindow).actualFocusedWindow != null) {
                        oppositeXWindow = ((XDecoratedPeer) oppositeXWindow).actualFocusedWindow;
                        oppositeTarget = oppositeXWindow.getTarget();
                        if (oppositeTarget instanceof Window && oppositeXWindow.isVisible() && oppositeXWindow.isNativelyNonFocusableWindow()) {
                            oppositeWindow = ((Window) oppositeTarget);
                        }
                    }
                }
                handleWindowFocusOut(oppositeWindow, xfe.get_serial());
            }
        }
    }
}
Also used : FocusEvent(java.awt.event.FocusEvent)

Aggregations

FocusEvent (java.awt.event.FocusEvent)81 FocusListener (java.awt.event.FocusListener)38 FocusAdapter (java.awt.event.FocusAdapter)33 JLabel (javax.swing.JLabel)21 ActionEvent (java.awt.event.ActionEvent)18 ActionListener (java.awt.event.ActionListener)17 JPanel (javax.swing.JPanel)15 JTextField (javax.swing.JTextField)15 Dimension (java.awt.Dimension)14 JButton (javax.swing.JButton)10 KeyEvent (java.awt.event.KeyEvent)9 JCheckBox (javax.swing.JCheckBox)9 BoxLayout (javax.swing.BoxLayout)8 JComboBox (javax.swing.JComboBox)8 Border (javax.swing.border.Border)8 Component (java.awt.Component)7 GridBagConstraints (java.awt.GridBagConstraints)6 GridBagLayout (java.awt.GridBagLayout)6 Insets (java.awt.Insets)6 MouseEvent (java.awt.event.MouseEvent)6