List of usage examples for javax.swing.event ChangeEvent getSource
public Object getSource()
From source file:projects.tgas.exec.HrDiagram.java
/** * Main constructor.//from ww w .j a v a 2s .co m */ public HrDiagram() { tgasStars = TgasUtils.loadTgasCatalogue(); method = METHOD.NAIVE; fMax = 1.0; final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values()); methodComboBox.setSelectedItem(method); methodComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { method = (METHOD) methodComboBox.getSelectedItem(); updateChart(); } }); final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f"); fSlider.setValue((int) Math.rint(100.0 * fMax / 2.0)); final JLabel fLabel = new JLabel(getFLabel()); // Create a change listener fot these ChangeListener cl = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (source == fSlider) { // Compute fractional parallax error from slider position double newF = (2.0 * source.getValue() / 100.0); fMax = newF; fLabel.setText(getFLabel()); } updateChart(); } }; fSlider.addChangeListener(cl); // Add a bit of padding to space things out fSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); // Present controls below the HR diagram JPanel controls = new JPanel(new GridLayout(2, 2)); controls.add(new JLabel("Distance estimation method:")); controls.add(methodComboBox); controls.add(fLabel); controls.add(fSlider); // Initialise the ChartPanel updateChart(); // Build the panel contents setLayout(new BorderLayout()); add(hrDiagPanel, BorderLayout.CENTER); add(controls, BorderLayout.SOUTH); }
From source file:DiningPhilosophers.java
public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); grabDelay = source.getValue() * 100; label.setText(String.valueOf(grabDelay + " milliseconds")); }
From source file:SliderTest.java
public SliderTestFrame() { setTitle("SliderTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); sliderPanel = new JPanel(); sliderPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); // common listener for all sliders listener = new ChangeListener() { public void stateChanged(ChangeEvent event) { // update text field when the slider value changes JSlider source = (JSlider) event.getSource(); textField.setText("" + source.getValue()); }// w w w. j a v a 2 s. c o m }; // add a plain slider JSlider slider = new JSlider(); addSlider(slider, "Plain"); // add a slider with major and minor ticks slider = new JSlider(); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); addSlider(slider, "Ticks"); // add a slider that snaps to ticks slider = new JSlider(); slider.setPaintTicks(true); slider.setSnapToTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); addSlider(slider, "Snap to ticks"); // add a slider with no track slider = new JSlider(); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); slider.setPaintTrack(false); addSlider(slider, "No track"); // add an inverted slider slider = new JSlider(); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); slider.setInverted(true); addSlider(slider, "Inverted"); // add a slider with numeric labels slider = new JSlider(); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); addSlider(slider, "Labels"); // add a slider with alphabetic labels slider = new JSlider(); slider.setPaintLabels(true); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(5); Dictionary<Integer, Component> labelTable = new Hashtable<Integer, Component>(); labelTable.put(0, new JLabel("A")); labelTable.put(20, new JLabel("B")); labelTable.put(40, new JLabel("C")); labelTable.put(60, new JLabel("D")); labelTable.put(80, new JLabel("E")); labelTable.put(100, new JLabel("F")); slider.setLabelTable(labelTable); addSlider(slider, "Custom labels"); // add a slider with icon labels slider = new JSlider(); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setSnapToTicks(true); slider.setMajorTickSpacing(20); slider.setMinorTickSpacing(20); labelTable = new Hashtable<Integer, Component>(); // add card images labelTable.put(0, new JLabel(new ImageIcon("nine.gif"))); labelTable.put(20, new JLabel(new ImageIcon("ten.gif"))); labelTable.put(40, new JLabel(new ImageIcon("jack.gif"))); labelTable.put(60, new JLabel(new ImageIcon("queen.gif"))); labelTable.put(80, new JLabel(new ImageIcon("king.gif"))); labelTable.put(100, new JLabel(new ImageIcon("ace.gif"))); slider.setLabelTable(labelTable); addSlider(slider, "Icon labels"); // add the text field that displays the slider value textField = new JTextField(); add(sliderPanel, BorderLayout.CENTER); add(textField, BorderLayout.SOUTH); }
From source file:compecon.dashboard.panel.HouseholdsPanel.java
public HouseholdsPanel() { this.setLayout(new BorderLayout()); for (Currency currency : Currency.values()) { HouseholdsPanelForCurrency panelForCurrency = new HouseholdsPanelForCurrency(currency); jTabbedPaneCurrency.addTab(currency.getIso4217Code(), panelForCurrency); panelForCurrency.setBackground(Color.lightGray); }/*from ww w .j a va2 s . c om*/ jTabbedPaneCurrency.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (e.getSource() instanceof JTabbedPane) { JTabbedPane pane = (JTabbedPane) e.getSource(); HouseholdsPanelForCurrency selectedComponent = (HouseholdsPanelForCurrency) pane .getSelectedComponent(); selectedComponent.notifyListener(); } } }); add(jTabbedPaneCurrency, BorderLayout.CENTER); }
From source file:net.sourceforge.doddle_owl.ui.GeneralOntologySelectionPanel.java
@Override public void stateChanged(ChangeEvent e) { if (e.getSource() == wn30RadioButton) { DODDLEConstants.ENWN_HOME = DODDLEConstants.ENWN_3_0_HOME; WordNetDic.resetWordNet();//from ww w .j a v a2 s . co m } else if (e.getSource() == wn31RadioButton) { DODDLEConstants.ENWN_HOME = DODDLEConstants.ENWN_3_1_HOME; WordNetDic.resetWordNet(); } }
From source file:es.emergya.ui.base.plugins.PluggableJTabbedPane.java
@Override protected void installListeners() { super.installListeners(); final BasicWindow window_ = window; this.tabPane.addChangeListener(new ChangeListener() { @Override//from w ww . j a v a 2 s . com public void stateChanged(ChangeEvent e) { window_.recolorAlert(); if (((PluggableJTabbedPane) e.getSource()).getSelectedIndex() == 0) { Component c = ((PluggableJTabbedPane) e.getSource()).getSelectedComponent(); if (c instanceof CleanUp) ((CleanUp) c).cleanUp(); } } }); }
From source file:projects.hip.exec.HrDiagram.java
/** * Main constructor./* w ww. j ava 2 s . com*/ */ public HrDiagram() { hipStars = HipUtils.loadHipCatalogue(); method = METHOD.NAIVE; fMax = 1.0; final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values()); methodComboBox.setSelectedItem(method); methodComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { method = (METHOD) methodComboBox.getSelectedItem(); updateChart(); } }); final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f"); fSlider.setValue((int) Math.rint(100.0 * fMax / 2.0)); final JLabel fLabel = new JLabel(getFLabel()); // Create a change listener fot these ChangeListener cl = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (source == fSlider) { // Compute fractional parallax error from slider position double newF = (2.0 * source.getValue() / 100.0); fMax = newF; fLabel.setText(getFLabel()); } updateChart(); } }; fSlider.addChangeListener(cl); // Add a bit of padding to space things out fSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); // Present controls below the HR diagram JPanel controls = new JPanel(new GridLayout(2, 2)); controls.add(new JLabel("Distance estimation method:")); controls.add(methodComboBox); controls.add(fLabel); controls.add(fSlider); // Initialise the ChartPanel updateChart(); // Build the panel contents setLayout(new BorderLayout()); add(hrDiagPanel, BorderLayout.WEST); add(dDistPanel, BorderLayout.EAST); add(controls, BorderLayout.SOUTH); }
From source file:jku.ss09.mir.lastfmecho.bo.visualization.MirArtistNetworkGraphVisualizer.java
public boolean init() { if (artistList.size() > similarityMatrix.length) { System.out.println(// ww w. j a v a2 s. c om "Error in MirArtistNetworkGraphVisualizer - The similaritymatrix is smaller than number of artists "); return false; } graph = getGraph(SIMILARITY_DEFAULT / 100.0); setVisualizationRenderer(); // create a frome to hold the graph final JFrame frame = new JFrame(); Container content = frame.getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final ModalGraphMouse gm = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(gm); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JSlider slider = new JSlider(JSlider.HORIZONTAL, SIMILARITY_MIN, SIMILARITY_MAX, SIMILARITY_DEFAULT); slider.setMajorTickSpacing(10); slider.setPaintTicks(true); final JLabel sliderLabel = new JLabel("0.87"); final MirArtistNetworkGraphVisualizer thisPointer = this; slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { JSlider source = (JSlider) arg0.getSource(); if (!source.getValueIsAdjusting()) { System.out.println(source.getValue() / 100.0); Graph testG = getGraph(source.getValue() / 100.0); sliderLabel.setText(Double.toString(source.getValue() / 100.0)); thisPointer.vv.setGraphLayout(new FRLayout<Integer, Number>(testG)); //thisPointer.setVisualizationRenderer(); thisPointer.vv.validate(); thisPointer.vv.repaint(); } } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(((DefaultModalGraphMouse<Integer, Number>) gm).getModeComboBox()); controls.add(new JLabel("Similarity Limit: ")); controls.add(sliderLabel); controls.add(slider); content.add(controls, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); return true; }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PortHeatMapPlotPanel.java
public void stateChanged(ChangeEvent e) { // handles both slider events if (e.getSource() == PortSlider) { //System.err.println("Port Slider is changing " + PortSlider.getValue()); // this is the vertical slider (moves the horizontal xhair), which moves through ports on vertical axis PortXhair.setValue(PortSlider.getValue()); int xIndex = PortSlider.getValue() - PortSlider.getMinimum(); if (pHeatMap != null) { // extract this slice from the heatmap, and display it XYDataset d = HeatMapUtilities.extractRowFromHeatMapDataset(pHeatMap, xIndex, "Y1"); SinglePortChart.getXYPlot().setDataset(d); SinglePortChart.setTitle(pHeatMap.getPortId(xIndex) + " (port " + xIndex + ")"); }/* w w w . ja v a 2s . c o m*/ } else if (e.getSource() == TimeSlider) { //System.err.println("Time Slider is changing " + TimeSlider.getValue()); // this is the horizontal slider (moves vertical xhair), which moves through time on the horizontal axis TimeXhair.setValue(TimeSlider.getValue()); int xIndex = TimeSlider.getValue() - TimeSlider.getMinimum(); if (pHeatMap != null) { // extract this slice from the heatmap, and display it XYDataset d = HeatMapUtilities.extractColumnFromHeatMapDataset(pHeatMap, xIndex, "Y2"); SingleTimeChart.getXYPlot().setDataset(d); SingleTimeChart.setTitle(new TimeStamp(pHeatMap.getXTimeValue(xIndex)).toString()); } } }
From source file:jatools.component.chart.customizer.Tabs.java
/** * DOCUMENT ME!/* w ww .j a v a 2 s .co m*/ * * @param e DOCUMENT ME! */ public void stateChanged(ChangeEvent e) { Properties props = new Properties(); props = this.javachart.getProperties(); if (e.getSource() instanceof SelectCommand) { SelectCommand cmd = (SelectCommand) e.getSource(); Class cls = cmd.field.getColumnClass(); if (cls != null) { if (cmd.type == SelectCommand.PLOTDATA) { if ((!(Number.class.isAssignableFrom(cls)))) { cmd.error = "!"; } } } } else { boolean update = false; if ((dataPanel.getReader() != null) && (dataPanel.getLabelField() != null) && (dataPanel.getShowData().length > 0)) { update = true; // if ((chart instanceof HiLoBarChart || chart instanceof HorizHiLoBarChart) && // (dataPanel.getShowData().length < 2)) { // update = false; // } else if (chart instanceof HiLoCloseChart && (dataPanel.getShowData().length < 3)) { // update = false; // } else if (chart instanceof CandlestickChart && // (dataPanel.getShowData().length < 4)) { // update = false; // } } dataPanelToJavaChart(); this.javachart.refersh(); this.javachart.setProperties(props); if (update) { fireChange(null); } } }