Esempio n. 1
0
 public static void main(String[] argv) throws NoSuchMethodException {
   f = new JFrame();
   Container c = f.getContentPane();
   c.setLayout(new BorderLayout());
   c.add(new WordListScreen(null), BorderLayout.CENTER);
   f.pack();
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   showFrame(true);
 }
  @SuppressWarnings("restriction")
  public static void enableAppleFullscreen(JFrame window) {
    window.pack();
    window.setVisible(true);
    setAutoRequestFocus(window, true);
    if (javaVersion()
        == 7) { // work around bug in java 7 where top bar space is blank unless undecorated
      FullScreenUtilities.addFullScreenListenerTo(
          window,
          new FullScreenAdapter() {
            boolean working = false;

            @Override
            public void windowEnteredFullScreen(AppEvent.FullScreenEvent e) {
              if (working) {
                working = false;
                return;
              }
              ;
              if (!((JFrame) e.getWindow()).isUndecorated()) {
                working = true;
                Application.getApplication().requestToggleFullScreen(e.getWindow());
              }
            }

            @Override
            public void windowExitedFullScreen(AppEvent.FullScreenEvent e) {
              if (working) {
                e.getWindow().dispose();
                ((JFrame) e.getWindow()).setUndecorated(true);
                e.getWindow().pack();
                e.getWindow().setVisible(true);
                Application.getApplication().requestToggleFullScreen(e.getWindow());
                return;
              }
              ;
              if (((JFrame) e.getWindow()).isUndecorated()) {
                e.getWindow().dispose();
                ((JFrame) e.getWindow()).setUndecorated(false);
                e.getWindow().setVisible(true);
              }
            }
          });
    }
    FullScreenUtilities.setWindowCanFullScreen(window, true);
  }
 // Adds a new keybinding equal to the character provided and the default super key (ctrl/cmd)
 private static void bind(int Character) {
   frame
       .getRootPane()
       .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
       .put(
           KeyStroke.getKeyStroke(Character, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
           "console");
 }
 private static GraphicsDevice getScreen(JFrame window) {
   for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
     if (gd.getDefaultConfiguration().getBounds().contains(window.getLocationOnScreen()))
       return gd;
   }
   System.err.println(
       window + " does not appear to be on any screen; fullscreening onto default screen");
   return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
 }
 public static void enableFullscreen(final JFrame window, final boolean useExclusiveFullscreen) {
   window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   if (appleEawtAvailable()
       && appleOSVersion() >= 7
       && // lion and above
       javaVersion() >= 7) { // java 7 and above
     System.out.println("trying to apple fullscreen");
     enableAppleFullscreen(window);
   }
   window.addKeyListener(
       new KeyAdapter() {
         @Override
         public void keyReleased(KeyEvent e) {
           if (e.getKeyCode() == KeyEvent.VK_F11) {
             e.consume();
             GraphicsDevice gd = getScreen(window);
             window.setVisible(false); // hide, so we can do stuff
             if (window.isUndecorated()) { // we are fullscreen, we should become unfullscreen
               window.setUndecorated(false);
               if (window.equals(
                   gd.getFullScreenWindow())) { // we used exclusive mode to go fullscreen
                 gd.setFullScreenWindow(null);
               } else { // we just got really big
                 window.setExtendedState(JFrame.NORMAL);
               }
             } else { // we aren't fullscreen, we should become fullscreen
               if (javaVersion() >= 7) setAutoRequestFocus(window, true);
               window.setUndecorated(true);
               window.setBounds(gd.getDefaultConfiguration().getBounds());
               if (useExclusiveFullscreen) {
                 gd.setFullScreenWindow(window);
               } else {
                 window.setExtendedState(JFrame.MAXIMIZED_BOTH);
                 window.toFront();
               }
             }
             window.pack();
             window.setVisible(true);
           }
         }
       });
 }
