Search in sources :

Example 46 with FileDialog

use of java.awt.FileDialog in project voltdb by VoltDB.

the class DatabaseManager method actionPerformed.

public void actionPerformed(ActionEvent ev) {
    String s = ev.getActionCommand();
    if (s == null) {
        if (ev.getSource() instanceof MenuItem) {
            MenuItem i;
            s = ((MenuItem) ev.getSource()).getLabel();
        }
    }
    if (s == null) {
    } else if (s.equals("Execute")) {
        execute();
    } else if (s.equals("Clear")) {
        clear();
    } else if (s.equals("Exit")) {
        windowClosing(null);
    } else if (s.equals("Transfer")) {
        Transfer.work(null);
    } else if (s.equals("Dump")) {
        Transfer.work(new String[] { "-d" });
    } else if (s.equals("Restore")) {
        Transfer.work(new String[] { "-r" });
        refreshTree();
    } else if (s.equals("Logging on")) {
        JavaSystem.setLogToSystem(true);
    } else if (s.equals("Logging off")) {
        JavaSystem.setLogToSystem(false);
    } else if (s.equals("Help")) {
        showHelp(new String[] { "", HELP_TEXT });
    } else if (s.equals("About")) {
        showHelp(new String[] { "", ABOUT_TEXT });
    } else if (s.equals("Refresh Tree")) {
        refreshTree();
    } else if (s.startsWith("#")) {
        int i = Integer.parseInt(s.substring(1));
        txtCommand.setText(sRecent[i]);
    } else if (s.equals("Connect...")) {
        connect(ConnectionDialog.createConnection(fMain, "Connect"));
        refreshTree();
    } else if (s.equals("Results in Grid")) {
        iResult = 0;
        pResult.removeAll();
        pResult.add("Center", gResult);
        pResult.doLayout();
    } else if (s.equals("Open Script...")) {
        FileDialog f = new FileDialog(fMain, "Open Script", FileDialog.LOAD);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String file = f.getFile();
        if (file != null) {
            StringBuffer buf = new StringBuffer();
            ifHuge = DatabaseManagerCommon.readFile(f.getDirectory() + file);
            if (4096 <= ifHuge.length()) {
                buf.append("This huge file cannot be edited.\n Please execute or clear\n");
                txtCommand.setText(buf.toString());
            } else {
                txtCommand.setText(ifHuge);
            }
        }
    } else if (s.equals("Save Script...")) {
        FileDialog f = new FileDialog(fMain, "Save Script", FileDialog.SAVE);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String file = f.getFile();
        if (file != null) {
            DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtCommand.getText());
        }
    } else if (s.equals("Save Result csv...")) {
        FileDialog f = new FileDialog(fMain, "Save Result CSV", FileDialog.SAVE);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String dir = f.getDirectory();
        String file = f.getFile();
        if (dir != null) {
            file = dir + "/" + file;
        }
        if (file != null) {
            showResultInText();
            saveAsCsv(file);
        }
    } else if (s.equals("Save Result...")) {
        FileDialog f = new FileDialog(fMain, "Save Result", FileDialog.SAVE);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String file = f.getFile();
        if (file != null) {
            showResultInText();
            DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtResult.getText());
        }
    } else if (s.equals("Results in Text")) {
        iResult = 1;
        pResult.removeAll();
        pResult.add("Center", txtResult);
        pResult.doLayout();
        showResultInText();
    } else if (s.equals("AutoCommit on")) {
        try {
            cConn.setAutoCommit(true);
        } catch (SQLException e) {
        }
    } else if (s.equals("AutoCommit off")) {
        try {
            cConn.setAutoCommit(false);
        } catch (SQLException e) {
        }
    } else if (s.equals("Enlarge Tree")) {
        Dimension d = tTree.getMinimumSize();
        d.width += 20;
        tTree.setMinimumSize(d);
        fMain.pack();
    } else if (s.equals("Shrink Tree")) {
        Dimension d = tTree.getMinimumSize();
        d.width -= 20;
        if (d.width >= 0) {
            tTree.setMinimumSize(d);
        }
        fMain.pack();
    } else if (s.equals("Enlarge Command")) {
        txtCommand.setRows(txtCommand.getRows() + 1);
        fMain.pack();
    } else if (s.equals("Shrink Command")) {
        int i = txtCommand.getRows() - 1;
        txtCommand.setRows(i < 1 ? 1 : i);
        fMain.pack();
    } else if (s.equals("Commit")) {
        try {
            cConn.commit();
        } catch (SQLException e) {
        }
    } else if (s.equals("Insert test data")) {
        insertTestData();
    } else if (s.equals("Rollback")) {
        try {
            cConn.rollback();
        } catch (SQLException e) {
        }
    } else if (s.equals("Disable MaxRows")) {
        try {
            sStatement.setMaxRows(0);
        } catch (SQLException e) {
        }
    } else if (s.equals("Set MaxRows to 100")) {
        try {
            sStatement.setMaxRows(100);
        } catch (SQLException e) {
        }
    } else if (s.equals("SELECT")) {
        showHelp(DatabaseManagerCommon.selectHelp);
    } else if (s.equals("INSERT")) {
        showHelp(DatabaseManagerCommon.insertHelp);
    } else if (s.equals("UPDATE")) {
        showHelp(DatabaseManagerCommon.updateHelp);
    } else if (s.equals("DELETE")) {
        showHelp(DatabaseManagerCommon.deleteHelp);
    } else if (s.equals("CREATE TABLE")) {
        showHelp(DatabaseManagerCommon.createTableHelp);
    } else if (s.equals("DROP TABLE")) {
        showHelp(DatabaseManagerCommon.dropTableHelp);
    } else if (s.equals("CREATE INDEX")) {
        showHelp(DatabaseManagerCommon.createIndexHelp);
    } else if (s.equals("DROP INDEX")) {
        showHelp(DatabaseManagerCommon.dropIndexHelp);
    } else if (s.equals("CHECKPOINT")) {
        showHelp(DatabaseManagerCommon.checkpointHelp);
    } else if (s.equals("SCRIPT")) {
        showHelp(DatabaseManagerCommon.scriptHelp);
    } else if (s.equals("SHUTDOWN")) {
        showHelp(DatabaseManagerCommon.shutdownHelp);
    } else if (s.equals("SET")) {
        showHelp(DatabaseManagerCommon.setHelp);
    } else if (s.equals("Test Script")) {
        showHelp(DatabaseManagerCommon.testHelp);
    }
}
Also used : SQLException(java.sql.SQLException) MenuItem(java.awt.MenuItem) Dimension(java.awt.Dimension) FileDialog(java.awt.FileDialog)

