/** * Lays out the widgets and positions the window in the middle of the screen. * * @param logo The Frame's background logo. * @param version The version of the software. * @param serverAvailable Pass <code>true</code> if the client needs to connect to a server, * <code>false</code> otherwise. */ private void buildGUI(Icon logo, String version, boolean serverAvailable) { JLabel splash = new JLabel(logo); layers = new JLayeredPane(); layers.add(splash, Integer.valueOf(0)); getContentPane().add(layers); int width = logo.getIconWidth(); int height = logo.getIconHeight(); layers.setBounds(0, 0, width, height); splash.setBounds(0, 0, width, height); int h = progressBar.getFontMetrics(progressBar.getFont()).getHeight(); int top = 120; int bottom = 100; currentTask.setBounds(TEXT_INDENT, top, width - 2 * TEXT_INDENT, h); top += 20; progressBar.setBounds(TEXT_INDENT, top, width - 2 * TEXT_INDENT, h); addToLayer(currentTask); addToLayer(progressBar); mainPanel = new JPanel(); mainPanel.setOpaque(false); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); Font f; versionInfo = UIUtilities.buildTextPane(version, FOOT_NOTE_COLOR); f = versionInfo.getFont(); versionInfo.setFont(f.deriveFont(VERSION_FONT_STYLE, f.getSize() - 4)); versionInfo.setOpaque(false); // Add login details. int y = height - bottom - 10; y = top + 2 * h; buildLogin(); displayComponents(serverAvailable); mainPanel.add(UIUtilities.buildComponentPanelCenter(versionInfo, 0, 0, false)); mainPanel.setBounds(0, y, width, height - top - bottom); addToLayer(mainPanel); }
/** * Builds the UI component hosting the buttons. * * @return See above. */ private JPanel buildLogin() { // server information JPanel p = new JPanel(); p.setOpaque(false); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.add(serverTextPane); p.add(connectionSpeedText); JToolBar bar = new JToolBar(); bar.setOpaque(false); bar.setBorder(null); bar.setFloatable(false); if (UIUtilities.isWindowsOS()) { bar.add(Box.createHorizontalStrut(5)); bar.add(encryptedButton); bar.add(Box.createHorizontalStrut(5)); bar.add(configButton); } else { bar.add(encryptedButton); bar.add(configButton); } JPanel row = new JPanel(); row.setOpaque(false); row.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); row.add(p); row.add(bar); mainPanel.add(row); components.add(row); // user name JPanel group = new JPanel(); group.setOpaque(false); group.setLayout(new BoxLayout(group, BoxLayout.Y_AXIS)); JTextPane l = UIUtilities.buildTextPane(USER_TEXT, TEXT_COLOR); row = new JPanel(); row.setOpaque(false); row.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); row.add(l); row.add(user); group.add(row); // password l = UIUtilities.buildTextPane(" " + PASSWORD_TEXT, TEXT_COLOR); row = new JPanel(); row.setOpaque(false); row.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); row.add(l); row.add(pass); group.add(row); mainPanel.add(group); components.add(group); // controls JPanel controls = new JPanel(); controls.setOpaque(false); controls.add(Box.createHorizontalGlue()); controls.add(login); controls.add(cancel); p = UIUtilities.buildComponentPanelCenter(controls, 0, 0, false); mainPanel.add(p); components.add(p); return mainPanel; }