📄 erdsavedialog.java
字号:
/* * ErdSaveDialog.java * * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */package org.executequery.gui.erd;import Acme.JPM.Encoders.GifEncoder;import com.sun.image.codec.jpeg.JPEGCodec;import com.sun.image.codec.jpeg.JPEGEncodeParam;import com.sun.image.codec.jpeg.JPEGImageEncoder;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Graphics2D;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.RenderingHints;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.geom.AffineTransform;import java.awt.image.BufferedImage;import java.io.File;import java.io.FileOutputStream;import java.io.BufferedOutputStream;import java.io.IOException;import java.io.OutputStreamWriter;import java.io.Writer;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JDialog;import javax.swing.JFileChooser;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JSlider;import javax.swing.JTextField;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import org.apache.batik.dom.GenericDOMImplementation;import org.apache.batik.svggen.ImageHandlerPNGEncoder;import org.apache.batik.svggen.SVGGeneratorContext;import org.apache.batik.svggen.SVGGraphics2D;import org.executequery.Constants;import org.executequery.GUIUtilities;import org.executequery.SystemUtilities;import org.executequery.components.FileChooserDialog;import org.underworldlabs.swing.NumberTextField;import org.underworldlabs.swing.FileSelector;import org.executequery.gui.SaveFunction;import org.underworldlabs.swing.GUIUtils;import org.underworldlabs.swing.util.SwingWorker;import org.underworldlabs.util.MiscUtils;import org.w3c.dom.DOMImplementation;import org.w3c.dom.Document;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the * release of version 3.0.0beta1 has meant a * resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * * @author Takis Diakoumis * @version $Revision: 1.6 $ * @date $Date: 2006/06/06 14:10:02 $ */public class ErdSaveDialog extends JDialog implements ActionListener, KeyListener, ChangeListener { /** Indicator for JPEG format */ private static final int JPEG_FORMAT = 1; /** Indicator for GIF format */ private static final int GIF_FORMAT = 2; /** Indicator for SVG format */ private static final int SVG_FORMAT = 4; /** Indicator for SVG format */ private static final int PNG_FORMAT = 3; /** Indicator for EQ format */ private static final int EQ_FORMAT = 0; /** Indicator for transparent background */ private static final int TRANSPARENT_BACKGROUND = 0; /** Indicator for white background */ private static final int WHITE_BACKGROUND = 1; /** The ERD parent panel */ private ErdViewerPanel parent; /** The open file's path - if any */ private String openPath; /** Image type combo-box */ private JComboBox imageTypeCombo; /** The quality text box */ private NumberTextField qualityTextField; /** The quality combo-box */ private JComboBox qualityCombo; /** The quality label */ private JLabel qualityLabel; /** The background label */ private JLabel backgroundLabel; /** The background combo-box */ private JComboBox backgroundCombo; /** The quality slider */ private JSlider qualitySlider; /** The path field */ private JTextField pathField; private JCheckBox svgFontCheckbox; /** The default file to save to */ private File defaultFile; private int savedResult; private ErdSaveDialog() { super(GUIUtilities.getParentFrame(), "Save ERD", true); savedResult = -1; try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public ErdSaveDialog(ErdViewerPanel parent) { this(); this.parent = parent; display(); } public ErdSaveDialog(ErdViewerPanel parent, File defaultFile) { this(); this.parent = parent; this.defaultFile = defaultFile; display(); } public ErdSaveDialog(ErdViewerPanel parent, String openPath) { this(); this.parent = parent; this.openPath = openPath; display(); } private void display() { pack(); this.setLocation(GUIUtilities.getLocationForDialog(this.getSize())); setVisible(true); } private void jbInit() throws Exception { qualityLabel = new JLabel("Quality:"); qualityTextField = new NumberTextField(2); qualityTextField.setValue(8); qualityTextField.addKeyListener(this); qualityCombo = new JComboBox(new String[]{"Low", "Medium", "High", "Maximum"}); qualityCombo.setSelectedIndex(2); Dimension fieldDim = new Dimension(50, 20); qualityTextField.setPreferredSize(fieldDim); Dimension comboDim = new Dimension(150, 23); qualityCombo.setPreferredSize(comboDim); qualitySlider = new JSlider(JSlider.HORIZONTAL, 1, 10, 8); qualitySlider.setMajorTickSpacing(5); qualitySlider.setMajorTickSpacing(1); qualitySlider.putClientProperty("JSlider.isFilled", Boolean.TRUE); qualitySlider.setPreferredSize(new Dimension(300, 30)); JPanel qualityPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(8,5,5,5); gbc.anchor = GridBagConstraints.NORTHWEST; qualityPanel.add(qualityLabel, gbc); gbc.gridx = 1; gbc.insets.left = 0; gbc.insets.top = 6; qualityPanel.add(qualityTextField, gbc); gbc.gridx = 2; gbc.insets.top = 5; qualityPanel.add(qualityCombo, gbc); gbc.insets.left = 5; gbc.insets.top = 0; gbc.insets.bottom = 0; gbc.weighty = 1.0; gbc.gridx = 0; gbc.gridy = 1; gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = GridBagConstraints.REMAINDER; qualityPanel.add(qualitySlider, gbc); qualityPanel.setBorder(BorderFactory.createTitledBorder("JPEG Options")); backgroundLabel = new JLabel("Background:"); backgroundCombo = new JComboBox(new String[]{"Transparent", "White"}); backgroundCombo.setPreferredSize(comboDim); backgroundCombo.setSelectedIndex(0); JPanel gifPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 20, 3)); gifPanel.add(backgroundLabel); gifPanel.add(backgroundCombo); gifPanel.setBorder(BorderFactory.createTitledBorder("GIF/PNG Options")); svgFontCheckbox = new JCheckBox("Render fonts as images"); JPanel svgPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 20, 3)); svgPanel.add(svgFontCheckbox); svgPanel.setBorder(BorderFactory.createTitledBorder("SVG Options")); imageTypeCombo = new JComboBox(new String[]{ "Execute Query ERD", "JPEG", "GIF", "PNG", "SVG"}); imageTypeCombo.setPreferredSize(comboDim); pathField = new JTextField(); pathField.setPreferredSize(fieldDim); JButton browseButton = new JButton("Browse"); JPanel base = new JPanel(new GridBagLayout()); gbc.fill = GridBagConstraints.NONE; gbc.insets.top = 7; gbc.insets.bottom = 5; gbc.weightx = 0; gbc.weighty = 0; gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; base.add(new JLabel("Format:"), gbc); gbc.insets.top = 5; gbc.gridx = 1; base.add(imageTypeCombo, gbc); gbc.gridx = 0; gbc.gridy++; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = GridBagConstraints.REMAINDER; base.add(qualityPanel, gbc); gbc.insets.top = 0; gbc.gridy++; base.add(gifPanel, gbc); gbc.gridy++; base.add(svgPanel, gbc); gbc.gridy++; gbc.gridx = 0; gbc.weightx = 0; gbc.gridwidth = 1; gbc.insets.top = 5; base.add(new JLabel("Path:"), gbc); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets.left = 0; gbc.insets.top = 8; gbc.gridx = 1; gbc.weightx = 1.0; base.add(pathField, gbc); gbc.gridx = 2; gbc.weightx = 0; gbc.gridwidth = 1; gbc.insets.top = 5; gbc.fill = GridBagConstraints.BOTH; base.add(browseButton, gbc); base.setBorder(BorderFactory.createEtchedBorder()); base.setPreferredSize(new Dimension(400, 300)); JButton saveButton = new JButton("Save"); JButton cancelButton = new JButton("Cancel"); cancelButton.setPreferredSize(Constants.BUTTON_SIZE); saveButton.setPreferredSize(Constants.BUTTON_SIZE); cancelButton.addActionListener(this); saveButton.addActionListener(this); browseButton.addActionListener(this); imageTypeCombo.addActionListener(this); qualityCombo.addActionListener(this); qualitySlider.addChangeListener(this); Container c = this.getContentPane(); c.setLayout(new GridBagLayout()); gbc.insets.top = 5; gbc.insets.left = 5; gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 2; c.add(base, gbc); gbc.gridwidth = 1; gbc.gridy = 1; gbc.anchor = GridBagConstraints.EAST; gbc.fill = GridBagConstraints.NONE; gbc.weighty = 0; gbc.insets.top = 0; c.add(saveButton, gbc); gbc.gridx = 1; gbc.weightx = 0; gbc.insets.left = 0; c.add(cancelButton, gbc); enableOptionsPanels(0); setResizable(false); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); } /** <p>Displays the file chooser dialog. */ private void showFileChooser() { String fileDescription = null; String fileExtension = null; int imageType = imageTypeCombo.getSelectedIndex(); if (imageType == EQ_FORMAT) { fileDescription = "Execute Query ERD Files"; fileExtension = "eqd"; } else if (imageType == JPEG_FORMAT) { fileDescription = "JPEG Files"; fileExtension = "jpeg"; } else if (imageType == SVG_FORMAT) { fileDescription = "SVG Files"; fileExtension = "svg"; } else if (imageType == PNG_FORMAT) { fileDescription = "PNG Files"; fileExtension = "png"; } else { fileDescription = "GIF Files"; fileExtension = "gif"; } FileSelector fs = new FileSelector(new String[]{fileExtension}, fileDescription); FileChooserDialog fileChooser = null; if (openPath != null) { fileChooser = new FileChooserDialog(openPath); } else { fileChooser = new FileChooserDialog(); } if (defaultFile != null && imageType == EQ_FORMAT) { fileChooser.setSelectedFile(defaultFile); } fileChooser.setDialogTitle("Select File..."); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); fileChooser.setFileFilter(fs); int result = fileChooser.showDialog(GUIUtilities.getParentFrame(), "Select"); String filePath = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -