Java Code Examples for javax.swing.JSlider#addChangeListener()

The following examples show how to use javax.swing.JSlider#addChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Sepia.java    From marvinproject with GNU Lesser General Public License v3.0 6 votes vote down vote up
public MarvinAttributesPanel getAttributesPanel(){ 
	if(attributesPanel == null){
		attributesPanel = new MarvinAttributesPanel();
		attributesPanel.addLabel("lblIntensidade", "Intensidade do Filtro");
		attributesPanel.addHorizontalSlider("hsIntensidade", "hsIntensidade", 0, 100, 20, attributes);
		attributesPanel.newComponentRow();
		attributesPanel.addTextField("txtValue", "txtValue",attributes);
			
		JTextField txtValue = (JTextField)(attributesPanel.getComponent("txtValue").getComponent());
		JSlider slider = (JSlider)(attributesPanel.getComponent("hsIntensidade").getComponent());
		
		slider.addChangeListener(this);
		txtValue.addKeyListener(this);
	}
	
	return attributesPanel;
}
 
Example 2
Source File: BlockDemo.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
 
    protected void addFuzzyControls(JPanel cntrl) {
        JPanel sp = new JPanel();
        sp.add(new JLabel("Position:"));
//        final double  maxAng=50;
        final double  steps=200;
//        final double fact=maxAng/steps/steps;
//        
        posSlider = new JSlider((int)-steps, (int)steps);
        //     final SpinnerNumberModel smA = new SpinnerNumberModel((int) angle, -180, 180, 1);
        posSlider.addChangeListener(new ChangeListener() {

            
            public void stateChanged(ChangeEvent e) {
                double x = 3.0*posSlider.getValue()/(double)steps;
                ((BlockFuzzyController) fuzzyController).setTargetPosition(x);
            }
        });
        posSlider.setEnabled(fuzzyControlActive);
        sp.add(posSlider);

        cntrl.add(sp);

    }
 
Example 3
Source File: ViewElementSlider.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
public ViewElementSlider(RobotOverlord ro,IntEntity e,int top,int bottom) {
	super(ro);
	this.e=e;

	e.addObserver(this);
	
	field = new JSlider();
	field.setMaximum(top);
	field.setMinimum(bottom);
	field.setMinorTickSpacing(1);
	field.setValue(e.get());
	field.addChangeListener(this);
	field.addFocusListener(this);

	JLabel label = new JLabel(e.getName(),JLabel.LEADING);
	value = new JLabel(Integer.toString(field.getValue()),JLabel.RIGHT);
	Dimension dim = new Dimension(30,1);
	value.setMinimumSize(dim);
	value.setPreferredSize(dim);
	value.setMaximumSize(dim);
	
	panel.setLayout(new BorderLayout());
	panel.add(label,BorderLayout.LINE_START);
	panel.add(field,BorderLayout.CENTER);
	panel.add(value,BorderLayout.LINE_END);
}
 
Example 4
Source File: LabChooserJFrame.java    From meshnet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create the frame.
 */
public LabChooserJFrame(CieXYZColorSelectedListener clickedListener) {
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	setBounds(100, 100, 450, 300);
	contentPane = new LabChooserJPanel();
	contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
	contentPane.setLayout(new BorderLayout(0, 0));
	setContentPane(contentPane);
	
	this.clickedListener = clickedListener;
	
	final JSlider slider = new JSlider(0, 100, 0);
	slider.addChangeListener(new ChangeListener() {
		public void stateChanged(ChangeEvent e) {
			currL = slider.getValue();
			contentPane.drawColorChooser();
			contentPane.repaint();
		}
	});
	getContentPane().add(slider, BorderLayout.NORTH);
}
 
