private void updateScrolling() { if (myScrollingEnabled) { myBoundedRangeModel.setRangeProperties( 0, myTermSize.height, -myTerminalTextBuffer.getHistoryBuffer().getLineCount(), myTermSize.height, false); } else { myBoundedRangeModel.setRangeProperties(0, myTermSize.height, 0, myTermSize.height, false); } }
/** * Update the visibility model with the associated JTextField (if there is one) to reflect the * current visibility as a result of changes to the document model. The bounded range properties * are updated. If the view hasn't yet been shown the extent will be zero and we just set it to be * full until determined otherwise. */ void updateVisibilityModel() { Component c = getContainer(); if (c instanceof JTextField) { JTextField field = (JTextField) c; BoundedRangeModel vis = field.getHorizontalVisibility(); int hspan = (int) getPreferredSpan(X_AXIS); int extent = vis.getExtent(); int maximum = Math.max(hspan, extent); extent = (extent == 0) ? maximum : extent; int value = maximum - extent; int oldValue = vis.getValue(); if ((oldValue + extent) > maximum) { oldValue = maximum - extent; } value = Math.max(0, Math.min(value, oldValue)); vis.setRangeProperties(value, extent, 0, maximum, false); } }
/** * Adjusts the allocation given to the view to be a suitable allocation for a text field. If the * view has been allocated more than the preferred span vertically, the allocation is changed to * be centered vertically. Horizontally the view is adjusted according to the horizontal alignment * property set on the associated JTextField (if that is the type of the hosting component). * * @param a the allocation given to the view, which may need to be adjusted. * @return the allocation that the superclass should use. */ protected Shape adjustAllocation(Shape a) { if (a != null) { Rectangle bounds = a.getBounds(); int vspan = (int) getPreferredSpan(Y_AXIS); int hspan = (int) getPreferredSpan(X_AXIS); if (bounds.height != vspan) { int slop = bounds.height - vspan; bounds.y += slop / 2; bounds.height -= slop; } // horizontal adjustments Component c = getContainer(); if (c instanceof JTextField) { JTextField field = (JTextField) c; BoundedRangeModel vis = field.getHorizontalVisibility(); int max = Math.max(hspan, bounds.width); int value = vis.getValue(); int extent = Math.min(max, bounds.width - 1); if ((value + extent) > max) { value = max - extent; } vis.setRangeProperties(value, extent, vis.getMinimum(), max, false); if (hspan < bounds.width) { // horizontally align the interior int slop = bounds.width - 1 - hspan; int align = ((JTextField) c).getHorizontalAlignment(); if (Utilities.isLeftToRight(c)) { if (align == LEADING) { align = LEFT; } else if (align == TRAILING) { align = RIGHT; } } else { if (align == LEADING) { align = RIGHT; } else if (align == TRAILING) { align = LEFT; } } switch (align) { case SwingConstants.CENTER: bounds.x += slop / 2; bounds.width -= slop; break; case SwingConstants.RIGHT: bounds.x += slop; bounds.width -= slop; break; } } else { // adjust the allocation to match the bounded range. bounds.width = hspan; bounds.x -= vis.getValue(); } } return bounds; } return null; }
/** Run the task. */ public void run() { final BoundedRangeModel model = progressBar.getModel(); switch (task) { case -LABEL: { value = description.getText(); return; } case +LABEL: { description.setText((String) value); return; } case PROGRESS: { model.setValue(((Integer) value).intValue()); progressBar.setIndeterminate(false); return; } case STARTED: { model.setRangeProperties(0, 1, 0, 100, false); window.setVisible(true); break; // Need further action below. } case COMPLETE: { model.setRangeProperties(100, 1, 0, 100, false); window.setVisible(warningArea != null); cancel.setEnabled(false); break; // Need further action below. } } /* * Some of the tasks above requires an action on the window, which may be a JDialog or * a JInternalFrame. We need to determine the window type before to apply the action. */ synchronized (ProgressWindow.this) { if (window instanceof JDialog) { final JDialog window = (JDialog) ProgressWindow.this.window; switch (task) { case -TITLE: { value = window.getTitle(); return; } case +TITLE: { window.setTitle((String) value); return; } case STARTED: { window.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); return; } case COMPLETE: { window.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); return; } case DISPOSE: { window.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); if (warningArea == null || !window.isVisible()) { window.dispose(); } return; } } } else { final JInternalFrame window = (JInternalFrame) ProgressWindow.this.window; switch (task) { case -TITLE: { value = window.getTitle(); return; } case +TITLE: { window.setTitle((String) value); return; } case STARTED: { window.setClosable(false); return; } case COMPLETE: { window.setClosable(true); return; } case DISPOSE: { window.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE); if (warningArea == null || !window.isVisible()) { window.dispose(); } return; } } } /* * Si la tâche spécifiée n'est aucune des tâches énumérées ci-haut, * on supposera que l'on voulait afficher un message d'avertissement. */ if (warningArea == null) { final JTextArea warningArea = new JTextArea(); final JScrollPane scroll = new JScrollPane(warningArea); final JPanel namedArea = new JPanel(new BorderLayout()); ProgressWindow.this.warningArea = warningArea; warningArea.setFont(Font.getFont("Monospaced")); warningArea.setEditable(false); namedArea.setBorder(BorderFactory.createEmptyBorder(0, HMARGIN, VMARGIN, HMARGIN)); namedArea.add(new JLabel(getString(VocabularyKeys.WARNING)), BorderLayout.NORTH); namedArea.add(scroll, BorderLayout.CENTER); content.add(namedArea, BorderLayout.CENTER); if (window instanceof JDialog) { final JDialog window = (JDialog) ProgressWindow.this.window; window.setResizable(true); } else { final JInternalFrame window = (JInternalFrame) ProgressWindow.this.window; window.setResizable(true); } window.setSize(WIDTH, HEIGHT + WARNING_HEIGHT); window.setVisible(true); // Seems required in order to force relayout. } final JTextArea warningArea = (JTextArea) ProgressWindow.this.warningArea; warningArea.append((String) value); } }