List of usage examples for javax.swing JPopupMenu add
public JMenuItem add(Action a)
Action
object. From source file:statechum.analysis.learning.Visualiser.java
public static void updatePopupMenu(JPopupMenu popupMenu, Map<Integer, Action> keyToActionMap) { for (Entry<Integer, Action> ia : keyToActionMap.entrySet()) { ia.getValue().putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(ia.getKey(), 0)); JMenuItem menuitem = new JMenuItem(ia.getValue()); popupMenu.add(menuitem); }//from w ww. j a v a 2 s . c o m }
From source file:statechum.analysis.learning.Visualiser.java
private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { if ((e.getModifiers() & InputEvent.SHIFT_MASK) == 0) popupMenu.show(e.getComponent(), e.getX(), e.getY()); else// www . j ava2 s . c o m // attempt the popup for the diff if (currentGraph >= 0) {// if there are any graphs in this frame JPopupMenu diffMenu = new JPopupMenu(); final LearnerGraphND ourGraph = graphsOrig.get(currentGraph); if (ourGraph != null) {// if this is a real graph for (Visualiser viz : framesVisible) { final Visualiser fViz = viz; if (fViz.currentGraph >= 0) { final LearnerGraphND otherGr = fViz.graphsOrig.get(fViz.currentGraph); if (ourGraph != otherGr && otherGr != null) {// only if this is a real graph JMenuItem menuitem = new JMenuItem(new AbstractAction() { /** * ID for serialization */ private static final long serialVersionUID = 6840129509410881970L; {// Constructor putValue(Action.NAME, otherGr.getNameNotNull()); putValue(SHORT_DESCRIPTION, otherGr.getNameNotNull()); } @Override public void actionPerformed(@SuppressWarnings("unused") ActionEvent ev) { GD<List<CmpVertex>, List<CmpVertex>, LearnerGraphNDCachedData, LearnerGraphNDCachedData> gd = new GD<List<CmpVertex>, List<CmpVertex>, LearnerGraphNDCachedData, LearnerGraphNDCachedData>(); DirectedSparseGraph gr = //gd.showGD(ourGraph,otherGr,ExperimentRunner.getCpuNumber()); ChangesToGraph.computeVisualisationParameters( Synapse.StatechumProcess.constructFSM(ourGraph), ChangesToGraph.computeGD(ourGraph, otherGr, ourGraph.config)); Visualiser.updateFrame(gr, null); } }); diffMenu.add(menuitem); } } // if otherGr != null } // if fViz.graphs.size() > 0 if (diffMenu.getComponentCount() > 0) diffMenu.show(e.getComponent(), e.getX(), e.getY()); } // if ourGraph != null } // if graphs.size() > 0 } // e.isPopupTrigger() }
From source file:storybook.model.EntityUtil.java
public static JPopupMenu createPopupMenu(MainFrame mainFrame, AbstractEntity entity) { JPopupMenu menu = new JPopupMenu(); if (entity == null) { return null; }//from www .ja v a 2s. c om if (entity.isTransient()) { return null; } JLabel lbTitle = new JLabel(" " + entity.toString()); lbTitle.setFont(FontUtil.getBoldFont()); menu.add(lbTitle); menu.add(new JPopupMenu.Separator()); menu.add(new EditEntityAction(mainFrame, entity, false)); if (entity instanceof Scene) { if (BookUtil.isUseLibreOffice(mainFrame)) { menu.add(new EditSceneLOAction(mainFrame, entity)); } } menu.add(new DeleteEntityAction(mainFrame, entity)); menu.add(new JPopupMenu.Separator()); if (entity instanceof Scene || entity instanceof Chapter) { menu.add(new ShowInChronoViewAction(mainFrame, entity)); menu.add(new ShowInBookViewAction(mainFrame, entity)); menu.add(new ShowInManageViewAction(mainFrame, entity)); } menu.add(new ShowInfoAction(mainFrame, entity)); if (isAvailableInMemoria(entity)) { menu.add(new ShowInMemoriaAction(mainFrame, entity)); } menu.add(new JPopupMenu.Separator()); if (entity instanceof Scene) { } if (entity instanceof Chapter) { menu.add(new ChapterOrderByTimestampAction(mainFrame, (Chapter) entity)); menu.add(new ChapterReSortAction(mainFrame, (Chapter) entity)); menu.add(new JPopupMenu.Separator()); } menu.add(new NewEntityAction(mainFrame, entity)); if (entity instanceof Location) { // google maps menu.add(new JPopupMenu.Separator()); menu.add(new ShowInGoogleMapsAction((Location) entity)); } if (menu.getComponents().length == 0) { return null; } return menu; }
From source file:storybook.toolkit.swing.SwingUtil.java
public static void addCopyPasteToPopupMenu(JPopupMenu menu, JComponent comp) { HashMap<Object, Action> actions = SwingUtil.createActionTable((JTextComponent) comp); Action cutAction = actions.get(DefaultEditorKit.cutAction); JMenuItem miCut = new JMenuItem(cutAction); miCut.setText(I18N.getMsg("msg.common.cut")); miCut.setIcon(I18N.getIcon("icon.small.cut")); menu.add(miCut); Action copyAction = actions.get(DefaultEditorKit.copyAction); JMenuItem miCopy = new JMenuItem(copyAction); miCopy.setText(I18N.getMsg("msg.common.copy")); miCopy.setIcon(I18N.getIcon("icon.small.copy")); menu.add(miCopy);//from w w w .ja v a 2s. co m Action pasteAction = actions.get(DefaultEditorKit.pasteAction); JMenuItem miPaste = new JMenuItem(pasteAction); miPaste.setText(I18N.getMsg("msg.common.paste")); miPaste.setIcon(I18N.getIcon("icon.small.paste")); menu.add(miPaste); }
From source file:storybook.toolkit.swing.SwingUtil.java
public static void addCopyToPopupMenu(JPopupMenu menu, JComponent comp) { HashMap<Object, Action> actions = SwingUtil.createActionTable((JTextComponent) comp); Action copyAction = actions.get(DefaultEditorKit.copyAction); JMenuItem miCopy = new JMenuItem(copyAction); miCopy.setText(I18N.getMsg("msg.common.copy")); miCopy.setIcon(I18N.getIcon("icon.small.copy")); menu.add(miCopy); }
From source file:studio.ui.Studio.java
private void rebuildMenus(TabIndexChanged event) { AppMenuBar appMenubar = getJMenuBar() instanceof AppMenuBar ? (AppMenuBar) getJMenuBar() : null; ToolBarActions toolBar = null;// w w w .j av a 2 s.c om ActionMenu menuBar = null; if (appToolbar == null && appMenubar == null) { appToolbar = new ToolBarActions(); getContentPane().add(appToolbar, BorderLayout.NORTH); appMenubar = new AppMenuBar(); setJMenuBar(appMenubar); toolBar = new ToolBarActions("File"); menuBar = new ActionMenu("File", 'f', "File operations", (MouseAdapter) null); Action action = new NewFileAction(tabEditors, tabConsoles); JPopupMenu popupMenu = new JPopupMenu(); JMenuItem item = new JMenuItem("Script"); item.setToolTipText("New script"); item.addMouseListener(new ActionHintsListener(tabEditors, "Create new script")); item.addActionListener(action); popupMenu.add(item); item = new JMenuItem("Project"); item.setToolTipText("New project"); item.addMouseListener(new ActionHintsListener(tabEditors, "Create new project")); try { item.addActionListener(new AddProjectAction(treeProjects)); popupMenu.add(item); } catch (StudioException ex) { } JButton button = new DropDownButton(action, popupMenu); if (button instanceof DataListener) { tabEditors.addFireDataListener((DataListener) button); } button.addMouseListener(new ActionHintsListener(tabEditors, action)); toolBar.add(button); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); action = new OpenFileAction(tabEditors, tabConsoles); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); popupMenu = null; if (studioConfig.getOpenedFiles() != null && !studioConfig.getOpenedFiles().isEmpty()) { popupMenu = new JPopupMenu(); int pos = 0; for (EditorFile file : studioConfig.getOpenedFiles()) { item = new JMenuItem((char) (pos + 48) + " " + file.getPath(), pos + 48); item.addMouseListener(new ActionHintsListener(tabEditors, "Open file " + file)); popupMenu.add(item); if (++pos > 9) { break; } } } button = new DropDownButton(action, popupMenu); if (button instanceof DataListener) { tabEditors.addFireDataListener((DataListener) button); } button.addMouseListener(new ActionHintsListener(tabEditors, action)); toolBar.add(button); appToolbar.add(toolBar); appMenubar.add(menuBar); appToolbar.add(new ToolBarActions("KDB+")); appMenubar.add(new ActionMenu("KDB+", 'k', "KDB+ databse operations", (MouseAdapter) null)); appToolbar.add(new ToolBarActions("Edit")); appMenubar.add(new ActionMenu("Edit", 'E', "Editor operations", (MouseAdapter) null)); toolBar = new ToolBarActions("Options"); appToolbar.add(toolBar); menuBar = new ActionMenu("Tools", 'T', "Tools", (MouseAdapter) null); ActionMenu opMenuBar = new ActionMenu("Options", 'O', "Studio settings", (MouseAdapter) null); ActionMenu lfMenuBar = new ActionMenu("Look and feel", 'L', "L&F", (MouseAdapter) null); LookAndFeelAction.getActionLookAndFeel(this, lfMenuBar, studioConfig); opMenuBar.add(lfMenuBar); opMenuBar.addSeparator(); action = new EditorSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); action = new TokensSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); opMenuBar.addSeparator(); action = new ConsoleSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); opMenuBar.addSeparator(); action = new ConnectionsSettingsAction(treeConnections); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); menuBar.add(opMenuBar); opMenuBar.addSeparator(); action = new GlobalSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); appMenubar.add(menuBar); opMenuBar.addSeparator(); action = new ProjectSettingsAction(this); opMenuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); appMenubar.add(menuBar); menuBar = new ActionMenu("Help", 'H', "Help...", (MouseAdapter) null); action = new VisitKxAction(); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); menuBar.addSeparator(); action = new VisitWroclawAction(); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); menuBar.addSeparator(); action = new KeyListAction(tabEditors); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); menuBar.addSeparator(); action = new AboutAction(tabEditors); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); appMenubar.add(menuBar); menuBar.addSeparator(); action = new CheckUpdate(this); menuBar.add(new ActionMenuItem(action, new ActionHintsListener(tabEditors, action))); appMenubar.add(menuBar); toolBar = null; this.setJMenuBar(appMenubar); } appToolbar.getToolBar("Edit").setVisible(event != null && event.getData() != -1); appToolbar.getToolBar("Options").setVisible(event != null && event.getData() != -1); appToolbar.getToolBar("KDB+").setVisible(event != null && event.getData() != -1); appToolbar.getToolBar("File").setVisible(event != null && event.getData() != -1); appMenubar.getMenu("Edit").setVisible(event != null && event.getData() != -1); appMenubar.getMenu("Tools").setVisible(event != null && event.getData() != -1); appMenubar.getMenu("KDB+").setVisible(event != null && event.getData() != -1); appMenubar.getMenu("File").setVisible(event != null && event.getData() != -1); if (event != null && event.getSource() instanceof EditorsTabbedPane && event.getData() != -1) { Editor editor = ((EditorsTabbedPane) event.getSource()).getEditor(event.getData()); if (editor != null) { JPopupMenu menu = editor.getComponentPopupMenu(); if (menu != null) { for (int count = 0; count < menu.getComponentCount(); count++) { if (menu.getComponent(count) instanceof JMenuItem) { JMenuItem menuItem = (JMenuItem) menu.getComponent(count); if (menuItem.getAction().getClass() == SaveAction.class) { appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction(), true); appMenubar.getMenu("File").update(tabEditors, menuItem.getAction(), true); } else { if (menuItem.getAction().getClass() == SaveAsAction.class || menuItem.getAction().getClass() == SaveAllAction.class) { appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction()); appMenubar.getMenu("File").update(tabEditors, menuItem.getAction()); } else { if (menuItem.getAction().getClass() == CloseAction.class) { appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction(), true); appMenubar.getMenu("File").update(tabEditors, menuItem.getAction(), true); } else { if (menuItem.getAction().getClass() == CloseAllAction.class) { appToolbar.getToolBar("File").update(tabEditors, menuItem.getAction()); appMenubar.getMenu("File").update(tabEditors, menuItem.getAction()); } else { if (menuItem.getAction().getClass() == RunAction.class || menuItem.getAction().getClass() == RunLineAction.class || menuItem.getAction().getClass() == CancelRunAction.class) { appToolbar.getToolBar("KDB+").update(tabEditors, menuItem.getAction()); appMenubar.getMenu("KDB+").update(tabEditors, menuItem.getAction()); } else { if (menuItem.getAction().getClass() == ExtKit.ReplaceAction.class || menuItem.getAction() .getClass() == ActionFactory.RedoAction.class || menuItem.getAction() .getClass() == ActionFactory.UndoAction.class || menuItem.getAction() .getClass() == BaseKit.CopyAction.class || menuItem.getAction() .getClass() == BaseKit.PasteAction.class || menuItem.getAction() .getClass() == ExtKit.GotoAction.class || menuItem.getAction() .getClass() == BaseKit.SelectAllAction.class || menuItem.getAction() .getClass() == BaseKit.SelectLineAction.class || menuItem.getAction() .getClass() == BaseKit.CutAction.class) { appToolbar.getToolBar("Edit").update(tabEditors, menuItem.getAction()); if (menuItem.getAction().getClass() == ExtKit.GotoAction.class || menuItem.getAction() .getClass() == BaseKit.CopyAction.class || menuItem.getAction() .getClass() == BaseKit.SelectAllAction.class) { appMenubar.getMenu("Edit").update(tabEditors, menuItem.getAction(), true); } else { appMenubar.getMenu("Edit").update(tabEditors, menuItem.getAction()); } } } } } } } } } } } } if (event != null && event.getData() != -1 && event.getSource() instanceof EditorsTabbedPane && ((EditorsTabbedPane) event.getSource()).getEditor(event.getData()) != null) { ((EditorsTabbedPane) event.getSource()).getEditor(event.getData()).requestFocus(); } }
From source file:utybo.branchingstorytree.swing.editor.StoryNodesEditor.java
private JPopupMenu createMenu() { JPopupMenu createMenu = new JPopupMenu(); createMenu.add(new AbstractAction(Lang.get("editor.panel.text"), // new ImageIcon(Icons.getImage("TextNode", 16))) { @Override//w w w . j a v a 2 s . c o m public void actionPerformed(ActionEvent e) { addNode(new StoryTextNodeEditor(StoryNodesEditor.this)); } }); createMenu.add(new AbstractAction(Lang.get("editor.panel.virtual"), new ImageIcon(Icons.getImage("VirtualNode", 16))) { @Override public void actionPerformed(ActionEvent e) { addNode(new StoryVirtualNodeEditor(StoryNodesEditor.this)); } }); createMenu.add(new AbstractAction(Lang.get("editor.panel.logical"), new ImageIcon(Icons.getImage("LogicalNode", 16))) { @Override public void actionPerformed(ActionEvent e) { addNode(new StoryLogicalNodeEditor(StoryNodesEditor.this)); } }); return createMenu; }
From source file:view.MainWindow.java
private void setupTreePopups() { jtOpenedDocuments.addMouseListener(new MouseAdapter() { @Override/* w ww . j av a 2 s . c om*/ public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { JPopupMenu popup = new JPopupMenu(); if (null != jtOpenedDocuments.getSelectionRows()) { if (1 >= jtOpenedDocuments.getSelectionRows().length) { int row = jtOpenedDocuments.getClosestRowForLocation(e.getX(), e.getY()); jtOpenedDocuments.setSelectionRow(row); } else { int row = jtOpenedDocuments.getClosestRowForLocation(e.getX(), e.getY()); boolean selected = false; for (int i : jtOpenedDocuments.getSelectionRows()) { if (i == row) { selected = true; break; } } if (!selected) { jtOpenedDocuments.setSelectionRow(row); } } JMenuItem m = null; ActionListener open = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { loadPdf(getSelectedFile(jtOpenedDocuments), true); } }; ActionListener remove = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { closeDocument(true); } }; ActionListener removeOthers = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final ArrayList<File> alFilesToClose = new ArrayList<>(); boolean showDialog = false; for (File file : getOpenedFiles()) { if (!getSelectedOpenedFiles().contains(file)) { alFilesToClose.add(file); if (file.equals(openedFile)) { showDialog = true; } } } closeDocuments(alFilesToClose, showDialog); } }; ActionListener removeAll = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { closeDocuments(getOpenedFiles(), true); } }; ActionListener show = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().open(getSelectedFile(jtOpenedDocuments).getParentFile()); } catch (IOException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } }; if (!openedFile.equals(getSelectedFile(jtOpenedDocuments))) { m = new JMenuItem(Bundle.getBundle().getString("menuItem.open")); m.addActionListener(open); popup.add(m); } m = new JMenuItem(getSelectedOpenedFiles().size() > 1 ? Bundle.getBundle().getString("menuItem.removeTheseLoadedDocuments") : Bundle.getBundle().getString("menuItem.removeThisLoadedDocument")); m.addActionListener(remove); popup.add(m); if (getOpenedFiles().size() > 1) { m = new JMenuItem(Bundle.getBundle().getString("menuItem.removeOtherLoadedDocuments")); m.addActionListener(removeOthers); popup.add(m); m = new JMenuItem(Bundle.getBundle().getString("menuItem.removeAllLoadedDocuments")); m.addActionListener(removeAll); popup.add(m); } if (getSelectedOpenedFiles().size() == 1) { m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer")); m.addActionListener(show); popup.add(m); } popup.show(e.getComponent(), e.getX(), e.getY()); } } } }); jtExplorer.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { JPopupMenu popup = new JPopupMenu(); if (null != jtExplorer.getSelectionRows()) { if (1 >= jtExplorer.getSelectionRows().length) { int row = jtExplorer.getClosestRowForLocation(e.getX(), e.getY()); jtExplorer.setSelectionRow(row); } else { int row = jtExplorer.getClosestRowForLocation(e.getX(), e.getY()); boolean selected = false; for (int i : jtExplorer.getSelectionRows()) { if (i == row) { selected = true; break; } } if (!selected) { jtExplorer.setSelectionRow(row); } } JMenuItem m = null; ActionListener loadFile = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (jtExplorer.getSelectionRows().length == 1) { loadPdf(getSelectedFile(jtExplorer), true); } else { ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer); for (File f : sl) { loadPdf(f, false); } } } }; ActionListener loadFolder = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (jtExplorer.getSelectionRows().length == 1) { File f = getSelectedFile(jtExplorer); loadFolder(f, false); } else { ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer); for (File f : sl) { loadFolder(f, false); } } } }; ActionListener loadFolderRecursively = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (jtExplorer.getSelectionRows().length == 1) { File f = getSelectedFile(jtExplorer); loadFolder(f, true); } else { ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer); for (File s : sl) { loadFolder(s, true); } } } }; ActionListener remove = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ArrayList<File> listaF = getMultipleSelectedFiles(jtExplorer); closeDocuments(listaF, true); } }; ActionListener show = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop() .open(getSelectedFile(jtExplorer).isFile() ? getSelectedFile(jtExplorer).getParentFile() : getSelectedFile(jtExplorer)); } catch (IOException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } }; if (files.isEmpty()) { if (jtExplorer.getSelectionRows().length <= 1) { File f = getSelectedFile(jtExplorer); if (f.isDirectory()) { m = new JMenuItem( Bundle.getBundle().getString("menuItem.openDocumentsInThisFolder")); m.addActionListener(loadFolder); popup.add(m); m = new JMenuItem(Bundle.getBundle() .getString("menuItem.openDocumentsThisFolderRecursive")); m.addActionListener(loadFolderRecursively); popup.add(m); m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer")); m.addActionListener(show); popup.add(m); } else { m = new JMenuItem(Bundle.getBundle().getString("menuItem.openDocument")); m.addActionListener(loadFile); popup.add(m); m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer")); m.addActionListener(show); popup.add(m); } } else { ArrayList<File> l = getMultipleSelectedFiles(jtExplorer); boolean file = l.get(0).isFile(); boolean allSame = true; for (File f : l) { if (file != f.isFile()) { allSame = false; break; } } if (allSame) { if (file) { m = new JMenuItem(Bundle.getBundle().getString("menuItem.openDocuments")); m.addActionListener(loadFile); popup.add(m); } else { m = new JMenuItem(Bundle.getBundle() .getString("menuItem.openDocumentsInTheseFolders")); m.addActionListener(loadFolder); popup.add(m); } } } } else { File f = getSelectedFile(jtExplorer); if (f.isDirectory()) { m = new JMenuItem( Bundle.getBundle().getString("menuItem.openDocumentsInThisFolder")); m.addActionListener(loadFolder); popup.add(m); m = new JMenuItem( Bundle.getBundle().getString("menuItem.openDocumentsThisFolderRecursive")); m.addActionListener(loadFolderRecursively); popup.add(m); } else if (files.contains(getSelectedFile(jtExplorer))) { m = new JMenuItem( Bundle.getBundle().getString("menuItem.removeFromLoadedDocuments")); m.addActionListener(remove); popup.add(m); } else { m = new JMenuItem(Bundle.getBundle().getString("menuItem.addToLoadedDocuments")); m.addActionListener(loadFile); popup.add(m); } } popup.show(e.getComponent(), e.getX(), e.getY()); } } } }); jtExplorer.setCellRenderer(new TooltipTreeCellRenderer()); ToolTipManager.sharedInstance().registerComponent(jtExplorer); FileListTreeCellRenderer renderer1 = new FileListTreeCellRenderer((MainWindow) this); jtOpenedDocuments.setCellRenderer(renderer1); ToolTipManager.sharedInstance().registerComponent(jtOpenedDocuments); }
From source file:view.WorkspacePanel.java
private void btnValidateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnValidateActionPerformed if (mainWindow.getOpenedFiles().size() > 1) { JPopupMenu popup = new JPopupMenu(); JMenuItem m = null;/* w w w . j a v a2s.c o m*/ ActionListener validateOne = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!rightPanel.isVisible()) { changeCard(CardEnum.VALIDATE_PANEL, true); startValidationThread(); } else if (WorkspacePanel.this.status == WorkspacePanel.Status.SIGNING) { String msg = Bundle.getBundle().getString("yes"); Object[] options = { Bundle.getBundle().getString("msg.signatureStillNotAppliedCancel1"), Bundle.getBundle().getString("no") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { status = Status.READY; changeCard(CardEnum.VALIDATE_PANEL, true); startValidationThread(); } } } }; ActionListener validateAll = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MultipleValidationDialog mvd = new MultipleValidationDialog(mainWindow, true, mainWindow.getOpenedFiles()); mvd.setLocationRelativeTo(null); mvd.setVisible(true); } }; int numSigs = CCInstance.getInstance().getNumberOfSignatures(document.getDocumentLocation()); if (numSigs == 0) { m = new JMenuItem(Bundle.getBundle().getString("notSigned")); m.addActionListener(validateOne); m.setEnabled(false); popup.add(m); } else { m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateOnlyThis")); m.addActionListener(validateOne); popup.add(m); } if (mainWindow.getSelectedOpenedFiles().size() > 1 && mainWindow.getSelectedOpenedFiles().size() < mainWindow.getOpenedFiles().size()) { m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateAllSelected")); m.addActionListener(validateAll); popup.add(m); m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateAll")); m.addActionListener(validateAll); popup.add(m); } else { m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateAll")); m.addActionListener(validateAll); popup.add(m); } popup.setLightWeightPopupEnabled(true); popup.show(btnValidate, 0, btnValidate.getHeight()); } else if (!rightPanel.isVisible()) { changeCard(CardEnum.VALIDATE_PANEL, true); startValidationThread(); } else if (WorkspacePanel.this.status == WorkspacePanel.Status.SIGNING) { String msg = Bundle.getBundle().getString("msg.signatureStillNotAppliedCancel1"); Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { status = Status.READY; changeCard(CardEnum.VALIDATE_PANEL, true); startValidationThread(); } else { return; } } removeTempSignature(); }
From source file:xtrememp.XtremeMP.java
protected void createPanels() { JPanel framePanel = new JPanel(new MigLayout("fill")); mainPanel = new JPanel(new CardLayout()); playlistManager = new PlaylistManager(this); visualizationManager = new VisualizationManager(audioPlayer.getDSS()); if (Settings.getLastView().equals(Utilities.VISUALIZATION_PANEL)) { visualizationManager.setDssEnabled(true); mainPanel.add(visualizationManager, Utilities.VISUALIZATION_PANEL); mainPanel.add(playlistManager, Utilities.PLAYLIST_MANAGER); visualizationMenuItem.setSelected(true); } else {/* ww w . j av a2s .c om*/ mainPanel.add(playlistManager, Utilities.PLAYLIST_MANAGER); mainPanel.add(visualizationManager, Utilities.VISUALIZATION_PANEL); playlistManagerMenuItem.setSelected(true); } framePanel.add(mainPanel, "grow"); JPanel southPanel = new JPanel(new MigLayout("fill", "[center]")); SubstanceLookAndFeel.setDecorationType(southPanel, DecorationAreaType.TOOLBAR); seekSlider = new SeekSlider(this); seekSlider.setEnabled(false); southPanel.add(seekSlider, "north, gap 4 4 1 0"); controlPanel = new JPanel(new MigLayout("gap 0, ins 0", "[center]")); controlPanel.setOpaque(false); stopButton = new StopButton(); stopButton.setEnabled(false); stopButton.addActionListener(this); controlPanel.add(stopButton); previousButton = new PreviousButton(); previousButton.setEnabled(false); previousButton.addActionListener(this); controlPanel.add(previousButton); playPauseButton = new PlayPauseButton(); playPauseButton.addActionListener(this); controlPanel.add(playPauseButton, "height pref!"); nextButton = new NextButton(); nextButton.setEnabled(false); nextButton.addActionListener(this); controlPanel.add(nextButton); volumeButton = new VolumeButton(Utilities.MIN_GAIN, Utilities.MAX_GAIN, Settings.getGain(), Settings.isMuted()); volumeButton.addMouseWheelListener((MouseWheelEvent e) -> { try { int volumeValue = volumeSlider.getValue() - 5 * e.getWheelRotation(); int volumeMin = volumeSlider.getMinimum(); int volumeMax = volumeSlider.getMaximum(); if (volumeValue < volumeMin) { volumeValue = volumeMin; } else if (volumeValue > volumeMax) { volumeValue = volumeMax; } volumeButton.setVolumeIcon(volumeValue); volumeSlider.setValue(volumeValue); audioPlayer.setGain(volumeValue / 100.0F); Settings.setGain(volumeValue); } catch (PlayerException ex) { logger.debug(ex.getMessage(), ex); } }); JPopupMenu volumePopupMenu = volumeButton.getPopupMenu(); volumeSlider = new JSlider(JSlider.VERTICAL, Utilities.MIN_GAIN, Utilities.MAX_GAIN, Settings.getGain()); volumeSlider.setMajorTickSpacing(25); volumeSlider.setMinorTickSpacing(5); volumeSlider.setPaintTicks(true); volumeSlider.setPaintLabels(true); volumeSlider.addChangeListener((ChangeEvent e) -> { if (volumeSlider.getValueIsAdjusting()) { try { int volumeValue = volumeSlider.getValue(); volumeButton.setVolumeIcon(volumeValue); audioPlayer.setGain(volumeValue / 100.0F); Settings.setGain(volumeValue); } catch (PlayerException ex) { logger.debug(ex.getMessage(), ex); } } }); volumeSlider.setEnabled(!Settings.isMuted()); JPanel volumePanel = new JPanel(new MigLayout("fill")); JLabel volumeLabel = new JLabel(tr("MainFrame.Menu.Player.Volume"), JLabel.CENTER); volumeLabel.setFont(volumeLabel.getFont().deriveFont(Font.BOLD)); volumePanel.add(volumeLabel, "north"); volumePanel.add(volumeSlider); JCheckBox muteCheckBox = new JCheckBox(tr("MainFrame.Menu.Player.Mute")); muteCheckBox.setSelected(Settings.isMuted()); muteCheckBox.addItemListener((ItemEvent e) -> { try { if (e.getStateChange() == ItemEvent.SELECTED) { volumeSlider.setEnabled(false); volumeButton.setVolumeMutedIcon(); audioPlayer.setMuted(true); Settings.setMuted(true); } else { volumeSlider.setEnabled(true); volumeButton.setVolumeIcon(Settings.getGain()); audioPlayer.setMuted(false); Settings.setMuted(false); } } catch (PlayerException ex) { logger.debug(ex.getMessage(), ex); } }); volumePanel.add(muteCheckBox, "south"); volumePopupMenu.add(volumePanel); controlPanel.add(volumeButton); southPanel.add(controlPanel, "gap 0 0 2 5"); JPanel statusBar = new JPanel(new MigLayout("ins 2 0 2 0")); SubstanceLookAndFeel.setDecorationType(statusBar, DecorationAreaType.FOOTER); timeLabel = new JLabel(Utilities.ZERO_TIMER); timeLabel.setFont(timeLabel.getFont().deriveFont(Font.BOLD)); statusBar.add(timeLabel, "gap 6 6 0 0, west"); statusBar.add(new JSeparator(SwingConstants.VERTICAL), "hmin 16"); statusLabel = new JLabel(); statusBar.add(statusLabel, "gap 0 2 0 0, wmin 0, push"); statusBar.add(new JSeparator(SwingConstants.VERTICAL), "hmin 16"); playModeLabel = new JLabel(); playModeLabel.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { Playlist.PlayMode[] playModes = Playlist.PlayMode.values(); Playlist.PlayMode playMode = playlist.getPlayMode(); int ordinal = playMode.ordinal(); playlist.setPlayMode(playModes[(ordinal == playModes.length - 1) ? 0 : ordinal + 1]); } }); statusBar.add(playModeLabel, "east, gap 2 2 2 2, width 18!, height 18!"); southPanel.add(statusBar, "south"); framePanel.add(southPanel, "south"); mainFrame.setContentPane(framePanel); }