List of usage examples for javax.swing JScrollBar addAdjustmentListener
public void addAdjustmentListener(AdjustmentListener l)
From source file:org.eobjects.datacleaner.widgets.result.DateGapAnalyzerResultSwingRenderer.java
@Override public JComponent render(DateGapAnalyzerResult result) { final TaskSeriesCollection dataset = new TaskSeriesCollection(); final Set<String> groupNames = result.getGroupNames(); final TaskSeries completeDurationTaskSeries = new TaskSeries(LABEL_COMPLETE_DURATION); final TaskSeries gapsTaskSeries = new TaskSeries(LABEL_GAPS); final TaskSeries overlapsTaskSeries = new TaskSeries(LABEL_OVERLAPS); for (final String groupName : groupNames) { final String groupDisplayName; if (groupName == null) { if (groupNames.size() == 1) { groupDisplayName = "All"; } else { groupDisplayName = LabelUtils.NULL_LABEL; }//from ww w . ja v a 2s .c o m } else { groupDisplayName = groupName; } final TimeInterval completeDuration = result.getCompleteDuration(groupName); final Task completeDurationTask = new Task(groupDisplayName, createTimePeriod(completeDuration.getFrom(), completeDuration.getTo())); completeDurationTaskSeries.add(completeDurationTask); // plot gaps { final SortedSet<TimeInterval> gaps = result.getGaps(groupName); int i = 1; Task rootTask = null; for (TimeInterval interval : gaps) { final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo()); if (rootTask == null) { rootTask = new Task(groupDisplayName, timePeriod); gapsTaskSeries.add(rootTask); } else { Task task = new Task(groupDisplayName + " gap" + i, timePeriod); rootTask.addSubtask(task); } i++; } } // plot overlaps { final SortedSet<TimeInterval> overlaps = result.getOverlaps(groupName); int i = 1; Task rootTask = null; for (TimeInterval interval : overlaps) { final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo()); if (rootTask == null) { rootTask = new Task(groupDisplayName, timePeriod); overlapsTaskSeries.add(rootTask); } else { Task task = new Task(groupDisplayName + " overlap" + i, timePeriod); rootTask.addSubtask(task); } i++; } } } dataset.add(overlapsTaskSeries); dataset.add(gapsTaskSeries); dataset.add(completeDurationTaskSeries); final SlidingGanttCategoryDataset slidingDataset = new SlidingGanttCategoryDataset(dataset, 0, GROUPS_VISIBLE); final JFreeChart chart = ChartFactory.createGanttChart( "Date gaps and overlaps in " + result.getFromColumnName() + " / " + result.getToColumnName(), result.getGroupColumnName(), "Time", slidingDataset, true, true, false); ChartUtils.applyStyles(chart); // make sure the 3 timeline types have correct coloring { final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDrawingSupplier(new DCDrawingSupplier(WidgetUtils.ADDITIONAL_COLOR_GREEN_BRIGHT, WidgetUtils.ADDITIONAL_COLOR_RED_BRIGHT, WidgetUtils.BG_COLOR_BLUE_BRIGHT)); } final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseMoved(ChartMouseEvent event) { Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); ChartEntity entity = event.getEntity(); if (entity instanceof PlotEntity) { cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR); } chartPanel.setCursor(cursor); } @Override public void chartMouseClicked(ChartMouseEvent event) { // do nothing } }); final int visibleLines = Math.min(GROUPS_VISIBLE, groupNames.size()); chartPanel.setPreferredSize(new Dimension(0, visibleLines * 50 + 200)); final JComponent decoratedChartPanel; StringBuilder chartDescription = new StringBuilder(); chartDescription .append("<html><p>The chart displays the recorded timeline based on FROM and TO dates.<br/><br/>"); chartDescription.append( "The <b>red items</b> represent gaps in the timeline and the <b>green items</b> represent points in the timeline where more than one record show activity.<br/><br/>"); chartDescription.append( "You can <b>zoom in</b> by clicking and dragging the area that you want to examine in further detail."); if (groupNames.size() > GROUPS_VISIBLE) { final JScrollBar scroll = new JScrollBar(JScrollBar.VERTICAL); scroll.setMinimum(0); scroll.setMaximum(groupNames.size()); scroll.addAdjustmentListener(new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent e) { int value = e.getAdjustable().getValue(); slidingDataset.setFirstCategoryIndex(value); } }); chartPanel.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int scrollType = e.getScrollType(); if (scrollType == MouseWheelEvent.WHEEL_UNIT_SCROLL) { int wheelRotation = e.getWheelRotation(); scroll.setValue(scroll.getValue() + wheelRotation); } } }); final DCPanel outerPanel = new DCPanel(); outerPanel.setLayout(new BorderLayout()); outerPanel.add(chartPanel, BorderLayout.CENTER); outerPanel.add(scroll, BorderLayout.EAST); chartDescription.append("<br/><br/>Use the right <b>scrollbar</b> to scroll up and down on the chart."); decoratedChartPanel = outerPanel; } else { decoratedChartPanel = chartPanel; } chartDescription.append("</p></html>"); final JLabel chartDescriptionLabel = new JLabel(chartDescription.toString()); chartDescriptionLabel.setBorder(new EmptyBorder(4, 10, 4, 10)); final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); split.add(decoratedChartPanel); split.add(chartDescriptionLabel); split.setDividerLocation(550); return split; }
From source file:it.unibas.spicygui.vista.JLayeredPaneCorrespondences.java
private void initListener() { // MyMouseEventListener myMouseEventlistener = new MyMouseEventListener(glassPane, pannelloPrincipale, this, split); // glassPane.getView().addMouseListener(myMouseEventlistener); // glassPane.getView().addMouseMotionListener(myMouseEventlistener); JScrollBar jScrollBarHorizontal = scrollSource.getHorizontalScrollBar(); JScrollBar jScrollBarVertical = scrollSource.getVerticalScrollBar(); ScrollPaneAdjustmentListener my = new ScrollPaneAdjustmentListener(this, sourceSchemaTree, glassPane, sourceSchemaTree, "source"); jScrollBarHorizontal.addAdjustmentListener(my); jScrollBarVertical.addAdjustmentListener(my); JScrollBar jScrollBarHorizontalTarget = scrollTarget.getHorizontalScrollBar(); JScrollBar jScrollBarVerticalTarget = scrollTarget.getVerticalScrollBar(); ScrollPaneAdjustmentListener my2 = new ScrollPaneAdjustmentListener(this, targetSchemaTree, glassPane, targetSchemaTree, "target"); jScrollBarHorizontalTarget.addAdjustmentListener(my2); jScrollBarVerticalTarget.addAdjustmentListener(my2); sourceSchemaTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { moveToFront(glassPane);//from w ww . j a v a2 s. c om } }); this.sourceSchemaTree.addTreeExpansionListener( new WidgetMoveExpansionListener(this, sourceSchemaTree, glassPane, sourceSchemaTree, "source")); this.targetSchemaTree.addTreeExpansionListener( new WidgetMoveExpansionListener(this, targetSchemaTree, glassPane, targetSchemaTree, "target")); // this.sourceSchemaTree.addTreeSelectionListener(new ConstraintColoringTreeSelectionListener(Costanti.CONNECTION_CONSTRAINT_SOURCE)); // this.targetSchemaTree.addTreeSelectionListener(new ConstraintColoringTreeSelectionListener(Costanti.CONNECTION_CONSTRAINT_TARGET)); initListenerSplit(); // creaPopUpSource(); // creaPopUpTarget(); }
From source file:savant.view.variation.swing.VariationModule.java
/** * Three of our panels consist of a component next to a scroll-bar */// w w w . ja v a 2s . c o m private JPanel populatePanel(JComponent content) { JScrollBar scroller = new JScrollBar(); scroller.setMinimum(1); scroller.addAdjustmentListener(scrollerListener); scrollers.add(scroller); JPanel container = new JPanel(); container.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 1.0; if (content instanceof JLabel) { gbc.anchor = GridBagConstraints.NORTH; gbc.insets = MESSAGE_INSETS; gbc.fill = GridBagConstraints.HORIZONTAL; } else { gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; } container.add(content, gbc); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.weightx = 0.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.VERTICAL; gbc.insets = new Insets(0, 0, 0, 0); container.add(scroller, gbc); return container; }
From source file:savant.view.variation.swing.VariationModule.java
public void visibleRangeChanged(String ref, Range r) { if (r.getLength() > ResolutionSettings.getVariantLowToHighThreshold()) { showMessage(ZOOM_MESSAGE);/* w w w .j a v a 2 s . com*/ } else { try { // Detach the adjustment listeners so that setting the maximum doesn't fire an event. for (JScrollBar sb : scrollers) { sb.removeAdjustmentListener(scrollerListener); } for (JScrollBar sb : scrollers) { sb.setMaximum(LocationController.getInstance().getMaxRangeEnd()); sb.setValue(r.getFrom()); sb.setVisibleAmount(r.getLength()); sb.setBlockIncrement(r.getLength()); sb.repaint(); } } finally { // Reattach the adjustment listeners. for (JScrollBar sb : scrollers) { sb.addAdjustmentListener(scrollerListener); } } } rangeField.setText(String.format("%s:%d-%d", ref, r.getFrom(), r.getTo())); }