Example 5
Source File: TrackingPong.java    From marvinproject with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void loadGUI(){	
	setTitle("Video Sample - Tracking Pong");
	
	videoPanel.addMouseListener(new MouseHandler());
	
	sliderSensibility = new JSlider(JSlider.HORIZONTAL, 0, 60, 30);
	sliderSensibility.setMinorTickSpacing(2);
	sliderSensibility.setPaintTicks(true);
	sliderSensibility.addChangeListener(new SliderHandler());
	
	labelSlider = new JLabel("Sensibility");
	
	panelSlider = new JPanel();
	panelSlider.add(labelSlider);
	panelSlider.add(sliderSensibility);
	
	Container container = getContentPane();
	container.setLayout(new BorderLayout());
	container.add(videoPanel, BorderLayout.NORTH);
	container.add(panelSlider, BorderLayout.SOUTH);
	
	setSize(videoInterface.getImageWidth()+20,videoInterface.getImageHeight()+100);
	setVisible(true);
}
 
Example 6
Source File: IPDemo.java    From jFuzzyLogic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void addFuzzyControls(JPanel cntrl) {
    JPanel sp = new JPanel();
    sp.add(new JLabel("Angle:"));
    final double  maxAng=50;
    final double  steps=200;
    final double fact=maxAng/steps/steps;
    
    angleSlider = new JSlider((int)-steps, (int)steps);
    //     final SpinnerNumberModel smA = new SpinnerNumberModel((int) angle, -180, 180, 1);
    angleSlider.addChangeListener(new ChangeListener() {

        
        public void stateChanged(ChangeEvent e) {
            angle = angleSlider.getValue();
            angle= Math.abs(angle)*angle*fact;
            ((IPFuzzyController2) fuzzyController).setTargetAngle(angle);
        }
    });
    angleSlider.setEnabled(fuzzyControlActive);
    sp.add(angleSlider);

    cntrl.add(sp);

}
 
Example 7
Source File: Slider.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
public Slider(JFrame parent, String title, String question,
        int defaultValue, int min, int max) {
    super(parent, title, true);
    super.setResizable(false);

    value = new JSlider(SwingConstants.HORIZONTAL, min, max, defaultValue);
    value.addChangeListener(this);

    getContentPane().setLayout(new BorderLayout());
    JPanel qp = new JPanel();
    qp.setLayout(new BorderLayout());
    lblText.setText(question);
    qp.add(lblText, BorderLayout.NORTH);
    getContentPane().add(qp, BorderLayout.NORTH);

    JPanel sp1 = new JPanel();
    sp1.setLayout(new FlowLayout());
    minText.setText(String.valueOf(min));
    maxText.setText(String.valueOf(max));
    curText.setText(String.valueOf(defaultValue));
    sp1.add(minText);
    sp1.add(value);
    sp1.add(maxText);
    sp1.add(curText);
    getContentPane().add(sp1, BorderLayout.CENTER);

    JPanel p = new JPanel();
    p.setLayout(new FlowLayout());
    butOk.addActionListener(this);
    p.add(butOk);
    butCancel.addActionListener(this);
    p.add(butCancel);
    getContentPane().add(p, BorderLayout.SOUTH);
    pack();
    setLocation(parent.getLocation().x + parent.getSize().width / 2
            - getSize().width / 2, parent.getLocation().y
            + parent.getSize().height / 2 - getSize().height / 2);
}
 
Example 8
Source File: AlphaCompositesApplication.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Component buildOpacitySelector() {
    opacity = new JSlider(0, 100, 50);
    opacity.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent changeEvent) {
            changeComposite();
        }
    });
    JPanel panel = new JPanel();
    panel.add(new JLabel("0%"));
    panel.add(opacity);
    panel.add(new JLabel("100%"));
    return panel;
}
 
Example 9
Source File: VolumeSliderPanel.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
public VolumeSliderPanel(int initialValue, MagicSound aSound) {

        slider = new JSlider(0, 100, initialValue);
        slider.setFocusable(false);
        slider.addChangeListener((event) -> {
            if (!slider.getValueIsAdjusting()) {
                aSound.play(slider.getValue());
            }
        });

        setLayout(new MigLayout());
        add(new JLabel("Off"));
        add(slider, "w 100%");
        add(new JLabel("100%"));
    }
 
Example 10
Source File: SoundSettings.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a volume slider, and initialize its value from the volume of a
 * channel.
 *
 * @param channel channel corresponding to the slider
 * @return volume slider for the channel
 */
