List of usage examples for java.awt GraphicsConfiguration getBounds
public abstract Rectangle getBounds();
From source file:GUIUtils.java
public static Rectangle getScreenBoundsFor(Rectangle rc) { final GraphicsDevice[] gds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); final List<GraphicsConfiguration> configs = new ArrayList<GraphicsConfiguration>(); for (int i = 0; i < gds.length; i++) { GraphicsConfiguration gc = gds[i].getDefaultConfiguration(); if (rc.intersects(gc.getBounds())) { configs.add(gc);//from ww w .j a va 2 s .c o m } } GraphicsConfiguration selected = null; if (configs.size() > 0) { for (Iterator<GraphicsConfiguration> it = configs.iterator(); it.hasNext();) { GraphicsConfiguration gcc = it.next(); if (selected == null) selected = gcc; else { if (gcc.getBounds().contains(rc.x + 20, rc.y + 20)) { selected = gcc; break; } } } } else { selected = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); } int x = selected.getBounds().x; int y = selected.getBounds().y; int w = selected.getBounds().width; int h = selected.getBounds().height; return new Rectangle(x, y, w, h); }
From source file:Main.java
/** * Used for getting the actual bound of the monitor that contains Point p * * @param p - point to check monitor for * @return - current monitor bounds/*from w w w .j a v a 2 s .c o m*/ */ public static Rectangle getScreenBoundsForPoint(Point p) { Rectangle bounds; GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsConfiguration graphicsConfiguration = null; for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { if (gd.getDefaultConfiguration().getBounds().contains(p)) { graphicsConfiguration = gd.getDefaultConfiguration(); break; } } if (graphicsConfiguration != null) { bounds = graphicsConfiguration.getBounds(); Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfiguration); bounds.x += screenInsets.left; bounds.y += screenInsets.top; bounds.height -= screenInsets.bottom; bounds.width -= screenInsets.right; } else { bounds = env.getMaximumWindowBounds(); } return (bounds); }
From source file:Utils.java
/** * <p>//from w w w. j a v a 2 s.com * Returns the <code>Point</code> at which a window should be placed to * center that window on the screen. * </p> * <p> * Some thought was taken as to whether to implement a method such as this, * or to simply make a method that, given a window, will center it. It was * decided that it is better to not alter an object within a method. * </p> * * @param window The window to calculate the center point for. This object * can not be null. * * @return the <code>Point</code> at which the window should be placed to * center that window on the screen. */ private static Rectangle getUsableDeviceBounds(Window window) { Window owner = window.getOwner(); GraphicsConfiguration gc = null; if (owner == null) { gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); } else { gc = owner.getGraphicsConfiguration(); } Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); Rectangle bounds = gc.getBounds(); bounds.x += insets.left; bounds.y += insets.top; bounds.width -= (insets.left + insets.right); bounds.height -= (insets.top + insets.bottom); return bounds; }
From source file:Main.java
/** * Retrieves the bounds represents the available space on the Window's display that is not used up by things like * the task bar or dock./*from w w w .j av a 2 s. c o m*/ * * @param window * The window to center * @return Bounds of the display's available space */ public static Rectangle getBoundsOfAvailableDisplaySpace(Window window) { GraphicsConfiguration graphicsConfigToUse = window.getGraphicsConfiguration(); // If the Window does not have a GraphicsConfiguration yet (perhaps when the Window is not set up yet) then use the default screen's GraphicsConfiguration. if (graphicsConfigToUse == null) { graphicsConfigToUse = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); } Rectangle boundsOfEntireScreen = graphicsConfigToUse.getBounds(); Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfigToUse); return new Rectangle(screenInsets.left, screenInsets.top, boundsOfEntireScreen.width - screenInsets.left - screenInsets.right, boundsOfEntireScreen.height - screenInsets.top - screenInsets.bottom); }
From source file:Utilities.java
/** * Returns the usable area of the screen where applications can place its * windows. The method subtracts from the screen the area of taskbars, * system menus and the like./*www.j ava2s. c om*/ * * @param gconf the GraphicsConfiguration of the monitor * @return the rectangle of the screen where one can place windows * * @since 2.5 */ public static Rectangle getUsableScreenBounds(GraphicsConfiguration gconf) { if (gconf == null) { gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); } Rectangle bounds = new Rectangle(gconf.getBounds()); String str; str = System.getProperty("netbeans.screen.insets"); // NOI18N if (str != null) { StringTokenizer st = new StringTokenizer(str, ", "); // NOI18N if (st.countTokens() == 4) { try { bounds.y = Integer.parseInt(st.nextToken()); bounds.x = Integer.parseInt(st.nextToken()); bounds.height -= (bounds.y + Integer.parseInt(st.nextToken())); bounds.width -= (bounds.x + Integer.parseInt(st.nextToken())); } catch (NumberFormatException ex) { Logger.getAnonymousLogger().log(Level.WARNING, null, ex); } } return bounds; } str = System.getProperty("netbeans.taskbar.height"); // NOI18N if (str != null) { bounds.height -= Integer.getInteger(str, 0).intValue(); return bounds; } try { Toolkit toolkit = Toolkit.getDefaultToolkit(); Insets insets = toolkit.getScreenInsets(gconf); bounds.y += insets.top; bounds.x += insets.left; bounds.height -= (insets.top + insets.bottom); bounds.width -= (insets.left + insets.right); } catch (Exception ex) { Logger.getAnonymousLogger().log(Level.WARNING, null, ex); } return bounds; }
From source file:com.tag.FramePreferences.java
public final Rectangle getGraphicsBounds() { GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle r = null;/*from w ww. j ava2s .com*/ for (GraphicsDevice device : environment.getScreenDevices()) { GraphicsConfiguration config = device.getDefaultConfiguration(); if (r == null) { r = config.getBounds(); } else { r.add(config.getBounds()); } } return r; }
From source file:com.haulmont.cuba.desktop.sys.DesktopToolTipManager.java
protected Rectangle getDeviceBounds(GraphicsDevice device) { GraphicsConfiguration gc = device.getDefaultConfiguration(); return gc.getBounds(); }
From source file:misc.ModalityDemo.java
/** * Create the GUI and show it. For thread safety, * this method is invoked from the/* w ww .j a va 2 s .c o m*/ * event-dispatching thread. */ private void createAndShowGUI() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); Insets ins = Toolkit.getDefaultToolkit().getScreenInsets(gc); int sw = gc.getBounds().width - ins.left - ins.right; int sh = gc.getBounds().height - ins.top - ins.bottom; // first document // frame f1 f1 = new JFrame("Book 1 (parent frame)"); f1.setBounds(32, 32, 300, 200); f1.addWindowListener(closeWindow); // create radio buttons rb11 = new JRadioButton("Biography", true); rb12 = new JRadioButton("Funny tale", false); rb13 = new JRadioButton("Sonnets", false); // place radio buttons into a single group ButtonGroup bg1 = new ButtonGroup(); bg1.add(rb11); bg1.add(rb12); bg1.add(rb13); JButton b1 = new JButton("OK"); b1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // get label of selected radiobutton String title = null; if (rb11.isSelected()) { title = rb11.getText(); } else if (rb12.isSelected()) { title = rb12.getText(); } else { title = rb13.getText(); } // prepend radio button label to dialogs' titles d2.setTitle(title + " (modeless dialog)"); d3.setTitle(title + " (document-modal dialog)"); d2.setVisible(true); } }); Container cp1 = f1.getContentPane(); // create three containers to improve layouting cp1.setLayout(new GridLayout(1, 3)); // an empty container Container cp11 = new Container(); // a container to layout components Container cp12 = new Container(); // an empty container Container cp13 = new Container(); // add a button into a separate panel JPanel p1 = new JPanel(); p1.setLayout(new FlowLayout()); p1.add(b1); // add radio buttons and the OK button one after another into a single column cp12.setLayout(new GridLayout(4, 1)); cp12.add(rb11); cp12.add(rb12); cp12.add(rb13); cp12.add(p1); // add three containers cp1.add(cp11); cp1.add(cp12); cp1.add(cp13); // dialog d2 d2 = new JDialog(f1); d2.setBounds(132, 132, 300, 200); d2.addWindowListener(closeWindow); JLabel l2 = new JLabel("Enter your name: "); l2.setHorizontalAlignment(SwingConstants.CENTER); tf2 = new JTextField(12); JButton b2 = new JButton("OK"); b2.setHorizontalAlignment(SwingConstants.CENTER); b2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //pass a name into the document modal dialog l3.setText("by " + tf2.getText()); d3.setVisible(true); } }); Container cp2 = d2.getContentPane(); // add label, text field and button one after another into a single column cp2.setLayout(new BorderLayout()); cp2.add(l2, BorderLayout.NORTH); cp2.add(tf2, BorderLayout.CENTER); JPanel p2 = new JPanel(); p2.setLayout(new FlowLayout()); p2.add(b2); cp2.add(p2, BorderLayout.SOUTH); // dialog d3 d3 = new JDialog(d2, "", Dialog.ModalityType.DOCUMENT_MODAL); d3.setBounds(232, 232, 300, 200); d3.addWindowListener(closeWindow); JTextArea ta3 = new JTextArea(); l3 = new JLabel(); l3.setHorizontalAlignment(SwingConstants.RIGHT); Container cp3 = d3.getContentPane(); cp3.setLayout(new BorderLayout()); cp3.add(new JScrollPane(ta3), BorderLayout.CENTER); JPanel p3 = new JPanel(); p3.setLayout(new FlowLayout(FlowLayout.RIGHT)); p3.add(l3); cp3.add(p3, BorderLayout.SOUTH); // second document // frame f4 f4 = new JFrame("Book 2 (parent frame)"); f4.setBounds(sw - 300 - 32, 32, 300, 200); f4.addWindowListener(closeWindow); // create radio buttons rb41 = new JRadioButton("Biography", true); rb42 = new JRadioButton("Funny tale", false); rb43 = new JRadioButton("Sonnets", false); // place radio buttons into a single group ButtonGroup bg4 = new ButtonGroup(); bg4.add(rb41); bg4.add(rb42); bg4.add(rb43); JButton b4 = new JButton("OK"); b4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // get label of selected radiobutton String title = null; if (rb41.isSelected()) { title = rb41.getText(); } else if (rb42.isSelected()) { title = rb42.getText(); } else { title = rb43.getText(); } // prepend radiobutton label to dialogs' titles d5.setTitle(title + " (modeless dialog)"); d6.setTitle(title + " (document-modal dialog)"); d5.setVisible(true); } }); Container cp4 = f4.getContentPane(); // create three containers to improve layouting cp4.setLayout(new GridLayout(1, 3)); Container cp41 = new Container(); Container cp42 = new Container(); Container cp43 = new Container(); // add the button into a separate panel JPanel p4 = new JPanel(); p4.setLayout(new FlowLayout()); p4.add(b4); // add radiobuttons and the OK button one after another into a single column cp42.setLayout(new GridLayout(4, 1)); cp42.add(rb41); cp42.add(rb42); cp42.add(rb43); cp42.add(p4); //add three containers cp4.add(cp41); cp4.add(cp42); cp4.add(cp43); // dialog d5 d5 = new JDialog(f4); d5.setBounds(sw - 400 - 32, 132, 300, 200); d5.addWindowListener(closeWindow); JLabel l5 = new JLabel("Enter your name: "); l5.setHorizontalAlignment(SwingConstants.CENTER); tf5 = new JTextField(12); tf5.setHorizontalAlignment(SwingConstants.CENTER); JButton b5 = new JButton("OK"); b5.setHorizontalAlignment(SwingConstants.CENTER); b5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //pass a name into the document modal dialog l6.setText("by " + tf5.getText()); d6.setVisible(true); } }); Container cp5 = d5.getContentPane(); // add label, text field and button one after another into a single column cp5.setLayout(new BorderLayout()); cp5.add(l5, BorderLayout.NORTH); cp5.add(tf5, BorderLayout.CENTER); JPanel p5 = new JPanel(); p5.setLayout(new FlowLayout()); p5.add(b5); cp5.add(p5, BorderLayout.SOUTH); // dialog d6 d6 = new JDialog(d5, "", Dialog.ModalityType.DOCUMENT_MODAL); d6.setBounds(sw - 500 - 32, 232, 300, 200); d6.addWindowListener(closeWindow); JTextArea ta6 = new JTextArea(); l6 = new JLabel(); l6.setHorizontalAlignment(SwingConstants.RIGHT); Container cp6 = d6.getContentPane(); cp6.setLayout(new BorderLayout()); cp6.add(new JScrollPane(ta6), BorderLayout.CENTER); JPanel p6 = new JPanel(); p6.setLayout(new FlowLayout(FlowLayout.RIGHT)); p6.add(l6); cp6.add(p6, BorderLayout.SOUTH); // third document // frame f7 f7 = new JFrame("Classics (excluded frame)"); f7.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); f7.setBounds(32, sh - 200 - 32, 300, 200); f7.addWindowListener(closeWindow); JLabel l7 = new JLabel("Famous writers: "); l7.setHorizontalAlignment(SwingConstants.CENTER); // create radio buttons rb71 = new JRadioButton("Burns", true); rb72 = new JRadioButton("Dickens", false); rb73 = new JRadioButton("Twain", false); // place radio buttons into a single group ButtonGroup bg7 = new ButtonGroup(); bg7.add(rb71); bg7.add(rb72); bg7.add(rb73); Container cp7 = f7.getContentPane(); // create three containers to improve layouting cp7.setLayout(new GridLayout(1, 3)); Container cp71 = new Container(); Container cp72 = new Container(); Container cp73 = new Container(); // add the label into a separate panel JPanel p7 = new JPanel(); p7.setLayout(new FlowLayout()); p7.add(l7); // add a label and radio buttons one after another into a single column cp72.setLayout(new GridLayout(4, 1)); cp72.add(p7); cp72.add(rb71); cp72.add(rb72); cp72.add(rb73); // add three containers cp7.add(cp71); cp7.add(cp72); cp7.add(cp73); // fourth document // frame f8 f8 = new JFrame("Feedback (parent frame)"); f8.setBounds(sw - 300 - 32, sh - 200 - 32, 300, 200); f8.addWindowListener(closeWindow); JButton b8 = new JButton("Rate yourself"); b8.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showConfirmDialog(null, "I really like my book", "Question (application-modal dialog)", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); } }); Container cp8 = f8.getContentPane(); cp8.setLayout(new FlowLayout(FlowLayout.CENTER, 8, 8)); cp8.add(b8); }
From source file:imageviewer.system.ImageViewerClient.java
private void initialize(CommandLine args) { // First, process all the different command line arguments that we // need to override and/or send onwards for initialization. boolean fullScreen = (args.hasOption("fullscreen")) ? true : false; String dir = (args.hasOption("dir")) ? args.getOptionValue("dir") : null; String type = (args.hasOption("type")) ? args.getOptionValue("type") : "DICOM"; String prefix = (args.hasOption("client")) ? args.getOptionValue("client") : null; LOG.info("Java home environment: " + System.getProperty("java.home")); // Logging system taken care of through properties file. Check // for JAI. Set up JAI accordingly with the size of the cache // tile and to recycle cached tiles as needed. verifyJAI();// w ww . j ava 2 s.co m TileCache tc = JAI.getDefaultInstance().getTileCache(); tc.setMemoryCapacity(32 * 1024 * 1024); TileScheduler ts = JAI.createTileScheduler(); ts.setPriority(Thread.MAX_PRIORITY); JAI.getDefaultInstance().setTileScheduler(ts); JAI.getDefaultInstance().setRenderingHint(JAI.KEY_CACHED_TILE_RECYCLING_ENABLED, Boolean.TRUE); // Set up the frame and everything else. First, try and set the // UI manager to use our look and feel because it's groovy and // lets us control the GUI components much better. try { UIManager.setLookAndFeel(new ImageViewerLookAndFeel()); LookAndFeelAddons.setAddon(ImageViewerLookAndFeelAddons.class); } catch (Exception exc) { LOG.error("Could not set imageViewer L&F."); } // Load up the ApplicationContext information... ApplicationContext ac = ApplicationContext.getContext(); if (ac == null) { LOG.error("Could not load configuration, exiting."); System.exit(1); } // Override the client node information based on command line // arguments...Make sure that the files are there, otherwise just // default to a local configuration. String hostname = new String("localhost"); try { hostname = InetAddress.getLocalHost().getHostName(); } catch (Exception exc) { } String[] gatewayConfigs = (prefix != null) ? (new String[] { "resources/server/" + prefix + "GatewayConfig.xml", (String) ac.getProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG), "resources/server/" + hostname + "GatewayConfig.xml", "resources/server/localGatewayConfig.xml" }) : (new String[] { (String) ac.getProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG), "resources/server/" + hostname + "GatewayConfig.xml", "resources/server/localGatewayConfig.xml" }); String[] nodeConfigs = (prefix != null) ? (new String[] { "resources/server/" + prefix + "NodeConfig.xml", (String) ac.getProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE), "resources/server/" + hostname + "NodeConfig.xml", "resources/server/localNodeConfig.xml" }) : (new String[] { (String) ac.getProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE), "resources/server/" + hostname + "NodeConfig.xml", "resources/server/localNodeConfig.xml" }); for (int loop = 0; loop < gatewayConfigs.length; loop++) { String s = gatewayConfigs[loop]; if ((s != null) && (s.length() != 0) && (!"null".equals(s))) { File f = new File(s); if (f.exists()) { ac.setProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG, s); break; } } } LOG.info("Using gateway config: " + ac.getProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG)); for (int loop = 0; loop < nodeConfigs.length; loop++) { String s = nodeConfigs[loop]; if ((s != null) && (s.length() != 0) && (!"null".equals(s))) { File f = new File(s); if (f.exists()) { ac.setProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE, s); break; } } } LOG.info("Using client config: " + ac.getProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE)); // Load the layouts and set the default window/level manager... LayoutFactory.initialize(); DefaultWindowLevelManager dwlm = new DefaultWindowLevelManager(); // Create the main JFrame, set its behavior, and let the // ApplicationPanel know the glassPane and layeredPane. Set the // menubar based on reading in the configuration menus. mainFrame = new JFrame("imageviewer"); try { ArrayList<Image> iconList = new ArrayList<Image>(); iconList.add(ImageIO.read(new File("resources/icons/mii.png"))); iconList.add(ImageIO.read(new File("resources/icons/mii32.png"))); mainFrame.setIconImages(iconList); } catch (Exception exc) { } mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { int confirm = ApplicationPanel.getInstance().showDialog( "Are you sure you want to quit imageViewer?", null, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, UIManager.getIcon("Dialog.shutdownIcon")); if (confirm == JOptionPane.OK_OPTION) { boolean hasUnsaved = SaveStack.getInstance().hasUnsavedItems(); if (hasUnsaved) { int saveResult = ApplicationPanel.getInstance().showDialog( "There is still unsaved data. Do you want to save this data in the local archive?", null, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION); if (saveResult == JOptionPane.CANCEL_OPTION) return; if (saveResult == JOptionPane.YES_OPTION) SaveStack.getInstance().saveAll(); } LOG.info("Shutting down imageServer local archive..."); try { ImageViewerClientNode.getInstance().shutdown(); } catch (Exception exc) { LOG.error("Problem shutting down imageServer local archive..."); } finally { System.exit(0); } } } }); String menuFile = (String) ApplicationContext.getContext().getProperty(ac.CONFIG_MENUS); String ribbonFile = (String) ApplicationContext.getContext().getProperty(ac.CONFIG_RIBBON); if (menuFile != null) { JMenuBar mb = new JMenuBar(); mb.setBackground(Color.black); MenuReader.parseFile(menuFile, mb); mainFrame.setJMenuBar(mb); ApplicationContext.getContext().setApplicationMenuBar(mb); } else if (ribbonFile != null) { RibbonReader rr = new RibbonReader(); JRibbon jr = rr.parseFile(ribbonFile); mainFrame.getContentPane().add(jr, BorderLayout.NORTH); ApplicationContext.getContext().setApplicationRibbon(jr); } mainFrame.getContentPane().add(ApplicationPanel.getInstance(), BorderLayout.CENTER); ApplicationPanel.getInstance().setGlassPane((JPanel) (mainFrame.getGlassPane())); ApplicationPanel.getInstance().setLayeredPane(mainFrame.getLayeredPane()); // Load specified plugins...has to occur after the menus are // created, btw. PluginLoader.initialize("config/plugins.xml"); // Detect operating system... String osName = System.getProperty("os.name"); ApplicationContext.getContext().setProperty(ApplicationContext.OS_NAME, osName); LOG.info("Detected operating system: " + osName); // Try and hack the searched library paths if it's windows so we // can add a local dll path... try { if (osName.contains("Windows")) { Field f = ClassLoader.class.getDeclaredField("usr_paths"); f.setAccessible(true); String[] paths = (String[]) f.get(null); String[] tmp = new String[paths.length + 1]; System.arraycopy(paths, 0, tmp, 0, paths.length); File currentPath = new File("."); tmp[paths.length] = currentPath.getCanonicalPath() + "/lib/dll/"; f.set(null, tmp); f.setAccessible(false); } } catch (Exception exc) { LOG.error("Error attempting to dynamically set library paths."); } // Get screen resolution... GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); Rectangle r = gc.getBounds(); LOG.info("Detected screen resolution: " + (int) r.getWidth() + "x" + (int) r.getHeight()); // Try and see if Java3D is installed, and if so, what version... try { VirtualUniverse vu = new VirtualUniverse(); Map m = vu.getProperties(); String s = (String) m.get("j3d.version"); LOG.info("Detected Java3D version: " + s); } catch (Throwable t) { LOG.info("Unable to detect Java3D installation"); } // Try and see if native JOGL is installed... try { System.loadLibrary("jogl"); ac.setProperty(ApplicationContext.JOGL_DETECTED, Boolean.TRUE); LOG.info("Detected native libraries for JOGL"); } catch (Throwable t) { LOG.info("Unable to detect native JOGL installation"); ac.setProperty(ApplicationContext.JOGL_DETECTED, Boolean.FALSE); } // Start the local client node to connect to the network and the // local archive running on this machine...Thread the connection // process so it doesn't block the imageViewerClient creating this // instance. We may not be connected to the given gateway, so the // socketServer may go blah... final boolean useNetwork = (args.hasOption("nonet")) ? false : true; ApplicationPanel.getInstance().addStatusMessage("ImageViewer is starting up, please wait..."); if (useNetwork) LOG.info("Starting imageServer client to join network - please wait..."); Thread t = new Thread(new Runnable() { public void run() { try { ImageViewerClientNode.getInstance( (String) ApplicationContext.getContext() .getProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG), (String) ApplicationContext.getContext() .getProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE), useNetwork); ApplicationPanel.getInstance().addStatusMessage("Ready"); } catch (Exception exc) { exc.printStackTrace(); } } }); t.setPriority(9); t.start(); this.fullScreen = fullScreen; mainFrame.setUndecorated(fullScreen); // Set the view to encompass the default screen. if (fullScreen) { Insets i = Toolkit.getDefaultToolkit().getScreenInsets(gc); mainFrame.setLocation(r.x + i.left, r.y + i.top); mainFrame.setSize(r.width - i.left - i.right, r.height - i.top - i.bottom); } else { mainFrame.setSize(1100, 800); mainFrame.setLocation(r.x + 200, r.y + 100); } if (dir != null) ApplicationPanel.getInstance().load(dir, type); timer = new Timer(); timer.schedule(new GarbageCollectionTimer(), 5000, 2500); mainFrame.setVisible(true); }
From source file:gate.Main.java
/** Run the user interface. */ protected static void runGui() throws GateException { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); // initialise the library and load user CREOLE directories try {/*from w ww . j av a 2 s . c o m*/ Gate.init(); } catch (Throwable t) { log.error("Problem while initialising GATE", t); int selection = JOptionPane.showOptionDialog(null, "Error during initialisation:\n" + t.toString() + "\nDo you still want to start GATE?", "GATE", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, new String[] { "Cancel", "Start anyway" }, "Cancel"); if (selection != 1) { System.exit(1); } } //create the main frame, show it SwingUtilities.invokeLater(new Runnable() { @Override public void run() { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice().getDefaultConfiguration(); //this needs to run before any GUI component is constructed. applyUserPreferences(); //all the defaults tables have been updated; build the GUI frame = MainFrame.getInstance(gc); if (DEBUG) Out.prln("constructing GUI"); // run the GUI frame.setTitleChangable(true); frame.setTitle(name + " " + version + " build " + build); // Set title from Java properties String title = System.getProperty(GateConstants.TITLE_JAVA_PROPERTY_NAME); if (title != null) { frame.setTitle(title); } // if frame.setTitleChangable(false); // Set icon from Java properties // iconName could be absolute or "gate:/img/..." String iconName = System.getProperty(GateConstants.APP_ICON_JAVA_PROPERTY_NAME); if (iconName != null) { try { frame.setIconImage(Toolkit.getDefaultToolkit().getImage(new URL(iconName))); } catch (MalformedURLException mue) { log.warn("Could not load application icon.", mue); } } // if // Validate frames that have preset sizes frame.validate(); // Center the window Rectangle screenBounds = gc.getBounds(); Dimension screenSize = screenBounds.getSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); //load session if required and available; //do everything from a new thread. Runnable runnable = new Runnable() { @Override public void run() { try { File sessionFile = Gate.getUserSessionFile(); if (sessionFile.exists()) { MainFrame.lockGUI("Loading saved session..."); PersistenceManager.loadObjectFromFile(sessionFile); } } catch (Exception e) { log.warn("Failed to load session data", e); } finally { MainFrame.unlockGUI(); } } }; Thread thread = new Thread(Thread.currentThread().getThreadGroup(), runnable, "Session loader"); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); } }); registerCreoleUrls(); }