/** Class constructor - make the JFrame ready */ public TestProgram() { // Set screen size Toolkit tk = Toolkit.getDefaultToolkit(); int x = (int) tk.getScreenSize().getWidth() - 150; int y = (int) tk.getScreenSize().getHeight() - 100; this.setSize(x, y); // Some settings this.setTitle("Friends With Benefits - Test program"); field = new Field(); random = new Random(System.currentTimeMillis()); // Set the panel c = this.getContentPane(); c.setLayout(new BorderLayout()); contentpanel = new ContentPanel(); contentpanel.setField(field); c.add(contentpanel, BorderLayout.CENTER); // Menupanel menupanel = new JPanel(); layout = new GroupLayout(menupanel); menupanel.setLayout(layout); c.add(menupanel, BorderLayout.EAST); progress = new JProgressBar(0, 99); progress.setValue(99); open = new JButton("Open"); open.setFocusPainted(false); save = new JButton("Save"); save.setFocusPainted(false); open.addActionListener(this); save.addActionListener(this); everywhere = new JRadioButton("Everywhere"); everywhere.setFocusPainted(false); inRectangle = new JRadioButton("In bounding rectangle"); inRectangle.setFocusPainted(false); inRectangle.setSelected(true); placeOfCluster = new ButtonGroup(); placeOfCluster.add(everywhere); placeOfCluster.add(inRectangle); addnoise = new JButton("Add noise"); addnoise.setFocusPainted(false); addnoise.addActionListener(this); circle = new JRadioButton("Circle"); circle.setFocusPainted(false); square = new JRadioButton("Square"); square.setFocusPainted(false); circle.setSelected(true); squarecircle = new ButtonGroup(); squarecircle.add(circle); squarecircle.add(square); fillFactor = new JSlider(); fillFactor.setMajorTickSpacing(20); fillFactor.setMinorTickSpacing(5); fillFactor.setPaintTicks(true); addacluster = new JButton("Add simple cluster"); addacluster.setFocusPainted(false); addacluster.addActionListener(this); clear = new JButton("Clear field"); clear.addActionListener(this); clear.setFocusPainted(false); center = new JButton("Center field"); center.addActionListener(this); center.setFocusPainted(false); minAlgo = new JTextField(); minAlgo.setText("0"); maxAlgo = new JTextField(); maxAlgo.setText("10"); run = new JButton("Run algo"); run.addActionListener(this); run.setFocusPainted(false); empty = new JPanel(); empty.setLayout(new BorderLayout()); JSeparator sep1 = new JSeparator(); JSeparator sep2 = new JSeparator(); JSeparator sep3 = new JSeparator(); JSeparator sep4 = new JSeparator(); JLabel runalgo = new JLabel("Run algorithm"), addcluster = new JLabel("Add simple cluster"); JLabel addNoise = new JLabel("Add noise"), fillf = new JLabel("Fill factor:"); JLabel minalgo = new JLabel("Min:"), maxalgo = new JLabel("Max:"); addcluster.setFont(f); addNoise.setFont(f); runalgo.setFont(f); fillFactor.setPreferredSize( new Dimension( menupanel.getPreferredSize().width / 2, fillFactor.getPreferredSize().height)); layout.setHorizontalGroup( layout .createParallelGroup(GroupLayout.Alignment.CENTER) .addGroup( layout.createSequentialGroup().addComponent(open).addGap(2).addComponent(save)) .addComponent(sep1) .addComponent(addNoise) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(everywhere) .addComponent(inRectangle)) .addComponent(addnoise) .addComponent(sep2) .addComponent(addcluster) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(circle) .addComponent(square)) .addComponent(fillf) .addComponent(fillFactor) .addComponent(addacluster) .addComponent(sep3) .addComponent(center) .addComponent(clear) .addComponent(sep4) .addComponent(runalgo) .addGroup( layout .createSequentialGroup() .addComponent(minalgo) .addGap(2) .addComponent(minAlgo) .addGap(10) .addComponent(maxalgo) .addGap(2) .addComponent(maxAlgo)) .addComponent(run) .addComponent(empty) .addComponent(progress)); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(open) .addComponent(save)) .addGap(5) .addComponent(sep1) .addGap(5) .addComponent(addNoise) .addComponent(everywhere) .addComponent(inRectangle) .addGap(3) .addComponent(addnoise) .addGap(5) .addComponent(sep2) .addGap(5) .addComponent(addcluster) .addComponent(circle) .addComponent(square) .addGap(3) .addComponent(fillf) .addGap(3) .addComponent(fillFactor) .addGap(3) .addComponent(addacluster) .addGap(5) .addComponent(sep3) .addGap(5) .addComponent(center) .addGap(3) .addComponent(clear) .addGap(5) .addComponent(sep4) .addGap(5) .addComponent(runalgo) .addGap(3) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(minalgo) .addComponent(minAlgo) .addComponent(maxalgo) .addComponent(maxAlgo)) .addComponent(run) .addComponent(empty) .addComponent(progress)); int width = menupanel.getPreferredSize().width; setSize(addNoise, width - 10); setSize(everywhere, width - 20); setSize(inRectangle, width - 20); setSize(addnoise, width); setSize(addcluster, width - 10); setSize(circle, width - 20); setSize(square, width - 20); setSize(addacluster, width); setSize(center, width); setSize(clear, width); setSize(runalgo, width - 10); setSize(minalgo, (int) Math.floor(width / 4) - 20); setMaxSize(minAlgo, (int) Math.ceil(width / 4)); setSize(maxalgo, (int) Math.floor(width / 4) - 20); setMaxSize(maxAlgo, (int) Math.ceil(width / 4)); setSize(run, width); empty.setPreferredSize(new Dimension(width, 1000)); menupanel.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder(Color.BLACK), "Menu", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION, f)); }
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; }