001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.ideTools;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/ideTools/SaveDialog.java $
024: //$Author: Dan $
025: //$Revision: 19 $
026: //$Modtime: 11/08/04 10:46a $
027: /////////////////////////
028: import java.awt.*;
029: import java.awt.event.*;
030: import java.io.File;
031:
032: import javax.swing.*;
033:
034: public class SaveDialog extends javax.swing.JDialog implements
035: ActionListener, WindowListener {
036: JTextField _fileName;
037: boolean _cancel;
038: String _fileText;
039: JFrame _owner;
040:
041: public SaveDialog(JFrame owner, String filename, String fileText) {
042: super (owner, "Save Generated Code", true);
043: _owner = owner;
044: _fileText = fileText;
045:
046: int width = 550;
047: int height = 200;
048: Dimension frameBounds = Toolkit.getDefaultToolkit()
049: .getScreenSize();
050: int x = (frameBounds.width - width) / 2;
051: int y = (frameBounds.height - height) / 2;
052:
053: setBounds(x, y, width, height);
054:
055: Panel data = new Panel(new java.awt.FlowLayout(
056: FlowLayout.CENTER));
057: JButton file = new JButton("Select");
058: file.addActionListener(this );
059: data.add(DialogComponentFactory.makeLabel("File Name:"));
060: data.add(_fileName = new JTextField(filename, 32));
061: data.add(file);
062:
063: JButton view = new JButton("View");
064: view.addActionListener(this );
065: JButton save = new JButton("Save");
066: save.addActionListener(this );
067: JButton cancel = new JButton("Cancel");
068: cancel.addActionListener(this );
069: JPanel buttonBar = new JPanel(new FlowLayout());
070: buttonBar.add(view);
071: buttonBar.add(save);
072: buttonBar.add(cancel);
073: buttonBar.setAlignmentX(Component.CENTER_ALIGNMENT);
074:
075: Box box = Box.createVerticalBox();
076: box.add(Box.createRigidArea(new Dimension(0, 20)));
077: box
078: .add(DialogComponentFactory
079: .makeLabel("Class generated successfully. Please specifiy a file to save as."));
080: box.add(Box.createRigidArea(new Dimension(0, 20)));
081: box.add(data);
082: box.add(Box.createRigidArea(new Dimension(0, 10)));
083: box.add(buttonBar);
084: //box.setAlignmentX(Component.CENTER_ALIGNMENT);
085:
086: getContentPane().add(box);
087:
088: addWindowListener(this );
089: setVisible(true);
090: }
091:
092: public void actionPerformed(ActionEvent e) {
093: if (((JButton) e.getSource()).getText().equals("View")) {
094: IDETool.displayCutPasteDialog(_fileText);
095: return;
096: } else if (((JButton) e.getSource()).getText().equals("Select")) {
097: JFileChooser c = new JFileChooser();
098: c.setCurrentDirectory(new File(_fileName.getText()));
099: if (c.showSaveDialog(this ) == JFileChooser.APPROVE_OPTION)
100: _fileName
101: .setText(c.getSelectedFile().getAbsolutePath());
102: return;
103: }
104: if (((JButton) e.getSource()).getText().equals("Cancel"))
105: _cancel = true;
106: else
107: _cancel = false;
108: setVisible(false);
109: }
110:
111: /**
112: * Returns true if the user clicked the cancel button to exit the dialog
113: */
114: public boolean getCancel() {
115: return _cancel;
116: }
117:
118: /**
119: * Returns the filename that the user specified to save the controller text under
120: */
121: public String getFileName() {
122: return _fileName.getText();
123: }
124:
125: public void windowActivated(WindowEvent e) {
126: _fileName.grabFocus();
127: }
128:
129: public void windowClosed(WindowEvent e) {
130: }
131:
132: public void windowClosing(WindowEvent e) {
133: }
134:
135: public void windowDeactivated(WindowEvent e) {
136: }
137:
138: public void windowDeiconified(WindowEvent e) {
139: }
140:
141: public void windowIconified(WindowEvent e) {
142: }
143:
144: public void windowOpened(WindowEvent e) {
145: }
146: }
|