private JSlider createVolumeSlider(String channel) {
	JSlider slider = new JSlider(0, 100);
	SoundGroup group = ClientSingletonRepository.getSound().getGroup(channel);
	slider.setValue(Numeric.floatToInt(group.getVolume(), 100f));
	slider.addChangeListener(new ChannelChangeListener(channel, group));

	return slider;
}
 
Example 11
Source File: SimpleMotionDetection.java    From marvinproject with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void loadGUI(){
	setTitle("Simple Motion Detection");
	labelMotion = new JLabel("MOTION: NO");
	labelMotion.setOpaque(true);
	labelMotion.setHorizontalAlignment(SwingConstants.CENTER);
	
	labelMotion.setBackground(Color.red);
	labelMotion.setForeground(Color.white);
	
	labelSlider = new JLabel("Sensibility:");
	
	sliderSensibility = new JSlider(JSlider.HORIZONTAL, 0, 13, 10);
	sliderSensibility.setMinorTickSpacing(1);
	sliderSensibility.setPaintTicks(true);
	sliderSensibility.addChangeListener(new SliderHandler());
	
	panelCenter = new JPanel(new BorderLayout());
	panelCenter.add(videoPanel, BorderLayout.NORTH);
	panelCenter.add(labelMotion, BorderLayout.SOUTH);
	
	panelSlider = new JPanel();
	panelSlider.add(labelSlider);
	panelSlider.add(sliderSensibility);
	
	Container l_container = getContentPane();
	l_container.add(videoPanel, BorderLayout.NORTH);
	l_container.add(labelMotion, BorderLayout.CENTER);
	l_container.add(panelSlider, BorderLayout.SOUTH);
	
	
	setSize(imageWidth,imageHeight+100);
	setVisible(true);
}
 
Example 12
Source File: ColorizationFactor.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates the main frame for <code>this</code> sample.
 */