Example 47 with FileDialog

use of java.awt.FileDialog in project voltdb by VoltDB.

the class ZaurusDatabaseManager method actionPerformed.

/**
     * Method declaration
     *
     *
     * @param ev
     */
public void actionPerformed(ActionEvent ev) {
    String s = ev.getActionCommand();
    if (s == null) {
        if (ev.getSource() instanceof MenuItem) {
            MenuItem i;
            s = ((MenuItem) ev.getSource()).getLabel();
        }
    }
    if (s.equals("Execute")) {
        execute();
        layoutCard.show(pCard, "result");
    } else if (s.equals("Tree")) {
        layoutCard.show(pCard, "tree");
    } else if (s.equals("Command")) {
        layoutCard.show(pCard, "command");
    } else if (s.equals("Result")) {
        layoutCard.show(pCard, "result");
    } else if (s.equals("Editor")) {
        layoutCard.show(pCard, "editor");
    } else if (s.equals("Exit")) {
        windowClosing(null);
    } else if (s.equals("Logging on")) {
        JavaSystem.setLogToSystem(true);
    } else if (s.equals("Logging off")) {
        JavaSystem.setLogToSystem(false);
    } else if (s.equals("Refresh Tree")) {
        refreshTree();
        layoutCard.show(pCard, "tree");
    } else if (s.startsWith("#")) {
        int i = Integer.parseInt(s.substring(1));
        txtCommand.setText(sRecent[i]);
    } else if (s.equals("Connect...")) {
        connect(ZaurusConnectionDialog.createConnection(fMain, "Connect", new Insets(defWidth, defHeight, defLocX, defLocY)));
        refreshTree();
        layoutCard.show(pCard, "tree");
    } else if (s.equals("View Tree")) {
        layoutCard.show(pCard, "tree");
    } else if (s.equals("View Command")) {
        layoutCard.show(pCard, "command");
    } else if (s.equals("View Result")) {
        layoutCard.show(pCard, "result");
    } else if (s.equals("View Editor")) {
        layoutCard.show(pCard, "editor");
    } else if (s.equals("Results in Grid")) {
        iResult = 0;
        pResult.removeAll();
        pResult.add("Center", gResult);
        pResult.doLayout();
        layoutCard.show(pCard, "result");
    } else if (s.equals("Open Script...")) {
        FileDialog f = new FileDialog(fMain, "Open Script", FileDialog.LOAD);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String file = f.getFile();
        if (file != null) {
            txtCommand.setText(DatabaseManagerCommon.readFile(f.getDirectory() + file));
        }
        layoutCard.show(pCard, "command");
    } else if (s.equals("Save Script...")) {
        FileDialog f = new FileDialog(fMain, "Save Script", FileDialog.SAVE);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String file = f.getFile();
        if (file != null) {
            DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtCommand.getText());
        }
    } else if (s.equals("Save Result...")) {
        FileDialog f = new FileDialog(fMain, "Save Result", FileDialog.SAVE);
        // (ulrivo): set default directory if set from command line
        if (defDirectory != null) {
            f.setDirectory(defDirectory);
        }
        f.show();
        String file = f.getFile();
        if (file != null) {
            showResultInText();
            DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtResult.getText());
        }
    } else if (s.equals("Results in Text")) {
        iResult = 1;
        pResult.removeAll();
        pResult.add("Center", txtResult);
        pResult.doLayout();
        showResultInText();
        layoutCard.show(pCard, "result");
    } else if (s.equals("AutoCommit on")) {
        try {
            cConn.setAutoCommit(true);
        } catch (SQLException e) {
        }
    } else if (s.equals("AutoCommit off")) {
        try {
            cConn.setAutoCommit(false);
        } catch (SQLException e) {
        }
    } else if (s.equals("Commit")) {
        try {
            cConn.commit();
        } catch (SQLException e) {
        }
    } else if (s.equals("Insert test data")) {
        insertTestData();
        layoutCard.show(pCard, "result");
    } else if (s.equals("Rollback")) {
        try {
            cConn.rollback();
        } catch (SQLException e) {
        }
    } else if (s.equals("Disable MaxRows")) {
        try {
            sStatement.setMaxRows(0);
        } catch (SQLException e) {
        }
    } else if (s.equals("Set MaxRows to 100")) {
        try {
            sStatement.setMaxRows(100);
        } catch (SQLException e) {
        }
    } else if (s.equals("SELECT")) {
        showHelp(DatabaseManagerCommon.selectHelp);
    } else if (s.equals("INSERT")) {
        showHelp(DatabaseManagerCommon.insertHelp);
    } else if (s.equals("UPDATE")) {
        showHelp(DatabaseManagerCommon.updateHelp);
    } else if (s.equals("DELETE")) {
        showHelp(DatabaseManagerCommon.deleteHelp);
    } else if (s.equals("CREATE TABLE")) {
        showHelp(DatabaseManagerCommon.createTableHelp);
    } else if (s.equals("DROP TABLE")) {
        showHelp(DatabaseManagerCommon.dropTableHelp);
    } else if (s.equals("CREATE INDEX")) {
        showHelp(DatabaseManagerCommon.createIndexHelp);
    } else if (s.equals("DROP INDEX")) {
        showHelp(DatabaseManagerCommon.dropIndexHelp);
    } else if (s.equals("CHECKPOINT")) {
        showHelp(DatabaseManagerCommon.checkpointHelp);
    } else if (s.equals("SCRIPT")) {
        showHelp(DatabaseManagerCommon.scriptHelp);
    } else if (s.equals("SHUTDOWN")) {
        showHelp(DatabaseManagerCommon.shutdownHelp);
    } else if (s.equals("SET")) {
        showHelp(DatabaseManagerCommon.setHelp);
    } else if (s.equals("Test Script")) {
        showHelp(DatabaseManagerCommon.testHelp);
    } else if (s.equals("Show HTML-Help in browser")) {
        try {
            System.out.println("Starting Opera on index.html");
            Runtime.getRuntime().exec(new String[] { "opera", "/home/QtPalmtop/help/html/hsqldb/index.html" });
        } catch (IOException e) {
            System.out.println("A problem with Opera occured.");
        }
    }
}
Also used : Insets(java.awt.Insets) SQLException(java.sql.SQLException) MenuItem(java.awt.MenuItem) IOException(java.io.IOException) FileDialog(java.awt.FileDialog)

