private void init() { CPanel panel = new CPanel(); panel.setLayout(new MigLayout()); getContentPane().add(panel); panel.add(new CLabel(Msg.translate(posPanel.getCtx(), "SalesRep_ID"))); username = new PosTextField( Msg.translate(posPanel.getCtx(), "SalesRep_ID"), posPanel, posPanel.p_pos.getOSK_KeyLayout_ID()); panel.add(username, "wrap"); panel.add(new CLabel(Msg.translate(posPanel.getCtx(), "UserPIN"))); pin = new PosTextField( Msg.translate(posPanel.getCtx(), "UserPIN"), posPanel, posPanel.p_pos.getOSNP_KeyLayout_ID()); panel.add(pin, ""); AppsAction act = new AppsAction("Ok", KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), false); act.setDelegate(this); bProcess = (CButton) act.getButton(); bProcess.setFocusable(false); panel.add(bProcess, "h 50!, w 50!"); pack(); }
/** * Create Action Button * * @param action action * @return button */ protected CButton createButtonAction(String action, KeyStroke accelerator) { AppsAction act = new AppsAction(action, accelerator, false); act.setDelegate(this); CButton button = (CButton) act.getButton(); button.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); button.setMinimumSize(getPreferredSize()); button.setMaximumSize(getPreferredSize()); button.setFocusable(false); return button; } // getButtonAction
/** * Sets initial answer (i.e. button that will be preselected by default). * * <p>Please note that this is not the default answer that will be returned by {@link * #getReturnCode()} if user does nothing (i.e. closes the window). It is just the preselectated * button. * * @param initialAnswer {@link #A_OK}, {@link #A_CANCEL}. */ public void setInitialAnswer(final int initialAnswer) { // If the inial answer did not actual changed, do nothing if (this._initialAnswer == initialAnswer) { return; } // // Configure buttons accelerator (KeyStroke) and RootPane's default button final JRootPane rootPane = getRootPane(); final CButton okButton = confirmPanel.getOKButton(); final AppsAction okAction = (AppsAction) okButton.getAction(); final CButton cancelButton = confirmPanel.getCancelButton(); final AppsAction cancelAction = (AppsAction) cancelButton.getAction(); if (initialAnswer == A_OK) { okAction.setDefaultAccelerator(); cancelAction.setDefaultAccelerator(); rootPane.setDefaultButton(okButton); } else if (initialAnswer == A_CANCEL) { // NOTE: we need to set the OK's Accelerator keystroke to null because in most of the cases it // is "Enter" // and we want to prevent user for hiting ENTER by mistake okAction.setAccelerator(null); cancelAction.setDefaultAccelerator(); rootPane.setDefaultButton(cancelButton); } else { throw new IllegalArgumentException("Unknown inital answer: " + initialAnswer); } // // Finally, set the new inial answer this._initialAnswer = initialAnswer; }