Skip to content

Commit

Permalink
Added possibility to use JLayer as a context (#109)
Browse files Browse the repository at this point in the history
Closes #63.
  • Loading branch information
Mihai Pârvu authored Jul 30, 2018
1 parent 6ce45bf commit e76fa00
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JLayer;

public class DefaultContextVerifier extends AbstractContextVerifier {
static final String ERROR_MESSAGE = "To use this keyword you must first select a correct context. Please see e.g. \"Select Dialog\" -keyword.";
Expand All @@ -33,6 +34,6 @@ public DefaultContextVerifier() {
@SuppressWarnings("unchecked")
@Override
protected Class<? extends Component>[] getExpectedClasses() {
return new Class[] { Window.class, JPanel.class, Panel.class, JInternalFrame.class };
return new Class[] { Window.class, JPanel.class, Panel.class, JInternalFrame.class, JLayer.class };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ private String titleOf(Component component) {
}

private static void verifyContext(Class contextClass) {
Class<? extends Component>[] expectedClasses = new Class[] { Window.class, JPanel.class, Panel.class, JInternalFrame.class };
Class<? extends Component>[] expectedClasses = new Class[] { Window.class, JPanel.class, Panel.class,
JInternalFrame.class, JLayer.class };
boolean assignable = false;
StringBuilder str = new StringBuilder();
for (Class<? extends Component> expectedClass : expectedClasses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JLayer;
import javax.swing.JLayeredPane;
import javax.swing.JList;
import javax.swing.JMenuBar;
Expand Down Expand Up @@ -48,6 +49,7 @@ public class ComponentOccurences {
put(JComboBox.class, -1);
put(JSpinner.class, -1);
put(JLabel.class, -1);
put(JLayer.class, -1);
put(JTabbedPane.class, -1);
put(JRootPane.class, -1);
put(JLayeredPane.class, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import javax.swing.SwingUtilities;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;
import javax.swing.plaf.LayerUI;
import javax.swing.JLayer;

public class TestApplication {
private JPanel panel;
Expand Down Expand Up @@ -213,6 +215,16 @@ public void actionPerformed(ActionEvent e) {
panel.add(tableWithHeader());
panel.add(new TestScrollPane());
panel.add(new TestFastUpdatingPane());

JTextField jLayerTextField = new JTextField() {
{
setPreferredSize(new Dimension(100, 30));
}
};
LayerUI layerUI = new LayerUI();
JLayer jLayer = new JLayer(jLayerTextField, layerUI);
jLayer.setName("jLayerComponent");
panel.add(jLayer);
}

private Component tableWithHeader() {
Expand Down
11 changes: 10 additions & 1 deletion src/test/resources/robot-tests/context.robot
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ${panelName} Main Panel
${dialogMenu2} Test Menu|Show Non-Modal Dialog
${dialogTitle2} Non-modal Dialog
${textFieldName} testTextField
${jLayerName} jLayerComponent

*** Test Cases ***
Select Context
Expand All @@ -16,7 +17,7 @@ Select Context

Select Invalid Context should fail
Select And Assert Main Window
Run keyword and expect error Invalid context *. Should be one of (java.awt.Window javax.swing.JPanel java.awt.Panel javax.swing.JInternalFrame ) selectContext ${textFieldName}
Run keyword and expect error Invalid context *. Should be one of (java.awt.Window javax.swing.JPanel java.awt.Panel javax.swing.JInternalFrame javax.swing.JLayer ) selectContext ${textFieldName}

Get Current Context With Panels
Select And Assert Main Window
Expand Down Expand Up @@ -46,6 +47,14 @@ Get Current Context With Dialog
Should Be Equal ${dialogTitle2} ${title}
[Teardown] closeDialog ${dialogTitle2}

Get Current Context With JLayer
Select And Assert Main Window
selectContext ${jLayerName}
${contextName}= getCurrentContext
Should Be Equal ${contextName} ${jLayerName}
${contextAsString}= getCurrentContextSourceAsString
shouldContain ${contextAsString} ${jLayerName}

*** Keywords ***
Select And Assert Main Window
selectMainWindow
Expand Down

0 comments on commit e76fa00

Please sign in to comment.