src/share/classes/sun/tools/jconsole/VMPanel.java

Print this page
rev 5340 : 7017818: NLS: JConsoleResources.java cannot be handled by translation team
Reviewed-by: duke


  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.tools.jconsole;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.beans.*;
  31 import java.io.*;
  32 import java.lang.reflect.*;
  33 import java.util.*;
  34 import java.util.List;
  35 import java.util.Timer;
  36 
  37 import javax.swing.*;
  38 import javax.swing.plaf.*;
  39 


  40 import com.sun.tools.jconsole.JConsolePlugin;
  41 import com.sun.tools.jconsole.JConsoleContext;
  42 import static com.sun.tools.jconsole.JConsoleContext.ConnectionState.*;
  43 
  44 import static sun.tools.jconsole.ProxyClient.*;
  45 
  46 @SuppressWarnings("serial")
  47 public class VMPanel extends JTabbedPane implements PropertyChangeListener {
  48 
  49     private ProxyClient proxyClient;
  50     private Timer timer;
  51     private int updateInterval;
  52     private String hostName;
  53     private int port;
  54     private int vmid;
  55     private String userName;
  56     private String password;
  57     private String url;
  58     private VMInternalFrame vmIF = null;
  59     private static final String windowsLaF =
  60             "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
  61     private static ArrayList<TabInfo> tabInfos = new ArrayList<TabInfo>();
  62     private boolean wasConnected = false;
  63 
  64     // The everConnected flag keeps track of whether the window can be
  65     // closed if the user clicks Cancel after a failed connection attempt.
  66     //
  67     private boolean everConnected = false;
  68 
  69     // The initialUpdate flag is used to enable/disable tabs each time
  70     // a connect or reconnect takes place. This flag avoids having to
  71     // enable/disable tabs on each update call.
  72     //
  73     private boolean initialUpdate = true;
  74 
  75     // Each VMPanel has its own instance of the JConsolePlugin
  76     // A map of JConsolePlugin to the previous SwingWorker
  77     private Map<JConsolePlugin, SwingWorker<?, ?>> plugins = null;
  78     private boolean pluginTabsAdded = false;
  79 
  80     // Update these only on the EDT


  83     private long time0;
  84 
  85     static {
  86         tabInfos.add(new TabInfo(OverviewTab.class, OverviewTab.getTabName(), true));
  87         tabInfos.add(new TabInfo(MemoryTab.class, MemoryTab.getTabName(), true));
  88         tabInfos.add(new TabInfo(ThreadTab.class, ThreadTab.getTabName(), true));
  89         tabInfos.add(new TabInfo(ClassTab.class, ClassTab.getTabName(), true));
  90         tabInfos.add(new TabInfo(SummaryTab.class, SummaryTab.getTabName(), true));
  91         tabInfos.add(new TabInfo(MBeansTab.class, MBeansTab.getTabName(), true));
  92     }
  93 
  94     public static TabInfo[] getTabInfos() {
  95         return tabInfos.toArray(new TabInfo[tabInfos.size()]);
  96     }
  97 
  98     VMPanel(ProxyClient proxyClient, int updateInterval) {
  99         this.proxyClient = proxyClient;
 100         this.updateInterval = updateInterval;
 101         this.hostName = proxyClient.getHostName();
 102         this.port = proxyClient.getPort();
 103         this.vmid = proxyClient.getVmid();
 104         this.userName = proxyClient.getUserName();
 105         this.password = proxyClient.getPassword();
 106         this.url = proxyClient.getUrl();
 107 
 108         for (TabInfo tabInfo : tabInfos) {
 109             if (tabInfo.tabVisible) {
 110                 addTab(tabInfo);
 111             }
 112         }
 113 
 114         plugins = new LinkedHashMap<JConsolePlugin, SwingWorker<?, ?>>();
 115         for (JConsolePlugin p : JConsole.getPlugins()) {
 116             p.setContext(proxyClient);
 117             plugins.put(p, null);
 118         }
 119 
 120         Utilities.updateTransparency(this);
 121 
 122         ToolTipManager.sharedInstance().registerComponent(this);
 123 


 169         Icon icon;
 170         Component c0 = getComponent(0);
 171         if (c0 != null && c0.getY() > 24) {
 172             icon = isConnected() ? connectedIcon24 : disconnectedIcon24;
 173         } else {
 174             icon = isConnected() ? connectedIcon16 : disconnectedIcon16;
 175         }
 176         Insets insets = getInsets();
 177         int x = getWidth() - insets.right - icon.getIconWidth() - 4;
 178         int y = insets.top;
 179         if (c0 != null) {
 180             y = (c0.getY() - icon.getIconHeight()) / 2;
 181         }
 182         icon.paintIcon(this, g, x, y);
 183         connectedIconBounds = new Rectangle(x, y, icon.getIconWidth(), icon.getIconHeight());
 184     }
 185 
 186     public String getToolTipText(MouseEvent event) {
 187         if (connectedIconBounds.contains(event.getPoint())) {
 188             if (isConnected()) {
 189                 return getText("Connected. Click to disconnect.");
 190             } else {
 191                 return getText("Disconnected. Click to connect.");
 192             }
 193         } else {
 194             return super.getToolTipText(event);
 195         }
 196     }
 197 
 198     private synchronized void addTab(TabInfo tabInfo) {
 199         Tab tab = instantiate(tabInfo);
 200         if (tab != null) {
 201             addTab(tabInfo.name, tab);
 202         } else {
 203             tabInfo.tabVisible = false;
 204         }
 205     }
 206 
 207     private synchronized void insertTab(TabInfo tabInfo, int index) {
 208         Tab tab = instantiate(tabInfo);
 209         if (tab != null) {
 210             insertTab(tabInfo.name, null, tab, null, index);
 211         } else {
 212             tabInfo.tabVisible = false;
 213         }
 214     }
 215 
 216     public synchronized void removeTabAt(int index) {
 217         super.removeTabAt(index);
 218     }
 219 
 220     private Tab instantiate(TabInfo tabInfo) {
 221         try {
 222             Constructor con = tabInfo.tabClass.getConstructor(VMPanel.class);
 223             return (Tab) con.newInstance(this);
 224         } catch (Exception ex) {
 225             System.err.println(ex);
 226             return null;
 227         }
 228     }
 229 
 230     boolean isConnected() {
 231         return proxyClient.isConnected();
 232     }
 233 
 234     public int getUpdateInterval() {
 235         return updateInterval;
 236     }
 237 
 238     /**
 239      * WARNING NEVER CALL THIS METHOD TO MAKE JMX REQUEST
 240      * IF  assertThread == false.
 241      * DISPATCHER THREAD IS NOT ASSERTED.
 242      * IT IS USED TO MAKE SOME LOCAL MANIPULATIONS.


 337                 case DISCONNECTED:
 338                     if (progressBar != null) {
 339                         progressBar.setIndeterminate(false);
 340                         progressBar.setValue(0);
 341                         closeOptionPane();
 342                     }
 343                     vmPanelDied();
 344                     if (oldState == ConnectionState.CONNECTED) {
 345                         // Notify tabs
 346                         fireConnectedChange(false);
 347                     }
 348                     break;
 349             }
 350         }
 351     }
 352 
 353     // Called on EDT
 354     private void onConnecting() {
 355         time0 = System.currentTimeMillis();
 356 
 357         final JConsole jc = (JConsole) SwingUtilities.getWindowAncestor(this);
 358 
 359         String connectionName = getConnectionName();
 360         progressBar = new JProgressBar();
 361         progressBar.setIndeterminate(true);
 362         JPanel progressPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
 363         progressPanel.add(progressBar);
 364 
 365         Object[] message = {
 366             "<html><h3>" + getText("connectingTo1", connectionName) + "</h3></html>",
 367             progressPanel,
 368             "<html><b>" + getText("connectingTo2", connectionName) + "</b></html>"
 369         };
 370 
 371         optionPane =
 372                 SheetDialog.showOptionDialog(this,
 373                 message,
 374                 JOptionPane.DEFAULT_OPTION,
 375                 JOptionPane.INFORMATION_MESSAGE, null,
 376                 new String[]{getText("Cancel")},
 377                 0);
 378 
 379 
 380     }
 381 
 382     // Called on EDT
 383     private void closeOptionPane() {
 384         if (optionPane != null) {
 385             new Thread("VMPanel.sleeper") {
 386                 public void run() {
 387                     long elapsed = System.currentTimeMillis() - time0;
 388                     if (elapsed < 2000) {
 389                         try {
 390                             sleep(2000 - elapsed);
 391                         } catch (InterruptedException ex) {
 392                         // Ignore
 393                         }
 394                     }
 395                     SwingUtilities.invokeLater(new Runnable() {
 396 
 397                         public void run() {
 398                             optionPane.setVisible(false);
 399                             progressBar = null;
 400                         }
 401                     });
 402                 }
 403             }.start();
 404         }
 405     }
 406 
 407     void updateFrameTitle() {
 408         VMInternalFrame vmIF = getFrame();
 409         if (vmIF != null) {
 410             String displayName = getDisplayName();
 411             if (!proxyClient.isConnected()) {
 412                 displayName = getText("ConnectionName (disconnected)", displayName);
 413             }
 414             vmIF.setTitle(displayName);
 415         }
 416     }
 417 
 418     private VMInternalFrame getFrame() {
 419         if (vmIF == null) {
 420             vmIF = (VMInternalFrame) SwingUtilities.getAncestorOfClass(VMInternalFrame.class,
 421                     this);
 422         }
 423         return vmIF;
 424     }
 425 
 426     // TODO: this method is not needed when all JConsole tabs
 427     // are migrated to use the new JConsolePlugin API.
 428     //
 429     // A thread safe clone of all JConsole tabs
 430     synchronized List<Tab> getTabs() {
 431         ArrayList<Tab> list = new ArrayList<Tab>();
 432         int n = getTabCount();


 441 
 442     private void startUpdateTimer() {
 443         if (timer != null) {
 444             timer.cancel();
 445         }
 446         TimerTask timerTask = new TimerTask() {
 447 
 448             public void run() {
 449                 update();
 450             }
 451         };
 452         String timerName = "Timer-" + getConnectionName();
 453         timer = new Timer(timerName, true);
 454         timer.schedule(timerTask, 0, updateInterval);
 455     }
 456 
 457     // Call on EDT
 458     private void vmPanelDied() {
 459         disconnect();
 460 
 461         final JConsole jc = (JConsole) SwingUtilities.getWindowAncestor(this);
 462 
 463         JOptionPane optionPane;
 464 
 465         final String connectStr = getText("Connect");
 466         final String reconnectStr = getText("Reconnect");
 467         final String cancelStr = getText("Cancel");
 468 
 469         String msgTitle, msgExplanation, buttonStr;
 470 
 471         if (wasConnected) {
 472             wasConnected = false;
 473             msgTitle = getText("connectionLost1");
 474             msgExplanation = getText("connectionLost2", getConnectionName());
 475             buttonStr = reconnectStr;
 476         } else {
 477             msgTitle = getText("connectionFailed1");
 478             msgExplanation = getText("connectionFailed2", getConnectionName());
 479             buttonStr = connectStr;
 480         }
 481 
 482         optionPane =
 483                 SheetDialog.showOptionDialog(this,
 484                 "<html><h3>" + msgTitle + "</h3>" +
 485                 "<b>" + msgExplanation + "</b>",
 486                 JOptionPane.DEFAULT_OPTION,
 487                 JOptionPane.WARNING_MESSAGE, null,
 488                 new String[]{buttonStr, cancelStr},
 489                 0);
 490 
 491         optionPane.addPropertyChangeListener(new PropertyChangeListener() {
 492 
 493             public void propertyChange(PropertyChangeEvent event) {
 494                 if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) {
 495                     Object value = event.getNewValue();
 496 
 497                     if (value == reconnectStr || value == connectStr) {
 498                         connect();
 499                     } else if (!everConnected) {
 500                         try {
 501                             getFrame().setClosed(true);
 502                         } catch (PropertyVetoException ex) {
 503                         // Should not happen, but can be ignored.
 504                         }
 505                     }
 506                 }
 507             }
 508         });
 509     }
 510 
 511     // Note: This method is called on a TimerTask thread. Any GUI manipulation
 512     // must be performed with invokeLater() or invokeAndWait().
 513     private Object lockObject = new Object();
 514 
 515     private void update() {
 516         synchronized (lockObject) {
 517             if (!isConnected()) {


 626         return proxyClient.connectionName();
 627     }
 628 
 629     public String getDisplayName() {
 630         return proxyClient.getDisplayName();
 631     }
 632 
 633     static class TabInfo {
 634 
 635         Class<? extends Tab> tabClass;
 636         String name;
 637         boolean tabVisible;
 638 
 639         TabInfo(Class<? extends Tab> tabClass, String name, boolean tabVisible) {
 640             this.tabClass = tabClass;
 641             this.name = name;
 642             this.tabVisible = tabVisible;
 643         }
 644     }
 645 
 646     // Convenience methods
 647     private static String getText(String key, Object... args) {
 648         return Resources.getText(key, args);
 649     }
 650 
 651     private void createPluginTabs() {
 652         // add plugin tabs if not done
 653         if (!pluginTabsAdded) {
 654             for (JConsolePlugin p : plugins.keySet()) {
 655                 Map<String, JPanel> tabs = p.getTabs();
 656                 for (Map.Entry<String, JPanel> e : tabs.entrySet()) {
 657                     addTab(e.getKey(), e.getValue());
 658                 }
 659             }
 660             pluginTabsAdded = true;
 661         }
 662     }
 663 
 664     private void fireConnectedChange(boolean connected) {
 665         for (Tab tab : getTabs()) {
 666             tab.firePropertyChange(JConsoleContext.CONNECTION_STATE_PROPERTY, !connected, connected);
 667         }
 668     }
 669 }


  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.tools.jconsole;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.beans.*;

  31 import java.lang.reflect.*;
  32 import java.util.*;
  33 import java.util.List;
  34 import java.util.Timer;

  35 import javax.swing.*;
  36 import javax.swing.plaf.*;
  37 
  38 import sun.tools.jconsole.resources.Messages;
  39 
  40 import com.sun.tools.jconsole.JConsolePlugin;
  41 import com.sun.tools.jconsole.JConsoleContext;

  42 
  43 import static sun.tools.jconsole.ProxyClient.*;
  44 
  45 @SuppressWarnings("serial")
  46 public class VMPanel extends JTabbedPane implements PropertyChangeListener {
  47 
  48     private ProxyClient proxyClient;
  49     private Timer timer;
  50     private int updateInterval;
  51     private String hostName;
  52     private int port;

  53     private String userName;
  54     private String password;
  55     private String url;
  56     private VMInternalFrame vmIF = null;


  57     private static ArrayList<TabInfo> tabInfos = new ArrayList<TabInfo>();
  58     private boolean wasConnected = false;
  59 
  60     // The everConnected flag keeps track of whether the window can be
  61     // closed if the user clicks Cancel after a failed connection attempt.
  62     //
  63     private boolean everConnected = false;
  64 
  65     // The initialUpdate flag is used to enable/disable tabs each time
  66     // a connect or reconnect takes place. This flag avoids having to
  67     // enable/disable tabs on each update call.
  68     //
  69     private boolean initialUpdate = true;
  70 
  71     // Each VMPanel has its own instance of the JConsolePlugin
  72     // A map of JConsolePlugin to the previous SwingWorker
  73     private Map<JConsolePlugin, SwingWorker<?, ?>> plugins = null;
  74     private boolean pluginTabsAdded = false;
  75 
  76     // Update these only on the EDT


  79     private long time0;
  80 
  81     static {
  82         tabInfos.add(new TabInfo(OverviewTab.class, OverviewTab.getTabName(), true));
  83         tabInfos.add(new TabInfo(MemoryTab.class, MemoryTab.getTabName(), true));
  84         tabInfos.add(new TabInfo(ThreadTab.class, ThreadTab.getTabName(), true));
  85         tabInfos.add(new TabInfo(ClassTab.class, ClassTab.getTabName(), true));
  86         tabInfos.add(new TabInfo(SummaryTab.class, SummaryTab.getTabName(), true));
  87         tabInfos.add(new TabInfo(MBeansTab.class, MBeansTab.getTabName(), true));
  88     }
  89 
  90     public static TabInfo[] getTabInfos() {
  91         return tabInfos.toArray(new TabInfo[tabInfos.size()]);
  92     }
  93 
  94     VMPanel(ProxyClient proxyClient, int updateInterval) {
  95         this.proxyClient = proxyClient;
  96         this.updateInterval = updateInterval;
  97         this.hostName = proxyClient.getHostName();
  98         this.port = proxyClient.getPort();

  99         this.userName = proxyClient.getUserName();
 100         this.password = proxyClient.getPassword();
 101         this.url = proxyClient.getUrl();
 102 
 103         for (TabInfo tabInfo : tabInfos) {
 104             if (tabInfo.tabVisible) {
 105                 addTab(tabInfo);
 106             }
 107         }
 108 
 109         plugins = new LinkedHashMap<JConsolePlugin, SwingWorker<?, ?>>();
 110         for (JConsolePlugin p : JConsole.getPlugins()) {
 111             p.setContext(proxyClient);
 112             plugins.put(p, null);
 113         }
 114 
 115         Utilities.updateTransparency(this);
 116 
 117         ToolTipManager.sharedInstance().registerComponent(this);
 118 


 164         Icon icon;
 165         Component c0 = getComponent(0);
 166         if (c0 != null && c0.getY() > 24) {
 167             icon = isConnected() ? connectedIcon24 : disconnectedIcon24;
 168         } else {
 169             icon = isConnected() ? connectedIcon16 : disconnectedIcon16;
 170         }
 171         Insets insets = getInsets();
 172         int x = getWidth() - insets.right - icon.getIconWidth() - 4;
 173         int y = insets.top;
 174         if (c0 != null) {
 175             y = (c0.getY() - icon.getIconHeight()) / 2;
 176         }
 177         icon.paintIcon(this, g, x, y);
 178         connectedIconBounds = new Rectangle(x, y, icon.getIconWidth(), icon.getIconHeight());
 179     }
 180 
 181     public String getToolTipText(MouseEvent event) {
 182         if (connectedIconBounds.contains(event.getPoint())) {
 183             if (isConnected()) {
 184                 return Messages.CONNECTED_PUNCTUATION_CLICK_TO_DISCONNECT_;
 185             } else {
 186                 return Messages.DISCONNECTED_PUNCTUATION_CLICK_TO_CONNECT_;
 187             }
 188         } else {
 189             return super.getToolTipText(event);
 190         }
 191     }
 192 
 193     private synchronized void addTab(TabInfo tabInfo) {
 194         Tab tab = instantiate(tabInfo);
 195         if (tab != null) {
 196             addTab(tabInfo.name, tab);
 197         } else {
 198             tabInfo.tabVisible = false;
 199         }
 200     }
 201 
 202     private synchronized void insertTab(TabInfo tabInfo, int index) {
 203         Tab tab = instantiate(tabInfo);
 204         if (tab != null) {
 205             insertTab(tabInfo.name, null, tab, null, index);
 206         } else {
 207             tabInfo.tabVisible = false;
 208         }
 209     }
 210 
 211     public synchronized void removeTabAt(int index) {
 212         super.removeTabAt(index);
 213     }
 214 
 215     private Tab instantiate(TabInfo tabInfo) {
 216         try {
 217             Constructor<?> con = tabInfo.tabClass.getConstructor(VMPanel.class);
 218             return (Tab) con.newInstance(this);
 219         } catch (Exception ex) {
 220             System.err.println(ex);
 221             return null;
 222         }
 223     }
 224 
 225     boolean isConnected() {
 226         return proxyClient.isConnected();
 227     }
 228 
 229     public int getUpdateInterval() {
 230         return updateInterval;
 231     }
 232 
 233     /**
 234      * WARNING NEVER CALL THIS METHOD TO MAKE JMX REQUEST
 235      * IF  assertThread == false.
 236      * DISPATCHER THREAD IS NOT ASSERTED.
 237      * IT IS USED TO MAKE SOME LOCAL MANIPULATIONS.


 332                 case DISCONNECTED:
 333                     if (progressBar != null) {
 334                         progressBar.setIndeterminate(false);
 335                         progressBar.setValue(0);
 336                         closeOptionPane();
 337                     }
 338                     vmPanelDied();
 339                     if (oldState == ConnectionState.CONNECTED) {
 340                         // Notify tabs
 341                         fireConnectedChange(false);
 342                     }
 343                     break;
 344             }
 345         }
 346     }
 347 
 348     // Called on EDT
 349     private void onConnecting() {
 350         time0 = System.currentTimeMillis();
 351 
 352         SwingUtilities.getWindowAncestor(this);
 353 
 354         String connectionName = getConnectionName();
 355         progressBar = new JProgressBar();
 356         progressBar.setIndeterminate(true);
 357         JPanel progressPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
 358         progressPanel.add(progressBar);
 359 
 360         Object[] message = {
 361             "<html><h3>" + Resources.format(Messages.CONNECTING_TO1, connectionName) + "</h3></html>",
 362             progressPanel,
 363             "<html><b>" + Resources.format(Messages.CONNECTING_TO2, connectionName) + "</b></html>"
 364         };
 365 
 366         optionPane =
 367                 SheetDialog.showOptionDialog(this,
 368                 message,
 369                 JOptionPane.DEFAULT_OPTION,
 370                 JOptionPane.INFORMATION_MESSAGE, null,
 371                 new String[]{Messages.CANCEL},
 372                 0);
 373 
 374 
 375     }
 376 
 377     // Called on EDT
 378     private void closeOptionPane() {
 379         if (optionPane != null) {
 380             new Thread("VMPanel.sleeper") {
 381                 public void run() {
 382                     long elapsed = System.currentTimeMillis() - time0;
 383                     if (elapsed < 2000) {
 384                         try {
 385                             sleep(2000 - elapsed);
 386                         } catch (InterruptedException ex) {
 387                         // Ignore
 388                         }
 389                     }
 390                     SwingUtilities.invokeLater(new Runnable() {
 391 
 392                         public void run() {
 393                             optionPane.setVisible(false);
 394                             progressBar = null;
 395                         }
 396                     });
 397                 }
 398             }.start();
 399         }
 400     }
 401 
 402     void updateFrameTitle() {
 403         VMInternalFrame vmIF = getFrame();
 404         if (vmIF != null) {
 405             String displayName = getDisplayName();
 406             if (!proxyClient.isConnected()) {
 407                 displayName = Resources.format(Messages.CONNECTION_NAME__DISCONNECTED_, displayName);
 408             }
 409             vmIF.setTitle(displayName);
 410         }
 411     }
 412 
 413     private VMInternalFrame getFrame() {
 414         if (vmIF == null) {
 415             vmIF = (VMInternalFrame) SwingUtilities.getAncestorOfClass(VMInternalFrame.class,
 416                     this);
 417         }
 418         return vmIF;
 419     }
 420 
 421     // TODO: this method is not needed when all JConsole tabs
 422     // are migrated to use the new JConsolePlugin API.
 423     //
 424     // A thread safe clone of all JConsole tabs
 425     synchronized List<Tab> getTabs() {
 426         ArrayList<Tab> list = new ArrayList<Tab>();
 427         int n = getTabCount();


 436 
 437     private void startUpdateTimer() {
 438         if (timer != null) {
 439             timer.cancel();
 440         }
 441         TimerTask timerTask = new TimerTask() {
 442 
 443             public void run() {
 444                 update();
 445             }
 446         };
 447         String timerName = "Timer-" + getConnectionName();
 448         timer = new Timer(timerName, true);
 449         timer.schedule(timerTask, 0, updateInterval);
 450     }
 451 
 452     // Call on EDT
 453     private void vmPanelDied() {
 454         disconnect();
 455 


 456         JOptionPane optionPane;





 457         String msgTitle, msgExplanation, buttonStr;
 458 
 459         if (wasConnected) {
 460             wasConnected = false;
 461             msgTitle = Messages.CONNECTION_LOST;
 462             msgExplanation = Resources.format(Messages.CONNECTING_TO2, getConnectionName());
 463             buttonStr = Messages.RECONNECT;
 464         } else {
 465             msgTitle =Messages.CONNECTION_FAILED1;
 466             msgExplanation = Resources.format(Messages.CONNECTION_FAILED2, getConnectionName());
 467             buttonStr = Messages.CONNECT;
 468         }
 469 
 470         optionPane =
 471                 SheetDialog.showOptionDialog(this,
 472                 "<html><h3>" + msgTitle + "</h3>" +
 473                 "<b>" + msgExplanation + "</b>",
 474                 JOptionPane.DEFAULT_OPTION,
 475                 JOptionPane.WARNING_MESSAGE, null,
 476                 new String[]{buttonStr, Messages.CANCEL},
 477                 0);
 478 
 479         optionPane.addPropertyChangeListener(new PropertyChangeListener() {
 480 
 481             public void propertyChange(PropertyChangeEvent event) {
 482                 if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) {
 483                     Object value = event.getNewValue();
 484 
 485                     if (value == Messages.RECONNECT || value == Messages.CONNECT) {
 486                         connect();
 487                     } else if (!everConnected) {
 488                         try {
 489                             getFrame().setClosed(true);
 490                         } catch (PropertyVetoException ex) {
 491                         // Should not happen, but can be ignored.
 492                         }
 493                     }
 494                 }
 495             }
 496         });
 497     }
 498 
 499     // Note: This method is called on a TimerTask thread. Any GUI manipulation
 500     // must be performed with invokeLater() or invokeAndWait().
 501     private Object lockObject = new Object();
 502 
 503     private void update() {
 504         synchronized (lockObject) {
 505             if (!isConnected()) {


 614         return proxyClient.connectionName();
 615     }
 616 
 617     public String getDisplayName() {
 618         return proxyClient.getDisplayName();
 619     }
 620 
 621     static class TabInfo {
 622 
 623         Class<? extends Tab> tabClass;
 624         String name;
 625         boolean tabVisible;
 626 
 627         TabInfo(Class<? extends Tab> tabClass, String name, boolean tabVisible) {
 628             this.tabClass = tabClass;
 629             this.name = name;
 630             this.tabVisible = tabVisible;
 631         }
 632     }
 633 





 634     private void createPluginTabs() {
 635         // add plugin tabs if not done
 636         if (!pluginTabsAdded) {
 637             for (JConsolePlugin p : plugins.keySet()) {
 638                 Map<String, JPanel> tabs = p.getTabs();
 639                 for (Map.Entry<String, JPanel> e : tabs.entrySet()) {
 640                     addTab(e.getKey(), e.getValue());
 641                 }
 642             }
 643             pluginTabsAdded = true;
 644         }
 645     }
 646 
 647     private void fireConnectedChange(boolean connected) {
 648         for (Tab tab : getTabs()) {
 649             tab.firePropertyChange(JConsoleContext.CONNECTION_STATE_PROPERTY, !connected, connected);
 650         }
 651     }
 652 }