List of usage examples for javax.swing JSlider JSlider
public JSlider(int orientation, int min, int max, int value)
From source file:org.datavyu.controllers.component.MixerController.java
private void initView() { // Set default scale values minStart = 0;//from w w w. ja v a 2 s . c o m listenerList = new EventListenerList(); // Set up the root panel tracksPanel = new JPanel(); tracksPanel.setLayout(new MigLayout("ins 0", "[left|left|left|left]rel push[right|right]", "")); tracksPanel.setBackground(Color.WHITE); if (Platform.isMac()) { osxGestureListener.register(tracksPanel); } // Menu buttons lockToggle = new JToggleButton("Lock all"); lockToggle.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { lockToggleHandler(e); } }); lockToggle.setName("lockToggleButton"); bookmarkButton = new JButton("Add Bookmark"); bookmarkButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { addBookmarkHandler(); } }); bookmarkButton.setEnabled(false); bookmarkButton.setName("bookmarkButton"); JButton snapRegion = new JButton("Snap Region"); snapRegion.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { snapRegionHandler(e); } }); snapRegion.setName("snapRegionButton"); JButton clearRegion = new JButton("Clear Region"); clearRegion.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { clearRegionHandler(e); } }); clearRegion.setName("clearRegionButton"); zoomSlide = new JSlider(JSlider.HORIZONTAL, 1, 1000, 1); zoomSlide.addChangeListener(new ChangeListener() { public void stateChanged(final ChangeEvent e) { if (!isUpdatingZoomSlide && zoomSlide.getValueIsAdjusting()) { try { isUpdatingZoomSlide = true; zoomSetting = (double) (zoomSlide.getValue() - zoomSlide.getMinimum()) / (zoomSlide.getMaximum() - zoomSlide.getMinimum() + 1); viewportModel.setViewportZoom(zoomSetting, needleController.getNeedleModel().getCurrentTime()); } finally { isUpdatingZoomSlide = false; } } } }); zoomSlide.setName("zoomSlider"); zoomSlide.setBackground(tracksPanel.getBackground()); JButton zoomRegionButton = new JButton("", zoomIcon); zoomRegionButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { zoomToRegion(e); } }); zoomRegionButton.setName("zoomRegionButton"); tracksPanel.add(lockToggle); tracksPanel.add(bookmarkButton); tracksPanel.add(snapRegion); tracksPanel.add(clearRegion); tracksPanel.add(zoomRegionButton); tracksPanel.add(zoomSlide, "wrap"); timescaleController = new TimescaleController(mixerModel); timescaleController.addTimescaleEventListener(this); needleController = new NeedleController(this, mixerModel); regionController = new RegionController(mixerModel); tracksEditorController = new TracksEditorController(this, mixerModel); needleController.setTimescaleTransitionHeight( timescaleController.getTimescaleModel().getZoomWindowToTrackTransitionHeight()); needleController .setZoomIndicatorHeight(timescaleController.getTimescaleModel().getZoomWindowIndicatorHeight()); // Set up the layered pane layeredPane = new JLayeredPane(); layeredPane.setLayout(new MigLayout("fillx, ins 0")); final int layeredPaneHeight = 272; final int timescaleViewHeight = timescaleController.getTimescaleModel().getHeight(); final int needleHeadHeight = (int) Math.ceil(NeedleConstants.NEEDLE_HEAD_HEIGHT); final int tracksScrollPaneY = needleHeadHeight + 1; final int timescaleViewY = layeredPaneHeight - MixerConstants.HSCROLL_HEIGHT - timescaleViewHeight; final int tracksScrollPaneHeight = timescaleViewY - tracksScrollPaneY; final int tracksScrollBarY = timescaleViewY + timescaleViewHeight; final int needleAndRegionMarkerHeight = (timescaleViewY + timescaleViewHeight - timescaleController.getTimescaleModel().getZoomWindowIndicatorHeight() - timescaleController.getTimescaleModel().getZoomWindowToTrackTransitionHeight() + 1); // Set up filler component responsible for horizontal resizing of the // layout. { // Null args; let layout manager handle sizes. Box.Filler filler = new Filler(null, null, null); filler.setName("Filler"); filler.addComponentListener(new SizeHandler()); Map<String, String> constraints = Maps.newHashMap(); constraints.put("wmin", Integer.toString(MixerConstants.MIXER_MIN_WIDTH)); // TODO Could probably use this same component to handle vertical // resizing... String template = "id filler, h 0!, grow 100 0, wmin ${wmin}, cell 0 0 "; StrSubstitutor sub = new StrSubstitutor(constraints); layeredPane.setLayer(filler, MixerConstants.FILLER_ZORDER); layeredPane.add(filler, sub.replace(template), MixerConstants.FILLER_ZORDER); } // Set up the timescale layout { JComponent timescaleView = timescaleController.getView(); Map<String, String> constraints = Maps.newHashMap(); constraints.put("x", Integer.toString(TimescaleConstants.XPOS_ABS)); constraints.put("y", Integer.toString(timescaleViewY)); // Calculate padding from the right int rightPad = (int) (RegionConstants.RMARKER_WIDTH + MixerConstants.VSCROLL_WIDTH + MixerConstants.R_EDGE_PAD); constraints.put("x2", "(filler.w-" + rightPad + ")"); constraints.put("y2", "(tscale.y+${height})"); constraints.put("height", Integer.toString(timescaleViewHeight)); String template = "id tscale, pos ${x} ${y} ${x2} ${y2}"; StrSubstitutor sub = new StrSubstitutor(constraints); // Must call setLayer first. layeredPane.setLayer(timescaleView, MixerConstants.TIMESCALE_ZORDER); layeredPane.add(timescaleView, sub.replace(template), MixerConstants.TIMESCALE_ZORDER); } // Set up the scroll pane's layout. { tracksScrollPane = new JScrollPane(tracksEditorController.getView()); tracksScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); tracksScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); tracksScrollPane.setBorder(BorderFactory.createEmptyBorder()); tracksScrollPane.setName("jScrollPane"); Map<String, String> constraints = Maps.newHashMap(); constraints.put("x", "0"); constraints.put("y", Integer.toString(tracksScrollPaneY)); constraints.put("x2", "(filler.w-" + MixerConstants.R_EDGE_PAD + ")"); constraints.put("height", Integer.toString(tracksScrollPaneHeight)); String template = "pos ${x} ${y} ${x2} n, h ${height}!"; StrSubstitutor sub = new StrSubstitutor(constraints); layeredPane.setLayer(tracksScrollPane, MixerConstants.TRACKS_ZORDER); layeredPane.add(tracksScrollPane, sub.replace(template), MixerConstants.TRACKS_ZORDER); } // Create the region markers and set up the layout. { JComponent regionView = regionController.getView(); Map<String, String> constraints = Maps.newHashMap(); int x = (int) (TrackConstants.HEADER_WIDTH - RegionConstants.RMARKER_WIDTH); constraints.put("x", Integer.toString(x)); constraints.put("y", "0"); // Padding from the right int rightPad = MixerConstants.R_EDGE_PAD + MixerConstants.VSCROLL_WIDTH - 2; constraints.put("x2", "(filler.w-" + rightPad + ")"); constraints.put("height", Integer.toString(needleAndRegionMarkerHeight)); String template = "pos ${x} ${y} ${x2} n, h ${height}::"; StrSubstitutor sub = new StrSubstitutor(constraints); layeredPane.setLayer(regionView, MixerConstants.REGION_ZORDER); layeredPane.add(regionView, sub.replace(template), MixerConstants.REGION_ZORDER); } // Set up the timing needle's layout { JComponent needleView = needleController.getView(); Map<String, String> constraints = Maps.newHashMap(); int x = (int) (TrackConstants.HEADER_WIDTH - NeedleConstants.NEEDLE_HEAD_WIDTH + NeedleConstants.NEEDLE_WIDTH); constraints.put("x", Integer.toString(x)); constraints.put("y", "0"); // Padding from the right int rightPad = MixerConstants.R_EDGE_PAD + MixerConstants.VSCROLL_WIDTH - 1; constraints.put("x2", "(filler.w-" + rightPad + ")"); constraints.put("height", Integer.toString(needleAndRegionMarkerHeight + timescaleController.getTimescaleModel().getZoomWindowToTrackTransitionHeight() + timescaleController.getTimescaleModel().getZoomWindowIndicatorHeight() - 1)); String template = "pos ${x} ${y} ${x2} n, h ${height}::"; StrSubstitutor sub = new StrSubstitutor(constraints); layeredPane.setLayer(needleView, MixerConstants.NEEDLE_ZORDER); layeredPane.add(needleView, sub.replace(template), MixerConstants.NEEDLE_ZORDER); } // Set up the snap marker's layout { JComponent markerView = tracksEditorController.getMarkerView(); Map<String, String> constraints = Maps.newHashMap(); constraints.put("x", Integer.toString(TimescaleConstants.XPOS_ABS)); constraints.put("y", Integer.toString(needleHeadHeight + 1)); // Padding from the right int rightPad = MixerConstants.R_EDGE_PAD + MixerConstants.VSCROLL_WIDTH - 1; constraints.put("x2", "(filler.w-" + rightPad + ")"); constraints.put("height", Integer.toString(needleAndRegionMarkerHeight - needleHeadHeight - 1)); String template = "pos ${x} ${y} ${x2} n, h ${height}::"; StrSubstitutor sub = new StrSubstitutor(constraints); layeredPane.setLayer(markerView, MixerConstants.MARKER_ZORDER); layeredPane.add(markerView, sub.replace(template), MixerConstants.MARKER_ZORDER); } // Set up the tracks horizontal scroll bar { tracksScrollBar = new JScrollBar(Adjustable.HORIZONTAL); tracksScrollBar.setValues(0, TRACKS_SCROLL_BAR_RANGE, 0, TRACKS_SCROLL_BAR_RANGE); tracksScrollBar.setUnitIncrement(TRACKS_SCROLL_BAR_RANGE / 20); tracksScrollBar.setBlockIncrement(TRACKS_SCROLL_BAR_RANGE / 2); tracksScrollBar.addAdjustmentListener(this); tracksScrollBar.setValueIsAdjusting(false); tracksScrollBar.setVisible(false); tracksScrollBar.setName("horizontalScrollBar"); Map<String, String> constraints = Maps.newHashMap(); constraints.put("x", Integer.toString(TimescaleConstants.XPOS_ABS)); constraints.put("y", Integer.toString(tracksScrollBarY)); int rightPad = (int) (RegionConstants.RMARKER_WIDTH + MixerConstants.VSCROLL_WIDTH + MixerConstants.R_EDGE_PAD); constraints.put("x2", "(filler.w-" + rightPad + ")"); constraints.put("height", Integer.toString(MixerConstants.HSCROLL_HEIGHT)); String template = "pos ${x} ${y} ${x2} n, h ${height}::"; StrSubstitutor sub = new StrSubstitutor(constraints); layeredPane.setLayer(tracksScrollBar, MixerConstants.TRACKS_SB_ZORDER); layeredPane.add(tracksScrollBar, sub.replace(template), MixerConstants.TRACKS_SB_ZORDER); } { Map<String, String> constraints = Maps.newHashMap(); constraints.put("span", "6"); constraints.put("width", Integer.toString(MixerConstants.MIXER_MIN_WIDTH)); constraints.put("height", Integer.toString(layeredPaneHeight)); String template = "growx, span ${span}, w ${width}::, h ${height}::, wrap"; StrSubstitutor sub = new StrSubstitutor(constraints); tracksPanel.add(layeredPane, sub.replace(template)); } tracksPanel.validate(); }
From source file:savant.view.swing.FrameCommandBar.java
/** * Create interval height slider for commandBar *//*from ww w .j av a 2 s .c o m*/ private JMenu createIntervalMenu() { JMenu menu = new JMenu("Interval Height"); intervalSlider = new JSlider(JSlider.VERTICAL, 1, AVAILABLE_INTERVAL_HEIGHTS.length, 1); intervalSlider.setMinorTickSpacing(1); intervalSlider.setMajorTickSpacing(AVAILABLE_INTERVAL_HEIGHTS.length / 2); intervalSlider.setSnapToTicks(true); intervalSlider.setPaintTicks(true); intervalSlider.setValue( getSliderFromIntervalHeight(InterfaceSettings.getIntervalHeight(mainTrack.getDataFormat()))); intervalSlider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int h = getIntervalHeight(); if (graphPane.isScaledToFit()) { graphPane.setUnitHeight(h); graphPane.setScaledToFit(false); // Forces rerender and repaint internally. } else if (graphPane.getUnitHeight() != h) { graphPane.setUnitHeight(h); graphPane.setRenderForced(); graphPane.repaint(); } } }); menu.add(intervalSlider); return menu; }
From source file:uk.ac.babraham.SeqMonk.Filters.GeneSetFilter.GeneSetDisplay.java
public GeneSetDisplay(DataCollection dataCollection, String description, DataStore fromStore, DataStore toStore, Probe[] probes, Hashtable zScoreLookupTable, MappedGeneSetTTestValue[] filterResults, ProbeList startingProbeList, float[][] customRegressionValues, SimpleRegression simpleRegression) { super(SeqMonkApplication.getInstance(), "Gene Set Results"); this.collection = dataCollection; this.filterResultsPVals = filterResults; this.startingProbeList = startingProbeList; this.description = description; this.fromStore = fromStore; this.toStore = toStore; this.probes = probes; this.zScoreLookupTable = zScoreLookupTable; this.customRegressionValues = customRegressionValues; this.simpleRegression = simpleRegression; this.addWindowListener(this); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); // This is to hold the scatterPanel and its associated bits. plotPanel = new JPanel(); plotPanel.setLayout(new BorderLayout()); scatterPlotPanel = new JPanel(); plotPanel.add(scatterPlotPanel, BorderLayout.CENTER); dotSizeSlider = new JSlider(JSlider.VERTICAL, 1, 100, 3); // This call is left in to work around a bug in the Windows 7 LAF // which makes the slider stupidly thin in ticks are not drawn. dotSizeSlider.setPaintTicks(true);/*from w w w.j a v a 2 s . co m*/ dotSizeSlider.addChangeListener(this); plotPanel.add(dotSizeSlider, BorderLayout.EAST); JPanel plotButtonPanel = new JPanel(); plotButtonPanel.setLayout(new GridBagLayout()); GridBagConstraints c1 = new GridBagConstraints(); c1.insets = new Insets(2, 2, 2, 2); c1.gridx = 0; c1.gridy = 0; saveImageButton = new JButton("Save Image"); saveImageButton.addActionListener(this); saveImageButton.setActionCommand("save_image"); plotButtonPanel.add(saveImageButton, c1); c1.gridx++; swapPlotButton = new JToggleButton("Display standard scatterplot"); swapPlotButton.addActionListener(this); swapPlotButton.setActionCommand("swap_plot"); plotButtonPanel.add(swapPlotButton, c1); plotPanel.add(plotButtonPanel, BorderLayout.SOUTH); /** The table where the probe lists are displayed */ tableModel = new GeneSetTableModel(filterResultsPVals); table = new JTable(new TableSorter(tableModel)); table.setRowSelectionAllowed(true); table.addMouseListener(this); table.setAutoCreateRowSorter(true); table.getSelectionModel().addListSelectionListener(this); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // sort by z-score table.getRowSorter().toggleSortOrder(3); // Set our initial column widths TableColumn column = null; for (int i = 0; i < tableModel.getColumnCount(); i++) { column = table.getColumnModel().getColumn(i); if (i == 0) { column.setPreferredWidth(40); } else if (i == 1) { column.setPreferredWidth(200); } else { column.setPreferredWidth(80); } } JScrollPane scrollPane = new JScrollPane(table); JPanel tablePanel = new JPanel(); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridBagLayout()); GridBagConstraints c2 = new GridBagConstraints(); c2.insets = new Insets(2, 2, 2, 2); c2.gridx = 0; c2.gridy = 0; selectAllButton = new JToggleButton("Select all"); selectAllButton.addActionListener(this); selectAllButton.setActionCommand("select_all"); buttonPanel.add(selectAllButton, c2); saveSelectedProbeListsButton = new JButton("Save selected probe lists"); saveSelectedProbeListsButton.addActionListener(this); saveSelectedProbeListsButton.setActionCommand("save_selected_probelists"); c2.gridx++; c2.gridx++; buttonPanel.add(saveSelectedProbeListsButton, c2); saveTableButton = new JButton("Save table"); saveTableButton.addActionListener(this); saveTableButton.setActionCommand("save_table"); c2.gridx++; c2.gridx++; buttonPanel.add(saveTableButton, c2); closeButton = new JButton("Close"); closeButton.addActionListener(this); closeButton.setActionCommand("close"); c2.gridx++; buttonPanel.add(closeButton, c2); tablePanel.setLayout(new BorderLayout()); tablePanel.add(scrollPane, BorderLayout.CENTER); tablePanel.add(buttonPanel, BorderLayout.SOUTH); // sort this out mainPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); mainPane.setLeftComponent(plotPanel); mainPane.setRightComponent(tablePanel); mainPane.setResizeWeight(0.6); mainPane.setDividerLocation(500); getContentPane().add(BorderLayout.CENTER, mainPane); if (storesQuantitated()) { plotPanel.remove(scatterPlotPanel); scatterPlotPanel = new ZScoreScatterPlotPanel(fromStore, toStore, probes, currentSelectedProbeList, dotSizeSlider.getValue(), zScoreLookupTable); plotPanel.add(scatterPlotPanel, BorderLayout.CENTER); } setSize(1000, 500); setVisible(true); }
From source file:xtrememp.XtremeMP.java
protected void createPanels() { JPanel framePanel = new JPanel(new MigLayout("fill")); mainPanel = new JPanel(new CardLayout()); playlistManager = new PlaylistManager(this); visualizationManager = new VisualizationManager(audioPlayer.getDSS()); if (Settings.getLastView().equals(Utilities.VISUALIZATION_PANEL)) { visualizationManager.setDssEnabled(true); mainPanel.add(visualizationManager, Utilities.VISUALIZATION_PANEL); mainPanel.add(playlistManager, Utilities.PLAYLIST_MANAGER); visualizationMenuItem.setSelected(true); } else {//from www .j a v a 2s. c o m mainPanel.add(playlistManager, Utilities.PLAYLIST_MANAGER); mainPanel.add(visualizationManager, Utilities.VISUALIZATION_PANEL); playlistManagerMenuItem.setSelected(true); } framePanel.add(mainPanel, "grow"); JPanel southPanel = new JPanel(new MigLayout("fill", "[center]")); SubstanceLookAndFeel.setDecorationType(southPanel, DecorationAreaType.TOOLBAR); seekSlider = new SeekSlider(this); seekSlider.setEnabled(false); southPanel.add(seekSlider, "north, gap 4 4 1 0"); controlPanel = new JPanel(new MigLayout("gap 0, ins 0", "[center]")); controlPanel.setOpaque(false); stopButton = new StopButton(); stopButton.setEnabled(false); stopButton.addActionListener(this); controlPanel.add(stopButton); previousButton = new PreviousButton(); previousButton.setEnabled(false); previousButton.addActionListener(this); controlPanel.add(previousButton); playPauseButton = new PlayPauseButton(); playPauseButton.addActionListener(this); controlPanel.add(playPauseButton, "height pref!"); nextButton = new NextButton(); nextButton.setEnabled(false); nextButton.addActionListener(this); controlPanel.add(nextButton); volumeButton = new VolumeButton(Utilities.MIN_GAIN, Utilities.MAX_GAIN, Settings.getGain(), Settings.isMuted()); volumeButton.addMouseWheelListener((MouseWheelEvent e) -> { try { int volumeValue = volumeSlider.getValue() - 5 * e.getWheelRotation(); int volumeMin = volumeSlider.getMinimum(); int volumeMax = volumeSlider.getMaximum(); if (volumeValue < volumeMin) { volumeValue = volumeMin; } else if (volumeValue > volumeMax) { volumeValue = volumeMax; } volumeButton.setVolumeIcon(volumeValue); volumeSlider.setValue(volumeValue); audioPlayer.setGain(volumeValue / 100.0F); Settings.setGain(volumeValue); } catch (PlayerException ex) { logger.debug(ex.getMessage(), ex); } }); JPopupMenu volumePopupMenu = volumeButton.getPopupMenu(); volumeSlider = new JSlider(JSlider.VERTICAL, Utilities.MIN_GAIN, Utilities.MAX_GAIN, Settings.getGain()); volumeSlider.setMajorTickSpacing(25); volumeSlider.setMinorTickSpacing(5); volumeSlider.setPaintTicks(true); volumeSlider.setPaintLabels(true); volumeSlider.addChangeListener((ChangeEvent e) -> { if (volumeSlider.getValueIsAdjusting()) { try { int volumeValue = volumeSlider.getValue(); volumeButton.setVolumeIcon(volumeValue); audioPlayer.setGain(volumeValue / 100.0F); Settings.setGain(volumeValue); } catch (PlayerException ex) { logger.debug(ex.getMessage(), ex); } } }); volumeSlider.setEnabled(!Settings.isMuted()); JPanel volumePanel = new JPanel(new MigLayout("fill")); JLabel volumeLabel = new JLabel(tr("MainFrame.Menu.Player.Volume"), JLabel.CENTER); volumeLabel.setFont(volumeLabel.getFont().deriveFont(Font.BOLD)); volumePanel.add(volumeLabel, "north"); volumePanel.add(volumeSlider); JCheckBox muteCheckBox = new JCheckBox(tr("MainFrame.Menu.Player.Mute")); muteCheckBox.setSelected(Settings.isMuted()); muteCheckBox.addItemListener((ItemEvent e) -> { try { if (e.getStateChange() == ItemEvent.SELECTED) { volumeSlider.setEnabled(false); volumeButton.setVolumeMutedIcon(); audioPlayer.setMuted(true); Settings.setMuted(true); } else { volumeSlider.setEnabled(true); volumeButton.setVolumeIcon(Settings.getGain()); audioPlayer.setMuted(false); Settings.setMuted(false); } } catch (PlayerException ex) { logger.debug(ex.getMessage(), ex); } }); volumePanel.add(muteCheckBox, "south"); volumePopupMenu.add(volumePanel); controlPanel.add(volumeButton); southPanel.add(controlPanel, "gap 0 0 2 5"); JPanel statusBar = new JPanel(new MigLayout("ins 2 0 2 0")); SubstanceLookAndFeel.setDecorationType(statusBar, DecorationAreaType.FOOTER); timeLabel = new JLabel(Utilities.ZERO_TIMER); timeLabel.setFont(timeLabel.getFont().deriveFont(Font.BOLD)); statusBar.add(timeLabel, "gap 6 6 0 0, west"); statusBar.add(new JSeparator(SwingConstants.VERTICAL), "hmin 16"); statusLabel = new JLabel(); statusBar.add(statusLabel, "gap 0 2 0 0, wmin 0, push"); statusBar.add(new JSeparator(SwingConstants.VERTICAL), "hmin 16"); playModeLabel = new JLabel(); playModeLabel.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { Playlist.PlayMode[] playModes = Playlist.PlayMode.values(); Playlist.PlayMode playMode = playlist.getPlayMode(); int ordinal = playMode.ordinal(); playlist.setPlayMode(playModes[(ordinal == playModes.length - 1) ? 0 : ordinal + 1]); } }); statusBar.add(playModeLabel, "east, gap 2 2 2 2, width 18!, height 18!"); southPanel.add(statusBar, "south"); framePanel.add(southPanel, "south"); mainFrame.setContentPane(framePanel); }