From ea63bf1ec7aa397032f75fe13104e168641e88d0 Mon Sep 17 00:00:00 2001 From: George Schneeloch Date: Sat, 14 Jan 2012 23:24:38 -0500 Subject: [PATCH] adding wrapper class to work around OpenJDK/Java3D bug in Ubuntu 11.04 --- src/replicatorg/app/ui/MainWindow.java | 12 ++- .../app/ui/MainWindowCardPanel.java | 87 +++++++++++++++++++ 2 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 src/replicatorg/app/ui/MainWindowCardPanel.java diff --git a/src/replicatorg/app/ui/MainWindow.java b/src/replicatorg/app/ui/MainWindow.java index 94e4c24b6..0ed0feed5 100755 --- a/src/replicatorg/app/ui/MainWindow.java +++ b/src/replicatorg/app/ui/MainWindow.java @@ -193,8 +193,7 @@ public class MainWindow extends JFrame implements MRJAboutHandler, MRJQuitHandle MainButtonPanel buttons; - CardLayout cardLayout = new CardLayout(); - JPanel cardPanel = new JPanel(cardLayout); + protected final MainWindowCardPanel cardPanel = new MainWindowCardPanel(); EditorHeader header = new EditorHeader(this); { header.setChangeListener(this); @@ -341,10 +340,10 @@ public void windowClosing(WindowEvent e) { console = new MessagePanel(this); console.setBorder(null); - splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, cardPanel, + splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, cardPanel.getPanel(), console); - new FileDrop( null, cardPanel, /*dragBorder,*/ new FileDrop.Listener() + new FileDrop( null, cardPanel.getPanel(), /*dragBorder,*/ new FileDrop.Listener() { public void filesDropped( java.io.File[] files ) { // for( java.io.File file : files ) @@ -3117,11 +3116,10 @@ public void toolStatusChanged(MachineToolStatusEvent event) { public void setCurrentElement(BuildElement e) { currentElement = e; if (currentElement != null) { - CardLayout cl = (CardLayout)cardPanel.getLayout(); if (currentElement.getType() == BuildElement.Type.MODEL ) { - cl.show(cardPanel, MODEL_TAB_KEY); + cardPanel.show(MODEL_TAB_KEY); } else { - cl.show(cardPanel, GCODE_TAB_KEY); + cardPanel.show(GCODE_TAB_KEY); } } diff --git a/src/replicatorg/app/ui/MainWindowCardPanel.java b/src/replicatorg/app/ui/MainWindowCardPanel.java new file mode 100644 index 000000000..402f7a071 --- /dev/null +++ b/src/replicatorg/app/ui/MainWindowCardPanel.java @@ -0,0 +1,87 @@ +package replicatorg.app.ui; + +import java.awt.CardLayout; +import java.awt.Component; +import java.util.HashMap; + +import javax.swing.JPanel; + +import replicatorg.app.Base; + +/** + * This class is a workaround for a problem with OpenJDK and Java3D on Ubuntu 11.04, + * where the preview window wouldn't show up when there are two cards in the JPanel + * with a CardLayout. To work around that, this will store the widgets in componentMap + * instead, and only add them to the JPanel when it's time to show them. + * + * Since this issue only occurs on linux, the add and show methods will just + * pass through to cardPanel and cardLayout if Base.isLinux() is false. + * + * @author George Schneeloch + * + */ +public class MainWindowCardPanel +{ + private final JPanel cardPanel; + private final CardLayout cardLayout; + + private final HashMap componentMap; + + public MainWindowCardPanel() + { + cardLayout = new CardLayout(); + cardPanel = new JPanel(cardLayout); + componentMap = new HashMap(); + } + + public void add(Component component, String key) { + if (Base.isLinux()) + { + componentMap.put(key, component); + + show(key); + } + else + { + cardPanel.add(component, key); + } + } + + /** + * Get the JPanel used by this class. This method should not be used to + * add or remove components, or to show a card; use add() and show() instead + * @return + */ + public Component getPanel() { + return cardPanel; + } + + public void show(String key) + { + if (Base.isLinux()) + { + if (componentMap.containsKey(key)) + { + Component component = componentMap.get(key); + // there should only be one widget in cardPanel at any time, + // but just in case, make them all invisible + for (Component otherComponent : cardPanel.getComponents()) + { + if (otherComponent.isVisible()) + { + otherComponent.setVisible(false); + } + } + cardPanel.removeAll(); + cardPanel.add(component, key); + + component.setVisible(true); + component.validate(); + } + } + else + { + cardLayout.show(cardPanel, key); + } + } +}