Back to index

wims  3.65+svn20090927
Public Member Functions | Private Attributes
ptolemy.gui.Query.QueryFileChooser Class Reference

Panel containing an entry box and file chooser. More...

Inheritance diagram for ptolemy.gui.Query.QueryFileChooser:
Inheritance graph
[legend]
Collaboration diagram for ptolemy.gui.Query.QueryFileChooser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 QueryFileChooser (String name, String defaultName, URI base, File startingDirectory, boolean allowFiles, boolean allowDirectories)
 QueryFileChooser (String name, String defaultName, URI base, File startingDirectory, boolean allowFiles, boolean allowDirectories, Color background, Color foreground)
void actionPerformed (ActionEvent e)
String getSelectedFileName ()
void setFileName (String name)

Private Attributes

URI _base
JTextField _entryBox
String _name
File _startingDirectory
boolean _allowFiles
boolean _allowDirectories

Detailed Description

Panel containing an entry box and file chooser.

Definition at line 1740 of file Query.java.


Constructor & Destructor Documentation

ptolemy.gui.Query.QueryFileChooser.QueryFileChooser ( String  name,
String  defaultName,
URI  base,
File  startingDirectory,
boolean  allowFiles,
boolean  allowDirectories 
) [inline]

Definition at line 1741 of file Query.java.

                                          {
            this(name, defaultName, base, startingDirectory, allowFiles,
                    allowDirectories, Color.white, Color.black);
        }
ptolemy.gui.Query.QueryFileChooser.QueryFileChooser ( String  name,
String  defaultName,
URI  base,
File  startingDirectory,
boolean  allowFiles,
boolean  allowDirectories,
Color  background,
Color  foreground 
) [inline]

Definition at line 1748 of file Query.java.

                                                                              {
            super(BoxLayout.X_AXIS);
            _base = base;
            _startingDirectory = startingDirectory;

            if (!allowFiles && !allowDirectories) {
                throw new IllegalArgumentException(
                        "QueryFileChooser: nothing to be chosen.");
            }

            _allowFiles = allowFiles;
            _allowDirectories = allowDirectories;
            _entryBox = new JTextField(defaultName, _width);
            _entryBox.setBackground(background);
            _entryBox.setForeground(foreground);

            JButton button = new JButton("Browse");
            button.addActionListener(this);
            add(_entryBox);
            add(button);

            // Add the listener last so that there is no notification
            // of the first value.
            _entryBox.addActionListener(new QueryActionListener(name));

            // Add a listener for loss of focus.  When the entry gains
            // and then loses focus, listeners are notified of an update,
            // but only if the value has changed since the last notification.
            // FIXME: Unfortunately, Java calls this listener some random
            // time after the window has been closed.  It is not even a
            // a queued event when the window is closed.  Thus, we have
            // a subtle bug where if you enter a value in a line, do not
            // hit return, and then click on the X to close the window,
            // the value is restored to the original, and then sometime
            // later, the focus is lost and the entered value becomes
            // the value of the parameter.  I don't know of any workaround.
            _entryBox.addFocusListener(new QueryFocusListener(name));

            _name = name;
        }

Member Function Documentation

void ptolemy.gui.Query.QueryFileChooser.actionPerformed ( ActionEvent  e) [inline]

Definition at line 1791 of file Query.java.

                                                   {
            // NOTE: If the last argument is null, then choose a default dir.
            JFileChooser fileChooser = new JFileChooser(_startingDirectory);
            fileChooser.setApproveButtonText("Select");

            // FIXME: The following doesn't have any effect.
            fileChooser.setApproveButtonMnemonic('S');

            if (_allowFiles && _allowDirectories) {
                fileChooser
                        .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            } else if (_allowFiles && !_allowDirectories) {
                // This is the default.
                fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            } else if (!_allowFiles && _allowDirectories) {
                fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            } else {
                // Usually, we would use InternalErrorException here,
                // but if we do, then this package would depend on kernel.util,
                // which causes problems when we ship Ptplot.
                throw new RuntimeException(
                        "QueryFileChooser: nothing to be chosen.");
            }

            int returnValue = fileChooser.showOpenDialog(Query.this);

            if (returnValue == JFileChooser.APPROVE_OPTION) {
                if (_base == null) {
                    // Absolute file name.
                    try {
                        _entryBox.setText(fileChooser.getSelectedFile()
                                .getCanonicalPath());
                    } catch (IOException ex) {
                        // If we can't get a path, then just use the name.
                        _entryBox.setText(fileChooser.getSelectedFile()
                                .getName());
                    }
                } else {
                    // Relative file name.
                    File selectedFile = fileChooser.getSelectedFile();

                    // FIXME: There is a bug here under Windows XP
                    // at least... Sometimes, the drive ID (like c:)
                    // is lower case, and sometimes it's upper case.
                    // When we open a MoML file, it's upper case.
                    // When we do "save as", it's lower case.
                    // This despite the fact that both use the same
                    // file browser to determine the file name.
                    // Beats me... Consequence is that if you save as,
                    // then the following relativize call doesn't work
                    // until you close and reopen the file.
                    try {
                        selectedFile = selectedFile.getCanonicalFile();
                    } catch (IOException ex) {
                        // Ignore, since we can't do much about it anyway.
                    }

                    URI relativeURI = _base.relativize(selectedFile.toURI());
                    _entryBox.setText(relativeURI.toString());
                }

                _notifyListeners(_name);
            }
        }

Here is the call graph for this function:

Definition at line 1856 of file Query.java.

                                            {
            return _entryBox.getText();
        }
void ptolemy.gui.Query.QueryFileChooser.setFileName ( String  name) [inline]

Definition at line 1860 of file Query.java.

                                             {
            _entryBox.setText(name);
        }

Member Data Documentation

Definition at line 1874 of file Query.java.

Definition at line 1872 of file Query.java.

Definition at line 1864 of file Query.java.

Definition at line 1866 of file Query.java.

Definition at line 1868 of file Query.java.

Definition at line 1870 of file Query.java.


The documentation for this class was generated from the following file: