public ImageOps() { setBackground(Color.white); for (int i = 0; i < imgName.length; i++) { Image image = getImage(imgName[i]); int iw = image.getWidth(this); int ih = image.getHeight(this); img[i] = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB); img[i].createGraphics().drawImage(image, 0, 0, null); } slider1 = new JSlider(JSlider.VERTICAL, 0, 255, low); slider1.setPreferredSize(new Dimension(15, 100)); slider1.addChangeListener(this); slider2 = new JSlider(JSlider.VERTICAL, 0, 255, high); slider2.setPreferredSize(new Dimension(15, 100)); slider2.addChangeListener(this); setControls(new Component[] {new DemoControls(this), slider1, slider2}); setConstraints(new String[] {BorderLayout.NORTH, BorderLayout.WEST, BorderLayout.EAST}); }
public java.awt.Container createControlPanel() { java.awt.Container panel2 = Box.createVerticalBox(); panel2 = super.createControlPanel(); brainPlay = new JCheckBox("Brain Play", false); if (testMode) brainPlay.setSelected(true); panel2.add(brainPlay); JPanel row2 = new JPanel(); // ADVERSARY slider row2.add(Box.createVerticalStrut(12)); row2.add(new JLabel("Adversary:")); adversary = new JSlider(0, 100, 0); // min, max, current adversary.setPreferredSize(new Dimension(100, 15)); row2.add(adversary); JPanel text = new JPanel(); text.add(adStat = new JLabel(adversaryOff)); panel2.add(text); panel2.add(row2); JPanel row3 = new JPanel(); // Mr. Happy slider row3.add(Box.createVerticalStrut(12)); row3.add(new JLabel("CELAB")); happy = new JSlider(0, 100, 0); // min, max, current happy.setPreferredSize(new Dimension(100, 15)); row3.add(happy); JPanel text2 = new JPanel(); text2.add(adHappy = new JLabel(happyOff)); panel2.add(text2); panel2.add(row3); return (panel2); }
/** 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)); }
// Initializes this component. private void jbInit() { fileChooser.setFileFilter(new ScriptFileFilter()); this.getContentPane().setLayout(null); Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); JLabel slowLabel = new JLabel("Slow"); slowLabel.setFont(Utilities.thinLabelsFont); JLabel fastLabel = new JLabel("Fast"); fastLabel.setFont(Utilities.thinLabelsFont); labelTable.put(1, slowLabel); labelTable.put(5, fastLabel); speedSlider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { SpeedSlider_stateChanged(e); } }); speedSlider.setLabelTable(labelTable); speedSlider.setMajorTickSpacing(1); speedSlider.setPaintTicks(true); speedSlider.setPaintLabels(true); speedSlider.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); speedSlider.setPreferredSize(new Dimension(95, 50)); speedSlider.setMinimumSize(new Dimension(95, 50)); speedSlider.setToolTipText("Speed"); speedSlider.setMaximumSize(new Dimension(95, 50)); final Dimension buttonSize = new Dimension(39, 39); loadProgramButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { loadProgramButton_actionPerformed(); } }); loadProgramButton.setMaximumSize(buttonSize); loadProgramButton.setMinimumSize(buttonSize); loadProgramButton.setPreferredSize(buttonSize); loadProgramButton.setSize(buttonSize); loadProgramButton.setToolTipText("Load Program"); loadProgramButton.setIcon(loadProgramIcon); ffwdButton.setMaximumSize(buttonSize); ffwdButton.setMinimumSize(buttonSize); ffwdButton.setPreferredSize(buttonSize); ffwdButton.setToolTipText("Run"); ffwdButton.setIcon(ffwdIcon); ffwdButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ffwdButton_actionPerformed(); } }); stopButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { stopButton_actionPerformed(); } }); stopButton.setMaximumSize(buttonSize); stopButton.setMinimumSize(buttonSize); stopButton.setPreferredSize(buttonSize); stopButton.setToolTipText("Stop"); stopButton.setIcon(stopIcon); rewindButton.setMaximumSize(buttonSize); rewindButton.setMinimumSize(buttonSize); rewindButton.setPreferredSize(buttonSize); rewindButton.setToolTipText("Reset"); rewindButton.setIcon(rewindIcon); rewindButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { rewindButton_actionPerformed(); } }); scriptButton.setMaximumSize(buttonSize); scriptButton.setMinimumSize(buttonSize); scriptButton.setPreferredSize(buttonSize); scriptButton.setToolTipText("Load Script"); scriptButton.setIcon(scriptIcon); scriptButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scriptButton_actionPerformed(); } }); breakButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { breakButton_actionPerformed(); } }); breakButton.setMaximumSize(buttonSize); breakButton.setMinimumSize(buttonSize); breakButton.setPreferredSize(buttonSize); breakButton.setToolTipText("Open breakpoint panel"); breakButton.setIcon(breakIcon); breakpointWindow.addBreakpointListener(this); singleStepButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { singleStepButton_actionPerformed(); } }); singleStepButton.setMaximumSize(buttonSize); singleStepButton.setMinimumSize(buttonSize); singleStepButton.setPreferredSize(buttonSize); singleStepButton.setSize(buttonSize); singleStepButton.setToolTipText("Single Step"); singleStepButton.setIcon(singleStepIcon); stepOverButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { stepOverButton_actionPerformed(); } }); stepOverButton.setMaximumSize(buttonSize); stepOverButton.setMinimumSize(buttonSize); stepOverButton.setPreferredSize(buttonSize); stepOverButton.setSize(buttonSize); stepOverButton.setToolTipText("Step Over"); stepOverButton.setIcon(stepOverIcon); animationCombo.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { animationCombo_actionPerformed(); } }); formatCombo.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { formatCombo_actionPerformed(); } }); additionalDisplayCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { additionalDisplayCombo_actionPerformed(); } }); messageLbl.setFont(Utilities.statusLineFont); messageLbl.setBorder(BorderFactory.createLoweredBevelBorder()); messageLbl.setBounds(new Rectangle(0, 667, CONTROLLER_WIDTH - 8, 25)); toolBar = new JToolBar(); toolBar.setSize(new Dimension(TOOLBAR_WIDTH, TOOLBAR_HEIGHT)); toolBar.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 0)); toolBar.setFloatable(false); toolBar.setLocation(0, 0); toolBar.setBorder(BorderFactory.createEtchedBorder()); arrangeToolBar(); this.getContentPane().add(toolBar, null); toolBar.revalidate(); toolBar.repaint(); repaint(); // Creating the menu bar menuBar = new JMenuBar(); arrangeMenu(); setJMenuBar(menuBar); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); this.getContentPane().add(messageLbl, null); setControllerSize(); // sets the frame to be visible. setVisible(true); }
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; }