public void initComponents() { GridBagLayout gridBag = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); JLabel label; JPanel panel; Dimension size; setBorder(new javax.swing.border.EtchedBorder()); setLayout(gridBag); label = new JLabel(name); constraints.anchor = GridBagConstraints.WEST; constraints.gridwidth = GridBagConstraints.REMAINDER; gridBag.setConstraints(label, constraints); add(label); panel = filterOptions(); gridBag.setConstraints(panel, constraints); add(panel); sliderCutoff = new JSlider(JSlider.VERTICAL); sliderCutoff.setPaintTicks(true); sliderCutoff.setToolTipText("Cutoff Frequency"); sliderCutoff.setMinimum(0); sliderCutoff.setMaximum(500); sliderCutoff.setMinorTickSpacing(25); sliderCutoff.setMajorTickSpacing(100); sliderCutoff.setValue(100); sliderCutoff.addChangeListener(new CutoffListener(filter)); constraints.anchor = GridBagConstraints.CENTER; constraints.gridwidth = 1; gridBag.setConstraints(sliderCutoff, constraints); add(sliderCutoff); sliderResonance = new JSlider(JSlider.VERTICAL); sliderResonance.setPaintTicks(true); sliderResonance.setToolTipText("Resonance (Pass-band Ripple)"); sliderResonance.setMinimum(1); sliderResonance.setMaximum(58); sliderResonance.setMinorTickSpacing(3); sliderResonance.setMajorTickSpacing(57); sliderResonance.setValue(1); sliderResonance.addChangeListener(new ResonanceListener(filter)); constraints.gridwidth = GridBagConstraints.REMAINDER; gridBag.setConstraints(sliderResonance, constraints); add(sliderResonance); label = new JLabel("Cutoff"); constraints.gridwidth = 1; constraints.ipadx = 10; gridBag.setConstraints(label, constraints); add(label); label = new JLabel("Resonance"); constraints.gridwidth = GridBagConstraints.REMAINDER; gridBag.setConstraints(label, constraints); add(label); }
private JComponent createSettingsPanel() { JPanel result = new JPanel(new FlowLayout(FlowLayout.RIGHT, 3, 0)); result.add(new JLabel(ApplicationBundle.message("label.font.size"))); myFontSizeSlider = new JSlider(JSlider.HORIZONTAL, 0, FontSize.values().length - 1, 3); myFontSizeSlider.setMinorTickSpacing(1); myFontSizeSlider.setPaintTicks(true); myFontSizeSlider.setPaintTrack(true); myFontSizeSlider.setSnapToTicks(true); UIUtil.setSliderIsFilled(myFontSizeSlider, true); result.add(myFontSizeSlider); result.setBorder(BorderFactory.createLineBorder(UIUtil.getBorderColor(), 1)); myFontSizeSlider.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (myIgnoreFontSizeSliderChange) { return; } EditorColorsManager colorsManager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = colorsManager.getGlobalScheme(); scheme.setQuickDocFontSize(FontSize.values()[myFontSizeSlider.getValue()]); applyFontSize(); } }); String tooltipText = ApplicationBundle.message("quickdoc.tooltip.font.size.by.wheel"); result.setToolTipText(tooltipText); myFontSizeSlider.setToolTipText(tooltipText); result.setVisible(false); result.setOpaque(true); myFontSizeSlider.setOpaque(true); return result; }
public Slider() { super("Slider"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLookAndFeel(); JSlider pickNum = new JSlider(JSlider.HORIZONTAL, 0, 30, 5); pickNum.setMajorTickSpacing(10); pickNum.setMinorTickSpacing(1); pickNum.setPaintTicks(true); pickNum.setPaintLabels(true); add(pickNum); pack(); setVisible(true); }
ApplicationFrame() { super("Ecuatii Neliniare"); setSize(frameWidth, frameHeight); setDefaultCloseOperation(this.EXIT_ON_CLOSE); panel.setOpaque(true); getContentPane().add(panel); addComponentListener(this); for (int i = 0; i < Methods.length; i++) ChooseMethod.addItem(Methods[i]); buttonPanel.add(ChooseMethod); buttonPanel.setOpaque(true); JButton buttonAdd = new JButton("Aplica..."); buttonAdd.setPreferredSize(new Dimension(125, 25)); buttonAdd.addActionListener(this); buttonPanel.add(buttonAdd); unitXSlider.setMinorTickSpacing(5); unitXSlider.setPaintTicks(true); unitXSlider.addChangeListener(this); unitYSlider.setMinorTickSpacing(5); unitYSlider.setPaintTicks(true); unitYSlider.addChangeListener(this); buttonPanel.add(unitXSlider); buttonPanel.add(unitYSlider); Border padding = BorderFactory.createEmptyBorder(0, 20, 20, 20); panel.setBorder(padding); panel.add(buttonPanel, BorderLayout.NORTH); panel.add(graph, BorderLayout.CENTER); pack(); setVisible(true); }
private JSlider makeJSlider() { JSlider slider = new JSlider(JSlider.VERTICAL, 0, 10, 1); slider.setMajorTickSpacing(1); slider.setPaintTicks(true); slider.setSnapToTicks(true); Hashtable labelTable = new Hashtable(); for (int i = 0; i <= 10; i += 2) { labelTable.put(new Integer(i), new JLabel(i + " Seconds")); } slider.setLabelTable(labelTable); slider.setPaintLabels(true); return slider; }
/** 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); }
private void makeComponents() { this.getWwd().setPreferredSize(new Dimension(1024, 768)); JPanel panel = new JPanel(new BorderLayout()); { panel.setBorder(new EmptyBorder(10, 0, 10, 0)); JPanel controlPanel = new JPanel(new BorderLayout(0, 10)); controlPanel.setBorder(new EmptyBorder(20, 10, 20, 10)); JPanel btnPanel = new JPanel(new GridLayout(5, 1, 0, 5)); { JButton btn = new JButton("Zoom to Matterhorn"); btn.setActionCommand(ACTION_COMMAND_BUTTON1); btn.addActionListener(this.controller); btnPanel.add(btn); btn = new JButton("DEMO getElevations()"); btn.setActionCommand(ACTION_COMMAND_BUTTON2); btn.addActionListener(this.controller); btnPanel.add(btn); btn = new JButton("DEMO getElevation()"); btn.setActionCommand(ACTION_COMMAND_BUTTON3); btn.addActionListener(this.controller); btnPanel.add(btn); btn = new JButton("DEMO new getElevations"); btn.setActionCommand(ACTION_COMMAND_BUTTON4); btn.addActionListener(this.controller); btnPanel.add(btn); // btn = new JButton("Button 5"); // btn.setActionCommand(ACTION_COMMAND_BUTTON5); // btn.addActionListener(this.controller); // btnPanel.add(btn); } controlPanel.add(btnPanel, BorderLayout.NORTH); JPanel vePanel = new JPanel(new BorderLayout(0, 5)); { JLabel label = new JLabel("Vertical Exaggeration"); vePanel.add(label, BorderLayout.NORTH); int MIN_VE = 1; int MAX_VE = 8; int curVe = (int) this.getWwd().getSceneController().getVerticalExaggeration(); curVe = curVe < MIN_VE ? MIN_VE : (curVe > MAX_VE ? MAX_VE : curVe); JSlider slider = new JSlider(MIN_VE, MAX_VE, curVe); slider.setMajorTickSpacing(1); slider.setPaintTicks(true); slider.setSnapToTicks(true); Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); labelTable.put(1, new JLabel("1x")); labelTable.put(2, new JLabel("2x")); labelTable.put(4, new JLabel("4x")); labelTable.put(8, new JLabel("8x")); slider.setLabelTable(labelTable); slider.setPaintLabels(true); slider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { double ve = ((JSlider) e.getSource()).getValue(); ActionEvent ae = new ActionEvent(ve, 0, ACTION_COMMAND_VERTICAL_EXAGGERATION); controller.actionPerformed(ae); } }); vePanel.add(slider, BorderLayout.SOUTH); } controlPanel.add(vePanel, BorderLayout.SOUTH); panel.add(controlPanel, BorderLayout.SOUTH); this.layerPanel = new LayerPanel(this.getWwd(), null); panel.add(this.layerPanel, BorderLayout.CENTER); } getContentPane().add(panel, BorderLayout.WEST); }
public ControlPanel(int width, int height) { this.width = width; this.height = height; // create 2 ball panels ballPanel = new JPanel(); ballPanel.setLayout(new GridLayout(2, 1)); ball1 = new BallPanel(0, 65, Color.RED, Color.CYAN); ball2 = new BallPanel(0, 65, Color.BLUE, Color.YELLOW); ballPanel.add(ball1); ballPanel.add(ball2); // create 10 buttons upRed = new JButton("Up Red"); downRed = new JButton("Down Red"); leftRed = new JButton("Left Red"); rightRed = new JButton("Right Red"); stopRed = new JButton("Stop Red"); upBlue = new JButton("Up Blue"); downBlue = new JButton("Down Blue"); leftBlue = new JButton("Left Blue"); rightBlue = new JButton("Right Blue"); stopBlue = new JButton("Stop Blue"); // create 2 sliders slider1 = new JSlider(JSlider.VERTICAL, 0, 50, 20); slider1.setMajorTickSpacing(10); slider1.setMinorTickSpacing(1); slider1.setPaintTicks(true); slider1.setPaintLabels(true); slider2 = new JSlider(JSlider.VERTICAL, 0, 50, 20); slider2.setMajorTickSpacing(10); slider2.setMinorTickSpacing(1); slider2.setPaintTicks(true); slider2.setPaintLabels(true); // add the corresponding listener to sliders and buttons ActionListener bListener = new ButtonListener(); SliderListener sListener = new SliderListener(); upRed.addActionListener(bListener); downRed.addActionListener(bListener); leftRed.addActionListener(bListener); rightRed.addActionListener(bListener); stopRed.addActionListener(bListener); upBlue.addActionListener(bListener); downBlue.addActionListener(bListener); leftBlue.addActionListener(bListener); rightBlue.addActionListener(bListener); stopBlue.addActionListener(bListener); slider1.addChangeListener(sListener); slider2.addChangeListener(sListener); // organize 5 buttons into a panel using grid layout buttonPanel1 = new JPanel(); buttonPanel1.setLayout(new GridLayout(5, 1)); buttonPanel1.add(upRed); buttonPanel1.add(downRed); buttonPanel1.add(leftRed); buttonPanel1.add(rightRed); buttonPanel1.add(stopRed); // organize 5 buttons into a panel using grid layout buttonPanel2 = new JPanel(); buttonPanel2.setLayout(new GridLayout(5, 1)); buttonPanel2.add(upBlue); buttonPanel2.add(downBlue); buttonPanel2.add(leftBlue); buttonPanel2.add(rightBlue); buttonPanel2.add(stopBlue); // create 2 labels label1 = new JLabel("Red Ball Delay"); label2 = new JLabel("Blue Ball Delay"); // organize a label and a slider into a panel using border layout sliderPanel1 = new JPanel(); sliderPanel1.setLayout(new BorderLayout()); sliderPanel1.add(label1, BorderLayout.NORTH); sliderPanel1.add(slider1, BorderLayout.CENTER); sliderPanel2 = new JPanel(); sliderPanel2.setLayout(new BorderLayout()); sliderPanel2.add(label2, BorderLayout.NORTH); sliderPanel2.add(slider2, BorderLayout.CENTER); // organize the panel containing buttons and the panel with a slider settingsPanel = new JPanel(); settingsPanel.setLayout(new GridLayout(2, 2)); settingsPanel.add(buttonPanel1); settingsPanel.add(sliderPanel1); settingsPanel.add(buttonPanel2); settingsPanel.add(sliderPanel2); // organize a label and a slider into a panel using border layout setLayout(new BorderLayout()); add(settingsPanel, BorderLayout.WEST); add(ballPanel, BorderLayout.CENTER); }
/** Construct the TV object - that is, the main GUI for the program */ public TV(JFrame f, TD mod) { super(); frm = f; theTD = mod; JButton b; // Build the GUI toolBar = new JToolBar(); toolBar.setFloatable(false); toolBar.getAccessibleContext().setAccessibleName("File Toolbar"); toolBar.addSeparator(); b = addTool(toolBar, "Cut"); b = addTool(toolBar, "Copy"); b = addTool(toolBar, "Paste"); toolBar.addSeparator(); toolBar.putClientProperty("JToolBar.isRollover", Boolean.FALSE); // The Slider numSlider = new JSlider(JSlider.HORIZONTAL, 1, 40, 1); numSlider.setPaintTicks(true); numSlider.setPaintLabels(false); numSlider.setMajorTickSpacing(10); numSlider.setMinorTickSpacing(2); numSlider.setExtent(1); numSlider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent ce) { // System.out.println("CHANGE: " + ce); setQNumber(((JSlider) (ce.getSource())).getValue()); } }); numSlider.setToolTipText("Slide to select question by number"); toolBar.add(numSlider); // The Question# textfield toolBar.add(numTF = new JTextField("01")); numTF.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String num = ((JTextField) e.getSource()).getText(); int n = Integer.parseInt(num.trim()); setQNumber(n); } }); numTF.setToolTipText("Type number to select question by number"); // The First Button b = addTool(toolBar, "First"); b.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { setQNumber(1); } }); // The Previous Button b = addTool(toolBar, "Previous"); b.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (getQNumber() <= 1) return; setQNumber(getQNumber() - 1); } }); // The Next Button b = addTool(toolBar, "Next"); b.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (getQNumber() >= getNumQuestions()) return; setQNumber(getQNumber() + 1); } }); // The "Last" Button b = addTool(toolBar, "Last"); b.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { setQNumber(getNumQuestions()); } }); add(BorderLayout.NORTH, toolBar); // Rest is a panel to hold the questions, one at a time. questionsPanel = new JPanel(); questionsPanel.setLayout(myCardLayout = new CardLayout()); add(BorderLayout.SOUTH, questionsPanel); fc = new FileDialog(frm); fc.setFilenameFilter( new FilenameFilter() { public boolean accept(File ff, String fname) { // System.out.println("accept("+fname+")"); // XXX TODO list of extentions, from properties. return fname.endsWith(".xam"); } }); TV.centre(fc); }
public Display(String title) throws IOException { super(title); setLayout(new GridLayout(1, 3)); JPanel options = new JPanel(new GridLayout(5, 1)); JPanel numCircles = new JPanel((new GridLayout(1, 2))); addWindowListener(this); b = new Button("Load Image"); c = new Button("filter"); findCircles = new Button("Find"); inputCircles = new JTextField("12"); numCircles.add(inputCircles); numCircles.add(findCircles); options.add(b); options.add(c); add(options); filterBtn = new JRadioButton("Filtered"); sobelBtn = new JRadioButton("Sobel"); nonMaxBtn = new JRadioButton("Non Maximal"); accumulator = new JRadioButton("Accumulator"); whichRadius = new JSlider(JSlider.HORIZONTAL, rmin, 125, 14); whichRadius.setMajorTickSpacing(10); whichRadius.setMinorTickSpacing(1); whichRadius.setPaintTicks(true); whichRadius.setPaintLabels(true); whichRadius.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); Font font = new Font("Serif", Font.ITALIC, 6); whichRadius.setFont(font); ButtonGroup rGroup = new ButtonGroup(); rGroup.add(filterBtn); rGroup.add(sobelBtn); rGroup.add(nonMaxBtn); rGroup.add(accumulator); JPanel radioPanel = new JPanel(new GridLayout(0, 1)); radioPanel.add(filterBtn); radioPanel.add(sobelBtn); radioPanel.add(nonMaxBtn); radioPanel.add(accumulator); options.add(radioPanel); options.add(numCircles); options.add(whichRadius); loadImage(); add(lbl1); add(lbl2); b.addActionListener(this); c.addActionListener(this); filterBtn.addActionListener(this); sobelBtn.addActionListener(this); nonMaxBtn.addActionListener(this); findCircles.addActionListener(this); accumulator.addActionListener(this); whichRadius.addChangeListener(this); }
public NumberField(NumberOption option) { super(option); panel = new JPanel(new GridBagLayout()); this.step = option.getStep(); Double min = option.getMin(); Double max = option.getMax(); Double defl = new Double(option.getDefault()); // Normalize parameters if (min != null && defl.compareTo(min) < 0) { defl = min; } else if (max != null && defl.compareTo(max) > 0) { defl = max; } if (min != null) { sliderMin = (int) (min.doubleValue() / step); } else { sliderMin = SLIDER_DEFAULT_MIN; } if (max != null) { sliderMax = (int) (max.doubleValue() / step); } else { sliderMax = SLIDER_DEFAULT_MAX; } // Create spinner SpinnerNumberModel spinnerModel = new SpinnerNumberModel(defl, min, max, new Double(step)); spinner = new JSpinner(spinnerModel); ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().setColumns(FIELD_WIDTH); // Create slider slider = new JSlider(sliderMin, sliderMax, sliderIndex(defl)); slider.setPaintLabels(false); slider.setPaintTicks(false); slider.setSnapToTicks(false); // Add listeners. The spinner is the master and the slider is // the slave. spinner.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int newIndex = sliderIndex((Double) spinner.getValue()); if (slider.getValue() != newIndex) { slider.setValue(newIndex); } fireChangeEvent(); } }); slider.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int newIndex = slider.getValue(); if (newIndex != sliderIndex((Double) spinner.getValue())) { spinner.setValue(new Double(newIndex * step)); } } }); // Create enable checkbox configureEnableToggle( option.isInitiallyEnabled(), string(option.getDisabledValue()), Arrays.asList((JComponent) spinner, slider)); // Add to the panel panel.add(spinner); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(0, 8, 0, 0); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; panel.add(slider, c); }