private void createGUI() { Container contentPane = this.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(desktop, BorderLayout.CENTER); JMenuBar menuBar = new JMenuBar(); createMenuBar(menuBar); this.setJMenuBar(menuBar); JXStatusBar statusBar = new JXStatusBar(); statusLabel = new JLabel(); statusBar.add(statusLabel); contentPane.add(statusBar, BorderLayout.SOUTH); updateStatus(Messages.getString("Frame.statusApplicationStarted")); // $NON-NLS-1$ }
@Override protected void paintBackground(Graphics2D g, JXStatusBar bar) { int w = bar.getWidth(); // TODO deal with insets int h = bar.getHeight(); // TODO deal with insets // This list is comprised of floats and Colors, which together // constitute the gradient. List<?> gradient = (List<?>) UIManager.get("MenuBar.gradient"); if (gradient != null && w > 0 && 0 < h) { float ratio1 = ((Number) gradient.get(0)).floatValue(); float ratio2 = ((Number) gradient.get(1)).floatValue(); Color c1 = (Color) gradient.get(2); Color c2 = (Color) gradient.get(3); Color c3 = (Color) gradient.get(4); int mid = (int) (ratio1 * h); int mid2 = (int) (ratio2 * h); if (mid > 0) { g.setPaint(new GradientPaint((float) 0, (float) 0, c1, (float) 0, (float) mid, c2)); g.fillRect(0, 0, w, mid); } if (mid2 > 0) { g.setColor(c2); g.fillRect(0, mid, w, mid2); } if (mid > 0) { g.setPaint( new GradientPaint( (float) 0, (float) mid + mid2, c2, (float) 0, (float) mid * 2 + mid2, c1)); g.fillRect(0, mid + mid2, w, mid); } if (h - mid * 2 - mid2 > 0) { g.setPaint( new GradientPaint((float) 0, (float) mid * 2 + mid2, c1, (float) 0, (float) h, c3)); g.fillRect(0, mid * 2 + mid2, w, h - mid * 2 - mid2); } } }
protected static JXStatusBar getStatusBar( final JXPanel jxPanel, final JTabbedPane mainTabbedPane) { JXStatusBar statusBar = new JXStatusBar(); try { ClassLoader cl = Thread.currentThread().getContextClassLoader(); Enumeration<URL> urls = cl.getResources("META-INF/MANIFEST.MF"); String substanceVer = null; String substanceBuildStamp = null; while (urls.hasMoreElements()) { InputStream is = urls.nextElement().openStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); while (true) { String line = br.readLine(); if (line == null) break; int firstColonIndex = line.indexOf(":"); if (firstColonIndex < 0) continue; String name = line.substring(0, firstColonIndex).trim(); String val = line.substring(firstColonIndex + 1).trim(); if (name.compareTo("Substance-Version") == 0) substanceVer = val; if (name.compareTo("Substance-BuildStamp") == 0) substanceBuildStamp = val; } try { br.close(); } catch (IOException ioe) { } } if (substanceVer != null) { JLabel statusLabel = new JLabel(substanceVer + " [built on " + substanceBuildStamp + "]"); JXStatusBar.Constraint cStatusLabel = new JXStatusBar.Constraint(); cStatusLabel.setFixedWidth(300); statusBar.add(statusLabel, cStatusLabel); } } catch (IOException ioe) { } JXStatusBar.Constraint c2 = new JXStatusBar.Constraint(JXStatusBar.Constraint.ResizeBehavior.FILL); final JLabel tabLabel = new JLabel(""); statusBar.add(tabLabel, c2); mainTabbedPane .getModel() .addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int selectedIndex = mainTabbedPane.getSelectedIndex(); if (selectedIndex < 0) tabLabel.setText("No selected tab"); else tabLabel.setText("Tab " + mainTabbedPane.getTitleAt(selectedIndex) + " selected"); } }); JPanel fontSizePanel = FontSizePanel.getPanel(); JXStatusBar.Constraint fontSizePanelConstraints = new JXStatusBar.Constraint(); fontSizePanelConstraints.setFixedWidth(270); statusBar.add(fontSizePanel, fontSizePanelConstraints); JPanel alphaPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0)); final JLabel alphaLabel = new JLabel("100%"); final JSlider alphaSlider = new JSlider(0, 100, 100); alphaSlider.setFocusable(false); alphaSlider.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int currValue = alphaSlider.getValue(); alphaLabel.setText(currValue + "%"); jxPanel.setAlpha(currValue / 100.0f); } }); alphaSlider.setToolTipText("Changes the global opacity. Is not Substance-specific"); alphaSlider.setPreferredSize(new Dimension(120, alphaSlider.getPreferredSize().height)); alphaPanel.add(alphaLabel); alphaPanel.add(alphaSlider); JXStatusBar.Constraint alphaPanelConstraints = new JXStatusBar.Constraint(); alphaPanelConstraints.setFixedWidth(160); statusBar.add(alphaPanel, alphaPanelConstraints); return statusBar; }