summaryrefslogtreecommitdiff
path: root/java/src/IceGridGUI/MainPane.java
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2006-03-29 21:21:02 +0000
committerBernard Normier <bernard@zeroc.com>2006-03-29 21:21:02 +0000
commit20744ae1f1182d08e26b175f59d14041aabaf754 (patch)
tree937d125b80663966b3a61e13e744e28daf1f22da /java/src/IceGridGUI/MainPane.java
parentJava metadata (diff)
downloadice-20744ae1f1182d08e26b175f59d14041aabaf754.tar.bz2
ice-20744ae1f1182d08e26b175f59d14041aabaf754.tar.xz
ice-20744ae1f1182d08e26b175f59d14041aabaf754.zip
IceGrid GUI refactoring
Diffstat (limited to 'java/src/IceGridGUI/MainPane.java')
-rwxr-xr-xjava/src/IceGridGUI/MainPane.java156
1 files changed, 156 insertions, 0 deletions
diff --git a/java/src/IceGridGUI/MainPane.java b/java/src/IceGridGUI/MainPane.java
new file mode 100755
index 00000000000..0384fe3f92c
--- /dev/null
+++ b/java/src/IceGridGUI/MainPane.java
@@ -0,0 +1,156 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
+
+import java.awt.Component;
+
+import javax.swing.*;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.border.EmptyBorder;
+
+public class MainPane extends JTabbedPane
+{
+ public void addApplication(ApplicationPane application)
+ {
+ IceGridGUI.Application.Root root = application.getRoot();
+ super.addTab(computeTitle(root.getId()),
+ getIcon(root), application);
+ }
+
+ public void setTitleAt(int index, String title)
+ {
+ super.setTitleAt(index, computeTitle(title));
+ }
+
+ public void resetTitle(IceGridGUI.Application.Root root)
+ {
+ System.err.println("Reset title");
+ int i = findIndex(root);
+ if(i > 0)
+ {
+ System.err.println("New title:" + root.getId());
+ setTitleAt(i, root.getId());
+ }
+ }
+
+ public void resetIcon(IceGridGUI.Application.Root root)
+ {
+ int i = findIndex(root);
+ if(i > 0)
+ {
+ setIconAt(i, getIcon(root));
+ }
+ }
+
+ public int findIndex(IceGridGUI.Application.Root root)
+ {
+ for(int i = 1; i < getTabCount(); ++i)
+ {
+ ApplicationPane pane = (ApplicationPane)getComponentAt(i);
+ if(pane.getRoot() == root)
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public ApplicationPane findApplication(IceGridGUI.Application.Root root)
+ {
+ for(int i = 1; i < getTabCount(); ++i)
+ {
+ ApplicationPane pane = (ApplicationPane)getComponentAt(i);
+ if(pane.getRoot() == root)
+ {
+ return pane;
+ }
+ }
+ return null;
+ }
+
+ public void removeApplication(IceGridGUI.Application.Root root)
+ {
+ for(int i = 1; i < getTabCount(); ++i)
+ {
+ ApplicationPane pane = (ApplicationPane)getComponentAt(i);
+ if(pane.getRoot() == root)
+ {
+ removeTabAt(i);
+ break;
+ }
+ }
+ }
+
+ MainPane(Coordinator coordinator)
+ {
+ _coordinator = coordinator;
+ setBorder(new EmptyBorder(10, 10, 10, 10));
+
+ addChangeListener(new ChangeListener()
+ {
+ public void stateChanged(ChangeEvent evt)
+ {
+ Tab tab = (Tab)getSelectedComponent();
+ tab.selected();
+ }
+ });
+
+ _liveIcon = Utils.getIcon("/icons/16x16/grid.png");
+ _fileIcon = Utils.getIcon("/icons/16x16/folder_open.png");
+
+ addTab("Live Deployment", _liveIcon, _coordinator.getLiveDeploymentPane());
+ }
+
+
+ private String computeTitle(String name)
+ {
+ String title = name;
+ int i = 0;
+ while(hasTitle(title))
+ {
+ title = name + " (" + Integer.toString(++i) + ")";
+ }
+ return title;
+ }
+
+ private boolean hasTitle(String title)
+ {
+ int tabCount = getTabCount();
+ for(int i = 0; i < tabCount; ++i)
+ {
+ if(title.equals(getTitleAt(i)))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private ImageIcon getIcon(IceGridGUI.Application.Root root)
+ {
+ if(root.isLive())
+ {
+ return _liveIcon;
+ }
+ else if(root.hasFile())
+ {
+ return _fileIcon;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ private Coordinator _coordinator;
+ private ImageIcon _liveIcon;
+ private ImageIcon _fileIcon;
+}