mc4j-cvs Mailing List for MC4J JMX Console (Page 37)
Brought to you by:
ghinkl
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
(7) |
Apr
(135) |
May
(32) |
Jun
(34) |
Jul
|
Aug
|
Sep
(7) |
Oct
(139) |
Nov
(11) |
Dec
(5) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(34) |
Feb
(1) |
Mar
(12) |
Apr
|
May
(87) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(27) |
Nov
(49) |
Dec
(13) |
2006 |
Jan
|
Feb
|
Mar
|
Apr
(252) |
May
(16) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
(2) |
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(3) |
Oct
|
Nov
(1) |
Dec
|
2009 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
(1) |
Jun
(2) |
Jul
(15) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2010 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
(6) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
(1) |
Nov
|
Dec
|
From: Greg H. <gh...@us...> - 2004-03-31 20:13:55
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/jre15/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22460/src/org/mc4j/jre15/components Added Files: ThreadMBeanThreadBrowserComponent.java Log Message: This component supports browsing Thread information from the jre15 ThreadMBean. --- NEW FILE: ThreadMBeanThreadBrowserComponent.java --- /* * Author: Greg Hinkle * * The contents of this file are subject to the Sapient Public License Version 1.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy of the * License at http://mc4j.sf.net/License-SPL.html. * * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, * either express or implied. See the License for the specific language governing rights and limitations * under the License. * * The Original Code is The MC4J Management Console * The Initial Developer of the Original Code is Greg Hinkle (gh...@us...) * Copyright (C) 2004 Greg Hinkle. All Rights Reserved. * * Redistributions of code or binary files using or based on this code must reproduce the * above copyright and disclaimer. For more information see <http://mc4j.sourceforge.net>. */ package org.mc4j.jre15.components; import java.awt.BorderLayout; import java.awt.Component; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; import java.lang.management.ThreadMBean; import java.lang.management.ThreadState; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; import javax.management.MBeanServer; import javax.management.MBeanServerInvocationHandler; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; import org.openide.ErrorManager; import org.mc4j.carbon.config.tree.ConfigurationTreeComponent; import org.mc4j.console.Refreshable; import org.mc4j.console.dashboard.Dashboard; import org.mc4j.console.dashboard.DashboardComponent; /** * This component supports viewing JVM thread information in a tree structure. It shows the thread * name, id and status as well as the current thread stack elements. * * @author Greg Hinkle (gh...@us...), Mar 31, 2004 * @version $Revision: 1.1 $($Author: ghinkl $ / $Date: 2004/03/31 20:02:04 $) */ public class ThreadMBeanThreadBrowserComponent extends JPanel implements DashboardComponent, Refreshable { protected ThreadMBean threadMBean; protected JTree threadTree; protected DefaultTreeModel treeModel; protected DefaultMutableTreeNode root; protected Map threadMap; public ThreadMBeanThreadBrowserComponent() { init(); threadMap = new HashMap(); } public void init() { setLayout(new BorderLayout()); threadTree = new JTree(); root = new DefaultMutableTreeNode("Threads"); treeModel = new DefaultTreeModel(root); threadTree.setRootVisible(false); threadTree.setModel(treeModel); threadTree.setCellRenderer(new ThreadTreeCellRenderer()); JScrollPane scrollpane = new JScrollPane(threadTree); add(scrollpane, BorderLayout.CENTER); } public void setContext(Map context) { MBeanServer mBeanServer = (MBeanServer) context.get(Dashboard.CONTEXT_MBEAN_SERVER); try { this.threadMBean = (ThreadMBean) MBeanServerInvocationHandler.newProxyInstance( mBeanServer, new ObjectName(ManagementFactory.THREAD_MBEAN_NAME), ThreadMBean.class, false); } catch (MalformedObjectNameException moe) { ErrorManager.getDefault().notify(moe); } refresh(); this.treeModel.nodeStructureChanged(root); } public void refresh() { try { // TODO GH: the added set is not being used and right now i'm firing // update events for each insertion or removal. this is probably much // slower than firing a single event with all of the changes. Set deadThreadSet = new HashSet(threadMap.values()); Set addedSet = new HashSet(); long[] threadIds = this.threadMBean.getAllThreadIds(); Arrays.sort(threadIds); ThreadInfo[] threadInfos = this.threadMBean.getThreadInfo(threadIds,Integer.MAX_VALUE); for (int i = 0; i < threadInfos.length; i++) { ThreadInfo threadInfo = threadInfos[i]; DefaultMutableTreeNode threadNode = null; threadNode = (DefaultMutableTreeNode) threadMap.get(new Long(threadInfo.getThreadId())); if (threadNode == null) { threadNode = new DefaultMutableTreeNode(threadInfo); root.add(threadNode); threadMap.put(new Long(threadInfo.getThreadId()),threadNode); addedSet.add(threadNode); this.treeModel.nodesWereInserted(root, new int[] { root.getChildCount() - 1 }); } else { threadNode.setUserObject(threadInfo); threadNode.removeAllChildren(); deadThreadSet.remove(threadNode); } StackTraceElement[] stackElements = threadInfo.getStackTrace(); for (int j = 0; j < stackElements.length; j++) { StackTraceElement stackElement = stackElements[j]; DefaultMutableTreeNode stackNode = new DefaultMutableTreeNode(stackElement); threadNode.add(stackNode); } this.treeModel.nodeStructureChanged(threadNode); } // Remove any threads we didn't remove from the dead thread set... and which are therefore now dead for (Iterator iterator = deadThreadSet.iterator(); iterator.hasNext();) { DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) iterator.next(); int index = root.getIndex(defaultMutableTreeNode); root.remove(defaultMutableTreeNode); this.treeModel.nodesWereRemoved(root, new int[] { index }, new Object[] { defaultMutableTreeNode }); threadMap.remove(new Long(((ThreadInfo)defaultMutableTreeNode.getUserObject()).getThreadId())); } // Fire insertions /* int[] childChanges = new int[addedSet.size()]; int i = 0; for (Iterator iterator = addedSet.iterator(); iterator.hasNext();) { DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) iterator.next(); childChanges[i++] = root.getIndex(defaultMutableTreeNode); } this.treeModel.nodesWereInserted(root, childChanges); */ //this.treeModel.nodeStructureChanged(root); this.threadTree.repaint(); } catch(Exception e) { ErrorManager.getDefault().notify(e); } } /** * Shows the status of a thread in the tree node icon. */ public static class ThreadTreeCellRenderer extends DefaultTreeCellRenderer { public ThreadTreeCellRenderer() { setOpenIcon(threadIcon); setClosedIcon(threadIcon); setLeafIcon(stackElementIcon); } public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { Object userObject = ((DefaultMutableTreeNode)value).getUserObject(); boolean isThread = false; String description = null; Icon icon = null; if (userObject instanceof ThreadInfo) { ThreadInfo threadInfo = (ThreadInfo) userObject; description = threadInfo.getThreadId() + " - " + threadInfo.getThreadName() + " (" + threadInfo.getThreadState() + ")"; isThread = true; if (threadInfo.getThreadState().equals(ThreadState.RUNNABLE) || threadInfo.getThreadState().equals(ThreadState.RUNNABLE_IN_NATIVE)) { icon = threadRunningIcon; } else if (threadInfo.getThreadState().equals(ThreadState.WAITING) || threadInfo.getThreadState().equals(ThreadState.WAITING_IO)) { icon = threadWaitingIcon; } else if (threadInfo.getThreadState().equals(ThreadState.BLOCKED)) { icon = threadBlockedIcon; } else if (threadInfo.getThreadState().equals(ThreadState.TERMINATED)) { icon = threadTerminatedIcon; } else { icon = threadIcon; } } else if (userObject instanceof StackTraceElement) { description = userObject.toString(); isThread = false; icon = stackElementIcon; } Component component = super.getTreeCellRendererComponent(tree, description, sel, expanded, !isThread, row, hasFocus); setIcon(icon); return component; } private static Icon threadIcon = createImageIcon("images/Thread.gif"); private static Icon threadRunningIcon = createImageIcon("images/ThreadRunning.gif"); private static Icon threadWaitingIcon = createImageIcon("images/ThreadWaiting.gif"); private static Icon threadBlockedIcon = createImageIcon("images/ThreadBlocked.gif"); private static Icon threadTerminatedIcon = createImageIcon("images/ThreadTerminated.gif"); private static Icon stackElementIcon = createImageIcon("images/StackElement.gif"); /** Returns an ImageIcon, or null if the path was invalid. */ protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = ConfigurationTreeComponent.class.getClassLoader().getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { System.err.println("Couldn't find file: " + path); return null; } } } } |
From: Greg H. <gh...@us...> - 2004-03-31 04:10:57
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/swing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31735/src/org/mc4j/console/swing Modified Files: SwingUtility.java Log Message: Added a starter message to describe the output. Index: SwingUtility.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/swing/SwingUtility.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SwingUtility.java 21 Mar 2004 21:48:02 -0000 1.1 --- SwingUtility.java 31 Mar 2004 03:59:12 -0000 1.2 *************** *** 41,44 **** --- 41,52 ---- StackTraceElement element = elements[i]; if (element.getClassName().startsWith("org.mc4j")) { + + if (alertedSet.isEmpty()) { + IOProvider.getDefault().getIO("MC4J Errors",false).getOut().println( + "This panel lists places within MC4J where calls are being made " + + "to a server from within the AWT Event Thread. These calls are " + + "not safe because long duration calls may cause the application to " + + "be unresponsive."); + } if (!alertedSet.contains(element)) { alertedSet.add(element); |
From: Greg H. <gh...@us...> - 2004-03-31 04:09:50
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/swing/graph In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31541/src/org/mc4j/console/swing/graph Modified Files: AbstractGraphPanel.java Log Message: Tweaked background and corrected NPE possibility in some usages. Index: AbstractGraphPanel.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/swing/graph/AbstractGraphPanel.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AbstractGraphPanel.java 3 Mar 2004 23:32:50 -0000 1.3 --- AbstractGraphPanel.java 31 Mar 2004 03:58:06 -0000 1.4 *************** *** 178,181 **** --- 178,182 ---- JPanel northPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); northPanel.add(this.controlsButton); + northPanel.setOpaque(false); add(northPanel,BorderLayout.NORTH); this.controlsPanel.setLocation(5,5); *************** *** 207,210 **** --- 208,212 ---- public ControlsPopupButton() { setIcon(descendingIcon); + setOpaque(false); init(); } *************** *** 229,232 **** --- 231,241 ---- + public long getUpdateDelay() { + if (sleepSlider != null) + return sleepSlider.getValue(); + else + return 1000L; + } + /** * Cancels any existing scheduled task and reschedules for the *************** *** 244,249 **** this.dataGeneratorTimer.schedule( this.dataGeneratorTimerTask = getDataGeneratorTask(), ! sleepSlider.getValue(), ! sleepSlider.getValue()); } --- 253,258 ---- this.dataGeneratorTimer.schedule( this.dataGeneratorTimerTask = getDataGeneratorTask(), ! getUpdateDelay(), ! getUpdateDelay()); } *************** *** 274,278 **** public void removeNotify() { super.removeNotify(); ! this.dataGeneratorTimer.cancel(); this.dataGeneratorTimer = null; this.removed = true; --- 283,288 ---- public void removeNotify() { super.removeNotify(); ! if (this.dataGeneratorTimer != null) ! this.dataGeneratorTimer.cancel(); this.dataGeneratorTimer = null; this.removed = true; |
From: Greg H. <gh...@us...> - 2004-03-31 03:40:47
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/swing/editor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26892/src/org/mc4j/console/swing/editor Modified Files: DateEditor.java Added Files: CalendarComboBox.java Log Message: A new calendar popup component and associated editor. This component is much cleaner and smaller than previous attempts and was originally written by Jane Graiscti and is available in the public domain. --- NEW FILE: CalendarComboBox.java --- package org.mc4j.console.swing.editor; /* *************************************************************************** * * File: CalendarWidget.java * Package: ca.janeg.calendar * * Contains: ButtonActionListener * CalendarModel * CalendarSelectionListener * InputListener * * References: 'Java Rules' by Douglas Dunn * Addison-Wesley, 2002 (Chapter 5, section 13 - 19) * * 'Professional Java Custom UI Components' * by Kenneth F. Krutsch, David S. Cargo, Virginia Howlett * WROX Press, 2001 (Chapter 1-3) * * Date Author Changes * ------------ ------------- ---------------------------------------------- * Oct 24, 2002 Jane Griscti Created * Oct 27, 2002 jg Cleaned up calendar display * Oct 30, 2002 jg added ctor CalendarComboBox( Calendar ) * Oct 31, 2002 jg Added listeners and Popup * Nov 1, 2002 jg Cleaned up InputListener code to only accept * valid dates * Nov 2, 2002 jg modified getPopup() to handle display when * component is positioned at the bottom of the screen * Nov 3, 2002 jg changed some instance variables to class variables * Mar 29, 2003 jg added setDate() contributed by James Waldrop * *************************************************************************** */ import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Font; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.text.DateFormat; import java.text.DateFormatSymbols; import java.text.ParseException; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JFormattedTextField; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.ListSelectionModel; import javax.swing.SwingConstants; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.plaf.basic.BasicArrowButton; import javax.swing.table.DefaultTableModel; import javax.swing.table.JTableHeader; import javax.swing.table.TableColumn; /** * A custom component that mimics a combo box, displaying * a perpetual calendar rather than a 'list'. * * @author Jane Griscti ja...@ja... * @version 1.0 Oct 24, 2002 */ public class CalendarComboBox extends JPanel { // -- class fields private static final DateFormatSymbols dfs = new DateFormatSymbols(); private static final String[] months = dfs.getMonths(); private static final String[] dayNames = new String[7]; // -- instance fields used with 'combo-box' panel private final JPanel inputPanel = new JPanel(); private final JFormattedTextField input = new JFormattedTextField(new Date()); private final BasicArrowButton comboBtn = new BasicArrowButton(SwingConstants.SOUTH); // -- instance fields used with calendar panel protected final JPanel calPanel = new JPanel(); private final JTextField calLabel = new JTextField(11); private final Calendar current = new GregorianCalendar(); private final CalendarModel display = new CalendarModel(6, 6); private final JTable table = new JTable(display); private final BasicArrowButton nextBtn = new BasicArrowButton(SwingConstants.EAST); private final BasicArrowButton prevBtn = new BasicArrowButton(SwingConstants.WEST); private final BasicArrowButton closeCalendarBtn = new BasicArrowButton(SwingConstants.NORTH); private JPopupMenu popup; /** * Create a new calendar combo-box object set with today's date. */ public CalendarComboBox() { this(new GregorianCalendar(), false); } /** * Create a new calendar component, defining if the component should use * the entire panel or just what would normally be an appropriate size. * When enclosing this Component in a table or some other externally sized * Container, use fillComponent of true. * * @param fillComponent true if the input box should take the entire area * of this compoennt, false otherwise */ public CalendarComboBox(boolean fillComponent) { this(new GregorianCalendar(), fillComponent); } /** * Create a new calendar combo-box object set with the given date. * * @param cal a calendar object * @see java.util.GregorianCalendar */ public CalendarComboBox(final Calendar cal, boolean fillComponent) { super(); // set the calendar and input box date Date date = cal.getTime(); current.setTime(date); input.setValue(date); // create the GUI elements and assign listeners buildInputPanel(); // intially, only display the input panel if (fillComponent) { setLayout(new BorderLayout()); add(inputPanel, BorderLayout.CENTER); } else { add(inputPanel); } buildCalendarDisplay(); registerListeners(); } /* * Creates a field and 'combo box' button above the calendar * to allow user input. */ private void buildInputPanel() { inputPanel.setLayout(new BoxLayout(inputPanel, BoxLayout.X_AXIS)); input.setColumns(12); inputPanel.add(input); comboBtn.setActionCommand("combo"); inputPanel.add(comboBtn); } /* * Builds the calendar panel to be displayed in the popup */ private void buildCalendarDisplay() { // Allow for individual cell selection and turn off // grid lines. table.setCellSelectionEnabled(true); table.getTableHeader().setResizingAllowed(false); table.getTableHeader().setReorderingAllowed(false); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setShowGrid(false); // Calendar (table) column headers // Set column headers to weekday names as given by // the default Locale. // // Need to re-map the retreived names. If used as is, // the table model ends up with an extra empty column as // the returned names begin at index 1, not zero. String[] names = dfs.getShortWeekdays(); for (int i = 1; i < names.length; i++) { dayNames[i - 1] = "" + names[i].charAt(0); } display.setColumnIdentifiers(dayNames); table.setModel(display); // Set the column widths. Need to turn // auto resizing off to make this work. table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); int count = table.getColumnCount(); for (int i = 0; i < count; i++) { TableColumn col = table.getColumnModel().getColumn(i); col.setPreferredWidth(20); } // Column headers are only displayed automatically // if the table is put in a JScrollPane. Don't want // to use one here, so need to add the headers // manually. JTableHeader header = table.getTableHeader(); header.setFont(header.getFont().deriveFont(Font.BOLD)); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(header); panel.add(table); //calPanel.setBorder( new LineBorder( Color.BLACK ) ); calPanel.setLayout(new BorderLayout()); calPanel.add(buildCalendarNavigationPanel(), BorderLayout.NORTH); calPanel.add(panel); } /* * Creates a small panel above the month table to display the month and * year along with the 'prevBtn', 'nextBtn' month selection buttons * and a 'closeCalendarBtn'. */ private JPanel buildCalendarNavigationPanel() { JPanel panel = new JPanel() { }; //panel.setLayout( new BoxLayout( panel, BoxLayout.X_AXIS ) ); panel.setLayout(new BorderLayout()); // Add a text display of the selected month and year. // A JTextField is used for the label instead of a JLabel // as it is easier to ensure a consistent size; JLabel // expands and contracts with the text size calLabel.setEditable(false); calLabel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); int fontSize = calLabel.getFont().getSize(); calLabel.setFont(calLabel.getFont().deriveFont(Font.PLAIN, fontSize - 1)); panel.add(calLabel, BorderLayout.CENTER); // set button commands and add to panel prevBtn.setActionCommand("prevBtn"); nextBtn.setActionCommand("nextBtn"); closeCalendarBtn.setActionCommand("close"); panel.add(prevBtn, BorderLayout.WEST); panel.add(nextBtn, BorderLayout.EAST); //panel.add( closeCalendarBtn ); return panel; } /* * Register all required listeners with appropriate * components */ private void registerListeners() { ButtonActionListener btnListener = new ButtonActionListener(); // 'Combo-box' listeners input.addKeyListener(new InputListener()); comboBtn.addActionListener(btnListener); // Calendar (table) selection listener // Must be added to both the table selection model // and the column selection model; otherwise, new // column selections on the same row are not recognized CalendarSelectionListener listener = new CalendarSelectionListener(); table.getSelectionModel().addListSelectionListener(listener); table.getColumnModel().getSelectionModel() .addListSelectionListener(listener); // Calendar navigation listeners prevBtn.addActionListener(btnListener); nextBtn.addActionListener(btnListener); closeCalendarBtn.addActionListener(btnListener); } /* * Fill the table model with the days in the selected month. * Rows in the table correspond to 'weeks', columns to 'days'. * * Strategy: * 1. get the first calendar day in the new month * 2. find it's position in the first week of the month to * determine the starting column for the day numbers * 3. find the actual number of days in the month * 4. fill the calendar with the day values, erasing any days * left over from the old month */ private void updateTable(Calendar cal) { Calendar dayOne = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), 1); // compute the number of days in the month and // the start column for the first day in the first week int actualDays = cal.getActualMaximum(Calendar.DATE); int startIndex = dayOne.get(Calendar.DAY_OF_WEEK) - 1; // fill the calendar for the new month int day = 1; for (int row = 0; row < 6; row++) { for (int col = 0; col < 7; col++) { if ((col < startIndex && row == 0) || day > actualDays) { // overwrite any left over values from old month display.setValueAt("", row, col); } else { display.setValueAt(new Integer(day), row, col); day++; } } } // set the month, year label calLabel.setText(months[cal.get(Calendar.MONTH)] + ", " + cal.get(Calendar.YEAR)); // set the calendar selection table.changeSelection(cal.get(Calendar.WEEK_OF_MONTH) - 1, cal.get(Calendar.DAY_OF_WEEK) - 1, false, false); } /* * Gets a Popup to hold the calendar display and determines * it's position on the screen. */ private JPopupMenu getPopup() { Point p = input.getLocationOnScreen(); Dimension inputSize = input.getPreferredSize(); Dimension calendarSize = calPanel.getPreferredSize(); /* if( ( p.y + calendarSize.height ) < screenSize.height) { // will fit below input panel popup = factory.getPopup( input, calPanel, p.x, p.y + (int)inputSize.height ); } else { // need to fit it above input panel popup = factory.getPopup( input, calPanel, p.x, p.y - (int)calendarSize.height ); } */ // Greg Hinkle: Use JPopupMenu as it can automatically close when // there is an outside click or it loses focus. JPopupMenu menu = new JPopupMenu(); menu.add(calPanel); return menu; } /* * Returns the currently selected date as a <code>Calendar</code> object. * * @return Calendar the currently selected calendar date */ public Calendar getDate() { return current; } /** * Sets the current date and updates the UI to reflect the new date. * * @param newDate the new date as a <code>Date</code> object. * @author James Waldrop * @see Date */ public void setDate(Date newDate) { current.setTime(newDate); input.setValue(current.getTime()); } /* * Creates a custom model to back the table. */ private class CalendarModel extends DefaultTableModel { public CalendarModel(int row, int col) { super(row, col); } /** * Overrides the method to return an Integer class * type for all columns. The numbers are automatically * right-aligned by a default renderer that's supplied * as part of JTable. */ public Class getColumnClass(int column) { return Integer.class; } /** * Overrides the method to disable cell editing. * The default is editable. */ public boolean isCellEditable(int row, int col) { return false; } } /* * Captures the 'prevBtn', 'nextBtn', 'comboBtn' and * 'closeCalendarBtn' actions. * * The combo button is disabled when the popup is shown * and enabled when the popup is hidden. Failure to do * so results in the popup screen area not being cleared * correctly if the user clicks the button while the popup * is being displayed. */ private class ButtonActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("prevBtn")) { current.add(Calendar.MONTH, -1); input.setValue(current.getTime()); } else if (cmd.equals("nextBtn")) { current.add(Calendar.MONTH, 1); input.setValue(current.getTime()); } else if (cmd.equals("close")) { popup.hide(); comboBtn.setEnabled(true); } else { //comboBtn.setEnabled( false ); popup = getPopup(); calPanel.setPreferredSize(new Dimension((int) inputPanel.getPreferredSize().getWidth(), (int) calPanel.getPreferredSize().getHeight())); popup.show(inputPanel, 0, inputPanel.getHeight()); } updateTable(current); } } /* * Captures a user selection in the calendar display and * changes the value in the 'combo box' to match the selected date. * */ private class CalendarSelectionListener implements ListSelectionListener { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int row = table.getSelectedRow(); int col = table.getSelectedColumn(); Object value = null; try { value = display.getValueAt(row, col); } catch (ArrayIndexOutOfBoundsException ex) { // ignore, happens when the calendar is // displayed for the first time } if (value instanceof Integer) { int day = ((Integer) value).intValue(); current.set(Calendar.DATE, day); input.setValue(current.getTime()); } } } } /* * Captures user input in the 'combo box' * If the input is a valid date and the user pressed * ENTER or TAB, the calendar selection is updated */ private class InputListener extends KeyAdapter { public void keyTyped(KeyEvent e) { DateFormat df = DateFormat.getDateInstance(); Date date = null; try { date = df.parse(input.getText()); } catch (ParseException ex) { // ignore invalid dates } // change the calendar selection if the date is valid // and the user hit ENTER or TAB char c = e.getKeyChar(); if (date != null && (c == KeyEvent.VK_ENTER || c == KeyEvent.VK_TAB)) { current.setTime(date); updateTable(current); } } } public static void main(String[] args) { JFrame frame = new JFrame("Calendar combo box test"); frame.getContentPane().add(new CalendarComboBox()); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } } Index: DateEditor.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/swing/editor/DateEditor.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DateEditor.java 7 Feb 2004 16:10:41 -0000 1.4 --- DateEditor.java 31 Mar 2004 03:29:03 -0000 1.5 *************** *** 20,34 **** package org.mc4j.console.swing.editor; ! import java.awt.Frame; import java.beans.PropertyEditor; - import java.text.ParseException; - import java.text.SimpleDateFormat; - import java.util.Calendar; import java.util.Date; - import java.util.GregorianCalendar; ! import javax.swing.table.DefaultTableModel; ! import org.mc4j.console.util.ExceptionUtility; /** --- 20,42 ---- package org.mc4j.console.swing.editor; ! import java.awt.Component; ! import java.awt.Graphics; ! import java.awt.Insets; ! import java.awt.Point; ! import java.awt.event.ActionListener; ! import java.awt.event.FocusEvent; ! import java.awt.event.FocusListener; ! import java.awt.event.InputEvent; ! import java.awt.event.KeyEvent; import java.beans.PropertyEditor; import java.util.Date; ! import javax.swing.JComponent; ! import javax.swing.KeyStroke; ! import javax.swing.SwingUtilities; ! import org.openide.explorer.propertysheet.InplaceEditor; ! import org.openide.explorer.propertysheet.PropertyEnv; ! import org.openide.explorer.propertysheet.PropertyModel; /** *************** *** 37,176 **** * @version $Revision$($Author$ / $Date$) */ ! public class DateEditor extends javax.swing.JPanel ! implements PropertyEditor { private Date currentDate; ! ! private Date viewDate = new Date(); ! ! private static SimpleDateFormat dateFormat = ! (SimpleDateFormat) ! SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.LONG,SimpleDateFormat.SHORT); ! ! /** Creates new form DateEditor */ public DateEditor() { ! initComponents(); } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - private void initComponents() {//GEN-BEGIN:initComponents - java.awt.GridBagConstraints gridBagConstraints; ! jComboBox1 = new javax.swing.JComboBox(); ! jComboBox2 = new javax.swing.JComboBox(); ! todayButton = new javax.swing.JButton(); ! jTable1 = new javax.swing.JTable(); ! setLayout(new java.awt.GridBagLayout()); ! jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" })); ! add(jComboBox1, new java.awt.GridBagConstraints()); ! add(jComboBox2, new java.awt.GridBagConstraints()); ! todayButton.setText("Today"); ! add(todayButton, new java.awt.GridBagConstraints()); - jTable1.setModel(getCurrentMonthTableModel()); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 1; - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - add(jTable1, gridBagConstraints); - }//GEN-END:initComponents ! public String getAsText() { ! return this.dateFormat.format(this.currentDate); ! } ! ! public java.awt.Component getCustomEditor() { ! return this; ! } ! ! public String getJavaInitializationString() { ! return "bah"; } ! ! public String[] getTags() { ! return null; } ! public Object getValue() { ! return this.currentDate; } ! ! public boolean isPaintable() { ! return true; } ! ! public void paintValue(java.awt.Graphics graphics, java.awt.Rectangle rectangle) { } ! ! public void setAsText(String str) throws java.lang.IllegalArgumentException { try { ! this.dateFormat.parse(str); ! } catch (ParseException pe) { ! throw new IllegalArgumentException("Failure to parse date: " + ! ExceptionUtility.printStackTracesToString(pe)); } } ! ! public void setValue(Object obj) { ! this.currentDate = (Date) obj; ! this.viewDate = this.currentDate; } ! ! public boolean supportsCustomEditor() { return true; } ! ! // Variables declaration - do not modify//GEN-BEGIN:variables ! private javax.swing.JButton todayButton; ! private javax.swing.JComboBox jComboBox2; ! private javax.swing.JComboBox jComboBox1; ! private javax.swing.JTable jTable1; ! // End of variables declaration//GEN-END:variables ! ! public static void main(String[] args) { ! ! DateEditor editor = new DateEditor(); ! editor.setValue(new Date()); ! Frame frame = new Frame("Date test"); ! frame.add(editor); ! frame.validate(); ! frame.pack(); ! frame.show(); ! ! } ! ! private DefaultTableModel getCurrentMonthTableModel() { ! String[] columnNames = ! new String[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; ! ! String[][] data = new String[6][7]; ! ! Calendar cal = GregorianCalendar.getInstance(); ! cal.setTime(this.viewDate); ! ! Calendar firstDay = (Calendar)cal.clone(); ! firstDay.set(Calendar.DAY_OF_MONTH, 1); ! ! int currentMonth = firstDay.get(Calendar.MONTH); ! while (currentMonth == firstDay.get(Calendar.MONTH)) { ! int dm = firstDay.get(Calendar.DAY_OF_MONTH); ! int dw = firstDay.get(Calendar.DAY_OF_WEEK); ! ! data[((dm-(dw)+7) / 7)][dw-1] = String.valueOf(dm); ! firstDay.add(Calendar.DAY_OF_YEAR, 1); } - - DefaultTableModel model = new DefaultTableModel(data, columnNames); - return model; } } --- 45,542 ---- * @version $Revision$($Author$ / $Date$) */ ! public class DateEditor extends CalendarComboBox implements InplaceEditor { private Date currentDate; ! ! ! ! protected PropertyEditor editor; ! protected PropertyEnv env; ! protected PropertyModel mdl; ! boolean inSetUI=false; ! private boolean tableUI; ! private boolean connecting=false; ! private boolean hasBeenEditable=false; ! private boolean needLayout=false; ! ! /*Keystrokes this inplace editor wants to consume */ ! static final KeyStroke[] cbKeyStrokes = ! new KeyStroke[] {KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,0,false), ! KeyStroke.getKeyStroke(KeyEvent.VK_UP,0,false), ! KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,0,true), ! KeyStroke.getKeyStroke(KeyEvent.VK_UP,0,true), ! KeyStroke.getKeyStroke (KeyEvent.VK_PAGE_DOWN,0,false), ! KeyStroke.getKeyStroke (KeyEvent.VK_PAGE_UP,0,false), ! KeyStroke.getKeyStroke (KeyEvent.VK_PAGE_DOWN,0,true), ! KeyStroke.getKeyStroke (KeyEvent.VK_PAGE_UP,0,true) ! }; ! ! /** Create a ComboInplaceEditor - the tableUI flag will tell it to use ! * less borders & such */ public DateEditor() { ! super(true); } ! public void addActionListener(ActionListener al) { ! //To change body of implemented methods use File | Settings | File Templates. ! } ! public void removeActionListener(ActionListener al) { ! //To change body of implemented methods use File | Settings | File Templates. ! } ! /** Overridden to add a listener to the editor if necessary, since the ! * UI won't do that for us without a focus listener */ ! public void addNotify() { ! super.addNotify(); ! // TODO GH: Probably important ! //getEditor().getEditorComponent().addFocusListener(this); ! getLayout().layoutContainer(this); ! } ! /** Overridden to hide the popup and remove any listeners from the ! * combo editor */ ! public void removeNotify() { ! log ("Combo editor for " + editor + " removeNotify forcing popup close"); ! setVisible(false); ! super.removeNotify(); ! //getEditor().getEditorComponent().removeFocusListener(this); } ! ! ! public Insets getInsets() { ! return new Insets(0,0,0,0); } ! ! public Point getLocation(Point rv) { ! return new Point(0,0); ! } ! ! ! public void clear() { ! editor = null; ! env = null; ! } ! ! public void connect(PropertyEditor pe, PropertyEnv env) { ! connecting = true; ! try { ! log ("Combo editor connect to " + pe + " env=" + env); ! ! this.env = env; ! this.editor = pe; ! //setModel(new DefaultComboBoxModel(pe.getTags())); ! /* ! boolean editable = (editor instanceof EnhancedPropertyEditor) ? ! ((EnhancedPropertyEditor) editor).supportsEditingTaggedValues() : ! env != null && ! Boolean.TRUE.equals( ! env.getFeatureDescriptor().getValue("canEditAsText")); //NOI18N ! */ ! //setEditable (editable); ! //setActionCommand(COMMAND_SUCCESS); ! reset(); ! ! } finally { ! connecting = false; ! } ! } ! ! private void log (String s) { ! //if (PropUtils.isLoggable(ComboInplaceEditor.class) && getClass() == ComboInplaceEditor.class) { ! // PropUtils.log (ComboInplaceEditor.class, s); //NOI18N ! //} ! } ! ! public void setSelectedItem(Object o) { ! //Some property editors (i.e. IMT's choice editor) treat ! //null as 0. Probably not the right way to do it, but needs to ! //be handled. ! if (o == null) { ! o = editor.getTags()[0]; ! } ! //super.setSelectedItem(o); ! } ! ! /** Overridden to not fire changes is an event is called inside the ! * connect method */ ! public void fireActionEvent() { ! if (connecting || editor == null) { ! return; ! } else { ! /* ! if ("comboBoxEdited".equals(getActionCommand())) { ! log ("Translating comboBoxEdited action command to COMMAND_SUCCESS"); ! setActionCommand(COMMAND_SUCCESS); ! } ! log ("Combo editor firing ActionPerformed command=" + getActionCommand()); ! super.fireActionEvent(); ! */ ! } ! } ! ! public void reset() { ! log ("Combo editor reset setting selected item to " + editor.getAsText()); ! String targetValue = editor.getAsText(); ! ! //issue 26367, form editor needs ability to set a custom value ! //when editing is initiated (event handler combos, part of them ! //cleaning up their EnhancedPropertyEditors). ! /* if (getClass() == ComboInplaceEditor.class && env != null && ! env.getFeatureDescriptor() != null) { ! ! String initialEditValue = (String) env.getFeatureDescriptor(). ! getValue("initialEditValue"); //NOI18N ! ! if (initialEditValue != null) { ! targetValue = initialEditValue; ! } ! ! } ! */ ! setSelectedItem(targetValue); ! } ! public Object getValue() { ! /* ! if (isEditable()) { ! return getEditor().getItem(); ! } else { ! return getSelectedItem(); ! } ! */ ! ! return super.getDate(); } ! ! public PropertyEditor getPropertyEditor() { ! return editor; } ! ! public PropertyModel getPropertyModel() { ! return mdl; } ! ! public void setPropertyModel(PropertyModel pm) { ! log ("Combo editor set property model to " + pm); ! this.mdl=pm; ! } ! ! public JComponent getComponent() { ! return this; ! } ! ! public KeyStroke[] getKeyStrokes() { ! return cbKeyStrokes; ! } ! ! public void handleInitialInputEvent(InputEvent e) { ! //do nothing, this should get deprecated in InplaceEditor ! } ! ! ! ! ! ! /** Overridden to set a flag used to block the UI from adding a focus ! * listener, and to use an alternate renderer class on GTK look and feel ! * to work around a painting bug in SynthComboUI (colors not set correctly)*/ ! /* ! public void setUI(ComboBoxUI ui) { ! inSetUI=true; try { ! super.setUI(ui); ! } finally { ! inSetUI=false; ! } ! //Workaround for GTK look and feel - combo boxes ignore background ! //color in 1.4.2 ! //XXX update this code if fixed in JDK 1.5 ! if ( ! ui.getClass().getName().equals( ! "com.sun.java.swing.plaf.gtk.SynthComboBoxUI")) { //NOI18N ! setRenderer (new Renderer()); } } ! */ ! ! /** Overridden to handle a corner case - an NPE if the UI tries to display ! * the popup, but the combo box is removed from the parent before that can ! * happen - only happens on very rapid clicks between popups */ ! /* ! public void showPopup() { ! ! try { ! log (" Combo editor show popup"); ! super.showPopup(); ! } catch (NullPointerException e) { ! //An inevitable consequence - the look and feel will queue display ! //of the popup, but it can be processed after the combo box is ! //offscreen ! log (" Combo editor show popup later due to npe"); ! ! SwingUtilities.invokeLater(new Runnable() { ! public void run() { ! ComboInplaceEditor.super.showPopup(); ! } ! }); ! } } ! */ ! ! /* ! private void prepareEditor() { ! Component c = getEditor().getEditorComponent(); ! if (c instanceof JTextComponent) { ! JTextComponent jtc = (JTextComponent) c; ! String s = jtc.getText(); ! if (s != null && s.length() > 0){ ! jtc.setSelectionStart(0); ! jtc.setSelectionEnd(s.length()); ! } ! if (tableUI) { ! jtc.setBackground(getBackground()); ! } else { ! jtc.setBackground(PropUtils.getTextFieldBackground()); ! } ! } ! if (getLayout() != null) { ! getLayout().layoutContainer(this); ! } ! c.requestFocus(); ! repaint(); ! }*/ ! ! /** Overridden to do the focus-popup handling that would normally be done ! * by the look and feel */ ! /* ! public void processFocusEvent(FocusEvent fe) { ! super.processFocusEvent(fe); ! Component focusOwner = KeyboardFocusManager. ! getCurrentKeyboardFocusManager().getFocusOwner(); ! ! if (isDisplayable() && fe.getID()==fe.FOCUS_GAINED && focusOwner==this ! && !isPopupVisible()) { ! if (isEditable()) { ! prepareEditor(); ! // showPopup(); ! } else { ! if (tableUI) { ! showPopup(); ! //Try to beat the event mis-ordering at its own game ! SwingUtilities.invokeLater(new PopupChecker()); ! } ! } ! repaint(); ! } else if (fe.getID() == fe.FOCUS_LOST && isPopupVisible() && !isDisplayable()) { ! if (!PropUtils.psCommitOnFocusLoss) { ! setActionCommand(COMMAND_FAILURE); ! fireActionEvent(); ! } ! //We were removed, but we may be immediately added. See if that's the ! //case after other queued events run ! SwingUtilities.invokeLater(new Runnable() { ! public void run() { ! if (!isDisplayable()) { ! hidePopup(); ! } ! } ! }); ! } ! repaint(); ! } ! */ ! ! public boolean isKnownComponent(Component c) { ! return (c == super.calPanel); ! } ! ! public void setValue(Object o) { ! super.setDate((Date) o); ! } ! ! /** Returns true if the combo box is editable */ ! public boolean supportsTextEntry() { return true; } ! ! /** Overridden to install an ancestor listener which will ensure the ! * popup is always opened correctly */ ! protected void installAncestorListener() { ! //Use a replacement which will check to ensure the popup is ! //displayed ! ! //addAncestorListener(this); ! } ! ! /** Overridden to block the UI from adding its own focus listener, which ! * will close the popup at the wrong times. We will manage focus ! * ourselves instead */ ! public void addFocusListener(FocusListener fl) { ! if (!inSetUI || !tableUI) { ! super.addFocusListener(fl); ! } ! } ! ! public void focusGained(FocusEvent e) { ! //do nothing ! } ! ! /** If the editor loses focus, we're done editing - fire COMMAND_FAILURE */ ! public void focusLost(FocusEvent e) { ! /* ! Component c = e.getOppositeComponent(); ! if (!isAncestorOf(c) && c != getEditor().getEditorComponent()) { ! if (c == this || (c instanceof SheetTable && ! ((SheetTable)c).isAncestorOf(this))) { ! //workaround for issue 38029 - editable combo editor can lose focus to ...itself ! return; ! } ! setActionCommand(COMMAND_FAILURE); ! log (" Combo editor lost focus - setting action command to " + COMMAND_FAILURE); ! getEditor().getEditorComponent().removeFocusListener(this); ! if (checker == null) { ! log ("No active popup checker, firing action event"); ! fireActionEvent(); ! } ! } ! */ ! } ! ! /** Overridden to ensure the editor gets focus if editable */ ! public void firePopupMenuCanceled() { ! /* ! super.firePopupMenuCanceled(); ! if (isEditable()) { ! Component focus = KeyboardFocusManager. ! getCurrentKeyboardFocusManager().getFocusOwner(); ! if (isDisplayable() && focus == this) { ! log ("combo editor popup menu canceled. Requesting focus on editor component"); ! getEditor().getEditorComponent().requestFocus(); ! } ! } ! */ ! } ! ! /** Overridden to fire COMMAND_FAILURE on Escape */ ! public void processKeyEvent(KeyEvent ke) { ! /* ! super.processKeyEvent(ke); ! if (ke.getID() == ke.KEY_PRESSED && ke.getKeyCode() == ke.VK_ESCAPE) { ! setActionCommand(COMMAND_FAILURE); ! fireActionEvent(); ! } ! */ ! } ! ! private static PopupChecker checker = null; ! public void ancestorAdded(javax.swing.event.AncestorEvent event) { ! //This is where we typically have a problem with popups not showing, ! //and below is the cure... Problem is that the popup is hidden ! //because the combo's ancestor is changed (even though we blocked ! //the normal ancestor listener from being added) ! checker = new PopupChecker(); ! SwingUtilities.invokeLater(checker); ! } ! ! public void ancestorMoved(javax.swing.event.AncestorEvent event) { ! //do nothing ! if (needLayout && getLayout() != null) { ! getLayout().layoutContainer(this); ! } ! } ! ! public void ancestorRemoved(javax.swing.event.AncestorEvent event) { ! //do nothing ! } ! ! /** A handy runnable which will ensure the popup is really displayed */ ! private class PopupChecker implements Runnable { ! ! public void run() { ! /* ! if (isShowing() && !isPopupVisible()) { ! log ("Popup checker ensuring editor prepared or popup visible"); ! if (isEditable()) { ! prepareEditor(); ! } else { ! showPopup(); ! } ! } ! checker = null; ! */ ! } ! } ! ! public void paintChildren(Graphics g) { ! if (editor != null && !hasFocus() && editor.isPaintable()) { ! return; ! } else { ! super.paintChildren(g); ! } ! } ! ! /* ! public void paintComponent (Graphics g) { ! //For property panel usage, allow the editor to paint ! if (editor != null && !hasFocus() && editor.isPaintable()) { ! Insets ins = getInsets(); ! Color c = g.getColor(); ! try { ! g.setColor(getBackground()); ! g.fillRect(0,0,getWidth(),getHeight()); ! } finally { ! g.setColor(c); ! } ! ins.left += PropUtils.getTextMargin(); ! editor.paintValue(g, new Rectangle(ins.left, ins.top, getWidth() - ! (ins.right + ins.left), getHeight() - (ins.top + ins.bottom))); ! } else { ! super.paintComponent(g); } } + */ + + /* Replacement renderer class to hack around bug in SynthComboUI - will + * only be used on GTK look & feel. GTK does not set background/highlight + * colors correctly */ + /* + private class Renderer extends DefaultListCellRenderer { + private boolean sel=false; + /** Overridden to return the combo box's background color if selected + * and focused - in GTK L&F combo boxes are always white (there's even + * a "fixme" note in the code. + public Color getBackground() { + //This method can be called in the superclass constructor, thanks + //to updateUI(). At that time, this==null, so an NPE would happen + //if we tried tor reference the outer class + if (ComboInplaceEditor.this == null) { + return null; + } + + if (!sel && (getText() != null && getSelectedItem() != null && + getText().equals(getSelectedItem()))) { + return ComboInplaceEditor.this.getBackground(); + } else { + return super.getBackground(); + } + } + + public Component getListCellRendererComponent(JList list,Object value, + int index, + boolean isSelected, + boolean cellHasFocus) { + sel = isSelected; + return super.getListCellRendererComponent(list, + value, index, isSelected, cellHasFocus); + } + + } + */ + } |
From: Greg H. <gh...@us...> - 2004-03-31 03:31:52
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25714/src/org/mc4j/console Modified Files: ConnectionExplorer.java Log Message: Don't synchronize the initial creation, this causes deadlock with some builds of netbeans platform. It doesn't break too much stuff if we accidentally create two instances and its pretty rare. Index: ConnectionExplorer.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/ConnectionExplorer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ConnectionExplorer.java 24 Feb 2004 03:40:47 -0000 1.2 --- ConnectionExplorer.java 31 Mar 2004 03:20:09 -0000 1.3 *************** *** 114,118 **** ! public static synchronized ConnectionExplorer getInstance() { // The ConnectionExplorer should've been loaded by the layer... // Try looking it up first before creating a new one. --- 114,118 ---- ! public static ConnectionExplorer getInstance() { // The ConnectionExplorer should've been loaded by the layer... // Try looking it up first before creating a new one. |
From: Greg H. <gh...@us...> - 2004-03-31 03:27:49
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/install In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25123/src/org/mc4j/console/install Modified Files: ExplorerUtil.java Log Message: Added check to see if a node isSelected. (There doesn't seem to be a way to see if a node's properties are visible) Index: ExplorerUtil.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/install/ExplorerUtil.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ExplorerUtil.java 19 Feb 2004 19:31:42 -0000 1.8 --- ExplorerUtil.java 31 Mar 2004 03:16:04 -0000 1.9 *************** *** 23,34 **** import org.openide.ErrorManager; - import org.openide.explorer.view.TreeView; - import org.openide.explorer.ExplorerPanel; import org.openide.nodes.Node; - import org.mc4j.console.swing.ExtendedExplorerPanel; import org.mc4j.console.ConnectionExplorer; /** * * @author Greg Hinkle (gh...@us...), August 2002 --- 23,32 ---- import org.openide.ErrorManager; import org.openide.nodes.Node; import org.mc4j.console.ConnectionExplorer; /** + * Useful utilities for dealing with the primary connection explorer tree. * * @author Greg Hinkle (gh...@us...), August 2002 *************** *** 57,60 **** --- 55,74 ---- } + /** + * + * @since MC4J 1.2b5 + * @param node any node to check if it is selected + * @return true if the node is selected in the primary explorer view + */ + public static boolean isSelected(Node node) { + Node[] selection = getExplorer().getExplorerManager().getSelectedNodes(); + for (int i = 0; i < selection.length; i++) { + Node selectedNode = selection[i]; + if (selectedNode.equals(node)) + return true; + } + return false; + } + public static boolean isExpanded(Node node) { return getExplorer().getBeanTreeView().isExpanded(node); |