List of usage examples for javax.swing JRadioButtonMenuItem isSelected
public boolean isSelected()
From source file:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java
private JMenu getjTypSortMenu() { JMenu typSortMenu = new JMenu("Typ Sortierung"); JRadioButtonMenuItem inOrder = new JRadioButtonMenuItem("Aufsteigend Sortieren"); inOrder.setSelected(ConfigReader.getInstance().isTypeInOrder()); inOrder.addActionListener(new ActionListener() { @Override/*from ww w . ja va 2s.c o m*/ public void actionPerformed(ActionEvent actionEvent) { try { ConfigReader.getInstance().setTypeInOrder(inOrder.isSelected()); // if (kabelTypAuswahlAAS != null) { // kabelTypAuswahlAAS.typSelected(kabelTypAuswahlAAS.getSelected()); // } } catch (IOException e) { e.printStackTrace(); } } }); typSortMenu.add(inOrder); typSortMenu.addSeparator(); ButtonGroup group = new ButtonGroup(); for (AbstractTypeSort aTS : ConfigReader.getInstance().getAllTypSort()) { JRadioButtonMenuItem sw = new JRadioButtonMenuItem(aTS.getName()); sw.setSelected(aTS.equals(ConfigReader.getInstance().getKabeltypSort())); group.add(sw); typSortMenu.add(sw); sw.addActionListener(aTS); } return typSortMenu; }
From source file:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java
private JMenu getjTrommelSortMenu() { JMenu trommelSortMenu = new JMenu("Trommel Sortierung"); JRadioButtonMenuItem inOrder = new JRadioButtonMenuItem("Aufsteigend Sortieren"); inOrder.setSelected(ConfigReader.getInstance().isTypeInOrder()); inOrder.addActionListener(new ActionListener() { @Override/*from w w w. ja v a 2 s . c o m*/ public void actionPerformed(ActionEvent actionEvent) { try { ConfigReader.getInstance().setTrommelInOrder(inOrder.isSelected()); // if (kabelTypAuswahlAAS != null) { // kabelTypAuswahlAAS.typSelected(kabelTypAuswahlAAS.getSelected()); // } } catch (IOException e) { e.printStackTrace(); } } }); trommelSortMenu.add(inOrder); trommelSortMenu.addSeparator(); ButtonGroup group = new ButtonGroup(); for (AbstractTrommelSort aTS : ConfigReader.getInstance().getAllTrommelSort()) { JRadioButtonMenuItem sw = new JRadioButtonMenuItem(aTS.getName()); sw.setSelected(aTS.equals(ConfigReader.getInstance().getTrommelSort())); group.add(sw); trommelSortMenu.add(sw); sw.addActionListener(aTS); } return trommelSortMenu; }
From source file:org.cds06.speleograph.graph.SeriesMenu.java
private JPopupMenu createPopupMenuForSeries(final Series series) { if (series == null) return new JPopupMenu(); final JPopupMenu menu = new JPopupMenu(series.getName()); menu.removeAll();// ww w. j a v a 2 s . c o m menu.add(new AbstractAction() { { putValue(NAME, "Renommer la srie"); } @Override public void actionPerformed(ActionEvent e) { menu.setVisible(false); String newName = ""; while (newName == null || newName.equals("")) { newName = (String) JOptionPane.showInputDialog(application, "Entrez un nouveau nom pour la srie", null, JOptionPane.QUESTION_MESSAGE, null, null, series.getName()); } series.setName(newName); } }); if (series.hasOwnAxis()) { menu.add(new AbstractAction() { { putValue(NAME, "Supprimer l'axe spcifique"); } @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes vous sr de vouloir supprimer cet axe ?", "Confirmation", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { series.setAxis(null); } } }); } else { menu.add(new JMenuItem(new AbstractAction() { { putValue(NAME, "Crer un axe spcifique pour la srie"); } @Override public void actionPerformed(ActionEvent e) { String name = JOptionPane.showInputDialog(application, "Quel titre pour cet axe ?", series.getAxis().getLabel()); if (name == null || "".equals(name)) return; // User has canceled series.setAxis(new NumberAxis(name)); } })); } menu.add(new SetTypeMenu(series)); if (series.isWater()) { menu.addSeparator(); menu.add(new SumOnPeriodAction(series)); menu.add(new CreateCumulAction(series)); } if (series.isWaterCumul()) { menu.addSeparator(); menu.add(new SamplingAction(series)); } if (series.isPressure()) { menu.addSeparator(); menu.add(new CorrelateAction(series)); menu.add(new WaterHeightAction(series)); } menu.addSeparator(); menu.add(new AbstractAction() { { String name; if (series.canUndo()) name = "Annuler " + series.getItemsName(); else name = series.getLastUndoName(); putValue(NAME, name); if (series.canUndo()) setEnabled(true); else { setEnabled(false); } } @Override public void actionPerformed(ActionEvent e) { series.undo(); } }); menu.add(new AbstractAction() { { String name; if (series.canRedo()) { name = "Refaire " + series.getNextRedoName(); setEnabled(true); } else { name = series.getNextRedoName(); setEnabled(false); } putValue(NAME, name); } @Override public void actionPerformed(ActionEvent e) { series.redo(); } }); menu.add(new AbstractAction() { { putValue(NAME, I18nSupport.translate("menus.serie.resetSerie")); if (series.canUndo()) setEnabled(true); else setEnabled(false); } @Override public void actionPerformed(ActionEvent e) { series.reset(); } }); menu.add(new LimitDateRangeAction(series)); menu.add(new HourSettingAction(series)); menu.addSeparator(); { JMenuItem deleteItem = new JMenuItem("Supprimer la srie"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes-vous sur de vouloir supprimer cette srie ?\n" + "Cette action est dfinitive.", "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { series.delete(); } } }); menu.add(deleteItem); } menu.addSeparator(); { final JMenuItem up = new JMenuItem("Remonter dans la liste"), down = new JMenuItem("Descendre dans la liste"); ActionListener listener = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (e.getSource().equals(up)) { series.upSeriesInList(); } else { series.downSeriesInList(); } } }; up.addActionListener(listener); down.addActionListener(listener); if (series.isFirst()) { menu.add(down); } else if (series.isLast()) { menu.add(up); } else { menu.add(up); menu.add(down); } } menu.addSeparator(); { menu.add(new SeriesInfoAction(series)); } { JMenuItem colorItem = new JMenuItem("Couleur de la srie"); colorItem.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { series.setColor(JColorChooser.showDialog(application, I18nSupport.translate("actions.selectColorForSeries"), series.getColor())); } }); menu.add(colorItem); } { JMenu plotRenderer = new JMenu("Affichage de la srie"); final ButtonGroup modes = new ButtonGroup(); java.util.List<DrawStyle> availableStyles; if (series.isMinMax()) { availableStyles = DrawStyles.getDrawableStylesForHighLow(); } else { availableStyles = DrawStyles.getDrawableStyles(); } for (final DrawStyle s : availableStyles) { final JRadioButtonMenuItem item = new JRadioButtonMenuItem(DrawStyles.getHumanCheckboxText(s)); item.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (item.isSelected()) series.setStyle(s); } }); modes.add(item); if (s.equals(series.getStyle())) { modes.setSelected(item.getModel(), true); } plotRenderer.add(item); } menu.add(plotRenderer); } menu.addSeparator(); menu.add(new AbstractAction() { { putValue(Action.NAME, "Fermer le fichier"); } @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes-vous sur de vouloir fermer toutes les sries du fichier ?", "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { final File f = series.getOrigin(); for (final Series s : Series.getInstances().toArray(new Series[Series.getInstances().size()])) { if (s.getOrigin().equals(f)) s.delete(); } } } }); return menu; }
From source file:net.sf.jabref.gui.openoffice.OpenOfficePanel.java
private void showSettingsPopup() { JPopupMenu menu = new JPopupMenu(); final JCheckBoxMenuItem autoSync = new JCheckBoxMenuItem( Localization.lang("Automatically sync bibliography when inserting citations"), preferences.syncWhenCiting()); final JRadioButtonMenuItem useActiveBase = new JRadioButtonMenuItem( Localization.lang("Look up BibTeX entries in the active tab only")); final JRadioButtonMenuItem useAllBases = new JRadioButtonMenuItem( Localization.lang("Look up BibTeX entries in all open databases")); final JMenuItem clearConnectionSettings = new JMenuItem(Localization.lang("Clear connection settings")); ButtonGroup bg = new ButtonGroup(); bg.add(useActiveBase);//from ww w .ja v a2 s . c o m bg.add(useAllBases); if (preferences.useAllDatabases()) { useAllBases.setSelected(true); } else { useActiveBase.setSelected(true); } autoSync.addActionListener(e -> preferences.setSyncWhenCiting(autoSync.isSelected())); useAllBases.addActionListener(e -> preferences.setUseAllDatabases(useAllBases.isSelected())); useActiveBase.addActionListener(e -> preferences.setUseAllDatabases(!useActiveBase.isSelected())); clearConnectionSettings.addActionListener(e -> frame.output(preferences.clearConnectionSettings())); menu.add(autoSync); menu.addSeparator(); menu.add(useActiveBase); menu.add(useAllBases); menu.addSeparator(); menu.add(clearConnectionSettings); menu.show(settingsB, 0, settingsB.getHeight()); }
From source file:net.sf.jabref.openoffice.OpenOfficePanel.java
private void showSettingsPopup() { JPopupMenu menu = new JPopupMenu(); final JCheckBoxMenuItem autoSync = new JCheckBoxMenuItem( Localization.lang("Automatically sync bibliography when inserting citations"), Globals.prefs.getBoolean(JabRefPreferences.SYNC_OO_WHEN_CITING)); final JRadioButtonMenuItem useActiveBase = new JRadioButtonMenuItem( Localization.lang("Look up BibTeX entries in the active tab only")); final JRadioButtonMenuItem useAllBases = new JRadioButtonMenuItem( Localization.lang("Look up BibTeX entries in all open databases")); final JMenuItem clearConnectionSettings = new JMenuItem(Localization.lang("Clear connection settings")); ButtonGroup bg = new ButtonGroup(); bg.add(useActiveBase);/* w w w . j a va 2 s .c om*/ bg.add(useAllBases); if (Globals.prefs.getBoolean(JabRefPreferences.USE_ALL_OPEN_BASES)) { useAllBases.setSelected(true); } else { useActiveBase.setSelected(true); } autoSync.addActionListener( e -> Globals.prefs.putBoolean(JabRefPreferences.SYNC_OO_WHEN_CITING, autoSync.isSelected())); useAllBases.addActionListener( e -> Globals.prefs.putBoolean(JabRefPreferences.USE_ALL_OPEN_BASES, useAllBases.isSelected())); useActiveBase.addActionListener( e -> Globals.prefs.putBoolean(JabRefPreferences.USE_ALL_OPEN_BASES, !useActiveBase.isSelected())); clearConnectionSettings.addActionListener(e -> { Globals.prefs.clear(JabRefPreferences.OO_PATH); Globals.prefs.clear(JabRefPreferences.OO_EXECUTABLE_PATH); Globals.prefs.clear(JabRefPreferences.OO_JARS_PATH); frame.output(Localization.lang("Cleared connection settings.")); }); menu.add(autoSync); menu.addSeparator(); menu.add(useActiveBase); menu.add(useAllBases); menu.addSeparator(); menu.add(clearConnectionSettings); menu.show(settingsB, 0, settingsB.getHeight()); }
From source file:org.f2o.absurdum.puck.gui.PuckFrame.java
/** * Instances and shows Puck's main frame. *///from w w w . ja v a 2s . c o m public PuckFrame() { super(); setLookAndFeel(PuckConfiguration.getInstance().getProperty("look")); /* LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels(); for ( int i = 0 ; i < lfs.length ; i++ ) { if ( lfs[i].getName().toLowerCase().contains("nimbus") ) { try { UIManager.setLookAndFeel(lfs[i].getClassName()); } catch (Exception e) //class not found, instantiation exception, etc. (shouldn't happen) { e.printStackTrace(); } } } */ setSize(PuckConfiguration.getInstance().getIntegerProperty("windowWidth"), PuckConfiguration.getInstance().getIntegerProperty("windowHeight")); setLocation(PuckConfiguration.getInstance().getIntegerProperty("windowLocationX"), PuckConfiguration.getInstance().getIntegerProperty("windowLocationY")); //setSize(600,600); if (PuckConfiguration.getInstance().getBooleanProperty("windowMaximized")) maximizeIfPossible(); //setTitle(Messages.getInstance().getMessage("frame.title")); refreshTitle(); left = new JPanel(); right = new JPanel(); JScrollPane rightScroll = new JScrollPane(right); rightScroll.getVerticalScrollBar().setUnitIncrement(16); //faster scrollbar (by default it was very slow, maybe because component inside is not text component!) split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, rightScroll) { //dynamic resizing of right panel /* public void setDividerLocation ( int pixels ) { if ( propPanel != null ) { double rightPartSize = getContentPane().getWidth() - pixels - 15; System.out.println("rps=" + rightPartSize); System.out.println("mnw=" + this.getMinimumSize().getWidth()); Dimension propPanSize = propPanel.getSize(); int propPanHeight = 0; if (propPanSize != null) propPanHeight = (int) propPanSize.getHeight(); //propPanel.revalidate(); System.out.println("h " + propPanHeight); //if ( rightPartSize >= propPanel.getMinimumSize().getWidth() ) propPanel.setPreferredSize(new Dimension((int)rightPartSize,propPanHeight)); //propPanel.setMinimumSize(new Dimension((int)rightPartSize,propPanHeight)); //propPanel.setMaximumSize(new Dimension((int)rightPartSize,propPanHeight)); //propPanel.setSize(new Dimension((int)rightPartSize,propPanHeight)); propPanel.revalidate(); } super.setDividerLocation(pixels); } */ }; split.setContinuousLayout(true); split.setResizeWeight(0.60); final int dividerLoc = PuckConfiguration.getInstance().getIntegerProperty("dividerLocation", 0); /* SwingUtilities.invokeLater(new Runnable(){ public void run() { */ /* } }); */ split.setOneTouchExpandable(true); getContentPane().add(split); System.out.println(Toolkit.getDefaultToolkit().getBestCursorSize(20, 20)); //it's 32x32. Will have to do it. //Image img = Toolkit.getDefaultToolkit().createImage( getClass().getResource("addCursor32.png") ); //Image img = Toolkit.getDefaultToolkit().createImage("addCursor32.png"); left.setLayout(new BorderLayout()); //right.setLayout(new BoxLayout(right,BoxLayout.LINE_AXIS)); if (PuckConfiguration.getInstance().getBooleanProperty("dynamicFormResizing")) right.setLayout(new BorderLayout()); else right.setLayout(new FlowLayout()); propPanel = new PropertiesPanel(); right.add(propPanel); graphPanel = new GraphEditingPanel(propPanel); graphPanel.setGrid(Boolean.valueOf(PuckConfiguration.getInstance().getProperty("showGrid")).booleanValue()); graphPanel.setSnapToGrid( Boolean.valueOf(PuckConfiguration.getInstance().getProperty("snapToGrid")).booleanValue()); propPanel.setGraphEditingPanel(graphPanel); tools = new PuckToolBar(graphPanel, propPanel, this); left.add(tools, BorderLayout.WEST); left.add(graphPanel, BorderLayout.CENTER); /* Action testAction = new AbstractAction() { public void actionPerformed ( ActionEvent evt ) { System.out.println("Puck!"); } } ; testAction.putValue(Action.NAME,"Print Puck"); tools.add(testAction); */ /* public void saveChanges ( ) { if ( editingFileName == null ) { //save as... code } else { File f = new File(editingFileName); try { Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d)); Transformer t = TransformerFactory.newInstance().newTransformer(); Source s = new DOMSource(d); Result r = new StreamResult(f); t.transform(s,r); editingFileName = f.toString(); refreshTitle(); } catch ( Exception e ) { JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } } */ JMenuBar mainMenuBar = new JMenuBar(); JMenu fileMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file")); fileMenu.setMnemonic(KeyEvent.VK_F); saveMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.save")); saveMenuItem.setMnemonic(KeyEvent.VK_S); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (editingFileName == null) JOptionPane.showMessageDialog(PuckFrame.this, "File has no name!", "Whoops!", JOptionPane.ERROR_MESSAGE); /* File f = new File(editingFileName); try { Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d)); Transformer t = TransformerFactory.newInstance().newTransformer(); Source s = new DOMSource(d); Result r = new StreamResult(f); t.transform(s,r); editingFileName = f.toString(); refreshTitle(); } catch ( Exception e ) { JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } */ try { saveChangesInCurrentFile(); } catch (Exception e) { JOptionPane.showMessageDialog(PuckFrame.this, e.getLocalizedMessage(), "Whoops!", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }); JMenu newMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.new")); JMenuItem newBlankMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.new.blank")); //newBlankMenuItem.setMnemonic(KeyEvent.VK_N); newBlankMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { GraphElementPanel.emptyQueue(); //stop deferred loads graphPanel.clear(); propPanel.clear(); JSyntaxBSHCodeFrame.closeAllInstances(); WorldPanel wp = new WorldPanel(graphPanel); WorldNode wn = new WorldNode(wp); graphPanel.setWorldNode(wn); propPanel.show(graphPanel.getWorldNode()); resetCurrentlyEditingFile(); refreshTitle(); //revalidate(); //only since java 1.7 //invalidate(); //validate(); split.revalidate(); //JComponents do have it before java 1.7 (not JFrame) } }); newMenu.add(newBlankMenuItem); JMenu templateMenus = new WorldTemplateMenuBuilder(this).getMenu(); if (templateMenus != null) { for (int i = 0; i < templateMenus.getItemCount(); i++) { if (i == 0) newMenu.add(new JSeparator()); newMenu.add(templateMenus.getItem(i)); } } JMenuItem saveAsMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.saveas")); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { /* JFileChooser jfc = new JFileChooser("."); int opt = jfc.showSaveDialog(PuckFrame.this); if ( opt == JFileChooser.APPROVE_OPTION ) { File f = jfc.getSelectedFile(); try { Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d)); Transformer t = TransformerFactory.newInstance().newTransformer(); Source s = new DOMSource(d); Result r = new StreamResult(f); t.transform(s,r); editingFileName = f.toString(); saveMenuItem.setEnabled(true); refreshTitle(); } catch ( Exception e ) { JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } */ try { saveAs(); saveMenuItem.setEnabled(true); } catch (Exception e) { JOptionPane.showMessageDialog(PuckFrame.this, e.getLocalizedMessage(), "Whoops!", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } //saveAs(saveMenuItem); } }); JMenuItem openMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.open")); openMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { //graphPanel.setVisible(false); //propPanel.setVisible(false); JFileChooser jfc = new JFileChooser("."); jfc.setFileFilter(new FiltroFicheroMundo()); int opt = jfc.showOpenDialog(PuckFrame.this); if (opt == JFileChooser.APPROVE_OPTION) { File f = jfc.getSelectedFile(); openFileOrShowError(f); } //graphPanel.setVisible(true); //propPanel.setVisible(true); } }); openRecentMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.recent")); JMenuItem exitMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.exit")); exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { /* int opt = JOptionPane.showConfirmDialog(PuckFrame.this,Messages.getInstance().getMessage("exit.sure.text"),Messages.getInstance().getMessage("exit.sure.title"),JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE); if ( opt == JOptionPane.YES_OPTION ) System.exit(0); */ userExit(); } }); JMenu exportMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.export")); JMenuItem exportAppletMenuItem = new JMenuItem( UIMessages.getInstance().getMessage("menu.file.export.applet")); exportAppletMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ExportAppletDialog dial = new ExportAppletDialog(PuckFrame.this); dial.setVisible(true); } }); exportMenu.add(exportAppletMenuItem); fileMenu.add(newMenu); fileMenu.add(openMenuItem); fileMenu.add(openRecentMenu); updateRecentMenu(); fileMenu.add(new JSeparator()); saveMenuItem.setEnabled(false); fileMenu.add(saveMenuItem); fileMenu.add(saveAsMenuItem); fileMenu.add(exportMenu); fileMenu.add(new JSeparator()); fileMenu.add(exitMenuItem); mainMenuBar.add(fileMenu); /** * Create an Edit menu to support cut/copy/paste. */ JMenu editMenu = new JMenu(UIMessages.getInstance().getMessage("menu.edit")); editMenu.setMnemonic(KeyEvent.VK_E); JMenuItem findMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.find.entity")); findMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showFindEntityDialog(); } }); editMenu.add(findMenuItem); editMenu.add(new JSeparator()); JMenuItem aMenuItem = new JMenuItem(new CutAction()); aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.cut")); aMenuItem.setMnemonic(KeyEvent.VK_T); editMenu.add(aMenuItem); aMenuItem = new JMenuItem(new CopyAction()); aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.copy")); aMenuItem.setMnemonic(KeyEvent.VK_C); editMenu.add(aMenuItem); aMenuItem = new JMenuItem(new PasteAction()); aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.paste")); aMenuItem.setMnemonic(KeyEvent.VK_P); editMenu.add(aMenuItem); mainMenuBar.add(editMenu); JMenu optionsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options")); JMenu gridMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options.grid")); optionsMenu.add(gridMenu); final JCheckBoxMenuItem showGridItem = new JCheckBoxMenuItem( UIMessages.getInstance().getMessage("menu.options.grid.show")); showGridItem.setSelected( Boolean.valueOf(PuckConfiguration.getInstance().getProperty("showGrid")).booleanValue()); gridMenu.add(showGridItem); showGridItem.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { graphPanel.setGrid(true); PuckConfiguration.getInstance().setProperty("showGrid", "true"); } else if (e.getStateChange() == ItemEvent.DESELECTED) { graphPanel.setGrid(false); PuckConfiguration.getInstance().setProperty("showGrid", "false"); } graphPanel.repaint(); } }); final JCheckBoxMenuItem snapToGridItem = new JCheckBoxMenuItem( UIMessages.getInstance().getMessage("menu.options.grid.snap")); snapToGridItem.setSelected( Boolean.valueOf(PuckConfiguration.getInstance().getProperty("snapToGrid")).booleanValue()); gridMenu.add(snapToGridItem); snapToGridItem.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { graphPanel.setSnapToGrid(true); PuckConfiguration.getInstance().setProperty("snapToGrid", "true"); } else if (e.getStateChange() == ItemEvent.DESELECTED) { graphPanel.setSnapToGrid(false); PuckConfiguration.getInstance().setProperty("snapToGrid", "false"); } graphPanel.repaint(); } }); JMenuItem translationModeMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options.translation")); ButtonGroup translationGroup = new ButtonGroup(); final JRadioButtonMenuItem holdMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.options.translation.hold")); final JRadioButtonMenuItem pushMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.options.translation.push")); pushMenuItem.setSelected("push".equals(PuckConfiguration.getInstance().getProperty("translateMode"))); if (!pushMenuItem.isSelected()) holdMenuItem.setSelected(true); translationGroup.add(holdMenuItem); translationGroup.add(pushMenuItem); holdMenuItem.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent arg0) { if (holdMenuItem.isSelected()) PuckConfiguration.getInstance().setProperty("translateMode", "hold"); else PuckConfiguration.getInstance().setProperty("translateMode", "push"); } }); translationModeMenu.add(holdMenuItem); translationModeMenu.add(pushMenuItem); optionsMenu.add(translationModeMenu); JMenuItem toolSelectionModeMenu = new JMenu( UIMessages.getInstance().getMessage("menu.options.toolselection")); ButtonGroup toolSelectionGroup = new ButtonGroup(); final JRadioButtonMenuItem oneUseMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.options.toolselection.oneuse")); final JRadioButtonMenuItem multipleUseMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.options.toolselection.multipleuse")); multipleUseMenuItem.setSelected( "multipleUse".equalsIgnoreCase(PuckConfiguration.getInstance().getProperty("toolSelectionMode"))); if (!multipleUseMenuItem.isSelected()) oneUseMenuItem.setSelected(true); toolSelectionGroup.add(oneUseMenuItem); toolSelectionGroup.add(multipleUseMenuItem); oneUseMenuItem.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent arg0) { if (oneUseMenuItem.isSelected()) PuckConfiguration.getInstance().setProperty("toolSelectionMode", "oneUse"); else PuckConfiguration.getInstance().setProperty("toolSelectionMode", "multipleUse"); } }); toolSelectionModeMenu.add(oneUseMenuItem); toolSelectionModeMenu.add(multipleUseMenuItem); optionsMenu.add(toolSelectionModeMenu); JMenuItem sizesMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.iconsizes")); sizesMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { IconSizesDialog dial = new IconSizesDialog(PuckFrame.this, true); dial.setVisible(true); } }); optionsMenu.add(sizesMenuItem); JMenuItem showHideMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.showhide")); showHideMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ShowHideDialog dial = new ShowHideDialog(PuckFrame.this, true); dial.setVisible(true); } }); optionsMenu.add(showHideMenuItem); JMenuItem mapColorsMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.mapcolors")); mapColorsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MapColorsDialog dial = new MapColorsDialog(PuckFrame.this, true); dial.setVisible(true); } }); optionsMenu.add(mapColorsMenuItem); String skinList = PuckConfiguration.getInstance().getProperty("availableSkins"); if (skinList != null && skinList.trim().length() > 0) { JMenu skinsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.skins")); StringTokenizer st = new StringTokenizer(skinList, ", "); ButtonGroup skinButtons = new ButtonGroup(); while (st.hasMoreTokens()) { final String nextSkin = st.nextToken(); final JRadioButtonMenuItem skinMenuItem = new JRadioButtonMenuItem(nextSkin); skinMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setSkin(nextSkin); skinMenuItem.setSelected(true); } }); if (nextSkin.equals(PuckConfiguration.getInstance().getProperty("skin"))) skinMenuItem.setSelected(true); skinsMenu.add(skinMenuItem); skinButtons.add(skinMenuItem); } optionsMenu.add(skinsMenu); } JMenu lookFeelMenu = new JMenu(UIMessages.getInstance().getMessage("menu.looks")); ButtonGroup lookButtons = new ButtonGroup(); final JRadioButtonMenuItem defaultLookMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.looks.default")); if ("default".equals(PuckConfiguration.getInstance().getProperty("look"))) { defaultLookMenuItem.setSelected(true); } lookFeelMenu.add(defaultLookMenuItem); lookButtons.add(defaultLookMenuItem); defaultLookMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLookAndFeel("default"); defaultLookMenuItem.setSelected(true); } }); final JRadioButtonMenuItem systemLookMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.looks.system")); if ("system".equals(PuckConfiguration.getInstance().getProperty("look"))) { systemLookMenuItem.setSelected(true); } lookFeelMenu.add(systemLookMenuItem); lookButtons.add(systemLookMenuItem); systemLookMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLookAndFeel("system"); systemLookMenuItem.setSelected(true); } }); String additionalLookList = PuckConfiguration.getInstance().getProperty("additionalLooks"); if (additionalLookList != null && additionalLookList.trim().length() > 0) { StringTokenizer st = new StringTokenizer(additionalLookList, ", "); while (st.hasMoreTokens()) { final String nextLook = st.nextToken(); final JRadioButtonMenuItem lookMenuItem = new JRadioButtonMenuItem(nextLook); lookMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLookAndFeel(nextLook); lookMenuItem.setSelected(true); } }); if (nextLook.equals(PuckConfiguration.getInstance().getProperty("look"))) { lookMenuItem.setSelected(true); } lookFeelMenu.add(lookMenuItem); lookButtons.add(lookMenuItem); } } optionsMenu.add(lookFeelMenu); optionsMenu.add(new UILanguageSelectionMenu(this)); mainMenuBar.add(optionsMenu); JMenu toolsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.tools")); final JMenuItem verbListMenuItem = new JMenuItem( UIMessages.getInstance().getMessage("menu.tools.verblist")); verbListMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { WorldPanel wp = (WorldPanel) graphPanel.getWorldNode().getAssociatedPanel(); VerbListFrame vlf = VerbListFrame.getInstance(wp.getSelectedLanguageCode()); vlf.setVisible(true); } }); toolsMenu.add(verbListMenuItem); final JMenuItem validateMenuItem = new JMenuItem( UIMessages.getInstance().getMessage("menu.tools.validatebsh")); validateMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { BeanShellCodeValidator bscv = new BeanShellCodeValidator(graphPanel); if (!bscv.validate()) { BeanShellErrorsDialog bsed = new BeanShellErrorsDialog(PuckFrame.this, bscv.getErrorText()); bsed.setVisible(true); //JOptionPane.showMessageDialog(PuckFrame.this, bscv.getErrorText()); } else { JOptionPane.showMessageDialog(PuckFrame.this, UIMessages.getInstance().getMessage("bsh.code.ok"), "OK!", JOptionPane.INFORMATION_MESSAGE); //JOptionPane.showMessageDialog(PuckFrame.this, bscv.getErrorText()); } } }); toolsMenu.add(validateMenuItem); mainMenuBar.add(toolsMenu); JMenu helpMenu = new JMenu(UIMessages.getInstance().getMessage("menu.help")); //JHelpAction.startHelpWorker("help/PUCKHelp.hs"); //JHelpAction helpTocAction = JHelpAction.getShowHelpInstance(Messages.getInstance().getMessage("menu.help.toc")); //JHelpAction helpContextSensitiveAction = JHelpAction.getTrackInstance(Messages.getInstance().getMessage("menu.help.context")); //final JMenuItem helpTocMenuItem = new JMenuItem(helpTocAction); //final JMenuItem helpContextSensitiveMenuItem = new JMenuItem(helpContextSensitiveAction); //helpMenu.add(helpTocMenuItem); //helpMenu.add(helpContextSensitiveMenuItem); final JMenuItem helpMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.help.toc")); helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DocumentationLinkDialog dial = new DocumentationLinkDialog(PuckFrame.this, true); dial.setVisible(true); } }); helpMenu.add(helpMenuItem); mainMenuBar.add(helpMenu); MenuMnemonicOnTheFly.setMnemonics(mainMenuBar); this.setJMenuBar(mainMenuBar); //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { userExit(); } }); propPanel.show(graphPanel.getWorldNode()); setVisible(true); SwingUtilities.invokeLater(new Runnable() { public void run() { if (dividerLoc > 0) split.setDividerLocation(dividerLoc); else split.setDividerLocation(0.60); } }); }
From source file:org.squidy.designer.Designer.java
/** * Initializes menu bar./*from w w w . j a v a 2 s. c o m*/ */ private void initMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu workspace = new JMenu("Workspace"); workspace.add(new AbstractAction("Open from...") { /* * (non-Javadoc) * * @see * java.awt.event.ActionListener#actionPerformed(java.awt.event. * ActionEvent) */ public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileHidingEnabled(true); fileChooser.setFileFilter(new FileFilter() { /* * (non-Javadoc) * * @see * javax.swing.filechooser.FileFilter#accept(java.io.File) */ @Override public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith(".sdy"); } /* * (non-Javadoc) * * @see javax.swing.filechooser.FileFilter#getDescription() */ @Override public String getDescription() { return "Squidy Workspace"; } }); int option = fileChooser.showOpenDialog(Designer.this); if (option == JFileChooser.APPROVE_OPTION) { // Stop replacing workspace if currently running. if (data != null) { data.getWorkspace().stop(); } File workspaceFile = fileChooser.getSelectedFile(); if (storage instanceof LocalJAXBStorage) { ((LocalJAXBStorage) storage).setWorkspaceFile(workspaceFile); load(); } else { try { data = ModelViewHandler.getModelViewHandler().load(new FileInputStream(workspaceFile)); WorkspaceShape workspace = data.getWorkspaceShape(); workspace.setModel(data); workspace.setStorageHandler(Designer.this); workspace.initialize(); LayoutConstraint lc = workspace.getLayoutConstraint(); workspace.setScale(lc.getScale()); workspace.setOffset(lc.getX(), lc.getY()); getCanvas().getLayer().addChild(workspace); zoomToZoomedShape(data); } catch (SquidyException e1) { e1.printStackTrace(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } } } } }); workspace.add(new AbstractAction("Export as...") { /* * (non-Javadoc) * * @see * java.awt.event.ActionListener#actionPerformed(java.awt.event. * ActionEvent) */ public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileHidingEnabled(true); fileChooser.setFileFilter(new FileFilter() { /* * (non-Javadoc) * * @see * javax.swing.filechooser.FileFilter#accept(java.io.File) */ @Override public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith(".sdy"); } /* * (non-Javadoc) * * @see javax.swing.filechooser.FileFilter#getDescription() */ @Override public String getDescription() { return "Squidy Workspace"; } }); if (storage instanceof LocalJAXBStorage) { fileChooser.setSelectedFile(((LocalJAXBStorage) storage).getWorkspaceFile()); } int option = fileChooser.showSaveDialog(Designer.this); if (option == JFileChooser.APPROVE_OPTION) { File workspaceFile = fileChooser.getSelectedFile(); try { ModelViewHandler.getModelViewHandler().save(new FileOutputStream(workspaceFile), data); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }); JMenu options = new JMenu("Options"); rendering.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { VisualShape.setRenderPrimitiveRect(rendering.isSelected()); data.setRenderPrimitiveRect(rendering.isSelected()); storage.store(data); repaint(); } }); options.add(rendering); JMenu storage = new JMenu("Storage"); ButtonGroup group = new ButtonGroup(); final JRadioButtonMenuItem storageLocalJAXB = new JRadioButtonMenuItem("Local JAXB"); storageLocalJAXB.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (storageLocalJAXB.isSelected()) { setStorageMode(StorageMode.FILE); } } }); storage.add(storageLocalJAXB); group.add(storageLocalJAXB); final JRadioButtonMenuItem storageBaseX = new JRadioButtonMenuItem("BaseX"); storageBaseX.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (storageBaseX.isSelected()) { setStorageMode(StorageMode.BASEX); } } }); storageBaseX.setSelected(storageType.equals(BaseXStorage.class)); storage.add(storageBaseX); group.add(storageBaseX); options.add(storage); menuBar.add(workspace); menuBar.add(options); setJMenuBar(menuBar); }