public TaskbarPositionTest() { super("Use CTRL-down to show a JPopupMenu"); setContentPane(panel = createContentPane()); setJMenuBar(createMenuBar("1 - First Menu", true)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // CTRL-down will show the popup. panel .getInputMap() .put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.CTRL_MASK), "OPEN_POPUP"); panel.getActionMap().put("OPEN_POPUP", new PopupHandler()); pack(); Toolkit toolkit = Toolkit.getDefaultToolkit(); fullScreenBounds = new Rectangle(new Point(), toolkit.getScreenSize()); screenBounds = new Rectangle(new Point(), toolkit.getScreenSize()); // Place the frame near the bottom. This is a pretty wild guess. this.setLocation(0, (int) screenBounds.getHeight() - 2 * this.getHeight()); // Reduce the screen bounds by the insets. GraphicsConfiguration gc = this.getGraphicsConfiguration(); if (gc != null) { Insets screenInsets = toolkit.getScreenInsets(gc); screenBounds = gc.getBounds(); screenBounds.width -= (screenInsets.left + screenInsets.right); screenBounds.height -= (screenInsets.top + screenInsets.bottom); screenBounds.x += screenInsets.left; screenBounds.y += screenInsets.top; } setVisible(true); }
public ActionFrame() { setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); buttonPanel = new JPanel(); // define actions Action yellowAction = new ColorAction("Yellow", new ImagIcon("yellow-ball.gif"), Color.YELLOW); Action blueAction = new ColorAction("Blue", new ImageIcon("blue-ball.gif"), Color.BLUE); Action redAction = new ColorAction("Red", new ImageIcon("red-ball.gif"), Color.RED); // add buttons for these actions buttonPanel.add(new JButton(yellowAction)); buttonPanel.add(new JButton(blueAction)); buttonPanel.add(new JButton(recAction)); // add panel to frame add(buttonPanel); // associate the Y, B, and R keys with names InputMap imap = buttonPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); imap.put(KeyStroke.getKeyStroke("ctrl Y"), "panel.yellow"); imap.put(KeyStroke.getKeyStroke("Ctrl B"), "panel.blue"); imap.put(KeyStroke.getKeyStroke("ctrl R"), "panel.red"); // associate the names with actions ActionMap amap = buttonPanel.getActionMap(); amap.put("panel.yellow", yellowAction); amap.put("panel.blue", blueAction); amap.put("panel.red", redAction); }
/** * @param wizardModel The overall wizard data model containing the aggregate information of all * components in the wizard * @param isExiting True if the exit button should trigger an application shutdown * @param wizardParameter An optional parameter that can be referenced during construction * @param escapeIsCancel If true, ESC cancels the wizard, if false, it does nothing */ protected AbstractWizard( M wizardModel, boolean isExiting, Optional wizardParameter, boolean escapeIsCancel) { Preconditions.checkNotNull(wizardModel, "'model' must be present"); log.debug("Building wizard..."); this.wizardModel = wizardModel; this.exiting = isExiting; this.wizardParameter = wizardParameter; // Subscribe to events ViewEvents.subscribe(this); CoreEvents.subscribe(this); // Optionally bind the ESC key to a Cancel event (escape to safety) if (escapeIsCancel) { wizardScreenHolder .getInputMap(JPanel.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "quit"); wizardScreenHolder.getActionMap().put("quit", getCancelAction()); } // TODO Bind the ENTER key to a Next/Finish/Apply event to speed up data entry through keyboard // wizardPanel.getInputMap(JPanel.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "next"); // wizardPanel.getActionMap().put("next", getNextAction(null)); log.debug("Populating view map and firing initial state view events..."); // Populate based on the current locale populateWizardViewMap(wizardViewMap); // Once all the views are created allow events to occur for (Map.Entry<String, AbstractWizardPanelView> entry : wizardViewMap.entrySet()) { // Ensure the panel is in the correct starting state entry.getValue().fireInitialStateViewEvents(); } wizardScreenHolder.setMinimumSize( new Dimension(MultiBitUI.WIZARD_MIN_WIDTH, MultiBitUI.WIZARD_MIN_HEIGHT)); wizardScreenHolder.setPreferredSize( new Dimension(MultiBitUI.WIZARD_MIN_WIDTH, MultiBitUI.WIZARD_MIN_HEIGHT)); wizardScreenHolder.setSize( new Dimension(MultiBitUI.WIZARD_MIN_WIDTH, MultiBitUI.WIZARD_MIN_HEIGHT)); // Show the panel specified by the initial state show(wizardModel.getPanelName()); }
private Container createReturnPane() { // Create return button returnButton = new JButton(returnAction); // Create text fields retISBN = new JTextField(15); retCustID = new JTextField(15); // Create panel and layout JPanel pane = new JPanel(); pane.setOpaque(false); GridBagLayout gb = new GridBagLayout(); pane.setLayout(gb); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(1, 5, 1, 5); // Fill panel c.anchor = GridBagConstraints.EAST; addToGridBag(gb, c, pane, new JLabel("ISBN:"), 0, 0, 1, 1); addToGridBag(gb, c, pane, new JLabel("Customer ID:"), 0, 1, 1, 1); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.HORIZONTAL; addToGridBag(gb, c, pane, retISBN, 1, 0, 3, 1); addToGridBag(gb, c, pane, retCustID, 1, 1, 3, 1); c.fill = GridBagConstraints.NONE; addToGridBag(gb, c, pane, returnButton, 4, 0, 1, 3); // Set up VK_ENTER triggering the return button in this panel InputMap input = pane.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); input.put(getKeyStroke("ENTER"), "returnAction"); pane.getActionMap().put("returnAction", returnAction); return pane; }
private void initGui() { Container pane = getContentPane(); pane.setLayout(new BorderLayout()); biblatexMode = Globals.prefs.getBoolean("biblatexMode"); JPanel main = new JPanel(), buttons = new JPanel(), right = new JPanel(); main.setLayout(new BorderLayout()); right.setLayout(new GridLayout(biblatexMode ? 2 : 1, 2)); java.util.List<String> entryTypes = new ArrayList<String>(); for (String s : BibtexEntryType.ALL_TYPES.keySet()) { entryTypes.add(s); } typeComp = new EntryTypeList(entryTypes); typeComp.addListSelectionListener(this); typeComp.addAdditionActionListener(this); typeComp.addDefaultActionListener(new DefaultListener()); typeComp.setListSelectionMode(ListSelectionModel.SINGLE_SELECTION); // typeComp.setEnabled(false); reqComp = new FieldSetComponent( Globals.lang("Required fields"), new ArrayList<String>(), preset, true, true); reqComp.setEnabled(false); reqComp.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); ListDataListener dataListener = new DataListener(); reqComp.addListDataListener(dataListener); optComp = new FieldSetComponent( Globals.lang("Optional fields"), new ArrayList<String>(), preset, true, true); optComp.setEnabled(false); optComp.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); optComp.addListDataListener(dataListener); right.add(reqComp); right.add(optComp); if (biblatexMode) { optComp2 = new FieldSetComponent( Globals.lang("Optional fields") + " 2", new ArrayList<String>(), preset, true, true); optComp2.setEnabled(false); optComp2.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); optComp2.addListDataListener(dataListener); right.add(new JPanel()); right.add(optComp2); } // right.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), // Globals.lang("Fields"))); right.setBorder(BorderFactory.createEtchedBorder()); ok = new JButton("Ok"); cancel = new JButton(Globals.lang("Cancel")); apply = new JButton(Globals.lang("Apply")); ok.addActionListener(this); apply.addActionListener(this); cancel.addActionListener(this); ButtonBarBuilder bb = new ButtonBarBuilder(buttons); buttons.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); bb.addGlue(); bb.addButton(ok); bb.addButton(apply); bb.addButton(cancel); bb.addGlue(); AbstractAction closeAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }; ActionMap am = main.getActionMap(); InputMap im = main.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.prefs.getKey("Close dialog"), "close"); am.put("close", closeAction); // con.fill = GridBagConstraints.BOTH; // con.weightx = 0.3; // con.weighty = 1; // gbl.setConstraints(typeComp, con); main.add(typeComp, BorderLayout.WEST); main.add(right, BorderLayout.CENTER); main.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); pane.add(main, BorderLayout.CENTER); pane.add(buttons, BorderLayout.SOUTH); pack(); }
void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, String title) { InputMap im = panel.getInputMap(JComponent.WHEN_FOCUSED); ActionMap am = panel.getActionMap(); im.put(Globals.prefs.getKey("Entry editor, previous entry"), "prev"); am.put("prev", parent.prevEntryAction); im.put(Globals.prefs.getKey("Entry editor, next entry"), "next"); am.put("next", parent.nextEntryAction); im.put(Globals.prefs.getKey("Entry editor, store field"), "store"); am.put("store", parent.storeFieldAction); im.put(Globals.prefs.getKey("Entry editor, next panel"), "right"); im.put(Globals.prefs.getKey("Entry editor, next panel 2"), "right"); am.put("left", parent.switchLeftAction); im.put(Globals.prefs.getKey("Entry editor, previous panel"), "left"); im.put(Globals.prefs.getKey("Entry editor, previous panel 2"), "left"); am.put("right", parent.switchRightAction); im.put(Globals.prefs.getKey("Help"), "help"); am.put("help", parent.helpAction); im.put(Globals.prefs.getKey("Save database"), "save"); am.put("save", parent.saveDatabaseAction); im.put(Globals.prefs.getKey("Next tab"), "nexttab"); am.put("nexttab", parent.frame.nextTab); im.put(Globals.prefs.getKey("Previous tab"), "prevtab"); am.put("prevtab", parent.frame.prevTab); panel.setName(title); // String rowSpec = "left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref"; String colSpec = "fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref, " + "8dlu, fill:pref, 1dlu, fill:10dlu:grow, 1dlu, fill:pref"; StringBuffer sb = new StringBuffer(); int rows = (int) Math.ceil((double) fields.length / 2.0); for (int i = 0; i < rows; i++) { sb.append("fill:pref:grow, "); } if (addKeyField) sb.append("4dlu, fill:pref"); else if (sb.length() >= 2) sb.delete(sb.length() - 2, sb.length()); String rowSpec = sb.toString(); DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout(colSpec, rowSpec), panel); for (int i = 0; i < fields.length; i++) { // Create the text area: int editorType = BibtexFields.getEditorType(fields[i]); final FieldEditor ta; if (editorType == GUIGlobals.FILE_LIST_EDITOR) ta = new FileListEditor(frame, bPanel.metaData(), fields[i], null, parent); else ta = new FieldTextArea(fields[i], null); // ta.addUndoableEditListener(bPanel.undoListener); JComponent ex = parent.getExtra(fields[i], ta); // Add autocompleter listener, if required for this field: AbstractAutoCompleter autoComp = bPanel.getAutoCompleter(fields[i]); AutoCompleteListener acl = null; if (autoComp != null) { acl = new AutoCompleteListener(autoComp); } setupJTextComponent(ta.getTextComponent(), acl); ta.setAutoCompleteListener(acl); // Store the editor for later reference: editors.put(fields[i], ta); if (i == 0) activeField = ta; // System.out.println(fields[i]+": "+BibtexFields.getFieldWeight(fields[i])); // ta.getPane().setPreferredSize(new Dimension(100, // (int)(50.0*BibtexFields.getFieldWeight(fields[i])))); builder.append(ta.getLabel()); if (ex == null) builder.append(ta.getPane(), 3); else { builder.append(ta.getPane()); JPanel pan = new JPanel(); pan.setLayout(new BorderLayout()); pan.add(ex, BorderLayout.NORTH); builder.append(pan); } if (i % 2 == 1) builder.nextLine(); } // Add the edit field for Bibtex-key. if (addKeyField) { final FieldTextField tf = new FieldTextField( BibtexFields.KEY_FIELD, parent.getEntry().getField(BibtexFields.KEY_FIELD), true); // tf.addUndoableEditListener(bPanel.undoListener); setupJTextComponent(tf, null); editors.put("bibtexkey", tf); /* * If the key field is the only field, we should have only one * editor, and this one should be set as active initially: */ if (editors.size() == 1) activeField = tf; builder.nextLine(); builder.append(tf.getLabel()); builder.append(tf, 3); } }
private Container createBorrowPane() { // Initialise date combo boxes borDay = new JComboBox(); borMonth = new JComboBox(); borYear = new JComboBox(); String[] days = new String[31]; for (int i = 0; i < 31; i++) days[i] = String.valueOf(i + 1); String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; String[] years = { "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014" }; borDay.setModel(new DefaultComboBoxModel(days)); borMonth.setModel(new DefaultComboBoxModel(months)); borYear.setModel(new DefaultComboBoxModel(years)); Calendar today = Calendar.getInstance(); borDay.setSelectedIndex(today.get(DAY_OF_MONTH) - 1); borMonth.setSelectedIndex(today.get(MONTH)); borYear.setSelectedIndex(today.get(YEAR) - 2005); // Create borrow button borrowButton = new JButton(borrowAction); // Create text fields borISBN = new JTextField(15); borCustID = new JTextField(15); // Create panel and layout JPanel pane = new JPanel(); pane.setOpaque(false); GridBagLayout gb = new GridBagLayout(); pane.setLayout(gb); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(1, 5, 1, 5); // Fill panel c.anchor = GridBagConstraints.EAST; addToGridBag(gb, c, pane, new JLabel("ISBN:"), 0, 0, 1, 1); addToGridBag(gb, c, pane, new JLabel("Customer ID:"), 0, 1, 1, 1); addToGridBag(gb, c, pane, new JLabel("Due Date:"), 0, 2, 1, 1); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.HORIZONTAL; addToGridBag(gb, c, pane, borISBN, 1, 0, 3, 1); addToGridBag(gb, c, pane, borCustID, 1, 1, 3, 1); c.fill = GridBagConstraints.NONE; addToGridBag(gb, c, pane, borDay, 1, 2, 1, 1); addToGridBag(gb, c, pane, borMonth, 2, 2, 1, 1); addToGridBag(gb, c, pane, borYear, 3, 2, 1, 1); addToGridBag(gb, c, pane, borrowButton, 4, 0, 1, 3); // Set up VK_ENTER triggering the borrow button in this panel InputMap input = pane.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); input.put(getKeyStroke("ENTER"), "borrowAction"); pane.getActionMap().put("borrowAction", borrowAction); return pane; }