public void loadBindingMap(InputMap im, ActionMap am) { results.append("Bound Actions\n"); String unboundActions = ""; String unboundInputKeys = ""; Hashtable mi = buildReverseMap(im); Object[] k = am.allKeys(); if (k != null) { for (int i = 0; i < k.length; i++) { if (mi.containsKey(k[i])) { results.append(" " + getActionName(k[i])); results.append(";" + mi.get(k[i]) + "\n"); } else { unboundActions += (" " + getActionName(k[i]) + "\n"); } } results.append("\nUnbound Actions\n\n"); results.append(unboundActions); } results.append("\nUnbound InputMap Entries\n"); k = im.allKeys(); if (k != null) { for (int i = 0; i < k.length; i++) { KeyStroke key = (KeyStroke) k[i]; Object actionKey = im.get(key); if (am.get(actionKey) == null) { results.append(" " + im.get((KeyStroke) k[i]) + ": " + k[i] + "\n"); } } } }
// --------> // original code: // ftp://ftp.oreilly.de/pub/examples/english_examples/jswing2/code/goodies/Mapper.java // modified by terai // private Hashtable<Object, ArrayList<KeyStroke>> buildReverseMap(InputMap im) { // Hashtable<Object, ArrayList<KeyStroke>> h = new Hashtable<>(); // if (Objects.isNull(im.allKeys())) { // return h; // } // for (KeyStroke ks: im.allKeys()) { // Object name = im.get(ks); // if (h.containsKey(name)) { // h.get(name).add(ks); // } else { // ArrayList<KeyStroke> keylist = new ArrayList<>(); // keylist.add(ks); // h.put(name, keylist); // } // } // return h; // } private void loadBindingMap(Integer focusType, InputMap im, ActionMap am) { if (Objects.isNull(im.allKeys())) { return; } ActionMap tmpAm = new ActionMap(); for (Object actionMapKey : am.allKeys()) { tmpAm.put(actionMapKey, am.get(actionMapKey)); } for (KeyStroke ks : im.allKeys()) { Object actionMapKey = im.get(ks); Action action = am.get(actionMapKey); if (Objects.isNull(action)) { model.addBinding(new Binding(focusType, "____" + actionMapKey.toString(), ks.toString())); } else { model.addBinding(new Binding(focusType, actionMapKey.toString(), ks.toString())); } tmpAm.remove(actionMapKey); } if (Objects.isNull(tmpAm.allKeys())) { return; } for (Object actionMapKey : tmpAm.allKeys()) { model.addBinding(new Binding(focusType, actionMapKey.toString(), "")); } }
ActionMap createActionMap() { ActionMap map = new ActionMapUIResource(); Action refreshAction = new UIAction(FilePane.ACTION_REFRESH) { public void actionPerformed(ActionEvent evt) { getFileChooser().rescanCurrentDirectory(); } }; map.put(FilePane.ACTION_APPROVE_SELECTION, getApproveSelectionAction()); map.put(FilePane.ACTION_CANCEL, getCancelSelectionAction()); map.put(FilePane.ACTION_REFRESH, refreshAction); map.put(FilePane.ACTION_CHANGE_TO_PARENT_DIRECTORY, getChangeToParentDirectoryAction()); return map; }
void initActions() { // TODO: copied from CloneableEditor - this has no effect ActionMap paneMap = editorPane.getActionMap(); ActionMap am = getActionMap(); am.setParent(paneMap); paneMap.put(DefaultEditorKit.cutAction, getAction(DefaultEditorKit.cutAction)); paneMap.put(DefaultEditorKit.copyAction, getAction(DefaultEditorKit.copyAction)); paneMap.put("delete", getAction(DefaultEditorKit.deleteNextCharAction)); // NOI18N paneMap.put(DefaultEditorKit.pasteAction, getAction(DefaultEditorKit.pasteAction)); }
public void loadActionMap(ActionMap am, String indent) { Object[] k = am.allKeys(); if (k == null) { results.append(indent + "No ActionMap defined\n"); } else { results.append(indent + "\nActionMap (" + k.length + " local keys)\n"); } if (k != null) { for (int i = 0; i < k.length; i++) { results.append(indent + " Action: " + k[i] + "\n"); } } }
EditFrame(RopeFrame parent) { super(parent); // Implement a smarter way to set the initial frame position and size setLocation(0, 0); setSize(670, 705); try { jbInit(); } catch (Exception ex) { ex.printStackTrace(); } sourceArea.addCaretListener(this); browseButton.addActionListener(this); optionsButton.addActionListener(this); assembleButton.addActionListener(this); saveButton.addActionListener(this); messageList.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent event) { highlightError(messageList.locationToIndex(event.getPoint())); } }); undoMgr = new CompoundUndoManager(sourceArea); undoAction = undoMgr.getUndoAction(); redoAction = undoMgr.getRedoAction(); undoMgr.updateUndoAction = new UpdateUndoAction(); undoMgr.updateRedoAction = new UpdateRedoAction(); document = sourceArea.getDocument(); ActionMap am = sourceArea.getActionMap(); InputMap im = sourceArea.getInputMap(JComponent.WHEN_FOCUSED); // Remove automatic key bindings because we want them controlled by menu items im.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, RopeHelper.modifierMaks), "none"); im.put( KeyStroke.getKeyStroke(KeyEvent.VK_Z, RopeHelper.modifierMaks + InputEvent.SHIFT_MASK), "none"); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, RopeHelper.modifierMaks), "none"); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, RopeHelper.modifierMaks), "none"); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, RopeHelper.modifierMaks), "none"); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, RopeHelper.modifierMaks), "none"); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_L, RopeHelper.modifierMaks), "none"); // Set custom binding action for tab key String action = "tabKeyAction"; im.put(KeyStroke.getKeyStroke("TAB"), action); am.put( action, new AbstractAction() { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { try { int caretPos = sourceArea.getCaretPosition(); int lineNum = sourceArea.getLineOfOffset(caretPos); int startLine = sourceArea.getLineStartOffset(lineNum); int endLine = sourceArea.getLineEndOffset(lineNum); int linePos = caretPos - startLine; if (linePos >= 39 && linePos < 79) { caretPos = startLine + linePos + 10 - ((linePos + 1) % 10); } else if (linePos >= 20 && linePos <= 39) { caretPos = startLine + 39; } else if (linePos >= 15 && linePos <= 19) { caretPos = startLine + 20; } else if (linePos >= 5 && linePos <= 14) { caretPos = startLine + 15; } else { caretPos = startLine + 5; } // If the line is shorter than the new position fo the caret add enough spaces... if (caretPos > endLine) { StringBuilder str = new StringBuilder(); int size = caretPos - endLine; while (size-- >= 0) { str.append(' '); } document.insertString(endLine - 1, str.toString(), null); } sourceArea.setCaretPosition(caretPos); } catch (BadLocationException ex) { ex.printStackTrace(); } } }); // Set custom binding action for return/enter key String actionKey = "backspaceKeyAction"; im.put(KeyStroke.getKeyStroke("BACK_SPACE"), actionKey); am.put( actionKey, new AbstractAction() // How can I get the original action? { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { try { int caretPos = sourceArea.getCaretPosition(); int lineNum = sourceArea.getLineOfOffset(caretPos); int startLine = sourceArea.getLineStartOffset(lineNum); int endLine = sourceArea.getLineEndOffset(lineNum); int linePos = caretPos - startLine; if (linePos == 15) { int endPos = 5; int charPos = linePos; for (; charPos > endPos; charPos--) { char ch = sourceArea.getText().charAt((startLine + charPos) - 1); if (!Character.isWhitespace(ch)) { break; } } sourceArea.setCaretPosition(startLine + charPos); } else { int startSel = sourceArea.getSelectionStart(); int endSel = sourceArea.getSelectionEnd(); if (startSel == endSel) { startSel = caretPos - 1; endSel = caretPos; } StringBuilder sb = new StringBuilder(sourceArea.getText()); sb.replace(startSel, endSel, ""); sourceArea.setText(sb.toString()); sourceArea.setCaretPosition(startSel); } } catch (BadLocationException ex) { ex.printStackTrace(); } } }); // Set custom binding action for return/enter key action = "enterKeyAction"; im.put(KeyStroke.getKeyStroke("ENTER"), action); am.put( action, new AbstractAction() { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { try { int caretPos = sourceArea.getCaretPosition(); int lineNum = sourceArea.getLineOfOffset(caretPos); int startLine = sourceArea.getLineStartOffset(lineNum); int linePos = caretPos - startLine; if (linePos >= 5) { document.insertString(caretPos, "\n ", null); } else { document.insertString(caretPos, "\n", null); } } catch (BadLocationException ex) { ex.printStackTrace(); } } }); document.addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { setSourceChanged(true); } @Override public void removeUpdate(DocumentEvent e) { setSourceChanged(true); } @Override public void changedUpdate(DocumentEvent e) { setSourceChanged(true); } }); }
private ActionMap createActionMap() { ActionMap map = new ActionMapUIResource(); map.put("selectNextColumn", new NavigationalAction(1, 0, false, false, false)); map.put("selectPreviousColumn", new NavigationalAction(-1, 0, false, false, false)); map.put("selectNextRow", new NavigationalAction(0, 1, false, false, false)); map.put("selectPreviousRow", new NavigationalAction(0, -1, false, false, false)); map.put("selectNextColumnExtendSelection", new NavigationalAction(1, 0, false, true, false)); map.put( "selectPreviousColumnExtendSelection", new NavigationalAction(-1, 0, false, true, false)); map.put("selectNextRowExtendSelection", new NavigationalAction(0, 1, false, true, false)); map.put("selectPreviousRowExtendSelection", new NavigationalAction(0, -1, false, true, false)); map.put("scrollUpChangeSelection", new PagingAction(false, false, true, false)); map.put("scrollDownChangeSelection", new PagingAction(false, true, true, false)); map.put("selectFirstColumn", new PagingAction(false, false, false, true)); map.put("selectLastColumn", new PagingAction(false, true, false, false)); map.put("scrollUpExtendSelection", new PagingAction(true, false, true, false)); map.put("scrollDownExtendSelection", new PagingAction(true, true, true, false)); map.put("selectFirstColumnExtendSelection", new PagingAction(true, false, false, true)); map.put("selectLastColumnExtendSelection", new PagingAction(true, true, false, false)); map.put("selectFirstRow", new PagingAction(false, false, true, true)); map.put("selectLastRow", new PagingAction(false, true, true, true)); map.put("selectFirstRowExtendSelection", new PagingAction(true, false, true, true)); map.put("selectLastRowExtendSelection", new PagingAction(true, true, true, true)); map.put("selectNextColumnCell", new NavigationalAction(1, 0, true, false, true)); map.put("selectPreviousColumnCell", new NavigationalAction(-1, 0, true, false, true)); map.put("selectNextRowCell", new NavigationalAction(0, 1, true, false, true)); map.put("selectPreviousRowCell", new NavigationalAction(0, -1, true, false, true)); map.put("selectAll", new SelectAllAction()); map.put("cancel", new CancelEditingAction()); map.put("startEditing", new StartEditingAction()); map.put("scrollLeftChangeSelection", new PagingAction(false, false, false, false)); map.put("scrollRightChangeSelection", new PagingAction(false, true, false, false)); map.put("scrollLeftExtendSelection", new PagingAction(true, false, false, false)); map.put("scrollRightExtendSelection", new PagingAction(true, true, false, false)); return map; }
// {{{ InstallPanel constructor InstallPanel(PluginManager window, boolean updates) { super(new BorderLayout(12, 12)); this.window = window; this.updates = updates; setBorder(new EmptyBorder(12, 12, 12, 12)); final JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT); split.setResizeWeight(0.75); /* Setup the table */ table = new JTable(pluginModel = new PluginTableModel()); table.setShowGrid(false); table.setIntercellSpacing(new Dimension(0, 0)); table.setRowHeight(table.getRowHeight() + 2); table.setPreferredScrollableViewportSize(new Dimension(500, 200)); table.setDefaultRenderer( Object.class, new TextRenderer((DefaultTableCellRenderer) table.getDefaultRenderer(Object.class))); table.addFocusListener(new TableFocusHandler()); InputMap tableInputMap = table.getInputMap(JComponent.WHEN_FOCUSED); ActionMap tableActionMap = table.getActionMap(); tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "tabOutForward"); tableActionMap.put("tabOutForward", new KeyboardAction(KeyboardCommand.TAB_OUT_FORWARD)); tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK), "tabOutBack"); tableActionMap.put("tabOutBack", new KeyboardAction(KeyboardCommand.TAB_OUT_BACK)); tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "editPlugin"); tableActionMap.put("editPlugin", new KeyboardAction(KeyboardCommand.EDIT_PLUGIN)); tableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "closePluginManager"); tableActionMap.put( "closePluginManager", new KeyboardAction(KeyboardCommand.CLOSE_PLUGIN_MANAGER)); TableColumn col1 = table.getColumnModel().getColumn(0); TableColumn col2 = table.getColumnModel().getColumn(1); TableColumn col3 = table.getColumnModel().getColumn(2); TableColumn col4 = table.getColumnModel().getColumn(3); TableColumn col5 = table.getColumnModel().getColumn(4); col1.setPreferredWidth(30); col1.setMinWidth(30); col1.setMaxWidth(30); col1.setResizable(false); col2.setPreferredWidth(180); col3.setPreferredWidth(130); col4.setPreferredWidth(70); col5.setPreferredWidth(70); JTableHeader header = table.getTableHeader(); header.setReorderingAllowed(false); header.addMouseListener(new HeaderMouseHandler()); header.setDefaultRenderer( new HeaderRenderer((DefaultTableCellRenderer) header.getDefaultRenderer())); scrollpane = new JScrollPane(table); scrollpane.getViewport().setBackground(table.getBackground()); split.setTopComponent(scrollpane); /* Create description */ JScrollPane infoPane = new JScrollPane(infoBox = new PluginInfoBox()); infoPane.setPreferredSize(new Dimension(500, 100)); split.setBottomComponent(infoPane); EventQueue.invokeLater( new Runnable() { @Override public void run() { split.setDividerLocation(0.75); } }); final JTextField searchField = new JTextField(); searchField.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) { table.dispatchEvent(e); table.requestFocus(); } } }); searchField .getDocument() .addDocumentListener( new DocumentListener() { void update() { pluginModel.setFilterString(searchField.getText()); } @Override public void changedUpdate(DocumentEvent e) { update(); } @Override public void insertUpdate(DocumentEvent e) { update(); } @Override public void removeUpdate(DocumentEvent e) { update(); } }); table.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { int i = table.getSelectedRow(), n = table.getModel().getRowCount(); if (e.getKeyCode() == KeyEvent.VK_DOWN && i == (n - 1) || e.getKeyCode() == KeyEvent.VK_UP && i == 0) { searchField.requestFocus(); searchField.selectAll(); } } }); Box filterBox = Box.createHorizontalBox(); filterBox.add(new JLabel("Filter : ")); filterBox.add(searchField); add(BorderLayout.NORTH, filterBox); add(BorderLayout.CENTER, split); /* Create buttons */ Box buttons = new Box(BoxLayout.X_AXIS); buttons.add(new InstallButton()); buttons.add(Box.createHorizontalStrut(12)); buttons.add(new SelectallButton()); buttons.add(chooseButton = new ChoosePluginSet()); buttons.add(new ClearPluginSet()); buttons.add(Box.createGlue()); buttons.add(new SizeLabel()); add(BorderLayout.SOUTH, buttons); String path = jEdit.getProperty(PluginManager.PROPERTY_PLUGINSET, ""); if (!path.isEmpty()) { loadPluginSet(path); } } // }}}
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(); }
public ManageJournalsPanel(final JabRefFrame frame) { this.frame = frame; personalFile.setEditable(false); ButtonGroup group = new ButtonGroup(); group.add(newFile); group.add(oldFile); addExtPan.setLayout(new BorderLayout()); JButton addExt = new JButton(IconTheme.JabRefIcon.ADD.getIcon()); addExtPan.add(addExt, BorderLayout.EAST); addExtPan.setToolTipText(Localization.lang("Add")); // addExtPan.setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red)); FormLayout layout = new FormLayout( "1dlu, 8dlu, left:pref, 4dlu, fill:200dlu:grow, 4dlu, fill:pref", // 4dlu, left:pref, // 4dlu", "pref, pref, pref, 20dlu, 20dlu, fill:200dlu, 4dlu, pref"); // 150dlu"); FormBuilder builder = FormBuilder.create().layout(layout); /*JLabel description = new JLabel("<HTML>"+Glbals.lang("JabRef can switch journal names between " +"abbreviated and full form. Since it knows only a limited number of journal names, " +"you may need to add your own definitions.")+"</HTML>");*/ builder.addSeparator(Localization.lang("Built-in journal list")).xyw(2, 1, 6); JLabel description = new JLabel( "<HTML>" + Localization.lang("JabRef includes a built-in list of journal abbreviations.") + "<br>" + Localization.lang( "You can add additional journal names by setting up a personal journal list,<br>as " + "well as linking to external journal lists.") + "</HTML>"); description.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); builder.add(description).xyw(2, 2, 6); JButton viewBuiltin = new JButton(Localization.lang("View")); builder.add(viewBuiltin).xy(7, 2); builder.addSeparator(Localization.lang("Personal journal list")).xyw(2, 3, 6); // builder.add(description).xyw(2,1,6)); builder.add(newFile).xy(3, 4); builder.add(newNameTf).xy(5, 4); JButton browseNew = new JButton(Localization.lang("Browse")); builder.add(browseNew).xy(7, 4); builder.add(oldFile).xy(3, 5); builder.add(personalFile).xy(5, 5); // BrowseAction action = new BrowseAction(personalFile, false); // JButton browse = new JButton(Globals.lang("Browse")); // browse.addActionListener(action); JButton browseOld = new JButton(Localization.lang("Browse")); builder.add(browseOld).xy(7, 5); userPanel.setLayout(new BorderLayout()); // builtInTable = new JTable(Globals.journalAbbrev.getTableModel()); builder.add(userPanel).xyw(2, 6, 4); ButtonStackBuilder butBul = new ButtonStackBuilder(); butBul.addButton(add); butBul.addButton(remove); butBul.addGlue(); builder.add(butBul.getPanel()).xy(7, 6); builder.addSeparator(Localization.lang("External files")).xyw(2, 8, 6); externalFilesPanel.setLayout(new BorderLayout()); // builder.add(/*new JScrollPane(*/externalFilesPanel/*)*/).xyw(2,8,6); setLayout(new BorderLayout()); builder .getPanel() .setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5)); // createMatteBorder(1,1,1,1,Color.green)); add(builder.getPanel(), BorderLayout.NORTH); add(externalFilesPanel, BorderLayout.CENTER); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); JButton ok = new JButton(Localization.lang("OK")); bb.addButton(ok); JButton cancel = new JButton(Localization.lang("Cancel")); bb.addButton(cancel); bb.addUnrelatedGap(); JButton help = new HelpAction(HelpFiles.journalAbbrHelp).getHelpButton(); bb.addButton(help); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); dialog = new JDialog(frame, Localization.lang("Journal abbreviations"), false); dialog.getContentPane().add(this, BorderLayout.CENTER); dialog.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); // add(new JScrollPane(builtInTable), BorderLayout.CENTER); // Set up panel for editing a single journal, to be used in a dialog box: FormLayout layout2 = new FormLayout("right:pref, 4dlu, fill:180dlu", "p, 2dlu, p"); FormBuilder builder2 = FormBuilder.create().layout(layout2); builder2.add(Localization.lang("Journal name")).xy(1, 1); builder2.add(nameTf).xy(3, 1); builder2.add(Localization.lang("ISO abbreviation")).xy(1, 3); builder2.add(abbrTf).xy(3, 3); journalEditPanel = builder2.getPanel(); viewBuiltin.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JournalAbbreviationRepository abbr = new JournalAbbreviationRepository(); abbr.readJournalListFromResource(Abbreviations.JOURNALS_FILE_BUILTIN); JTable table = new JTable(JournalAbbreviationsUtil.getTableModel(Abbreviations.journalAbbrev)); JScrollPane pane = new JScrollPane(table); JOptionPane.showMessageDialog( null, pane, Localization.lang("Journal list preview"), JOptionPane.INFORMATION_MESSAGE); } }); browseNew.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { File old = null; if (!"".equals(newNameTf.getText())) { old = new File(newNameTf.getText()); } String name = FileDialogs.getNewFile(frame, old, null, JFileChooser.SAVE_DIALOG, false); if (name != null) { newNameTf.setText(name); newFile.setSelected(true); } } }); browseOld.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { File old = null; if (!"".equals(personalFile.getText())) { old = new File(personalFile.getText()); } String name = FileDialogs.getNewFile(frame, old, null, JFileChooser.OPEN_DIALOG, false); if (name != null) { personalFile.setText(name); oldFile.setSelected(true); oldFile.setEnabled(true); setupUserTable(); } } }); ok.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (readyToClose()) { try { storeSettings(); dialog.dispose(); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog( null, Localization.lang("Error opening file") + ": " + ex.getMessage(), Localization.lang("Error opening file"), JOptionPane.ERROR_MESSAGE); } } } }); AbstractAction cancelAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; cancel.addActionListener(cancelAction); add.addActionListener(tableModel); remove.addActionListener(tableModel); addExt.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { externals.add(new ExternalFileEntry()); buildExternalsPanel(); } }); // Key bindings: ActionMap am = getActionMap(); InputMap im = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", cancelAction); // dialog.pack(); int xSize = getPreferredSize().width; dialog.setSize(xSize + 10, 700); }
/** * Constructor, initialises the editor components. * * @param initialText The initial text to be displayed in the editor. * @param handler The GUI handler for this component. */ public GUITextModelEditor(String initialText, GUIMultiModelHandler handler) { this.handler = handler; setLayout(new BorderLayout()); // Setup the editor with it's custom editor kits. To switch between // editor kits just use setContentType() for the desired content type. editor = new JEditorPane() { @Override public String getToolTipText(MouseEvent event) { if (parseError != null) { try { int offset = this.viewToModel(new Point(event.getX(), event.getY())); int startOffset = computeDocumentOffset(parseError.getBeginLine(), parseError.getBeginColumn()); int endOffset = computeDocumentOffset(parseError.getEndLine(), parseError.getEndColumn()) + 1; if (offset >= startOffset && offset <= endOffset) return parseError.getMessage(); } catch (BadLocationException e) { } } return null; } }; editor.setToolTipText("dummy"); editor.setEditorKitForContentType("text/prism", new PrismEditorKit(handler)); editor.setEditorKitForContentType("text/pepa", new PepaEditorKit(handler)); // The default editor kit is the Prism one. editor.setContentType("text/prism"); editor.setBackground(Color.white); editor.addMouseListener(editorMouseListener); editor.setEditable(true); editor.setText(initialText); editor.getDocument().addDocumentListener(this); editor.addCaretListener( new CaretListener() { public void caretUpdate(CaretEvent e) { GUITextModelEditor.this .handler .getGUIPlugin() .getSelectionChangeHandler() .notifyListeners(new GUIEvent(1)); } }); editor.getDocument().putProperty(PlainDocument.tabSizeAttribute, new Integer(4)); editor.addMouseListener(this); errorHighlightPainter = new DefaultHighlighter.DefaultHighlightPainter(new Color(255, 192, 192)); undoManager = new GUIUndoManager(GUIPrism.getGUI()); undoManager.setLimit(200); // Setup the scrollpane editorScrollPane = new JScrollPane(editor); add(editorScrollPane, BorderLayout.CENTER); gutter = new GUITextModelEditorGutter(editor); // Get the 'show line numbers' setting to determine // if the line numbers should be shown. showLineNumbersSetting = handler .getGUIPlugin() .getPrism() .getSettings() .getBoolean(PrismSettings.MODEL_SHOW_LINE_NUMBERS); if (showLineNumbersSetting) { editorScrollPane.setRowHeaderView(gutter); } // Add a Prism settings listener to catch changes made to the // 'show line numbers' setting. handler .getGUIPlugin() .getPrism() .getSettings() .addSettingsListener( new PrismSettingsListener() { public void notifySettings(PrismSettings settings) { // Check if the setting has changed. if (settings.getBoolean(PrismSettings.MODEL_SHOW_LINE_NUMBERS) != showLineNumbersSetting) { showLineNumbersSetting = !showLineNumbersSetting; if (showLineNumbersSetting) { editorScrollPane.setRowHeaderView(gutter); } else { editorScrollPane.setRowHeaderView(null); } } } }); // initialize the actions for the context menu initActions(); // method to initialize the context menu popup initContextMenu(); InputMap inputMap = editor.getInputMap(); inputMap.clear(); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_undo"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_undo"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_redo"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_selectall"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_delete"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_cut"); inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | java.awt.event.InputEvent.SHIFT_MASK), "prism_redo"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_paste"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_E, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_jumperr"); ActionMap actionMap = editor.getActionMap(); actionMap.put("prism_undo", GUIPrism.getClipboardPlugin().getUndoAction()); actionMap.put("prism_redo", GUIPrism.getClipboardPlugin().getRedoAction()); actionMap.put("prism_selectall", GUIPrism.getClipboardPlugin().getSelectAllAction()); actionMap.put("prism_cut", GUIPrism.getClipboardPlugin().getCutAction()); actionMap.put("prism_copy", GUIPrism.getClipboardPlugin().getCopyAction()); actionMap.put("prism_paste", GUIPrism.getClipboardPlugin().getPasteAction()); actionMap.put("prism_delete", GUIPrism.getClipboardPlugin().getDeleteAction()); actionMap.put("prism_jumperr", actionJumpToError); // Attempt to programmatically allow all accelerators /*ArrayList plugins = ((GUIMultiModel)handler.getGUIPlugin()).getGUI().getPlugins(); Iterator it = plugins.iterator(); while (it.hasNext()) { GUIPlugin plugin = ((GUIPlugin)it.next()); System.out.println(plugin.getName()); JMenu firstMenu = plugin.getMenu(); Stack<MenuElement> menuStack = new Stack<MenuElement>(); menuStack.add(firstMenu); while (!menuStack.empty()) { MenuElement menu = menuStack.pop(); if (menu instanceof JMenuItem) { JMenuItem menuItem = ((JMenuItem)menu); KeyStroke accelerator = menuItem.getAccelerator(); Action action = menuItem.getAction(); if (action != null && accelerator != null && menuItem.getText() != null) { System.out.println(menuItem.getText() + " " + menuItem.getName()); inputMap.put(accelerator, "prism_" + menuItem.getText()); actionMap.put("prism_" + menuItem.getText(), action); } } MenuElement[] subelements = menu.getSubElements(); if (subelements != null) { for (int i = 0; i < subelements.length; i++) menuStack.push(subelements[i]); } } }*/ editor.getDocument().addUndoableEditListener(undoManager); editor .getDocument() .addUndoableEditListener( new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent e) { System.out.println("adding undo edit"); } }); }
private static void installActionWrapper( ActionMap map, String actionName, ActionWrapper wrapper) { wrapper.setParent(map.get(actionName)); map.put(actionName, wrapper); }