Example 48 with FileDialog

use of java.awt.FileDialog in project voltdb by VoltDB.

the class Transfer method actionPerformed.

/**
     * Method declaration
     *
     *
     * @param ev
     */
public void actionPerformed(ActionEvent ev) {
    if (ev.getSource() instanceof TextField) {
        saveTable();
        return;
    }
    String s = ev.getActionCommand();
    MenuItem i = new MenuItem();
    if (s == null) {
        if (ev.getSource() instanceof MenuItem) {
            i = (MenuItem) ev.getSource();
            s = i.getLabel();
        }
    }
    if (s == null) {
    }
    if (s.equals("Start Transfer") || s.equals("ReStart Transfer")) {
        bStart.setLabel("ReStart Transfer");
        bStart.invalidate();
        CurrentTransfer = 0;
        CurrentAlter = 0;
        transfer();
    } else if (s.equals("Continue Transfer")) {
        transfer();
    } else if (s.equals("Start Dump") || s.equals("Start Restore")) {
        CurrentTransfer = 0;
        CurrentAlter = 0;
        transfer();
    } else if (s.equals("Quit")) {
        exit();
    } else if (s.indexOf("Select Schema") >= 0) {
        String[] selection = lTable.getSelectedItems();
        if ((selection == null) || (selection.length == 0)) {
            return;
        }
        if (iSelectionStep == Transfer.SELECT_SOURCE_SCHEMA) {
            sSourceSchemas = selection;
        } else {
            sDestSchema = selection[0];
        }
        if (iTransferMode == TRFM_DUMP) {
            iSelectionStep = Transfer.SELECT_SOURCE_TABLES;
        } else {
            iSelectionStep++;
        }
        ProcessNextStep();
    } else if (s.indexOf("Select Catalog") >= 0) {
        String selection = lTable.getSelectedItem();
        if ((selection == null) || (selection.equals(""))) {
            return;
        }
        if (iSelectionStep == Transfer.SELECT_SOURCE_CATALOG) {
            sSourceCatalog = selection;
            sSourceSchemas = null;
        } else {
            sDestCatalog = selection;
            sDestSchema = null;
            try {
                targetDb.setCatalog(sDestCatalog);
            } catch (Exception ex) {
                trace("Catalog " + sDestCatalog + " could not be selected in the target database");
                sDestCatalog = null;
            }
        }
        iSelectionStep++;
        ProcessNextStep();
    } else if (s.equals("Insert 10 rows only")) {
        iMaxRows = 10;
    } else if (s.equals("Insert 1000 rows only")) {
        iMaxRows = 1000;
    } else if (s.equals("Insert all rows")) {
        iMaxRows = 0;
    } else if (s.equals("Load Settings...")) {
        FileDialog f = new FileDialog(fMain, "Load Settings", FileDialog.LOAD);
        f.show();
        String file = f.getDirectory() + f.getFile();
        if (file != null) {
            LoadPrefs(file);
            displayTable(tCurrent);
        }
    } else if (s.equals("Save Settings...")) {
        FileDialog f = new FileDialog(fMain, "Save Settings", FileDialog.SAVE);
        f.show();
        String file = f.getDirectory() + f.getFile();
        if (file != null) {
            SavePrefs(file);
        }
    } else if (s.equals("Exit")) {
        windowClosing(null);
    }
}
Also used : TextField(java.awt.TextField) MenuItem(java.awt.MenuItem) FileDialog(java.awt.FileDialog)

