List of usage examples for java.awt FileDialog getFile
public String getFile()
From source file:edu.ucla.stat.SOCR.analyses.util.moduls.frm.Panels.Jpan_btn.java
private FitxerDades getFitxerDades(final String sPath) { final FileDialog fd = new FileDialog(fDialog, Language.getLabel(9), FileDialog.LOAD); FitxerDades fitx;//w w w .ja va 2s. com fitx = new FitxerDades(); fd.setDirectory(sPath); fd.setVisible(true); if (fd.getFile() == null) { fitx = null; } else { fitx.setNom(fd.getFile()); fitx.setPath(fd.getDirectory()); } return fitx; }
From source file:com.moneydance.modules.features.importlist.io.MacOSDirectoryChooser.java
@Override void chooseBaseDirectory() { System.setProperty("apple.awt.fileDialogForDirectories", "true"); final FileDialog fileDialog = new FileDialog((Frame) null, this.getLocalizable().getDirectoryChooserTitle(), FileDialog.LOAD);//w ww . j a v a2 s . c o m fileDialog.setModal(true); fileDialog.setFilenameFilter(DirectoryValidator.INSTANCE); try { fileDialog.setDirectory(FileUtils.getUserDirectory().getAbsolutePath()); } catch (SecurityException e) { LOG.log(Level.WARNING, e.getMessage(), e); } if (this.getBaseDirectory() != null) { final File parentDirectory = this.getBaseDirectory().getParentFile(); if (parentDirectory != null) { fileDialog.setDirectory(parentDirectory.getAbsolutePath()); } } fileDialog.setVisible(true); System.setProperty("apple.awt.fileDialogForDirectories", "false"); if (fileDialog.getFile() == null) { return; } this.getPrefs() .setBaseDirectory(new File(fileDialog.getDirectory(), fileDialog.getFile()).getAbsolutePath()); LOG.info(String.format("Base directory is %s", this.getPrefs().getBaseDirectory())); }
From source file:pipeline.GUI_utils.JXTablePerColumnFiltering.java
/** * * @param columnsFormulasToPrint//ww w .ja v a2s . c o m * If null, print all columns * @param stripNewLinesInCells * @param filePath * Full path to save file to; if null, user will be prompted. */ public void saveFilteredRowsToFile(List<Integer> columnsFormulasToPrint, boolean stripNewLinesInCells, String filePath) { String saveTo; if (filePath == null) { FileDialog dialog = new FileDialog(new Frame(), "Save filtered rows to", FileDialog.SAVE); dialog.setVisible(true); saveTo = dialog.getDirectory(); if (saveTo == null) return; saveTo += "/" + dialog.getFile(); } else { saveTo = filePath; } PrintWriter out = null; try { out = new PrintWriter(saveTo); StringBuffer b = new StringBuffer(); if (columnsFormulasToPrint == null) { for (int i = 0; i < this.getColumnCount(); i++) { b.append(getColumnName(i)); if (i < getColumnCount() - 1) b.append("\t"); } } else { int index = 0; for (int i : columnsFormulasToPrint) { b.append(getColumnName(i)); if (index + 1 < columnsFormulasToPrint.size()) b.append("\t"); index++; } } out.println(b); for (int i = 0; i < model.getRowCount(); i++) { int rowIndex = convertRowIndexToView(i); if (rowIndex > -1) { if (columnsFormulasToPrint == null) if (stripNewLinesInCells) out.println(getRowAsString(rowIndex).replaceAll("\n", " ")); else out.println(getRowAsString(rowIndex)); else { boolean first = true; for (int column : columnsFormulasToPrint) { if (!first) { out.print("\t"); } first = false; SpreadsheetCell cell = (SpreadsheetCell) getValueAt(rowIndex, column); if (cell != null) { String formula = cell.getFormula(); if (formula != null) { if (stripNewLinesInCells) out.print(formula.replaceAll("\n", " ")); else out.print(formula); } } } out.println(""); } } } out.close(); } catch (FileNotFoundException e) { Utils.printStack(e); Utils.displayMessage("Could not save table", true, LogLevel.ERROR); } }
From source file:com.awesheet.models.Workbook.java
@Override public void onMessage(final UIMessage message) { switch (message.getType()) { case UIMessageType.CREATE_SHEET: { addSheet(new Sheet(this, "Sheet " + (newSheetID + 1))); break;//from ww w . j av a2 s . c om } case UIMessageType.SELECT_SHEET: { SelectSheetMessage uiMessage = (SelectSheetMessage) message; selectSheet(uiMessage.getSheet()); break; } case UIMessageType.DELETE_SHEET: { DeleteSheetMessage uiMessage = (DeleteSheetMessage) message; removeSheet(uiMessage.getSheet()); break; } case UIMessageType.CREATE_BAR_CHART: { CreateBarChartMessage uiMessage = (CreateBarChartMessage) message; // Get selected cells. Cell selectedCells[] = getSelectedSheet().collectSelectedCells(); BarChart chart = new BarChart(selectedCells); chart.setNameX(uiMessage.getXaxis()); chart.setNameY(uiMessage.getYaxis()); chart.setTitle(uiMessage.getTitle()); if (!chart.generateImageData()) { UIMessageManager.getInstance().dispatchAction( new ShowPopupAction<MessagePopup>(UIPopupType.MESSAGE_POPUP, new MessagePopup("Error", "Could not create a chart. Please make sure the cells you selected are in the correct format."))); break; } UIMessageManager.getInstance() .dispatchAction(new ShowPopupAction<ChartPopup>(UIPopupType.VIEW_CHART_POPUP, new ChartPopup(new Base64().encodeAsString(chart.getImageData())))); break; } case UIMessageType.CREATE_LINE_CHART: { CreateLineChartMessage uiMessage = (CreateLineChartMessage) message; // Get selected cells. Cell selectedCells[] = getSelectedSheet().collectSelectedCells(); LineChart chart = new LineChart(selectedCells); chart.setNameX(uiMessage.getXaxis()); chart.setNameY(uiMessage.getYaxis()); chart.setTitle(uiMessage.getTitle()); if (!chart.generateImageData()) { UIMessageManager.getInstance().dispatchAction( new ShowPopupAction<MessagePopup>(UIPopupType.MESSAGE_POPUP, new MessagePopup("Error", "Could not create a chart. Please make sure the cells you selected are in the correct format."))); break; } UIMessageManager.getInstance() .dispatchAction(new ShowPopupAction<ChartPopup>(UIPopupType.VIEW_CHART_POPUP, new ChartPopup(new Base64().encodeAsString(chart.getImageData())))); break; } case UIMessageType.SAVE_CHART_IMAGE: { final SaveChartImageMessage uiMessage = (SaveChartImageMessage) message; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { byte imageData[] = new Base64().decode(uiMessage.getImageData()); FileDialog dialog = new FileDialog(MainFrame.getInstance(), "Save Chart Image", FileDialog.SAVE); dialog.setFile("*.png"); dialog.setVisible(true); dialog.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return (dir.isFile() && name.endsWith(".png")); } }); String filePath = dialog.getFile(); String directory = dialog.getDirectory(); dialog.dispose(); if (directory != null && filePath != null) { String absolutePath = new File(directory + filePath).getAbsolutePath(); if (!FileManager.getInstance().saveFile(absolutePath, imageData)) { UIMessageManager.getInstance() .dispatchAction(new ShowPopupAction<MessagePopup>(UIPopupType.MESSAGE_POPUP, new MessagePopup("Error", "Could not save chart image."))); } } } }); break; } } }
From source file:net.chaosserver.timelord.swingui.Timelord.java
/** * Persists out the timelord file and allows the user to choose where * the file should go./*from www.j av a 2 s .com*/ * * @param rwClassName the name of the RW class * (e.g. "net.chaosserver.timelord.data.ExcelDataReaderWriter") * @param userSelect allows the user to select where the file should * be persisted. */ public void writeTimeTrackData(String rwClassName, boolean userSelect) { try { Class<?> rwClass = Class.forName(rwClassName); TimelordDataReaderWriter timelordDataRW = (TimelordDataReaderWriter) rwClass.newInstance(); int result = JFileChooser.APPROVE_OPTION; File outputFile = timelordDataRW.getDefaultOutputFile(); if (timelordDataRW instanceof TimelordDataReaderWriterUI) { TimelordDataReaderWriterUI timelordDataReaderWriterUI = (TimelordDataReaderWriterUI) timelordDataRW; timelordDataReaderWriterUI.setParentFrame(applicationFrame); JDialog configDialog = timelordDataReaderWriterUI.getConfigDialog(); configDialog.pack(); configDialog.setLocationRelativeTo(applicationFrame); configDialog.setVisible(true); } if (userSelect) { if (OsUtil.isMac()) { FileDialog fileDialog = new FileDialog(applicationFrame, "Select File", FileDialog.SAVE); fileDialog.setDirectory(outputFile.getParent()); fileDialog.setFile(outputFile.getName()); fileDialog.setVisible(true); if (fileDialog.getFile() != null) { outputFile = new File(fileDialog.getDirectory(), fileDialog.getFile()); } } else { JFileChooser fileChooser = new JFileChooser(outputFile.getParentFile()); fileChooser.setSelectedFile(outputFile); fileChooser.setFileFilter(timelordDataRW.getFileFilter()); result = fileChooser.showSaveDialog(applicationFrame); if (result == JFileChooser.APPROVE_OPTION) { outputFile = fileChooser.getSelectedFile(); } } } if (result == JFileChooser.APPROVE_OPTION) { timelordDataRW.writeTimelordData(getTimelordData(), outputFile); } } catch (Exception e) { JOptionPane.showMessageDialog(applicationFrame, "Error writing to file.\n" + "Do you have the output file open?", "Save Error", JOptionPane.ERROR_MESSAGE, applicationIcon); if (log.isErrorEnabled()) { log.error("Error persisting file", e); } } }
From source file:edu.ku.brc.specify.prefs.FormattingPrefsPanel.java
/** * Method for enabling a user to choose a toolbar icon. * @param appLabel the label used to display the icon. * @param clearIconBtn the button used to clear the icon *//* w w w. j av a 2 s.co m*/ protected void chooseToolbarIcon(final JLabel appLabel, final JButton clearIconBtn) { FileDialog fileDialog = new FileDialog((Frame) UIRegistry.get(UIRegistry.FRAME), getResourceString("PREF_CHOOSE_APPICON_TITLE"), FileDialog.LOAD); //$NON-NLS-1$ fileDialog.setFilenameFilter(new ImageFilter()); UIHelper.centerAndShow(fileDialog); fileDialog.dispose(); String path = fileDialog.getDirectory(); if (StringUtils.isNotEmpty(path)) { String fullPath = path + File.separator + fileDialog.getFile(); File imageFile = new File(fullPath); if (imageFile.exists()) { ImageIcon newIcon = null; ImageIcon icon = new ImageIcon(fullPath); if (icon.getIconWidth() != -1 && icon.getIconHeight() != -1) { if (icon.getIconWidth() > 32 || icon.getIconHeight() > 32) { Image img = GraphicsUtils.getScaledImage(icon, 32, 32, false); if (img != null) { newIcon = new ImageIcon(img); } } else { newIcon = icon; } } ImageIcon appIcon; if (newIcon != null) { appLabel.setIcon(newIcon); clearIconBtn.setEnabled(true); String imgBufStr = GraphicsUtils.uuencodeImage(newAppIconName, newIcon); AppPreferences.getRemote().put(iconImagePrefName, imgBufStr); appIcon = newIcon; } else { appIcon = IconManager.getIcon("AppIcon"); appLabel.setIcon(appIcon); //$NON-NLS-1$ clearIconBtn.setEnabled(false); AppPreferences.getRemote().remove(iconImagePrefName); } IconEntry entry = IconManager.getIconEntryByName(INNER_APPICON_NAME); entry.setIcon(appIcon); if (entry.getIcons().get(IconManager.IconSize.Std32) != null) { entry.getIcons().get(IconManager.IconSize.Std32).setImageIcon(appIcon); } //((FormViewObj)form).getMVParent().set form.getValidator().dataChanged(null, null, null); } } }
From source file:sim.util.media.chart.ChartGenerator.java
/** Generates a new ChartGenerator with a blank chart. Before anything else, buildChart() is called. */ public ChartGenerator() { // create the chart buildChart();//www . j a va2 s . c o m chart.getPlot().setBackgroundPaint(Color.WHITE); chart.setAntiAlias(true); JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true); split.setBorder(new EmptyBorder(0, 0, 0, 0)); JScrollPane scroll = new JScrollPane(); JPanel b = new JPanel(); b.setLayout(new BorderLayout()); b.add(seriesAttributes, BorderLayout.NORTH); b.add(new JPanel(), BorderLayout.CENTER); scroll.getViewport().setView(b); scroll.setBackground(getBackground()); scroll.getViewport().setBackground(getBackground()); JPanel p = new JPanel(); p.setLayout(new BorderLayout()); LabelledList list = new LabelledList("Chart Properties"); DisclosurePanel pan1 = new DisclosurePanel("Chart Properties", list); globalAttributes.add(pan1); JLabel j = new JLabel("Right-Click or Control-Click"); j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC)); list.add(j); j = new JLabel("on Chart for More Options"); j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC)); list.add(j); titleField = new PropertyField() { public String newValue(String newValue) { setTitle(newValue); getChartPanel().repaint(); return newValue; } }; titleField.setValue(chart.getTitle().getText()); list.add(new JLabel("Title"), titleField); buildGlobalAttributes(list); final JCheckBox legendCheck = new JCheckBox(); ItemListener il = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { LegendTitle title = new LegendTitle(chart.getPlot()); title.setLegendItemGraphicPadding(new org.jfree.ui.RectangleInsets(0, 8, 0, 4)); chart.addLegend(title); } else { chart.removeLegend(); } } }; legendCheck.addItemListener(il); list.add(new JLabel("Legend"), legendCheck); legendCheck.setSelected(true); /* final JCheckBox aliasCheck = new JCheckBox(); aliasCheck.setSelected(chart.getAntiAlias()); il = new ItemListener() { public void itemStateChanged(ItemEvent e) { chart.setAntiAlias( e.getStateChange() == ItemEvent.SELECTED ); } }; aliasCheck.addItemListener(il); list.add(new JLabel("Antialias"), aliasCheck); */ JPanel pdfButtonPanel = new JPanel(); pdfButtonPanel.setBorder(new javax.swing.border.TitledBorder("Chart Output")); DisclosurePanel pan2 = new DisclosurePanel("Chart Output", pdfButtonPanel); pdfButtonPanel.setLayout(new BorderLayout()); Box pdfbox = new Box(BoxLayout.Y_AXIS); pdfButtonPanel.add(pdfbox, BorderLayout.WEST); JButton pdfButton = new JButton("Save as PDF"); pdfbox.add(pdfButton); pdfButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileDialog fd = new FileDialog(frame, "Choose PDF file...", FileDialog.SAVE); fd.setFile(chart.getTitle().getText() + ".pdf"); fd.setVisible(true); String fileName = fd.getFile(); if (fileName != null) { Dimension dim = chartPanel.getPreferredSize(); PDFEncoder.generatePDF(chart, dim.width, dim.height, new File(fd.getDirectory(), Utilities.ensureFileEndsWith(fd.getFile(), ".pdf"))); } } }); movieButton = new JButton("Create a Movie"); pdfbox.add(movieButton); pdfbox.add(Box.createGlue()); movieButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (movieMaker == null) startMovie(); else stopMovie(); } }); globalAttributes.add(pan2); // we add into an outer box so we can later on add more global seriesAttributes // as the user instructs and still have glue be last Box outerAttributes = Box.createVerticalBox(); outerAttributes.add(globalAttributes); outerAttributes.add(Box.createGlue()); p.add(outerAttributes, BorderLayout.NORTH); p.add(scroll, BorderLayout.CENTER); p.setMinimumSize(new Dimension(0, 0)); p.setPreferredSize(new Dimension(200, 0)); split.setLeftComponent(p); // Add scale and proportion fields Box header = Box.createHorizontalBox(); final double MAXIMUM_SCALE = 8; fixBox = new JCheckBox("Fill"); fixBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFixed(fixBox.isSelected()); } }); header.add(fixBox); fixBox.setSelected(true); // add the scale field scaleField = new NumberTextField(" Scale: ", 1.0, true) { public double newValue(double newValue) { if (newValue <= 0.0) newValue = currentValue; if (newValue > MAXIMUM_SCALE) newValue = currentValue; scale = newValue; resizeChart(); return newValue; } }; scaleField.setToolTipText("Zoom in and out"); scaleField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); scaleField.setEnabled(false); scaleField.setText(""); header.add(scaleField); // add the proportion field proportionField = new NumberTextField(" Proportion: ", 1.5, true) { public double newValue(double newValue) { if (newValue <= 0.0) newValue = currentValue; proportion = newValue; resizeChart(); return newValue; } }; proportionField.setToolTipText("Change the chart proportions (ratio of width to height)"); proportionField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); header.add(proportionField); chartHolder.setMinimumSize(new Dimension(0, 0)); chartHolder.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); chartHolder.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); chartHolder.getViewport().setBackground(Color.gray); JPanel p2 = new JPanel(); p2.setLayout(new BorderLayout()); p2.add(chartHolder, BorderLayout.CENTER); p2.add(header, BorderLayout.NORTH); split.setRightComponent(p2); setLayout(new BorderLayout()); add(split, BorderLayout.CENTER); // set the default to be white, which looks good when printed chart.setBackgroundPaint(Color.WHITE); // JFreeChart has a hillariously broken way of handling font scaling. // It allows fonts to scale independently in X and Y. We hack a workaround here. chartPanel.setMinimumDrawHeight((int) DEFAULT_CHART_HEIGHT); chartPanel.setMaximumDrawHeight((int) DEFAULT_CHART_HEIGHT); chartPanel.setMinimumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion)); chartPanel.setMaximumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion)); chartPanel.setPreferredSize(new java.awt.Dimension((int) (DEFAULT_CHART_HEIGHT * DEFAULT_CHART_PROPORTION), (int) (DEFAULT_CHART_HEIGHT))); }
From source file:edu.gmu.cs.sim.util.media.chart.ChartGenerator.java
/** Generates a new ChartGenerator with a blank chart. Before anything else, buildChart() is called. */ public ChartGenerator() { // create the chart buildChart();/* w w w . j av a 2 s. c om*/ chart.getPlot().setBackgroundPaint(Color.WHITE); chart.setAntiAlias(true); JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true); split.setBorder(new EmptyBorder(0, 0, 0, 0)); JScrollPane scroll = new JScrollPane(); JPanel b = new JPanel(); b.setLayout(new BorderLayout()); b.add(seriesAttributes, BorderLayout.NORTH); b.add(new JPanel(), BorderLayout.CENTER); scroll.getViewport().setView(b); scroll.setBackground(getBackground()); scroll.getViewport().setBackground(getBackground()); JPanel p = new JPanel(); p.setLayout(new BorderLayout()); LabelledList list = new LabelledList("Chart Properties"); DisclosurePanel pan1 = new DisclosurePanel("Chart Properties", list); globalAttributes.add(pan1); JLabel j = new JLabel("Right-Click or Control-Click"); j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC)); list.add(j); j = new JLabel("on Chart for More Options"); j.setFont(j.getFont().deriveFont(10.0f).deriveFont(java.awt.Font.ITALIC)); list.add(j); titleField = new PropertyField() { public String newValue(String newValue) { setTitle(newValue); getChartPanel().repaint(); return newValue; } }; titleField.setValue(chart.getTitle().getText()); list.add(new JLabel("Title"), titleField); buildGlobalAttributes(list); final JCheckBox legendCheck = new JCheckBox(); ItemListener il = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { LegendTitle title = new LegendTitle(chart.getPlot()); title.setLegendItemGraphicPadding(new org.jfree.ui.RectangleInsets(0, 8, 0, 4)); chart.addLegend(title); } else { chart.removeLegend(); } } }; legendCheck.addItemListener(il); list.add(new JLabel("Legend"), legendCheck); legendCheck.setSelected(true); /* final JCheckBox aliasCheck = new JCheckBox(); aliasCheck.setSelected(chart.getAntiAlias()); il = new ItemListener() { public void itemStateChanged(ItemEvent e) { chart.setAntiAlias( e.getStateChange() == ItemEvent.SELECTED ); } }; aliasCheck.addItemListener(il); list.add(new JLabel("Antialias"), aliasCheck); */ JPanel pdfButtonPanel = new JPanel(); pdfButtonPanel.setBorder(new javax.swing.border.TitledBorder("Chart Output")); DisclosurePanel pan2 = new DisclosurePanel("Chart Output", pdfButtonPanel); pdfButtonPanel.setLayout(new BorderLayout()); Box pdfbox = new Box(BoxLayout.Y_AXIS); pdfButtonPanel.add(pdfbox, BorderLayout.WEST); JButton pdfButton = new JButton("Save as PDF"); pdfbox.add(pdfButton); pdfButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileDialog fd = new FileDialog(frame, "Choose PDF file...", FileDialog.SAVE); fd.setFile(chart.getTitle().getText() + ".pdf"); fd.setVisible(true); String fileName = fd.getFile(); if (fileName != null) { Dimension dim = chartPanel.getPreferredSize(); PDFEncoder.generatePDF(chart, dim.width, dim.height, new File(fd.getDirectory(), Utilities.ensureFileEndsWith(fd.getFile(), ".pdf"))); } } }); movieButton = new JButton("Create a Movie"); pdfbox.add(movieButton); pdfbox.add(Box.createGlue()); movieButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (movieMaker == null) { startMovie(); } else { stopMovie(); } } }); globalAttributes.add(pan2); // we add into an outer box so we can later on add more global seriesAttributes // as the user instructs and still have glue be last Box outerAttributes = Box.createVerticalBox(); outerAttributes.add(globalAttributes); outerAttributes.add(Box.createGlue()); p.add(outerAttributes, BorderLayout.NORTH); p.add(scroll, BorderLayout.CENTER); p.setMinimumSize(new Dimension(0, 0)); p.setPreferredSize(new Dimension(200, 0)); split.setLeftComponent(p); // Add scale and proportion fields Box header = Box.createHorizontalBox(); final double MAXIMUM_SCALE = 8; fixBox = new JCheckBox("Fill"); fixBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFixed(fixBox.isSelected()); } }); header.add(fixBox); fixBox.setSelected(true); // add the scale field scaleField = new NumberTextField(" Scale: ", 1.0, true) { public double newValue(double newValue) { if (newValue <= 0.0) { newValue = currentValue; } if (newValue > MAXIMUM_SCALE) { newValue = currentValue; } scale = newValue; resizeChart(); return newValue; } }; scaleField.setToolTipText("Zoom in and out"); scaleField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); scaleField.setEnabled(false); scaleField.setText(""); header.add(scaleField); // add the proportion field proportionField = new NumberTextField(" Proportion: ", 1.5, true) { public double newValue(double newValue) { if (newValue <= 0.0) { newValue = currentValue; } proportion = newValue; resizeChart(); return newValue; } }; proportionField.setToolTipText("Change the chart proportions (ratio of width to height)"); proportionField.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); header.add(proportionField); chartHolder.setMinimumSize(new Dimension(0, 0)); chartHolder.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); chartHolder.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); chartHolder.getViewport().setBackground(Color.gray); JPanel p2 = new JPanel(); p2.setLayout(new BorderLayout()); p2.add(chartHolder, BorderLayout.CENTER); p2.add(header, BorderLayout.NORTH); split.setRightComponent(p2); setLayout(new BorderLayout()); add(split, BorderLayout.CENTER); // set the default to be white, which looks good when printed chart.setBackgroundPaint(Color.WHITE); // JFreeChart has a hillariously broken way of handling font scaling. // It allows fonts to scale independently in X and Y. We hack a workaround here. chartPanel.setMinimumDrawHeight((int) DEFAULT_CHART_HEIGHT); chartPanel.setMaximumDrawHeight((int) DEFAULT_CHART_HEIGHT); chartPanel.setMinimumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion)); chartPanel.setMaximumDrawWidth((int) (DEFAULT_CHART_HEIGHT * proportion)); chartPanel.setPreferredSize(new java.awt.Dimension((int) (DEFAULT_CHART_HEIGHT * DEFAULT_CHART_PROPORTION), (int) (DEFAULT_CHART_HEIGHT))); }
From source file:org.broad.igv.hic.MainWindow.java
private void loadMenuItemActionPerformed(ActionEvent e) { FileDialog dlg = new FileDialog(this); dlg.setMode(FileDialog.LOAD); dlg.setVisible(true);/*from w ww .j a va 2 s . c o m*/ String file = dlg.getFile(); if (file != null) { try { File f = new File(dlg.getDirectory(), dlg.getFile()); load(f.getAbsolutePath()); } catch (IOException e1) { e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } }
From source file:de.freese.base.swing.mac_os_x.MyApp.java
/** * @see//from w w w . java 2 s .c o m * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @Override public void actionPerformed(final ActionEvent e) { Object source = e.getSource(); if (source == this.quitMI) { quit(); } else { if (source == this.optionsMI) { preferences(); } else { if (source == this.aboutMI) { about(); } else { if (source == this.openMI) { // File:Open action shows a FileDialog for loading displayable images FileDialog openDialog = new FileDialog(this); openDialog.setMode(FileDialog.LOAD); openDialog.setFilenameFilter(new FilenameFilter() { /** * @see java.io.FilenameFilter#accept(java.io.File, * java.lang.String) */ @Override public boolean accept(final File dir, final String name) { String[] supportedFiles = ImageIO.getReaderFormatNames(); for (String supportedFile : supportedFiles) { if (name.endsWith(supportedFile)) { return true; } } return false; } }); openDialog.setVisible(true); String filePath = openDialog.getDirectory() + openDialog.getFile(); if (filePath.length() > 0) { loadImageFile(filePath); } } } } } }