public ColorizationFactor() {
    super("Colorization factor");

    this.setLayout(new BorderLayout());

    final JPanel panel = new JPanel(new FlowLayout());
    JButton button = new JButton("sample");
    button.setBackground(Color.yellow);
    button.setForeground(Color.red);
    panel.add(button);
    JCheckBox checkbox = new JCheckBox("sample");
    checkbox.setSelected(true);
    checkbox.setBackground(Color.green.brighter());
    checkbox.setForeground(Color.blue.darker());
    panel.add(checkbox);
    JRadioButton radiobutton = new JRadioButton("sample");
    radiobutton.setSelected(true);
    radiobutton.setBackground(Color.yellow);
    radiobutton.setForeground(Color.green.darker());
    panel.add(radiobutton);

    this.add(panel, BorderLayout.CENTER);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    final JSlider colorizationSlider = new JSlider(0, 100, 50);
    colorizationSlider.addChangeListener((ChangeEvent e) -> {
        double val = colorizationSlider.getValue() / 100.0;
        SubstanceCortex.ComponentOrParentChainScope.setColorizationFactor(panel, val);
        panel.repaint();
    });
    controls.add(colorizationSlider);

    this.add(controls, BorderLayout.SOUTH);

    this.setSize(400, 200);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
 
Example 13
Source File: ColorPick.java    From Spark with Apache License 2.0 5 votes vote down vote up
public void addChangeListener(ChangeListener cl)
   {
for(JSlider sl : _sliderarray)
{
    sl.addChangeListener(cl);
}
   }
 
Example 14
Source File: TestbedSidePanel.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void addSettings(JPanel argPanel, TestbedSettings argSettings, SettingType argIgnore) {
  for (TestbedSetting setting : argSettings.getSettings()) {
    if (setting.settingsType == argIgnore) {
      continue;
    }
    switch (setting.constraintType) {
      case RANGE:
        JLabel text = new JLabel(setting.name + ": " + setting.value);
        JSlider slider = new JSlider(setting.min, setting.max, setting.value);
        slider.setMaximumSize(new Dimension(200, 20));
        slider.addChangeListener(this);
        slider.setName(setting.name);
        slider.putClientProperty(SETTING_TAG, setting);
        slider.putClientProperty(LABEL_TAG, text);
        argPanel.add(text);
        argPanel.add(slider);
        break;
      case BOOLEAN:
        JCheckBox checkbox = new JCheckBox(setting.name);
        checkbox.setSelected(setting.enabled);
        checkbox.addChangeListener(this);
        checkbox.putClientProperty(SETTING_TAG, setting);
        argPanel.add(checkbox);
        break;
    }
  }
}
 
Example 15
Source File: Plugin.java    From marvinproject with GNU Lesser General Public License v3.0 5 votes vote down vote up
public MarvinAttributesPanel getAttributesPanel(){
	if(attributesPanel == null){
		attributesPanel = new MarvinAttributesPanel();
		attributesPanel.addLabel("lblC", "Cyan");
		attributesPanel.addHorizontalSlider("hsR", "hsR", -100, 100, 0, attributes);
		attributesPanel.addLabel("lblR", "Red");
		attributesPanel.addTextField("txtR", "txtR",attributes);
		
		attributesPanel.newComponentRow();
		attributesPanel.addLabel("lblM", "Magenta");
		attributesPanel.addHorizontalSlider("hsG", "hsG", -100, 100, 0, attributes);
		attributesPanel.addLabel("lblG", "Green");
		attributesPanel.addTextField("txtG", "txtG",attributes);
		
		attributesPanel.newComponentRow();
		attributesPanel.addLabel("lblY", "Yellow");
		attributesPanel.addHorizontalSlider("hsB", "hsB", -100, 100, 0, attributes);
		attributesPanel.addLabel("lblB", "Blue");
		attributesPanel.addTextField("txtB", "txtB",attributes);
		
		attributesPanel.newComponentRow();
		
			
		JSlider sliderR = (JSlider)(attributesPanel.getComponent("hsR").getComponent());
		JSlider sliderG = (JSlider)(attributesPanel.getComponent("hsG").getComponent());
		JSlider sliderB = (JSlider)(attributesPanel.getComponent("hsB").getComponent());
		
		JTextField txtR = (JTextField)(attributesPanel.getComponent("txtR").getComponent());
		JTextField txtG = (JTextField)(attributesPanel.getComponent("txtG").getComponent());
		JTextField txtB = (JTextField)(attributesPanel.getComponent("txtB").getComponent());
		
		sliderR.addChangeListener(this);
		sliderG.addChangeListener(this);
		sliderB.addChangeListener(this);
		txtR.addKeyListener(this);
		txtG.addKeyListener(this);
		txtB.addKeyListener(this);
	}
	return attributesPanel;
}
 
Example 16
Source File: AqlViewer.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
private <X, Y> Component viewAlgebra(float z,
		Algebra<catdata.aql.exp.Ty, catdata.aql.exp.En, catdata.aql.exp.Sym, catdata.aql.exp.Fk, catdata.aql.exp.Att, catdata.aql.exp.Gen, catdata.aql.exp.Sk, X, Y> algebra) {

	JPanel top = new JPanel(new GridBagLayout());
	top.setBorder(BorderFactory.createEmptyBorder());

	JCheckBox simp = new JCheckBox("", false);
	int a = Integer.min(maxrows, algebra.sizeOfBiggest());
	JSlider sl = new JSlider(0, a, Integer.min(32, a));

	JLabel limit = new JLabel("Row limit:", JLabel.RIGHT);

	JLabel lbl = new JLabel("Provenance:", JLabel.RIGHT);
	JLabel ids = new JLabel(
			" " + algebra.size() + " IDs, " + algebra.talg().sks.size() + " nulls, " + z + " seconds.",
			JLabel.LEFT);

	GridBagConstraints gbc = new GridBagConstraints();
	gbc.weightx = 1;
	gbc.fill = GridBagConstraints.HORIZONTAL;

	gbc.anchor = GridBagConstraints.WEST;
	top.add(ids, gbc);

	gbc.anchor = GridBagConstraints.EAST;
	top.add(lbl, gbc);
	gbc.anchor = GridBagConstraints.WEST;
	top.add(simp, gbc);
	gbc.anchor = GridBagConstraints.EAST;
	top.add(limit, gbc);
	gbc.anchor = GridBagConstraints.WEST;
	top.add(sl, gbc);

	JPanel out = new JPanel(new BorderLayout());
	out.setBorder(BorderFactory.createEtchedBorder());

	Map<Pair<Boolean, Integer>, JScrollPane> cache = new THashMap<>();
	viewAlgebraHelper(top, algebra, out, simp, sl, cache);

	sl.addChangeListener((x) -> {
		viewAlgebraHelper(top, algebra, out, simp, sl, cache);
	});
	simp.addChangeListener((x) -> {
		viewAlgebraHelper(top, algebra, out, simp, sl, cache);
	});

	return out;
}
 
Example 17
Source File: MainWindow.java    From Creatures with GNU General Public License v2.0 4 votes vote down vote up
private void initUI(WorldView view) {
	JPanel rightContainer = new JPanel();
	rightContainer.setLayout(new BoxLayout(rightContainer, BoxLayout.PAGE_AXIS));

	textLabel = new JLabel("Creatures");
	textLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
	
	speedLabel = new JLabel("Speed");
	speedLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
	
	speedSlider = new JSlider(0, 15, 1);
	speedSlider.setAlignmentX(Component.LEFT_ALIGNMENT);
	speedSlider.setMajorTickSpacing(5);
	speedSlider.setMinorTickSpacing(1);
	speedSlider.setSnapToTicks(true);
	speedSlider.setPaintLabels(true);
	speedSlider.setPaintTicks(true);
	speedSlider.addChangeListener(this);
	
	JPanel maxFoodContainer = new JPanel();
	maxFoodContainer.setLayout(new FlowLayout(FlowLayout.LEFT));
	maxFoodContainer.setAlignmentX(Component.LEFT_ALIGNMENT);
	
	maxFoodLabel = new JLabel("Max Food");
	SpinnerModel maxFoodSpinnerModel = new SpinnerNumberModel(WorldModel.maxFoodAmount, 0, 100000, 1);
	maxFoodSpinner = new JSpinner(maxFoodSpinnerModel);
	maxFoodSpinner.setEditor(new JSpinner.NumberEditor(maxFoodSpinner, "#"));
	maxFoodSpinner.addChangeListener(this);
	
	maxFoodContainer.add(maxFoodLabel);
	maxFoodContainer.add(maxFoodSpinner);
	
	rightContainer.add(textLabel);
	rightContainer.add(Box.createVerticalStrut(10));
	rightContainer.add(speedLabel);
	rightContainer.add(speedSlider);
	rightContainer.add(maxFoodContainer);

	splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, view, rightContainer);
	splitPane.setResizeWeight(0.8);

	add(splitPane);
	
	menuBar = new JMenuBar();
	
	fileMenu = new JMenu("File");
	exportStatisticsItem = new JMenuItem("Export Statistics");
	exportStatisticsItem.addActionListener(this);
	closeItem = new JMenuItem("Close");
	closeItem.addActionListener(this);
	fileMenu.add(exportStatisticsItem);
	fileMenu.addSeparator();
	fileMenu.add(closeItem);
	
	worldMenu = new JMenu("Creation");
	createWorldItem = new JMenuItem("Create World");
	createWorldItem.addActionListener(this);
	worldMenu.add(createWorldItem);
	worldMenu.addSeparator();
	createCreatureItem = new JMenuItem("Create Creature");
	createCreatureItem.addActionListener(this);
	worldMenu.add(createCreatureItem);
	createCreaturesItem = new JMenuItem("Create Creatures");
	createCreaturesItem.addActionListener(this);
	worldMenu.add(createCreaturesItem);
	
	statisticsMenu = new JMenu("Statistics");
	showStatisticsItem = new JMenuItem("Show Statistics");
	showStatisticsItem.addActionListener(this);
	statisticsMenu.add(showStatisticsItem);
	
	menuBar.add(fileMenu);
	menuBar.add(worldMenu);
	menuBar.add(statisticsMenu);
	
	setJMenuBar(menuBar);
}
 
