List of usage examples for javax.swing JFileChooser setDialogTitle
@BeanProperty(preferred = true, description = "The title of the JFileChooser dialog window.") public void setDialogTitle(String dialogTitle)
JFileChooser
window's title bar. From source file:client.welcome2.java
private void SupplierUploadContractButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SupplierUploadContractButton1ActionPerformed try {/*from ww w . j a v a 2 s.c o m*/ JFileChooser supplier_chooser = new JFileChooser(); supplier_chooser.setDialogTitle("Open a File"); FileNameExtensionFilter docFilter = new FileNameExtensionFilter("Word Files", "docx"); FileNameExtensionFilter pdfFilter = new FileNameExtensionFilter("PDF Documents", "pdf"); supplier_chooser.addChoosableFileFilter(docFilter); supplier_chooser.addChoosableFileFilter(pdfFilter); int result = supplier_chooser.showOpenDialog(null); if (result == 0) { File f = supplier_chooser.getSelectedFile(); supplier_filename_update = f.getAbsolutePath(); SupplierUploadText1.setText(supplier_filename_update); f.getAbsoluteFile(); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:client.welcome2.java
private void SupplierUploadContractButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SupplierUploadContractButtonActionPerformed try {/*from ww w. j av a 2s .com*/ JFileChooser supplier_chooser = new JFileChooser(); supplier_chooser.setDialogTitle("Open a File"); FileNameExtensionFilter docFilter = new FileNameExtensionFilter("Word Files", "docx"); FileNameExtensionFilter pdfFilter = new FileNameExtensionFilter("PDF Documents", "pdf"); supplier_chooser.addChoosableFileFilter(docFilter); supplier_chooser.addChoosableFileFilter(pdfFilter); int result = supplier_chooser.showOpenDialog(null); if (result == 0) { File f = supplier_chooser.getSelectedFile(); filename_supplier = f.getAbsolutePath(); SupplierUploadText.setText(filename_supplier); f.getAbsoluteFile(); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }
From source file:com.emental.mindraider.ui.frames.MindRaiderMainWindow.java
/** * Build main menu.//w w w . j a v a 2s . co m * * @param spiders */ private void buildMenu(final SpidersGraph spiders) { JMenuBar menuBar; JMenu menu, submenu; JMenuItem menuItem, subMenuItem; JRadioButtonMenuItem rbMenuItem; // create the menu bar menuBar = new JMenuBar(); setJMenuBar(menuBar); // - main menu ------------------------------------------------------- menu = new JMenu(MindRaiderConstants.MR_TITLE); menu.setMnemonic(KeyEvent.VK_M); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.setActiveNotebookAsHome")); menuItem.setMnemonic(KeyEvent.VK_H); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MindRaider.profile.setHomeNotebook(); } }); menu.add(menuItem); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.preferences")); menuItem.setMnemonic(KeyEvent.VK_P); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new PreferencesJDialog(); } }); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.exit"), KeyEvent.VK_X); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { exitMindRaider(); } }); menu.add(menuItem); menuBar.add(menu); // - Find ---------------------------------------------------------- menu = new JMenu(Messages.getString("MindRaiderJFrame.search")); menu.setMnemonic(KeyEvent.VK_F); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchNotebooks")); menuItem.setMnemonic(KeyEvent.VK_N); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new OpenOutlineJDialog(); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchFulltext")); menuItem.setMnemonic(KeyEvent.VK_F); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menuItem.setEnabled(true); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new FtsJDialog(); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchConceptsInNotebook")); menuItem.setMnemonic(KeyEvent.VK_C); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (MindRaider.profile.getActiveOutlineUri() != null) { new OpenNoteJDialog(); } } }); menu.add(menuItem); // search by tag menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchConceptsByTag")); menuItem.setEnabled(true); menuItem.setMnemonic(KeyEvent.VK_T); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new OpenConceptByTagJDialog(); } }); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.previousNote")); menuItem.setEnabled(true); menuItem.setMnemonic(KeyEvent.VK_P); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ActionEvent.ALT_MASK)); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MindRaider.recentConcepts.moveOneNoteBack(); } }); menu.add(menuItem); // global RDF search // menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchRdql")); // menuItem.setEnabled(false); // menuItem.setMnemonic(KeyEvent.VK_R); // menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, // ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); // menuItem.addActionListener(new ActionListener() { // // public void actionPerformed(ActionEvent e) { // // TODO rdql to be implemented // } // }); // menu.add(menuItem); menuBar.add(menu); // - view ------------------------------------------------------------ menu = new JMenu(Messages.getString("MindRaiderJFrame.view")); menu.setMnemonic(KeyEvent.VK_V); // TODO localize L&F menu ButtonGroup lfGroup = new ButtonGroup(); submenu = new JMenu(Messages.getString("MindRaiderJFrame.lookAndFeel")); logger.debug("Look and feel is: " + MindRaider.profile.getLookAndFeel()); // {{debug}} submenu.setMnemonic(KeyEvent.VK_L); subMenuItem = new JRadioButtonMenuItem(Messages.getString("MindRaiderJFrame.lookAndFeelNative")); if (MindRaider.LF_NATIVE.equals(MindRaider.profile.getLookAndFeel())) { subMenuItem.setSelected(true); } subMenuItem.setEnabled(true); subMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLookAndFeel(MindRaider.LF_NATIVE); } }); submenu.add(subMenuItem); lfGroup.add(subMenuItem); subMenuItem = new JRadioButtonMenuItem(Messages.getString("MindRaiderJFrame.lookAndFeelJava")); if (MindRaider.LF_JAVA_DEFAULT.equals(MindRaider.profile.getLookAndFeel())) { subMenuItem.setSelected(true); } subMenuItem.setEnabled(true); subMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLookAndFeel(MindRaider.LF_JAVA_DEFAULT); } }); submenu.add(subMenuItem); lfGroup.add(subMenuItem); menu.add(submenu); menu.addSeparator(); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.leftSideBar")); menuItem.setMnemonic(KeyEvent.VK_L); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (leftSidebarSplitPane.getDividerLocation() == 1) { leftSidebarSplitPane.resetToPreferredSizes(); } else { closeLeftSidebar(); } } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.rightSideBar")); menuItem.setMnemonic(KeyEvent.VK_R); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { OutlineJPanel.getInstance().toggleRightSidebar(); } }); menu.add(menuItem); // TODO tips to be implemented // JCheckBoxMenuItem helpCheckbox=new JCheckBoxMenuItem("Tips",true); // menu.add(helpCheckbox); // TODO localize menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.toolbar")); menuItem.setMnemonic(KeyEvent.VK_T); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MindRaider.masterToolBar.toggleVisibility(); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.rdfNavigatorDashboard")); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MindRaider.spidersGraph.getGlPanel().toggleControlPanel(); } }); menu.add(menuItem); JCheckBoxMenuItem checkboxMenuItem; ButtonGroup colorSchemeGroup; // if (!MindRaider.OUTLINER_PERSPECTIVE.equals(MindRaider.profile // .getUiPerspective())) { menu.addSeparator(); // Facets submenu = new JMenu(Messages.getString("MindRaiderJFrame.facet")); submenu.setMnemonic(KeyEvent.VK_F); colorSchemeGroup = new ButtonGroup(); String[] facetLabels = FacetCustodian.getInstance().getFacetLabels(); if (!ArrayUtils.isEmpty(facetLabels)) { for (String facetLabel : facetLabels) { rbMenuItem = new JRadioButtonMenuItem(facetLabel); rbMenuItem.addActionListener(new FacetActionListener(facetLabel)); colorSchemeGroup.add(rbMenuItem); submenu.add(rbMenuItem); if (BriefFacet.LABEL.equals(facetLabel)) { rbMenuItem.setSelected(true); } } } menu.add(submenu); checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.graphLabelAsUri")); checkboxMenuItem.setMnemonic(KeyEvent.VK_G); checkboxMenuItem.setState(MindRaider.spidersGraph.isUriLabels()); checkboxMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JCheckBoxMenuItem) { JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource(); MindRaider.spidersGraph.setUriLabels(j.getState()); MindRaider.spidersGraph.renderModel(); MindRaider.profile.setGraphShowLabelsAsUris(j.getState()); MindRaider.profile.save(); } } }); menu.add(checkboxMenuItem); checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.predicateNodes")); checkboxMenuItem.setMnemonic(KeyEvent.VK_P); checkboxMenuItem.setState(!MindRaider.spidersGraph.getHidePredicates()); checkboxMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JCheckBoxMenuItem) { JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource(); MindRaider.spidersGraph.hidePredicates(!j.getState()); MindRaider.spidersGraph.renderModel(); MindRaider.profile.setGraphHidePredicates(!j.getState()); MindRaider.profile.save(); } } }); menu.add(checkboxMenuItem); checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.multilineLabels")); checkboxMenuItem.setMnemonic(KeyEvent.VK_M); checkboxMenuItem.setState(MindRaider.spidersGraph.isMultilineNodes()); checkboxMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JCheckBoxMenuItem) { JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource(); MindRaider.spidersGraph.setMultilineNodes(j.getState()); MindRaider.spidersGraph.renderModel(); MindRaider.profile.setGraphMultilineLabels(j.getState()); MindRaider.profile.save(); } } }); menu.add(checkboxMenuItem); // } menu.addSeparator(); // Antialias checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.antiAliased"), true); checkboxMenuItem.setMnemonic(KeyEvent.VK_A); checkboxMenuItem.setState(SpidersGraph.antialiased); checkboxMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JCheckBoxMenuItem) { JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource(); SpidersGraph.antialiased = j.getState(); MindRaider.spidersGraph.renderModel(); } } }); menu.add(checkboxMenuItem); // Enable hyperbolic checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.hyperbolic"), true); checkboxMenuItem.setMnemonic(KeyEvent.VK_H); checkboxMenuItem.setState(SpidersGraph.hyperbolic); checkboxMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JCheckBoxMenuItem) { JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource(); SpidersGraph.hyperbolic = j.getState(); MindRaider.spidersGraph.renderModel(); } } }); menu.add(checkboxMenuItem); // Show FPS checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.fps"), true); checkboxMenuItem.setMnemonic(KeyEvent.VK_F); checkboxMenuItem.setState(SpidersGraph.fps); checkboxMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JCheckBoxMenuItem) { JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource(); SpidersGraph.fps = j.getState(); MindRaider.spidersGraph.renderModel(); } } }); menu.add(checkboxMenuItem); // Graph color scheme submenu = new JMenu(Messages.getString("MindRaiderJFrame.colorScheme")); submenu.setMnemonic(KeyEvent.VK_C); String[] allProfilesUris = MindRaider.spidersColorProfileRegistry.getAllProfilesUris(); colorSchemeGroup = new ButtonGroup(); for (int i = 0; i < allProfilesUris.length; i++) { rbMenuItem = new UriJRadioButtonMenuItem( MindRaider.spidersColorProfileRegistry.getColorProfileByUri(allProfilesUris[i]).getLabel(), allProfilesUris[i]); rbMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof UriJRadioButtonMenuItem) { MindRaider.spidersColorProfileRegistry .setCurrentProfile(((UriJRadioButtonMenuItem) e.getSource()).uri); MindRaider.spidersGraph .setRenderingProfile(MindRaider.spidersColorProfileRegistry.getCurrentProfile()); MindRaider.spidersGraph.renderModel(); } } }); colorSchemeGroup.add(rbMenuItem); submenu.add(rbMenuItem); } menu.add(submenu); // Annotation color scheme submenu = new JMenu(Messages.getString("MindRaiderJFrame.colorSchemeAnnotation")); submenu.setMnemonic(KeyEvent.VK_A); allProfilesUris = MindRaider.annotationColorProfileRegistry.getAllProfilesUris(); colorSchemeGroup = new ButtonGroup(); for (int i = 0; i < allProfilesUris.length; i++) { rbMenuItem = new UriJRadioButtonMenuItem( MindRaider.annotationColorProfileRegistry.getColorProfileByUri(allProfilesUris[i]).getLabel(), allProfilesUris[i]); rbMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof UriJRadioButtonMenuItem) { MindRaider.annotationColorProfileRegistry .setCurrentProfile(((UriJRadioButtonMenuItem) e.getSource()).uri); OutlineJPanel.getInstance().conceptJPanel.refresh(); } } }); colorSchemeGroup.add(rbMenuItem); submenu.add(rbMenuItem); } menu.add(submenu); menu.addSeparator(); checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.fullScreen")); checkboxMenuItem.setMnemonic(KeyEvent.VK_U); checkboxMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0)); checkboxMenuItem.setState(false); checkboxMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JCheckBoxMenuItem) { JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource(); if (j.getState()) { Gfx.toggleFullScreen(MindRaiderMainWindow.this); } else { Gfx.toggleFullScreen(null); } } } }); menu.add(checkboxMenuItem); menuBar.add(menu); // - outline // ---------------------------------------------------------------------- menu = new JMenu(Messages.getString("MindRaiderJFrame.notebook")); menu.setMnemonic(KeyEvent.VK_N); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.newNotebook")); menuItem.setMnemonic(KeyEvent.VK_N); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO clear should be optional - only if creation finished // MindRider.spidersGraph.clear(); new NewOutlineJDialog(); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.open")); menuItem.setMnemonic(KeyEvent.VK_O); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new OpenOutlineJDialog(); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.close")); menuItem.setMnemonic(KeyEvent.VK_C); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MindRaider.outlineCustodian.close(); OutlineJPanel.getInstance().refresh(); MindRaider.spidersGraph.renderModel(); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.discard")); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.setEnabled(false); // TODO discard method must be implemented menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int result = JOptionPane.showConfirmDialog(MindRaiderMainWindow.this, Messages.getString( "MindRaiderJFrame.confirmDiscardNotebook", MindRaider.profile.getActiveOutline())); if (result == JOptionPane.YES_OPTION) { if (MindRaider.profile.getActiveOutlineUri() != null) { try { MindRaider.labelCustodian .discardOutline(MindRaider.profile.getActiveOutlineUri().toString()); MindRaider.outlineCustodian.close(); } catch (Exception e1) { logger.error(Messages.getString("MindRaiderJFrame.unableToDiscardNotebook"), e1); } } } } }); menu.add(menuItem); menu.addSeparator(); // export submenu = new JMenu(Messages.getString("MindRaiderJFrame.export")); submenu.setMnemonic(KeyEvent.VK_E); // Atom subMenuItem = new JMenuItem("Atom"); subMenuItem.setEnabled(true); subMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { exportActiveOutlineToAtom(); } }); submenu.add(subMenuItem); // OPML subMenuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.opml")); subMenuItem.setEnabled(true); subMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (MindRaider.profile.getActiveOutline() == null) { JOptionPane.showMessageDialog(MindRaiderMainWindow.this, Messages.getString("MindRaiderJFrame.exportNotebookWarning"), Messages.getString("MindRaiderJFrame.exportError"), JOptionPane.ERROR_MESSAGE); return; } JFileChooser fc = new JFileChooser(); fc.setApproveButtonText(Messages.getString("MindRaiderJFrame.export")); fc.setControlButtonsAreShown(true); fc.setDialogTitle(Messages.getString("MindRaiderJFrame.chooseExportDirectory")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // prepare directory String exportDirectory = MindRaider.profile.getHomeDirectory() + File.separator + "export" + File.separator + "opml"; Utils.createDirectory(exportDirectory); fc.setCurrentDirectory(new File(exportDirectory)); int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this); if (returnVal == JFileChooser.APPROVE_OPTION) { String dstFileName = fc.getSelectedFile().getAbsolutePath() + File.separator + "OPML-EXPORT-" + MindRaider.outlineCustodian.getActiveNotebookNcName() + ".xml"; logger.debug(Messages.getString("MindRaiderJFrame.exportingToFile", dstFileName)); MindRaider.outlineCustodian.exportOutline(OutlineCustodian.FORMAT_OPML, dstFileName); Launcher.launchViaStart(dstFileName); } else { logger.debug(Messages.getString("MindRaiderJFrame.exportCommandCancelledByUser")); } } }); submenu.add(subMenuItem); // TWiki subMenuItem = new JMenuItem("TWiki"); subMenuItem.setEnabled(true); subMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (MindRaider.profile.getActiveOutline() == null) { JOptionPane.showMessageDialog(MindRaiderMainWindow.this, Messages.getString("MindRaiderJFrame.exportNotebookWarning"), Messages.getString("MindRaiderJFrame.exportError"), JOptionPane.ERROR_MESSAGE); return; } JFileChooser fc = new JFileChooser(); fc.setApproveButtonText(Messages.getString("MindRaiderJFrame.export")); fc.setControlButtonsAreShown(true); fc.setDialogTitle(Messages.getString("MindRaiderJFrame.chooseExportDirectory")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // prepare directory String exportDirectory = MindRaider.profile.getHomeDirectory() + File.separator + "export" + File.separator + "twiki"; Utils.createDirectory(exportDirectory); fc.setCurrentDirectory(new File(exportDirectory)); int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this); if (returnVal == JFileChooser.APPROVE_OPTION) { final String dstFileName = fc.getSelectedFile().getAbsolutePath() + File.separator + "TWIKI-EXPORT-" + MindRaider.outlineCustodian.getActiveNotebookNcName() + ".txt"; logger.debug(Messages.getString("MindRaiderJFrame.exportingToFile", dstFileName)); MindRaider.outlineCustodian.exportOutline(OutlineCustodian.FORMAT_TWIKI, dstFileName); } else { logger.debug(Messages.getString("MindRaiderJFrame.exportCommandCancelledByUser")); } } }); submenu.add(subMenuItem); menu.add(submenu); // import submenu = new JMenu(Messages.getString("MindRaiderJFrame.import")); submenu.setMnemonic(KeyEvent.VK_I); subMenuItem = new JMenuItem("Atom"); subMenuItem.setEnabled(true); subMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { importFromAtom(); } }); submenu.add(subMenuItem); // TWiki subMenuItem = new JMenuItem("TWiki"); subMenuItem.setEnabled(true); subMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // choose file to be transformed OutlineJPanel.getInstance().clear(); MindRaider.profile.setActiveOutlineUri(null); JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this); if (returnVal == JFileChooser.APPROVE_OPTION) { final File file = fc.getSelectedFile(); MindRaider.profile.deleteActiveModel(); logger.debug( Messages.getString("MindRaiderJFrame.importingTWikiTopic", file.getAbsolutePath())); // perform it async final SwingWorker worker = new SwingWorker() { public Object construct() { ProgressDialogJFrame progressDialogJFrame = new ProgressDialogJFrame( Messages.getString("MindRaiderJFrame.twikiImport"), Messages.getString("MindRaiderJFrame.processingTopicTWiki")); try { MindRaider.outlineCustodian.importNotebook(OutlineCustodian.FORMAT_TWIKI, (file != null ? file.getAbsolutePath() : null), progressDialogJFrame); } finally { if (progressDialogJFrame != null) { progressDialogJFrame.dispose(); } } return null; } }; worker.start(); } else { logger.debug(Messages.getString("MindRaiderJFrame.openCommandCancelledByUser")); } } }); submenu.add(subMenuItem); menu.add(submenu); menuBar.add(menu); // - note // ---------------------------------------------------------------------- menu = new JMenu(Messages.getString("MindRaiderJFrame.concept")); menu.setMnemonic(KeyEvent.VK_C); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.new")); menuItem.setMnemonic(KeyEvent.VK_N); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { OutlineJPanel.getInstance().newConcept(); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.open")); menuItem.setMnemonic(KeyEvent.VK_O); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (MindRaider.profile.getActiveOutlineUri() != null) { new OpenNoteJDialog(); } } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.discard")); // do not accelerate this command with DEL - it's already handled // elsewhere menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { OutlineJPanel.getInstance().conceptDiscard(); } }); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.up")); menuItem.setMnemonic(KeyEvent.VK_U); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, ActionEvent.CTRL_MASK)); menuItem.setEnabled(true); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { OutlineJPanel.getInstance().conceptUp(); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.promote")); menuItem.setMnemonic(KeyEvent.VK_P); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ActionEvent.CTRL_MASK)); menuItem.setEnabled(true); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { OutlineJPanel.getInstance().conceptPromote(); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.demote")); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, ActionEvent.CTRL_MASK)); menuItem.setEnabled(true); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { OutlineJPanel.getInstance().conceptDemote(); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.down")); menuItem.setMnemonic(KeyEvent.VK_O); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, ActionEvent.CTRL_MASK)); menuItem.setEnabled(true); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { OutlineJPanel.getInstance().conceptDown(); } }); menu.add(menuItem); menuBar.add(menu); // - Tools ----------------------------------------------------------- menu = new JMenu(Messages.getString("MindRaiderJFrame.tools")); menu.setMnemonic(KeyEvent.VK_T); menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.checkAndFix")); menuItem.setMnemonic(KeyEvent.VK_F); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Checker.checkAndFixRepositoryAsync(); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.backupRepository")); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Installer.backupRepositoryAsync(); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.rebuildSearchIndex")); menuItem.setMnemonic(KeyEvent.VK_R); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SearchCommander.rebuildSearchAndTagIndices(); } }); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.captureScreen")); menuItem.setMnemonic(KeyEvent.VK_S); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setApproveButtonText(Messages.getString("MindRaiderJFrame.screenshot")); fc.setControlButtonsAreShown(true); fc.setDialogTitle(Messages.getString("MindRaiderJFrame.chooseScreenshotDirectory")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // prepare directory String exportDirectory = MindRaider.profile.getHomeDirectory() + File.separator + "Screenshots"; Utils.createDirectory(exportDirectory); fc.setCurrentDirectory(new File(exportDirectory)); int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this); if (returnVal == JFileChooser.APPROVE_OPTION) { final String filename = fc.getSelectedFile().getAbsolutePath() + File.separator + "screenshot.jpg"; // do it in async (redraw screen) Thread thread = new Thread() { public void run() { OutputStream file = null; try { file = new FileOutputStream(filename); Robot robot = new Robot(); robot.delay(1000); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(file); encoder.encode(robot.createScreenCapture( new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()))); } catch (Exception e1) { logger.error("Unable to capture screen!", e1); } finally { if (file != null) { try { file.close(); } catch (IOException e1) { logger.error("Unable to close stream", e1); } } } } }; thread.setDaemon(true); thread.start(); } } }); menu.add(menuItem); menuBar.add(menu); // - MindForger ----------------------------------------------------------- menu = new JMenu(Messages.getString("MindRaiderMainWindow.menuMindForger")); menu.setMnemonic(KeyEvent.VK_O); //menu.setIcon(IconsRegistry.getImageIcon("tasks-internet.png")); menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.menuMindForgerVideoTutorial")); menuItem.setMnemonic(KeyEvent.VK_G); menuItem.setToolTipText("http://mindraider.sourceforge.net/mindforger.html"); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Launcher.launchInBrowser("http://mindraider.sourceforge.net/mindforger.html"); } }); menuItem.setEnabled(true); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.signUp")); menuItem.setMnemonic(KeyEvent.VK_S); menuItem.setToolTipText("http://www.mindforger.com"); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Launcher.launchInBrowser("http://www.mindforger.com"); } }); menuItem.setEnabled(true); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.menuMindForgerUpload")); menuItem.setMnemonic(KeyEvent.VK_U); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // fork in order to enable status updates in the main window new MindForgerUploadOutlineJDialog(); } }); menuItem.setEnabled(true); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.menuMindForgerDownload")); menuItem.setMnemonic(KeyEvent.VK_U); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { downloadAnOutlineFromMindForger(); } }); menuItem.setEnabled(true); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.menuMindForgerMyOutlines")); menuItem.setMnemonic(KeyEvent.VK_O); menuItem.setEnabled(true); menuItem.setToolTipText("http://web.mindforger.com"); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Launcher.launchInBrowser("http://web.mindforger.com"); } }); menu.add(menuItem); menuBar.add(menu); // - align Help on right ------------------------------------------------------------- menuBar.add(Box.createHorizontalGlue()); // - help ------------------------------------------------------------- menu = new JMenu(Messages.getString("MindRaiderJFrame.help")); menu.setMnemonic(KeyEvent.VK_H); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.documentation")); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { MindRaider.outlineCustodian.loadOutline(new URI(MindRaiderVocabulary .getNotebookUri(OutlineCustodian.MR_DOC_NOTEBOOK_DOCUMENTATION_LOCAL_NAME))); OutlineJPanel.getInstance().refresh(); } catch (Exception e1) { logger.error(Messages.getString("MindRaiderJFrame.unableToLoadHelp", e1.getMessage())); } } }); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.webHomepage")); menuItem.setMnemonic(KeyEvent.VK_H); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Launcher.launchInBrowser("http://mindraider.sourceforge.net"); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.reportBug")); menuItem.setMnemonic(KeyEvent.VK_R); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Launcher.launchInBrowser("http://sourceforge.net/forum/?group_id=128454"); } }); menu.add(menuItem); menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.updateCheck")); menuItem.setMnemonic(KeyEvent.VK_F); menuItem.setEnabled(true); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // just open html page at: // http://mindraider.sourceforge.net/update-7.2.html // this page will either contain "you have the last version" or will ask user to // download the latest version from main page Launcher.launchInBrowser("http://mindraider.sourceforge.net/" + "update-" + MindRaiderConstants.majorVersion + "." + MindRaiderConstants.minorVersion + ".html"); } }); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.about", MindRaiderConstants.MR_TITLE)); menuItem.setMnemonic(KeyEvent.VK_A); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new AboutJDialog(); } }); menu.add(menuItem); menuBar.add(menu); }
From source file:com.lfv.lanzius.server.LanziusServer.java
public void menuChoiceLoadExercise() { if (isSwapping) return;//from w w w . j av a2 s. c o m log.info("Menu: Load exercise"); JFileChooser fc = new JFileChooser("data/exercises"); fc.setDialogTitle("Load exercise..."); fc.setMultiSelectionEnabled(false); fc.setFileFilter(new FileFilter() { public boolean accept(File f) { return !f.isHidden() && (f.isDirectory() || f.getName().endsWith(".xml")); } public String getDescription() { return "Exercise (*.xml)"; } }); int returnVal = JFileChooser.APPROVE_OPTION; if (Config.SERVER_AUTOLOAD_EXERCISE == null) returnVal = fc.showOpenDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { //File file; if (Config.SERVER_AUTOLOAD_EXERCISE == null) exerciseFile = fc.getSelectedFile(); else exerciseFile = new File(Config.SERVER_AUTOLOAD_EXERCISE); log.info("Loading exercise " + exerciseFile); if (exerciseFile.exists()) { loadExercise(exerciseFile); } else JOptionPane.showMessageDialog(frame, "Unable to load exercise! File not found!", "Error!", JOptionPane.ERROR_MESSAGE); } }
From source file:com.lfv.lanzius.server.LanziusServer.java
private void menuChoiceLoadConfiguration() { if (isSwapping) return;/*ww w .ja v a 2 s .c o m*/ log.info("Menu: Load configuration"); JFileChooser fc = new JFileChooser("data/configurations"); fc.setDialogTitle("Load configuration..."); fc.setMultiSelectionEnabled(false); fc.setFileFilter(new FileFilter() { public boolean accept(File f) { return !f.isHidden() && (f.isDirectory() || f.getName().endsWith(".xml")); } public String getDescription() { return "Configuration (*.xml)"; } }); int returnVal = JFileChooser.APPROVE_OPTION; if (Config.SERVER_AUTOLOAD_CONFIGURATION == null) returnVal = fc.showOpenDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file; if (Config.SERVER_AUTOLOAD_CONFIGURATION == null) file = fc.getSelectedFile(); else file = new File(Config.SERVER_AUTOLOAD_CONFIGURATION); log.info("Loading configuration " + file); if (file.exists()) { if (buildConfigurationDocument(file)) { isConfigLoaded = true; updateView(); } else JOptionPane.showMessageDialog(frame, "Invalid configuration file! Make sure that all required tags are defined!", "Error!", JOptionPane.ERROR_MESSAGE); } else JOptionPane.showMessageDialog(frame, "Unable to load configuration! File not found!", "Error!", JOptionPane.ERROR_MESSAGE); } }
From source file:base.BasePlayer.AddGenome.java
public void actionPerformed(ActionEvent event) { if (event.getSource() == download) { if (!downloading) { downloading = true;/* w w w . j av a 2s.c o m*/ downloadGenome(genometable.getValueAt(genometable.getSelectedRow(), 0).toString()); downloading = false; } } else if (event.getSource() == getLinks) { URL[] urls = AddGenome.genomeHash .get(genometable.getValueAt(genometable.getSelectedRow(), 0).toString()); JPopupMenu menu = new JPopupMenu(); JTextArea area = new JTextArea(); JScrollPane menuscroll = new JScrollPane(); area.setFont(Main.menuFont); menu.add(menuscroll); menu.setPreferredSize(new Dimension( menu.getFontMetrics(Main.menuFont).stringWidth(urls[0].toString()) + Main.defaultFontSize * 10, (int) menu.getFontMetrics(Main.menuFont).getHeight() * 4)); //area.setMaximumSize(new Dimension(300, 600)); area.setLineWrap(true); area.setWrapStyleWord(true); for (int i = 0; i < urls.length; i++) { area.append(urls[i].toString() + "\n"); } area.setCaretPosition(0); area.revalidate(); menuscroll.getViewport().add(area); menu.pack(); menu.show(this, 0, 0); } else if (event.getSource() == checkEnsembl) { if (ensemblfetch) { menu.show(AddGenome.treescroll, 0, 0); } else { EnsemblFetch fetcher = new EnsemblFetch(); fetcher.execute(); } } else if (event.getSource() == checkUpdates) { URL testfile = null; try { // kattoo onko paivityksia annotaatioon String ref = selectedNode.toString(); if (AddGenome.genomeHash.get(ref) != null) { ArrayList<String> testfiles = new ArrayList<String>(); if (Main.drawCanvas != null) { for (int i = 0; i < Main.genomehash.get(ref).size(); i++) { testfiles.add(Main.genomehash.get(ref).get(i).getName().replace(".bed.gz", "")); } } testfile = AddGenome.genomeHash.get(ref)[1]; String result = Main.checkFile(testfile, testfiles); if (result.length() == 0) { Main.showError("You have newest annotation file.", "Note"); } else { int n = JOptionPane.showConfirmDialog(Main.drawCanvas, "New annotation file found: " + result + "\nDownload it now?", "Note", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { URL fileurl = new URL(testfile.getProtocol() + "://" + testfile.getHost() + testfile.getPath().substring(0, testfile.getPath().lastIndexOf("/") + 1) + result); OutputRunner runner = new OutputRunner(fileurl, ref); runner.downloadAnnotation = true; runner.execute(); } } } else { Main.showError("This genome is not from Ensembl list, could not check for updates.", "Note", AddGenome.genometable); } } catch (Exception e) { Main.showError("Cannot connect to " + testfile.getHost() + ".\nTry again later.", "Error"); e.printStackTrace(); } } else if (event.getSource() == remove) { if (!selectedNode.isLeaf()) { String removeref = selectedNode.toString(); // Boolean same = false; try { if (Main.drawCanvas != null) { if (removeref.equals(Main.refDropdown.getSelectedItem().toString())) { Main.referenceFile.close(); // same = true; if (ChromDraw.exonReader != null) { ChromDraw.exonReader.close(); } } } if (Main.genomehash.containsKey(removeref)) { for (int i = Main.genomehash.get(removeref).size() - 1; i >= 0; i--) { Main.genomehash.get(removeref).remove(i); } Main.genomehash.remove(removeref); } if (Main.drawCanvas != null) { Main.refModel.removeElement(removeref); Main.refDropdown.removeItem(removeref); Main.refDropdown.revalidate(); } for (int i = 0; i < Main.genome.getItemCount(); i++) { if (Main.genome.getItem(i).getName() != null) { if (Main.genome.getItem(i).getName().equals(removeref)) { Main.genome.remove(Main.genome.getItem(i)); break; } } } FileUtils.deleteDirectory(new File(Main.genomeDir.getCanonicalPath() + "/" + removeref)); checkGenomes(); Main.setAnnotationDrop(""); if (Main.genomehash.size() == 0) { Main.refDropdown.setSelectedIndex(0); Main.setChromDrop("-1"); } } catch (Exception e) { e.printStackTrace(); try { Main.showError("Could not delete genome folder.\nYou can do it manually by deleting folder " + Main.genomeDir.getCanonicalPath() + "/" + removeref, "Note"); } catch (IOException e1) { e1.printStackTrace(); } } } else { try { if (Main.drawCanvas != null) { if (ChromDraw.exonReader != null) { ChromDraw.exonReader.close(); } } Main.removeAnnotationFile(selectedNode.getParent().toString(), selectedNode.toString()); FileUtils.deleteDirectory(new File(Main.genomeDir.getCanonicalPath() + "/" + selectedNode.getParent().toString() + "/annotation/" + selectedNode.toString())); // root.remove(selectedNode.getParent().getIndex(selectedNode)); // root.remove // checkGenomes(); } catch (Exception e) { e.printStackTrace(); try { Main.showError("Could not delete genome folder.\nYou can do it manually by deleting folder " + Main.genomeDir.getCanonicalPath() + "/" + selectedNode.getParent().toString() + "/annotation/" + selectedNode.toString(), "Note"); } catch (IOException e1) { e1.printStackTrace(); } } treemodel.removeNodeFromParent(selectedNode); } } else if (event.getSource() == add) { if (genomeFile == null) { if (new File(genomeFileText.getText()).exists()) { genomeFile = new File(genomeFileText.getText()); } else { genomeFileText.setText("Select reference genome fasta-file."); genomeFileText.setForeground(Color.red); return; } } /*if(genomeName.getText().contains("Give name") || genomeName.getText().length() == 0) { genomeName.setText("Give name of the genome"); genomeName.setForeground(Color.red); genomeName.revalidate(); } else if(!annotation && new File(Main.userDir +"/genomes/"+genomeName.getText().trim().replace("\\s+", "_")).exists()) { genomeName.setText("This genome exists already."); genomeName.setForeground(Color.red); genomeName.revalidate(); } else */ if ((genomeFileText.getText().length() == 0 || genomeFileText.getText().startsWith("Select reference"))) { genomeFileText.setText("Select reference genome fasta-file."); genomeFileText.setForeground(Color.red); genomeFileText.revalidate(); } else { OutputRunner runner = new OutputRunner( genomeFile.getName().replace(".fasta", "").replace(".gz", ""), genomeFile, annotationFile); runner.execute(); } } else if (event.getSource() == openRef) { try { JFileChooser chooser = new JFileChooser(Main.downloadDir); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(false); MyFilterFasta fastaFilter = new MyFilterFasta(); chooser.addChoosableFileFilter(fastaFilter); chooser.setDialogTitle("Select reference fasta-file"); if (Main.screenSize != null) { chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3, (int) Main.screenSize.getHeight() / 3)); } int returnVal = chooser.showOpenDialog((Component) this.getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { genomeFile = chooser.getSelectedFile(); Main.downloadDir = genomeFile.getParent(); Main.writeToConfig("DownloadDir=" + genomeFile.getParent()); genomeFileText.setText(genomeFile.getName()); genomeFileText.revalidate(); frame.pack(); } } catch (Exception ex) { ex.printStackTrace(); } } else if (event.getSource() == openAnno) { try { JFileChooser chooser = new JFileChooser(Main.downloadDir); chooser.setMultiSelectionEnabled(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(false); MyFilterGFF gffFilter = new MyFilterGFF(); chooser.addChoosableFileFilter(gffFilter); chooser.setDialogTitle("Select annotation gff3-file"); if (Main.screenSize != null) { chooser.setPreferredSize(new Dimension((int) Main.screenSize.getWidth() / 3, (int) Main.screenSize.getHeight() / 3)); } int returnVal = chooser.showOpenDialog((Component) this.getParent()); if (returnVal == JFileChooser.APPROVE_OPTION) { if (genomeFile == null) { genomeFile = Main.fastahash.get(Main.hoverGenome); } annotationFile = chooser.getSelectedFile(); Main.downloadDir = annotationFile.getParent(); Main.writeToConfig("DownloadDir=" + annotationFile.getParent()); OutputRunner runner = new OutputRunner( genomeFile.getName().replace(".fasta", "").replace(".gz", ""), genomeFile, annotationFile); runner.execute(); } } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:ffx.ui.MainPanel.java
/** * Trys to convert a file picked from a JFileChooser *//*from www . j a v a 2 s . c o m*/ private Thread open() { if (openThread != null && openThread.isAlive()) { return null; } JFileChooser fc = resetFileChooser(); fc.setDialogTitle("Choose FFX, PDB, XYZ or ARC"); fc.addChoosableFileFilter(xyzFileFilter); fc.addChoosableFileFilter(pdbFileFilter); fc.addChoosableFileFilter(intFileFilter); fc.addChoosableFileFilter(arcFileFilter); fc.addChoosableFileFilter(ffxFileFilter); fc.setAcceptAllFileFilterUsed(true); int result = fc.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); return open(file, null); } return null; }
From source file:gdsc.smlm.ij.plugins.PeakFit.java
/** * @return An input directory containing a series of images *///from w w w . j av a2s. com @SuppressWarnings("unused") private String getInputDirectory(String title) { final JFileChooser chooser = new JFileChooser() { private static final long serialVersionUID = 275144634537614122L; public void approveSelection() { if (getSelectedFile().isFile()) { return; } else super.approveSelection(); } }; if (System.getProperty("os.name").startsWith("Mac OS X")) { chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); } else { chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); } chooser.setDialogTitle(title); int returnVal = chooser.showOpenDialog(IJ.getInstance()); if (returnVal == JFileChooser.APPROVE_OPTION) { return chooser.getSelectedFile().getPath(); } return null; }
From source file:ffx.ui.MainPanel.java
/** * <p>/*from ww w.ja va2s .co m*/ * createKeyFile</p> * * @param system a {@link ffx.ui.FFXSystem} object. * @return a boolean. */ public boolean createKeyFile(FFXSystem system) { String message = new String("Please select a parameter file " + "and a TINKER Key file will be created."); String params = (String) JOptionPane.showInputDialog(this, message, "Parameter File", JOptionPane.QUESTION_MESSAGE, null, keywordPanel.getParamFiles(), null); if (params != null) { if (params.equalsIgnoreCase("Use an existing TINKER Key file")) { JFileChooser fc = resetFileChooser(); fc.setDialogTitle("Choose a KEY File"); fc.setCurrentDirectory(pwd); fc.setSelectedFile(null); fc.setFileFilter(keyFileFilter); int result = fc.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File keyfile = fc.getSelectedFile(); if (keyfile.exists()) { Hashtable<String, Keyword> keywordHash = KeyFilter.open(keyfile); if (keywordHash != null) { system.setKeywords(keywordHash); } else { return false; } system.setKeyFile(keyfile); system.setForceField(null); return true; } } } else { File tempFile = system.getFile(); if (tempFile.getParentFile().canWrite()) { String path = system.getFile().getParent() + File.separatorChar; String keyFileName = system.getName() + ".key"; File keyfile = new File(path + keyFileName); try { FileWriter fw = new FileWriter(keyfile); BufferedWriter bw = new BufferedWriter(fw); bw.write("\n"); bw.write("# Force Field Selection\n"); String tempParm = keywordPanel.getParamPath(params); if (tempParm.indexOf(" ") > 0) { tempParm = "\"" + keywordPanel.getParamPath(params) + "\""; } bw.write("PARAMETERS " + tempParm + "\n"); bw.close(); fw.close(); Hashtable<String, Keyword> keywordHash = KeyFilter.open(keyfile); if (keywordHash != null) { system.setKeywords(keywordHash); } else { return false; } system.setKeyFile(keyfile); system.setForceField(null); return true; } catch (Exception e) { logger.warning("" + e); message = new String("There was an error creating " + keyfile.getAbsolutePath()); JOptionPane.showMessageDialog(this, message); } } else { message = new String( "Could not create a Key file because " + pwd.getAbsolutePath() + " is not writable"); JOptionPane.showMessageDialog(this, message); } } } return false; }
From source file:tarea1.controlador.java
public void seleccionOpcion(int z) throws IOException, Exception { switch (z) {/*from w w w .j a va2s. c om*/ case 1: { //ELEGIR UN ARCHIVO// //EN CASO DE QUERER CAMBIAR EL TIPO DE ARCHIVO. FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "bmp"); JFileChooser abrir = new JFileChooser(); abrir.setFileSelectionMode(JFileChooser.FILES_ONLY); abrir.setFileFilter(filter); abrir.setCurrentDirectory(new File(System.getProperty("user.home"))); int result = abrir.showOpenDialog(inicio); if (result == JFileChooser.APPROVE_OPTION) { // se seleciona el archivo de imagen original File selectedFile = abrir.getSelectedFile(); ruta = selectedFile.getAbsolutePath(); System.out.println("El archivo es: " + ruta); //ruta img = ImageIO.read(new File(ruta)); //se lee el archivo rotate = false; zoomv = false; escalav = false; brillos = false; contrastes = false; undoDelete = false; undoIndex = 0; Change(); inicio.setTitle("PDI: Tarea 3 -" + ruta); } } break;//end case 1 case 2: //imagen en negativo { //se crea un buffer BufferedImage imagenNegativa = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB); //se convierten los colores a negativo y se va guardando en el buffer for (int y = 0; y < alto; y++) { for (int x = 0; x < ancho; x++) { int p = img.getRGB(x, y); //obtenermos el valor r g b a de cada pixel // int a = (p>>24)&0xff; int r = (p >> 16) & 0xff; int g = (p >> 8) & 0xff; int b = p & 0xff; //se resta el rbg r = truncate(255 - r); g = truncate(255 - g); b = truncate(255 - b); //se guarda el rgb p = (r << 16) | (g << 8) | b; imagenNegativa.setRGB(x, y, p); } } //PARA LOS ROTACIONES img = imagenNegativa; ancho = img.getWidth(); alto = img.getHeight(); //se crea un buffer imagenNegativa = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB); //se convierten los colores a negativo y se va guardando en el buffer for (int y = 0; y < alto; y++) { for (int x = 0; x < ancho; x++) { int p = original.getRGB(x, y); //obtenermos el valor r g b a de cada pixel int a = (p >> 24) & 0xff; int r = (p >> 16) & 0xff; int g = (p >> 8) & 0xff; int b = p & 0xff; //se resta el rbg r = 255 - r; g = 255 - g; b = 255 - b; //se guarda el rgb p = (a << 24) | (r << 16) | (g << 8) | b; imagenNegativa.setRGB(x, y, p); } } img = imagenNegativa; Change(); } break;//end case 2 case 3: //flip imagen vertical { //buffer para la imagen BufferedImage mirrorimgV = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB); //recorremos pixel a pixel tooooooooooooodo el buffer for (int i = 0; i < alto; i++) { for (int izquierda = 0, derecha = ancho - 1; izquierda < alto; izquierda++, derecha--) { int p = img.getRGB(izquierda, i); mirrorimgV.setRGB(derecha, i, p); } } img = mirrorimgV; Change(); } break;//end case 3 case 4://flip imagen horizontal { BufferedImage mirrorimgH = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB); for (int i = 0; i < ancho; i++) { for (int arriba = 0, abajo = alto - 1; arriba < alto; arriba++, abajo--) { int p = img.getRGB(i, arriba); mirrorimgH.setRGB(i, abajo, p); } } img = mirrorimgH; Change(); } break;//end case 4 case 5: { //boton de reset //RESET File f = null; //leer image try { f = new File(ruta); rotate = false; zoomv = false; escalav = false; brillos = false; contrastes = false; undoDelete = false; undoIndex = 0; img = ImageIO.read(f); } catch (IOException e) { System.out.println(e); } Change(); } break; //end case 5 case 6: { //leer en formato binario FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "bmp"); JFileChooser abrir = new JFileChooser(); abrir.setFileSelectionMode(JFileChooser.FILES_ONLY); abrir.setFileFilter(filter); //abrir.setCurrentDirectory(new File(System.getProperty("user.home"))); abrir.setCurrentDirectory(new File(System.getProperty("user.dir"))); int result = abrir.showOpenDialog(inicio); if (result == JFileChooser.APPROVE_OPTION) { try { File selectedFile = abrir.getSelectedFile(); ruta = selectedFile.getAbsolutePath(); FileInputStream is = null; is = new FileInputStream(ruta); bmp.read(is); System.out.println("aqui"); MemoryImageSource mis = bmp.crearImageSource(); System.out.println("hola"); Image im = Toolkit.getDefaultToolkit().createImage(mis); //Para poder colorcarlo en el label //Image image = createImage(new MemoryImageSource(bmp.crearImageSource())); BufferedImage newImage = new BufferedImage(im.getWidth(null), im.getHeight(null), BufferedImage.TYPE_INT_RGB); //obtenemos la imagen que si se puede desplgar Graphics2D g = newImage.createGraphics(); g.drawImage(im, 0, 0, null); g.dispose(); img = newImage; rotate = false; zoomv = false; escalav = false; brillos = false; contrastes = false; undoDelete = false; undoIndex = 0; Change(); //add img info inicio.setTitle("PDI: Tarea 3 -" + ruta); //dimensiones, profundidad de bits, Mb ocupados content = ("Size: " + (bmp.tamArchivo) / 1000 + "kb\nDimension: " + bmp.ancho + " x " + bmp.alto + "\nBpp: " + bmp.bitsPorPixel + "bits"); ancho = bmp.ancho; alto = bmp.alto; } catch (Exception ex) { Logger.getLogger(controlador.class.getName()).log(Level.SEVERE, null, ex); } } //end approval if } break; //end case 6 //girar CW case 7: { BufferedImage new_Image = new BufferedImage(alto, ancho, BufferedImage.TYPE_INT_RGB); for (int i = 0; i < ancho; i++) { for (int j = 0; j < alto; j++) { int p = img.getRGB(i, j); new_Image.setRGB(alto - j - 1, i, p); } } img = new_Image; Change(); } break;//end case 7 //girar CCW case 8: { BufferedImage new_Image = new BufferedImage(alto, ancho, BufferedImage.TYPE_INT_RGB); for (int i = 0; i < ancho; i++) { for (int j = 0; j < alto; j++) { int p = img.getRGB(i, j); new_Image.setRGB(j, ancho - i - 1, p); } } img = new_Image; Change(); } break;//end case 8 case 9: { //Guardar Imagen FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "bmp"); JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(filter); fileChooser.setDialogTitle("Save"); fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); int userSelection = fileChooser.showSaveDialog(inicio); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = fileChooser.getSelectedFile(); System.out.println("Save as file: " + fileToSave.getAbsolutePath() + ".bmp"); System.out.println("Save as: " + fileToSave.getName()); bmp.saveMyLifeTonight(fileToSave, img); } } break; case 10: { //free rotation double anguloCartesiano = inicio.optionr; double aux; if (rotate == false) { original = img; } //para la ilusion de rotar sobre la "misma imagen" if (anguloCartesiano < 0) { aux = anguloCartesiano; anguloCartesiano = anguloCartesiano + angulo; angulo = anguloCartesiano; } else if (anguloCartesiano > 0) { aux = anguloCartesiano; anguloCartesiano = angulo + anguloCartesiano; angulo = anguloCartesiano; } anguloCartesiano = anguloCartesiano * Math.PI / 180; //CC coordinates int x, y; double distance, anguloPolar; int pisoX, techoX, pisoY, techoY; double rasterX, rasterY; // colores de los pixeles Color colorTL = null, colorTR, colorBL, colorBR = null; // interpolaciones double intX, intY; double rojoT, verdeT, azulT; double rojoB, verdeB, azulB; int centroX, centroY; centroX = original.getWidth() / 2; centroY = original.getHeight() / 2; BufferedImage imagenRotada = new BufferedImage(original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_ARGB);//fondo transparente for (int i = 0; i < original.getHeight(); ++i) for (int j = 0; j < original.getWidth(); ++j) { // convert raster to Cartesian x = j - centroX; y = centroY - i; // convert Cartesian to polar distance = Math.sqrt(x * x + y * y); anguloPolar = 0.0; if (x == 0) { if (y == 0) { // centre of image, no rotation needed imagenRotada.setRGB(j, i, original.getRGB(j, i)); continue; } else if (y < 0) anguloPolar = 1.5 * Math.PI; else anguloPolar = 0.5 * Math.PI; } else anguloPolar = Math.atan2((double) y, (double) x); // anguloPolar -= anguloCartesiano; //polr a carte rasterX = distance * Math.cos(anguloPolar); rasterY = distance * Math.sin(anguloPolar); // cartesiano a raster rasterX = rasterX + (double) centroX; rasterY = (double) centroY - rasterY; pisoX = (int) (Math.floor(rasterX)); pisoY = (int) (Math.floor(rasterY)); techoX = (int) (Math.ceil(rasterX)); techoY = (int) (Math.ceil(rasterY)); // check bounds /// AQUIWWIUEI if (pisoX < 0 || techoX < 0 || pisoX >= original.getWidth() || techoX >= original.getWidth() || pisoY < 0 || techoY < 0 || pisoY >= original.getHeight() || techoY >= original.getHeight()) continue; intX = rasterX - (double) pisoX; intY = rasterY - (double) pisoY; colorTL = new Color(original.getRGB(pisoX, pisoY)); colorTR = new Color(original.getRGB(techoX, pisoY)); colorBL = new Color(original.getRGB(pisoX, techoY)); colorBR = new Color(original.getRGB(techoX, techoY)); // interpolacion horizontal top rojoT = (1 - intX) * colorTL.getRed() + intX * colorTR.getRed(); verdeT = (1 - intX) * colorTL.getGreen() + intX * colorTR.getGreen(); azulT = (1 - intX) * colorTL.getBlue() + intX * colorTR.getBlue(); // interpolacion horizontal bot rojoB = (1 - intX) * colorBL.getRed() + intX * colorBR.getRed(); verdeB = (1 - intX) * colorBL.getGreen() + intX * colorBR.getGreen(); azulB = (1 - intX) * colorBL.getBlue() + intX * colorBR.getBlue(); // interpolacion vertical int p = original.getRGB(j, i); int a = (p >> 24) & 0xff; int r = (p >> 16) & 0xff; int g = (p >> 8) & 0xff; int b = p & 0xff; r = truncate(Math.round((1 - intY) * rojoT + intY * rojoB)); g = truncate(Math.round((1 - intY) * verdeT + intY * verdeB)); b = truncate(Math.round((1 - intY) * azulT + intY * azulB)); p = (a << 24) | (r << 16) | (g << 8) | b; imagenRotada.setRGB(j, i, p); } img = imagenRotada; rotate = true; inicio.jLabel3.setBounds(0, 0, ancho, alto); ImageIcon icon = new ImageIcon(img); inicio.jLabel3.setIcon(icon); } break; //case 10 case 11: { //histogram //para recorrer todos los valores y obtener los samples /* for (y) { for (x) { pixel = raster.getDataElements(x, y, pixel); } } */ int BINS = 256; HistogramDataset dataset = new HistogramDataset(); Raster raster = img.getRaster(); double[] r = new double[ancho * alto]; ChartPanel panelB = null; ChartPanel panelG = null; ChartPanel panelR = null; ChartPanel panel; if (bmp.bitsPorPixel == 1) { r = raster.getSamples(0, 0, ancho, alto, 0, r); ColorModel ColorM = img.getColorModel(); dataset.addSeries("Grey", r, BINS); //de aqui para abajo es el plotting // chart all JFreeChart chart = ChartFactory.createHistogram("Histogram", "Value", "Count", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setBarPainter(new StandardXYBarPainter()); Paint[] paintArray = { new Color(0x80ff0000, true) }; plot.setDrawingSupplier( new DefaultDrawingSupplier(paintArray, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); panel = new ChartPanel(chart); panel.setMouseWheelEnabled(true); } else { r = raster.getSamples(0, 0, ancho, alto, 0, r); dataset.addSeries("Red", r, BINS); r = raster.getSamples(0, 0, ancho, alto, 1, r); dataset.addSeries("Green", r, BINS); r = raster.getSamples(0, 0, ancho, alto, 2, r); dataset.addSeries("Blue", r, BINS); //de aqui para abajo es el plotting // chart all JFreeChart chart = ChartFactory.createHistogram("Histogram", "Value", "Count", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setBarPainter(new StandardXYBarPainter()); // translucent red, green & blue Paint[] paintArray = { new Color(0x80ff0000, true), new Color(0x8000ff00, true), new Color(0x800000ff, true) }; plot.setDrawingSupplier( new DefaultDrawingSupplier(paintArray, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); panel = new ChartPanel(chart); panel.setMouseWheelEnabled(true); //CHART Red HistogramDataset datasetR = new HistogramDataset(); r = raster.getSamples(0, 0, ancho, alto, 0, r); datasetR.addSeries("Red", r, BINS); JFreeChart chartR = ChartFactory.createHistogram("Histogram B", "Value", "Count", datasetR, PlotOrientation.VERTICAL, true, true, false); XYPlot plotR = (XYPlot) chartR.getPlot(); XYBarRenderer rendererR = (XYBarRenderer) plotR.getRenderer(); rendererR.setBarPainter(new StandardXYBarPainter()); // translucent red, green & blue Paint[] paintArrayR = { new Color(0x80ff0000, true) }; plotR.setDrawingSupplier( new DefaultDrawingSupplier(paintArrayR, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); panelR = new ChartPanel(chartR); panelR.setMouseWheelEnabled(true); //CHART GREEN HistogramDataset datasetG = new HistogramDataset(); r = raster.getSamples(0, 0, ancho, alto, 1, r); datasetG.addSeries("Green", r, BINS); JFreeChart chartG = ChartFactory.createHistogram("Histogram G ", "Value", "Count", datasetG, PlotOrientation.VERTICAL, true, true, false); XYPlot plotG = (XYPlot) chartG.getPlot(); XYBarRenderer rendererG = (XYBarRenderer) plotG.getRenderer(); rendererG.setBarPainter(new StandardXYBarPainter()); // translucent red, green & blue Paint[] paintArrayG = { new Color(0x8000ff00, true) }; plotG.setDrawingSupplier( new DefaultDrawingSupplier(paintArrayG, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); panelG = new ChartPanel(chartG); panelG.setMouseWheelEnabled(true); //CHART BLUE HistogramDataset datasetB = new HistogramDataset(); r = raster.getSamples(0, 0, ancho, alto, 2, r); datasetB.addSeries("Blue", r, BINS); JFreeChart chartB = ChartFactory.createHistogram("Histogram B ", "Value", "Count", datasetB, PlotOrientation.VERTICAL, true, true, false); XYPlot plotB = (XYPlot) chartB.getPlot(); XYBarRenderer rendererB = (XYBarRenderer) plotB.getRenderer(); rendererB.setBarPainter(new StandardXYBarPainter()); // translucent red, green & blue Paint[] paintArrayB = { new Color(0x800000ff, true) }; plotB.setDrawingSupplier( new DefaultDrawingSupplier(paintArrayB, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); panelB = new ChartPanel(chartB); panelB.setMouseWheelEnabled(true); } //JTabbedPane jtp=new JTabbedPane(); if (!viewH) { inicio.jTabbedPane1.addTab("Histogram", panel); inicio.jTabbedPane1.addTab("Histogram R", panelR); inicio.jTabbedPane1.addTab("Histogram G", panelG); inicio.jTabbedPane1.addTab("Histogram B", panelB); viewH = true; } else { inicio.jTabbedPane1.remove(inicio.jTabbedPane1.indexOfTab("Histogram")); inicio.jTabbedPane1.remove(inicio.jTabbedPane1.indexOfTab("Histogram R")); inicio.jTabbedPane1.remove(inicio.jTabbedPane1.indexOfTab("Histogram G")); inicio.jTabbedPane1.remove(inicio.jTabbedPane1.indexOfTab("Histogram B")); viewH = false; } } break; case 12: { //BRILLO int dif = inicio.brillo; if (brillos == false) { original = img; } int ancho = img.getWidth(); int alto = img.getHeight(); //se crea un buffer BufferedImage brillito = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB); //se convierten los colores a negativo y se va guardando en el buffer for (int y = 0; y < alto; y++) { for (int x = 0; x < ancho; x++) { int p = original.getRGB(x, y); //obtenemos el valor r g b a de cada pixel int a = (p >> 24) & 0xff; int r = (p >> 16) & 0xff; int g = (p >> 8) & 0xff; int b = p & 0xff; //se resta el rbg r = truncate(r + dif); g = truncate(g + dif); b = truncate(b + dif); //se guarda el rgb p = (r << 16) | (g << 8) | b; brillito.setRGB(x, y, p); } } img = brillito; brillos = true; inicio.jLabel3.setBounds(0, 0, ancho, alto); ImageIcon icon = new ImageIcon(img); inicio.jLabel3.setIcon(icon); } break; //end case 12 case 13: { //CONTRAST double dif = inicio.contraste; double level = Math.pow(((100.0 + dif) / 100.0), 2.0); if (contrastes == false) { original = img; } int ancho = original.getWidth(); int alto = original.getHeight(); BufferedImage contraste = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB); for (int y = 0; y < alto; y++) { for (int x = 0; x < ancho; x++) { int p = original.getRGB(x, y); int a = (p >> 24) & 0xff; int r = (p >> 16) & 0xff; int g = (p >> 8) & 0xff; int b = p & 0xff; b = truncate((int) ((((((double) b / 255.0) - 0.5) * level) + 0.5) * 255.0)); g = truncate((int) ((((((double) g / 255.0) - 0.5) * level) + 0.5) * 255.0)); r = truncate((int) ((((((double) r / 255.0) - 0.5) * level) + 0.5) * 255.0)); p = (r << 16) | (g << 8) | b; contraste.setRGB(x, y, p); } } img = contraste; contrastes = true; inicio.jLabel3.setBounds(0, 0, ancho, alto); ImageIcon icon = new ImageIcon(img); inicio.jLabel3.setIcon(icon); } break;// case 13 case 14: { //UMBRALIZACION double u = inicio.umbral; if (inicio.jCheckBox1.isSelected()) { int ancho = img.getWidth(); int alto = img.getHeight(); BufferedImage contraste = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB); for (int y = 0; y < alto; y++) { for (int x = 0; x < ancho; x++) { int p = img.getRGB(x, y); int a = (p >> 24) & 0xff; int r = (p >> 16) & 0xff; int g = (p >> 8) & 0xff; int b = p & 0xff; double mediana = (double) (r + b + g); mediana /= 3; int med = (int) Math.round(mediana); b = med; g = med; r = med; if (r <= u) r = 0; else r = 255; if (g <= u) g = 0; else g = 255; if (b <= u) b = 0; else b = 255; p = (r << 16) | (g << 8) | b; contraste.setRGB(x, y, p); } } img = contraste; Change(); } } break; case 15: { BufferedImage equalized = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB); int r, g, b, a; int pixel = 0; //look up table rgb int[] rhist = new int[256]; int[] ghist = new int[256]; int[] bhist = new int[256]; for (int i = 0; i < rhist.length; i++) rhist[i] = 0; for (int i = 0; i < ghist.length; i++) ghist[i] = 0; for (int i = 0; i < bhist.length; i++) bhist[i] = 0; for (int i = 0; i < img.getWidth(); i++) { for (int j = 0; j < img.getHeight(); j++) { int red = new Color(img.getRGB(i, j)).getRed(); int green = new Color(img.getRGB(i, j)).getGreen(); int blue = new Color(img.getRGB(i, j)).getBlue(); rhist[red]++; ghist[green]++; bhist[blue]++; } } //histograma color ArrayList<int[]> imageHist = new ArrayList<int[]>(); imageHist.add(rhist); imageHist.add(ghist); imageHist.add(bhist); //lookup table ArrayList<int[]> imgLT = new ArrayList<int[]>(); // llenar rhist = new int[256]; ghist = new int[256]; bhist = new int[256]; for (int i = 0; i < rhist.length; i++) rhist[i] = 0; for (int i = 0; i < ghist.length; i++) ghist[i] = 0; for (int i = 0; i < bhist.length; i++) bhist[i] = 0; long rojosT = 0; long verdesT = 0; long azulT = 0; // float factorDeEscala = (float) (255.0 / (ancho * alto)); for (int i = 0; i < rhist.length; i++) { rojosT += imageHist.get(0)[i]; int valor = (int) (rojosT * factorDeEscala); if (valor > 255) { rhist[i] = 255; } else rhist[i] = valor; verdesT += imageHist.get(1)[i]; int valg = (int) (verdesT * factorDeEscala); if (valg > 255) { ghist[i] = 255; } else ghist[i] = valg; azulT += imageHist.get(2)[i]; int valb = (int) (azulT * factorDeEscala); if (valb > 255) { bhist[i] = 255; } else bhist[i] = valb; } imgLT.add(rhist); imgLT.add(ghist); imgLT.add(bhist); for (int i = 0; i < ancho; i++) { for (int j = 0; j < alto; j++) { // colores a = new Color(img.getRGB(i, j)).getAlpha(); r = new Color(img.getRGB(i, j)).getRed(); g = new Color(img.getRGB(i, j)).getGreen(); b = new Color(img.getRGB(i, j)).getBlue(); // nuevos valoooooores r = imgLT.get(0)[r]; g = imgLT.get(1)[g]; b = imgLT.get(2)[b]; // rgb otra vez pixel = colorToRGB(a, r, g, b); //imagen final equalized.setRGB(i, j, pixel); } } img = equalized; Change(); } break; case 16: { //zoom double du = inicio.zoom; double u = du / 100; if (zoomv == false) { original = img; } BufferedImage zoom = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB); for (int i = 0; i < zoom.getHeight(); ++i) for (int j = 0; j < zoom.getWidth(); ++j) { //nearest if (tipo == 1) { int ax = (int) (Math.floor(i / u)); int ay = (int) (Math.floor(j / u)); int p = original.getRGB(ax, ay); zoom.setRGB(i, j, p); } //bilinear if (tipo == 2) { } //no loss if (tipo == 0) { int ax = (int) (i / u); int ay = (int) (j / u); int p = original.getRGB(ax, ay); zoom.setRGB(i, j, p); } } img = zoom; zoomv = true; inicio.jLabel3.setBounds(0, 0, ancho, alto); ImageIcon icon = new ImageIcon(img); inicio.jLabel3.setIcon(icon); } break; case 17: { //escala double du = inicio.escala; double u = du / 100; if (escalav == false) { original = img; } int escalaX = (int) (ancho * u); int escalaY = (int) (alto * u); BufferedImage escala = new BufferedImage(escalaX, escalaY, BufferedImage.TYPE_INT_RGB); for (int i = 0; i < escala.getHeight(); ++i) for (int j = 0; j < escala.getWidth(); ++j) { //R(x,y):= A(x/ax, y/ay) //R(x,y):= A(Floor x/10 ,Floor /10) //nearest if (tipo == 1) { int ax = (int) (Math.floor(i / u)); int ay = (int) (Math.floor(j / u)); int p = original.getRGB(ax, ay); escala.setRGB(i, j, p); } //bilinear if (tipo == 2) { } //no loss if (tipo == 0) { int ax = (int) (i / u); int ay = (int) (j / u); int p = original.getRGB(ax, ay); escala.setRGB(i, j, p); } } img = escala; escalav = true; inicio.jLabel3.setBounds(0, 0, ancho, alto); ImageIcon icon = new ImageIcon(img); inicio.jLabel3.setIcon(icon); content = ("Dimension: " + img.getWidth() + " x " + img.getHeight() + "\nBpp: " + bmp.bitsPorPixel + "bits"); } break; case 18://prewitt both { BufferedImage aux = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB); aux = img; BufferedImage y, x; float[][] arraya = { { -1, 0, 1 }, { -1, 0, 1 }, { -1, 0, 1 } }; float[][] arrayb = { { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 }, }; float[][] arrayc = { { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, }; float[][] array = { { -1, -1, -1 }, { 0, 0, 0 }, { 1, 1, 1 } }; float[][] array2 = { { -2, -2, -2, -2, -2 }, { -1, -1, -1, -1, -1 }, { 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1 }, { 2, 2, 2, 2, 2 }, }; float[][] array3 = { { -3, -3, -3, -3, -3, -3, -3 }, { -2, -2, -2, -2, -2, -2, -2 }, { -1, -1, -1, -1, -1, -1, -1 }, { 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1, 1, 1 }, { 2, 2, 2, 2, 2, 2, 2 }, { 3, 3, 3, 3, 3, 3, 3 }, }; if (inicio.size == 7) { y = generalKernel(array3, 7); img = aux; x = generalKernel(arrayc, 7); } else if (inicio.size == 5) { y = generalKernel(array2, 5); img = aux; x = generalKernel(arrayb, 5); } else { y = generalKernel(array, 3); img = aux; x = generalKernel(arraya, 3); } for (int i = 0; i < ancho; i++) { for (int j = 0; j < alto; j++) { int p = x.getRGB(i, j); int p2 = y.getRGB(i, j); //obtenemos el valor r g b a de cada pixel int r = (p >> 16) & 0xff; int g = (p >> 8) & 0xff; int b = p & 0xff; int r2 = (p2 >> 16) & 0xff; int g2 = (p2 >> 8) & 0xff; int b2 = p2 & 0xff; //process int resR = truncate(Math.sqrt(Math.pow(r, 2) + Math.pow(r2, 2))); int resG = truncate(Math.sqrt(Math.pow(g, 2) + Math.pow(g2, 2))); int resB = truncate(Math.sqrt(Math.pow(b, 2) + Math.pow(b2, 2))); //se guarda el rgb p = (resR << 16) | (resG << 8) | resB; img.setRGB(i, j, p); } Change(); } } break; case 19://prewitt x { BufferedImage x; float[][] arraya = { { -1, 0, 1 }, { -1, 0, 1 }, { -1, 0, 1 } }; float[][] arrayb = { { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 }, { -2, -1, 0, 1, 2 }, }; float[][] arrayc = { { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, { -3, -2, -1, 0, 1, 2, 3 }, }; if (inicio.size == 7) { x = generalKernel(arrayc, 7); } else if (inicio.size == 5) { x = generalKernel(arrayb, 5); } else { x = generalKernel(arraya, 3); } img = x; Change(); } break; case 20://prewitt y { BufferedImage y; float[][] array = { { -1, -1, -1 }, { 0, 0, 0 }, { 1, 1, 1 } }; float[][] array2 = { { -2, -2, -2, -2, -2 }, { -1, -1, -1, -1, -1 }, { 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1 }, { 2, 2, 2, 2, 2 }, }; float[][] array3 = { { -3, -3, -3, -3, -3, -3, -3 }, { -2, -2, -2, -2, -2, -2, -2 }, { -1, -1, -1, -1, -1, -1, -1 }, { 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1, 1, 1 }, { 2, 2, 2, 2, 2, 2, 2 }, { 3, 3, 3, 3, 3, 3, 3 }, }; if (inicio.size == 7) { y = generalKernel(array3, 7); } else if (inicio.size == 5) { y = generalKernel(array2, 5); } else { y = generalKernel(array, 3); } img = y; Change(); } break; case 21://Sobel x { BufferedImage x; float[][] arraya = { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } }; float[][] arrayb = { { -5, -4, 0, 4, 5 }, { -8, -10, 0, 10, 8 }, { -10, -20, 0, 20, 10 }, { -8, -10, 0, 10, 8 }, { -5, -4, 0, 4, 5 }, }; float[][] arrayc = { { 3, 2, 1, 0, -1, -2, -3 }, { 4, 3, 2, 0, -2, -3, -4 }, { 5, 4, 3, 0, -3, -4, -5 }, { 6, 5, 4, 0, -4, -5, -6 }, { 5, 4, 3, 0, -3, -4, -5 }, { 4, 3, 2, 0, -2, -3, -4 }, { 3, 2, 1, 0, -1, -2, -3 }, }; if (inicio.size == 7) { x = generalKernel(arrayc, 7); } else if (inicio.size == 5) { x = generalKernel(arrayb, 5); } else { x = generalKernel(arraya, 3); } img = x; Change(); } break; case 22://sobel y { BufferedImage y; float[][] array1 = { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } }; float[][] array2 = { { 5, 8, 10, 8, 5 }, { 4, 10, 20, 10, 4 }, { 0, 0, 0, 0, 0 }, { -4, -10, -20, -10, -4 }, { -5, -8, -10, -8, -5 }, }; float[][] array3 = { { 3, 4, 5, 6, 5, 4, 3 }, { 2, 3, 4, 5, 4, 3, 2 }, { 1, 2, 3, 4, 3, 2, 1 }, { 0, 0, 0, 0, 0, 0, 0 }, { -1, -2, -3, -4, -3, -2, -1 }, { -2, -3, -4, -5, -4, -3, -2 }, { -3, -4, -5, -6, -5, -4, -3 }, }; if (inicio.size == 7) { y = generalKernel(array3, 7); } else if (inicio.size == 5) { y = generalKernel(array2, 5); } else { y = generalKernel(array1, 3); } img = y; Change(); } break; case 23://sobel both { BufferedImage aux = new BufferedImage(ancho, alto, BufferedImage.TYPE_INT_RGB); aux = img; BufferedImage y, x; float[][] arraya = { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } }; float[][] arrayb = { { -5, -4, 0, 4, 5 }, { -8, -10, 0, 10, 8 }, { -10, -20, 0, 20, 10 }, { -8, -10, 0, 10, 8 }, { -5, -4, 0, 4, 5 }, }; float[][] arrayc = { { 3, 2, 1, 0, -1, -2, -3 }, { 4, 3, 2, 0, -2, -3, -4 }, { 5, 4, 3, 0, -3, -4, -5 }, { 6, 5, 4, 0, -4, -5, -6 }, { 5, 4, 3, 0, -3, -4, -5 }, { 4, 3, 2, 0, -2, -3, -4 }, { 3, 2, 1, 0, -1, -2, -3 }, }; float[][] array1 = { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } }; float[][] array2 = { { 5, 8, 10, 8, 5 }, { 4, 10, 20, 10, 4 }, { 0, 0, 0, 0, 0 }, { -4, -10, -20, -10, -4 }, { -5, -8, -10, -8, -5 }, }; float[][] array3 = { { 3, 4, 5, 6, 5, 4, 3 }, { 2, 3, 4, 5, 4, 3, 2 }, { 1, 2, 3, 4, 3, 2, 1 }, { 0, 0, 0, 0, 0, 0, 0 }, { -1, -2, -3, -4, -3, -2, -1 }, { -2, -3, -4, -5, -4, -3, -2 }, { -3, -4, -5, -6, -5, -4, -3 }, }; if (inicio.size == 7) { y = generalKernel(array3, 7); img = aux; x = generalKernel(arrayc, 7); } else if (inicio.size == 5) { y = generalKernel(array2, 5); img = aux; x = generalKernel(arrayb, 5); } else { y = generalKernel(array1, 3); img = aux; x = generalKernel(arraya, 3); } for (int i = 0; i < ancho; i++) { for (int j = 0; j < alto; j++) { int p = x.getRGB(i, j); int p2 = y.getRGB(i, j); //obtenermos el valor r g b a de cada pixel int r = (p >> 16) & 0xff; int g = (p >> 8) & 0xff; int b = p & 0xff; int r2 = (p2 >> 16) & 0xff; int g2 = (p2 >> 8) & 0xff; int b2 = p2 & 0xff; //process int resR = truncate(Math.sqrt(Math.pow(r, 2) + Math.pow(r2, 2))); int resG = truncate(Math.sqrt(Math.pow(g, 2) + Math.pow(g2, 2))); int resB = truncate(Math.sqrt(Math.pow(b, 2) + Math.pow(b2, 2))); //se guarda el rgb p = (resR << 16) | (resG << 8) | resB; img.setRGB(i, j, p); } Change(); } } break; case 24://Gauss { BufferedImage y; float[][] arraya = { { 1 / 16f, 1 / 8f, 1 / 16f }, { 1 / 8f, 1 / 4f, 1 / 8f }, { 1 / 16f, 1 / 8f, 1 / 16f }, }; float[][] arrayb = { { 1 / 273f, 4 / 273f, 7 / 273f, 4 / 273f, 1 / 273f }, { 4 / 273f, 16 / 273f, 26 / 273f, 16 / 273f, 4 / 273f }, { 7 / 273f, 26 / 273f, 41 / 273f, 26 / 273f, 7 / 273f }, { 4 / 273f, 16 / 273f, 26 / 273f, 16 / 273f, 4 / 273f }, { 1 / 273f, 4 / 273f, 7 / 273f, 4 / 273f, 1 / 273f }, }; float[][] arrayc = { { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f }, { 0.00002292f, 0.00078634f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f }, { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f }, { 0.00038771f, 0.01330373f, 0.11098164f, 0.22508352f, 0.11098164f, 0.01330373f, 0.00038771f }, { 0.00019117f, 0.00655965f, 0.05472157f, 0.11098164f, 0.05472157f, 0.00655965f, 0.00019117f }, { 0.00002292f, 0.00078634f, 0.00655965f, 0.01330373f, 0.00655965f, 0.00078633f, 0.00002292f }, { 0.00000067f, 0.00002292f, 0.00019117f, 0.00038771f, 0.00019117f, 0.00002292f, 0.00000067f } }; if (inicio.size == 7) { y = generalKernel(arrayc, 7); } else if (inicio.size == 5) { y = generalKernel(arrayb, 5); } else { y = generalKernel(arraya, 3); } img = y; Change(); } break; case 25: { BufferedImage y; float[][] arraya = { { 1 / 9f, 1 / 9f, 1 / 9f }, { 1 / 9f, 1 / 9f, 1 / 9f }, { 1 / 9f, 1 / 9f, 1 / 9f }, }; float[][] arrayb = { { 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f }, { 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f }, { 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f }, { 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f }, { 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f, 1 / 25f }, }; float[][] arrayc = { { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f }, { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f }, { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f }, { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f }, { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f }, { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f }, { 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f, 1 / 49f }, }; if (inicio.size == 7) { y = generalKernel(arrayc, 7); } else if (inicio.size == 5) { y = generalKernel(arrayb, 5); } else { y = generalKernel(arraya, 3); } img = y; Change(); } break; case 26://sharpen { BufferedImage y; float[][] arraya = { { -1, -1, -1 }, { -1, 9, -1 }, { -1, -1, -1 }, }; float[][] arrayb = { { -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1 }, { -1, -1, 26, -1, -1 }, { -1, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1 }, }; float[][] arrayc = { { -1, -1, -1, -1, -1, -1, -1 }, { -1, -2, -2, -2, -2, -2, -1 }, { -1, -2, -3, -3, -3, -2, -1 }, { -1, -2, -3, 81, -3, -2, -1 }, { -1, -2, -3, -3, -3, -2, -1 }, { -1, -2, -2, -2, -2, -2, -1 }, { -1, -1, -1, -1, -1, -1, -1 }, }; if (inicio.size == 7) { y = generalKernel(arrayc, 7); } else if (inicio.size == 5) { y = generalKernel(arrayb, 5); } else { y = generalKernel(arraya, 3); } img = y; Change(); } break; case 27: { kernel = new Kernel(); kernel.show(); kernel.setTitle("Kernel"); kernel.setVisible(true); kernel.setLocationRelativeTo(null); kernel.setResizable(false); kernel.pack(); } break; case 28: //valores { float[][] floatdata = new float[kernel.dim][kernel.dim]; for (int i = 0; i < kernel.dim; i++) { for (int j = 0; j < kernel.dim; j++) { floatdata[i][j] = floatValue(kernel.tableData[i][j]); } } kernel.dispose(); BufferedImage y; y = generalKernel(floatdata, kernel.dim); img = y; Change(); } break; case 29://motion blur { BufferedImage y; float[][] array = { { 1 / 9f, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 1 / 9f, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 1 / 9f, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 1 / 9f, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 1 / 9f, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 1 / 9f, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 1 / 9f, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 1 / 9f, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 1 / 9f }, }; /* float[][] arrayb = { {1/3f, 0, 0}, {0, 1/3f, 0}, {0, 0, 1/3f}, };*/ y = generalKernel(array, 9); img = y; Change(); } break; } //end switch }