List of usage examples for javax.swing JComponent WHEN_IN_FOCUSED_WINDOW
int WHEN_IN_FOCUSED_WINDOW
To view the source code for javax.swing JComponent WHEN_IN_FOCUSED_WINDOW.
Click Source Link
registerKeyboardAction
that means that the command should be invoked when the receiving component is in the window that has the focus or is itself the focused component. From source file:net.sf.jabref.gui.entryeditor.EntryEditor.java
private void setupToolBar() { JPanel leftPan = new JPanel(); leftPan.setLayout(new BorderLayout()); JToolBar toolBar = new OSXCompatibleToolbar(SwingConstants.VERTICAL); toolBar.setBorder(null);// w w w . ja v a2s.c o m toolBar.setRollover(true); toolBar.setMargin(new Insets(0, 0, 0, 2)); // The toolbar carries all the key bindings that are valid for the whole // window. ActionMap actionMap = toolBar.getActionMap(); InputMap inputMap = toolBar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_ENTRY_EDITOR), "close"); actionMap.put("close", closeAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_STORE_FIELD), "store"); actionMap.put("store", getStoreFieldAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.AUTOGENERATE_BIBTEX_KEYS), "generateKey"); actionMap.put("generateKey", getGenerateKeyAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.AUTOMATICALLY_LINK_FILES), "autoLink"); actionMap.put("autoLink", autoLinkAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_ENTRY), "prev"); actionMap.put("prev", getPrevEntryAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_ENTRY), "next"); actionMap.put("next", getNextEntryAction()); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.UNDO), "undo"); actionMap.put("undo", undoAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.REDO), "redo"); actionMap.put("redo", redoAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help"); actionMap.put("help", getHelpAction()); toolBar.setFloatable(false); // Add actions (and thus buttons) JButton closeBut = new JButton(closeAction); closeBut.setText(null); closeBut.setBorder(null); closeBut.setMargin(new Insets(8, 0, 8, 0)); leftPan.add(closeBut, BorderLayout.NORTH); // Create type-label TypedBibEntry typedEntry = new TypedBibEntry(entry, Optional.empty(), panel.getBibDatabaseContext().getMode()); leftPan.add(new TypeLabel(typedEntry.getTypeForDisplay()), BorderLayout.CENTER); TypeButton typeButton = new TypeButton(); toolBar.add(typeButton); toolBar.add(getGenerateKeyAction()); toolBar.add(autoLinkAction); toolBar.add(writeXmp); toolBar.addSeparator(); toolBar.add(deleteAction); toolBar.add(getPrevEntryAction()); toolBar.add(getNextEntryAction()); toolBar.addSeparator(); toolBar.add(getHelpAction()); Component[] comps = toolBar.getComponents(); for (Component comp : comps) { ((JComponent) comp).setOpaque(false); } leftPan.add(toolBar, BorderLayout.SOUTH); add(leftPan, BorderLayout.WEST); }
From source file:com.github.fritaly.dualcommander.DualCommander.java
public DualCommander() { // TODO Generate a fat jar at build time super(String.format("Dual Commander %s", Utils.getApplicationVersion())); if (logger.isInfoEnabled()) { logger.info(String.format("Dual Commander %s", Utils.getApplicationVersion())); }/*from w w w .j a v a 2 s.co m*/ try { // Apply the JGoodies L&F UIManager.setLookAndFeel(new WindowsLookAndFeel()); } catch (Exception e) { // Not supposed to happen } // Layout, columns & rows setLayout(new MigLayout("insets 0px", "[grow]0px[grow]", "[grow]0px[]")); // Create a menu bar final JMenu fileMenu = new JMenu("File"); fileMenu.add(new JMenuItem(preferencesAction)); fileMenu.add(new JSeparator()); fileMenu.add(new JMenuItem(quitAction)); final JMenu helpMenu = new JMenu("Help"); helpMenu.add(new JMenuItem(aboutAction)); final JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); menuBar.add(helpMenu); setJMenuBar(menuBar); this.leftPane = new TabbedPane(preferences); this.leftPane.setName("Left"); this.leftPane.addChangeListener(this); this.leftPane.addKeyListener(this); this.leftPane.addFocusListener(this); this.rightPane = new TabbedPane(preferences); this.rightPane.setName("Right"); this.rightPane.addChangeListener(this); this.rightPane.addKeyListener(this); this.rightPane.addFocusListener(this); // Adding the 2 components to the same sizegroup ensures they always // keep the same width getContentPane().add(leftPane, "grow, sizegroup g1"); getContentPane().add(rightPane, "grow, sizegroup g1, wrap"); // The 7 buttons must all have the same width (they must belong to the // same size group) final JPanel buttonPanel = new JPanel( new MigLayout("insets 0px", StringUtils.repeat("[grow, sizegroup g1]", 7), "[grow]")); buttonPanel.add(viewButton, "grow"); buttonPanel.add(editButton, "grow"); buttonPanel.add(copyButton, "grow"); buttonPanel.add(moveButton, "grow"); buttonPanel.add(mkdirButton, "grow"); buttonPanel.add(deleteButton, "grow"); buttonPanel.add(quitButton, "grow"); getContentPane().add(buttonPanel, "grow, span 2"); // Register shortcuts at a global level (not on every component) final InputMap inputMap = this.leftPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0, true), "view"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0, true), "edit"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0, true), "copy"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0, true), "move"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0, true), "mkdir"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0, true), "delete"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, KeyEvent.ALT_DOWN_MASK), "quit"); final ActionMap actionMap = this.leftPane.getActionMap(); actionMap.put("view", viewAction); actionMap.put("edit", editAction); actionMap.put("copy", copyAction); actionMap.put("move", moveAction); actionMap.put("mkdir", mkdirAction); actionMap.put("delete", deleteAction); actionMap.put("quit", quitAction); addWindowListener(this); addKeyListener(this); // Listen to preference change events this.preferences.addPropertyChangeListener(this); // Reload the last configuration and init the left & right panels // accordingly final Preferences prefs = Preferences.userNodeForPackage(this.getClass()); // The user preferences must be loaded first because they're needed to // init the UI this.preferences.init(prefs.node("user.preferences")); this.leftPane.init(prefs.node("left.panel")); this.rightPane.init(prefs.node("right.panel")); if (logger.isInfoEnabled()) { logger.info("Loaded preferences"); } // Init the buttons refreshButtons(this.leftPane.getActiveBrowser().getSelection()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setExtendedState(JFrame.MAXIMIZED_BOTH); if (logger.isInfoEnabled()) { logger.info("UI initialized"); } }
From source file:dk.dma.epd.ship.EPDShip.java
private void makeKeyBindings() { JPanel content = (JPanel) mainFrame.getContentPane(); InputMap inputMap = content.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); @SuppressWarnings("serial") Action zoomIn = new AbstractAction() { @Override/* w w w .j a va 2s . c o m*/ public void actionPerformed(ActionEvent actionEvent) { mainFrame.getChartPanel().doZoom(0.5f); } }; @SuppressWarnings("serial") Action zoomOut = new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { mainFrame.getChartPanel().doZoom(2f); } }; @SuppressWarnings("serial") Action centreOnShip = new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { mainFrame.saveCentreOnShip(); } }; @SuppressWarnings("serial") Action newRoute = new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { // newRouteBtn.requestFocusInWindow(); mainFrame.getTopPanel().activateNewRouteButton(); } }; @SuppressWarnings("serial") Action routes = new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { RouteManagerDialog routeManagerDialog = new RouteManagerDialog(mainFrame); routeManagerDialog.setVisible(true); } }; @SuppressWarnings("serial") Action ais = new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { mainFrame.getTopPanel().getAisDialog().setVisible(true); } }; @SuppressWarnings("serial") Action panUp = new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { mainFrame.getChartPanel().pan(1); } }; @SuppressWarnings("serial") Action panDown = new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { mainFrame.getChartPanel().pan(2); } }; @SuppressWarnings("serial") Action panLeft = new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { mainFrame.getChartPanel().pan(3); } }; @SuppressWarnings("serial") Action panRight = new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { mainFrame.getChartPanel().pan(4); } }; inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ADD, 0), "ZoomIn"); inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_SUBTRACT, 0), "ZoomOut"); inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, 0), "centre"); inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_UP, 0), "panUp"); inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DOWN, 0), "panDown"); inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_LEFT, 0), "panLeft"); inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_RIGHT, 0), "panRight"); inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_KP_UP, 0), "panUp"); inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_KP_DOWN, 0), "panDown"); inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_KP_LEFT, 0), "panLeft"); inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_KP_RIGHT, 0), "panRight"); inputMap.put(KeyStroke.getKeyStroke("control N"), "newRoute"); inputMap.put(KeyStroke.getKeyStroke("control R"), "routes"); inputMap.put(KeyStroke.getKeyStroke("control M"), "msi-nm"); inputMap.put(KeyStroke.getKeyStroke("control A"), "ais"); content.getActionMap().put("ZoomOut", zoomOut); content.getActionMap().put("ZoomIn", zoomIn); content.getActionMap().put("centre", centreOnShip); content.getActionMap().put("newRoute", newRoute); content.getActionMap().put("routes", routes); content.getActionMap().put("ais", ais); content.getActionMap().put("panUp", panUp); content.getActionMap().put("panDown", panDown); content.getActionMap().put("panLeft", panLeft); content.getActionMap().put("panRight", panRight); }
From source file:userinterface.graph.Histogram.java
/** * Generates the property dialog for a Histogram. Allows the user to select either a new or an exisitng Histogram * to plot data on// ww w .ja va 2s. co m * * @param defaultSeriesName * @param handler instance of {@link GUIGraphHandler} * @param minVal the min value in data cache * @param maxVal the max value in data cache * @return Either a new instance of a Histogram or an old one depending on what the user selects */ public static Pair<Histogram, SeriesKey> showPropertiesDialog(String defaultSeriesName, GUIGraphHandler handler, double minVal, double maxVal) { // make sure that the probabilities are valid if (maxVal > 1.0) maxVal = 1.0; if (minVal < 0.0) minVal = 0.0; // set properties for the dialog JDialog dialog = new JDialog(GUIPrism.getGUI(), "Histogram properties", true); dialog.setLayout(new BorderLayout()); JPanel p1 = new JPanel(new FlowLayout()); p1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Number of buckets")); JPanel p2 = new JPanel(new FlowLayout()); p2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Series name")); JSpinner buckets = new JSpinner(new SpinnerNumberModel(10, 5, Integer.MAX_VALUE, 1)); buckets.setToolTipText("Select the number of buckets for this Histogram"); // provides the ability to select a new or an old histogram to plot the series on JTextField seriesName = new JTextField(defaultSeriesName); JRadioButton newSeries = new JRadioButton("New Histogram"); JRadioButton existing = new JRadioButton("Existing Histogram"); newSeries.setSelected(true); JPanel seriesSelectPanel = new JPanel(); seriesSelectPanel.setLayout(new BoxLayout(seriesSelectPanel, BoxLayout.Y_AXIS)); JPanel seriesTypeSelect = new JPanel(new FlowLayout()); JPanel seriesOptionsPanel = new JPanel(new FlowLayout()); seriesTypeSelect.add(newSeries); seriesTypeSelect.add(existing); JComboBox<String> seriesOptions = new JComboBox<>(); seriesOptionsPanel.add(seriesOptions); seriesSelectPanel.add(seriesTypeSelect); seriesSelectPanel.add(seriesOptionsPanel); seriesSelectPanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Add series to")); // provides ability to select the min/max range of the plot JLabel minValsLabel = new JLabel("Min range:"); JSpinner minVals = new JSpinner(new SpinnerNumberModel(0.0, 0.0, minVal, 0.01)); minVals.setToolTipText("Does not allow value more than the min value in the probabilities"); JLabel maxValsLabel = new JLabel("Max range:"); JSpinner maxVals = new JSpinner(new SpinnerNumberModel(1.0, maxVal, 1.0, 0.01)); maxVals.setToolTipText("Does not allow value less than the max value in the probabilities"); JPanel minMaxPanel = new JPanel(); minMaxPanel.setLayout(new BoxLayout(minMaxPanel, BoxLayout.X_AXIS)); JPanel leftValsPanel = new JPanel(new BorderLayout()); JPanel rightValsPanel = new JPanel(new BorderLayout()); minMaxPanel.setBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Range")); leftValsPanel.add(minValsLabel, BorderLayout.WEST); leftValsPanel.add(minVals, BorderLayout.CENTER); rightValsPanel.add(maxValsLabel, BorderLayout.WEST); rightValsPanel.add(maxVals, BorderLayout.CENTER); minMaxPanel.add(leftValsPanel); minMaxPanel.add(rightValsPanel); // fill the old histograms in the property dialog boolean found = false; for (int i = 0; i < handler.getNumModels(); i++) { if (handler.getModel(i) instanceof Histogram) { seriesOptions.addItem(handler.getGraphName(i)); found = true; } } existing.setEnabled(found); seriesOptions.setEnabled(false); // the bottom panel JPanel options = new JPanel(new FlowLayout(FlowLayout.RIGHT)); JButton ok = new JButton("Plot"); JButton cancel = new JButton("Cancel"); // bind keyboard keys to plot and cancel buttons to improve usability ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok"); ok.getActionMap().put("ok", new AbstractAction() { private static final long serialVersionUID = -7324877661936685228L; @Override public void actionPerformed(ActionEvent e) { ok.doClick(); } }); cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "ok"); cancel.getActionMap().put("ok", new AbstractAction() { private static final long serialVersionUID = 2642213543774356676L; @Override public void actionPerformed(ActionEvent e) { cancel.doClick(); } }); //Action listener for the new series radio button newSeries.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (newSeries.isSelected()) { existing.setSelected(false); seriesOptions.setEnabled(false); buckets.setEnabled(true); buckets.setToolTipText("Select the number of buckets for this Histogram"); minVals.setEnabled(true); maxVals.setEnabled(true); } } }); //Action listener for the existing series radio button existing.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (existing.isSelected()) { newSeries.setSelected(false); seriesOptions.setEnabled(true); buckets.setEnabled(false); minVals.setEnabled(false); maxVals.setEnabled(false); buckets.setToolTipText("Number of buckets can't be changed on an existing Histogram"); } } }); //Action listener for the plot button ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); if (newSeries.isSelected()) { hist = new Histogram(); hist.setNumOfBuckets((int) buckets.getValue()); hist.setIsNew(true); } else if (existing.isSelected()) { String HistName = (String) seriesOptions.getSelectedItem(); hist = (Histogram) handler.getModel(HistName); hist.setIsNew(false); } key = hist.addSeries(seriesName.getText()); if (minVals.isEnabled() && maxVals.isEnabled()) { hist.setMinProb((double) minVals.getValue()); hist.setMaxProb((double) maxVals.getValue()); } } }); //Action listener for the cancel button cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); hist = null; } }); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { hist = null; } }); p1.add(buckets, BorderLayout.CENTER); p2.add(seriesName, BorderLayout.CENTER); options.add(ok); options.add(cancel); // add everything to the main panel of the dialog JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.add(seriesSelectPanel); mainPanel.add(p1); mainPanel.add(p2); mainPanel.add(minMaxPanel); // add main panel to the dialog dialog.add(mainPanel, BorderLayout.CENTER); dialog.add(options, BorderLayout.SOUTH); // set dialog properties dialog.setSize(320, 290); dialog.setLocationRelativeTo(GUIPrism.getGUI()); dialog.setVisible(true); // return the user selected Histogram with the properties set return new Pair<Histogram, SeriesKey>(hist, key); }
From source file:com.openbravo.pos.sales.JRetailPanelTakeAway.java
/** * Creates new form JTicketView//w w w. ja v a 2 s. c o m */ public JRetailPanelTakeAway() { initComponents(); tnbbutton = new ThumbNailBuilderPopularItems(110, 57, "com/openbravo/images/bluetoit.png"); TextListener txtL; // cusName = (JTextField) m_jCboCustName.getEditor().getEditorComponent(); // cusPhoneNo= (JTextField) m_jCboContactNo.getEditor().getEditorComponent(); itemName = (JTextField) m_jCboItemName.getEditor().getEditorComponent(); m_jTxtItemCode.setFocusable(true); // m_jTxtCustomerId.setFocusable(true); txtL = new TextListener(); // m_jCreditAllowed.setVisible(false); // m_jCreditAllowed.setSelected(false); // cusPhoneNo.addFocusListener(txtL); //cusName.addFocusListener(txtL); itemName.addFocusListener(txtL); Action doMorething = new AbstractAction() { public void actionPerformed(ActionEvent e) { // m_jPrice.setEnabled(true); // m_jPrice.setFocusable(true); m_jKeyFactory.setFocusable(true); m_jKeyFactory.setText(null); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { m_jKeyFactory.requestFocus(); } }); } }; // InputMap imap = m_jPrice.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); // imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_B, Event.CTRL_MASK), "doMorething"); // m_jPrice.getActionMap().put("doMorething",doMorething); // Action doLastBill = new AbstractAction() { // public void actionPerformed(ActionEvent e) { // m_jLastBillActionPerformed(e); // stateToZero(); // } // }; // InputMap imapLastBill = m_jLastBill.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); // imapLastBill.put(KeyStroke.getKeyStroke("F7"), "doLastBill"); // m_jLastBill.getActionMap().put("doLastBill",doLastBill); Action cashNoBill = new AbstractAction() { public void actionPerformed(ActionEvent e) { // cashPayment(3); // setPrinterOn(); } }; InputMap imapCashNoBill = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); imapCashNoBill.put(KeyStroke.getKeyStroke("F1"), "cashNoBill"); m_jAction.getActionMap().put("cashNoBill", cashNoBill); // }; Action cashReceipt = new AbstractAction() { public void actionPerformed(ActionEvent e) { // cashPayment(2); } }; InputMap imapCashReceipt = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); imapCashReceipt.put(KeyStroke.getKeyStroke("F2"), "cashReceipt"); m_jAction.getActionMap().put("cashReceipt", cashReceipt); Action docashPrint = new AbstractAction() { public void actionPerformed(ActionEvent e) { // cashPayment(1); } }; InputMap imapCashPrint = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); imapCashPrint.put(KeyStroke.getKeyStroke("F3"), "docashPrint"); m_jAction.getActionMap().put("docashPrint", docashPrint); Action doCardnobill = new AbstractAction() { public void actionPerformed(ActionEvent e) { //m_jCloseShiftActionPerformed(e); // cardPayment(1); } }; InputMap imapCardnoBill = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); imapCardnoBill.put(KeyStroke.getKeyStroke("F4"), "doCardnobill"); m_jAction.getActionMap().put("doCardnobill", doCardnobill); Action doNonChargablePrint = new AbstractAction() { public void actionPerformed(ActionEvent e) { try { closeTicketNonChargable(m_oTicket, m_oTicketExt, m_aPaymentInfo); } catch (BasicException ex) { logger.info("exception in closeTicketNonChargable" + ex.getMessage()); Logger.getLogger(JRetailPanelTakeAway.class.getName()).log(Level.SEVERE, null, ex); } } }; InputMap imapNonChargablePrint = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); imapNonChargablePrint.put(KeyStroke.getKeyStroke("F7"), "doNonChargablePrint"); m_jAction.getActionMap().put("doNonChargablePrint", doNonChargablePrint); Action doCreditreceipt = new AbstractAction() { public void actionPerformed(ActionEvent e) { // m_jCreditAmount.setText(Double.toString(m_oTicket.getTotal())); // // try { // closeCreditTicket(m_oTicket, m_oTicketExt, m_aPaymentInfo); // } catch (BasicException ex) { // Logger.getLogger(JRetailPanelTakeAway.class.getName()).log(Level.SEVERE, null, ex); // } } }; InputMap imapCreditReceipt = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); imapCreditReceipt.put(KeyStroke.getKeyStroke("F5"), "doCreditreceipt"); m_jAction.getActionMap().put("doCreditreceipt", doCreditreceipt); Action doHomeDeliveryNotPaid = new AbstractAction() { public void actionPerformed(ActionEvent e) { // m_jHomeDelivery.setSelected(true); if (getEditSale() == "Edit") { // getServiceCharge("Y"); printPartialTotals(); try { closeTicketHomeDelivery(m_oTicket, m_oTicketExt, m_aPaymentInfo); } catch (BasicException ex) { logger.info("exception in closeTicketHomeDelivery" + ex.getMessage()); Logger.getLogger(JRetailPanelTakeAway.class.getName()).log(Level.SEVERE, null, ex); } } } }; InputMap imapCardPrint = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); imapCardPrint.put(KeyStroke.getKeyStroke("F6"), "doHomeDeliveryNotPaid"); m_jAction.getActionMap().put("doHomeDeliveryNotPaid", doHomeDeliveryNotPaid); Action doLogout = new AbstractAction() { public void actionPerformed(ActionEvent e) { m_jLogoutActionPerformed(e); } }; InputMap imapLog = m_jLogout.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); imapLog.put(KeyStroke.getKeyStroke("F12"), "doLogout"); m_jLogout.getActionMap().put("doLogout", doLogout); Action doupArrow = new AbstractAction() { public void actionPerformed(ActionEvent e) { // m_jUpActionPerformed(e); } }; InputMap imapUpArrow = m_jPlus.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); imapUpArrow.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "doupArrow"); m_jPlus.getActionMap().put("doupArrow", doupArrow); // Action doCustomer = new AbstractAction() { // public void actionPerformed(ActionEvent e) { // //// m_jTxtCustomerId.setFocusable(true); // // // cusPhoneNo.setFocusable(true); // // cusName.setFocusable(true); // stateToBarcode(); // } // }; // InputMap imapCustomer= m_jTxtCustomerId.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); // imapCustomer.put(KeyStroke.getKeyStroke("F8"), "doCustomer"); // m_jTxtCustomerId.getActionMap().put("doCustomer", // doCustomer); Action doItem = new AbstractAction() { public void actionPerformed(ActionEvent e) { itemName.setFocusable(true); m_jTxtItemCode.setFocusable(true); stateToItem(); } }; InputMap imapItem = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); imapItem.put(KeyStroke.getKeyStroke("F9"), "doItem"); m_jAction.getActionMap().put("doItem", doItem); // Action doHomeDelivery = new AbstractAction() { // public void actionPerformed(ActionEvent e) { //// m_jHomeDelivery.setFocusable(true); // // m_jHomeDelivery.setSelected(true); // // m_jHomeDeliveryActionPerformed(e); // // m_jTxtAdvance.setFocusable(true); // stateToHomeDelivery(); // } // }; // // InputMap imapHomeDelivery= m_jHomeDelivery.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); // imapHomeDelivery.put(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.ALT_MASK), "doHomeDelivery"); // m_jHomeDelivery.getActionMap().put("doHomeDelivery", // doHomeDelivery); // Action doPayment = new AbstractAction() { public void actionPerformed(ActionEvent e) { // m_jCash.setFocusable(true); // m_jCard.setFocusable(true); // m_jCheque.setFocusable(true); // m_jtxtChequeNo.setFocusable(true); // m_jFoodCoupon.setFocusable(true); // m_jVoucher.setFocusable(true); // m_jCreditAmount.setFocusable(true); stateToPayment(); } }; InputMap imapPayment = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); imapPayment.put(KeyStroke.getKeyStroke("F11"), "doPayment"); m_jAction.getActionMap().put("doPayment", doPayment); Action doDownpArrow = new AbstractAction() { public void actionPerformed(ActionEvent e) { // m_jDownActionPerformed(e); } }; InputMap imapArrow = m_jMinus.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); imapArrow.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "doDownpArrow"); m_jMinus.getActionMap().put("doDownpArrow", doDownpArrow); itemName.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (!itemName.getText().equals("") || !itemName.getText().equals(null)) { incProductByItemDetails(pdtId); // itemName.setText(""); // m_jCboItemName.setSelectedIndex(-1); ArrayList<String> itemCode = new ArrayList<String>(); ArrayList<String> itemName1 = new ArrayList<String>(); vItemName.removeAllElements(); try { productListDetails = (ArrayList<ProductInfoExt>) dlSales.getProductDetails(); } catch (BasicException ex) { Logger.getLogger(JRetailPanelTakeAway.class.getName()).log(Level.SEVERE, null, ex); } for (ProductInfoExt product : productListDetails) { itemCode.add(product.getItemCode()); itemName1.add(product.getName()); } String[] productName = itemName1.toArray(new String[itemName1.size()]); for (int i = 0; i < itemName1.size(); i++) { vItemName.addElement(productName[i]); } itemName = (JTextField) m_jCboItemName.getEditor().getEditorComponent(); } else { pdtId = ""; ArrayList<String> itemCode = new ArrayList<String>(); ArrayList<String> itemName1 = new ArrayList<String>(); vItemName.removeAllElements(); try { productListDetails = (ArrayList<ProductInfoExt>) dlSales.getProductDetails(); } catch (BasicException ex) { Logger.getLogger(JRetailPanelTakeAway.class.getName()).log(Level.SEVERE, null, ex); } for (ProductInfoExt product : productListDetails) { itemCode.add(product.getItemCode()); itemName1.add(product.getName()); } String[] productName = itemName1.toArray(new String[itemName1.size()]); for (int i = 0; i < itemName1.size(); i++) { vItemName.addElement(productName[i]); } itemName = (JTextField) m_jCboItemName.getEditor().getEditorComponent(); } } }); }
From source file:com.pianobakery.complsa.MainGui.java
public MainGui() { $$$setupUI$$$();/* ww w. j a va 2 s.co m*/ runtimeParameters(); trainCorp = new HashMap<String, File>(); trainSentModels = new HashMap<String, File>(); indexFilesModel = new HashMap<String, File>(); searchCorpusModel = new HashMap<String, File>(); selDocdirContent = new ArrayList<File>(); langModelsText.setText("None"); posIndRadiusTextField.setEnabled(false); //Disable all Components as long as wDir is not set. enableUIElements(false); ButtonGroup selSearchGroup = new ButtonGroup(); selSearchGroup.add(searchSearchCorpRadioButton); selSearchGroup.add(searchTopCorpRadioButton); ButtonGroup searchSelGroup = new ButtonGroup(); searchSelGroup.add(selTextRadioButton); searchSelGroup.add(selDocRadioButton); //licenseKeyGUI = new LicenseKeyGUI(frame, true); //Added to get the docSearchTable the focus when opening the Reader without selecting something so up down button will work frame.addWindowFocusListener(new WindowAdapter() { public void windowGainedFocus(WindowEvent e) { docSearchResTable.requestFocusInWindow(); } }); frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "CTRL + S"); frame.getRootPane().getActionMap().put("CTRL + S", runSearch()); frame.addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent evt) { formWindowOpened(evt); } }); //Needs to get a white background in the termtableview (only in windows) termTablePane.getViewport().setBackground(Color.WHITE); //Project Page //Project Folder newFolderButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { newFolderMethod(); } }); selectFolderButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectFolderMethod(); } }); //Download Language Models downloadModelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { downloadModelMethod(); } }); //Add-Remove Topic Corpus addTopicCorpusButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { addTopicCorpusMethod(); } }); selectTrainCorp.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { frame.setTitle("Selected Training Corpus: " + selectTrainCorp.getSelectedItem() + " and " + "Sel. Search Corpus: " + searchCorpComboBox.getSelectedItem()); algTextField.setText("Knowledge Corpus: " + selectTrainCorp.getSelectedItem()); try { updateIndexFileFolder(); } catch (IOException e1) { e1.printStackTrace(); } } }); removeTopicCorpusButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) throws ArrayIndexOutOfBoundsException { removeTopicCorpusMethod(); } }); //Update and remove Index updateIndexButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateIndexMethod(); } }); removeIndexButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { removeIndexMethod(); } }); //Train Semantic trainCorpButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { trainCorpMethod(); } }); indexTypeComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (indexTypeComboBox.getSelectedIndex() == 2) { logger.debug("Enable indexType Combo with Index: " + indexTypeComboBox.getSelectedIndex()); posIndRadiusTextField.setEnabled(true); return; } logger.debug("Disable indexType Combo with Index: " + indexTypeComboBox.getSelectedIndex()); posIndRadiusTextField.setEnabled(false); } }); //Import and remove Search Corpora impSearchCorpButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { impSearchCorpMethod(); } }); searchCorpComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { frame.setTitle("Selected Training Corpus: " + selectTrainCorp.getSelectedItem() + " and " + "Sel. Search Corpus: " + searchCorpComboBox.getSelectedItem()); } }); removeSearchCorpButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) throws ArrayIndexOutOfBoundsException { removeSearchCorpMethod(); } }); //Search Page //Choose Index Type selectIndexTypeComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (searchModelList.isEmpty()) { return; } if (searchModelList.get(selectIndexTypeComboBox.getSelectedItem()) == null) { return; } List<String> theList = searchModelList.get(selectIndexTypeComboBox.getSelectedItem().toString()); selectTermweightComboBox.removeAllItems(); for (String aTFItem : theList) { selectTermweightComboBox.addItem(aTFItem); } getSelectedSearchModelFiles(); } }); selectTermweightComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (searchModelList.isEmpty()) { return; } if (searchModelList.get(selectIndexTypeComboBox.getSelectedItem()) == null) { return; } getSelectedSearchModelFiles(); } }); //Select Search Type selTextRadioButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectDocumentButton.setEnabled(false); searchTextArea.setEnabled(true); //searchDocValue.setText("nothing selected"); } }); selDocRadioButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectDocumentButton.setEnabled(true); searchTextArea.setText(null); searchTextArea.setEnabled(false); } }); selectDocumentButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { importSearchFile(); openSearchDocumentButton.setEnabled(true); } }); openSearchDocumentButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (searchDocReader == null) { searchDocReader = getReaderLater(null, maingui); searchDocReader.setSearchTerms(getSelectedTermTableWords()); } else if (!searchDocReader.getFrameVisible()) { searchDocReader.setFrameVisible(true); searchDocReader.setSearchTerms(getSelectedTermTableWords()); } searchDocReader.setDocumentText(searchFileString); searchDocReader.setSelFullDocLabel(searchDocValue.toString()); searchDocReader.setViewPane(2); searchDocReader.disableComponents(); searchDocReader.setSearchTerms(getSelectedTermTableWords()); } }); //Search Button searchButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { searchMethod(); } }); //Table Listeners docSearchResTable.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { JTable table = (JTable) me.getSource(); Point p = me.getPoint(); int row = docSearchResTable.rowAtPoint(p); if (docSearchResModel == null || docSearchResModel.getRowCount() == 0 || docSearchResModel.getDocFile(0).getFileName().equals(emptyTable)) { return; } switch (me.getClickCount()) { case 1: if (row == -1) { break; } if (docSearchResTable.getRowCount() > 0) { logger.debug("Single click Doc: " + ((DocSearchModel) docSearchResTable.getModel()) .getDocSearchFile(row).getFile().toString()); fillMetaDataField( ((DocSearchModel) docSearchResTable.getModel()).getDocSearchFile(row).getFile()); if (reader != null) { reader.setSearchTerms(getSelectedTermTableWords()); } if (searchDocReader != null) { searchDocReader.setSearchTerms(getSelectedTermTableWords()); } setSelReaderContent(); setDocReaderContent(0); if (reader != null) { reader.setSearchTerms(getSelectedTermTableWords()); } if (searchDocReader != null) { searchDocReader.setSearchTerms(getSelectedTermTableWords()); } } break; case 2: if (row == -1) { break; } if (docSearchResTable.getRowCount() > 0) { logger.debug("Double click Doc: " + ((DocSearchModel) docSearchResTable.getModel()) .getDocSearchFile(row).getFile().toString()); fillMetaDataField( ((DocSearchModel) docSearchResTable.getModel()).getDocSearchFile(row).getFile()); if (reader == null) { reader = getReaderLater((DocSearchModel) docSearchResTable.getModel(), maingui); reader.setSearchTerms(getSelectedTermTableWords()); } else if (!reader.getFrameVisible()) { reader.setFrameVisible(true); reader.setSearchTerms(getSelectedTermTableWords()); } setSelReaderContent(); setDocReaderContent(0); if (reader != null) { reader.setSearchTerms(getSelectedTermTableWords()); } if (searchDocReader != null) { searchDocReader.setSearchTerms(getSelectedTermTableWords()); } } break; } } }); termSearchResTable.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { JTable table = (JTable) me.getSource(); Point p = me.getPoint(); int row = docSearchResTable.rowAtPoint(p); if (termSearchResTable.getModel() == null || termSearchResTable.getRowCount() == 0 || termSearchResTable.getModel().getValueAt(row, 1).equals(emptyTable)) { return; } switch (me.getClickCount()) { case 1: logger.debug("Single click Term: " + termSearchResTable.getModel().getValueAt(row, 1)); logger.debug("Selected Terms: " + Arrays.toString(getSelectedTermTableWords())); if (reader != null) { reader.setSearchTerms(getSelectedTermTableWords()); } if (searchDocReader != null) { searchDocReader.setSearchTerms(getSelectedTermTableWords()); } break; case 2: logger.debug("Double click Term: " + termSearchResTable.getModel().getValueAt(row, 1)); if (reader != null) { reader.setSearchTerms(getSelectedTermTableWords()); } if (searchDocReader != null) { searchDocReader.setSearchTerms(getSelectedTermTableWords()); } break; } } }); docSearchResTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent event) { if (docSearchResModel == null || docSearchResModel.getRowCount() == 0 || docSearchResModel.getDocFile(0).getFileName().equals(emptyTable)) { return; } if (docSearchResTable.getSelectedRow() > -1) { // print first column value from selected row logger.debug("KeyboardSelection: " + ((DocSearchModel) docSearchResTable.getModel()) .getDocSearchFile( docSearchResTable.convertRowIndexToModel(docSearchResTable.getSelectedRow())) .getFile().toString()); fillMetaDataField(((DocSearchModel) docSearchResTable.getModel()) .getDocSearchFile( docSearchResTable.convertRowIndexToModel(docSearchResTable.getSelectedRow())) .getFile()); setSelReaderContent(); setDocReaderContent(0); if (reader != null) { reader.setSearchTerms(getSelectedTermTableWords()); } if (searchDocReader != null) { searchDocReader.setSearchTerms(getSelectedTermTableWords()); } } } }); termSearchResTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (termSearchResTable.getModel() == null || termSearchResTable.getRowCount() == 0 || termSearchResTable.getModel().getValueAt(0, 1).equals(emptyTable)) { return; } if (termSearchResTable.getSelectedRow() > -1) { // print first column value from selected row if (reader != null) { reader.setSearchTerms(getSelectedTermTableWords()); } if (searchDocReader != null) { searchDocReader.setSearchTerms(getSelectedTermTableWords()); } } } }); }
From source file:edu.umich.robot.GuiApplication.java
/** * <p>/*from www .j a v a2 s .co m*/ * Pops up a window to create a new splinter robot to add to the simulation. */ public void createSplinterRobotDialog() { final Pose pose = new Pose(); FormLayout layout = new FormLayout("right:pref, 4dlu, 30dlu, 4dlu, right:pref, 4dlu, 30dlu", "pref, 2dlu, pref, 2dlu, pref"); layout.setRowGroups(new int[][] { { 1, 3 } }); final JDialog dialog = new JDialog(frame, "Create Splinter Robot", true); dialog.setLayout(layout); final JTextField name = new JTextField(); final JTextField x = new JTextField(Double.toString((pose.getX()))); final JTextField y = new JTextField(Double.toString((pose.getY()))); final JButton cancel = new JButton("Cancel"); final JButton ok = new JButton("OK"); CellConstraints cc = new CellConstraints(); dialog.add(new JLabel("Name"), cc.xy(1, 1)); dialog.add(name, cc.xyw(3, 1, 5)); dialog.add(new JLabel("x"), cc.xy(1, 3)); dialog.add(x, cc.xy(3, 3)); dialog.add(new JLabel("y"), cc.xy(5, 3)); dialog.add(y, cc.xy(7, 3)); dialog.add(cancel, cc.xyw(1, 5, 3)); dialog.add(ok, cc.xyw(5, 5, 3)); x.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { try { pose.setX(Double.parseDouble(x.getText())); } catch (NumberFormatException ex) { x.setText(Double.toString(pose.getX())); } } }); y.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { try { pose.setY(Double.parseDouble(y.getText())); } catch (NumberFormatException ex) { y.setText(Double.toString(pose.getX())); } } }); final ActionListener okListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String robotName = name.getText().trim(); if (robotName.isEmpty()) { logger.error("Create splinter: robot name empty"); return; } for (char c : robotName.toCharArray()) if (!Character.isDigit(c) && !Character.isLetter(c)) { logger.error("Create splinter: illegal robot name"); return; } controller.createSplinterRobot(robotName, pose, true); controller.createSimSplinter(robotName); controller.createSimLaser(robotName); dialog.dispose(); } }; name.addActionListener(okListener); x.addActionListener(okListener); y.addActionListener(okListener); ok.addActionListener(okListener); ActionListener cancelAction = new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; cancel.addActionListener(cancelAction); dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); dialog.setLocationRelativeTo(frame); dialog.pack(); dialog.setVisible(true); }
From source file:edu.ku.brc.af.ui.forms.ResultSetController.java
/** * Sets the current (or focused ResultSetController) into the action btns. * @param rsc ResultSetController/*from ww w . java2 s . c o m*/ */ protected static void installRS(final ResultSetController rsc) { if (commandsHash == null && rsc != null) { rsc.createRSActions(); } if (commandsHash != null) { for (RSAction<CommandType> rsca : commandsHash.values()) { rsca.setRs(rsc); if (rsc != null) { JButton btn = rsc.btnsHash.get(rsca.getType()); if (btn != null) { KeyStroke ks = UIHelper.getKeyStroke(rsca.getType()); String ACTION_KEY = rsca.getType().toString(); InputMap inputMap = btn.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); ActionMap actionMap = btn.getActionMap(); inputMap.put(ks, ACTION_KEY); actionMap.put(ACTION_KEY, rsca); rsca.setBtn(btn); } else { //System.err.println("Btn for ["+rsca.getType()+"] is null"); } } } } }
From source file:edu.umich.robot.GuiApplication.java
public void createSuperdroidRobotDialog() { final Pose pose = new Pose(); FormLayout layout = new FormLayout("right:pref, 4dlu, 30dlu, 4dlu, right:pref, 4dlu, 30dlu", "pref, 2dlu, pref, 2dlu, pref"); layout.setRowGroups(new int[][] { { 1, 3 } }); final JDialog dialog = new JDialog(frame, "Create Superdroid Robot", true); dialog.setLayout(layout);//from w w w. j a v a 2s . co m final JTextField name = new JTextField(); final JTextField x = new JTextField(Double.toString((pose.getX()))); final JTextField y = new JTextField(Double.toString((pose.getY()))); final JButton cancel = new JButton("Cancel"); final JButton ok = new JButton("OK"); CellConstraints cc = new CellConstraints(); dialog.add(new JLabel("Name"), cc.xy(1, 1)); dialog.add(name, cc.xyw(3, 1, 5)); dialog.add(new JLabel("x"), cc.xy(1, 3)); dialog.add(x, cc.xy(3, 3)); dialog.add(new JLabel("y"), cc.xy(5, 3)); dialog.add(y, cc.xy(7, 3)); dialog.add(cancel, cc.xyw(1, 5, 3)); dialog.add(ok, cc.xyw(5, 5, 3)); x.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { try { pose.setX(Double.parseDouble(x.getText())); } catch (NumberFormatException ex) { x.setText(Double.toString(pose.getX())); } } }); y.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { try { pose.setY(Double.parseDouble(y.getText())); } catch (NumberFormatException ex) { y.setText(Double.toString(pose.getX())); } } }); final ActionListener okListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String robotName = name.getText().trim(); if (robotName.isEmpty()) { logger.error("Create Superdroid: robot name empty"); return; } for (char c : robotName.toCharArray()) if (!Character.isDigit(c) && !Character.isLetter(c)) { logger.error("Create Superdroid: illegal robot name"); return; } controller.createSuperdroidRobot(robotName, pose, true); controller.createSimSuperdroid(robotName); dialog.dispose(); } }; name.addActionListener(okListener); x.addActionListener(okListener); y.addActionListener(okListener); ok.addActionListener(okListener); ActionListener cancelAction = new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; cancel.addActionListener(cancelAction); dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); dialog.setLocationRelativeTo(frame); dialog.pack(); dialog.setVisible(true); }
From source file:com.net2plan.gui.tools.GUINetworkDesign.java
private void addAllKeyCombinationActions() { addKeyCombinationAction("Resets the tool", new AbstractAction() { @Override//from w w w.j a v a 2 s . com public void actionPerformed(ActionEvent e) { resetButton(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK)); addKeyCombinationAction("Outputs current design to console", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { System.out.println(getDesign().toString()); } }, KeyStroke.getKeyStroke(KeyEvent.VK_F11, InputEvent.CTRL_DOWN_MASK)); /* FROM THE OFFLINE ALGORITHM EXECUTION */ addKeyCombinationAction("Execute algorithm", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { executionPane.doClickInExecutionButton(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_E, KeyEvent.CTRL_DOWN_MASK)); /* From the TOPOLOGY PANEL */ addKeyCombinationAction("Load design", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { topologyPanel.loadDesign(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK)); addKeyCombinationAction("Save design", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { topologyPanel.saveDesign(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); addKeyCombinationAction("Zoom in", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (topologyPanel.getSize().getWidth() != 0 && topologyPanel.getSize().getHeight() != 0) topologyPanel.getCanvas().zoomIn(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ADD, InputEvent.CTRL_DOWN_MASK), KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, InputEvent.CTRL_DOWN_MASK)); addKeyCombinationAction("Zoom out", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (topologyPanel.getSize().getWidth() != 0 && topologyPanel.getSize().getHeight() != 0) topologyPanel.getCanvas().zoomOut(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, InputEvent.CTRL_DOWN_MASK), KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, InputEvent.CTRL_DOWN_MASK)); addKeyCombinationAction("Zoom all", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (topologyPanel.getSize().getWidth() != 0 && topologyPanel.getSize().getHeight() != 0) topologyPanel.getCanvas().zoomAll(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_MULTIPLY, InputEvent.CTRL_DOWN_MASK)); addKeyCombinationAction("Take snapshot", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { topologyPanel.takeSnapshot(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_F12, InputEvent.CTRL_DOWN_MASK)); addKeyCombinationAction("Load traffic demands", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { topologyPanel.loadTrafficDemands(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_DOWN_MASK)); /* FROM REPORT */ addKeyCombinationAction("Close selected report", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { int tab = reportPane.getReportContainer().getSelectedIndex(); if (tab == -1) return; reportPane.getReportContainer().remove(tab); } }, KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK)); addKeyCombinationAction("Close all reports", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { reportPane.getReportContainer().removeAll(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); /* Online simulation */ addKeyCombinationAction("Run simulation", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { try { if (onlineSimulationPane.isRunButtonEnabled()) onlineSimulationPane.runSimulation(false); } catch (Net2PlanException ex) { if (ErrorHandling.isDebugEnabled()) ErrorHandling.addErrorOrException(ex, OnlineSimulationPane.class); ErrorHandling.showErrorDialog(ex.getMessage(), "Error executing simulation"); } catch (Throwable ex) { ErrorHandling.addErrorOrException(ex, OnlineSimulationPane.class); ErrorHandling.showErrorDialog("An error happened"); } } }, KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_DOWN_MASK)); // Windows addKeyCombinationAction("Show control window", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { WindowController.showTablesWindow(true); } }, KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK + ActionEvent.SHIFT_MASK)); viewEditTopTables.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)); viewEditTopTables.setActionMap(this.getActionMap()); reportPane.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)); reportPane.setActionMap(this.getActionMap()); executionPane.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)); executionPane.setActionMap(this.getActionMap()); onlineSimulationPane.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)); onlineSimulationPane.setActionMap(this.getActionMap()); whatIfAnalysisPane.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)); whatIfAnalysisPane.setActionMap(this.getActionMap()); }