Example 18
Source File: ColorPick.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
    * Creates a Colorpicker with initial values 0,0,0,0
    * 
    * @param opacity
    *            , true if Opacity Slider should be visible
    */
   public ColorPick(boolean opacity)
   {
this.setLayout(new GridBagLayout());



JLabel red = new JLabel(Res.getString("lookandfeel.color.red"));
JLabel green = new JLabel(Res.getString("lookandfeel.color.green"));
JLabel blue = new JLabel(Res.getString("lookandfeel.color.blue"));
JLabel opaq = new JLabel(Res.getString("lookandfeel.color.opacity"));

JSlider redslider = new JSlider(0,255);
JSlider greenslider = new JSlider(0,255);
JSlider blueslider = new JSlider(0,255);
JSlider opaqslider = new JSlider(0,255);


_sliderarray = new JSlider[4];
_sliderarray[0] = redslider;
_sliderarray[1] = greenslider;
_sliderarray[2] = blueslider;
_sliderarray[3] = opaqslider;

for(JSlider s : _sliderarray)
{
    s.addChangeListener(this);
    s.setMajorTickSpacing(256/3);
    s.setMinorTickSpacing(0);
    s.setPaintTicks(true);
    s.setPaintLabels(true);
}


_preview = new JLabel("   ");
_preview.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
_preview.setOpaque(true);

this.add(red,new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0));
this.add(redslider,new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0));

