List of usage examples for javax.swing Action putValue
public void putValue(String key, Object value);
From source file:ro.nextreports.designer.querybuilder.SQLViewPanel.java
private void initUI() { sqlEditor = new Editor() { public void afterCaretMove() { removeHighlightErrorLine();/*w w w . ja v a2 s . co m*/ } }; this.queryArea = sqlEditor.getEditorPanel().getEditorPane(); queryArea.setText(DEFAULT_QUERY); errorPainter = new javax.swing.text.Highlighter.HighlightPainter() { @Override public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) { try { Rectangle r = c.modelToView(c.getCaretPosition()); g.setColor(Color.RED.brighter().brighter()); g.fillRect(0, r.y, c.getWidth(), r.height); } catch (BadLocationException e) { // ignore } } }; ActionMap actionMap = sqlEditor.getEditorPanel().getEditorPane().getActionMap(); // create the toolbar JToolBar toolBar = new JToolBar(); toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); // hide buttons borders toolBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH); toolBar.setBorderPainted(false); // add cut action Action cutAction = actionMap.get(BaseEditorKit.cutAction); cutAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("cut")); cutAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqlviewpanel.cut")); toolBar.add(cutAction); // add copy action Action copyAction = actionMap.get(BaseEditorKit.copyAction); copyAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("copy")); copyAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqlviewpanel.copy")); toolBar.add(copyAction); // add paste action Action pasteAction = actionMap.get(BaseEditorKit.pasteAction); pasteAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("paste")); pasteAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqlviewpanel.paste")); toolBar.add(pasteAction); // add separator SwingUtil.addCustomSeparator(toolBar); // add undo action Action undoAction = actionMap.get(BaseEditorKit.undoAction); undoAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("undo")); undoAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("undo")); toolBar.add(undoAction); // add redo action Action redoAction = actionMap.get(BaseEditorKit.redoAction); redoAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("redo")); redoAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("redo")); toolBar.add(redoAction); // add separator SwingUtil.addCustomSeparator(toolBar); // add find action Action findReplaceAction = actionMap.get(BaseEditorKit.findReplaceAction); findReplaceAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("find")); findReplaceAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqleditor.findReplaceActionName")); toolBar.add(findReplaceAction); // add separator SwingUtil.addCustomSeparator(toolBar); // add run action runAction = new SQLRunAction(); runAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("run")); runAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(ShortcutsUtil.getShortcut("query.run.accelerator", "control 4"))); runAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("run.query") + " (" + ShortcutsUtil.getShortcut("query.run.accelerator.display", "Ctrl 4") + ")"); // runAction is globally registered in QueryBuilderPanel ! toolBar.add(runAction); // ro.nextreports.designer.util.SwingUtil.registerButtonsForFocus(buttonsPanel); // create the table resultTable = new JXTable(); resultTable.setDefaultRenderer(Integer.class, new ToStringRenderer()); // to remove thousand separators resultTable.setDefaultRenderer(Long.class, new ToStringRenderer()); resultTable.setDefaultRenderer(Date.class, new DateRenderer()); resultTable.setDefaultRenderer(Double.class, new DoubleRenderer()); resultTable.addMouseListener(new CopyTableMouseAdapter(resultTable)); TableUtil.setRowHeader(resultTable); resultTable.setColumnControlVisible(true); // resultTable.getTableHeader().setReorderingAllowed(false); resultTable.setHorizontalScrollEnabled(true); // highlight table Highlighter alternateHighlighter = HighlighterFactory.createAlternateStriping(Color.WHITE, ColorUtil.PANEL_BACKROUND_COLOR); Highlighter nullHighlighter = new TextHighlighter(ResultSetTableModel.NULL_VALUE, Color.YELLOW.brighter()); Highlighter blobHighlighter = new TextHighlighter(ResultSetTableModel.BLOB_VALUE, Color.GRAY.brighter()); Highlighter clobHighlighter = new TextHighlighter(ResultSetTableModel.CLOB_VALUE, Color.GRAY.brighter()); resultTable.setHighlighters(alternateHighlighter, nullHighlighter, blobHighlighter, clobHighlighter); resultTable.setBackground(ColorUtil.PANEL_BACKROUND_COLOR); resultTable.setGridColor(Color.LIGHT_GRAY); resultTable.setRolloverEnabled(true); resultTable.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW, null, Color.RED)); JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT); split.setResizeWeight(0.66); split.setOneTouchExpandable(true); JPanel topPanel = new JPanel(); topPanel.setLayout(new GridBagLayout()); topPanel.add(toolBar, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); topPanel.add(sqlEditor, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); JPanel bottomPanel = new JPanel(); bottomPanel.setLayout(new GridBagLayout()); JScrollPane scrPanel = new JScrollPane(resultTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); statusPanel = new SQLStatusPanel(); bottomPanel.add(scrPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); bottomPanel.add(statusPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); split.setTopComponent(topPanel); split.setBottomComponent(bottomPanel); split.setDividerLocation(400); setLayout(new BorderLayout()); this.add(split, BorderLayout.CENTER); }
From source file:se.trixon.jota.client.ui.MainFrame.java
private void loadClientOption(ClientOptionsEvent clientOptionEvent) { switch (clientOptionEvent) { case LOOK_AND_FEEL: if (mOptions.isForceLookAndFeel()) { SwingUtilities.invokeLater(() -> { try { UIManager.setLookAndFeel(SwingHelper.getLookAndFeelClassName(mOptions.getLookAndFeel())); SwingUtilities.updateComponentTreeUI(MainFrame.this); SwingUtilities.updateComponentTreeUI(sPopupMenu); if (mOptions.getLookAndFeel().equalsIgnoreCase("Darcula")) { int iconSize = 32; UIDefaults uiDefaults = UIManager.getLookAndFeelDefaults(); uiDefaults.put("OptionPane.informationIcon", MaterialIcon.Action.INFO_OUTLINE.get(iconSize, IconColor.WHITE)); uiDefaults.put("OptionPane.errorIcon", MaterialIcon.Alert.ERROR_OUTLINE.get(iconSize, IconColor.WHITE)); uiDefaults.put("OptionPane.questionIcon", MaterialIcon.Action.HELP_OUTLINE.get(iconSize, IconColor.WHITE)); uiDefaults.put("OptionPane.warningIcon", MaterialIcon.Alert.WARNING.get(iconSize, IconColor.WHITE)); }// w w w. jav a 2 s .c om } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { //Xlog.timedErr(ex.getMessage()); } }); } break; case MENU_ICONS: ActionMap actionMap = getRootPane().getActionMap(); for (Object allKey : actionMap.allKeys()) { Action action = actionMap.get(allKey); Icon icon = null; if (mOptions.isDisplayMenuIcons()) { icon = (Icon) action.getValue(ActionManager.JOTA_SMALL_ICON_KEY); } action.putValue(Action.SMALL_ICON, icon); } break; default: throw new AssertionError(); } }
From source file:se.trixon.jota.client.ui.MainFrame.java
private void loadConfiguration() { if (!mManager.isConnected()) { return;/*from w w w.j ava 2 s. co m*/ } boolean hasJob = mManager.isConnected() && mManager.hasJobs(); Action cronAction = mActionManager.getAction(ActionManager.CRON); try { boolean cronActive = mManager.getServerCommander().isCronActive(); cronAction.putValue(Action.SELECTED_KEY, cronActive); } catch (RemoteException ex) { System.err.println("mManager: " + mManager); } }
From source file:storybook.action.ActionHandler.java
public void handleRenameCity() { RenameCityDialog dlg = new RenameCityDialog(mainFrame); ActionManager actMngr = mainFrame.getSbActionManager().getActionManager(); Action act = actMngr.getAction("rename-city-command"); Object obj = act.getValue(SbConstants.ActionKey.CATEGORY.toString()); if (obj != null) { dlg.setSelectedItem(obj);//from ww w .j av a 2 s . c om } SwingUtil.showModalDialog(dlg, mainFrame); act.putValue(SbConstants.ActionKey.CATEGORY.toString(), null); }
From source file:storybook.action.ActionHandler.java
public void handleRenameCountry() { RenameCountryDialog dlg = new RenameCountryDialog(mainFrame); ActionManager actMngr = mainFrame.getSbActionManager().getActionManager(); Action act = actMngr.getAction("rename-country-command"); Object obj = act.getValue(SbConstants.ActionKey.CATEGORY.toString()); if (obj != null) { dlg.setSelectedItem(obj);/*from w w w. j a v a 2s.c o m*/ } SwingUtil.showModalDialog(dlg, mainFrame); act.putValue(SbConstants.ActionKey.CATEGORY.toString(), null); }
From source file:storybook.action.ActionHandler.java
public void handleRenameTagCategory() { RenameTagCategoryDialog dlg = new RenameTagCategoryDialog(mainFrame); ActionManager actMngr = mainFrame.getSbActionManager().getActionManager(); Action act = actMngr.getAction("rename-tag-category-command"); Object obj = act.getValue(SbConstants.ActionKey.CATEGORY.toString()); if (obj != null) { dlg.setSelectedItem(obj);/*ww w . j av a 2s .co m*/ } SwingUtil.showModalDialog(dlg, mainFrame); act.putValue(SbConstants.ActionKey.CATEGORY.toString(), null); }
From source file:storybook.action.ActionHandler.java
public void handleRenameItemCategory() { RenameItemCategoryDialog dlg = new RenameItemCategoryDialog(mainFrame); ActionManager actMngr = mainFrame.getSbActionManager().getActionManager(); Action act = actMngr.getAction("rename-item-category-command"); Object obj = act.getValue(SbConstants.ActionKey.CATEGORY.toString()); if (obj != null) { dlg.setSelectedItem(obj);/*from w ww. j a v a2 s .c o m*/ } SwingUtil.showModalDialog(dlg, mainFrame); act.putValue(SbConstants.ActionKey.CATEGORY.toString(), null); }
From source file:tvbrowser.extras.favoritesplugin.dlgs.FavoriteTreeModel.java
public void updatePluginTree(final PluginTreeNode node, final ArrayList<Program> allPrograms, FavoriteNode parentFavorite) {/*w ww . j a v a 2s . c o m*/ if (parentFavorite == null) { parentFavorite = (FavoriteNode) getRoot(); } if (parentFavorite.isDirectoryNode()) { @SuppressWarnings("unchecked") Enumeration<FavoriteNode> e = parentFavorite.children(); while (e.hasMoreElements()) { final FavoriteNode child = e.nextElement(); if (child.isDirectoryNode()) { PluginTreeNode newNode = new PluginTreeNode(child.toString()); newNode.setGroupingByWeekEnabled(true); updatePluginTree(newNode, allPrograms, child); if (!newNode.isEmpty()) { node.add(newNode); } } else { Program[] progArr = child.getFavorite().getWhiteListPrograms(); if (progArr.length > 0) { PluginTreeNode newNode = new PluginTreeNode(child.toString()); newNode.setGroupingByWeekEnabled(true); newNode.getMutableTreeNode().setIcon(FavoritesPlugin.getFavoritesIcon(16)); node.add(newNode); Action editFavorite = new AbstractAction() { public void actionPerformed(ActionEvent e) { FavoritesPlugin.getInstance().editFavorite(child.getFavorite()); } }; editFavorite.putValue(Action.NAME, mLocalizer.ellipsisMsg("editTree", "Edit")); editFavorite.putValue(Action.SMALL_ICON, TVBrowserIcons.edit(TVBrowserIcons.SIZE_SMALL)); Action deleteFavorite = new AbstractAction() { public void actionPerformed(ActionEvent e) { FavoritesPlugin.getInstance().askAndDeleteFavorite(child.getFavorite()); } }; deleteFavorite.putValue(Action.NAME, mLocalizer.ellipsisMsg("deleteTree", "Delete")); deleteFavorite.putValue(Action.SMALL_ICON, TVBrowserIcons.delete(TVBrowserIcons.SIZE_SMALL)); deleteFavorite.putValue(ContextMenuIf.ACTIONKEY_KEYBOARD_EVENT, KeyEvent.VK_DELETE); newNode.addAction(editFavorite); newNode.addAction(deleteFavorite); if (progArr.length <= 10) { newNode.setGroupingByDateEnabled(false); } boolean episodeOnly = progArr.length > 1; for (Program program : progArr) { String episode = program.getTextField(ProgramFieldType.EPISODE_TYPE); if (StringUtils.isBlank(episode)) { episodeOnly = false; break; } } for (Program program : progArr) { PluginTreeNode pNode = newNode.addProgramWithoutCheck(program); allPrograms.add(program); if (episodeOnly || progArr.length <= 10) { pNode.setNodeFormatter(new NodeFormatter() { public String format(ProgramItem pitem) { Program p = pitem.getProgram(); return FavoriteTreeModel.getFavoriteLabel(child.getFavorite(), p); } }); } } } } } } }
From source file:tvbrowser.extras.reminderplugin.ReminderPlugin.java
/** * Updates the plugin tree entry for this plugin. * <p>//from w w w . ja va 2 s . com * * @param save * <code>True</code> if the reminder entries should be saved. */ public void updateRootNode(boolean save) { mRootNode.removeAllActions(); mRootNode.getMutableTreeNode() .setIcon(IconLoader.getInstance().getIconFromTheme("apps", "appointment", 16)); Action editReminders = new AbstractAction() { public void actionPerformed(ActionEvent e) { ReminderListDialog dlg = new ReminderListDialog(MainFrame.getInstance(), mReminderList); UiUtilities.centerAndShow(dlg); } }; editReminders.putValue(Action.SMALL_ICON, IconLoader.getInstance().getIconFromTheme("apps", "appointment", 16)); editReminders.putValue(Action.NAME, mLocalizer.ellipsisMsg("buttonText", "Edit reminder list")); Action openSettings = new AbstractAction() { public void actionPerformed(ActionEvent e) { MainFrame.getInstance().showSettingsDialog(SettingsItem.REMINDER); } }; openSettings.putValue(Action.SMALL_ICON, TVBrowserIcons.preferences(TVBrowserIcons.SIZE_SMALL)); openSettings.putValue(Action.NAME, Localizer.getLocalization(Localizer.I18N_SETTINGS)); mRootNode.addAction(editReminders); mRootNode.addAction(null); mRootNode.addAction(openSettings); mRootNode.removeAllChildren(); ReminderListItem[] items = mReminderList.getReminderItems(); ArrayList<Program> listNewPrograms = new ArrayList<Program>(items.length); for (ReminderListItem reminderItem : items) { listNewPrograms.add(reminderItem.getProgram()); } mRootNode.addPrograms(listNewPrograms); mRootNode.update(); if (save && mHasRightToSave) { saveReminders(); } }
From source file:VASSAL.launch.EditorWindow.java
protected EditorWindow() { setTitle("VASSAL " + getEditorType() + " Editor"); setLayout(new BorderLayout()); ApplicationIcons.setFor(this); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { close();/* w w w.ja v a 2s .c o m*/ } }); toolBar.setFloatable(false); add(toolBar, BorderLayout.NORTH); // setup menubar and actions final MenuManager mm = MenuManager.getInstance(); final MenuBarProxy mb = mm.getMenuBarProxyFor(this); // file menu if (SystemUtils.IS_OS_MAC_OSX) { mm.addToSection("Editor.File", mm.addKey("Editor.save")); mm.addToSection("Editor.File", mm.addKey("Editor.save_as")); } else { final MenuProxy fileMenu = new MenuProxy(Resources.getString("General.file")); // FIMXE: setting nmemonic from first letter could cause collisions in // some languages fileMenu.setMnemonic(Resources.getString("General.file.shortcut").charAt(0)); fileMenu.add(mm.addKey("Editor.save")); fileMenu.add(mm.addKey("Editor.save_as")); fileMenu.addSeparator(); fileMenu.add(mm.addKey("General.quit")); mb.add(fileMenu); } // edit menu final MenuProxy editMenu = new MenuProxy(Resources.getString("General.edit")); editMenu.setMnemonic(Resources.getString("General.edit.shortcut").charAt(0)); editMenu.add(mm.addKey("Editor.cut")); editMenu.add(mm.addKey("Editor.copy")); editMenu.add(mm.addKey("Editor.paste")); editMenu.add(mm.addKey("Editor.move")); editMenu.addSeparator(); editMenu.add(mm.addKey("Editor.ModuleEditor.properties")); editMenu.add(mm.addKey("Editor.ModuleEditor.translate")); // tools menu final MenuProxy toolsMenu = new MenuProxy(Resources.getString("General.tools")); toolsMenu.setMnemonic(Resources.getString("General.tools.shortcut").charAt(0)); toolsMenu.add(mm.addKey("create_module_updater")); toolsMenu.add(mm.addKey("Editor.ModuleEditor.update_saved")); if (SystemUtils.IS_OS_MAC_OSX) { mm.addToSection("Editor.MenuBar", editMenu); mm.addToSection("Editor.MenuBar", toolsMenu); } else { mb.add(editMenu); mb.add(toolsMenu); } // help menu if (SystemUtils.IS_OS_MAC_OSX) { mm.addToSection("Documentation.VASSAL", mm.addKey("Editor.ModuleEditor.reference_manual")); } else { final MenuProxy helpMenu = new MenuProxy(Resources.getString("General.help")); // FIMXE: setting nmemonic from first letter could cause collisions in // some languages helpMenu.setMnemonic(Resources.getString("General.help.shortcut").charAt(0)); helpMenu.add(mm.addKey("General.help")); helpMenu.add(mm.addKey("Editor.ModuleEditor.reference_manual")); helpMenu.addSeparator(); helpMenu.add(mm.addKey("AboutScreen.about_vassal")); mb.add(helpMenu); } final int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); saveAction = new SaveAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { save(); treeStateChanged(false); } }; saveAction.setEnabled(false); saveAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, mask)); mm.addAction("Editor.save", saveAction); toolBar.add(saveAction); saveAsAction = new SaveAsAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { saveAs(); treeStateChanged(false); } }; saveAsAction.setEnabled(false); saveAsAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A, mask)); mm.addAction("Editor.save_as", saveAsAction); toolBar.add(saveAsAction); mm.addAction("General.quit", new ShutDownAction()); // FXIME: mnemonics should be language-dependant // mm.getAction("General.quit").setMnemonic('Q'); createUpdater = new AbstractAction("Create " + getEditorType() + " updater") { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { new ModuleUpdaterDialog(EditorWindow.this).setVisible(true); } }; createUpdater.setEnabled(false); mm.addAction("create_module_updater", createUpdater); URL url = null; try { url = new File(Documentation.getDocumentationBaseDir(), "README.html").toURI().toURL(); } catch (MalformedURLException e) { ErrorDialog.bug(e); } mm.addAction("General.help", new ShowHelpAction(url, null)); url = null; try { File dir = VASSAL.build.module.Documentation.getDocumentationBaseDir(); dir = new File(dir, "ReferenceManual/index.htm"); //$NON-NLS-1$ url = URLUtils.toURL(dir); } catch (MalformedURLException e) { ErrorDialog.bug(e); } final Action helpAction = new ShowHelpAction(url, helpWindow.getClass().getResource("/images/Help16.gif")); //$NON-NLS-1$ helpAction.putValue(Action.SHORT_DESCRIPTION, Resources.getString("Editor.ModuleEditor.reference_manual")); //$NON-NLS-1$ mm.addAction("Editor.ModuleEditor.reference_manual", helpAction); toolBar.add(helpAction); mm.addAction("AboutScreen.about_vassal", new AboutVASSALAction(this)); setJMenuBar(mm.getMenuBarFor(this)); // the presence of the panel prevents a NullPointerException on packing final JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(250, 400)); scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); add(scrollPane, BorderLayout.CENTER); pack(); }