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:org.f2o.absurdum.puck.gui.PuckFrame.java
/** * "Save As..." functionality//from w w w . j a v a2s . c o m */ public boolean saveAs() throws Exception { JFileChooser jfc = new JFileChooser("."); FiltroFicheroMundo filter = new FiltroFicheroMundo(); jfc.setFileFilter(filter); int opt = jfc.showSaveDialog(PuckFrame.this); if (opt == JFileChooser.APPROVE_OPTION) { File f = jfc.getSelectedFile(); if (jfc.getFileFilter() == filter && !filter.acceptFilename(f)) { String fileName = f.getAbsolutePath(); fileName += ".agw"; f = new File(fileName); } saveToFile(f); editingFileName = f.toString(); refreshTitle(); addRecentFile(f); return true; } else return false; }
From source file:org.f2o.absurdum.puck.gui.PuckFrame.java
/** * Instances and shows Puck's main frame. */// w w w . ja va 2 s. c o m public PuckFrame() { super(); setLookAndFeel(PuckConfiguration.getInstance().getProperty("look")); /* LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels(); for ( int i = 0 ; i < lfs.length ; i++ ) { if ( lfs[i].getName().toLowerCase().contains("nimbus") ) { try { UIManager.setLookAndFeel(lfs[i].getClassName()); } catch (Exception e) //class not found, instantiation exception, etc. (shouldn't happen) { e.printStackTrace(); } } } */ setSize(PuckConfiguration.getInstance().getIntegerProperty("windowWidth"), PuckConfiguration.getInstance().getIntegerProperty("windowHeight")); setLocation(PuckConfiguration.getInstance().getIntegerProperty("windowLocationX"), PuckConfiguration.getInstance().getIntegerProperty("windowLocationY")); //setSize(600,600); if (PuckConfiguration.getInstance().getBooleanProperty("windowMaximized")) maximizeIfPossible(); //setTitle(Messages.getInstance().getMessage("frame.title")); refreshTitle(); left = new JPanel(); right = new JPanel(); JScrollPane rightScroll = new JScrollPane(right); rightScroll.getVerticalScrollBar().setUnitIncrement(16); //faster scrollbar (by default it was very slow, maybe because component inside is not text component!) split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, rightScroll) { //dynamic resizing of right panel /* public void setDividerLocation ( int pixels ) { if ( propPanel != null ) { double rightPartSize = getContentPane().getWidth() - pixels - 15; System.out.println("rps=" + rightPartSize); System.out.println("mnw=" + this.getMinimumSize().getWidth()); Dimension propPanSize = propPanel.getSize(); int propPanHeight = 0; if (propPanSize != null) propPanHeight = (int) propPanSize.getHeight(); //propPanel.revalidate(); System.out.println("h " + propPanHeight); //if ( rightPartSize >= propPanel.getMinimumSize().getWidth() ) propPanel.setPreferredSize(new Dimension((int)rightPartSize,propPanHeight)); //propPanel.setMinimumSize(new Dimension((int)rightPartSize,propPanHeight)); //propPanel.setMaximumSize(new Dimension((int)rightPartSize,propPanHeight)); //propPanel.setSize(new Dimension((int)rightPartSize,propPanHeight)); propPanel.revalidate(); } super.setDividerLocation(pixels); } */ }; split.setContinuousLayout(true); split.setResizeWeight(0.60); final int dividerLoc = PuckConfiguration.getInstance().getIntegerProperty("dividerLocation", 0); /* SwingUtilities.invokeLater(new Runnable(){ public void run() { */ /* } }); */ split.setOneTouchExpandable(true); getContentPane().add(split); System.out.println(Toolkit.getDefaultToolkit().getBestCursorSize(20, 20)); //it's 32x32. Will have to do it. //Image img = Toolkit.getDefaultToolkit().createImage( getClass().getResource("addCursor32.png") ); //Image img = Toolkit.getDefaultToolkit().createImage("addCursor32.png"); left.setLayout(new BorderLayout()); //right.setLayout(new BoxLayout(right,BoxLayout.LINE_AXIS)); if (PuckConfiguration.getInstance().getBooleanProperty("dynamicFormResizing")) right.setLayout(new BorderLayout()); else right.setLayout(new FlowLayout()); propPanel = new PropertiesPanel(); right.add(propPanel); graphPanel = new GraphEditingPanel(propPanel); graphPanel.setGrid(Boolean.valueOf(PuckConfiguration.getInstance().getProperty("showGrid")).booleanValue()); graphPanel.setSnapToGrid( Boolean.valueOf(PuckConfiguration.getInstance().getProperty("snapToGrid")).booleanValue()); propPanel.setGraphEditingPanel(graphPanel); tools = new PuckToolBar(graphPanel, propPanel, this); left.add(tools, BorderLayout.WEST); left.add(graphPanel, BorderLayout.CENTER); /* Action testAction = new AbstractAction() { public void actionPerformed ( ActionEvent evt ) { System.out.println("Puck!"); } } ; testAction.putValue(Action.NAME,"Print Puck"); tools.add(testAction); */ /* public void saveChanges ( ) { if ( editingFileName == null ) { //save as... code } else { File f = new File(editingFileName); try { Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d)); Transformer t = TransformerFactory.newInstance().newTransformer(); Source s = new DOMSource(d); Result r = new StreamResult(f); t.transform(s,r); editingFileName = f.toString(); refreshTitle(); } catch ( Exception e ) { JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } } */ JMenuBar mainMenuBar = new JMenuBar(); JMenu fileMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file")); fileMenu.setMnemonic(KeyEvent.VK_F); saveMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.save")); saveMenuItem.setMnemonic(KeyEvent.VK_S); saveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (editingFileName == null) JOptionPane.showMessageDialog(PuckFrame.this, "File has no name!", "Whoops!", JOptionPane.ERROR_MESSAGE); /* File f = new File(editingFileName); try { Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d)); Transformer t = TransformerFactory.newInstance().newTransformer(); Source s = new DOMSource(d); Result r = new StreamResult(f); t.transform(s,r); editingFileName = f.toString(); refreshTitle(); } catch ( Exception e ) { JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } */ try { saveChangesInCurrentFile(); } catch (Exception e) { JOptionPane.showMessageDialog(PuckFrame.this, e.getLocalizedMessage(), "Whoops!", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } }); JMenu newMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.new")); JMenuItem newBlankMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.new.blank")); //newBlankMenuItem.setMnemonic(KeyEvent.VK_N); newBlankMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { GraphElementPanel.emptyQueue(); //stop deferred loads graphPanel.clear(); propPanel.clear(); JSyntaxBSHCodeFrame.closeAllInstances(); WorldPanel wp = new WorldPanel(graphPanel); WorldNode wn = new WorldNode(wp); graphPanel.setWorldNode(wn); propPanel.show(graphPanel.getWorldNode()); resetCurrentlyEditingFile(); refreshTitle(); //revalidate(); //only since java 1.7 //invalidate(); //validate(); split.revalidate(); //JComponents do have it before java 1.7 (not JFrame) } }); newMenu.add(newBlankMenuItem); JMenu templateMenus = new WorldTemplateMenuBuilder(this).getMenu(); if (templateMenus != null) { for (int i = 0; i < templateMenus.getItemCount(); i++) { if (i == 0) newMenu.add(new JSeparator()); newMenu.add(templateMenus.getItem(i)); } } JMenuItem saveAsMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.saveas")); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { /* JFileChooser jfc = new JFileChooser("."); int opt = jfc.showSaveDialog(PuckFrame.this); if ( opt == JFileChooser.APPROVE_OPTION ) { File f = jfc.getSelectedFile(); try { Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d)); Transformer t = TransformerFactory.newInstance().newTransformer(); Source s = new DOMSource(d); Result r = new StreamResult(f); t.transform(s,r); editingFileName = f.toString(); saveMenuItem.setEnabled(true); refreshTitle(); } catch ( Exception e ) { JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } */ try { saveAs(); saveMenuItem.setEnabled(true); } catch (Exception e) { JOptionPane.showMessageDialog(PuckFrame.this, e.getLocalizedMessage(), "Whoops!", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } //saveAs(saveMenuItem); } }); JMenuItem openMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.open")); openMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { //graphPanel.setVisible(false); //propPanel.setVisible(false); JFileChooser jfc = new JFileChooser("."); jfc.setFileFilter(new FiltroFicheroMundo()); int opt = jfc.showOpenDialog(PuckFrame.this); if (opt == JFileChooser.APPROVE_OPTION) { File f = jfc.getSelectedFile(); openFileOrShowError(f); } //graphPanel.setVisible(true); //propPanel.setVisible(true); } }); openRecentMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.recent")); JMenuItem exitMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.exit")); exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { /* int opt = JOptionPane.showConfirmDialog(PuckFrame.this,Messages.getInstance().getMessage("exit.sure.text"),Messages.getInstance().getMessage("exit.sure.title"),JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE); if ( opt == JOptionPane.YES_OPTION ) System.exit(0); */ userExit(); } }); JMenu exportMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.export")); JMenuItem exportAppletMenuItem = new JMenuItem( UIMessages.getInstance().getMessage("menu.file.export.applet")); exportAppletMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { ExportAppletDialog dial = new ExportAppletDialog(PuckFrame.this); dial.setVisible(true); } }); exportMenu.add(exportAppletMenuItem); fileMenu.add(newMenu); fileMenu.add(openMenuItem); fileMenu.add(openRecentMenu); updateRecentMenu(); fileMenu.add(new JSeparator()); saveMenuItem.setEnabled(false); fileMenu.add(saveMenuItem); fileMenu.add(saveAsMenuItem); fileMenu.add(exportMenu); fileMenu.add(new JSeparator()); fileMenu.add(exitMenuItem); mainMenuBar.add(fileMenu); /** * Create an Edit menu to support cut/copy/paste. */ JMenu editMenu = new JMenu(UIMessages.getInstance().getMessage("menu.edit")); editMenu.setMnemonic(KeyEvent.VK_E); JMenuItem findMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.find.entity")); findMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showFindEntityDialog(); } }); editMenu.add(findMenuItem); editMenu.add(new JSeparator()); JMenuItem aMenuItem = new JMenuItem(new CutAction()); aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.cut")); aMenuItem.setMnemonic(KeyEvent.VK_T); editMenu.add(aMenuItem); aMenuItem = new JMenuItem(new CopyAction()); aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.copy")); aMenuItem.setMnemonic(KeyEvent.VK_C); editMenu.add(aMenuItem); aMenuItem = new JMenuItem(new PasteAction()); aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.paste")); aMenuItem.setMnemonic(KeyEvent.VK_P); editMenu.add(aMenuItem); mainMenuBar.add(editMenu); JMenu optionsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options")); JMenu gridMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options.grid")); optionsMenu.add(gridMenu); final JCheckBoxMenuItem showGridItem = new JCheckBoxMenuItem( UIMessages.getInstance().getMessage("menu.options.grid.show")); showGridItem.setSelected( Boolean.valueOf(PuckConfiguration.getInstance().getProperty("showGrid")).booleanValue()); gridMenu.add(showGridItem); showGridItem.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { graphPanel.setGrid(true); PuckConfiguration.getInstance().setProperty("showGrid", "true"); } else if (e.getStateChange() == ItemEvent.DESELECTED) { graphPanel.setGrid(false); PuckConfiguration.getInstance().setProperty("showGrid", "false"); } graphPanel.repaint(); } }); final JCheckBoxMenuItem snapToGridItem = new JCheckBoxMenuItem( UIMessages.getInstance().getMessage("menu.options.grid.snap")); snapToGridItem.setSelected( Boolean.valueOf(PuckConfiguration.getInstance().getProperty("snapToGrid")).booleanValue()); gridMenu.add(snapToGridItem); snapToGridItem.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { graphPanel.setSnapToGrid(true); PuckConfiguration.getInstance().setProperty("snapToGrid", "true"); } else if (e.getStateChange() == ItemEvent.DESELECTED) { graphPanel.setSnapToGrid(false); PuckConfiguration.getInstance().setProperty("snapToGrid", "false"); } graphPanel.repaint(); } }); JMenuItem translationModeMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options.translation")); ButtonGroup translationGroup = new ButtonGroup(); final JRadioButtonMenuItem holdMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.options.translation.hold")); final JRadioButtonMenuItem pushMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.options.translation.push")); pushMenuItem.setSelected("push".equals(PuckConfiguration.getInstance().getProperty("translateMode"))); if (!pushMenuItem.isSelected()) holdMenuItem.setSelected(true); translationGroup.add(holdMenuItem); translationGroup.add(pushMenuItem); holdMenuItem.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent arg0) { if (holdMenuItem.isSelected()) PuckConfiguration.getInstance().setProperty("translateMode", "hold"); else PuckConfiguration.getInstance().setProperty("translateMode", "push"); } }); translationModeMenu.add(holdMenuItem); translationModeMenu.add(pushMenuItem); optionsMenu.add(translationModeMenu); JMenuItem toolSelectionModeMenu = new JMenu( UIMessages.getInstance().getMessage("menu.options.toolselection")); ButtonGroup toolSelectionGroup = new ButtonGroup(); final JRadioButtonMenuItem oneUseMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.options.toolselection.oneuse")); final JRadioButtonMenuItem multipleUseMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.options.toolselection.multipleuse")); multipleUseMenuItem.setSelected( "multipleUse".equalsIgnoreCase(PuckConfiguration.getInstance().getProperty("toolSelectionMode"))); if (!multipleUseMenuItem.isSelected()) oneUseMenuItem.setSelected(true); toolSelectionGroup.add(oneUseMenuItem); toolSelectionGroup.add(multipleUseMenuItem); oneUseMenuItem.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent arg0) { if (oneUseMenuItem.isSelected()) PuckConfiguration.getInstance().setProperty("toolSelectionMode", "oneUse"); else PuckConfiguration.getInstance().setProperty("toolSelectionMode", "multipleUse"); } }); toolSelectionModeMenu.add(oneUseMenuItem); toolSelectionModeMenu.add(multipleUseMenuItem); optionsMenu.add(toolSelectionModeMenu); JMenuItem sizesMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.iconsizes")); sizesMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { IconSizesDialog dial = new IconSizesDialog(PuckFrame.this, true); dial.setVisible(true); } }); optionsMenu.add(sizesMenuItem); JMenuItem showHideMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.showhide")); showHideMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ShowHideDialog dial = new ShowHideDialog(PuckFrame.this, true); dial.setVisible(true); } }); optionsMenu.add(showHideMenuItem); JMenuItem mapColorsMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.mapcolors")); mapColorsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MapColorsDialog dial = new MapColorsDialog(PuckFrame.this, true); dial.setVisible(true); } }); optionsMenu.add(mapColorsMenuItem); String skinList = PuckConfiguration.getInstance().getProperty("availableSkins"); if (skinList != null && skinList.trim().length() > 0) { JMenu skinsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.skins")); StringTokenizer st = new StringTokenizer(skinList, ", "); ButtonGroup skinButtons = new ButtonGroup(); while (st.hasMoreTokens()) { final String nextSkin = st.nextToken(); final JRadioButtonMenuItem skinMenuItem = new JRadioButtonMenuItem(nextSkin); skinMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setSkin(nextSkin); skinMenuItem.setSelected(true); } }); if (nextSkin.equals(PuckConfiguration.getInstance().getProperty("skin"))) skinMenuItem.setSelected(true); skinsMenu.add(skinMenuItem); skinButtons.add(skinMenuItem); } optionsMenu.add(skinsMenu); } JMenu lookFeelMenu = new JMenu(UIMessages.getInstance().getMessage("menu.looks")); ButtonGroup lookButtons = new ButtonGroup(); final JRadioButtonMenuItem defaultLookMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.looks.default")); if ("default".equals(PuckConfiguration.getInstance().getProperty("look"))) { defaultLookMenuItem.setSelected(true); } lookFeelMenu.add(defaultLookMenuItem); lookButtons.add(defaultLookMenuItem); defaultLookMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLookAndFeel("default"); defaultLookMenuItem.setSelected(true); } }); final JRadioButtonMenuItem systemLookMenuItem = new JRadioButtonMenuItem( UIMessages.getInstance().getMessage("menu.looks.system")); if ("system".equals(PuckConfiguration.getInstance().getProperty("look"))) { systemLookMenuItem.setSelected(true); } lookFeelMenu.add(systemLookMenuItem); lookButtons.add(systemLookMenuItem); systemLookMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLookAndFeel("system"); systemLookMenuItem.setSelected(true); } }); String additionalLookList = PuckConfiguration.getInstance().getProperty("additionalLooks"); if (additionalLookList != null && additionalLookList.trim().length() > 0) { StringTokenizer st = new StringTokenizer(additionalLookList, ", "); while (st.hasMoreTokens()) { final String nextLook = st.nextToken(); final JRadioButtonMenuItem lookMenuItem = new JRadioButtonMenuItem(nextLook); lookMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLookAndFeel(nextLook); lookMenuItem.setSelected(true); } }); if (nextLook.equals(PuckConfiguration.getInstance().getProperty("look"))) { lookMenuItem.setSelected(true); } lookFeelMenu.add(lookMenuItem); lookButtons.add(lookMenuItem); } } optionsMenu.add(lookFeelMenu); optionsMenu.add(new UILanguageSelectionMenu(this)); mainMenuBar.add(optionsMenu); JMenu toolsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.tools")); final JMenuItem verbListMenuItem = new JMenuItem( UIMessages.getInstance().getMessage("menu.tools.verblist")); verbListMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { WorldPanel wp = (WorldPanel) graphPanel.getWorldNode().getAssociatedPanel(); VerbListFrame vlf = VerbListFrame.getInstance(wp.getSelectedLanguageCode()); vlf.setVisible(true); } }); toolsMenu.add(verbListMenuItem); final JMenuItem validateMenuItem = new JMenuItem( UIMessages.getInstance().getMessage("menu.tools.validatebsh")); validateMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { BeanShellCodeValidator bscv = new BeanShellCodeValidator(graphPanel); if (!bscv.validate()) { BeanShellErrorsDialog bsed = new BeanShellErrorsDialog(PuckFrame.this, bscv.getErrorText()); bsed.setVisible(true); //JOptionPane.showMessageDialog(PuckFrame.this, bscv.getErrorText()); } else { JOptionPane.showMessageDialog(PuckFrame.this, UIMessages.getInstance().getMessage("bsh.code.ok"), "OK!", JOptionPane.INFORMATION_MESSAGE); //JOptionPane.showMessageDialog(PuckFrame.this, bscv.getErrorText()); } } }); toolsMenu.add(validateMenuItem); mainMenuBar.add(toolsMenu); JMenu helpMenu = new JMenu(UIMessages.getInstance().getMessage("menu.help")); //JHelpAction.startHelpWorker("help/PUCKHelp.hs"); //JHelpAction helpTocAction = JHelpAction.getShowHelpInstance(Messages.getInstance().getMessage("menu.help.toc")); //JHelpAction helpContextSensitiveAction = JHelpAction.getTrackInstance(Messages.getInstance().getMessage("menu.help.context")); //final JMenuItem helpTocMenuItem = new JMenuItem(helpTocAction); //final JMenuItem helpContextSensitiveMenuItem = new JMenuItem(helpContextSensitiveAction); //helpMenu.add(helpTocMenuItem); //helpMenu.add(helpContextSensitiveMenuItem); final JMenuItem helpMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.help.toc")); helpMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DocumentationLinkDialog dial = new DocumentationLinkDialog(PuckFrame.this, true); dial.setVisible(true); } }); helpMenu.add(helpMenuItem); mainMenuBar.add(helpMenu); MenuMnemonicOnTheFly.setMnemonics(mainMenuBar); this.setJMenuBar(mainMenuBar); //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { userExit(); } }); propPanel.show(graphPanel.getWorldNode()); setVisible(true); SwingUtilities.invokeLater(new Runnable() { public void run() { if (dividerLoc > 0) split.setDividerLocation(dividerLoc); else split.setDividerLocation(0.60); } }); }
From source file:org.fhaes.analysis.FHInterval.java
/** * Actually perform the analysis.//from w w w. ja va 2 s .c o m */ @SuppressWarnings("deprecation") private void doAnalysis() { log.debug("INPUT PARAMETERS"); log.debug("inputFileArray = " + inputFileArray); log.debug("analyissType = " + analysisType); log.debug("startYear = " + startYear); log.debug("endYear = " + endYear); log.debug("fireFilterType = " + fireFilterType); log.debug("filterValue = " + filterValue); log.debug("includeIncomplete = " + includeIncomplete); log.debug("alphaLevel = " + alphaLevel); boolean highway = true; ArrayList<FHX2FileReader> myReader = new ArrayList<FHX2FileReader>(); Integer minFirstYear = new Integer(9999); Integer maxLastYear = new Integer(0); String savePath = new String(); savePath = inputFileArray[0].getAbsolutePath(); for (int i = 0; i < inputFileArray.length; i++) { myReader.add(new FHX2FileReader(inputFileArray[i])); /* * set the beginning year accounting for the filter */ if (eventTypeToProcess.equals(EventTypeToProcess.FIRE_EVENT)) { // myReader.get(i).makeClimate2d(); if (startYear == 0 && highway) { if (myReader.get(i).getFirstFireYear() < minFirstYear) { minFirstYear = myReader.get(i).getFirstFireYear(); } } else if (startYear != 0 && highway) { if (myReader.get(i).getFirstYear() < minFirstYear) { minFirstYear = myReader.get(i).getFirstYear(); } } if (startYear != 0) { minFirstYear = startYear; // minFirstYear = minFirstYear+1; } } else if (eventTypeToProcess.equals(EventTypeToProcess.INJURY_EVENT)) { // myReader.get(i).makeClimate2dII(); if (startYear == 0 && highway) { if (myReader.get(i).getFirstInjuryYear() < minFirstYear) { minFirstYear = myReader.get(i).getFirstInjuryYear(); } } else if (startYear != 0 && highway) { if (myReader.get(i).getFirstYear() < minFirstYear) { minFirstYear = myReader.get(i).getFirstYear(); } } if (startYear != 0) { minFirstYear = startYear; // minFirstYear = minFirstYear+1; } } else if (eventTypeToProcess.equals(EventTypeToProcess.FIRE_AND_INJURY_EVENT)) { // myReader.get(i).makeClimate2dII(); if (startYear == 0 && highway) { if (myReader.get(i).getFirstIndicatorYear() < minFirstYear) { minFirstYear = myReader.get(i).getFirstIndicatorYear(); } } else if (startYear != 0 && highway) { if (myReader.get(i).getFirstYear() < minFirstYear) { minFirstYear = myReader.get(i).getFirstYear(); } } if (startYear != 0) { minFirstYear = startYear; // minFirstYear = minFirstYear+1; } } else { log.error("Unsupported event type caught"); } /* * Set the last year accounting for the filter */ if (myReader.get(i).getLastYear() > maxLastYear) { maxLastYear = myReader.get(i).getLastYear(); } if (endYear != 0) { maxLastYear = endYear; } } // end of i loop log.debug("the input filelength is " + inputFileArray.length); log.debug("The FIRST FIRE YEAR is " + minFirstYear); log.debug("The LAST YEAR is " + maxLastYear); log.debug("Minimum and Maximum years are " + minFirstYear + " " + maxLastYear); /* * set the format for the output of the numbers to 2 decimal formats */ DecimalFormat twoPlace = new DecimalFormat("0.00"); DecimalFormat threePlace = new DecimalFormat("0.000"); /* * Calculate the listYears the common years where the files will be analyzed */ ArrayList<Integer> listYears = new ArrayList<Integer>(); for (int i = 0; i < maxLastYear - minFirstYear + 1; i++) { listYears.add(minFirstYear + i); } /* * create arraylist need for the Interval Analysis */ ArrayList<ArrayList<Integer>> climateMatrixSite = new ArrayList<ArrayList<Integer>>(); ArrayList<ArrayList<Double>> filterMatrix = new ArrayList<ArrayList<Double>>(); ArrayList<Integer> climateVector = new ArrayList<Integer>(); ArrayList<ArrayList<Double>> climateVectorFilter2 = new ArrayList<ArrayList<Double>>(); // ArrayList<Double> fireintervalspersite = new ArrayList<Double>(); ArrayList<Integer> climateVectorActualSite = null; ArrayList<Double> filterVectorActual = null; ArrayList<Integer> climateYear = new ArrayList<Integer>(); ArrayList<Integer> minSampleFilter = null; ArrayList<Double> percentOfRecordingfilter = null; Double[] Dfireintervalspersite; double[] dfireintervalspersite; String[] statsparam = new String[22]; if (eventTypeToProcess.equals(EventTypeToProcess.FIRE_EVENT)) { statsparam[0] = "Total intervals"; statsparam[1] = "Mean fire interval"; statsparam[2] = "Median fire interval"; statsparam[3] = "Standard deviation"; statsparam[4] = "Fire frequency"; statsparam[5] = "Coefficient of variation"; statsparam[6] = "Skewness"; statsparam[7] = "Kurtosis"; statsparam[8] = "Minimum fire interval"; statsparam[9] = "Maximum fire interval"; statsparam[10] = "Weibull scale parameter"; statsparam[11] = "Weibull shape parameter"; statsparam[12] = "Weibull mean"; statsparam[13] = "Weibull median"; statsparam[14] = "Weibull mode"; statsparam[15] = "Weibull standard deviation"; statsparam[16] = "Weibull fire frequency"; statsparam[17] = "Weibull skewness"; statsparam[18] = "Lower exceedance interval"; statsparam[19] = "Upper exceedance interval"; statsparam[20] = "Significantly short interval upper bound"; statsparam[21] = "Significantly long interval lower bound"; } else if (eventTypeToProcess.equals(EventTypeToProcess.INJURY_EVENT)) { statsparam[0] = "Total intervals"; statsparam[1] = "Mean indicator interval"; statsparam[2] = "Median indicator interval"; statsparam[3] = "Standard deviation"; statsparam[4] = "Indicator frequency"; statsparam[5] = "Coefficient of variation"; statsparam[6] = "Skewness"; statsparam[7] = "Kurtosis"; statsparam[8] = "Minimum fire interval"; statsparam[9] = "Maximum indicator interval"; statsparam[10] = "Weibull scale parameter"; statsparam[11] = "Weibull shape parameter"; statsparam[12] = "Weibull mean"; statsparam[13] = "Weibull median"; statsparam[14] = "Weibull mode"; statsparam[15] = "Weibull standard deviation"; statsparam[16] = "Weibull indicator frequency"; statsparam[17] = "Weibull skewness"; statsparam[18] = "Lower exceedance interval"; statsparam[19] = "Upper exceedance interval"; statsparam[20] = "Significantly short interval upper bound"; statsparam[21] = "Significantly long interval lower bound"; } else if (eventTypeToProcess.equals(EventTypeToProcess.FIRE_AND_INJURY_EVENT)) { statsparam[0] = "Total intervals"; statsparam[1] = "Mean fire and other indicator interval"; statsparam[2] = "Median fire and other indicator interval"; statsparam[3] = "Standard deviation"; statsparam[4] = "Fire and other indicator frequency"; statsparam[5] = "Coefficient of variation"; statsparam[6] = "Skewness"; statsparam[7] = "Kurtosis"; statsparam[8] = "Minimum fire and other indicator interval"; statsparam[9] = "Maximum fire interval"; statsparam[10] = "Weibull scale parameter"; statsparam[11] = "Weibull shape parameter"; statsparam[12] = "Weibull mean"; statsparam[13] = "Weibull median"; statsparam[14] = "Weibull mode"; statsparam[15] = "Weibull standard deviation"; statsparam[16] = "Weibull indicator frequency"; statsparam[17] = "Weibull skewness"; statsparam[18] = "Lower exceedance interval"; statsparam[19] = "Upper exceedance interval"; statsparam[20] = "Significantly short interval upper bound"; statsparam[21] = "Significantly long interval lower bound"; } else { log.error("Unsupported event type caught"); } double[] fixvalt = { 0.999, 0.99, 0.975, 0.95, 0.9, 0.875, 0.8, 0.75, 0.7, 0.667, 0.5, 0.333, 0.3, 0.25, 0.2, 0.125, 0.1, 0.05, 0.025, 0.01, 0.001 }; double[][] ExceeProbcomp = new double[fixvalt.length][myReader.size()]; double[][] ExceeProbsample = new double[fixvalt.length][myReader.size()]; // log.debug("the size of statsparam is " + // statsparam.length); double[][] summaryComp = new double[statsparam.length][myReader.size()]; double[] numberOfintervalscomp = new double[myReader.size()]; // ArrayList<ArrayList<Integer>>(); // ArrayList<ArrayList<Integer>> FIyearperSample = new // ArrayList<ArrayList<Integer>>(); ArrayList<Integer> FyearperSampletemp; ArrayList<Integer> FIyearperSampletemp; // ArrayList<Double> fireintervalspersample = new double[] numberOfintervalssamp = new double[myReader.size()]; double[][] summarySample = new double[statsparam.length][myReader.size()]; Double[] Dfireintervalspersample; double[] dfireintervalspersample; /* * Set up either of the two filters two create the binary matrix on the case of composite analysis there are two possible filters: * Number of fires and percentage of scarred trees. */ Integer firesFilter1 = new Integer(0); Double firesFilter2 = new Double(0); if (fireFilterType.equals(FireFilterType.NUMBER_OF_EVENTS)) { if (filterValue != 1) firesFilter1 = filterValue.intValue(); // log.debug("number of fires is selected is: "+ // firesFilter1); } else if (fireFilterType.equals(FireFilterType.PERCENTAGE_OF_ALL_TREES)) { if (filterValue != 1) firesFilter2 = filterValue / 100.0; // log.debug("percentage of fires is selected is: "+ // firesFilter2); } else if (fireFilterType.equals(FireFilterType.PERCENTAGE_OF_RECORDING)) { if (filterValue != 1) firesFilter2 = filterValue / 100.0; // TODO ELENA TO CHECK } else { log.error("Unknown FireFilterType"); return; } boolean[] enoughIntComp = new boolean[myReader.size()]; boolean[] enoughIntSamp = new boolean[myReader.size()]; // NEW FOR ELENA log.debug("Sample depth filter type = " + sampleDepthFilterType); log.debug("Sample depth value = " + sampleDepthFilterValue); // if (sampleDepthFilterType.equals(SampleDepthFilterType.MIN_NUM_SAMPLES)) // { // // TODO ELENA // } // else if (sampleDepthFilterType.equals(SampleDepthFilterType.MIN_NUM_RECORDER_SAMPLES)) // { // // TODO ELENA // } /* * start processing each file individually: The analysis can be done by either tree (by sample/non-binary) or by site * (composite/binary). by tree the box selected is: jCheckTree. by site the box selected is: */ for (int i = 0; i < myReader.size(); i++) { log.debug(" Starting to Process file : " + myReader.get(i).getName()); /* * get the vector Year containing the vector of year of a given fhx file load it into the array list climateYear. */ climateYear = myReader.get(i).getYearArray(); // new stuff // Create filter based on min number of samples/recorder samples int[] depths = null; if (sampleDepthFilterType.equals(SampleDepthFilterType.MIN_NUM_SAMPLES)) { depths = myReader.get(i).getSampleDepths(); log.debug("MIN_NUM_SAMPLES "); } else if (sampleDepthFilterType.equals(SampleDepthFilterType.MIN_NUM_RECORDER_SAMPLES)) { depths = myReader.get(i).getRecordingDepths(eventTypeToProcess); log.debug(" MIN_NUM_RECORDER_SAMPLES"); } else { log.error("Unknown sample depth filter type."); return; } minSampleFilter = new ArrayList<Integer>(); for (int ij = 0; ij < listYears.size(); ij++) { if (climateYear.indexOf(listYears.get(ij)) == -1) { minSampleFilter.add(-1); } else { // log.debug("the sample depth is " // + myReader.get(i).getSampleDepths()[climateYear.indexOf(listYearsComp.get(ij))]); minSampleFilter.add(new Integer(depths[climateYear.indexOf(listYears.get(ij))])); } // log.debug(" " + minSampleFilter.get(ij)); } // end new stuff /* * get filter matrix for each file. * * filters2d matrix composed of the 3 filters number of fires (total capital letter per row) total number of tree (total lower * case letter plus bars counting only after a fire) percent of scared trees total fires/total trees */ // climateVectorFilter2 = myReader.get(i).getFilterArrays(eventTypeToProcess); /* * More new stuff */ if (filterValue != 1) { /* * get both matrices: * * 2. filters2d matrix composed of the 3 filters number of fires (total capital letter per row) total number of tree (total * lower case letter plus bars counting only after a fire) percent of scared trees total fires/total trees */ climateVectorFilter2 = myReader.get(i).getFilterArrays(eventTypeToProcess); /* * if by tree analysis is selected create two matrices (array list) 1. filterMatrix containing the three filter vectors only * in between common years (so using the listYearComp array list subset of the years vector) 2. climateMatrix 2 dimensional * array list containing binary matrices restricted to the listYear list. */ if (fireFilterType.equals(FireFilterType.PERCENTAGE_OF_RECORDING)) { percentOfRecordingfilter = new ArrayList<Double>(); for (int ij = 0; ij < listYears.size(); ij++) { if (climateYear.indexOf(listYears.get(ij)) == -1) { percentOfRecordingfilter.add(-1.0); } else { if (myReader.get(i).getRecordingDepths(eventTypeToProcess)[climateYear .indexOf(listYears.get(ij))] != 0) { percentOfRecordingfilter.add(new Double( climateVectorFilter2.get(0).get(climateYear.indexOf(listYears.get(ij))) / myReader.get(i).getRecordingDepths(eventTypeToProcess)[climateYear .indexOf(listYears.get(ij))])); } else { percentOfRecordingfilter.add(-99.0); } } log.debug("PERCENTAGE_OF_RECORDING is: " + percentOfRecordingfilter.get(ij)); } } else { for (int ik = 0; ik < 3; ik++) { log.debug("filter number is: " + ik); filterVectorActual = new ArrayList<Double>(); for (int ij = 0; ij < listYears.size(); ij++) { // log.debug(" climateYear.indexOf(listYearsComp.get(j))" + // climateYear.indexOf(listYearsComp.get(ij))); // if(ik==0){log.debug("number of fires // "+climateVectorFilter2.get(0).get(climateYear.indexOf(listYears.get(ij)))+" year // "+listYearsComp.get(ij));} if (climateYear.indexOf(listYears.get(ij)) == -1) { filterVectorActual.add(-1.0); } else { filterVectorActual.add(new Double( climateVectorFilter2.get(ik).get(climateYear.indexOf(listYears.get(ij))))); } if (ik == 2) { log.debug("filteperc " + filterVectorActual.get(ij)); } } // log.debug("size of filterVectorActual is : "+filterVectorActual.size()); filterMatrix.add(filterVectorActual); // if(ik==0){log.debug("filters is: "+filter); } } // end of if-else percentageofrecording // log.debug("size of the FilterMatrix is" + filterMatrix.size()); } // end of if filters not equal to 1 /* * end of more new stuff */ /* * * 1. Create the filterMatrix containing the tree filter vectors only in between common years (so using the listYearComp array * list subset of the years vector) */ // for (int ik = 0; ik < 3; ik++) // { // filterVectorActual = new ArrayList<Double>(); // for (int ij = 0; ij < listYears.size(); ij++) // { // if (climateYear.indexOf(listYears.get(ij)) == -1) // { // filterVectorActual.add(-1.0); // } // else // { // filterVectorActual.add(new Double(climateVectorFilter2.get(ik).get(climateYear.indexOf(listYears.get(ij))))); // } // } /* * ArrayList filterMatrix containes the filter matrix for each of the files */ // filterMatrix.add(filterVectorActual); // }//end of creating the filter matrix. /* * get matrix climate binary matrix by site (binary analysis) if Composite is selected. */ // if ((doComposite)&&(!jTextOfFires.getText().equals("1"))){ if (analysisType.equals(AnalysisType.COMPOSITE)) { log.debug("inside the comp"); // System.out.println("inside the comp " + " working on file "+ myReader.get(i).getName() ); if (eventTypeToProcess.equals(EventTypeToProcess.FIRE_EVENT)) { climateVector = myReader.get(i).getFireEventsArray(); } else if (eventTypeToProcess.equals(EventTypeToProcess.INJURY_EVENT)) { climateVector = myReader.get(i).getOtherInjuriesArray(); } else if (eventTypeToProcess.equals(EventTypeToProcess.FIRE_AND_INJURY_EVENT)) { climateVector = myReader.get(i).getFiresAndInjuriesArray(); } else { log.error("Unsupported event type caught"); } climateVectorActualSite = new ArrayList<Integer>(); for (int j = 0; j < listYears.size(); j++) { if (climateYear.indexOf(listYears.get(j)) == -1) { climateVectorActualSite.add(-1); } else { if (minSampleFilter.get(j).intValue() >= sampleDepthFilterValue.intValue()) { if (filterValue != 1) { if (fireFilterType.equals(FireFilterType.NUMBER_OF_EVENTS)) { // log.debug("fire filter: "+firesFilter1+" year is: "+listYears.get(j) // +" fires: "+filterMatrix.get(3*i).get(j)+" climatevector: // "+climateVector.get(climateYear.indexOf(listYears.get(j)))); if ((filterMatrix.get(3 * i).get(j) < firesFilter1) && (climateVector.get(climateYear.indexOf(listYears.get(j)))) != -1.0) { climateVectorActualSite.add(0); } else { climateVectorActualSite .add(climateVector.get(climateYear.indexOf(listYears.get(j)))); } } else if (fireFilterType.equals(FireFilterType.PERCENTAGE_OF_ALL_TREES)) { // log.debug("percent of fires is selected is: "+ // firesFilter2+" "+climateVector.get(climateYear.indexOf(listYearsComp.get(j)))); // log.debug("the filter percent of fires is"+filterMatrix.get((3*i+2)).get(j)); if ((filterMatrix.get(3 * i + 2).get(j) == -99)) { climateVectorActualSite.add(-1); } else { if ((filterMatrix.get(3 * i + 2).get(j) < firesFilter2) && ((climateVector .get(climateYear.indexOf(listYears.get(j)))) != -1.0)) { climateVectorActualSite.add(0); } else { climateVectorActualSite .add(climateVector.get(climateYear.indexOf(listYears.get(j)))); } } } else if (fireFilterType.equals(FireFilterType.PERCENTAGE_OF_RECORDING)) { // TODO // ELENA TO IMPLEMENT if (percentOfRecordingfilter.get(j) == -99) { climateVectorActualSite.add(-1); } else { if ((percentOfRecordingfilter.get(j) < firesFilter2) && ((climateVector .get(climateYear.indexOf(listYears.get(j)))) != -1.0)) { climateVectorActualSite.add(0); } else { climateVectorActualSite .add(climateVector.get(climateYear.indexOf(listYears.get(j)))); } } } else { log.error("Unknown FireFilterType"); return; } } // end of if filter not equal to 1 else { climateVectorActualSite .add(climateVector.get(climateYear.indexOf(listYears.get(j)))); } // end of else of if filter not equal to 1 } // end of if the filter minsampedepth else { // log.debug("j is " + j + "minSampleFilter is " + minSampleFilter.get(j)); climateVectorActualSite.add(-1); } } // end else 645 to 721 } // end of j loop listyears (420-459) /* * climateMatrixSite has the composite information taking in consideration both the filters and common years */ climateMatrixSite.add(climateVectorActualSite); /* * Must get the years with Fires from the climateMatrixSite which has been filter already */ ArrayList<Double> fireintervalspersite = new ArrayList<Double>(); ArrayList<Integer> yearsWithFires = new ArrayList<Integer>(); for (int ij = 0; ij < listYears.size(); ij++) { if (climateMatrixSite.get(i).get(ij) == 1) { yearsWithFires.add(listYears.get(ij)); log.debug("year with fires " + listYears.get(ij)); } } /* * check that the number of years with fires is bigger of equal than 3 if so make the fire intervals else the test can not * be run and report NA */ // new swich if (yearsWithFires.size() != 0) { if (includeIncomplete) { if (maxLastYear.compareTo(yearsWithFires.get(yearsWithFires.size() - 1)) != 0) { log.debug("here"); numberOfintervalscomp[i] = yearsWithFires.size(); } else { numberOfintervalscomp[i] = yearsWithFires.size() - 1; } } else { numberOfintervalscomp[i] = yearsWithFires.size() - 1; } } log.debug("number of invervlas in comp is: " + numberOfintervalscomp[i]); // end of new switch if (numberOfintervalscomp[i] >= 3) { enoughIntComp[i] = true; ArrayList<Integer> fireIntervals = generateFireIntervals(yearsWithFires); for (int ij = 0; ij < fireIntervals.size(); ij++) { // log.debug("fire intervals are: "+ // test1.getFireIntervals().get(ij)); fireintervalspersite.add(fireIntervals.get(ij) * 1.0); } /* * Add extra interval if include incomplete is selected. the interval goes from the last fire scar year to the last year * of the fire history. */ if (includeIncomplete) { double includeinterval = maxLastYear - yearsWithFires.get(yearsWithFires.size() - 1); if (includeinterval > 0) { fireintervalspersite.add(includeinterval); System.out.println("the last year is " + maxLastYear + "the last year with fire is " + yearsWithFires.get(yearsWithFires.size() - 1)); log.debug("the included interval is " + includeinterval); } } log.debug("FireintervalsPerSite =" + fireintervalspersite); /* * Get the normal statistics for the fire intervals add the values to the stats and then call them for the stats */ DescriptiveStatistics stats = new DescriptiveStatistics(); Dfireintervalspersite = new Double[fireintervalspersite.size()]; Dfireintervalspersite = fireintervalspersite.toArray(Dfireintervalspersite); dfireintervalspersite = new double[fireintervalspersite.size()]; // summaryComp = new // double[statsparam.length][myReader.size()]; for (int ik = 0; ik < fireintervalspersite.size(); ik++) { stats.addValue(Dfireintervalspersite[ik].doubleValue()); dfireintervalspersite[ik] = Dfireintervalspersite[ik].doubleValue(); } /* * load the Summary Analysis for the Composite fire intervals */ summaryComp[0][i] = fireintervalspersite.size(); // double mean = stats.getMean(); summaryComp[1][i] = stats.getMean(); // double median = // StatUtils.percentile(dfireintervalspersite, 50); summaryComp[2][i] = StatUtils.percentile(dfireintervalspersite, 50); // double std = stats.getStandardDeviation(); summaryComp[3][i] = stats.getStandardDeviation(); // double skew = stats.getSkewness(); summaryComp[4][i] = 1.0 / summaryComp[1][i]; summaryComp[5][i] = summaryComp[3][i] / summaryComp[1][i]; summaryComp[6][i] = stats.getSkewness(); // double kurt = stats.getKurtosis(); if (numberOfintervalscomp[i] == 3) { summaryComp[7][i] = -99; } else { summaryComp[7][i] = stats.getKurtosis(); } // log.debug("nomean \t\t nostd \t\t nokurt \t noskew \t\t nomedian"); // log.debug(twoPlace.format(mean)+"\t\t"+twoPlace.format(std)+"\t\t"+twoPlace.format(kurt)+"\t\t"+twoPlace.format(skew)+"\t\t"+twoPlace.format(median)); Weibull weibull = new Weibull(fireintervalspersite); ArrayList<Double> weibullProb = weibull.getWeibullProbability(fireintervalspersite); ArrayList<Double> siglonglowbound = new ArrayList<Double>(); ArrayList<Double> sigshortupbound = new ArrayList<Double>(); log.debug("the weibull probability of first element is " + weibullProb.get(0)); log.debug("the index the size of the interval is " + weibullProb.indexOf(weibullProb.get(0))); for (int ij = 0; ij < weibullProb.size() - 1; ij++) { if (weibullProb.get(ij) <= alphaLevel) { siglonglowbound.add(fireintervalspersite.get(ij)); } if (weibullProb.get(ij) >= (1 - alphaLevel)) { sigshortupbound.add(fireintervalspersite.get(ij)); } } summaryComp[10][i] = weibull.getScale(); summaryComp[11][i] = weibull.getShape(); summaryComp[12][i] = weibull.getMean(); summaryComp[13][i] = weibull.getMedian(); summaryComp[14][i] = weibull.getMode(); summaryComp[15][i] = weibull.getSigma(); summaryComp[16][i] = 1.0 / summaryComp[13][i]; summaryComp[17][i] = weibull.getSkew(); summaryComp[18][i] = weibull.getExceedenceProbability2()[0]; summaryComp[19][i] = weibull.getExceedenceProbability2()[1]; Collections.sort(sigshortupbound); log.debug("siglonglowbound is " + siglonglowbound); try { summaryComp[20][i] = sigshortupbound.get(sigshortupbound.size() - 1); } catch (Exception e) { summaryComp[20][i] = Double.NaN; } Collections.sort(siglonglowbound); try { summaryComp[21][i] = siglonglowbound.get(0); } catch (Exception e) { summaryComp[21][i] = Double.NaN; } log.debug("sigshortupbound is " + sigshortupbound); Collections.sort(fireintervalspersite); summaryComp[8][i] = fireintervalspersite.get(0); summaryComp[9][i] = fireintervalspersite.get(fireintervalspersite.size() - 1); // log.debug("shape \t\t scale \t\t median "); // log.debug(twoPlace.format(test1.Weibull_Parameters(fireintervalspersite)[0])+"\t\t"+twoPlace.format(test1.Weibull_Parameters(fireintervalspersite)[1])+"\t\t"+twoPlace.format(test1.weibull_median(test1.Weibull_Parameters(fireintervalspersite)))); // log.debug("mean \t\t sigma \t\t mode \t\t skewness"); // log.debug(twoPlace.format(test1.weibull_mean(test1.Weibull_Parameters(fireintervalspersite)))+"\t\t"+twoPlace.format(test1.weibull_sigma(test1.Weibull_Parameters(fireintervalspersite)))+"\t\t"+twoPlace.format(test1.weibull_mode(test1.Weibull_Parameters(fireintervalspersite)))+"\t\t"+twoPlace.format(test1.weibull_skew(test1.Weibull_Parameters(fireintervalspersite)))); // log.debug("maxhazard \t\t lei \t\t uei "); // log.debug(twoPlace.format(test1.maxhazard_int(test1.Weibull_Parameters(fireintervalspersite)))+"\t\t"+twoPlace.format(test1.weibull_lowuppexcint(test1.Weibull_Parameters(fireintervalspersite))[0])+"\t\t"+twoPlace.format(test1.weibull_lowuppexcint(test1.Weibull_Parameters(fireintervalspersite))[1])); // log.debug("the size of YearWith Fires is "+YearsWithFires.size()); System.out.println("the size of the prb exdc is " + weibull.getExceedenceProbability().length); for (int kk = 0; kk < weibull.getExceedenceProbability().length; kk++) { ExceeProbcomp[kk][i] = weibull.getExceedenceProbability()[kk]; // log.debug("file "+i+"Exce probability "+ // ExceeProbcomp[kk][i]); } } // end of if enoughIntComp else { enoughIntComp[i] = false; } } // end the if composite is selected /* * starting the process for the sample mode. */ if (analysisType.equals(AnalysisType.SAMPLE)) { log.debug("I am in sample "); ArrayList<Double> fireintervalspersample = new ArrayList<Double>(); FIyearperSampletemp = new ArrayList<Integer>(); // FyearperSampletemp = new ArrayList<Integer>(); for (int k = 0; k < myReader.get(i).getNumberOfSeries(); k++) { log.debug("Parsing file index " + i + ", series number " + (k + 1)); FyearperSampletemp = new ArrayList<Integer>(); // log.debug("the size of the years of the file is:"+ // myReader.get(i).getYear().size()); // log.debug("years with fires in sample "+k + // "years are "); // for (int j = 0; j < myReader.get(i).getYearArray().size(); j++) for (int j = 0; j < listYears.size(); j++) { // log.debug("the size climate2d is "+myReader.get(i).getClimate2d().get(k).get(j)); if (eventTypeToProcess.equals(EventTypeToProcess.FIRE_EVENT)) { if (climateYear.indexOf(listYears.get(j)) != -1) { if (myReader.get(i).getClimate2d().get(k) .get(climateYear.indexOf(listYears.get(j))) == 1) { // FyearperSampletemp.add((j + myReader.get(i).getFirstYear())); FyearperSampletemp.add(listYears.get(j)); } } } // { // if ((myReader.get(i).getClimate2d().get(k).get(j) == 1)) // { // / log.debug("I here inside ==1 "+ // / j+" "+myReader.get(i).getFirstYear()); // / int temp=j+myReader.get(i).getFirstYear(); // / log.debug((j+myReader.get(i).getFirstYear())); // /// FyearperSampletemp.add((j + myReader.get(i).getFirstYear())); // } // } else if (eventTypeToProcess.equals(EventTypeToProcess.INJURY_EVENT)) { if (climateYear.indexOf(listYears.get(j)) != -1) { if (myReader.get(i).getClimate2dII().get(k) .get(climateYear.indexOf(listYears.get(j))) == 1) { FyearperSampletemp.add(listYears.get(j)); } } // if ((myReader.get(i).getClimate2dII().get(k).get(j) == 1)) // { // FyearperSampletemp.add((j + myReader.get(i).getFirstYear())); // } } else if (eventTypeToProcess.equals(EventTypeToProcess.FIRE_AND_INJURY_EVENT)) { if (climateYear.indexOf(listYears.get(j)) != -1) { if (myReader.get(i).getClimate2dIII().get(k) .get(climateYear.indexOf(listYears.get(j))) == 1) { FyearperSampletemp.add(listYears.get(j)); } } // if ((myReader.get(i).getClimate2dIII().get(k).get(j) == 1)) // { // FyearperSampletemp.add((j + myReader.get(i).getFirstYear())); // } } else { log.error("Unsupported event type caught"); } } // / end of the loop for listYears in common (finish loading the fire year per sample log.debug( "series number " + (k + 1) + " FyearperSampletemp.size() " + FyearperSampletemp.size()); if (FyearperSampletemp.size() != 0) { if (includeIncomplete) { if (maxLastYear.compareTo(FyearperSampletemp.get(FyearperSampletemp.size() - 1)) != 0) { numberOfintervalssamp[i] = numberOfintervalssamp[i] + FyearperSampletemp.size(); } } else { numberOfintervalssamp[i] = numberOfintervalssamp[i] + (FyearperSampletemp.size() - 1); } } log.debug("series number: " + (k + 1) + " number of intervals " + numberOfintervalssamp[i]); // new if ((FyearperSampletemp.size() == 1) && (includeIncomplete)) { log.debug("last index per sample is " + myReader.get(i).getLastYearIndexPerSample()[k]); log.debug("first year per sample is " + myReader.get(i).getFirstYear()); log.debug("maxLastyear is " + maxLastYear); // if (maxLastYear != FyearperSampletemp.get(FyearperSampletemp.size() - 1)) if (maxLastYear.compareTo(FyearperSampletemp.get(FyearperSampletemp.size() - 1)) != 0) { log.debug("I am in not equal "); log.debug( "last year in the sample is " + (myReader.get(i).getLastYearIndexPerSample()[k] + myReader.get(i).getFirstYear())); log.debug("maxLastyear is " + maxLastYear); log.debug("the last fire year in the sample " + FyearperSampletemp.get(FyearperSampletemp.size() - 1)); if (maxLastYear <= (myReader.get(i).getLastYearIndexPerSample()[k] + myReader.get(i).getFirstYear())) { Integer temp = ((maxLastYear) - FyearperSampletemp.get(FyearperSampletemp.size() - 1)); // int temp1 = maxLastYear.intValue() - FyearperSampletemp.get(FyearperSampletemp.size() - 1).intValue(); log.debug("in less than or equal to "); // temp = (maxLastYear) - FyearperSampletemp.get(FyearperSampletemp.size() - 1); log.debug("the resta temp is " + temp); // FIyearperSampletemp.add(((maxLastYear) - FyearperSampletemp.get(FyearperSampletemp.size() - 1))); if ((maxLastYear) - FyearperSampletemp.get(FyearperSampletemp.size() - 1) > 0) { FIyearperSampletemp.add( (maxLastYear) - FyearperSampletemp.get(FyearperSampletemp.size() - 1)); log.debug("the fire intervals for sample " + k + " is " + FIyearperSampletemp.get(0)); } // FIyearperSampletemp.add(temp); // log.debug("the fire intervals for sample " + k + " is " + FIyearperSampletemp.get(0)); } else { log.debug("in else "); FIyearperSampletemp.add((myReader.get(i).getLastYearIndexPerSample()[k] + myReader.get(i).getFirstYear()) - FyearperSampletemp.get(FyearperSampletemp.size() - 1)); log.debug("fire intervals for sample " + k + " is " + FIyearperSampletemp.get(0)); } // FIyearperSampletemp.add((myReader.get(i).getFirstYear() + myReader.get(i).getLastYearIndexPerSample()[k]) // - FyearperSampletemp.get(FyearperSampletemp.size() - 1)); } // log.debug("fire intervals for sample " + k + " is " + FIyearperSampletemp.get(0)); } // end of if one fire year and includelastyear so we have at least one interval in a given series. // endofnew if ((FyearperSampletemp.size() >= 2)) { log.debug("Series number is " + (k + 1)); for (int jk = 0; jk < FyearperSampletemp.size() - 1; jk++) { // FIyearperSampletemp.add(FyearperSample.get(k).get(jk+1) // - FyearperSample.get(k).get(jk)); log.debug("FyearperSampletemp is " + FyearperSampletemp.get(jk)); if ((FyearperSampletemp.get(jk + 1) - FyearperSampletemp.get(jk)) > 0) { FIyearperSampletemp .add(FyearperSampletemp.get(jk + 1) - FyearperSampletemp.get(jk)); } // FIyearperSampletemp.add(FyearperSampletemp.get(jk+1) // - FyearperSampletemp.get(jk)); log.debug("fire intervals for sample " + k + " is " + FIyearperSampletemp.get(jk)); // fisumtemp= fisumtemp + // FIyearperSampletemp.get(jk).intValue(); } if (includeIncomplete) { // if (maxLastYear != FyearperSampletemp.get(FyearperSampletemp.size() - 1)) if (maxLastYear.compareTo(FyearperSampletemp.get(FyearperSampletemp.size() - 1)) != 0) // if ((myReader.get(i).getLastYearIndexPerSample()[k] + myReader.get(i).getFirstYear()) != FyearperSampletemp // .get(FyearperSampletemp.size() - 1)) { if (maxLastYear <= (myReader.get(i).getLastYearIndexPerSample()[k] + myReader.get(i).getFirstYear())) { if (((maxLastYear) - FyearperSampletemp.get(FyearperSampletemp.size() - 1)) > 0) { FIyearperSampletemp.add(((maxLastYear) - FyearperSampletemp.get(FyearperSampletemp.size() - 1))); } } else { FIyearperSampletemp.add((myReader.get(i).getLastYearIndexPerSample()[k] + myReader.get(i).getFirstYear()) - FyearperSampletemp.get(FyearperSampletemp.size() - 1)); } // log.debug("the sample number is "+k+ // " the size of the fyearpersampletemp is "+ // FyearperSampletemp.size() ); // log.debug("the last year per sample is " // + (myReader.get(i).getLastYearIndexPerSample()[k] + myReader.get(i).getFirstYear())); // log.debug(" the last fire year per sample " + FyearperSampletemp.get(FyearperSampletemp.size() - 1)); // FIyearperSampletemp.add((maxLastYear) - FyearperSampletemp.get(FyearperSampletemp.size() - 1)); // log.debug("the last intrval in included is on is " // + FIyearperSampletemp.get(FIyearperSampletemp.size() - 1)); } } } // end of if at least 2 fier years so we have at least one interval in a given series. log.debug("size of FIyearperSampletemp " + FIyearperSampletemp.size() + " at series is :" + (k + 1)); // FIyearperSampletemp.size()+ // " X "+FIyearperSampletemp.get(0).size()); } // end of the loop for number of series. // log.debug("size of FIyearperSample "+ // FIyearperSampletemp.size()); for (int j = 0; j < FIyearperSampletemp.size(); j++) { fireintervalspersample.add(FIyearperSampletemp.get(j) * 1.0); } /* * Get the normal statistics for the fire intervals add the values to the stats and then call them for the stats */ if (fireintervalspersample.size() >= 3) { enoughIntSamp[i] = true; DescriptiveStatistics stasample = new DescriptiveStatistics(); Dfireintervalspersample = new Double[fireintervalspersample.size()]; Dfireintervalspersample = fireintervalspersample.toArray(Dfireintervalspersample); dfireintervalspersample = new double[fireintervalspersample.size()]; // summarySample = new // double[statsparam.length][myReader.size()]; for (int ik = 0; ik < fireintervalspersample.size(); ik++) { stasample.addValue(Dfireintervalspersample[ik].doubleValue()); dfireintervalspersample[ik] = Dfireintervalspersample[ik].doubleValue(); log.debug("the " + ik + " fire interval is " + dfireintervalspersample[ik]); } log.debug("the size for dfireintervalspersample is " + dfireintervalspersample.length); // ADDED BY PETE if (dfireintervalspersample.length == 0) continue; /* * load the Summary Analysis for the Sample fire intervals */ summarySample[0][i] = fireintervalspersample.size(); // double mean = stats.getMean(); summarySample[1][i] = stasample.getMean(); log.debug("mean sample is " + stasample.getMean()); // double median = // StatUtils.percentile(dfireintervalspersite, 50); summarySample[2][i] = StatUtils.percentile(dfireintervalspersample, 50); log.debug("summarySample[2][] " + i + " " + summarySample[2][i]); // double std = stats.getStandardDeviation(); summarySample[3][i] = stasample.getStandardDeviation(); log.debug("summarySample[3][] " + i + " " + summarySample[3][i]); // double skew = stats.getSkewness(); summarySample[4][i] = 1.0 / summarySample[1][i]; log.debug("summarySample[4][] " + i + " " + summarySample[4][i]); summarySample[5][i] = summarySample[3][i] / summarySample[1][i]; log.debug("summarySample[5][] " + i + " " + summarySample[5][i]); summarySample[6][i] = stasample.getSkewness(); log.debug("summarySample[6][] " + i + " " + summarySample[6][i]); // double kurt = stats.getKurtosis(); if (numberOfintervalssamp[i] == 3) { summarySample[7][i] = -99; } else { summarySample[7][i] = stasample.getKurtosis(); } // summarySample[7][i] = stasample.getKurtosis(); log.debug("summarySample[7][] " + i + " " + summarySample[7][i]); // log.debug("nomean \t\t nostd \t\t nokurt \t noskew \t\t nomedian"); // log.debug(twoPlace.format(mean)+"\t\t"+twoPlace.format(std)+"\t\t"+twoPlace.format(kurt)+"\t\t"+twoPlace.format(skew)+"\t\t"+twoPlace.format(median)); Weibull weibull = new Weibull(fireintervalspersample); // ArrayList<Double> weibullProb = weibull.getWeibullProbability(fireintervalspersample); ArrayList<Double> siglonglowbound = new ArrayList<Double>(); ArrayList<Double> sigshortupbound = new ArrayList<Double>(); log.debug("the weibull probability of first element is " + weibullProb.get(0)); log.debug("the index the size of the interval is " + weibullProb.indexOf(weibullProb.get(0))); for (int ij = 0; ij < weibullProb.size() - 1; ij++) { if (weibullProb.get(ij) <= alphaLevel) { siglonglowbound.add(fireintervalspersample.get(ij)); } if (weibullProb.get(ij) >= (1 - alphaLevel)) { sigshortupbound.add(fireintervalspersample.get(ij)); } } // summarySample[10][i] = weibull.getScale(); log.debug("summarySample[10][] " + i + " " + summarySample[10][i]); summarySample[11][i] = weibull.getShape(); log.debug("summarySample[11][] " + i + " " + summarySample[11][i]); summarySample[12][i] = weibull.getMean(); summarySample[13][i] = weibull.getMedian(); summarySample[14][i] = weibull.getMode(); summarySample[15][i] = weibull.getSigma(); summarySample[16][i] = 1.0 / summarySample[13][i]; summarySample[17][i] = weibull.getSkew(); summarySample[18][i] = weibull.getExceedenceProbability2()[0]; summarySample[19][i] = weibull.getExceedenceProbability2()[1]; Collections.sort(sigshortupbound); log.debug("siglonglowbound is " + siglonglowbound); try { summarySample[20][i] = sigshortupbound.get(sigshortupbound.size() - 1); } catch (Exception e) { summarySample[20][i] = Double.NaN; } Collections.sort(siglonglowbound); try { summarySample[21][i] = siglonglowbound.get(0); } catch (Exception e) { summarySample[21][i] = Double.NaN; } log.debug("sigshortupbound is " + sigshortupbound); Collections.sort(fireintervalspersample); try { summarySample[8][i] = fireintervalspersample.get(0); } catch (Exception ex) { log.error("Index out of bounds exception caught: "); log.error(" summarySample[8][i] = fireintervalspersample.get(0)"); ex.printStackTrace(); } summarySample[9][i] = fireintervalspersample.get(fireintervalspersample.size() - 1); // log.debug("shape \t\t scale \t\t median "); // log.debug(twoPlace.format(test2.Weibull_Parameters(fireintervalspersample)[0])+"\t\t"+twoPlace.format(test2.Weibull_Parameters(fireintervalspersample)[1])+"\t\t"+twoPlace.format(test2.weibull_median(test1.Weibull_Parameters(fireintervalspersample)))); // log.debug("mean \t\t sigma \t\t mode \t\t skewness"); // log.debug(twoPlace.format(test1.weibull_mean(test2.Weibull_Parameters(fireintervalspersample)))+"\t\t"+twoPlace.format(test1.weibull_sigma(test2.Weibull_Parameters(fireintervalspersample)))+"\t\t"+twoPlace.format(test2.weibull_mode(test1.Weibull_Parameters(fireintervalspersample)))+"\t\t"+twoPlace.format(test1.weibull_skew(test2.Weibull_Parameters(fireintervalspersample)))); // log.debug("maxhazard \t\t lei \t\t uei "); // log.debug(twoPlace.format(test2.maxhazard_int(test2.Weibull_Parameters(fireintervalspersample)))+"\t\t"+twoPlace.format(test2.weibull_lowuppexcint(test2.Weibull_Parameters(fireintervalspersample))[0])+"\t\t"+twoPlace.format(test2.weibull_lowuppexcint(test2.Weibull_Parameters(fireintervalspersample))[1])); // log.debug("the size of YearWith Fires is "+YearsWithFires.size()); // log.debug("the size of the prb exdc is // "+test2.weibull_Exprob(test2.Weibull_Parameters(fireintervalspersample)).length); System.out.println( "the size of the prb exdc sample is " + weibull.getExceedenceProbability().length); for (int kk = 0; kk < weibull.getExceedenceProbability().length; kk++) { ExceeProbsample[kk][i] = weibull.getExceedenceProbability()[kk]; log.debug("file " + i + " Exce probability " + ExceeProbsample[kk][i]); // log.debug("the size is "+ExceeProbsample.length); } } // end of if at least 4 fireintervals else { enoughIntSamp[i] = false; } } // end of if jRadioSample selected. // log.debug("the size of exceeprobsample is "ExceeProbsample.length+" X "+ExceeProbsample[0].length); } // end of i readering each file loop do loop (354-1185) /* * */ // log.debug("size of the climateMatrixSite is "+climateMatrixSite.size()+" X "+climateMatrixSite.get(0).size()); // for (int j = 0; j < listYears.size(); j++){ // log.debug(climateMatrixSite.get(0).get(j) + " " + // listYears.get(j)); // } // setCursor(Cursor.getDefaultCursor()); /* * create JFileChooser object to generate a browsing capabilities */ JFileChooser fileBrowse = new JFileChooser(); fileBrowse = new JFileChooser(savePath.substring(0, savePath.lastIndexOf(File.separator))); /* * set multiselect on (even though we don't need it) */ fileBrowse.setMultiSelectionEnabled(true); /* * set file and folder directive */ fileBrowse.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); /* * set file type: coma delimited file csv */ // FileFilter filter1 = new CSVFileFilter(); fileBrowse.setFileFilter(filter1); /* * set dialog text: select the name and location of the matrix files */ fileBrowse.setDialogTitle("Select the name and location of the Stats Summary file:"); /* * create the writer object for each of the files to be created */ Writer wr; Writer wrWDE; Writer wrSample; Writer wrWDESample; /* * set delimiter in this case we are using comas "," */ String delim = ","; /* * Start writing information into the files */ try { if (analysisType.equals(AnalysisType.COMPOSITE)) { wr = new BufferedWriter(new FileWriter(summaryFile)); wrWDE = new BufferedWriter(new FileWriter(exceedenceFile)); /* * write the heading to the files */ String buffer = ""; buffer = buffer + "Composite Parameters" + delim; for (int i = 0; i < inputFileArray.length; i++) { buffer = buffer + inputFileArray[i].getLabel() + delim; } ; wr.write(buffer.substring(0, buffer.length() - 1) + System.getProperty("line.separator")); buffer = ""; for (int j = 0; j < statsparam.length; j++) { buffer = buffer + statsparam[j] + delim; for (int k = 0; k < inputFileArray.length; k++) { if (j == 0) { if (numberOfintervalscomp[k] < 3) { buffer = buffer + twoPlace.format(numberOfintervalscomp[k]) + delim; } else { buffer = buffer + twoPlace.format(summaryComp[0][k]) + delim; } } else { if (enoughIntComp[k]) { if (summaryComp[j][k] == -99) { buffer = buffer + "" + delim; } else { buffer = buffer + twoPlace.format(summaryComp[j][k]) + delim; } } else { buffer = buffer + "" + delim; } } } // end of k loop filearray wr.write(buffer.substring(0, buffer.length() - 1) + System.getProperty("line.separator")); buffer = ""; } // end of j loop Stats // wr.close(); // // // wrWDE = new BufferedWriter(new // FileWriter(outputWDExceeTable)); /* * write the heading to the files */ buffer = ""; wrWDE.write("Exceedence Prob" + delim); for (int i = 0; i < inputFileArray.length; i++) { buffer = buffer + inputFileArray[i].getLabel() + delim; } wrWDE.write(buffer.substring(0, buffer.length() - 1) + System.getProperty("line.separator")); buffer = ""; for (int j = 0; j < fixvalt.length; j++) { buffer = buffer + threePlace.format(fixvalt[j]) + delim; for (int k = 0; k < inputFileArray.length; k++) { if (enoughIntComp[k]) { buffer = buffer + twoPlace.format(ExceeProbcomp[j][k]) + delim; } else { buffer = buffer + "" + delim; } } wrWDE.write(buffer.substring(0, buffer.length() - 1) + System.getProperty("line.separator")); buffer = ""; } wr.close(); wrWDE.close(); } // end of if jRadioComp is selecte if (analysisType.equals(AnalysisType.SAMPLE)) { wrSample = new BufferedWriter(new FileWriter(summaryFile)); wrWDESample = new BufferedWriter(new FileWriter(exceedenceFile)); /* * write the heading to the files */ wrSample.write("Sample Parameters" + delim); for (int i = 0; i < inputFileArray.length; i++) { wrSample.write(inputFileArray[i].getLabel() + delim); } wrSample.write(System.getProperty("line.separator")); for (int j = 0; j < statsparam.length; j++) { wrSample.write(statsparam[j] + delim); for (int k = 0; k < inputFileArray.length; k++) { if (j == 0) { if (numberOfintervalssamp[k] < 3) { wrSample.write(twoPlace.format(numberOfintervalssamp[k]) + delim); } else { wrSample.write(twoPlace.format(summarySample[0][k]) + delim); } } else { if (enoughIntSamp[k]) { if (summarySample[j][k] == -99) { wrSample.write("" + delim); } else { wrSample.write(twoPlace.format(summarySample[j][k]) + delim); } } else { wrSample.write("" + delim); } } } // end of k loop file array wrSample.write(System.getProperty("line.separator")); } // end of loop j loop stats // wrSample.close(); // // // log.debug("the size is "+fixvalt.length+" X "+inputFile.length); // wrWDESample = new BufferedWriter(new // FileWriter(outputWDExceeTablesample)); /* * write the heading to the files */ wrWDESample.write("Exceedence Prob" + delim); for (int i = 0; i < inputFileArray.length; i++) { wrWDESample.write(inputFileArray[i].getLabel() + delim); } wrWDESample.write(System.getProperty("line.separator")); for (int j = 0; j < fixvalt.length; j++) { wrWDESample.write(threePlace.format(fixvalt[j]) + delim); for (int k = 0; k < inputFileArray.length; k++) { // System.out.print(ExceeProbcomp[j][k]+delim); if (enoughIntSamp[k]) { wrWDESample.write(twoPlace.format(ExceeProbsample[j][k]) + delim); } else { wrWDESample.write("" + delim); } } // System.out.print(System.getProperty("line.separator")); wrWDESample.write(System.getProperty("line.separator")); } wrSample.close(); wrWDESample.close(); } // end of jradiosample } // end of Try catch (IOException ex) { ex.printStackTrace(); } finally { } }
From source file:org.fhaes.gui.ShapeFileDialog.java
/** * Prompt the user for an output filename * //from w ww. j ava 2 s . co m * @param filter * @return */ private File getOutputFile(FileFilter filter) { String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null); File outputFile; // Create a file chooser final JFileChooser fc = new JFileChooser(lastVisitedFolder); fc.setAcceptAllFileFilterUsed(true); if (filter != null) { fc.addChoosableFileFilter(filter); fc.setFileFilter(filter); } fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false); fc.setDialogTitle("Save as..."); // In response to a button click: int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { outputFile = fc.getSelectedFile(); if (FileUtils.getExtension(outputFile.getAbsolutePath()) == "") { log.debug("Output file extension not set by user"); if (fc.getFileFilter().getDescription().equals(new SHPFileFilter().getDescription())) { log.debug("Adding shp extension to output file name"); outputFile = new File(outputFile.getAbsolutePath() + ".shp"); } } else { log.debug("Output file extension set my user to '" + FileUtils.getExtension(outputFile.getAbsolutePath()) + "'"); } App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, outputFile.getAbsolutePath()); } else { return null; } if (outputFile.exists()) { Object[] options = { "Overwrite", "No", "Cancel" }; int response = JOptionPane.showOptionDialog(this, "The file '" + outputFile.getName() + "' already exists. Are you sure you want to overwrite?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a custom Icon options, // the titles of buttons options[0]); // default button title if (response != JOptionPane.YES_OPTION) { return null; } } return outputFile; }
From source file:org.geopublishing.geopublisher.GpUtil.java
/** * Performs a file OPEN choose as a fallback * /* www .j a v a 2 s . c o m*/ * @param parent * component for the dialog (can be {@code null}) * @param startFolder * start folder for the chooser (if {@code null} "/" is used) * @param filter * defines which files can be selected. Only the last filter in * the list will be offered due to limitations * @return {@code null} if the dialog was not approved */ public static File chooseFileOpenFallback(Component parent, File startFolder, String title, FileExtensionFilter... filters) { if (startFolder == null) startFolder = new File("/"); if (startFolder.isFile()) startFolder = startFolder.getParentFile(); JFileChooser chooser = new JFileChooser(startFolder); chooser.setDialogType(JFileChooser.OPEN_DIALOG); if (filters != null) { chooser.setAcceptAllFileFilterUsed(false); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setFileFilter(filters[0].toJFileChooserFilter()); } if (title != null) chooser.setDialogTitle(title); int ret = chooser.showOpenDialog(parent); if (ret == JFileChooser.APPROVE_OPTION) return chooser.getSelectedFile(); return null; }
From source file:org.giswater.controller.MenuController.java
private String chooseSqlFile(boolean save) { String path = ""; JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("SQL extension file", "sql"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(Utils.getBundleString("MenuController.file_sql")); File file = new File(PropertiesDao.getLastSqlPath()); chooser.setCurrentDirectory(file.getParentFile()); int returnVal; if (save) {/*from w w w. ja v a 2 s . c o m*/ returnVal = chooser.showSaveDialog(mainFrame); } else { returnVal = chooser.showOpenDialog(mainFrame); } if (returnVal == JFileChooser.APPROVE_OPTION) { File fileSql = chooser.getSelectedFile(); path = fileSql.getAbsolutePath(); if (path.lastIndexOf(".") == -1) { path += ".sql"; fileSql = new File(path); } PropertiesDao.setLastSqlPath(path); } return path; }
From source file:org.giswater.controller.MenuController.java
private File gswChooseFile(boolean save) { String path = ""; File file = null;//from w ww. ja va 2 s . com JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("GSW extension file", "gsw"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(Utils.getBundleString("MenuController.gsw_file")); File fileProp = new File(prop.get("FILE_GSW", Utils.getLogFolder())); chooser.setCurrentDirectory(fileProp.getParentFile()); int returnVal; if (save) { returnVal = chooser.showSaveDialog(mainFrame); } else { returnVal = chooser.showOpenDialog(mainFrame); } if (returnVal == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); path = file.getAbsolutePath(); if (path.lastIndexOf(".") == -1) { path += ".gsw"; file = new File(path); } } return file; }
From source file:org.giswater.controller.MenuController.java
private String chooseFileSetup(String fileName) { String path = ""; JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("EXE extension file", "exe"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle(Utils.getBundleString("file_exe")); File file = new File(usersFolder + fileName); chooser.setCurrentDirectory(file);//from w ww.j av a 2 s. c om chooser.setSelectedFile(file); int returnVal = chooser.showOpenDialog(mainFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { File fileSql = chooser.getSelectedFile(); path = fileSql.getAbsolutePath(); if (path.lastIndexOf(".") == -1) { path += ".exe"; fileSql = new File(path); } } return path; }
From source file:org.jcurl.core.jnlp.FileDialogSwing.java
private static JFileChooser createFileChooser(final String pathHint, final String[] extensions, final boolean showDir) { final JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(false);/*from w ww .j ava 2 s . c o m*/ fc.setAcceptAllFileFilterUsed(true); fc.setFileFilter(new FileFilter() { @Override public boolean accept(final File f) { if (f == null) return false; if (showDir && f.isDirectory()) return true; for (final String element : extensions) if (f.getName().endsWith("." + element)) return true; return false; } @Override public String getDescription() { final StringBuilder b = new StringBuilder(); for (final String element : extensions) b.append("*.").append(element).append(", "); if (b.length() > 0) b.setLength(b.length() - 2); return b.toString(); } }); return fc; }
From source file:org.jdal.swing.report.ReportFileView.java
/** * Add a file to this report/*from www . j ava2s . c o m*/ * @throws ReportingException */ private void addAttachment() throws ReportingException { Report report = getModel(); JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new ReportFileFilter()); if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(getPanel())) { File file = chooser.getSelectedFile(); try { getModel().setData(FileUtils.readFileToByteArray(file)); getModel().setFileName(file.getName()); fileName.setText(file.getName()); // Update hidden value hasSQL to determine whether this report requires a Connection // to be displayed. InputStream reportStream = null; try { reportStream = new FileInputStream(file); } catch (FileNotFoundException e) { throw new ReportingException("Error cargando fichero"); } JasperReport jasperReport = null; try { String suffix = ReportManager.getSuffix(file.getName()); if (".jrxml".equals(suffix)) jasperReport = JasperCompileManager.compileReport(reportStream); else if (".jasper".equals(suffix)) jasperReport = (JasperReport) JRLoader.loadObject(reportStream); else { throw new ReportingException("Archivos del tipo " + suffix + " no pueden ser procesados"); } if (jasperReport.getQuery() != null) report.setHasQuery(new Boolean(true)); else report.setHasQuery(new Boolean(false)); } catch (JRException e) { log.error(e); e.printStackTrace(); throw new ReportingException("Error procesando fichero"); } } catch (IOException e) { throw new ReportingException("No se puede leer el Fichero: " + file.getName()); } } }