Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for preview panel not showing in Ubuntu 11.04 with OpenJDK #257

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
12 changes: 5 additions & 7 deletions src/replicatorg/app/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,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);
Expand Down Expand Up @@ -355,10 +354,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 )
Expand Down Expand Up @@ -3365,11 +3364,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);
}

}
Expand Down
87 changes: 87 additions & 0 deletions src/replicatorg/app/ui/MainWindowCardPanel.java
Original file line number Diff line number Diff line change
@@ -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<String, Component> componentMap;

public MainWindowCardPanel()
{
cardLayout = new CardLayout();
cardPanel = new JPanel(cardLayout);
componentMap = new HashMap<String, Component>();
}

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);
}
}
}