this.add(green,new GridBagConstraints(0, 1, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0));
this.add(greenslider,new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0));

this.add(blue,new GridBagConstraints(0, 2, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0));
this.add(blueslider,new GridBagConstraints(1, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0));


if(opacity)
{
       	this.add(opaq,new GridBagConstraints(0, 3, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0));
       	this.add(opaqslider,new GridBagConstraints(1, 3, 1, 1, 1.0, 1.0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0));
}

this.add(_preview,new GridBagConstraints(2, 0, 1, 4, 0.1, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5,5,5,5),0,0));


   }
 
Example 19
Source File: ResearchTechPanel.java    From Open-Realms-of-Stars with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create Research Tech panel with - and + buttons and up arrow to
 * upgrade tech level.
 * @param actionMinus ActionCommand for minus button
 * @param actionPlus ActionCommand for plus button
 * @param iconName Icon name to show
 * @param text Text for tech focus label
 * @param text2 Text for tech level label
 * @param actionUpgrade ActionCommand for upgrade button
 * @param sliderValue slider value
 * @param actionSlider slider action command
 * @param listener Action Listener
 */
public ResearchTechPanel(final String actionMinus,
    final String actionPlus, final String iconName, final String text,
    final String text2, final String actionUpgrade, final int sliderValue,
    final String actionSlider, final ActionListener listener) {
  super();
  this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
  btnMinus = new IconButton(Icons.getIconByName(Icons.ICON_MINUS),
      Icons.getIconByName(Icons.ICON_MINUS_PRESSED), false, actionMinus,
      this);
  btnMinus.addActionListener(listener);
  this.add(Box.createRigidArea(new Dimension(5, 5)));
  this.add(btnMinus);
  SpaceGreyPanel panel = new SpaceGreyPanel();
  panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

  label = new IconLabel(null, Icons.getIconByName(iconName), text);
  panel.add(label);
  slider = new JSlider(0, 100, sliderValue);
  slider.setMinorTickSpacing(4);
  slider.setMajorTickSpacing(20);
  slider.setPaintTicks(true);
  slider.setSnapToTicks(true);
  slider.setBackground(GuiStatics.COLOR_GREYBLUE);
  slider.setForeground(GuiStatics.COLOR_COOL_SPACE_BLUE);
  slider.addKeyListener(null);
  slider.addChangeListener(new ChangeListener() {

    @Override
    public void stateChanged(final ChangeEvent e) {
      if (e.getSource() instanceof JSlider) {
        JSlider slide = (JSlider) e.getSource();
        if (slide.getValue() % 4 == 0) {
          listener.actionPerformed(new ActionEvent(e, 0, actionSlider));
        }
      }
    }
  });
  panel.add(slider);
  lvlLabel = new IconLabel(null, Icons.getIconByName(Icons.ICON_EMPTY),
      text2);
  panel.add(lvlLabel);

  this.add(panel);

  btnUpgrade = new IconButton(Icons.getIconByName(Icons.ICON_ARROWUP),
      Icons.getIconByName(Icons.ICON_ARROWUP_PRESSED), false, actionUpgrade,
      this);
  btnUpgrade.setDisabledImage(
      Icons.getIconByName(Icons.ICON_ARROWUP_DISABLED).getIcon());
  btnUpgrade.addActionListener(listener);
  btnUpgrade.setEnabled(false);

  this.add(btnUpgrade);

  btnPlus = new IconButton(Icons.getIconByName(Icons.ICON_PLUS),
      Icons.getIconByName(Icons.ICON_PLUS_PRESSED), false, actionPlus, this);
  btnPlus.addActionListener(listener);
  this.add(btnPlus);
  this.add(Box.createRigidArea(new Dimension(5, 5)));
}
 
