Example usage for javax.swing JFrame getFocusTraversalKeys

List of usage examples for javax.swing JFrame getFocusTraversalKeys

Introduction

In this page you can find the example usage for javax.swing JFrame getFocusTraversalKeys.

Prototype

@SuppressWarnings("unchecked")
public Set<AWTKeyStroke> getFocusTraversalKeys(int id) 

Source Link

Document

Gets a focus traversal key for this Window.

Usage

From source file:visolate.Main.java

public static void main(final String[] argv) {

    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    options.addOption("x", "flip-x", false, "flip around x axis");
    options.addOption("y", "flip-y", false, "flip around y axis");
    options.addOption("a", "absolute", false, "use absolute cooridnates");
    options.addOption("d", "dpi", true, "dpi to use for rastering");
    options.addOption("A", "auto", false, "auto-mode (run, save and exit)");
    options.addOption("o", "outfile", true, "name of output file");

    options.addOption("h", "help", false, "display this help and exit");
    options.addOption("V", "version", false, "output version information and exit");

    CommandLine commandline;/*from www  .ja va 2  s.  c  o  m*/
    try {
        commandline = parser.parse(options, argv);
    } catch (ParseException e) {
        System.err.println(e.getLocalizedMessage());
        System.exit(1);
        return; // make it clear to the compiler that the following code is not run
    }

    if (commandline.hasOption("version")) {
        System.out.println(APPNAME);
        return;
    }

    if (commandline.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("visolate [options] [filename]", options);
        return;
    }

    if (commandline.getArgs().length >= 2) {
        System.err.println("Error: Too many arguments.");
        System.exit(1);
    }

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //TODO: Make look and feel options
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    final JFrame frame = new JFrame(APPNAME);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocation(DEF_LOC_X, DEF_LOC_Y);

    // Add the Enter key to the forward traversal keys, so fields loose focus
    // when using it in a field and we don't need to set up both, an ActionListener
    // and a FocusListener for each text/number field.
    Set<AWTKeyStroke> forwardKeys = new HashSet<AWTKeyStroke>(
            frame.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    Set<AWTKeyStroke> newForwardKeys = new HashSet<AWTKeyStroke>(forwardKeys);
    newForwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
    frame.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newForwardKeys);

    final Visolate visolate = new Visolate();
    visolate.commandline = commandline;

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(visolate, "Center");
    contentPane.setBackground(Color.WHITE);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {

            frame.pack();
            frame.setVisible(true);

            if (visolate.commandline.getArgs().length == 1) {
                visolate.loadFile(new File(visolate.commandline.getArgs()[0]));
            } else {
                visolate.loadDemo();
            }

            if (visolate.commandline.hasOption("auto")) {
                System.out.println("Automatic processing enabled! Files will be overwritten without asking!");
                visolate.auto_mode = true;
            }

            if (visolate.commandline.hasOption("dpi")) {
                visolate.getDisplay().setDPI(Integer.parseInt(visolate.commandline.getOptionValue("dpi")));
            }

            if (visolate.commandline.hasOption("flip-x")) {
                visolate.model.setFlipX(true);
            }
            if (visolate.commandline.hasOption("flip-y")) {
                visolate.model.setFlipY(true);
            }

            if (visolate.commandline.hasOption("absolute")) {
                visolate.setAbsoluteCoordinates(true);
            }

            if (visolate.commandline.hasOption("outfile")) {
                visolate.setGcodeFile(visolate.commandline.getOptionValue("outfile"));
            }

            if (visolate.commandline.hasOption("auto")) {
                System.out.println("now starting fixing topology due to automatic mode");
                visolate.processstatus = 1;

                visolate.fixTopology();
                // fix.Topology() calls visolate.processFinished after its done. Also, the Toolpathprocessor does so. processstatus discriminates this.
            }

            visolate.model.rebuild();
        }

    });
}