List of usage examples for javax.swing JScrollBar JScrollBar
public JScrollBar(int orientation)
minimum = 0 maximum = 100 value = 0 extent = 10
From source file:TextSlider.java
public TextSlider() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); textField = new JTextField(); scrollBar = new JScrollBar(JScrollBar.HORIZONTAL); BoundedRangeModel brm = textField.getHorizontalVisibility(); scrollBar.setModel(brm);/*from ww w . ja va 2 s .c om*/ add(textField); add(scrollBar); }
From source file:mulavito.gui.components.GraphPanel.java
protected GraphPanel() { super(new BorderLayout()); layout = new MyGridLayout(1, 1); contentPane = new JPanel(); add(contentPane);/*from w w w . jav a2 s . c om*/ contentPane.setLayout(layout); vvs = new LinkedList<LV>(); verticalScrollBar = new JScrollBar(JScrollBar.VERTICAL); verticalScrollBar.setValues(0, 0, 0, 0); add(verticalScrollBar, BorderLayout.EAST); horizontalScrollBar = new JScrollBar(JScrollBar.HORIZONTAL); horizontalScrollBar.setValues(0, 0, 0, 0); south = new JPanel(new BorderLayout()); south.add(horizontalScrollBar); add(south, BorderLayout.SOUTH); setCorner(new SatelliteMultiViewerCorner()); // for layer stack stackListener = new ChangeListener() { @SuppressWarnings("unchecked") @Override public void stateChanged(ChangeEvent e) { // handle layer change if (e instanceof LayerChangedEvent<?>) { LayerChangedEvent<L> lce = (LayerChangedEvent<L>) e; if (lce.remove) { if (lce.g != null)// remove layer removeLayer(getViewer(lce.g)); else // clear layers while (vvs.size() > 0) removeLayer(vvs.get(0)); } else if (lce.g != null) // add layer addLayer(lce.g); javax.swing.SwingUtilities.invokeLater(new Runnable() { // To ensure correct behavior when several layers are // added at the same time, we slightly delay these // calls. @Override public void run() { configureScrollBars(); configureSpinner(); arrangeViewers(); autoZoomToFit(); } }); } // else removed vertices updateUI(); } }; // configure contexts contexts = new LinkedList<ViewerContext<L, LV>>(); // addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { arrangeViewers(); autoZoomToFit(); } }); }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
private JScrollBar createJScrollBar() { JScrollBar b = new JScrollBar(JScrollBar.HORIZONTAL); b.setModel(new DefaultBoundedRangeModel()); b.setEnabled(false);// w w w .j a v a2 s . com return b; }
From source file:org.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 w ww .j ava 2s .c om } 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 int visibleLines = Math.min(GROUPS_VISIBLE, groupNames.size()); final ChartPanel chartPanel = ChartUtils.createPanel(chart, ChartUtils.WIDTH_WIDE, visibleLines * 50 + 200); 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 JComponent decoratedChartPanel; final StringBuilder chartDescription = new StringBuilder("<html>"); chartDescription.append("<p>The chart displays the recorded timeline based on FROM and TO dates.</p>"); chartDescription.append( "<p>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.</p>"); chartDescription.append( "<p>You can <b>zoom in</b> by clicking and dragging the area that you want to examine in further detail.</p>"); 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("<p>Use the right <b>scrollbar</b> to scroll up and down on the chart.</p>"); decoratedChartPanel = outerPanel; } else { decoratedChartPanel = chartPanel; } chartDescription.append("</html>"); final JLabel chartDescriptionLabel = new JLabel(chartDescription.toString()); final DCPanel panel = new DCPanel(); panel.setLayout(new VerticalLayout()); panel.add(chartDescriptionLabel); panel.add(decoratedChartPanel); return panel; }
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; }// w w w .j a v a2 s . 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:apidemo.PanScrollZoomDemo.java
/** * Creates the toolbar./*from www . ja v a2 s . c o m*/ * * @return the toolbar. */ private JToolBar createToolbar() { final JToolBar toolbar = new JToolBar(); final ButtonGroup groupedButtons = new ButtonGroup(); // ACTION_CMD_PAN this.panButton = new JToggleButton(); prepareButton(this.panButton, ACTION_CMD_PAN, " Pan ", "Pan mode"); groupedButtons.add(this.panButton); toolbar.add(this.panButton); // ACTION_CMD_ZOOM_BOX this.zoomButton = new JToggleButton(); prepareButton(this.zoomButton, ACTION_CMD_ZOOM_BOX, " Zoom ", "Zoom mode"); groupedButtons.add(this.zoomButton); this.zoomButton.setSelected(true); // no other makes sense after startup toolbar.add(this.zoomButton); // end of toggle-button group for select/pan/zoom-box toolbar.addSeparator(); // ACTION_CMD_ZOOM_IN this.zoomInButton = new JButton(); prepareButton(this.zoomInButton, ACTION_CMD_ZOOM_IN, " + ", "Zoom in"); toolbar.add(this.zoomInButton); // ACTION_CMD_ZOOM_OUT this.zoomOutButton = new JButton(); prepareButton(this.zoomOutButton, ACTION_CMD_ZOOM_OUT, " - ", "Zoom out"); toolbar.add(this.zoomOutButton); // ACTION_CMD_ZOOM_TO_FIT this.fitButton = new JButton(); prepareButton(this.fitButton, ACTION_CMD_ZOOM_TO_FIT, " Fit ", "Fit all"); toolbar.add(this.fitButton); toolbar.addSeparator(); this.scrollBar = new JScrollBar(JScrollBar.HORIZONTAL); // int ht = (int) zoomButton.getPreferredSize().getHeight(); // scrollBar.setPreferredSize(new Dimension(0, ht)); this.scrollBar.setModel(new DefaultBoundedRangeModel()); toolbar.add(this.scrollBar); this.zoomOutButton.setEnabled(false); this.fitButton.setEnabled(false); this.scrollBar.setEnabled(false); toolbar.setFloatable(false); return toolbar; }
From source file:com.sshtools.sshterm.SshTermSessionPanel.java
/** * * * @param application/* www . ja v a 2 s . co m*/ * * @throws SshToolsApplicationException */ public void init(SshToolsApplication application) throws SshToolsApplicationException { super.init(application); // Additional connection tabs additionalTabs = new SshToolsConnectionTab[] { new SshTermTerminalTab() }; // Printing page format try { if (System.getSecurityManager() != null) { AccessController.checkPermission(new RuntimePermission("queuePrintJob")); } try { PrinterJob job = PrinterJob.getPrinterJob(); if (job == null) { throw new IOException("Could not get print page format."); } pageFormat = job.defaultPage(); if (PreferencesStore.preferenceExists(PREF_PAGE_FORMAT_ORIENTATION)) { pageFormat.setOrientation( PreferencesStore.getInt(PREF_PAGE_FORMAT_ORIENTATION, PageFormat.LANDSCAPE)); Paper paper = new Paper(); paper.setImageableArea(PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_X, 0), PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_Y, 0), PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_W, 0), PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_H, 0)); paper.setSize(PreferencesStore.getDouble(PREF_PAGE_FORMAT_SIZE_W, 0), PreferencesStore.getDouble(PREF_PAGE_FORMAT_SIZE_H, 0)); pageFormat.setPaper(paper); } } catch (Exception e) { showExceptionMessage("Error", e.getMessage()); } } catch (AccessControlException ace) { ace.printStackTrace(); } enableEvents(VDU_EVENTS); // Set up the actions initActions(); // Create the status bar statusBar = new StatusBar(); dataListener = new DataNotificationListener(statusBar); // Create our terminal emulation object try { emulation = createEmulation(); } catch (IOException ioe) { throw new SshToolsApplicationException(ioe); } emulation.addTerminalListener(this); // Set a scrollbar for the terminal - doesn't seem to be as simple as this scrollBar = new JScrollBar(JScrollBar.VERTICAL); emulation.setBufferSize(1000); // Create our swing terminal and add it to the main frame terminal = new TerminalPanel(emulation) { public void processEvent(AWTEvent evt) { /** We can't add a MouseWheelListener because it was not available in 1.3, so direct processing of events is necessary */ if (evt instanceof MouseEvent && evt.getID() == 507) { try { Method m = evt.getClass().getMethod("getWheelRotation", new Class[] {}); SshTermSessionPanel.this.scrollBar.setValue(SshTermSessionPanel.this.scrollBar.getValue() + (SshTermSessionPanel.this.scrollBar.getUnitIncrement() * ((Integer) m.invoke(evt, new Object[] {})).intValue() * PreferencesStore.getInt(PREF_MOUSE_WHEEL_INCREMENT, 1))); } catch (Throwable t) { } } else { super.processEvent(evt); } } public void copyNotify() { copyAction.actionPerformed(null); } }; terminal.requestFocus(); terminal.setScrollbar(scrollBar); terminal.addMouseMotionListener(this); //terminal.addMouseWheelListener(this); // Center panel with terminal and scrollbar JPanel center = new JPanel(new BorderLayout()); center.setBackground(Color.red); center.add(terminal, BorderLayout.CENTER); center.add(scrollBar, BorderLayout.EAST); // Show the context menu on mouse button 3 (right click) terminal.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if ((evt.getModifiers() & MouseEvent.BUTTON3_MASK) > 0) { getContextMenu().setLabel(getApplication().getApplicationName()); getContextMenu().show(terminal, evt.getX(), evt.getY()); } else if ((evt.getModifiers() & MouseEvent.BUTTON2_MASK) > 0) { pasteAction.actionPerformed(null); } } }); // // JPanel top = new JPanel(new BorderLayout()); // top.add(getJMenuBar(), BorderLayout.NORTH); // top.add(north, BorderLayout.SOUTH); setLayout(new BorderLayout()); add(center, BorderLayout.CENTER); // add(top, BorderLayout.NORTH); // Make sure that the swing terminal has focus terminal.requestFocus(); }
From source file:com.sshtools.sshterm.SshTerminalPanel.java
public void init(SshToolsApplication application) throws SshToolsApplicationException { super.init(application); boolean kerb_support = false; if (PreferencesStore.get(PREF_KRB5_MYPROXY_USE, "NONE").indexOf("true") >= 0) kerb_support = true;/*from ww w . j a va2 s. co m*/ // Additional connection tabs if (kerb_support == true) { additionalTabs = new SshToolsConnectionTab[] { new SshTermCommandTab(), new SshTermTerminalTab(), new GSIAuthTab(), new XForwardingTab(), new SshToolsConnectionKerberosTab() }; SshTerminalPanel.PREF_KRB5_MYPROXY_ENABLED = true; } else { additionalTabs = new SshToolsConnectionTab[] { new SshTermCommandTab(), new SshTermTerminalTab(), new GSIAuthTab(), new XForwardingTab() }; SshTerminalPanel.PREF_KRB5_MYPROXY_ENABLED = false; } // //portForwardingPane = new PortForwardingPane(); // Printing page format try { if (System.getSecurityManager() != null) { AccessController.checkPermission(new RuntimePermission("queuePrintJob")); } try { PrinterJob job = PrinterJob.getPrinterJob(); if (job == null) { throw new IOException("Could not get print page format."); } pageFormat = job.defaultPage(); if (PreferencesStore.preferenceExists(PREF_PAGE_FORMAT_ORIENTATION)) { pageFormat.setOrientation( PreferencesStore.getInt(PREF_PAGE_FORMAT_ORIENTATION, PageFormat.LANDSCAPE)); Paper paper = new Paper(); paper.setImageableArea(PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_X, 0), PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_Y, 0), PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_W, 0), PreferencesStore.getDouble(PREF_PAGE_FORMAT_IMAGEABLE_H, 0)); paper.setSize(PreferencesStore.getDouble(PREF_PAGE_FORMAT_SIZE_W, 0), PreferencesStore.getDouble(PREF_PAGE_FORMAT_SIZE_H, 0)); pageFormat.setPaper(paper); } } catch (Exception e) { showExceptionMessage("Error", e.getMessage()); } } catch (AccessControlException ace) { ace.printStackTrace(); } enableEvents(VDU_EVENTS); // Set up the actions initActions(); // Create the status bar statusBar = new StatusBar(); dataListener = new DataNotificationListener(statusBar); // Create our terminal emulation object try { emulation = createEmulation(); } catch (IOException ioe) { throw new SshToolsApplicationException(ioe); } emulation.addTerminalListener(this); // Set a scrollbar for the terminal - doesn't seem to be as simple as this scrollBar = new JScrollBar(JScrollBar.VERTICAL); emulation.setBufferSize(1000); // Create our swing terminal and add it to the main frame terminal = new TerminalPanel(emulation) { public void processEvent(AWTEvent evt) { /** We can't add a MouseWheelListener because it was not available in 1.3, so direct processing of events is necessary */ if (evt instanceof MouseEvent && evt.getID() == 507) { try { Method m = evt.getClass().getMethod("getWheelRotation", new Class[] {}); SshTerminalPanel.this.scrollBar.setValue(SshTerminalPanel.this.scrollBar.getValue() + (SshTerminalPanel.this.scrollBar.getUnitIncrement() * ((Integer) m.invoke(evt, new Object[] {})).intValue() * PreferencesStore.getInt(PREF_MOUSE_WHEEL_INCREMENT, 1))); } catch (Throwable t) { // In theory, this should never happen } } else { super.processEvent(evt); } } public void copyNotify() { copyAction.actionPerformed(null); } }; terminal.requestFocus(); terminal.setScrollbar(scrollBar); terminal.addMouseMotionListener(this); //terminal.addMouseWheelListener(this); // Center panel with terminal and scrollbar JPanel center = new JPanel(new BorderLayout()); center.setBackground(Color.red); center.add(terminal, BorderLayout.CENTER); center.add(scrollBar, BorderLayout.EAST); // Show the context menu on mouse button 3 (right click) terminal.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if ((evt.getModifiers() & MouseEvent.BUTTON3_MASK) > 0) { getContextMenu() .setLabel((getCurrentConnectionFile() == null) ? getApplication().getApplicationName() : getCurrentConnectionFile().getName()); getContextMenu().show(terminal, evt.getX(), evt.getY()); } else if ((evt.getModifiers() & MouseEvent.BUTTON2_MASK) > 0) { pasteAction.actionPerformed(null); } } }); // // JPanel top = new JPanel(new BorderLayout()); // top.add(getJMenuBar(), BorderLayout.NORTH); // top.add(north, BorderLayout.SOUTH); setLayout(new BorderLayout()); add(center, BorderLayout.CENTER); // add(top, BorderLayout.NORTH); // Make sure that the swing terminal has focus terminal.requestFocus(); }
From source file:org.datavyu.controllers.component.MixerController.java
private void initView() { // Set default scale values minStart = 0;//from w w w. ja va 2s.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:org.kepler.gui.KeplerGraphFrame.java
/** * Override BasicGraphFrame._initBasicGraphFrame() *//*ww w. java2s. c o m*/ @Override protected void _initBasicGraphFrame() { /** * @todo - FIXME - Need to move this further up the hierarchy, so other * types of frames use it too. Don't put it in a launcher class * like KeplerApplication, because it then gets overridden later, * elsewhere in PTII */ StaticGUIResources.setLookAndFeel(); _initBasicGraphFrameInitialization(); _dropTarget = BasicGraphFrameExtension.getDropTarget(_jgraph); // add a CanvasDropTargetListener so that other classes can get CanvasDropTargetListener listener = CanvasDropTargetListener.getInstance(); _dropTarget.registerAdditionalListener(listener); ActionListener deletionListener = new DeletionListener(); _rightComponent.registerKeyboardAction(deletionListener, "Delete", KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); _rightComponent.registerKeyboardAction(deletionListener, "BackSpace", KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); _initBasicGraphFrameRightComponent(); _jgraph.setRequestFocusEnabled(true); // Background color is parameterizable by preferences. Configuration configuration = getConfiguration(); if (configuration != null) { try { // Set the PtolemyPreference to the desired background. // See // http://bugzilla.ecoinformatics.org/show_bug.cgi?id=2321#c14 PtolemyPreferences preferences = PtolemyPreferences .getPtolemyPreferencesWithinConfiguration(configuration); if (_isDebugging) { _log.debug("bg: " + BACKGROUND_COLOR); } if (preferences != null) { float[] components = new float[4]; // Make sure we get only 4 elements in case the color space // is bigger than 4 components = BACKGROUND_COLOR.getComponents(components); preferences.backgroundColor.setExpression("{" + components[0] + "," + components[1] + "," + components[2] + "," + components[3] + "}"); _rightComponent.setBackground(preferences.backgroundColor.asColor()); if (_isDebugging) { _log.debug("desired background: " + BACKGROUND_COLOR + " actual background: " + preferences.backgroundColor.asColor()); } } } catch (IllegalActionException e1) { // Ignore the exception and use the default color. } } _initBasicGraphFrameRightComponentMouseListeners(); try { // The SizeAttribute property is used to specify the size // of the JGraph component. Unfortunately, with Swing's // mysterious and undocumented handling of component sizes, // there appears to be no way to control the size of the // JGraph from the size of the Frame, which is specified // by the WindowPropertiesAttribute. SizeAttribute size = (SizeAttribute) getModel().getAttribute("_vergilSize", SizeAttribute.class); if (size != null) { size.setSize(_jgraph); } else { // Set the default size. // Note that the location is of the frame, while the size // is of the scrollpane. _jgraph.setPreferredSize(new Dimension(600, 400)); } _initBasicGraphFrameSetZoomAndPan(); } catch (Exception ex) { // Ignore problems here. Errors simply result in a default // size and location. } // Create the panner. _graphPanner = new JCanvasPanner(_jgraph); _horizontalScrollBar = new JScrollBar(Adjustable.HORIZONTAL); _verticalScrollBar = new JScrollBar(Adjustable.VERTICAL); // see if we want scrollbars on the canvas or not // the answer defaults to 'no' CanvasNavigationModifierFactory CNMfactory = (CanvasNavigationModifierFactory) getConfiguration() .getAttribute("canvasNavigationModifier"); if (CNMfactory != null) { // get the scrollbar flag from the factory if // it exists in the config ScrollBarModifier modifier = CNMfactory.createScrollBarModifier(); _scrollBarFlag = modifier.getScrollBarModifier(); } _canvasPanel = new JPanel(); _canvasPanel.setBorder(null); _canvasPanel.setLayout(new BorderLayout()); if (_scrollBarFlag) { _canvasPanel.add(_horizontalScrollBar, BorderLayout.SOUTH); _canvasPanel.add(_verticalScrollBar, BorderLayout.EAST); _horizontalScrollBar.setModel(_jgraph.getGraphPane().getCanvas().getHorizontalRangeModel()); _verticalScrollBar.setModel(_jgraph.getGraphPane().getCanvas().getVerticalRangeModel()); _horizontalScrollBarListener = new ScrollBarListener(_horizontalScrollBar); _verticalScrollBarListener = new ScrollBarListener(_verticalScrollBar); _horizontalScrollBar.addAdjustmentListener(_horizontalScrollBarListener); _verticalScrollBar.addAdjustmentListener(_verticalScrollBarListener); } // NOTE: add _rightComponent instead of _jgraph since _rightComponent // may be sub-divided into tabbed panes. // see http://bugzilla.ecoinformatics.org/show_bug.cgi?id=3708 _canvasPanel.add(_rightComponent, BorderLayout.CENTER); TabManager tabman = TabManager.getInstance(); tabman.initializeTabs(this); ViewManager viewman = ViewManager.getInstance(); viewman.initializeViews(this); try { viewman.addCanvasToLocation(_canvasPanel, this); } catch (Exception e) { throw new RuntimeException("Could not add canvas panel: " + e.getMessage()); } // _jgraph.setMinimumSize(new Dimension(0, 0)); getContentPane().add(viewman.getViewArea(this), BorderLayout.CENTER); // The toolbar panel is the container that contains the main toolbar and // any additional toolbars JPanel toolbarPanel = new JPanel(); toolbarPanel.setLayout(new BoxLayout(toolbarPanel, BoxLayout.Y_AXIS)); // They // stack _toolbar = new JToolBar(); // The main Kepler toolbar toolbarPanel.add(_toolbar); getContentPane().add(toolbarPanel, BorderLayout.NORTH); // Place the // toolbar panel _initBasicGraphFrameToolBarZoomButtons(); _initBasicGraphFrameActions(); // Add a weak reference to this to keep track of all // the graph frames that have been created. _openGraphFrames.add(this); System.gc(); }