예제 #1
0
 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);
 }
  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;
  }
  // 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);
  }
예제 #6
0
  /** 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);
  }
예제 #7
0
  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);
  }
예제 #8
0
    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);
    }