/** * 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; } } }
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); } }
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(); }
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); }
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); } }
@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 */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); // 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) { } } }
public void showError(String err) { enableButtons(); Utilities.errorMessage(resourceBundle.getString(err)); }
/** @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()); } } }
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); }
public void scrollTo(int index) { Utilities.tableCenterScroll(this, segmentTable, index); }
/** flashes the value at the given index. */ public void flash(int index) { flashIndex = index; Utilities.tableCenterScroll(this, segmentTable, index); }
/** Sets the top level location. */ public void setTopLevelLocation() { topLevelLocation = Utilities.getTopLevelLocation(topLevelComponent, segmentTable); }