Example 49 with FileDialog

use of java.awt.FileDialog in project jdk8u_jdk by JetBrains.

the class WPrinterJob method displayNativeDialog.

private boolean displayNativeDialog() {
    // "attributes" is required for getting the updated attributes
    if (attributes == null) {
        return false;
    }
    DialogOwner dlgOwner = (DialogOwner) attributes.get(DialogOwner.class);
    Frame ownerFrame = (dlgOwner != null) ? dlgOwner.getOwner() : null;
    WPrintDialog dialog = new WPrintDialog(ownerFrame, this);
    dialog.setRetVal(false);
    dialog.setVisible(true);
    boolean prv = dialog.getRetVal();
    dialog.dispose();
    Destination dest = (Destination) attributes.get(Destination.class);
    if ((dest == null) || !prv) {
        return prv;
    } else {
        String title = null;
        String strBundle = "sun.print.resources.serviceui";
        ResourceBundle rb = ResourceBundle.getBundle(strBundle);
        try {
            title = rb.getString("dialog.printtofile");
        } catch (MissingResourceException e) {
        }
        FileDialog fileDialog = new FileDialog(ownerFrame, title, FileDialog.SAVE);
        URI destURI = dest.getURI();
        // Old code destURI.getPath() would return null for "file:out.prn"
        // so we use getSchemeSpecificPart instead.
        String pathName = (destURI != null) ? destURI.getSchemeSpecificPart() : null;
        if (pathName != null) {
            File file = new File(pathName);
            fileDialog.setFile(file.getName());
            File parent = file.getParentFile();
            if (parent != null) {
                fileDialog.setDirectory(parent.getPath());
            }
        } else {
            fileDialog.setFile("out.prn");
        }
        fileDialog.setVisible(true);
        String fileName = fileDialog.getFile();
        if (fileName == null) {
            fileDialog.dispose();
            return false;
        }
        String fullName = fileDialog.getDirectory() + fileName;
        File f = new File(fullName);
        File pFile = f.getParentFile();
        while ((f.exists() && (!f.isFile() || !f.canWrite())) || ((pFile != null) && (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
            (new PrintToFileErrorDialog(ownerFrame, ServiceDialog.getMsg("dialog.owtitle"), ServiceDialog.getMsg("dialog.writeerror") + " " + fullName, ServiceDialog.getMsg("button.ok"))).setVisible(true);
            fileDialog.setVisible(true);
            fileName = fileDialog.getFile();
            if (fileName == null) {
                fileDialog.dispose();
                return false;
            }
            fullName = fileDialog.getDirectory() + fileName;
            f = new File(fullName);
            pFile = f.getParentFile();
        }
        fileDialog.dispose();
        attributes.add(new Destination(f.toURI()));
        return true;
    }
}
Also used : Destination(javax.print.attribute.standard.Destination) Frame(java.awt.Frame) MissingResourceException(java.util.MissingResourceException) DialogOwner(sun.print.DialogOwner) ResourceBundle(java.util.ResourceBundle) FileDialog(java.awt.FileDialog) URI(java.net.URI) File(java.io.File)

Example 50 with FileDialog

use of java.awt.FileDialog in project jdk8u_jdk by JetBrains.

the class SubjDelegPerm method displaySaveAsDialog.

/**
     * perform SAVE AS
     */
void displaySaveAsDialog(int nextEvent) {
    // pop up a dialog box for the user to enter a filename.
    FileDialog fd = new FileDialog(tw, PolicyTool.getMessage("Save.As"), FileDialog.SAVE);
    fd.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            e.getWindow().setVisible(false);
        }
    });
    fd.setVisible(true);
    // see if the user hit cancel
    if (fd.getFile() == null || fd.getFile().equals(""))
        return;
    // get the entered filename
    File saveAsFile = new File(fd.getDirectory(), fd.getFile());
    String filename = saveAsFile.getPath();
    fd.dispose();
    try {
        // save the policy entries to a file
        tool.savePolicy(filename);
        // display status
        MessageFormat form = new MessageFormat(PolicyTool.getMessage("Policy.successfully.written.to.filename"));
        Object[] source = { filename };
        tw.displayStatusDialog(null, form.format(source));
        // display the new policy filename
        JTextField newFilename = (JTextField) tw.getComponent(ToolWindow.MW_FILENAME_TEXTFIELD);
        newFilename.setText(filename);
        tw.setVisible(true);
        // now continue with the originally requested command
        // (QUIT, NEW, or OPEN)
        userSaveContinue(tool, tw, this, nextEvent);
    } catch (FileNotFoundException fnfe) {
        if (filename == null || filename.equals("")) {
            tw.displayErrorDialog(null, new FileNotFoundException(PolicyTool.getMessage("null.filename")));
        } else {
            tw.displayErrorDialog(null, fnfe);
        }
    } catch (Exception ee) {
        tw.displayErrorDialog(null, ee);
    }
}
Also used : MessageFormat(java.text.MessageFormat) FileDialog(java.awt.FileDialog) MalformedURLException(java.net.MalformedURLException) ExpandException(sun.security.util.PropertyExpander.ExpandException) CertificateException(java.security.cert.CertificateException)

Aggregations

FileDialog (java.awt.FileDialog)78 File (java.io.File)43 JFileChooser (javax.swing.JFileChooser)18 Frame (java.awt.Frame)16 IOException (java.io.IOException)16 FilenameFilter (java.io.FilenameFilter)10 Dialog (java.awt.Dialog)8 FileFilter (javax.swing.filechooser.FileFilter)7 FileOutputStream (java.io.FileOutputStream)5 PrintStream (java.io.PrintStream)4 Button (java.awt.Button)3 Dimension (java.awt.Dimension)3 MenuItem (java.awt.MenuItem)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 MalformedURLException (java.net.MalformedURLException)3 SQLException (java.sql.SQLException)3 JLabel (javax.swing.JLabel)3 Component (java.awt.Component)2 GridLayout (java.awt.GridLayout)2