List of usage examples for java.awt FileDialog FileDialog
public FileDialog(Dialog parent, String title, int mode)
From source file:JDAC.JDAC.java
public void saveData() { DateFormat df = new SimpleDateFormat("ddmmyy_HHmm"); FileDialog fd = new FileDialog(this, "Export as...", FileDialog.SAVE); fd.setFile("Data_" + df.format(new Date()) + ".csv"); fd.setVisible(true);//from ww w .j a v a 2s . co m if (fd.getFile() == null) { setStatus("Export CSV canceled"); //export canceled return; } try { BufferedWriter out = new BufferedWriter(new FileWriter(fd.getDirectory() + fd.getFile())); out.write(dataToCSVstring()); out.close(); setStatus("Export CSV successful"); } catch (IOException e) { JOptionPane.showMessageDialog(this, "" + "Error while exporting data...\n" + "If the error persists please contact the system administrator"); return; } }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaToolsDlg.java
/** * //from www . j av a2 s . c om */ @SuppressWarnings("unchecked") protected void exportSchemaLocales() { FileDialog dlg = new FileDialog(((Frame) UIRegistry.getTopWindow()), getResourceString("Save"), FileDialog.SAVE); dlg.setVisible(true); String fileName = dlg.getFile(); if (fileName != null) { final File outFile = new File(dlg.getDirectory() + File.separator + fileName); //final File outFile = new File("xxx.xml"); final SimpleGlassPane glassPane = new SimpleGlassPane(getResourceString("SL_EXPORT_SCHEMA"), 18); glassPane.setBarHeight(12); glassPane.setFillColor(new Color(0, 0, 0, 85)); setGlassPane(glassPane); glassPane.setVisible(true); SwingWorker<Integer, Integer> backupWorker = new SwingWorker<Integer, Integer>() { @Override protected Integer doInBackground() throws Exception { DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); int dispId = AppContextMgr.getInstance().getClassObject(Discipline.class).getDisciplineId(); String sql = String.format( "FROM SpLocaleContainer WHERE disciplineId = %d AND schemaType = %d", dispId, schemaType); List<SpLocaleContainer> spContainers = (List<SpLocaleContainer>) session.getDataList(sql); try { FileWriter fw = new FileWriter(outFile); //fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<vector>\n"); fw.write("<vector>\n"); BeanWriter beanWriter = new BeanWriter(fw); XMLIntrospector introspector = beanWriter.getXMLIntrospector(); introspector.getConfiguration().setWrapCollectionsInElement(true); beanWriter.getBindingConfiguration().setMapIDs(false); beanWriter.setWriteEmptyElements(false); beanWriter.enablePrettyPrint(); double step = 100.0 / (double) spContainers.size(); double total = 0.0; for (SpLocaleContainer container : spContainers) { // force Load of lazy collections container.getDescs().size(); container.getNames().size(); // Leaving this Code as an example of specifying the bewtixt file. /*InputStream inputStream = Specify.class.getResourceAsStream("datamodel/SpLocaleContainer.betwixt"); //InputStream inputStream = Specify.class.getResourceAsStream("/edu/ku/brc/specify/tools/schemalocale/SpLocaleContainer.betwixt"); InputSource inputSrc = new InputSource(inputStream); beanWriter.write(container, inputSrc); inputStream.close(); */ beanWriter.write(container); total += step; firePropertyChange("progress", 0, (int) total); } fw.write("</vector>\n"); fw.close(); } catch (Exception ex) { ex.printStackTrace(); } } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SchemaLocalizerDlg.class, e); e.printStackTrace(); } finally { if (session != null) { session.close(); } } return null; } @Override protected void done() { super.done(); glassPane.setVisible(false); } }; backupWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if (evt.getPropertyName().equals("progress")) { glassPane.setProgress((Integer) evt.getNewValue()); } } }); backupWorker.execute(); } }
From source file:JDAC.JDAC.java
public void exportPNG() { DateFormat df = new SimpleDateFormat("ddmmyy_HHmm"); FileDialog fd = new FileDialog(this, "Export as...", FileDialog.SAVE); fd.setFile("Chart_" + df.format(new Date()) + ".png"); fd.setVisible(true);/*w ww.j a v a 2s .co m*/ if (fd.getFile() == null) { setStatus("Export PNG canceled"); //export canceled return; } mChart.setTitle(currentSensor); try { ChartUtilities.saveChartAsPNG(new File(fd.getDirectory() + fd.getFile()), mChart, Definitions.exportPNGwidth, Definitions.exportPNGheight); setStatus("Export PNG successful"); } catch (IOException e) { JOptionPane.showMessageDialog(this, "" + "Error while exporting chart...\n" + "If the error persists please contact the system administrator"); mChart.setTitle(mainChartPreviewTitle); return; } mChart.setTitle(mainChartPreviewTitle); }
From source file:edu.ku.brc.specify.tasks.services.PickListUtils.java
/** * @param localizableIO/* ww w. ja v a 2 s . c o m*/ * @param hash HashSet of names of picklists to be pre-selected (can be null) */ public static void exportPickList(final LocalizableIOIFace localizableIO, final HashSet<String> hash) { // Cancel is Export All PickLists List<PickList> items = getPickLists(localizableIO, true, false); List<PickList> selectedItems = new ArrayList<PickList>(); if (hash != null) { for (PickList pl : items) { if (hash.contains(pl.getName())) { selectedItems.add(pl); } } } Window window = UIRegistry.getTopWindow(); boolean isDialog = window instanceof Dialog; ToggleButtonChooserDlg<PickList> pickDlg; if (isDialog) { pickDlg = new ToggleButtonChooserDlg<PickList>((Dialog) window, getI18n("PL_EXPORT"), items); } else { pickDlg = new ToggleButtonChooserDlg<PickList>((JFrame) window, getI18n("PL_EXPORT"), items); } pickDlg.setUseScrollPane(true); pickDlg.setAddSelectAll(true); pickDlg.createUI(); pickDlg.setSelectedObjects(selectedItems); UIHelper.centerAndShow(pickDlg); Integer cnt = null; if (!pickDlg.isCancelled()) { items = pickDlg.getSelectedObjects(); String dlgTitle = getResourceString(getI18n("RIE_ExportResource")); FileDialog dlg; if (isDialog) { dlg = new FileDialog((Dialog) window, dlgTitle, FileDialog.SAVE); } else { dlg = new FileDialog((Frame) window, dlgTitle, FileDialog.SAVE); } dlg.setDirectory(UIRegistry.getUserHomeDir()); dlg.setFile(getPickListXMLName()); UIHelper.centerAndShow(dlg); String dirStr = dlg.getDirectory(); String fileName = dlg.getFile(); if (StringUtils.isNotEmpty(dirStr) && StringUtils.isNotEmpty(fileName)) { String ext = FilenameUtils.getExtension(fileName); if (StringUtils.isEmpty(ext) || !ext.equalsIgnoreCase("xml")) { fileName += ".xml"; } try { File xmlFile = new File(dirStr + File.separator + fileName); ArrayList<BldrPickList> bldrPickLists = new ArrayList<BldrPickList>(); for (PickList pl : items) { bldrPickLists.add(new BldrPickList(pl)); } DataBuilder.writePickListsAsXML(xmlFile, bldrPickLists); cnt = bldrPickLists.size(); } catch (Exception ex) { ex.printStackTrace(); } UIRegistry.displayInfoMsgDlgLocalized(getI18n(cnt != null ? "PL_WASEXPORT" : "PL_ERR_IMP"), cnt); } } }
From source file:views.View.java
private void fileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileActionPerformed // TODO add your handling code here: FileDialog fd = new FileDialog(this, "Open", FileDialog.SAVE); }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerFrame.java
/** * Export data /* ww w . j av a 2 s . c o m*/ */ protected void exportSingleLocale() { statusBar.setText(getResourceString("SchemaLocalizerFrame.EXPORTING")); //$NON-NLS-1$ statusBar.paintImmediately(statusBar.getBounds()); schemaLocPanel.getAllDataFromUI(); if (localizableIO.hasChanged()) { if (UIRegistry.askYesNoLocalized("SAVE", "CANCEL", UIRegistry.getResourceString("SchemaLocalizerFrame.NEEDS_SAVING"), "SAVE") == JOptionPane.YES_NO_OPTION) { localizableIO.save(); } else { return; } } Vector<Locale> stdLocales = SchemaI18NService.getInstance().getStdLocaleList(false); final JList list = new JList(stdLocales); list.setCellRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value != null) { setText(((Locale) value).getDisplayName()); } return this; } }); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g")); pb.add(UIHelper.createScrollPane(list), (new CellConstraints()).xy(1, 1)); pb.setDefaultDialogBorder(); final CustomDialog dlg = new CustomDialog((Frame) UIRegistry.getTopWindow(), getResourceString("SchemaLocalizerFrame.CHOOSE_LOCALE"), true, pb.getPanel()); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { dlg.getOkBtn().setEnabled(list.getSelectedValue() != null); } } }); dlg.createUI(); dlg.getOkBtn().setEnabled(false); UIHelper.centerAndShow(dlg); if (!dlg.isCancelled()) { Locale locale = (Locale) list.getSelectedValue(); if (locale != null) { FileDialog fileDlg = new FileDialog((Frame) UIRegistry.getTopWindow(), getResourceString("SchemaLocalizerFrame.SVFILENAME"), FileDialog.SAVE); fileDlg.setVisible(true); String fileName = fileDlg.getFile(); if (StringUtils.isNotEmpty(fileName)) { File outFile = new File(fileDlg.getDirectory() + File.separator + fileName); boolean savedOK = localizableIO.exportSingleLanguageToDirectory(outFile, locale); if (savedOK) { String msg = UIRegistry.getLocalizedMessage("SchemaLocalizerFrame.EXPORTEDTO", locale.getDisplayName(), outFile.getAbsolutePath()); UIRegistry.displayInfoMsgDlg(msg); } else { String msg = UIRegistry.getLocalizedMessage("SchemaLocalizerFrame.EXPORTING_ERR", outFile.getAbsolutePath()); UIRegistry.showError(msg); } } } } }
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();/*from w ww.j ava 2s . com*/ 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.ku.brc.af.core.db.MySQLBackupService.java
@Override public void doRestore() { AppPreferences remotePrefs = AppPreferences.getLocalPrefs(); final String mysqlLoc = remotePrefs.get(MYSQL_LOC, getDefaultMySQLLoc()); final String backupLoc = remotePrefs.get(MYSQLBCK_LOC, getDefaultBackupLoc()); if (!(new File(mysqlLoc)).exists()) { UIRegistry.showLocalizedError("MySQLBackupService.MYSQL_NO_RESTORE", mysqlLoc); return;//from ww w. j a v a 2s . co m } File backupDir = new File(backupLoc); if (!backupDir.exists()) { if (!backupDir.mkdir()) { UIRegistry.showLocalizedError("MySQLBackupService.MYSQL_NO_BK_DIR", backupDir.getAbsoluteFile()); return; } } FileDialog dlg = new FileDialog(((Frame) UIRegistry.getTopWindow()), getResourceString("Open"), FileDialog.LOAD); dlg.setDirectory(backupLoc); dlg.setVisible(true); String dirStr = dlg.getDirectory(); String fileName = dlg.getFile(); if (StringUtils.isEmpty(dirStr) || StringUtils.isEmpty(fileName)) { return; } errorMsg = null; final String path = dirStr + fileName; final JStatusBar statusBar = UIRegistry.getStatusBar(); statusBar.setIndeterminate(STATUSBAR_NAME, true); String databaseName = DBConnection.getInstance().getDatabaseName(); SimpleGlassPane glassPane = UIRegistry .writeSimpleGlassPaneMsg(getLocalizedMessage("MySQLBackupService.RESTORING", databaseName), 24); doCompareBeforeRestore(path, glassPane); }
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 a v a 2s .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.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 *//*from w w w . j a v a2s .c o 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); } } }