List of usage examples for javax.swing JMenuBar add
public JMenu add(JMenu c)
From source file:org.pentaho.reporting.engine.classic.demo.ancient.demo.layouts.internalframe.InternalFrameDemoFrame.java
protected JMenuBar createMenuBar() { final JMenuBar menuBar = new JMenuBar(); //Set up the lone menu. final JMenu menu = new JMenu("Document"); menu.setMnemonic(KeyEvent.VK_D); menuBar.add(menu); menu.add(new JMenuItem(new NewFrameAction())); menu.add(new JMenuItem(getPreviewAction())); menu.addSeparator();/*from w w w. j a v a 2 s.co m*/ menu.add(new JMenuItem(getCloseAction())); final JMenu helpmenu = new JMenu("Help"); helpmenu.setMnemonic(KeyEvent.VK_H); helpmenu.add(new JMenuItem(getAboutAction())); return menuBar; }
From source file:org.photovault.swingui.BrowserWindow.java
protected void createUI(PhotoCollection collection) { window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); tabPane = new JTabbedPane(); queryPane = new QueryPane(); PhotoFolderTreeController treeCtrl = new PhotoFolderTreeController(window, this); viewCtrl = new PhotoViewController(window, this); treePane = treeCtrl.folderTree;/* w w w . ja v a2s . com*/ viewPane = viewCtrl.getThumbPane(); previewPane = viewCtrl.getPreviewPane(); tabPane.addTab("Query", queryPane); tabPane.addTab("Folders", treePane); VolumeTreeController volTreeCtrl = new VolumeTreeController(this); JTree volumeTree = volTreeCtrl.getView(); JScrollPane voltreeScrollPane = new JScrollPane(volumeTree); voltreeScrollPane.setPreferredSize(new Dimension(200, 500)); tabPane.add("Volumes", voltreeScrollPane); // TODO: get rid of this!!!! EditSelectionColorsAction colorAction = (EditSelectionColorsAction) viewPane.getEditSelectionColorsAction(); colorAction.setPreviewCtrl(previewPane); // Set listeners to both query and folder tree panes /* If an actionEvent comes from query pane, swich to query results. */ queryPane.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { viewCtrl.setCollection(queryPane.getResultCollection()); } }); /* If the selected folder is changed in treePane, switch to that immediately */ treeCtrl.registerEventListener(PhotoFolderTreeEvent.class, new DefaultEventListener<PhotoCollection>() { public void handleEvent(DefaultEvent<PhotoCollection> event) { PhotoCollection c = event.getPayload(); if (c != null) { viewCtrl.setCollection(c); if (c instanceof PhotoFolder) { PhotoFolder f = (PhotoFolder) c; if (f.getExternalDir() != null) { ExternalDir ed = f.getExternalDir(); folderIndexer.updateDir(ed.getVolume(), ed.getPath()); viewCtrl.setIndexingOngoing(true); } } } } }); volTreeCtrl.registerEventListener(PhotoFolderTreeEvent.class, new DefaultEventListener<PhotoCollection>() { public void handleEvent(DefaultEvent<PhotoCollection> event) { PhotoCollection c = event.getPayload(); if (c != null) { viewCtrl.setCollection(c); if (c instanceof ExtDirPhotos) { ExtDirPhotos photos = (ExtDirPhotos) c; ExternalVolume vol = (ExternalVolume) viewCtrl.getDAOFactory().getVolumeDAO() .getVolume(photos.getVolId()); folderIndexer.updateDir(vol, photos.getDirPath()); viewCtrl.setIndexingOngoing(true); } } } }); collectionPane = viewCtrl.getCollectionPane(); JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tabPane, collectionPane); split.putClientProperty(JSplitPane.ONE_TOUCH_EXPANDABLE_PROPERTY, new Boolean(true)); Container cp = window.getContentPane(); cp.setLayout(new BorderLayout()); cp.add(split, BorderLayout.CENTER); statusBar = new StatusBar(); cp.add(statusBar, BorderLayout.SOUTH); // Create actions for BrowserWindow UI ImageIcon indexDirIcon = getIcon("index_dir.png"); DefaultAction indexDirAction = new DefaultAction("Index directory...", indexDirIcon) { public void actionPerformed(ActionEvent e) { indexDir(); } }; indexDirAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_D); indexDirAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Index all images in a directory"); this.registerAction("new_ext_vol", indexDirAction); ImageIcon importIcon = getIcon("import.png"); importAction = new AbstractAction("Import image...", importIcon) { public void actionPerformed(ActionEvent e) { importFile(); } }; importAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_O); importAction.putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); importAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Import new image into database"); ImageIcon updateIcon = getIcon("update_indexed_dirs.png"); UpdateIndexAction updateIndexAction = new UpdateIndexAction(viewCtrl, "Update indexed dirs", updateIcon, "Check for changes in previously indexed directories", KeyEvent.VK_U); this.registerAction("update_indexed_dirs", updateIndexAction); updateIndexAction.addStatusChangeListener(statusBar); ImageIcon previewTopIcon = getIcon("view_preview_top.png"); DefaultAction previewTopAction = new DefaultAction("Preview on top", previewTopIcon) { public void actionPerformed(ActionEvent e) { viewCtrl.setLayout(PhotoViewController.Layout.PREVIEW_HORIZONTAL_THUMBS); } }; previewTopAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Show preview on top of thumbnails"); previewTopAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_T); this.registerAction("view_preview_top", previewTopAction); ImageIcon previewRightIcon = getIcon("view_preview_right.png"); DefaultAction previewRightAction = new DefaultAction("Preview on right", previewRightIcon) { public void actionPerformed(ActionEvent e) { viewCtrl.setLayout(PhotoViewController.Layout.PREVIEW_VERTICAL_THUMBS); } }; previewRightAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Show preview on right of thumbnails"); previewRightAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_R); this.registerAction("view_preview_right", previewRightAction); ImageIcon previewNoneIcon = getIcon("view_no_preview.png"); DefaultAction previewNoneAction = new DefaultAction("No preview", previewNoneIcon) { public void actionPerformed(ActionEvent e) { viewCtrl.setLayout(PhotoViewController.Layout.ONLY_THUMBS); } }; previewNoneAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Show no preview image"); previewNoneAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_O); this.registerAction("view_no_preview", previewNoneAction); DefaultAction previewLargeAction = new DefaultAction("Large", null) { public void actionPerformed(ActionEvent e) { viewCtrl.setPreviewSize(200); } }; DefaultAction previewSmallAction = new DefaultAction("Small", null) { public void actionPerformed(ActionEvent e) { viewCtrl.setPreviewSize(100); } }; JToolBar tb = createToolbar(); cp.add(tb, BorderLayout.NORTH); // Create the menu bar & menus JMenuBar menuBar = new JMenuBar(); window.setJMenuBar(menuBar); // File menu JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu); JMenuItem newWindowItem = new JMenuItem("New window", KeyEvent.VK_N); newWindowItem.setIcon(getIcon("window_new.png")); newWindowItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { BrowserWindow br = new BrowserWindow(getParentController(), null); // br.setVisible( true ); } }); fileMenu.add(newWindowItem); JMenuItem importItem = new JMenuItem(importAction); fileMenu.add(importItem); JMenuItem indexDirItem = new JMenuItem(indexDirAction); fileMenu.add(indexDirItem); fileMenu.add(new JMenuItem(viewCtrl.getActionAdapter("update_indexed_dirs"))); ExportSelectedAction exportAction = (ExportSelectedAction) viewPane.getExportSelectedAction(); JMenuItem exportItem = new JMenuItem(exportAction); exportAction.addStatusChangeListener(statusBar); fileMenu.add(exportItem); JMenu dbMenu = new JMenu("Database"); dbMenu.setMnemonic(KeyEvent.VK_B); dbMenu.setIcon(getIcon("empty_icon.png")); ExportMetadataAction exportMetadata = new ExportMetadataAction("Export as XML...", null, "Export whole database as XML file", KeyEvent.VK_E); dbMenu.add(new JMenuItem(exportMetadata)); ImportXMLAction importMetadata = new ImportXMLAction("Import XML data...", null, "Import data from other Photovault database as XML", KeyEvent.VK_I); importMetadata.addStatusChangeListener(statusBar); dbMenu.add(new JMenuItem(importMetadata)); fileMenu.add(dbMenu); JMenuItem exitItem = new JMenuItem("Exit", KeyEvent.VK_X); exitItem.setIcon(getIcon("exit.png")); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); fileMenu.add(exitItem); JMenu viewMenu = new JMenu("View"); viewMenu.setMnemonic(KeyEvent.VK_V); menuBar.add(viewMenu); JMenuItem vertIconsItem = new JMenuItem(previewRightAction); viewMenu.add(vertIconsItem); JMenuItem horzIconsItem = new JMenuItem(previewTopAction); viewMenu.add(horzIconsItem); JMenuItem noPreviewItem = new JMenuItem(previewNoneAction); viewMenu.add(noPreviewItem); JMenuItem nextPhotoItem = new JMenuItem(viewPane.getSelectNextAction()); viewMenu.add(nextPhotoItem); JMenuItem prevPhotoItem = new JMenuItem(viewPane.getSelectPreviousAction()); viewMenu.add(prevPhotoItem); viewMenu.add(new JMenuItem(previewSmallAction)); viewMenu.add(new JMenuItem(previewLargeAction)); JMenu sortMenu = new JMenu("Sort by"); sortMenu.setMnemonic(KeyEvent.VK_S); sortMenu.setIcon(getIcon("empty_icon.png")); JMenuItem byDateItem = new JMenuItem(new SetPhotoOrderAction(viewCtrl, new ShootingDateComparator(), "Date", null, "Order photos by date", KeyEvent.VK_D)); sortMenu.add(byDateItem); JMenuItem byPlaceItem = new JMenuItem(new SetPhotoOrderAction(viewCtrl, new ShootingPlaceComparator(), "Place", null, "Order photos by shooting place", KeyEvent.VK_P)); sortMenu.add(byPlaceItem); JMenuItem byQualityItem = new JMenuItem(new SetPhotoOrderAction(viewCtrl, new QualityComparator(), "Quality", null, "Order photos by quality", KeyEvent.VK_Q)); sortMenu.add(byQualityItem); viewMenu.add(sortMenu); // Set default ordering by date byDateItem.getAction().actionPerformed(new ActionEvent(this, 0, "Setting default")); JMenu imageMenu = new JMenu("Image"); imageMenu.setMnemonic(KeyEvent.VK_I); menuBar.add(imageMenu); imageMenu.add(new JMenuItem(viewPane.getEditSelectionPropsAction())); imageMenu.add(new JMenuItem(viewPane.getShowSelectedPhotoAction())); imageMenu.add(new JMenuItem(viewCtrl.getActionAdapter("rotate_cw"))); imageMenu.add(new JMenuItem(viewCtrl.getActionAdapter("rotate_ccw"))); imageMenu.add(new JMenuItem(viewCtrl.getActionAdapter("rotate_180"))); imageMenu.add(new JMenuItem(previewPane.getCropAction())); imageMenu.add(new JMenuItem(viewPane.getEditSelectionColorsAction())); imageMenu.add(new JMenuItem(viewPane.getDeleteSelectedAction())); // Create the Quality submenu JMenu qualityMenu = new JMenu("Quality"); qualityMenu.setIcon(getIcon("empty_icon.png")); for (int n = 0; n < 6; n++) { Action qualityAction = viewCtrl.getActionAdapter("quality_" + n); JMenuItem qualityMenuItem = new JMenuItem(qualityAction); qualityMenu.add(qualityMenuItem); } imageMenu.add(qualityMenu); JMenu aboutMenu = new JMenu("About"); aboutMenu.setMnemonic(KeyEvent.VK_A); aboutMenu.add(new JMenuItem(new ShowAboutDlgAction("About Photovault...", null, "", null))); menuBar.add(Box.createHorizontalGlue()); menuBar.add(aboutMenu); window.pack(); window.setVisible(true); }
From source file:org.renjin.studio.MainFrame.java
private void setupMenu() { //Create the menu bar. JMenuBar menuBar = new JMenuBar(); //Build the first menu. JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_A); menuBar.add(fileMenu); JMenu newMenu = new JMenu("New"); newMenu.setMnemonic(KeyEvent.VK_N); JMenuItem newScriptItem = new JMenuItem("R Script"); newMenu.add(newScriptItem);//from w ww . j ava 2s . c o m fileMenu.add(newMenu); setJMenuBar(menuBar); }
From source file:org.richie.codeGen.ui.CodeGenMainUI.java
public void initMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu(""); menuBar.add(fileMenu); openPdmFileItem = new JMenuItem("dpm"); openPdmFileItem.setIcon(new ImageIcon(ClassLoader.getSystemResource("resources/images/pdm.png"))); fileMenu.add(openPdmFileItem);//from w w w .j ava2s.c o m JMenu configMenu = new JMenu("?"); menuBar.add(configMenu); templateConfigItem = new JMenuItem("??"); templateConfigItem.addActionListener(this); configMenu.add(templateConfigItem); consConfigItem = new JMenuItem("??"); consConfigItem.addActionListener(this); configMenu.add(consConfigItem); dataTypeConfigItem = new JMenuItem("??"); dataTypeConfigItem.addActionListener(this); configMenu.add(dataTypeConfigItem); JMenu mnHelp = new JMenu(""); menuBar.add(mnHelp); helpDoc = new JMenuItem(""); helpDoc.setIcon(new ImageIcon(ClassLoader.getSystemResource("resources/images/docs.gif"))); mnHelp.add(helpDoc); helpDoc.addActionListener(this); miAbout = new JMenuItem(""); mnHelp.add(miAbout); miAbout.addActionListener(this); openPdmFileItem.addActionListener(this); this.setJMenuBar(menuBar); }
From source file:org.rimudb.editor.RimuDBEditor.java
public JMenuBar buildJMenuBar() { log.debug("buildJMenuBar()"); JMenuBar menuBar = new JMenuBar(); // File menu//from w w w. ja v a2 s . c o m JMenu menu = new JMenu("File"); menu.setMnemonic(KeyEvent.VK_F); openMenuItem = new JMenuItem( new OpenDescriptorAction(this, "Open...", loadIcon("/images/famfamfam/folder.png"))); openMenuItem.setName("OpenMenuItem"); openMenuItem.setMnemonic(KeyEvent.VK_O); openMenuItem.setAccelerator( KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)); menu.add(openMenuItem); saveMenuItem = new JMenuItem( new SaveDescriptorAction(this, "Save", loadIcon("/images/famfamfam/disk.png"))); saveMenuItem.setName("SaveMenuItem"); saveMenuItem.setMnemonic(KeyEvent.VK_S); saveMenuItem.setAccelerator( KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)); menu.add(saveMenuItem); saveAsMenuItem = new JMenuItem(new SaveAsDescriptorAction(this, "Save as...")); saveAsMenuItem.setName("SaveAsMenuItem"); menu.add(saveAsMenuItem); menu.addSeparator(); clearMenuItem = new JMenuItem( new ClearTableAction(this, "Clear...", loadIcon("/images/famfamfam/bin_closed.png"))); clearMenuItem.setName("ClearMenuItem"); clearMenuItem.setMnemonic(KeyEvent.VK_C); menu.add(clearMenuItem); preferencesMenuItem = new JMenuItem( new PreferencesAction(this, "Preferences...", loadIcon("/images/famfamfam/text_list_bullets.png"))); preferencesMenuItem.setName("PreferencesMenuItem"); preferencesMenuItem.setEnabled(false); preferencesMenuItem.setMnemonic(KeyEvent.VK_P); menu.add(preferencesMenuItem); menu.addSeparator(); exitMenuItem = new JMenuItem(new ExitAction(this, "Exit")); exitMenuItem.setName("ExitMenuItem"); exitMenuItem.setMnemonic(KeyEvent.VK_E); menu.add(exitMenuItem); menuBar.add(menu); JMenu toolsMenu = new JMenu("Tools"); toolsMenu.setMnemonic(KeyEvent.VK_T); dbImportMenuItem = new JMenuItem( new ImportAction(this, "Import from database...", loadIcon("/images/famfamfam/database_go.png"))); dbImportMenuItem.setName("DbImportMenuItem"); dbImportMenuItem.setEnabled(false); dbImportMenuItem.setMnemonic(KeyEvent.VK_I); dbImportMenuItem.setAccelerator( KeyStroke.getKeyStroke('I', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false)); toolsMenu.add(dbImportMenuItem); createClassesMenuItem = new JMenuItem(new GenerateJavaAction(this, "Create classes...", loadIcon("/images/famfamfam/page_white_cup.png"))); createClassesMenuItem.setName("CreateClassesMenuItem"); createClassesMenuItem.setMnemonic(KeyEvent.VK_C); toolsMenu.add(createClassesMenuItem); ddsExportMenuItem = new JMenuItem("Export as DDS..."); ddsExportMenuItem.setName("DdsExportMenuItem"); ddsExportMenuItem.setMnemonic(KeyEvent.VK_D); ddsExportMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { actionExportToDDS(); } }); toolsMenu.add(ddsExportMenuItem); sqlExportMenuItem = new JMenuItem("Export as SQL..."); sqlExportMenuItem.setIcon(loadIcon("/images/famfamfam/page_white_database.png")); sqlExportMenuItem.setName("SqlExportMenuItem"); sqlExportMenuItem.setMnemonic(KeyEvent.VK_Q); sqlExportMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { actionExportToSQL(); } }); toolsMenu.add(sqlExportMenuItem); toolsMenu.addSeparator(); propertyRenameMenuItem = new JMenuItem("Rename Properties..."); propertyRenameMenuItem.setName("PropertyRenameMenuItem"); propertyRenameMenuItem.setMnemonic(KeyEvent.VK_R); propertyRenameMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { actionRenameProperties(); } }); toolsMenu.add(propertyRenameMenuItem); copyCodeMenuItem = new JMenuItem(new GenerateCopyCodeAction(this, "Create Java DO Copy Code...", null)); copyCodeMenuItem.setName("CopyCodeMenuItem"); toolsMenu.add(copyCodeMenuItem); convertFinderMenuItem = new JMenuItem(new ConvertFinderAction(this, "Convert Finders (pre 1.1)...", null)); convertFinderMenuItem.setName("ConvertFinderMenuItem"); toolsMenu.add(convertFinderMenuItem); convertCDBMenuItem = new JMenuItem(new ConvertCDBAction(this, "Convert CDB Configs (pre 1.2)...", null)); convertCDBMenuItem.setName("ConvertCDBMenuItem"); toolsMenu.add(convertCDBMenuItem); menuBar.add(toolsMenu); JMenu helpMenu = new JMenu("Help"); helpMenu.setMnemonic(KeyEvent.VK_H); aboutMenuItem = new JMenuItem(new AboutAction(this, "About...")); aboutMenuItem.setName("AboutMenuItem"); helpMenu.add(aboutMenuItem); menuBar.add(helpMenu); return menuBar; }
From source file:org.sintef.thingml.ThingMLPanel.java
public ThingMLPanel(Boolean ArduinoPlugin, final ObservableString transferBuf) { try {/*w ww . j ava 2 s . com*/ this.setLayout(new BorderLayout()); jsyntaxpane.DefaultSyntaxKit.initKit(); jsyntaxpane.DefaultSyntaxKit.registerContentType("text/thingml", Class.forName("org.sintef.thingml.ThingMLJSyntaxKit").getName()); JScrollPane scrPane = new JScrollPane(codeEditor); codeEditor.setContentType("text/thingml; charset=UTF-8"); Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; reg.getExtensionToFactoryMap().put("thingml", new ThingmlResourceFactory()); //codeEditor.setBackground(Color.LIGHT_GRAY) JMenuBar menubar = new JMenuBar(); JInternalFrame menuframe = new JInternalFrame(); menuframe.setSize(getWidth(), getHeight()); menuframe.setJMenuBar(menubar); menuframe.setLayout(new BorderLayout()); menuframe.add(scrPane, BorderLayout.CENTER); if (!ArduinoPlugin) { try { this.transferBuf = transferBuf; EditorKit editorKit = codeEditor.getEditorKit(); JToolBar toolPane = new JToolBar(); ((ThingMLJSyntaxKit) editorKit).addToolBarActions(codeEditor, toolPane); menuframe.add(toolPane, BorderLayout.NORTH); } catch (Exception e) { if (ThingMLApp.debug) e.printStackTrace(); } } menuframe.setVisible(true); ((BasicInternalFrameUI) menuframe.getUI()).setNorthPane(null); menuframe.setBorder(BorderFactory.createEmptyBorder()); add(menuframe, BorderLayout.CENTER); if (!ArduinoPlugin) {//FIXME: Nicolas, avoid code duplication final ThingMLCompilerRegistry registry = ThingMLCompilerRegistry.getInstance(); JMenu newCompilersMenu = new JMenu("Compile to"); for (final String id : registry.getCompilerIds()) { JMenuItem item = new JMenuItem(id); ThingMLCompiler c = registry.createCompilerInstanceByName(id); if (c.getConnectorCompilers().size() > 0) { JMenu compilerMenu = new JMenu(c.getID()); newCompilersMenu.add(compilerMenu); compilerMenu.add(item); for (final Map.Entry<String, CfgExternalConnectorCompiler> connectorCompiler : c .getConnectorCompilers().entrySet()) { JMenuItem connectorMenu = new JMenuItem(connectorCompiler.getKey()); compilerMenu.add(connectorMenu); connectorMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ThingMLModel thingmlModel = ThingMLCompiler.loadModel(targetFile); for (Configuration cfg : ThingMLHelpers.allConfigurations(thingmlModel)) { final ThingMLCompiler compiler = registry.createCompilerInstanceByName(id); for (NetworkPlugin np : loadedPlugins) { if (np.getTargetedLanguages().contains(compiler.getID())) { compiler.addNetworkPlugin(np); } } for (SerializationPlugin sp : loadedSerPlugins) { if (sp.getTargetedLanguages().contains(compiler.getID())) { compiler.addSerializationPlugin(sp); } } compiler.setOutputDirectory(new File(System.getProperty("java.io.tmpdir") + "/ThingML_temp/" + cfg.getName())); compiler.compileConnector(connectorCompiler.getKey(), cfg); } } }); } } else { newCompilersMenu.add(item); } item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Input file : " + targetFile); if (targetFile == null) return; try { ThingMLModel thingmlModel = ThingMLCompiler.loadModel(targetFile); if (thingmlModel != null) { for (Configuration cfg : ThingMLHelpers.allConfigurations(thingmlModel)) { final ThingMLCompiler compiler = registry.createCompilerInstanceByName(id); for (NetworkPlugin np : loadedPlugins) { if (np.getTargetedLanguages().contains(compiler.getID())) { compiler.addNetworkPlugin(np); } } for (SerializationPlugin sp : loadedSerPlugins) { if (sp.getTargetedLanguages().contains(compiler.getID())) { compiler.addSerializationPlugin(sp); } } compiler.setOutputDirectory(new File(System.getProperty("java.io.tmpdir") + "/ThingML_temp/" + cfg.getName())); compiler.compile(cfg); } } } catch (Exception ex) { if (ThingMLApp.debug) ex.printStackTrace(); } } }); c = null; } menubar.add(newCompilersMenu); } else { final ThingMLCompilerRegistry registry = ThingMLCompilerRegistry.getInstance(); JMenu newCompilersMenu = new JMenu("Compile to"); for (final String id : registry.getCompilerIds()) { if (id.compareToIgnoreCase("arduino") == 0) { JMenuItem item = new JMenuItem(id); ThingMLCompiler c = registry.createCompilerInstanceByName(id); if (c.getConnectorCompilers().size() > 0) { JMenu compilerMenu = new JMenu(c.getID()); newCompilersMenu.add(compilerMenu); compilerMenu.add(item); for (final Map.Entry<String, CfgExternalConnectorCompiler> connectorCompiler : c .getConnectorCompilers().entrySet()) { JMenuItem connectorMenu = new JMenuItem(connectorCompiler.getKey()); compilerMenu.add(connectorMenu); connectorMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ThingMLModel thingmlModel = ThingMLCompiler.loadModel(targetFile); for (Configuration cfg : ThingMLHelpers.allConfigurations(thingmlModel)) { final ThingMLCompiler compiler = registry .createCompilerInstanceByName(id); for (NetworkPlugin np : loadedPlugins) { if (np.getTargetedLanguages().contains(compiler.getID())) { compiler.addNetworkPlugin(np); } } for (SerializationPlugin sp : loadedSerPlugins) { if (sp.getTargetedLanguages().contains(compiler.getID())) { compiler.addSerializationPlugin(sp); } } compiler.setOutputDirectory( new File(System.getProperty("java.io.tmpdir") + "/ThingML_temp/" + cfg.getName())); compiler.compileConnector(connectorCompiler.getKey(), cfg); } } }); } } else { newCompilersMenu.add(item); } item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Input file : " + targetFile); if (targetFile == null) return; try { ThingMLModel thingmlModel = ThingMLCompiler.loadModel(targetFile); for (Configuration cfg : ThingMLHelpers.allConfigurations(thingmlModel)) { final ThingMLCompiler compiler = registry.createCompilerInstanceByName(id); for (NetworkPlugin np : loadedPlugins) { if (np.getTargetedLanguages().contains(compiler.getID())) { compiler.addNetworkPlugin(np); } } for (SerializationPlugin sp : loadedSerPlugins) { if (sp.getTargetedLanguages().contains(compiler.getID())) { compiler.addSerializationPlugin(sp); } } File myFileBuf = new File(System.getProperty("java.io.tmpdir") + "/ThingML_temp/" + cfg.getName()); compiler.setOutputDirectory(myFileBuf); compiler.compile(cfg); final InputStream input = new FileInputStream(myFileBuf.getAbsolutePath() + "/" + cfg.getName() + "/" + cfg.getName() + ".pde"); //System.out.println("tmp file: " + myFileBuf.getAbsolutePath() + "/" + cfg.getName() + "/" + cfg.getName() + ".pde"); //final InputStream input = new FileInputStream(myFileBuf); String result = null; try { if (input != null) { result = org.apache.commons.io.IOUtils.toString(input); input.close(); transferBuf.setString(result); transferBuf.hasChanged(); transferBuf.notifyObservers(); } else { //System.out.println("WHY"); } } catch (Exception exce) { if (ThingMLApp.debug) System.out.println("OH REALLY?"); } } } catch (Exception ex) { if (ThingMLApp.debug) ex.printStackTrace(); } } }); c = null; } } menubar.add(newCompilersMenu); } codeEditor.getDocument().addDocumentListener(new DocumentListener() { public void removeUpdate(DocumentEvent e) { lastUpdate.set(System.currentTimeMillis()); checkNeeded.set(true); } public void insertUpdate(DocumentEvent e) { lastUpdate.set(System.currentTimeMillis()); checkNeeded.set(true); } public void changedUpdate(DocumentEvent e) { lastUpdate.set(System.currentTimeMillis()); checkNeeded.set(true); } }); java.util.Timer timer = new Timer(); timer.scheduleAtFixedRate(new SeamlessNotification(), 250, 250); } catch (Exception e) { if (ThingMLApp.debug) e.printStackTrace(); } }
From source file:org.spottedplaid.ui.Mainframe.java
/** * Create the frame.//from w ww .j a va 2 s .co m * * @param _Sqliteops the _ sqliteops * @param _Crypto the _ crypto */ public Mainframe(SQliteOps _Sqliteops, Crypto _Crypto) { l_sqliteops = _Sqliteops; l_crypto = _Crypto; setTitle("The Password Saver - Management"); setResizable(false); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 982, 656); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); menuBar.add(mnFile); JMenuItem mntmExit = new JMenuItem("Exit"); mntmExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); mnFile.add(mntmExit); JMenu mnTools = new JMenu("Tools"); menuBar.add(mnTools); JMenuItem mntmChgpwd = new JMenuItem("Change Passphrase"); mntmChgpwd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Changepwd changePwd = new Changepwd(l_crypto, l_sqliteops); changePwd.setVisible(true); } }); mnTools.add(mntmChgpwd); JMenuItem mntmExpirationReport = new JMenuItem("Expiration Report"); mntmExpirationReport.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { DbRecord dbRecExp = new DbRecord(); dbRecExp.setType(Pwdtypes.S_EXP_RPT); ArrayList<String> arrData = l_sqliteops.getRecords(dbRecExp); String[] sRecord = new String[3]; String sData = ""; int iElement = 0; /// Cycle through the data, output to text file, and open in WordPad if (arrData != null && arrData.size() > 0) { try { String sFilename = "ExpirationReport.txt"; File fileExpRpt = new File(sFilename); BufferedWriter buffWriter = new BufferedWriter(new FileWriter(fileExpRpt)); buffWriter.write("URL/Application Challenge Expiration"); buffWriter.write("\n"); buffWriter.write("--------------------------------------------------------------"); buffWriter.write("\n"); for (int iCount = 0; iCount < arrData.size(); iCount++) { sData = arrData.get(iCount); System.out.println("DEBUG->sData [" + sData + "]"); StringTokenizer st = new StringTokenizer(sData, "|"); iElement = 0; while (st.hasMoreTokens()) { sRecord[iElement] = st.nextToken(); iElement++; } /// Define the padding for the output int iPadValue1 = 35 - sRecord[0].length(); if (iPadValue1 < 0) { iPadValue1 = 2; } int iPadValue2 = 55 - (35 + sRecord[1].length()); if (iPadValue2 < 0) { iPadValue2 = 2; } iPadValue1 += sRecord[1].length(); iPadValue2 += sRecord[2].length(); buffWriter.write(sRecord[0] + StringUtils.leftPad(sRecord[1], iPadValue1) + StringUtils.leftPad(sRecord[2], iPadValue2) + "\n"); buffWriter.write("\n"); } buffWriter.close(); /// Opens WordPad on Windows systems. This could be changed to use a property in order to work on a linux/unix/apple system ProcessBuilder pb = new ProcessBuilder("write.exe", sFilename); pb.start(); } catch (IOException ie) { System.out.println("Expiration Report IO Exception [" + ie.getMessage() + "]"); ie.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "No expiring records found"); } } }); mnTools.add(mntmExpirationReport); JMenuItem mntmViewLogs = new JMenuItem("View Logs"); mntmViewLogs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DbRecord dbRecLogs = new DbRecord(); dbRecLogs.setType(Pwdtypes.S_LOG_TYPE); ArrayList<String> arrData = l_sqliteops.getRecords(dbRecLogs); String[] sRecord = new String[3]; String sData = ""; String sTitle = "Display Data Changes"; String sDisplay = "Date Log Message"; sDisplay += "\n"; int iElement = 0; /// Cycle through the data, output to text file, and open in WordPad if (arrData != null) { for (int iCount = 0; iCount < arrData.size(); iCount++) { sData = arrData.get(iCount); System.out.println("DEBUG->sData [" + sData + "]"); StringTokenizer st = new StringTokenizer(sData, "|"); iElement = 0; while (st.hasMoreTokens()) { sRecord[iElement] = st.nextToken(); iElement++; } sDisplay += sRecord[2] + ":" + sRecord[1]; sDisplay += "\n"; } if (arrData.size() > 0) { JOptionPane.showMessageDialog(null, sDisplay, sTitle, JOptionPane.INFORMATION_MESSAGE); } } } }); mnTools.add(mntmViewLogs); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); JLabel lblThePasswordSaver = new JLabel("The Password Saver - Manage Passwords"); lblThePasswordSaver.setFont(new Font("Arial", Font.BOLD, 16)); lblThePasswordSaver.setHorizontalAlignment(SwingConstants.CENTER); JLabel lblUrlapplication = new JLabel("URL/Application"); jtxtApp = new JTextField(); jtxtApp.setColumns(10); JLabel lblDescription = new JLabel("Description"); jtxtDesc = new JTextField(); jtxtDesc.setColumns(10); /// Button - Add button for clients/apps JButton btnAdd = new JButton("Add"); btnAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (FormValidation.verifyAppData(jtxtApp.getText().toString(), jtxtDesc.getText().toString()) < 0) { JOptionPane.showMessageDialog(null, "URL/Application and Description are required"); } else { dbRec = new DbRecord(); dbRec.setType(Pwdtypes.S_CLIENT_TYPE); dbRec.setClientName(jtxtApp.getText().toString()); dbRec.setClientDesc(jtxtDesc.getText().toString()); int l_iClientId = l_sqliteops.insertRecord(dbRec); if (l_iClientId <= 0) { JOptionPane.showMessageDialog(null, "Insert record failed [" + dbRec.getResult() + "]"); } else { dbRec.setClientId(l_iClientId); addToTable(); } } } }); /// Buttons - Replace button for clients/apps btnReplace = new JButton("Replace"); btnReplace.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (iClientId <= 0) { JOptionPane.showMessageDialog(null, "Update record warning: Please select record to continue"); return; } dbRec = new DbRecord(); dbRec.setType(Pwdtypes.S_CLIENT_TYPE); dbRec.setClientId(iClientId); dbRec.setClientName(jtxtApp.getText().toString()); dbRec.setClientDesc(jtxtDesc.getText().toString()); if (l_sqliteops.updateRecord(dbRec) < 0) { JOptionPane.showMessageDialog(null, "Update record failed [" + dbRec.getResult() + "]"); } else { int iRow = jtabApps.getSelectedRow(); jtabApps.setValueAt(jtxtApp.getText().toString(), iRow, 1); jtabApps.setValueAt(jtxtDesc.getText().toString(), iRow, 2); clearFields(); } } }); btnReplace.setEnabled(false); /// Button - Delete button for clients/apps btnDelete = new JButton("Delete"); btnDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (iClientId <= 0) { JOptionPane.showMessageDialog(null, "Delete record failed: Please select a record then click Delete"); return; } dbRec = new DbRecord(); dbRec.setType("clients"); dbRec.setClientId(iClientId); dbRec.setDelCreds(0); if (chkDelAssoc.isSelected()) { dbRec.setDelCreds(1); } if (l_sqliteops.deleteRecord(dbRec) < 0) { JOptionPane.showMessageDialog(null, "Delete record failed [" + dbRec.getResult() + "]"); } else { DefaultTableModel jtabModel = (DefaultTableModel) jtabApps.getModel(); jtabModel.removeRow(jtabApps.getSelectedRow()); if (chkDelAssoc.isSelected()) { DefaultTableModel model = (DefaultTableModel) jtabCreds.getModel(); model.setRowCount(0); } clearFields(); } } }); btnDelete.setEnabled(false); /// Buttons - Search button for clients/apps btnSearch = new JButton("Search"); btnSearch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dbRec = new DbRecord(); dbRec.setType(Pwdtypes.S_CLIENT_TYPE); dbRec.setClientName(jtxtApp.getText().toString()); dbRec.setClientDesc(jtxtDesc.getText().toString()); loadTable(dbRec); } }); btnClear = new JButton("Clear"); btnClear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { clearFields(); } }); JScrollPane scrollPane = new JScrollPane(); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); /// Begin section for credentials challenges/responses - text fields and buttons JLabel lblChallenge = new JLabel("Challenge"); JLabel lblResponse = new JLabel("Response"); jtxtChlng = new JTextField(); jtxtChlng.setColumns(10); jtxtRsp = new JTextField(); jtxtRsp.setColumns(10); /// Buttons - Add button for credentials btnCredAdd = new JButton("Add"); btnCredAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (FormValidation.verifyCredData(jtxtChlng.getText().toString(), jtxtRsp.getText().toString()) < 0) { JOptionPane.showMessageDialog(null, "Challenge and Response are required"); } else { dbRec = new DbRecord(); dbRec.setType(Pwdtypes.S_CREDS_TYPE); dbRec.setClientId(iClientId); dbRec.setChallenge(jtxtChlng.getText().toString()); dbRec.setResponse(l_crypto.encrypt(jtxtRsp.getText().toString())); dbRec.setTrack(jcbTrack.getSelectedItem().toString()); /// Set the modify date if the track days are > 0 if (!jcbTrack.getSelectedItem().toString().equals("0")) { Calendar calNow = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); int iDaysToAdd = Integer.parseInt(jcbTrack.getSelectedItem().toString()); calNow.add(Calendar.DATE, iDaysToAdd); String sValue = sdf.format(calNow.getTime()); dbRec.setModifyDate(sValue); } int l_iClientId = l_sqliteops.insertRecord(dbRec); if (l_iClientId <= 0) { JOptionPane.showMessageDialog(null, "Insert record failed [" + dbRec.getResult() + "]"); } else { dbRec.setCredId(l_iClientId); addToCredsTable(); } } } }); /// Button - Replace button for credentials btnCredReplace = new JButton("Replace"); btnCredReplace.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { DbRecord dbRecLog = new DbRecord(); int iDaysToAdd = 0; Calendar calNow = Calendar.getInstance(); SimpleDateFormat sdf1 = new SimpleDateFormat("MM/dd/yyyy"); String sCurDate = sdf1.format(calNow.getTime()); String sValue = sDateModified; String sLogMsg = ""; StringBuilder sbLogMsg = new StringBuilder(sLogMsg); if (dbRec.getType().equals(Pwdtypes.S_CREDS_TYPE) && (dbRec.getCredId() > 0)) { dbRec.setClientId(iClientId); dbRec.setCredId(iCredId); dbRec.setChallenge(jtxtChlng.getText().toString()); dbRec.setResponse(l_crypto.encrypt(jtxtRsp.getText().toString())); dbRec.setTrack(jcbTrack.getSelectedItem().toString()); /** Check for changes and insert log if necessary */ if (!sChallenge.equals(jtxtChlng.getText())) { sbLogMsg.append("Application [" + jtxtApp.getText() + "], Challenge modified, old [" + sChallenge + "], new [" + jtxtChlng.getText() + "]"); } if (!sResponse.equals(jtxtRsp.getText())) { if (sbLogMsg.toString().length() > 0) { sbLogMsg.append(","); } else { sbLogMsg.append("Application [" + jtxtApp.getText() + "],"); } sbLogMsg.append("Response modified, old [" + sResponse + "]"); } if (sbLogMsg.toString().length() > 0) { dbRecLog.setType(Pwdtypes.S_LOG_TYPE); dbRecLog.setLog(sbLogMsg.toString()); dbRecLog.setModifyDate(sCurDate); if (l_sqliteops.insertRecord(dbRecLog) < 0) { JOptionPane.showMessageDialog(null, "Insert log record failed [" + dbRecLog.getResult() + "]"); } } if (!jcbTrack.getSelectedItem().toString().equals("0")) { iDaysToAdd = Integer.parseInt(jcbTrack.getSelectedItem().toString()); calNow.add(Calendar.DATE, iDaysToAdd); sValue = sdf1.format(calNow.getTime()); System.out.println("DEBUG->Date (sValue) [" + sValue + "]"); dbRec.setModifyDate(sValue); } /// Update the record if (l_sqliteops.updateRecord(dbRec) < 0) { JOptionPane.showMessageDialog(null, "Update record failed [" + dbRec.getResult() + "]"); } else { int iRow = jtabCreds.getSelectedRow(); jtabCreds.setValueAt(jtxtChlng.getText().toString(), iRow, 1); jtabCreds.setValueAt(l_crypto.encrypt(jtxtRsp.getText().toString()), iRow, 2); jtabCreds.setValueAt(jcbTrack.getSelectedItem().toString(), iRow, 3); jtabCreds.setValueAt(sValue, iRow, 4); jtabCreds.setValueAt(sValue, iRow, 4); clearCredsFields(); enableCredsButtons(); } } } }); /// Button - Delete button for credentials btnCredDelete = new JButton("Delete"); btnCredDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dbRec.setType(Pwdtypes.S_CREDS_TYPE); dbRec.setCredId(iCredId); dbRec.setChallenge(jtxtChlng.getText().toString()); dbRec.setResponse(jtxtRsp.getText().toString()); if (l_sqliteops.deleteRecord(dbRec) < 0) { JOptionPane.showMessageDialog(null, "Delete credential record failed [" + dbRec.getResult() + "]"); } else { DefaultTableModel jtabModel = (DefaultTableModel) jtabCreds.getModel(); jtabModel.removeRow(jtabCreds.getSelectedRow()); clearCredsFields(); enableCredsButtons(); } } }); /// Button - Clear button for credentials btnCredClear = new JButton("Clear"); btnCredClear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { clearCredsFields(); enableCredsButtons(); } }); /// End section for credentials challenges/responses - text fields and buttons JScrollPane scrollPane_1 = new JScrollPane(); scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); btnShowAssoc = new JButton("Display Associated Challenges/Responses in new window"); /// Display the challenges/responses associated to the application in a popup window. /// This is to make it easier to view when all of the values are needed btnShowAssoc.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String sTitle = "Credentials for: " + jtxtApp.getText(); String sDisplay = ""; sDisplay += "\n"; DefaultTableModel jTmpModel = (DefaultTableModel) jtabCreds.getModel(); for (int i = 0; i < jTmpModel.getRowCount(); i++) { sDisplay += "Q. " + jTmpModel.getValueAt(i, 1).toString() + " A. " + l_crypto.decrypt(jTmpModel.getValueAt(i, 2).toString()) + "\n"; } JOptionPane.showMessageDialog(null, sDisplay, sTitle, JOptionPane.INFORMATION_MESSAGE); } }); JLabel lblTrackUpdates = new JLabel("Exp Days"); /// Values for expiration days are hardcoded, may want to move to a table for metadata jcbTrack.addItem("0"); jcbTrack.addItem("30"); jcbTrack.addItem("45"); jcbTrack.addItem("60"); jcbTrack.addItem("90"); jcbTrack.addItem("180"); jcbTrack.addItem("365"); jcbTrack.setSelectedItem("0"); btnEdit = new JButton("Edit"); btnEdit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { jtxtChlng.setEnabled(true); jtxtRsp.setEnabled(true); jcbTrack.setEnabled(true); btnCredReplace.setEnabled(true); btnCredAdd.setEnabled(true); } }); btnEdit.setEnabled(false); GroupLayout gl_contentPane = new GroupLayout(contentPane); gl_contentPane.setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup().addGroup(gl_contentPane .createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup().addGap(207) .addComponent(lblThePasswordSaver)) .addGroup(gl_contentPane.createSequentialGroup().addGap(23).addGroup(gl_contentPane .createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup().addComponent(btnAdd) .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnReplace) .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnDelete) .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnSearch) .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnClear)) .addGroup(gl_contentPane.createSequentialGroup().addGroup(gl_contentPane .createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addComponent(lblUrlapplication) .addComponent(lblDescription)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addComponent(jtxtApp, GroupLayout.PREFERRED_SIZE, 154, GroupLayout.PREFERRED_SIZE) .addComponent(jtxtDesc, GroupLayout.PREFERRED_SIZE, 260, GroupLayout.PREFERRED_SIZE))) .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 355, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED, 18, Short.MAX_VALUE) .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) .addComponent(btnShowAssoc) .addGroup(gl_contentPane.createSequentialGroup() .addGroup(gl_contentPane .createParallelGroup(Alignment.TRAILING) .addComponent(lblResponse) .addComponent(lblChallenge)) .addGap(18) .addGroup(gl_contentPane .createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addComponent(jtxtRsp, 272, 272, 272) .addGap(26).addComponent(lblTrackUpdates) .addPreferredGap( ComponentPlacement.UNRELATED) .addComponent(jcbTrack, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)) .addComponent(jtxtChlng, GroupLayout.PREFERRED_SIZE, 440, GroupLayout.PREFERRED_SIZE))) .addGroup(gl_contentPane .createParallelGroup(Alignment.LEADING, false) .addGroup(gl_contentPane.createSequentialGroup() .addComponent(btnCredAdd, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(btnCredReplace) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(btnCredDelete, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(btnCredClear) .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnEdit)) .addComponent(scrollPane_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))))) .addGroup(gl_contentPane.createSequentialGroup().addGap(36).addComponent(chkDelAssoc))) .addContainerGap(57, Short.MAX_VALUE))); gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup().addContainerGap().addComponent(lblThePasswordSaver) .addGap(45) .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) .addGroup(gl_contentPane.createSequentialGroup().addGroup(gl_contentPane .createParallelGroup(Alignment.BASELINE).addComponent(lblUrlapplication) .addComponent(jtxtApp, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(lblChallenge)).addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(lblDescription) .addComponent(jtxtDesc, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(lblResponse))) .addGroup(gl_contentPane.createSequentialGroup() .addComponent(jtxtChlng, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(jtxtRsp, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(lblTrackUpdates) .addComponent(jcbTrack, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))) .addGap(18) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(btnAdd) .addComponent(btnReplace).addComponent(btnDelete).addComponent(btnSearch) .addComponent(btnClear).addComponent(btnCredAdd).addComponent(btnCredReplace) .addComponent(btnCredDelete).addComponent(btnCredClear).addComponent(btnEdit)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 208, GroupLayout.PREFERRED_SIZE) .addComponent(scrollPane_1, GroupLayout.PREFERRED_SIZE, 109, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_contentPane.createSequentialGroup().addGap(120) .addComponent(btnShowAssoc))) .addGap(18).addComponent(chkDelAssoc).addContainerGap(170, Short.MAX_VALUE))); /// JTable - Credentials table setup/definition - BEGIN jtabCreds = new JTable(); jtabCreds.setModel(new DefaultTableModel(new Object[][] {}, new String[] { "ID", "Challenge", "Response", "Exp Days", "Expiration Date" }) { Class[] columnTypes = new Class[] { Integer.class, String.class, String.class, String.class, String.class }; public Class getColumnClass(int columnIndex) { return columnTypes[columnIndex]; } }); jtabCreds.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0))); scrollPane_1.setViewportView(jtabCreds); /// JTable - Credentials table setup/definition - END jtabApps = new JTable(); scrollPane.setViewportView(jtabApps); jtabApps.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jtabApps.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0))); jtabApps.setModel( new DefaultTableModel(new Object[][] {}, new String[] { "ID", "URL/Application", "Description" }) { Class[] columnTypes = new Class[] { Integer.class, String.class, String.class }; public Class getColumnClass(int columnIndex) { return columnTypes[columnIndex]; } @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }); jtabApps.getColumnModel().getColumn(1).setMinWidth(55); jtabApps.getColumnModel().getColumn(2).setMinWidth(55); contentPane.setLayout(gl_contentPane); contentPane.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[] { jtxtChlng, lblThePasswordSaver, jtxtApp, jtxtDesc, btnAdd, btnReplace, btnDelete, btnSearch, btnClear, jtxtRsp, btnCredAdd, btnCredReplace, btnCredDelete, btnCredClear, scrollPane, jtabApps, lblUrlapplication, lblDescription, chkDelAssoc, lblChallenge, lblResponse, scrollPane_1, jtabCreds })); setFocusTraversalPolicy(new FocusTraversalOnArray( new Component[] { menuBar, jtxtApp, jtxtDesc, btnAdd, btnReplace, btnDelete, btnSearch, btnClear, jtxtChlng, jtxtRsp, btnCredAdd, btnCredReplace, btnCredDelete, btnCredClear, contentPane, mnFile, mntmExit, lblThePasswordSaver, scrollPane, jtabApps, lblUrlapplication, lblDescription, chkDelAssoc, lblChallenge, lblResponse, scrollPane_1, jtabCreds })); /// Initial data load dbRec = new DbRecord(); dbRec.setType(Pwdtypes.S_CLIENT_TYPE); dbRec.setClientName(""); dbRec.setClientDesc(""); loadTable(dbRec); disableCredsButtons(); ListSelectionModel rowSM = jtabApps.getSelectionModel(); //Listener for client row change; rowSM.addListSelectionListener(new ListSelectionListener() { /// Fill the form values when a row is selected in the JTable @Override public void valueChanged(ListSelectionEvent e) { ListSelectionModel lsmData = (ListSelectionModel) e.getSource(); if (!lsmData.isSelectionEmpty()) { int iRow = lsmData.getMinSelectionIndex(); iClientId = Integer.parseInt(jtabApps.getValueAt(iRow, 0).toString()); jtxtApp.setText(jtabApps.getValueAt(iRow, 1).toString()); jtxtDesc.setText(jtabApps.getValueAt(iRow, 2).toString()); dbRec.setType(Pwdtypes.S_CREDS_TYPE); dbRec.setClientId(iClientId); loadTable(dbRec); enableButtons(); clearCredsFields(); enableCredsButtons(); } } }); ListSelectionModel rowCred = jtabCreds.getSelectionModel(); //Listener for credential row change; rowCred.addListSelectionListener(new ListSelectionListener() { /// Fill the form values when a row is selected in the JTable @Override public void valueChanged(ListSelectionEvent e) { ListSelectionModel lsmData = (ListSelectionModel) e.getSource(); if (!lsmData.isSelectionEmpty()) { int iRow = lsmData.getMinSelectionIndex(); iCredId = Integer.parseInt(jtabCreds.getValueAt(iRow, 0).toString()); jtxtChlng.setText(jtabCreds.getValueAt(iRow, 1).toString()); jtxtRsp.setText(l_crypto.decrypt(jtabCreds.getValueAt(iRow, 2).toString())); jcbTrack.setSelectedItem(jtabCreds.getValueAt(iRow, 3).toString()); if (null == jtabCreds.getValueAt(iRow, 4)) { sDateModified = ""; } else { sDateModified = jtabCreds.getValueAt(iRow, 4).toString(); } sChallenge = jtxtChlng.getText(); sResponse = jtxtRsp.getText(); dbRec.setType(Pwdtypes.S_CREDS_TYPE); dbRec.setCredId(iClientId); jtxtChlng.setEnabled(false); jtxtRsp.setEnabled(false); jcbTrack.setEnabled(false); btnEdit.setEnabled(true); btnCredDelete.setEnabled(true); btnCredClear.setEnabled(true); } } }); }
From source file:org.squidy.designer.Designer.java
/** * Initializes menu bar.//from www . j a v a2s. 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); }
From source file:org.stanwood.nwn2.gui.MainWindow.java
private void createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu mnuFile = new JMenu("File"); mnuFile.setMnemonic('F'); JMenuItem newAction = new JMenuItem("Add GUI file"); newAction.setMnemonic('A'); newAction.setIcon(IconManager.getInstance().getIcon(IconManager.SIZE_16, IconManager.ICON_LIST_ADD)); newAction.addActionListener(new ActionListener() { @Override/*from w w w . j a v a 2 s . c om*/ public void actionPerformed(ActionEvent e) { addNewGUIFile(); } }); mnuFile.add(newAction); Action exitAction = StandardActions.getApplicationExit(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { closeWindow(); } }); mnuFile.add(exitAction); JMenu mnuPrefences = new JMenu("Prefences"); mnuPrefences.setMnemonic('P'); JMenuItem pref = new JMenuItem("Options"); pref.setMnemonic('O'); pref.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showOptionsDialog(); } }); mnuPrefences.add(pref); JMenu mnuHelp = new JMenu("Help"); mnuHelp.setMnemonic('H'); Action helpAction = StandardActions.getAboutAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { AboutDialog ad = new AboutDialog(MainWindow.this, APP_TITLE, APP_VERSION); ad.setApplicationWebLink("http://code.google.com/p/nwn2gui/"); ad.setMessage("A NWN2 GUI XML viewer.\n\n (C) 2010, The NWN2 GUI developers"); ad.addAuthor(new Author("John-Paul Stanford", "dev@stanwood.org.uk", "Lead developer and project creator")); ad.setIcon(new ImageIcon(MainWindow.class.getResource("nwn2gui48.png"))); ad.init(); ad.setVisible(true); } }); mnuHelp.add(helpAction); menuBar.add(mnuFile); menuBar.add(mnuPrefences); menuBar.add(mnuHelp); setJMenuBar(menuBar); }
From source file:org.terentich.pram.GUIPRAM.java
private void setContent() { FrameView mainview = getMainView();// w w w . j a va2 s .com Action openFileAction = mainview.getContext().getActionMap().get(ResourceNames.OPEN_FILE_ACTION_NAME); Action aboutDialogAction = mainview.getContext().getActionMap().get(ResourceNames.ABOUT_DIALOG_ACTION_NAME); JMenuBar bar = new JMenuBar(); JMenu menuFile = new JMenu(getContext().getResourceMap().getString(ResourceNames.MENU_FILE_NAME)); JMenu menuHelp = new JMenu(getContext().getResourceMap().getString(ResourceNames.MENU_HELP_NAME)); menuFile.add(openFileAction); menuHelp.add(aboutDialogAction); bar.add(menuFile); bar.add(menuHelp); mainview.setMenuBar(bar); // Container panel = mainview.getRootPane().getContentPane(); // panel.setLayout(new MigLayout()); // panel.add(new JButton(mainview.getContext().getActionMap() // .get(OPEN_FILE_ACTION_NAME))); mainview.getFrame().setTitle(MessageFormat.format(APPLICATION_TITLE_FORMAT, metaReader.getApplicationName(), metaReader.getApplicationVersion())); Container content = mainview.getRootPane().getContentPane(); tabPane = new JTabbedPane(); content.add(tabPane); JToolBar toolbar = new JToolBar(); toolbar.add(getContext().getActionMap().get(ResourceNames.OPEN_FILE_ACTION_NAME)); toolbar.add(getContext().getActionMap().get(ResourceNames.ABOUT_DIALOG_ACTION_NAME)); content.add(toolbar, BorderLayout.NORTH); initCLIOptions(); }