Esempio n. 6
0
 public static void openFrame(Object frame) {
   boolean packFrame = false;
   if (packFrame) {
     ((JFrame) frame).pack();
   } else {
     ((JFrame) frame).validate();
   }
   // Center the window
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   Dimension frameSize = ((JFrame) frame).getSize();
   if (frameSize.height > screenSize.height) {
     frameSize.height = screenSize.height;
   }
   if (frameSize.width > screenSize.width) {
     frameSize.width = screenSize.width;
   }
   ((JFrame) frame)
       .setLocation(
           (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
   ((JFrame) frame).setVisible(true);
 }
  public void init() {
    // 添加按钮
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(okButton);

    mainPanel.setLayout(new GridLayout(0, 3));
    mainWin.add(mainPanel, BorderLayout.CENTER);

    JFormattedTextField intField0 =
        new JFormattedTextField(
            new InternationalFormatter(NumberFormat.getIntegerInstance()) {
              protected DocumentFilter getDocumentFilter() {
                return new NumberFilter();
              }
            });
    intField0.setValue(100);
    addRow("只接受数字的文本框", intField0);

    JFormattedTextField intField1 = new JFormattedTextField(NumberFormat.getIntegerInstance());
    intField1.setValue(new Integer(100));
    // 添加输入校验器
    intField1.setInputVerifier(new FormattedTextFieldVerifier());
    addRow("带输入校验器的文本框", intField1);

    // 创建自定义格式器对象
    IPAddressFormatter ipFormatter = new IPAddressFormatter();
    ipFormatter.setOverwriteMode(false);
    // 以自定义格式器对象创建格式化文本框
    JFormattedTextField ipField = new JFormattedTextField(ipFormatter);
    ipField.setValue(new byte[] {(byte) 192, (byte) 168, 4, 1});
    addRow("IP地址格式", ipField);

    mainWin.add(buttonPanel, BorderLayout.SOUTH);
    mainWin.pack();
    mainWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainWin.setVisible(true);
  }
Esempio n. 8
0
  /**
   * Test code.
   *
   * @param args First arg is the class name to create
   */
  public static void main(String[] args) {

    try {
      Class type = null;
      Object instance = null;
      if (args.length > 0) {
        type = Class.forName(args[0]);
        instance = type.newInstance();
      } else {
        type = TestClass.class;
        instance = new TestClass();
        ((TestClass) instance).setObject(new TestClass());
      }

      JFrame f = new JFrame(type.getName());
      DynamicCustomizer custom = new DynamicCustomizer(type);
      custom.setObject(instance);
      f.getContentPane().add(new JScrollPane(custom));
      f.pack();
      f.setVisible(true);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
 public static void setAutoRequestFocus(JFrame window, boolean autoRequestFocus) {
   try {
     Method setAutoRequestFocusMethod =
         window.getClass().getMethod("setAutoRequestFocus", boolean.class);
     setAutoRequestFocusMethod.invoke(window, autoRequestFocus);
   } catch (NoSuchMethodException e) {
     throw new RuntimeException(e);
   } catch (SecurityException e) {
     throw new RuntimeException(e);
   } catch (IllegalAccessException e) {
     throw new RuntimeException(e);
   } catch (IllegalArgumentException e) {
     throw new RuntimeException(e);
   } catch (InvocationTargetException e) {
     throw new RuntimeException(e);
   }
 }
Esempio n. 10
0
 @Override
 public void dispose() {
   super.dispose();
   if (VncViewer.osEID()) cleanupExtInputHelper();
 }
 public static void toFullScreen(
     JFrame window,
     GraphicsDevice gd,
     boolean tryAppleFullscreen,
     boolean tryExclusiveFullscreen) {
   if (appleEawtAvailable()
       && tryAppleFullscreen
       && appleOSVersion() >= 7
       && // lion and above
       javaVersion() >= 7) { // java 7 and above
     System.out.println("trying to apple fullscreen");
     enableAppleFullscreen(window);
     doAppleFullscreen(window);
   } else if (appleEawtAvailable()
       && // Snow Leopard and below OR apple java 6 and below TODO: test this on SL
       tryExclusiveFullscreen
       && gd.isFullScreenSupported()) {
     if (javaVersion() >= 7) setAutoRequestFocus(window, true);
     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     window.setUndecorated(true);
     // window.setExtendedState(JFrame.MAXIMIZED_BOTH);
     gd.setFullScreenWindow(window);
     window.toFront();
     Rectangle r = gd.getDefaultConfiguration().getBounds();
     window.setBounds(r);
     // window.pack();
   } else { // Windows and Linux TODO: test this
     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     window.setUndecorated(true);
     window.setSize(gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight());
     window.setLocation(0, 0);
     window.setExtendedState(JFrame.MAXIMIZED_BOTH);
     window.toFront();
   }
   window.pack();
   window.setVisible(true);
 }
  public static void main() {
    // Main
    frame = new JFrame("Java Playground");
    frame.setSize(640, 480);
    // Make sure the divider is properly resized
    frame.addComponentListener(
        new ComponentAdapter() {
          public void componentResized(ComponentEvent c) {
            splitter.setDividerLocation(.8);
          }
        });
    // Make sure the JVM is reset on close
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosed(WindowEvent w) {
            new FrameAction().kill();
          }
        });

    // Setting up the keybinding
    // Ctrl+k or Cmd+k -> compile
    bind(KeyEvent.VK_K);

    // Ctrl+e or Cmd+e -> console
    bind(KeyEvent.VK_E);

    // Save, New file, Open file, Print.
    // Currently UNUSED until I figure out how normal java files and playground files will
    // interface.
    bind(KeyEvent.VK_S);
    bind(KeyEvent.VK_N);
    bind(KeyEvent.VK_O);
    bind(KeyEvent.VK_P);

    // Binds the keys to the action defined in the FrameAction class.
    frame.getRootPane().getActionMap().put("console", new FrameAction());

    // The main panel for typing code in.
    text = new JTextPane();
    textScroll = new JScrollPane(text);
    textScroll.setBorder(null);
    textScroll.setPreferredSize(new Dimension(640, 480));

    // Document with syntax highlighting. Currently unfinished.
    doc = text.getStyledDocument();
    doc.addDocumentListener(
        new DocumentListener() {
          public void changedUpdate(DocumentEvent d) {}

          public void insertUpdate(DocumentEvent d) {}

          public void removeUpdate(DocumentEvent d) {}
        });

    ((AbstractDocument) doc).setDocumentFilter(new NewLineFilter());

    // The output log; a combination compiler warning/error/runtime error/output log.
    outputText = new JTextPane();
    outputScroll = new JScrollPane(outputText);
    outputScroll.setBorder(null);

    // "Constant" for the error font
    error = new SimpleAttributeSet();
    error.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE);
    error.addAttribute(StyleConstants.Foreground, Color.RED);

    // "Constant" for the warning message font
    warning = new SimpleAttributeSet();
    warning.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE);
    warning.addAttribute(StyleConstants.Foreground, Color.PINK);

    // "Constant" for the debugger error font
    progErr = new SimpleAttributeSet();
    progErr.addAttribute(StyleConstants.Foreground, Color.BLUE);

    // Print streams to redirect System.out and System.err.
    out = new TextOutputStream(outputText, null);
    err = new TextOutputStream(outputText, error);
    System.setOut(new PrintStream(out));
    System.setErr(new PrintStream(err));

    // Sets up the output log
    outputText.setEditable(false);
    outputScroll.setVisible(true);

    // File input/output setup
    chooser = new JFileChooser();

    // Setting up miscellaneous stuff
    compiler = ToolProvider.getSystemJavaCompiler();
    JVMrunning = false;
    redirectErr = null;
    redirectOut = null;
    redirectIn = null;

    // Sets up the splitter pane and opens the program up
    splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT, textScroll, outputScroll);
    consoleDisplayed = false;
    splitter.remove(outputScroll); // Initially hides terminal until it is needed
    splitter.setOneTouchExpandable(true);
    frame.add(splitter);
    frame.setVisible(true);

    // Sets the divider to the proper one, for debugging
    // splitter.setDividerLocation(.8);
  }
Esempio n. 13
0
 public void setTable(Properties w, MapTableModel t) {
   wordList = w;
   tableModel = t;
   f.repaint();
 }
Esempio n. 14
0
 public static void showFrame(boolean show) {
   f.setVisible(show);
   f.repaint();
   return;
 }