/** * Displays the window, allowing the MiniGame application to start accepting user input and allow * the user to actually play the game. */ public void startGame() { // DISPLAY THE WINDOW window.setVisible(true); // LET'S NOW CORRECT THE WINDOW SIZE. THE REASON WE DO THIS // IS BECAUSE WE'RE USING null LAYOUT MANAGER, SO WE NEED TO // SIZE STUFF OURSELVES, AND WE WANT THE WINDOW SIZE TO BE THE // SIZE OF THE CANVAS + THE BORDER OF THE WINDOW, WHICH WOULD // INCLUDE THE TITLE BAR. THIS IS CALLED THE WINDOW'S INSETS Insets insets = window.getInsets(); int correctedWidth = data.getGameWidth() + insets.left + insets.right; int correctedHeight = data.getGameHeight() + insets.top + insets.bottom; window.setSize(correctedWidth, correctedHeight); }
public void viewAttachments(List<String> attachmentIds) { JFrame frame = new JFrame("Image Viewer"); try { Attachment attachment = parent.mirthClient.getAttachment(attachmentIds.get(0)); byte[] rawData = attachment.getData(); byte[] rawImage = Base64.decodeBase64(rawData); ByteArrayInputStream bis = new ByteArrayInputStream(rawImage); image = ImageIO.read(bis); JScrollPane pictureScrollPane = new JScrollPane(new JLabel(new ImageIcon(image))); pictureScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); pictureScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); frame.add(pictureScrollPane); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { e.getWindow().dispose(); } }); frame.pack(); int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); // Resize the frame so that it fits and scrolls images larger than // 800x600 properly. if (imageWidth > 800 || imageHeight > 600) { int width = imageWidth; int height = imageHeight; if (imageWidth > 800) { width = 800; } if (imageHeight > 600) { height = 600; } // Also add the scrollbars to the window width if necessary. Integer scrollBarWidth = (Integer) UIManager.get("ScrollBar.width"); int verticalScrollBar = 0; int horizontalScrollBar = 0; if (width == 800) { horizontalScrollBar = scrollBarWidth.intValue(); } if (height == 600) { verticalScrollBar = scrollBarWidth.intValue(); } // Also add the window borders to the width. width = width + frame.getInsets().left + frame.getInsets().right + verticalScrollBar; height = height + frame.getInsets().top + frame.getInsets().bottom + horizontalScrollBar; frame.setSize(width, height); } Dimension dlgSize = frame.getSize(); Dimension frmSize = parent.getSize(); Point loc = parent.getLocation(); if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) { frame.setLocationRelativeTo(null); } else { frame.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); } frame.setVisible(true); } catch (Exception e) { parent.alertException(parent, e.getStackTrace(), e.getMessage()); } }
/** * @param args the command line arguments * @throws java.lang.InterruptedException * @throws java.util.concurrent.BrokenBarrierException */ public static void main(String[] args) throws InterruptedException, BrokenBarrierException { int NTHREADS = Runtime.getRuntime().availableProcessors(); int m = 1000; int n = 1000; int steps = 1000; boolean graphics = false; boolean glider = false; int seed = 0; boolean seedBool = false, optimised = false; if (args.length == 9) { try { m = Integer.parseInt(args[0]); } catch (NumberFormatException e) { System.err.println("Argument" + args[0] + " must be an integer."); System.exit(1); } try { n = Integer.parseInt(args[1]); } catch (NumberFormatException e) { System.err.println("Argument" + args[1] + " must be an integer."); System.exit(1); } try { steps = Integer.parseInt(args[2]); } catch (NumberFormatException e) { System.err.println("Argument" + args[2] + " must be an integer."); System.exit(1); } try { optimised = Boolean.parseBoolean(args[3]); } catch (NumberFormatException e) { System.err.println("Argument" + args[3] + " must be a bool."); System.exit(1); } try { graphics = Boolean.parseBoolean(args[4]); } catch (NumberFormatException e) { System.err.println("Argument" + args[4] + " must be a bool."); System.exit(1); } try { glider = Boolean.parseBoolean(args[5]); } catch (NumberFormatException e) { System.err.println("Argument" + args[5] + " must be a bool."); System.exit(1); } try { NTHREADS = Integer.parseInt(args[6]); } catch (NumberFormatException e) { System.err.println("Argument" + args[6] + " must be an integer."); System.exit(1); } try { seedBool = Boolean.parseBoolean(args[7]); } catch (NumberFormatException e) { System.err.println("Argument" + args[7] + " must be a bool."); System.exit(1); } try { seed = Integer.parseInt(args[8]); } catch (NumberFormatException e) { System.err.println("Argument" + args[8] + " must be an integer."); System.exit(1); } } else { System.err.println("Ooops. Wrong parameters as arguments."); System.exit(1); } final Board board = new Board(m, n); Interval[] bounds = board.splitBoard(NTHREADS); if (glider) { board.initializeGlider(); } else { if (seedBool) board.initializeBoard(seed); else board.initializeBoard(); } if (graphics) { JFrame frame = new JFrame("Game of Life - Multithreaded"); Graphics g = frame.getGraphics(); frame.pack(); Insets insets = frame.getInsets(); frame.getContentPane().add(new GraphicBoard(board), BorderLayout.CENTER); frame.paint(g); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(insets.left + insets.right + n, insets.top + insets.bottom + m); frame.setVisible(true); } final CyclicBarrier barrier = new CyclicBarrier(NTHREADS, board::swapBoards); ExecutorService threadPool = Executors.newFixedThreadPool(NTHREADS); final long startTime = System.currentTimeMillis(); for (int j = 0; j < NTHREADS; j++) { threadPool.execute(new Consumer(board, bounds[j].a, bounds[j].b, steps, barrier)); } threadPool.shutdown(); threadPool.awaitTermination(10, TimeUnit.MINUTES); final long endTime = System.currentTimeMillis(); System.out.println(endTime - startTime); System.exit(0); }
void createFrame() { /* see Preferences.java */ int GUI_BIG = 13; int GUI_BETWEEN = 10; int GUI_SMALL = 6; int FIELD_SIZE = 30; int left = GUI_BIG; int top = GUI_BIG; int right = 0; Dimension d; frame = new JFrame("Directives Editor"); Container pane = frame.getContentPane(); pane.setLayout(null); JLabel label = new JLabel("Click here to read about directives."); label.addMouseListener( new MouseListener() { public void mouseClicked(MouseEvent e) { Base.openURL("http://processingjs.org/reference/pjs%20directive"); } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} }); pane.add(label); d = label.getPreferredSize(); label.setBounds(left, top, d.width, d.height); top += d.height + GUI_BETWEEN + GUI_BETWEEN; // CRISP crispBox = new JCheckBox("\"crisp\": disable antialiasing for line(), triangle() and rect()"); pane.add(crispBox); d = crispBox.getPreferredSize(); crispBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // FONTS label = new JLabel("\"font\": to load (comma separated)"); pane.add(label); d = label.getPreferredSize(); label.setBounds(left, top, d.width, d.height); top += d.height + GUI_SMALL; fontField = new JTextField(FIELD_SIZE); pane.add(fontField); d = fontField.getPreferredSize(); fontField.setBounds(left, top, d.width, d.height); JButton button = new JButton("scan"); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { handleScanFonts(); } }); pane.add(button); Dimension d2 = button.getPreferredSize(); button.setBounds(left + d.width + GUI_SMALL, top, d2.width, d2.height); right = Math.max(right, left + d.width + GUI_SMALL + d2.width); top += d.height + GUI_BETWEEN; // GLOBAL_KEY_EVENTS globalKeyEventsBox = new JCheckBox("\"globalKeyEvents\": receive global key events"); pane.add(globalKeyEventsBox); d = globalKeyEventsBox.getPreferredSize(); globalKeyEventsBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // PAUSE_ON_BLUR pauseOnBlurBox = new JCheckBox("\"pauseOnBlur\": pause if applet loses focus"); pane.add(pauseOnBlurBox); d = pauseOnBlurBox.getPreferredSize(); pauseOnBlurBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // PRELOAD images label = new JLabel("\"preload\": images (comma separated)"); pane.add(label); d = label.getPreferredSize(); label.setBounds(left, top, d.width, d.height); top += d.height + GUI_SMALL; preloadField = new JTextField(FIELD_SIZE); pane.add(preloadField); d = preloadField.getPreferredSize(); preloadField.setBounds(left, top, d.width, d.height); button = new JButton("scan"); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { handleScanImages(); } }); pane.add(button); d2 = button.getPreferredSize(); button.setBounds(left + d.width + GUI_SMALL, top, d2.width, d2.height); right = Math.max(right, left + d.width + GUI_SMALL + d2.width); top += d.height + GUI_BETWEEN; // TRANSPARENT /*transparentBox = new JCheckBox("\"transparent\": set applet background to be transparent"); pane.add(transparentBox); d = transparentBox.getPreferredSize(); transparentBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN;*/ // APPLY / OK button = new JButton("OK"); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { applyDirectives(); hide(); } }); pane.add(button); d2 = button.getPreferredSize(); int BUTTON_HEIGHT = d2.height; int BUTTON_WIDTH = 80; int h = right - (BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH); button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); h += BUTTON_WIDTH + GUI_SMALL; button = new JButton("Cancel"); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { hide(); } }); pane.add(button); button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); top += BUTTON_HEIGHT + GUI_BETWEEN; // frame.getContentPane().add(box); frame.pack(); Insets insets = frame.getInsets(); frame.setSize( right + GUI_BIG + insets.left + insets.right, top + GUI_SMALL + insets.top + insets.bottom); // frame.setResizable(false); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { frame.setVisible(false); } }); Toolkit.registerWindowCloseKeys( frame.getRootPane(), new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { frame.setVisible(false); } }); Toolkit.setIcon(frame); }
public Preferences() { // setup dialog for the prefs //dialog = new JDialog(editor, "Preferences", true); dialog = new JFrame(_("Preferences")); dialog.setResizable(false); Container pain = dialog.getContentPane(); pain.setLayout(null); int top = GUI_BIG; int left = GUI_BIG; int right = 0; JLabel label; JButton button; //, button2; //JComboBox combo; Dimension d, d2; //, d3; int h, vmax; // Sketchbook location: // [...............................] [ Browse ] label = new JLabel(_("Sketchbook location:")); pain.add(label); d = label.getPreferredSize(); label.setBounds(left, top, d.width, d.height); top += d.height; // + GUI_SMALL; sketchbookLocationField = new JTextField(40); pain.add(sketchbookLocationField); d = sketchbookLocationField.getPreferredSize(); button = new JButton(PROMPT_BROWSE); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { File dflt = new File(sketchbookLocationField.getText()); File file = Base.selectFolder(_("Select new sketchbook location"), dflt, dialog); if (file != null) { sketchbookLocationField.setText(file.getAbsolutePath()); } } }); pain.add(button); d2 = button.getPreferredSize(); // take max height of all components to vertically align em vmax = Math.max(d.height, d2.height); sketchbookLocationField.setBounds(left, top + (vmax-d.height)/2, d.width, d.height); h = left + d.width + GUI_SMALL; button.setBounds(h, top + (vmax-d2.height)/2, d2.width, d2.height); right = Math.max(right, h + d2.width + GUI_BIG); top += vmax + GUI_BETWEEN; // Preferred language: [ ] (requires restart of Arduino) Container box = Box.createHorizontalBox(); label = new JLabel(_("Editor language: ")); box.add(label); comboLanguage = new JComboBox(languages); comboLanguage.setSelectedIndex((Arrays.asList(languagesISO)).indexOf(Preferences.get("editor.languages.current"))); box.add(comboLanguage); label = new JLabel(_(" (requires restart of Arduino)")); box.add(label); pain.add(box); d = box.getPreferredSize(); box.setForeground(Color.gray); box.setBounds(left, top, d.width, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // Editor font size [ ] box = Box.createHorizontalBox(); label = new JLabel(_("Editor font size: ")); box.add(label); fontSizeField = new JTextField(4); box.add(fontSizeField); label = new JLabel(_(" (requires restart of Arduino)")); box.add(label); pain.add(box); d = box.getPreferredSize(); box.setBounds(left, top, d.width, d.height); Font editorFont = Preferences.getFont("editor.font"); fontSizeField.setText(String.valueOf(editorFont.getSize())); top += d.height + GUI_BETWEEN; // Show verbose output during: [ ] compilation [ ] upload box = Box.createHorizontalBox(); label = new JLabel(_("Show verbose output during: ")); box.add(label); verboseCompilationBox = new JCheckBox(_("compilation ")); box.add(verboseCompilationBox); verboseUploadBox = new JCheckBox(_("upload")); box.add(verboseUploadBox); pain.add(box); d = box.getPreferredSize(); box.setBounds(left, top, d.width, d.height); top += d.height + GUI_BETWEEN; // [ ] Verify code after upload verifyUploadBox = new JCheckBox(_("Verify code after upload")); pain.add(verifyUploadBox); d = verifyUploadBox.getPreferredSize(); verifyUploadBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // [ ] Use external editor externalEditorBox = new JCheckBox(_("Use external editor")); pain.add(externalEditorBox); d = externalEditorBox.getPreferredSize(); externalEditorBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // [ ] Check for updates on startup checkUpdatesBox = new JCheckBox(_("Check for updates on startup")); pain.add(checkUpdatesBox); d = checkUpdatesBox.getPreferredSize(); checkUpdatesBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; // [ ] Update sketch files to new extension on save (.pde -> .ino) updateExtensionBox = new JCheckBox(_("Update sketch files to new extension on save (.pde -> .ino)")); pain.add(updateExtensionBox); d = updateExtensionBox.getPreferredSize(); updateExtensionBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; domainPortField= new JTextField(); domainPortField.setColumns(30); Box domainBox = Box.createHorizontalBox(); domainBox.add(new JLabel("Tftp upload Domain:")); domainBox.add(domainPortField); pain.add(domainBox); d = domainBox.getPreferredSize(); domainBox.setBounds(left, top, d.width, d.height); top += d.height + GUI_BETWEEN; autoResetPortField= new JTextField(); autoResetPortField.setColumns(8); Box resetBox = Box.createHorizontalBox(); resetBox.add(new JLabel("Auto Reset Port:")); resetBox.add(autoResetPortField); pain.add(resetBox); d = resetBox.getPreferredSize(); resetBox.setBounds(left, top, d.width, d.height); top += d.height + GUI_BETWEEN; tftpPassField = new JTextField(); tftpPassField.setColumns(30); Box tftpBox = Box.createHorizontalBox(); tftpBox.add(new JLabel("Tftp Secret Password:"******"Automatically associate .ino files with Arduino")); pain.add(autoAssociateBox); d = autoAssociateBox.getPreferredSize(); autoAssociateBox.setBounds(left, top, d.width + 10, d.height); right = Math.max(right, left + d.width); top += d.height + GUI_BETWEEN; } // More preferences are in the ... label = new JLabel(_("More preferences can be edited directly in the file")); pain.add(label); d = label.getPreferredSize(); label.setForeground(Color.gray); label.setBounds(left, top, d.width, d.height); right = Math.max(right, left + d.width); top += d.height; // + GUI_SMALL; label = new JLabel(preferencesFile.getAbsolutePath()); final JLabel clickable = label; label.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { Base.openFolder(Base.getSettingsFolder()); } public void mouseEntered(MouseEvent e) { clickable.setForeground(new Color(0, 0, 140)); } public void mouseExited(MouseEvent e) { clickable.setForeground(Color.BLACK); } }); pain.add(label); d = label.getPreferredSize(); label.setBounds(left, top, d.width, d.height); right = Math.max(right, left + d.width); top += d.height; label = new JLabel(_("(edit only when Arduino is not running)")); pain.add(label); d = label.getPreferredSize(); label.setForeground(Color.gray); label.setBounds(left, top, d.width, d.height); right = Math.max(right, left + d.width); top += d.height; // + GUI_SMALL; // [ OK ] [ Cancel ] maybe these should be next to the message? button = new JButton(PROMPT_OK); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { applyFrame(); disposeFrame(); } }); pain.add(button); d2 = button.getPreferredSize(); BUTTON_HEIGHT = d2.height; h = right - (BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH); button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); h += BUTTON_WIDTH + GUI_SMALL; button = new JButton(PROMPT_CANCEL); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { disposeFrame(); } }); pain.add(button); button.setBounds(h, top, BUTTON_WIDTH, BUTTON_HEIGHT); top += BUTTON_HEIGHT + GUI_BETWEEN; // finish up wide = right + GUI_BIG; high = top + GUI_SMALL; // closing the window is same as hitting cancel button dialog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { disposeFrame(); } }); ActionListener disposer = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { disposeFrame(); } }; Base.registerWindowCloseKeys(dialog.getRootPane(), disposer); Base.setIcon(dialog); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); dialog.setLocation((screen.width - wide) / 2, (screen.height - high) / 2); dialog.pack(); // get insets Insets insets = dialog.getInsets(); dialog.setSize(wide + insets.left + insets.right, high + insets.top + insets.bottom); // handle window closing commands for ctrl/cmd-W or hitting ESC. pain.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { //System.out.println(e); KeyStroke wc = Editor.WINDOW_CLOSE_KEYSTROKE; if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) || (KeyStroke.getKeyStrokeForEvent(e).equals(wc))) { disposeFrame(); } } }); }