List of usage examples for javax.swing JFileChooser setFileFilter
@BeanProperty(preferred = true, description = "Sets the File Filter used to filter out files of type.") public void setFileFilter(FileFilter filter)
From source file:src.gui.ItSIMPLE.java
/** * @return Returns the planAnalysisFramePanel. *///from w w w . j a va2 s .co m private ItFramePanel getPlanAnalysisFramePanel() { if (planAnalysisFramePanel == null) { planAnalysisFramePanel = new ItFramePanel(":: Plan Analysis", ItFramePanel.NO_MINIMIZE_MAXIMIZE); // tool bar JToolBar chartsToolBar = new JToolBar(); chartsToolBar.add(new JButton(drawChartAction)); // charts panel chartsPanel = new JPanel(); chartsPanel.setLayout(new BoxLayout(chartsPanel, BoxLayout.Y_AXIS)); ItFramePanel variableSelectionPanel = new ItFramePanel(".: Select variables to be tracked", ItFramePanel.NO_MINIMIZE_MAXIMIZE); //variableSelectionPanel.setBackground(new Color(151,151,157)); JSplitPane split = new JSplitPane(); split.setContinuousLayout(true); split.setOrientation(JSplitPane.HORIZONTAL_SPLIT); split.setDividerLocation(2 * screenSize.height / 3); split.setDividerSize(8); //split.setPreferredSize(new Dimension(screenSize.width/4-20, screenSize.height/2 - 50)); //split.setPreferredSize(new Dimension(screenSize.width/4-20, 120)); split.setLeftComponent(new JScrollPane(variablesPlanTree)); split.setRightComponent(new JScrollPane(selectedVariablesPlanTree)); variableSelectionPanel.setContent(split, false); //variableSelectionPanel.setParentSplitPane() //JPanel variableSelectionPanel = new JPanel(new BorderLayout()); //variableSelectionPanel.add(new JScrollPane(variablesPlanTree), BorderLayout.CENTER); //variableSelectionPanel.add(new JScrollPane(selectedVariablesPlanTree), BorderLayout.EAST); ItFramePanel variableGraphPanel = new ItFramePanel(".: Chart", ItFramePanel.NO_MINIMIZE_MAXIMIZE); variableGraphPanel.setContent(chartsPanel, true); JSplitPane mainvariablesplit = new JSplitPane(); mainvariablesplit.setContinuousLayout(true); mainvariablesplit.setOrientation(JSplitPane.VERTICAL_SPLIT); mainvariablesplit.setDividerLocation(150); mainvariablesplit.setDividerSize(8); //mainvariablesplit.setPreferredSize(new Dimension(screenSize.width/4-20, screenSize.height/2 - 50)); mainvariablesplit.setTopComponent(variableSelectionPanel); mainvariablesplit.setBottomComponent(variableGraphPanel); // main charts panel - used to locate the tool bar above the charts panel JPanel mainChartsPanel = new JPanel(new BorderLayout()); mainChartsPanel.add(chartsToolBar, BorderLayout.NORTH); //mainChartsPanel.add(new JScrollPane(chartsPanel), BorderLayout.CENTER); mainChartsPanel.add(mainvariablesplit, BorderLayout.CENTER); //Results planInfoEditorPane = new JEditorPane(); planInfoEditorPane.setContentType("text/html"); planInfoEditorPane.setEditable(false); planInfoEditorPane.setCursor(new Cursor(Cursor.TEXT_CURSOR)); planInfoEditorPane.setBackground(Color.WHITE); JPanel resultsPanel = new JPanel(new BorderLayout()); JToolBar resultsToolBar = new JToolBar(); resultsToolBar.setRollover(true); JButton planReportButton = new JButton("View Full Report", new ImageIcon("resources/images/viewreport.png")); planReportButton.setToolTipText("<html>View full plan report.<br> For multiple plans you will need " + "access to the Internet.<br> The components used in the report require such access (no data is " + "sent through the Internet).</html>"); planReportButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { //Opens html with defaut browser String path = "resources/report/Report.html"; File report = new File(path); path = report.getAbsolutePath(); try { BrowserLauncher launcher = new BrowserLauncher(); launcher.openURLinBrowser("file://" + path); } catch (BrowserLaunchingInitializingException ex) { Logger.getLogger(ItSIMPLE.class.getName()).log(Level.SEVERE, null, ex); appendOutputPanelText("ERROR. Problem while trying to open the default browser. \n"); } catch (UnsupportedOperatingSystemException ex) { Logger.getLogger(ItSIMPLE.class.getName()).log(Level.SEVERE, null, ex); appendOutputPanelText("ERROR. Problem while trying to open the default browser. \n"); } } }); resultsToolBar.add(planReportButton); resultsToolBar.addSeparator(); JButton planReportDataButton = new JButton("Save Report Data", new ImageIcon("resources/images/savePDDL.png")); planReportDataButton.setToolTipText("<html>Save report data to file</html>"); planReportDataButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { //Save report data if (solveResult != null) { Element lastOpenFolderElement = itSettings.getChild("generalSettings") .getChild("lastOpenFolder"); JFileChooser fc = new JFileChooser(lastOpenFolderElement.getText()); fc.setDialogTitle("Save Report Data"); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileFilter(new XMLFileFilter()); int returnVal = fc.showSaveDialog(ItSIMPLE.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File selectedFile = fc.getSelectedFile(); String path = selectedFile.getPath(); if (!path.toLowerCase().endsWith(".xml")) { path += ".xml"; } //save file (xml) try { FileWriter file = new FileWriter(path); file.write(XMLUtilities.toString(solveResult)); file.close(); } catch (IOException e1) { e1.printStackTrace(); } //Save as a last open folder String folder = selectedFile.getParent(); //Element lastOpenFolderElement = itSettings.getChild("generalSettings").getChild("lastOpenFolder"); lastOpenFolderElement.setText(folder); XMLUtilities.writeToFile("resources/settings/itSettings.xml", itSettings.getDocument()); //Ask if the user wants to save plans individually too. boolean needToSavePlans = false; int option = JOptionPane.showOptionDialog(instance, "<html><center>Do you also want to save the plans" + "<br>in individual files?</center></html>", "Save plans", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); switch (option) { case JOptionPane.YES_OPTION: { needToSavePlans = true; } break; case JOptionPane.NO_OPTION: { needToSavePlans = false; } break; } if (needToSavePlans) { //Close Open tabs List<?> problems = null; try { XPath ppath = new JDOMXPath("project/domains/domain/problems/problem"); problems = ppath.selectNodes(solveResult); } catch (JaxenException e2) { e2.printStackTrace(); } for (int i = 0; i < problems.size(); i++) { Element problem = (Element) problems.get(i); //create a folder for each problem and put all plans inside as xml files String folderName = problem.getChildText("name"); String folderPath = selectedFile.getAbsolutePath() .replace(selectedFile.getName(), folderName); //System.out.println(folderPath); File planfolder = new File(folderPath); boolean canSavePlan = false; try { if (planfolder.mkdir()) { System.out.println("Directory '" + folderPath + "' created."); canSavePlan = true; } else { System.out.println("Directory '" + folderPath + "' was not created."); } } catch (Exception ep) { ep.printStackTrace(); } if (canSavePlan) { Element plans = problem.getChild("plans"); for (Iterator<Element> it = plans.getChildren("xmlPlan").iterator(); it .hasNext();) { Element eaplan = it.next(); Element theplanner = eaplan.getChild("planner"); //save file (xml) String planFileName = "solution" + theplanner.getChildText("name") + "-" + theplanner.getChildText("version") + "-" + Integer.toString(plans.getChildren().indexOf(eaplan)) + ".xml"; String planPath = folderPath + File.separator + planFileName; /* try { FileWriter planfile = new FileWriter(planPath); planfile.write(XMLUtilities.toString(eaplan)); planfile.close(); System.out.println("File '" + planPath + "' created."); } catch (IOException e1) { e1.printStackTrace(); } * */ if (eaplan.getChild("plan").getChildren().size() > 0) { //TODO: save the plan in PDDL too. It should be done through the XPDDL/PDDL classes String pddlplan = ToXPDDL.XMLtoXPDDLPlan(eaplan); String planFileNamePDDL = "solution" + theplanner.getChildText("name") + "-" + theplanner.getChildText("version") + "-" + Integer.toString(plans.getChildren().indexOf(eaplan)) + ".pddl"; String planPathPDDL = folderPath + File.separator + planFileNamePDDL; //String cfolderPath = selectedFile.getAbsolutePath().replace(selectedFile.getName(), ""); //String planFileNamePDDL = theplanner.getChildText("name")+"-"+theplanner.getChildText("version") + "-" + folderName+"-solution.pddl"; //String planPathPDDL = cfolderPath + File.separator + planFileNamePDDL; //if (!theplanner.getChildText("name").contains("MIPS")){ try { FileWriter planfile = new FileWriter(planPathPDDL); planfile.write(pddlplan); planfile.close(); System.out.println("File '" + planPathPDDL + "' created."); } catch (IOException e1) { e1.printStackTrace(); } } //} } } } } } } else { appendOutputPanelText(">> No report data available to save! \n"); } } }); resultsToolBar.add(planReportDataButton); JButton openPlanReportDataButton = new JButton("Open Report Data", new ImageIcon("resources/images/openreport.png")); openPlanReportDataButton.setToolTipText("<html>Open report data to file</html>"); openPlanReportDataButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { planSimStatusBar.setText("Status: Opening File..."); appendOutputPanelText(">> Opening File... \n"); //Open report data Element lastOpenFolderElement = itSettings.getChild("generalSettings") .getChild("lastOpenFolder"); JFileChooser fc = new JFileChooser(lastOpenFolderElement.getText()); fc.setDialogTitle("Open Report Data"); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileFilter(new XMLFileFilter()); int returnVal = fc.showOpenDialog(ItSIMPLE.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // Get itSIMPLE itSettings from itSettings.xml org.jdom.Document resultsDoc = null; try { resultsDoc = XMLUtilities.readFromFile(file.getPath()); solveResult = resultsDoc.getRootElement(); //XMLUtilities.printXML(solveResult); if (solveResult.getName().equals("projects")) { String report = PlanAnalyzer.generatePlannersComparisonReport(solveResult); String comparisonReport = PlanAnalyzer .generateFullPlannersComparisonReport(solveResult); //Save Comparison Report file saveFile("resources/report/Report.html", comparisonReport); setPlanInfoPanelText(report); setPlanEvaluationInfoPanelText(""); appendOutputPanelText(">> Report data read! \n"); //My experiments PlanAnalyzer.myAnalysis(itPlanners.getChild("planners"), solveResult); } } catch (Exception e1) { e1.printStackTrace(); } //Save as a last open folder String folder = fc.getSelectedFile().getParent(); lastOpenFolderElement.setText(folder); XMLUtilities.writeToFile("resources/settings/itSettings.xml", itSettings.getDocument()); } else { planSimStatusBar.setText("Status:"); appendOutputPanelText(">> Canceled \n"); } } }); resultsToolBar.add(openPlanReportDataButton); JButton compareProjectReportDataButton = new JButton("Compare Project Data", new ImageIcon("resources/images/compare.png")); compareProjectReportDataButton.setToolTipText( "<html>Compare different project report data <br> This is commonly use to compare diferent domain models with different adjustments.<br>" + "One project data must be chosen as a reference; others will be compared to this referencial one.</html>"); compareProjectReportDataButton.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { final ProjectComparisonDialog dialog = new ProjectComparisonDialog(); dialog.setVisible(true); final List<String> files = dialog.getFiles(); if (files.size() > 1) { new Thread() { public void run() { appendOutputPanelText(">> Project comparison report requested. Processing... \n"); planSimStatusBar.setText("Status: Reading files ..."); appendOutputPanelText(">> Reading files ... \n"); //base project file String baseFileName = files.get(0); appendOutputPanelText(">> Reading file '" + baseFileName + "' \n"); org.jdom.Document baseProjectDoc = null; try { baseProjectDoc = XMLUtilities.readFromFile(baseFileName); } catch (Exception ec) { ec.printStackTrace(); } Element baseProject = null; if (baseProjectDoc != null) { baseProject = baseProjectDoc.getRootElement().getChild("project"); } //The comparible projects List<Element> comparableProjects = new ArrayList<Element>(); for (int i = 1; i < files.size(); i++) { String eafile = files.get(i); appendOutputPanelText(">> Reading file '" + eafile + "' \n"); org.jdom.Document eaProjectDoc = null; try { eaProjectDoc = XMLUtilities.readFromFile(eafile); } catch (Exception ec) { ec.printStackTrace(); } if (eaProjectDoc != null) { comparableProjects.add(eaProjectDoc.getRootElement().getChild("project")); } } appendOutputPanelText(">> Files read. Building report... \n"); String comparisonReport = PlanAnalyzer.generateProjectComparisonReport(baseProject, comparableProjects); saveFile("resources/report/Report.html", comparisonReport); appendOutputPanelText( ">> Project comparison report generated. Press 'View Full Report'\n"); appendOutputPanelText(" \n"); } }.start(); } } }); resultsToolBar.add(compareProjectReportDataButton); resultsPanel.add(resultsToolBar, BorderLayout.NORTH); resultsPanel.add(new JScrollPane(planInfoEditorPane), BorderLayout.CENTER); JTabbedPane planAnalysisTabbedPane = new JTabbedPane(); planAnalysisTabbedPane.addTab("Results", resultsPanel); planAnalysisTabbedPane.addTab("Variable Tracking", mainChartsPanel); planAnalysisTabbedPane.addTab("Movie Maker", getMovieMakerPanel()); planAnalysisTabbedPane.addTab("Plan Evaluation", getPlanEvaluationPanel()); planAnalysisTabbedPane.addTab("Plan Database", getPlanDatabasePanel()); planAnalysisTabbedPane.addTab("Rationale Database", getRationaleDatabasePanel()); JPanel planAnalysisPanel = new JPanel(new BorderLayout()); //planAnalysisPanel.add(chartsToolBar, BorderLayout.NORTH); planAnalysisPanel.add(planAnalysisTabbedPane, BorderLayout.CENTER); planAnalysisFramePanel.setContent(planAnalysisPanel, false); } return planAnalysisFramePanel; }
From source file:nl.detoren.ijsco.ui.Mainscreen.java
private void addMenubar() { // Menu bar met 1 niveau Mainscreen ms = this; JMenuBar menubar = new JMenuBar(); JMenu filemenu = new JMenu("Bestand"); // File menu//from w ww . j a v a 2 s .c o m JMenuItem item; /* item = new JMenuItem("Openen..."); item.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); //controller.leesBestand(file.getAbsolutePath()); ms.repaint(); } } }); filemenu.add(item); */ /* item = new JMenuItem("Opslaan"); item.setAccelerator(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { //controller.saveState(true, "save"); } }); filemenu.add(item); */ filemenu.addSeparator(); item = new JMenuItem("Instellingen..."); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { actieInstellingen(); } }); item.setAccelerator(KeyStroke.getKeyStroke('I', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); filemenu.add(item); filemenu.addSeparator(); item = new JMenuItem("Afsluiten"); item.setAccelerator(KeyStroke.getKeyStroke('Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { controller.saveState(false, null); System.exit(EXIT_ON_CLOSE); } }); filemenu.add(item); menubar.add(filemenu); /** * Toernooi menu */ JMenu toernooimenu = new JMenu("Toernooi"); item = new JMenuItem("Toernooiinformatie"); item.setAccelerator(KeyStroke.getKeyStroke('T', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieNieuweSpeler(null, null); bewerkToernooi(); hoofdPanel.repaint(); } }); toernooimenu.add(item); menubar.add(toernooimenu); /** * Spelersdatabase menu */ JMenu spelermenu = new JMenu("Spelersdatabase"); item = new JMenuItem("OSBO JSON lijst ophalen (Online)"); item.setAccelerator(KeyStroke.getKeyStroke('J', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieNieuweSpeler(null, null); leeslijstOnline("www.osbo.nl", "/jeugd/currentratings.json"); hoofdPanel.repaint(); } }); spelermenu.add(item); item = new JMenuItem("OSBO htmllijst ophalen !verouderd! (Online)"); item.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieNieuweSpeler(null, null); leeslijstOnline("www.osbo.nl", "/jeugd/jrating.htm"); hoofdPanel.repaint(); } }); spelermenu.add(item); item = new JMenuItem("OSBO/IJSCO compatible lijst inlezen (Bestand)"); item.setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); leesOSBOlijstBestand(file.getAbsolutePath()); } hoofdPanel.repaint(); } }); spelermenu.add(item); /* item = new JMenuItem("Groslijst CSV inlezen (Bestand) N/A"); item.setAccelerator(KeyStroke.getKeyStroke('C', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieNieuweSpeler(null, null); // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); leesCSV(file.getAbsolutePath()); } hoofdPanel.repaint(); } }); spelermenu.add(item); */ menubar.add(spelermenu); JMenu deelnemersmenu = new JMenu("Deelnemers"); item = new JMenuItem("Wis Deelnemerslijst"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser wisDeelnemers(); hoofdPanel.repaint(); } }); deelnemersmenu.add(item); item = new JMenuItem("Importeren Deelnemerslijst"); item.setAccelerator(KeyStroke.getKeyStroke('I', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); leesDeelnemers(file.getAbsolutePath()); } hoofdPanel.repaint(); } }); deelnemersmenu.add(item); item = new JMenuItem("Export Deelnemerslijst (JSON)"); item.setAccelerator(KeyStroke.getKeyStroke('E', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser final JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("JSON", "json"); fc.setFileFilter(filter); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showSaveDialog(ms); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); schrijfDeelnemers(file.getAbsolutePath()); } hoofdPanel.repaint(); } }); deelnemersmenu.add(item); menubar.add(deelnemersmenu); JMenu uitslagenmenu = new JMenu("Uitslagen"); Component hs = this; item = new JMenuItem("Importeer uitslagenbestand"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(System.getProperty("user.dir"))); // In response to a button click: int returnVal = fc.showOpenDialog(hs); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + "."); status.groepenuitslagen = (GroepsUitslagen) new ExcelImport().importeerUitslagen(file); OutputUitslagen ou = new OutputUitslagen(); ou.exportuitslagen(status.groepenuitslagen); IJSCOController.t().wisUitslagen(); ou.exportJSON(status.groepenuitslagen); GroepsUitslagen verwerkteUitslag = new Uitslagverwerker() .verwerkUitslag(status.groepenuitslagen); logger.log(Level.INFO, verwerkteUitslag.ToString()); new OutputUitslagen().exporteindresultaten(verwerkteUitslag); JOptionPane.showMessageDialog(null, "Uitslagen geimporteerd en bestanden aangemaakt."); } hoofdPanel.repaint(); } }); uitslagenmenu.add(item); menubar.add(uitslagenmenu); JMenu osbomenu = new JMenu("OSBO"); item = new JMenuItem("Verstuur uitslagen handmatig."); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser SendAttachmentInEmail SAIM = new SendAttachmentInEmail(); SAIM.sendAttachement("Uitslagen.json"); hoofdPanel.repaint(); } }); osbomenu.add(item); menubar.add(osbomenu); JMenu helpmenu = new JMenu("Help"); item = new JMenuItem("Verstuur logging"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Create a file chooser SendAttachmentInEmail SAIM = new SendAttachmentInEmail(); SAIM.sendAttachement("IJSCO_UI.log"); hoofdPanel.repaint(); } }); helpmenu.add(item); item = new JMenuItem("About"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { AboutDialog ad = new AboutDialog(ms); ad.setVisible(true); hoofdPanel.repaint(); } }); helpmenu.add(item); menubar.add(helpmenu); /* JMenu indelingMenu = new JMenu("Indeling"); //item = new JMenuItem("Automatisch aan/uit"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { //actieAutomatisch(); } }); indelingMenu.add(item); //item = new JMenuItem("Maak wedstrijdgroep"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieMaakWedstrijdgroep(); } }); indelingMenu.add(item); //item = new JMenuItem("Maak speelschema"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evetn) { //actieMaakSpeelschema(); } }); indelingMenu.add(item); //item = new JMenuItem("Bewerk speelschema"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { //updateAutomatisch(false); // ResultaatDialoog //actieBewerkSchema(); } }); indelingMenu.add(item); indelingMenu.addSeparator(); //item = new JMenuItem("Export"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { //actieExport(); } }); indelingMenu.add(item); indelingMenu.addSeparator(); //item = new JMenuItem("Vul uitslagen in"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieVoerUitslagenIn(); } }); indelingMenu.add(item); //item = new JMenuItem("Externe spelers"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieExterneSpelers(); } }); indelingMenu.add(item); //item = new JMenuItem("Maak nieuwe stand"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieUpdateStand(); } }); indelingMenu.add(item); indelingMenu.addSeparator(); //item = new JMenuItem("Volgende ronde"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //actieVolgendeRonde(); } }); indelingMenu.add(item); menubar.add(indelingMenu); */ /* JMenu overigmenu = new JMenu("Overig"); //item = new JMenuItem("Reset punten"); item = new JMenuItem("N/A"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //controller.resetPunten(); hoofdPanel.repaint(); } }); overigmenu.add(item); menubar.add(overigmenu); */ this.setJMenuBar(menubar); }
From source file:nl.fontys.sofa.limo.view.project.actions.ExportChainAction.java
private void openFileChooser() throws HeadlessException, IOException { JFileChooser fc = new ChainSaveFileChooser(); FileNameExtensionFilter chainFilter = new FileNameExtensionFilter("Supply chains (*.lsc)", "lsc"); if (supplyChain.getFilepath() != null) { //This happens if a supply chain is loaded. fc.setCurrentDirectory(new File(supplyChain.getFilepath())); }/*from www.j a v a 2 s .c om*/ fc.setFileFilter(chainFilter); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setSelectedFile(new File(FilenameUtils.removeExtension(supplyChain.getName()))); // This sets the name without the extension int result = fc.showOpenDialog(null); String fileName = fc.getSelectedFile().getName(); //name with extension if (result == JFileChooser.APPROVE_OPTION) { //If folder is selected than save the supply chain. supplyChain.setName(fileName); File file = fc.getSelectedFile(); supplyChain.saveToFile(file.getAbsolutePath() + ".lsc"); } else { //If no folder is selected throw an exception so the saving process is cancelled. throw new IOException("The supply chain " + supplyChain.getName() + " is invalid."); } }
From source file:no.java.swing.SingleSelectionFileDialog.java
private Result showJFileChooser(Component target, boolean open) { JFileChooser chooser = new JFileChooser(previousDirectory); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(filter); chooser.setAcceptAllFileFilterUsed(filter == null); chooser.setDialogType(open ? JFileChooser.OPEN_DIALOG : JFileChooser.SAVE_DIALOG); int selection = chooser.showDialog(target, null); switch (selection) { case JFileChooser.APPROVE_OPTION: this.selected = chooser.getSelectedFile(); if (rememberPreviousLocation) { previousDirectory = chooser.getCurrentDirectory(); }/* w ww . j a v a 2 s . com*/ return Result.APPROVE; case JFileChooser.CANCEL_OPTION: case JFileChooser.ERROR_OPTION: default: this.selected = null; return Result.ERROR; } }
From source file:nubisave.component.graph.splitteradaption.NubisaveEditor.java
/** * create an instance of a simple graph with popup controls to * create a graph./*from w w w. j a v a 2s .c om*/ * */ public NubisaveEditor() { // create a simple graph for the demo graph = new SortedSparseMultiGraph<NubiSaveVertex, NubiSaveEdge>(); this.layout = new StaticLayout<NubiSaveVertex, NubiSaveEdge>(graph, new Dimension(600, 600)); vv = new VisualizationViewer<NubiSaveVertex, NubiSaveEdge>(layout); dataVertexEdgeFactory = new DataVertexEdgeFactory(); storage_directory = new PropertiesUtil("nubi.properties").getProperty("storage_configuration_directory"); //Immediate Adaption to external changes int mask = JNotify.FILE_CREATED | JNotify.FILE_DELETED | JNotify.FILE_MODIFIED | JNotify.FILE_RENAMED; boolean watchSubtree = false; // try { // JNotify.addWatch(Nubisave.mainSplitter.getConfigDir(), mask, watchSubtree, new JNotifyConfigUpdater(dataVertexEdgeFactory, graph, vv)); // } catch (Exception ex) { // Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex); // } vv.setBackground(Color.white); vv.getRenderContext().setEdgeStrokeTransformer(new EdgeWeightStrokeFunction<NubiSaveEdge>()); vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<NubiSaveEdge>()); vv.getRenderContext() .setVertexShapeTransformer(new BufferedImageDelegatorVertexShapeTransformer<NubiSaveVertex>()); vv.getRenderContext() .setVertexIconTransformer(new BufferedImageDelegatorVertexIconTransformer<NubiSaveVertex>()); vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv.getRenderContext().setVertexLabelTransformer(new GenericComponentLabeller<NubiSaveVertex>()); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<NubiSaveVertex, NubiSaveEdge>()); new BufferedImageDelegatorHighlighter(vv.getPickedVertexState()); Container content = this; final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final StatefulNubiSaveComponentFactory vertexFactory = new StatefulNubiSaveComponentFactory(); Factory<? extends NubiSaveEdge> edgeFactory = new WeightedNubisaveVertexEdgeFactory(); final PluggableGraphMouse graphMouse = createPluggableGraphMouse(vv.getRenderContext(), vertexFactory, edgeFactory, dataVertexEdgeFactory); // try { // // the EditingGraphMouse will pass mouse event coordinates to the // // vertexLocations function to set the locations of the vertices as // // they are created //graphMouse.setVertexLocations(vertexLocations); // nubiSaveComponent = new NubiSaveComponent(); // nubiSaveComponent.addToGraph(vv, new java.awt.Point((int)layout.getSize().getHeight()/2,(int)layout.getSize().getWidth()/2)); // } catch (IOException ex) { // Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex); // } vv.setGraphMouse(graphMouse); vv.addKeyListener(new ActionKeyAdapter(vv.getPickedVertexState(), graph)); JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(vv, instructions); } }); addServicesToGraph(); Graph<AbstractNubisaveComponent, Object> nubisaveComponentGraph = new VertexPredicateFilter( new Predicate() { @Override public boolean evaluate(Object vertex) { return vertex instanceof AbstractNubisaveComponent; } }).transform(graph); interconnectNubisaveComponents(nubisaveComponentGraph, edgeFactory); //interconnectNubisaveComponents(); JPanel controls = new JPanel(); JButton chooseLocalComponent = new JButton("Custom Storage/Modification/Splitter Module"); chooseLocalComponent.addActionListener(new ActionListener() { /** * Create new {@link StorageService} from chosen file and set it as the next Vertex to create in {@link StatefulNubiSaveComponentFactory} */ @Override public void actionPerformed(ActionEvent ae) { CustomServiceDlg cusDlg = new CustomServiceDlg(); cusDlg.pack(); cusDlg.setLocationRelativeTo(null); cusDlg.setTitle("Module Selection"); cusDlg.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); cusDlg.setVisible(true); String module = (String) cusDlg.getItemName(); if (module != null) { module = module.split("\\.")[0]; } if (module != null) { if (cusDlg.okstatus == "True") { if (module.toLowerCase().equals("nubisave")) { StorageService newService = new StorageService(module); try { vertexFactory.setNextInstance(new NubiSaveComponent(newService)); //nubiSaveComponent.addToGraph(vv, new java.awt.Point((int)layout.getSize().getHeight()/2,(int)layout.getSize().getWidth()/2)); } catch (IOException ex) { Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex); } nubisave.Nubisave.services.addNubisave(newService); } else { StorageService newService = new StorageService(module); try { vertexFactory.setNextInstance(new GenericNubiSaveComponent(newService)); } catch (IOException ex) { Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex); } nubisave.Nubisave.services.add(newService); } } } else { JFileChooser customStorageserviceChooser = new javax.swing.JFileChooser(); customStorageserviceChooser.setCurrentDirectory( new java.io.File(nubisave.Nubisave.mainSplitter.getMountScriptDir())); customStorageserviceChooser.setDialogTitle("Custom Service"); customStorageserviceChooser.setFileFilter(new IniFileFilter()); int returnVal = customStorageserviceChooser.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = customStorageserviceChooser.getSelectedFile(); if (file.getName().toLowerCase().equals("nubisave.ini")) { StorageService newService = new StorageService(file); try { vertexFactory.setNextInstance(new NubiSaveComponent(newService)); //nubiSaveComponent.addToGraph(vv, new java.awt.Point((int)layout.getSize().getHeight()/2,(int)layout.getSize().getWidth()/2)); } catch (IOException ex) { Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex); } nubisave.Nubisave.services.addNubisave(newService); } else { StorageService newService = new StorageService(file); try { vertexFactory.setNextInstance(new GenericNubiSaveComponent(newService)); } catch (IOException ex) { Logger.getLogger(NubisaveEditor.class.getName()).log(Level.SEVERE, null, ex); } nubisave.Nubisave.services.add(newService); } } } } }); controls.add(chooseLocalComponent); JButton searchServiceComponent = new JButton("Storage Service Directory"); searchServiceComponent.addActionListener(new ActionListener() { /** * Create new {@link StorageService} from chosen file and set it as the next Vertex to create in {@link StatefulNubiSaveComponentFactory} */ @Override public void actionPerformed(ActionEvent ae) { AddServiceDialog addServiceDlg = new AddServiceDialog(null, true); addServiceDlg.setVisible(true); for (MatchmakerService newService : addServiceDlg.getSelectedServices()) { try { vertexFactory.setNextInstance(new GenericNubiSaveComponent(newService)); } catch (IOException ex) { Logger.getLogger(AddServiceDialog.class.getName()).log(Level.SEVERE, null, ex); } } } }); controls.add(searchServiceComponent); controls.add(help); content.add(controls, BorderLayout.SOUTH); }
From source file:nz.ac.massey.cs.gql4jung.browser.ResultBrowser.java
private void actExport2CSV() { JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(this); FileFilter filter = new FileFilter() { @Override// w ww . java 2 s .c o m public boolean accept(File f) { return f.getAbsolutePath().endsWith(".csv"); } @Override public String getDescription() { return "csv files"; } }; fc.setFileFilter(filter); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); QueryResultsExporter2CSV exporter = new QueryResultsExporter2CSV(); try { exporter.export(this.results, file); log("results exported to " + file.getAbsolutePath()); JOptionPane.showMessageDialog(this, "Results have been exported to\n" + file.getAbsolutePath()); } catch (IOException x) { this.handleException("Error exporting file", x); } } }
From source file:nz.ac.massey.cs.gql4jung.browser.ResultBrowser.java
private void actLoadQuery() { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(".")); fc.setDialogTitle("Load query"); int returnVal = fc.showOpenDialog(this); FileFilter filter = new FileFilter() { @Override//from w ww . j av a2 s .co m public boolean accept(File f) { return f.getAbsolutePath().endsWith(".xml"); } @Override public String getDescription() { return "xml"; } }; fc.setFileFilter(filter); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); loadQuery(file); } updateActions(); updateStatus(); }
From source file:nz.ac.massey.cs.gql4jung.browser.ResultBrowser.java
private void actLoadData() { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(".")); fc.setDialogTitle("Load graph"); int returnVal = fc.showOpenDialog(this); FileFilter filter = new FileFilter() { @Override//from w w w . j a v a 2 s . c om public boolean accept(File f) { return f.getAbsolutePath().endsWith(".graphml"); } @Override public String getDescription() { return "graphml files"; } }; fc.setFileFilter(filter); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); loadData(file); } updateActions(); updateStatus(); }
From source file:openlr.mapviewer.coding.ui.LoadConfigButtonListener.java
@Override public void actionPerformed(final ActionEvent e) { JFileChooser chooser = fileChooserFactory.createFileChooser(FILE_CHOOSER_TOPIC_CODING_PROPERTIES); chooser.setFileFilter(new XmlOrPropertiesFileFilter()); String codingTypeString = codeOptionsDialog.getCodingType().name().toLowerCase(); chooser.setDialogTitle("Select " + codingTypeString + " properties file"); int re = chooser.showOpenDialog(null); if (re == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try {//from ww w .ja v a2s .c o m FileConfiguration config = OpenLRPropertiesReader.loadPropertiesFromFile(file); this.codeOptionsDialog.setValues(config); } catch (OpenLRPropertyException e1) { WrappedLabelLookAlikeTextArea mapNameArea = new WrappedLabelLookAlikeTextArea(1, NR_COLUMNS_ERROR_TEXT_FIELD); mapNameArea.setText("Error reading the " + codingTypeString + " properties! " + e1); mapNameArea.setPreferredSize(PREFERRED_SIZE_ERROR_TEXT_FIELD); JOptionPane.showMessageDialog(null, mapNameArea, "Properties error", JOptionPane.ERROR_MESSAGE); } } }
From source file:openqcm.mainGUI.java
private void saveFileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveFileBtnActionPerformed // if the button is pressed if (saveFileBtn.isSelected() == true) { saveFileBtn.setText("Stop Save"); // open a file chooser JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files", "txt", "dat"); chooser.setFileFilter(filter); int option = chooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { sf = chooser.getSelectedFile(); saveFileBtn.setText("Stop Save"); titleJTextField.setText(sf.getName() + " - QCM Data Chart"); //saveFile = true; //jFormattedTextField3.setText(sf.getName()); } else {//from w w w. ja v a 2 s .com JOptionPane.showMessageDialog(null, "No file selected", "Error", JOptionPane.ERROR_MESSAGE); saveFileBtn.setText("Save File"); saveFileBtn.setSelected(false); titleJTextField.setText("QCM Data Chart"); } } // if the button is released else if (saveFileBtn.isSelected() == false) { saveFileBtn.setText("Save File"); titleJTextField.setText("QCM Data Chart"); } }