protected void paintString( Graphics g, int x, int y, int width, int height, int amountFull, Insets b) { boolean indeterminate = false; if (Utilities.getJavaVersion() >= 1.6) { indeterminate = progressBar.isIndeterminate(); } if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { if (Utilities.isLeftToRight(progressBar)) { if (indeterminate) { boxRect = getBox(boxRect); paintString(g, x, y, width, height, boxRect.x, boxRect.width, b); } else { paintString(g, x, y, width, height, x, amountFull, b); } } else { paintString(g, x, y, width, height, x + width - amountFull, amountFull, b); } } else { if (indeterminate) { boxRect = getBox(boxRect); paintString(g, x, y, width, height, boxRect.y, boxRect.height, b); } else { paintString(g, x, y, width, height, y + height - amountFull, amountFull, b); } } }
private void paintString( Graphics g, int x, int y, int width, int height, int fillStart, int amountFull, Insets b) { if (!(g instanceof Graphics2D)) { return; } Graphics2D g2D = (Graphics2D) g; String progressString = progressBar.getString(); g2D.setFont(progressBar.getFont()); Point renderLocation = getStringPlacement(g2D, progressString, x, y, width, height); Rectangle savedClip = g2D.getClipBounds(); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { g2D.setColor(getSelectionBackground()); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); g2D.setColor(getSelectionForeground()); g2D.clipRect(fillStart, y, amountFull, height); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); } else { // VERTICAL g2D.setColor(getSelectionBackground()); AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2); g2D.setFont(progressBar.getFont().deriveFont(rotate)); renderLocation = getStringPlacement(g2D, progressString, x, y, width, height); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); g2D.setColor(getSelectionForeground()); g2D.clipRect(x, fillStart, width, amountFull); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); } g2D.setClip(savedClip); }
protected void paintIndeterminate(Graphics g, JComponent c) { if (!(g instanceof Graphics2D)) { return; } Graphics2D g2D = (Graphics2D) g; Insets b = progressBar.getInsets(); // area for border int barRectWidth = progressBar.getWidth() - (b.right + b.left); int barRectHeight = progressBar.getHeight() - (b.top + b.bottom); Color colors[]; if (progressBar.getForeground() instanceof UIResource) { if (!Utilities.isActive(c)) { colors = BaseLookAndFeel.getTheme().getInActiveColors(); } else if (c.isEnabled()) { colors = BaseLookAndFeel.getTheme().getProgressBarColors(); } else { colors = BaseLookAndFeel.getTheme().getDisabledColors(); } } else { Color hiColor = ColorHelper.brighter(progressBar.getForeground(), 40); Color loColor = ColorHelper.darker(progressBar.getForeground(), 20); colors = ColorHelper.createColorArr(hiColor, loColor, 20); } Color cHi = ColorHelper.darker(colors[colors.length - 1], 5); Color cLo = ColorHelper.darker(colors[colors.length - 1], 10); // Paint the bouncing box. Rectangle box = getBox(null); if (box != null) { g2D.setColor(progressBar.getForeground()); Utilities.draw3DBorder(g, cHi, cLo, box.x + 1, box.y + 1, box.width - 2, box.height - 2); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { Utilities.fillHorGradient(g, colors, box.x + 2, box.y + 2, box.width - 4, box.height - 4); } else { Utilities.fillVerGradient(g, colors, box.x + 2, box.y + 2, box.width - 4, box.height - 4); } // Deal with possible text painting if (progressBar.isStringPainted()) { Object savedRenderingHint = null; if (BaseLookAndFeel.getTheme().isTextAntiAliasingOn()) { savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g2D.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, BaseLookAndFeel.getTheme().getTextAntiAliasingHint()); } if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { paintString(g2D, b.left, b.top, barRectWidth, barRectHeight, box.width, b); } else { paintString(g2D, b.left, b.top, barRectWidth, barRectHeight, box.height, b); } if (BaseLookAndFeel.getTheme().isTextAntiAliasingOn()) { g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint); } } } }
private void end(StringBuilder ans, Pretty pretty, String indent) { if (endEncloser == null) return; if (!pretty.pretty) ans.append(endEncloser); else { Utilities.assureEndsWithNewLine(ans); ans.append(indent + endEncloser); if (pretty.comments && endComment.length() > 0) ans.append("#" + endComment); Utilities.assureEndsWithNewLine(ans); } }
/** * Converts an offset in a line into an x co-ordinate. This is a fast version that should only be * used if no changes were made to the text since the last repaint. * * @param line The line * @param offset The offset, from the start of the line */ public int _offsetToX(int line, int offset) { TokenMarker tokenMarker = getTokenMarker(); /* Use painter's cached info for speed */ FontMetrics fm = painter.getFontMetrics(); getLineText(line, lineSegment); int segmentOffset = lineSegment.offset; int x = horizontalOffset; /* If syntax coloring is disabled, do simple translation */ if (tokenMarker == null) { lineSegment.count = offset; return x + Utilities.getTabbedTextWidth(lineSegment, fm, x, painter, 0); } /* If syntax coloring is enabled, we have to do this because * tokens can vary in width */ else { Token tokens; if (painter.currentLineIndex == line && painter.currentLineTokens != null) tokens = painter.currentLineTokens; else { painter.currentLineIndex = line; tokens = painter.currentLineTokens = tokenMarker.markTokens(lineSegment, line); } Toolkit toolkit = painter.getToolkit(); Font defaultFont = painter.getFont(); SyntaxStyle[] styles = painter.getStyles(); for (; ; ) { byte id = tokens.id; if (id == Token.END) { return x; } if (id == Token.NULL) fm = painter.getFontMetrics(); else fm = styles[id].getFontMetrics(defaultFont); int length = tokens.length; if (offset + segmentOffset < lineSegment.offset + length) { lineSegment.count = offset - (lineSegment.offset - segmentOffset); return x + Utilities.getTabbedTextWidth(lineSegment, fm, x, painter, 0); } else { lineSegment.count = length; x += Utilities.getTabbedTextWidth(lineSegment, fm, x, painter, 0); lineSegment.offset += length; } tokens = tokens.next; } } }
public void paint(Graphics g) { Dimension size = getSize(); Color colors[]; if (isEnabled()) { if (getModel().isArmed() && getModel().isPressed()) { colors = BaseLookAndFeel.getTheme().getPressedColors(); } else if (getModel().isRollover()) { colors = BaseLookAndFeel.getTheme().getRolloverColors(); } else { colors = BaseLookAndFeel.getTheme().getButtonColors(); } } else { colors = BaseLookAndFeel.getTheme().getDisabledColors(); } Utilities.fillHorGradient(g, colors, 0, 0, size.width, size.height); boolean inverse = ColorHelper.getGrayValue(colors) < 128; Icon icon = inverse ? BaseIcons.getComboBoxInverseIcon() : BaseIcons.getComboBoxIcon(); int x = (size.width - icon.getIconWidth()) / 2; int y = (size.height - icon.getIconHeight()) / 2; Graphics2D g2D = (Graphics2D) g; Composite savedComposite = g2D.getComposite(); g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); if (getModel().isPressed() && getModel().isArmed()) { icon.paintIcon(this, g, x + 2, y + 1); } else { icon.paintIcon(this, g, x + 1, y); } g2D.setComposite(savedComposite); paintBorder(g2D); }
/** * Determines the preferred span for this view along an axis. * * @param axis may be either View.X_AXIS or View.Y_AXIS * @return the span the view would like to be rendered into >= 0. Typically the view is told to * render into the span that is returned, although there is no guarantee. The parent may * choose to resize or break the view. */ public float getPreferredSpan(int axis) { switch (axis) { case View.X_AXIS: Segment buff = SegmentCache.getSharedSegment(); Document doc = getDocument(); int width; try { FontMetrics fm = getFontMetrics(); doc.getText(0, doc.getLength(), buff); width = Utilities.getTabbedTextWidth(buff, fm, 0, this, 0); if (buff.count > 0) { Component c = getContainer(); firstLineOffset = sun.swing.SwingUtilities2.getLeftSideBearing( (c instanceof JComponent) ? (JComponent) c : null, fm, buff.array[buff.offset]); firstLineOffset = Math.max(0, -firstLineOffset); } else { firstLineOffset = 0; } } catch (BadLocationException bl) { width = 0; } SegmentCache.releaseSharedSegment(buff); return width + firstLineOffset; default: return super.getPreferredSpan(axis); } }
public void actionPerformed(java.awt.event.ActionEvent arg0) { if (JTable1.getSelectedRowCount() != 1) { Utilities.errorMessage(resourceBundle.getString("Please select a view to edit")); return; } views = new ViewsWizard(ViewConfig.this, applet); views.setSecurityModel(model); Point p = JLabel1.getLocationOnScreen(); views.setLocation(p); views.init(); views.setState(false); Vector viewvec = model.getAllViews(); for (int i = 0; i < viewvec.size(); i++) { String viewname = ((AuthViewWithOperations) viewvec.elementAt(i)).getAuthorizedViewName(); if (JTable1.getValueAt(JTable1.getSelectedRow(), 0).toString().equals(viewname)) { views.setValues((AuthViewWithOperations) viewvec.elementAt(i)); } } disableButtons(); views.setVisible(true); }
public void actionPerformed(java.awt.event.ActionEvent arg0) { if (JTable1.getSelectedRowCount() != 1) { Utilities.errorMessage(resourceBundle.getString("Please select a view to delete")); return; } if (JOptionPane.showConfirmDialog( null, resourceBundle.getString("Are you sure you want to delete the selected view "), resourceBundle.getString("Warning!"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null) == JOptionPane.NO_OPTION) return; Vector viewvec = model.getAllViews(); for (int i = 0; i < viewvec.size(); i++) { String viewname = ((AuthViewWithOperations) viewvec.elementAt(i)).getAuthorizedViewName(); if (JTable1.getValueAt(JTable1.getSelectedRow(), 0).toString().equals(viewname)) { AuthViewWithOperations avop = (AuthViewWithOperations) viewvec.elementAt(i); model.delViewOp( avop.getAuthorizedViewName(), avop.getViewProperties(), avop.getOperations()); } } disableButtons(); }
protected void setButtonBorder() { if (Utilities.isLeftToRight(comboBox)) { Border border = BorderFactory.createMatteBorder(0, 1, 0, 0, BaseLookAndFeel.getFrameColor()); arrowButton.setBorder(border); } else { Border border = BorderFactory.createMatteBorder(0, 0, 0, 1, BaseLookAndFeel.getFrameColor()); arrowButton.setBorder(border); } }
public JButton createArrowButton() { JButton button = new ArrowButton(); if (Utilities.isLeftToRight(comboBox)) { Border border = BorderFactory.createMatteBorder(0, 1, 0, 0, BaseLookAndFeel.getFrameColor()); button.setBorder(border); } else { Border border = BorderFactory.createMatteBorder(0, 0, 0, 1, BaseLookAndFeel.getFrameColor()); button.setBorder(border); } return button; }
public void paint(Graphics g, JComponent c) { if (Utilities.getJavaVersion() >= 1.4) { if (progressBar.isIndeterminate()) { paintIndeterminate(g, c); } else { paintDeterminate(g, c); } } else { paintDeterminate(g, c); } }
void doKids(StringBuilder ans, Pretty pretty, String indent) { if (kids == null) return; for (Rope kid : kids) { if (!pretty.pretty) { kid.toString(ans, pretty, ""); } else { kid.toString(ans, pretty, indent + getKidIndentIncrement(kid, pretty)); Utilities.assureEndsWithNewLine(ans); } } }
private void start(StringBuilder ans, Pretty pretty, String indent) { if (startEncloser == null) return; if (!pretty.pretty) { ans.append(startEncloser); } else { String comment; if (pretty.comments && startComment.length() > 0) comment = " #" + startComment; else comment = ""; ans.append(indent + startEncloser + comment); Utilities.assureEndsWithNewLine(ans); } }
public Dimension getPreferredSize(JComponent c) { Dimension size = super.getPreferredSize(c); if (comboBox.getGraphics() != null) { FontMetrics fm = Utilities.getFontMetrics(comboBox, comboBox.getGraphics(), comboBox.getFont()); size.height = fm.getHeight() + 2; if (UIManager.getLookAndFeel() instanceof BaseLookAndFeel) { BaseLookAndFeel laf = (BaseLookAndFeel) UIManager.getLookAndFeel(); size.height = Math.max(size.height, laf.getIconFactory().getDownArrowIcon().getIconHeight() + 2); } } return new Dimension(size.width + 2, size.height + 2); }
@Override public Component getListCellRendererComponent( JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) (super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus)); if (value instanceof TypeColorEntry) { TypeColorEntry entry = (TypeColorEntry) value; Token.Type type = entry.getType(); Color color = entry.getColor(); label.setText(Utilities.normalize(type.toString())); if ((type == Token.Type.MATCHED_BRACKET) || (type == Token.Type.UNMATCHED_BRACKET)) { label.setBackground(color); label.setForeground(Color.BLACK); } else { label.setForeground(color); } } return label; }
/** * Draw the line numbers * * @param g */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); ((Graphics2D) g) .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Determine the width of the space available to draw the line number FontMetrics fontMetrics = component.getFontMetrics(component.getFont()); Insets insets = getInsets(); int availableWidth = getSize().width - insets.left - insets.right; // Determine the rows to draw within the clipped bounds. Rectangle clip = g.getClipBounds(); int rowStartOffset = component.viewToModel(new Point(0, clip.y)); int endOffset = component.viewToModel(new Point(0, clip.y + clip.height)); while (rowStartOffset <= endOffset) { try { if (isCurrentLine(rowStartOffset)) g.setColor(getCurrentLineForeground()); else g.setColor(getForeground()); // Get the line number as a string and then determine the // "X" and "Y" offsets for drawing the string. String lineNumber = getTextLineNumber(rowStartOffset); int stringWidth = fontMetrics.stringWidth(lineNumber); int x = getOffsetX(availableWidth, stringWidth) + insets.left; int y = getOffsetY(rowStartOffset, fontMetrics); g.drawString(lineNumber, x, y); // Move to the next row rowStartOffset = Utilities.getRowEnd(component, rowStartOffset) + 1; } catch (Exception e) { break; } } }
/** Sets the top level location. */ public void setTopLevelLocation() { topLevelLocation = Utilities.getTopLevelLocation(topLevelComponent, segmentTable); }
public void scrollTo(int index) { Utilities.tableCenterScroll(this, segmentTable, index); }
public void showError(String err) { enableButtons(); Utilities.errorMessage(resourceBundle.getString(err)); }
public AboutDialog(JConsole jConsole) { super(jConsole, Resources.getText("Help.AboutDialog.title"), false); setAccessibleDescription(this, getText("Help.AboutDialog.accessibleDescription")); setDefaultCloseOperation(HIDE_ON_CLOSE); setResizable(false); JComponent cp = (JComponent) getContentPane(); createActions(); JLabel mastheadLabel = new JLabel(mastheadIcon); setAccessibleName(mastheadLabel, getText("Help.AboutDialog.masthead.accessibleName")); JPanel mainPanel = new TPanel(0, 0); mainPanel.add(mastheadLabel, NORTH); String jConsoleVersion = Version.getVersion(); String vmName = System.getProperty("java.vm.name"); String vmVersion = System.getProperty("java.vm.version"); String urlStr = getText("Help.AboutDialog.userGuideLink.url"); if (isBrowseSupported()) { urlStr = "<a style='color:#35556b' href=\"" + urlStr + "\">" + urlStr + "</a>"; } JPanel infoAndLogoPanel = new JPanel(new BorderLayout(10, 10)); infoAndLogoPanel.setBackground(bgColor); String colorStr = String.format("%06x", textColor.getRGB() & 0xFFFFFF); JEditorPane helpLink = new JEditorPane( "text/html", "<html><font color=#" + colorStr + ">" + getText("Help.AboutDialog.jConsoleVersion", jConsoleVersion) + "<p>" + getText("Help.AboutDialog.javaVersion", (vmName + ", " + vmVersion)) + "<p>" + getText("Help.AboutDialog.userGuideLink", urlStr) + "</html>"); helpLink.setOpaque(false); helpLink.setEditable(false); helpLink.setForeground(textColor); mainPanel.setBorder(BorderFactory.createLineBorder(borderColor)); infoAndLogoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); helpLink.addHyperlinkListener( new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { browse(e.getDescription()); } } }); infoAndLogoPanel.add(helpLink, NORTH); ImageIcon brandLogoIcon = new ImageIcon(getClass().getResource("resources/brandlogo.png")); JLabel brandLogo = new JLabel(brandLogoIcon, JLabel.LEADING); JButton closeButton = new JButton(closeAction); JPanel bottomPanel = new TPanel(0, 0); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING)); buttonPanel.setOpaque(false); mainPanel.add(infoAndLogoPanel, CENTER); cp.add(bottomPanel, SOUTH); infoAndLogoPanel.add(brandLogo, SOUTH); buttonPanel.setBorder(new EmptyBorder(2, 12, 2, 12)); buttonPanel.add(closeButton); bottomPanel.add(buttonPanel, NORTH); statusBar = new JLabel(" "); bottomPanel.add(statusBar, SOUTH); cp.add(mainPanel, NORTH); pack(); setLocationRelativeTo(jConsole); Utilities.updateTransparency(this); }
/** @author todd */ class OnlineStatusIndicator { private static Image OPEN_IMAGE = Utilities.loadImage(SessionNode.OPEN_ICON); private static Image CLOSED_IMAGE = Utilities.loadImage(SessionNode.CLOSED_ICON); private static Image AWAY_IMAGE = Utilities.loadImage(SessionNode.AWAY_ICON); private static Image BUSY_IMAGE = Utilities.loadImage(SessionNode.BUSY_ICON); private static Image IDLE_IMAGE = Utilities.loadImage(SessionNode.IDLE_ICON); private static OnlineStatusIndicator instance; //////////////////////////////////////////////////////////////////////////// // Instance fields //////////////////////////////////////////////////////////////////////////// private JLabel label; private Helper helper; private int currentStatus = CollabPrincipal.STATUS_UNKNOWN; Component getComponent() { return label; } /** */ protected OnlineStatusIndicator() { helper = new Helper(); label = new JLabel(); label.addMouseListener(helper); initListening(1); } private void initListening(final int level) { CollabManager man = CollabManager.getDefault(); if (man == null) { // manager not yet registered. This is a transient condition during // module enablement because of manager registration mechanism. // Retry 5s later assert level < 10; RequestProcessor.getDefault() .post( new Runnable() { public void run() { initListening(level + 1); } }, level * 5000); } else { man.addPropertyChangeListener(helper); attachListeners(); updateStatus(); } } private void setStatus(int value) { currentStatus = value; SwingUtilities.invokeLater(helper); } /** */ protected void updateStatus() { final CollabManager manager = CollabManager.getDefault(); if (manager != null) { int sharedStatus = CollabPrincipal.STATUS_OFFLINE; boolean unilateral = true; CollabSession[] sessions = manager.getSessions(); for (int i = 0; i < sessions.length; i++) { int status = sessions[i].getUserPrincipal().getStatus(); if (sharedStatus == CollabPrincipal.STATUS_OFFLINE) { sharedStatus = status; } if (status != sharedStatus) { unilateral = false; } } if (unilateral) { // This will occur if either: // 1) No sessions were found // 2) All available sessions had the same status setStatus(sharedStatus); } else { // Assume at least one session is online setStatus(CollabPrincipal.STATUS_ONLINE); } } } //////////////////////////////////////////////////////////////////////////// // Helper methods //////////////////////////////////////////////////////////////////////////// /** */ public static String getStatusDescription(int status) { final String description; switch (status) { case CollabPrincipal.STATUS_AWAY: description = NbBundle.getMessage(ContactNode.class, "LBL_ContactNode_StatusAway"); // NOI18N break; case CollabPrincipal.STATUS_BUSY: description = NbBundle.getMessage(ContactNode.class, "LBL_ContactNode_StatusBusy"); // NOI18N break; case CollabPrincipal.STATUS_IDLE: description = NbBundle.getMessage(ContactNode.class, "LBL_ContactNode_StatusIdle"); // NOI18N break; case CollabPrincipal.STATUS_OFFLINE: description = NbBundle.getMessage(ContactNode.class, "LBL_ContactNode_StatusOffline"); // NOI18N break; case CollabPrincipal.STATUS_ONLINE: description = NbBundle.getMessage(ContactNode.class, "LBL_ContactNode_StatusOnline"); // NOI18N break; default: description = NbBundle.getMessage(ContactNode.class, "LBL_ContactNode_StatusUnknown"); // NOI18N } return description; } /** */ public static Image getStatusIcon(int status) { final Image statusIcon; switch (status) { case CollabPrincipal.STATUS_AWAY: statusIcon = AWAY_IMAGE; break; case CollabPrincipal.STATUS_BUSY: statusIcon = BUSY_IMAGE; break; case CollabPrincipal.STATUS_IDLE: statusIcon = IDLE_IMAGE; break; case CollabPrincipal.STATUS_OFFLINE: statusIcon = CLOSED_IMAGE; break; case CollabPrincipal.STATUS_ONLINE: statusIcon = OPEN_IMAGE; break; default: statusIcon = CLOSED_IMAGE; } return statusIcon; } /** */ protected static String getStatusToolTip() { StringBuffer result = new StringBuffer("<html>"); // NOI18N result.append("<table cellspacing=\"0\" border=\"0\">"); // NOI18N final CollabManager manager = CollabManager.getDefault(); if (manager != null) { Set sessions = new TreeSet( new Comparator() { public int compare(Object o1, Object o2) { String s1 = ((CollabSession) o1).getUserPrincipal().getDisplayName(); String s2 = ((CollabSession) o2).getUserPrincipal().getDisplayName(); return s1.compareTo(s2); } }); sessions.addAll(Arrays.asList(manager.getSessions())); if (sessions.size() == 0) { result.append("<tr><td>"); // NOI18N result.append(getStatusDescription(CollabPrincipal.STATUS_OFFLINE)); result.append("</td></tr>"); // NOI18N } else { for (Iterator i = sessions.iterator(); i.hasNext(); ) { CollabPrincipal principal = ((CollabSession) i.next()).getUserPrincipal(); result.append("<tr>"); // NOI18N result.append("<td>"); // NOI18N result.append("<b>"); // NOI18N result.append(principal.getDisplayName()); result.append(": "); // NOI18N result.append("</b>"); // NOI18N result.append("</td>"); // NOI18N result.append("<td>"); // NOI18N result.append(getStatusDescription(principal.getStatus())); result.append("</td>"); // NOI18N result.append("</tr>"); // NOI18N } } } result.append("</table>"); // NOI18N return result.toString(); } //////////////////////////////////////////////////////////////////////////// // Management methods //////////////////////////////////////////////////////////////////////////// /** */ static synchronized OnlineStatusIndicator getDefault() { if (instance == null) { instance = new OnlineStatusIndicator(); } return instance; } /** */ private void attachListeners() { // Add the listener from each collab session principal CollabSession[] sessions = CollabManager.getDefault().getSessions(); for (int i = 0; i < sessions.length; i++) { sessions[i].getUserPrincipal().removePropertyChangeListener(helper); sessions[i].getUserPrincipal().addPropertyChangeListener(helper); } } private class Helper extends MouseAdapter implements PropertyChangeListener, Runnable { public void mouseClicked(MouseEvent event) { CollabExplorerPanel.getInstance().open(); CollabExplorerPanel.getInstance().requestActive(); } public void propertyChange(PropertyChangeEvent event) { // session list changed if (event.getSource() instanceof CollabManager) { attachListeners(); } // either session list or session status changed updateStatus(); } public void run() { Image statusIcon = getStatusIcon(currentStatus); label.setIcon(new ImageIcon(statusIcon)); label.setToolTipText(getStatusToolTip()); } } }
/** * 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; }
protected void paintDeterminate(Graphics g, JComponent c) { if (!(g instanceof Graphics2D)) { return; } Graphics2D g2D = (Graphics2D) g; Insets b = progressBar.getInsets(); // area for border int w = progressBar.getWidth() - (b.right + b.left); int h = progressBar.getHeight() - (b.top + b.bottom); // amount of progress to draw int amountFull = getAmountFull(b, w, h); Color colors[]; if (progressBar.getForeground() instanceof UIResource) { if (!Utilities.isActive(c)) { colors = BaseLookAndFeel.getTheme().getInActiveColors(); } else if (c.isEnabled()) { colors = BaseLookAndFeel.getTheme().getProgressBarColors(); } else { colors = BaseLookAndFeel.getTheme().getDisabledColors(); } } else { Color hiColor = ColorHelper.brighter(progressBar.getForeground(), 40); Color loColor = ColorHelper.darker(progressBar.getForeground(), 20); colors = ColorHelper.createColorArr(hiColor, loColor, 20); } Color cHi = ColorHelper.darker(colors[colors.length - 1], 5); Color cLo = ColorHelper.darker(colors[colors.length - 1], 10); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { if (Utilities.isLeftToRight(progressBar)) { Utilities.draw3DBorder(g, cHi, cLo, 1 + b.left, 2, amountFull - 2, h - 2); Utilities.fillHorGradient(g, colors, 2 + b.left, 3, amountFull - 4, h - 4); } else { Utilities.draw3DBorder( g, cHi, cLo, progressBar.getWidth() - amountFull - b.right + 2, 2, amountFull - 2, h - 2); Utilities.fillHorGradient( g, colors, progressBar.getWidth() - amountFull - b.right + 3, 3, amountFull - 4, h - 4); } } else { // VERTICAL Utilities.draw3DBorder(g, cHi, cLo, 2, h - amountFull + 2, w - 2, amountFull - 2); Utilities.fillVerGradient(g, colors, 3, h - amountFull + 3, w - 4, amountFull - 4); } // Deal with possible text painting if (progressBar.isStringPainted()) { Object savedRenderingHint = null; if (BaseLookAndFeel.getTheme().isTextAntiAliasingOn()) { savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g2D.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, BaseLookAndFeel.getTheme().getTextAntiAliasingHint()); } paintString(g, b.left, b.top, w, h, amountFull, b); if (BaseLookAndFeel.getTheme().isTextAntiAliasingOn()) { g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint); } } }
/** flashes the value at the given index. */ public void flash(int index) { flashIndex = index; Utilities.tableCenterScroll(this, segmentTable, index); }