Example 20
Source File: SendDialog.java    From btdex with GNU General Public License v3.0 4 votes vote down vote up
public SendDialog(JFrame owner, Market token) {
	super(owner, ModalityType.APPLICATION_MODAL);
	setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	
	this.token = token;

	setTitle(tr("main_send", token==null ? "BURST" : token));

	JPanel topPanel = new JPanel(new GridLayout(0, 1, 4, 4));

	JPanel panel = new JPanel(new GridLayout(0, 2, 4, 4));

	recipient = new JTextField(26);
	message = new JTextField(26);

	pin = new JPasswordField(12);
	pin.addActionListener(this);

	amount = new JFormattedTextField(token==null ? NumberFormatting.BURST.getFormat() : token.getNumberFormat().getFormat());
	fee = new JSlider(1, 4);

	topPanel.add(new Desc(tr("send_recipient"), recipient));
	topPanel.add(new Desc(tr("send_message"), message));
	message.setToolTipText(tr("send_empty_for_no_message"));

	panel.add(new Desc(tr("send_amount", token==null ? "BURST" : token), amount));
	Desc feeDesc = new Desc("", fee);
	panel.add(feeDesc);
	FeeSuggestion suggestedFee = BurstNode.getInstance().getSuggestedFee();
	
	fee.addChangeListener(new ChangeListener() {
		public void stateChanged(ChangeEvent evt) {
			String feeType;
			switch (fee.getValue()) {
			case 1:
				feeType = tr("fee_minimum");
				selectedFee = BurstValue.fromPlanck(Constants.FEE_QUANT);
				break;
			case 2:
				feeType = tr("fee_cheap");
				selectedFee = suggestedFee.getCheapFee();
				break;
			case 3:
				feeType = tr("fee_standard");
				selectedFee = suggestedFee.getStandardFee();
				break;
			default:
				feeType = tr("fee_priority");
				selectedFee = suggestedFee.getPriorityFee();
				break;
			}
			feeDesc.setDesc(tr("send_fee", feeType, selectedFee.toUnformattedString()));
		}
	});

	// Create a button
	JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));

	calcelButton = new JButton(tr("dlg_cancel"));
	okButton = new JButton(tr("dlg_ok"));

	calcelButton.addActionListener(this);
	okButton.addActionListener(this);

	if(Globals.getInstance().usingLedger()) {
		ledgerStatus = new JTextField(26);
		ledgerStatus.setEditable(false);
		buttonPane.add(new Desc(tr("ledger_status"), ledgerStatus));
		LedgerService.getInstance().setCallBack(this);
	}
	else
		buttonPane.add(new Desc(tr("dlg_pin"), pin));
	buttonPane.add(new Desc(" ", calcelButton));
	buttonPane.add(new Desc(" ", okButton));

	// set action listener on the button

	JPanel content = (JPanel)getContentPane();
	content.setBorder(new EmptyBorder(4, 4, 4, 4));

	content.add(topPanel, BorderLayout.PAGE_START);
	content.add(panel, BorderLayout.CENTER);
	content.add(buttonPane, BorderLayout.PAGE_END);

	pack();

	fee.getModel().setValue(4);
}