Java Code Examples for javax.swing.JPanel#getComponents()

The following examples show how to use javax.swing.JPanel#getComponents() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelTableView.java    From arcusplatform with Apache License 2.0 7 votes vote down vote up
private void setCollapsed(boolean collapsed) {
   if(!isActive()) {
      return;
   }
   for(Component c: ((JPanel) getComponent()).getComponents()) {
      if(!(c instanceof JPanel)) {
         continue;
      }
      JPanel jp = (JPanel) c;
      if(!(jp.getComponents().length == 2 && jp.getComponents()[1] instanceof JXCollapsiblePane)) {
         continue;
      }
      JXCollapsiblePane collapser = (JXCollapsiblePane) jp.getComponents()[1];
      collapser.setCollapsed(collapsed);
   }
}
 
Example 2
Source File: PagesAndReferencesDDTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testDelWelcomePage() throws Exception {
    JPanel panel = utils.getInnerSectionPanel("welcome_files");
    Component[] comp = panel.getComponents();
    utils.setText((JTextField) comp[1], "index.jsp");
    ((Component) comp[2]).requestFocus();
    DDTestUtils.waitForDispatchThread();
    new StepIterator() {

        @Override
        public boolean step() throws Exception {
            return utils.contains(".*<welcome-file-list>\\s*<welcome-file>\\s*index.jsp\\s*</welcome-file>\\s*</welcome-file-list>.*");
        }

        @Override
        public void finalCheck() {
            utils.checkInDDXML(".*<welcome-file-list>\\s*<welcome-file>\\s*index.jsp\\s*</welcome-file>\\s*</welcome-file-list>.*");
            String[] files = webapp.getSingleWelcomeFileList().getWelcomeFile();
            assertEquals("Wrong count of welcome pages", 1, files.length);
            assertEquals("Welcome file name doesn't match.", "index.jsp", files[0].trim());
        }
    };
    utils.save();
}
 
Example 3
Source File: BeltOpenChartAction.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Shows the opened visualization.
 */
private void getOpenedVisualizations(ButtonBarCardPanel cardPanel, AbstractBeltColumnStatisticsModel model) {
	JPanel outerPanel = (JPanel) cardPanel.getShownComponent();
	for (Component innerComp : outerPanel.getComponents()) {
		if (innerComp != null && innerComp.getClass().getName().equals(VISUALIZATIONS_CLASS_NAME)) {
			// adjust settings
			String attributeName = model.getColumnName();
			try {
				if (model instanceof BeltNominalColumnStatisticsModel) {
					Method showAggregatedColumnChart = innerComp.getClass().getDeclaredMethod(SHOW_AGGREGATED_COLUMN_METHOD_NAME, String.class);
					showAggregatedColumnChart.setAccessible(true);
					showAggregatedColumnChart.invoke(innerComp, attributeName);
				} else if (model instanceof BeltNumericalColumnStatisticsModel
						|| model instanceof BeltDateTimeColumnStatisticsModel || model instanceof BeltTimeColumnStatisticsModel) {
					Method showHistogramChart = innerComp.getClass().getDeclaredMethod(SHOW_HISTOGRAM_METHOD_NAME, String.class);
					showHistogramChart.setAccessible(true);
					showHistogramChart.invoke(innerComp, attributeName);
				}
			} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e1) {
				LogService.getRoot().log(Level.WARNING, "com.rapidminer.gui.viewer.metadata.actions.OpenChartAction.cannot_show_visualization", e1);
			}
			break;
		}
	}
}
 
Example 4
Source File: TestObject.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    JPanel panel = (JPanel) decoder.readObject();
    if (2 != panel.getComponents().length) {
        throw new Error("unexpected component count");
    }
    JButton button = (JButton) panel.getComponents()[0];
    if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected button text");
    }
    if (SwingConstants.CENTER != button.getVerticalAlignment()) {
        throw new Error("unexpected vertical alignment");
    }
    JLabel label = (JLabel) panel.getComponents()[1];
    if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected label text");
    }
    if (button != label.getLabelFor()) {
        throw new Error("unexpected component");
    }
}
 
Example 5
Source File: WebProjectDDTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testDelListener() throws Exception {
    JPanel panel = utils.getInnerSectionPanel("listeners");
    Component[] comp = panel.getComponents();
    ListenersTablePanel listPanel = (ListenersTablePanel) comp[1];
    DDBeanTableModel model = (DDBeanTableModel) listPanel.getModel();
    int i;
    for (i = 0; i < model.getRowCount(); i++) {
        if (model.getValueAt(i, 0).equals("newlistmod")) {
            break;
        }
    }
    assertFalse("Listener not found", i == model.getRowCount());
    model.removeRow(i);
    ddObj.modelUpdatedFromUI();
    for (i = 0; i < model.getRowCount(); i++) {
        if (model.getValueAt(i, 0).equals("newlistmod")) {
            break;
        }
    }
    assertTrue("Listener not deleted from in table model", i == model.getRowCount());
    Thread.sleep(2000);
    utils.checkNotInDDXML(".* <listener>\\s*<description>newlistdescmod</description>\\s*<listener-class>mewlistmod</listener-class>\\s*</listener>.*");
    utils.save();
}
 
Example 6
Source File: SecurityDDTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testAddSecurityRole() throws Exception {
    JPanel panel = utils.getInnerSectionPanel("security_roles");
    Component[] comp = panel.getComponents();
    SecurityRoleTableModel model = (SecurityRoleTableModel) ((DefaultTablePanel) comp[0]).getModel();
    model.addRow(new Object[]{"user1", "user1desc"});
    ddObj.modelUpdatedFromUI();
    DDTestUtils.waitForDispatchThread();
    utils.save();
    assertEquals("Role not added", 3, model.getRowCount());
    ((Component) comp[0]).requestFocus();
    new StepIterator() {

        @Override
        public boolean step() throws Exception {
            return utils.contains(".*<security-role>\\s*<description>user1desc</description>\\s*<role-name>user1</role-name>\\s*</security-role>.*");
        }

        @Override
        public void finalCheck() {
            utils.checkInDDXML(".*<security-role>\\s*<description>user1desc</description>\\s*<role-name>user1</role-name>\\s*</security-role>.*");
        }
    };
}
 
Example 7
Source File: WebProjectDDTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testExistingFilters() throws Exception {
    ddObj.openView(6); // open Filters view
    Utils.waitForAWTDispatchThread();
    Filter[] filters = webapp.getFilter();
    assertEquals("Unexpected filter count", 1, filters.length);
    Filter filter = filters[0];
    ddObj.showElement(filter);
    JPanel panel = utils.getInnerSectionPanel(filter);
    Component[] comp = panel.getComponents();
    assertEquals("Filter name does not match", "FilterName", ((JTextField) comp[1]).getText());
    assertEquals("Filter description does not match", "FilterDescription", ((JTextArea) comp[3]).getText());
    assertEquals("Filter class does not match", "FilterClass", ((JTextField) comp[5]).getText());
    DDBeanTableModel model = (DDBeanTableModel) ((FilterParamsPanel) comp[9]).getModel();
    assertEquals("Unexpected filter params count", 1, model.getRowCount());
    utils.testTableRow(model, 0, new String[]{"FilterParamName", "FilterParamValue", "FilterParamDescription"});
    utils.testProperties(filter, new String[]{"FilterName", "FilterClass"}, new Object[]{"FilterName", "FilterClass"});
    assertEquals("Description does not match", "FilterDescription", filter.getDefaultDescription());
    assertEquals("Unexpected conut of filter init params", 1, filter.getInitParam().length);
    utils.testProperties(filter.getInitParam(0), new String[]{"ParamName", "ParamValue"}, new Object[]{"FilterParamName", "FilterParamValue"});
    assertEquals("Filter param description does not match.", "FilterParamDescription", filter.getInitParam(0).getDefaultDescription());
}
 
Example 8
Source File: TestObject.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    JPanel panel = (JPanel) decoder.readObject();
    if (2 != panel.getComponents().length) {
        throw new Error("unexpected component count");
    }
    JButton button = (JButton) panel.getComponents()[0];
    if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected button text");
    }
    if (SwingConstants.CENTER != button.getVerticalAlignment()) {
        throw new Error("unexpected vertical alignment");
    }
    JLabel label = (JLabel) panel.getComponents()[1];
    if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected label text");
    }
    if (button != label.getLabelFor()) {
        throw new Error("unexpected component");
    }
}
 
Example 9
Source File: MenuEditLayer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void rebuildOnScreenMenu(RADVisualContainer menuRAD) {
    if(menuRAD == null) return;
    if(hackedPopupFactory == null) return;
    JMenu menu = (JMenu) formDesigner.getComponent(menuRAD);
    if(hackedPopupFactory.containerMap.containsKey(menu)) {
        JPanel popupContainer = hackedPopupFactory.containerMap.get(menu);
        if(popupContainer == null) return;
        for(Component c : popupContainer.getComponents()) {
            if(c instanceof JMenu) {
                unconfigureMenu((JMenu)c);
            } else {
                unconfigureMenuItem((JComponent)c);
            }
        }
        popupContainer.removeAll();
        // rebuild it
        for(RADVisualComponent child : menuRAD.getSubComponents()) {
            if(child != null) {
                JComponent jchild = (JComponent) formDesigner.getComponent(child);
                if(!isConfigured(jchild)) {
                    if(jchild instanceof JMenu) {
                        configureMenu(menu, (JMenu)jchild);
                    } else {
                        configureMenuItem(menu,jchild);
                    }
                }
                popupContainer.add(jchild);
            }
        }
        
        // repack it
        popupContainer.setSize(popupContainer.getLayout().preferredLayoutSize(popupContainer));
        validate();
        popupContainer.repaint();
    }
}
 
Example 10
Source File: PagesAndReferencesDDTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testAddErrorPage() throws Exception {
    JPanel panel = utils.getInnerSectionPanel("error_pages");
    Component[] comp = panel.getComponents();
    DDBeanTableModel model = (DDBeanTableModel) ((ErrorPagesTablePanel) comp[1]).getTable().getModel();
    model.addRow(new Object[]{"/index2.jsp", null, "java.lang.NullPointerException"});
    ddObj.modelUpdatedFromUI();
    DDTestUtils.waitForDispatchThread();
    utils.save();
    assertEquals("Error page not added", 2, model.getRowCount());
    int i = 0;
    ErrorPage[] errorPages = webapp.getErrorPage();
    for (i = 0; i < errorPages.length; i++) {
        if (errorPages[i].getLocation().equals("/index2.jsp")) {
            break;
        }
    }
    assertTrue("New error page not found", i < errorPages.length);
    utils.testProperties(errorPages[i], new String[]{"Location", "ErrorCode", "ExceptionType"}, new Object[]{"/index2.jsp", null, "java.lang.NullPointerException"});
    for (i = 0; i < model.getRowCount(); i++) {
        if (model.getValueAt(i, 0).equals("/index2.jsp")) {
            break;
        }
    }
    assertTrue("New error page not found", i < model.getRowCount());
    utils.testTableRow(model, i, new String[]{"/index2.jsp", null, "java.lang.NullPointerException"});
    utils.checkInDDXML(".*<error-page>\\s*<exception-type>java.lang.NullPointerException</exception-type>\\s*<location>/index2.jsp</location>\\s*</error-page>.*");
}
 
Example 11
Source File: FreeColFileChooserUI.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void addControlButtons() {
    JPanel buttonPanel = getButtonPanel();
    Component[] buttons = buttonPanel.getComponents();
    buttonPanel.removeAll();
    for (int i=buttons.length-1; i>=0; i--) {
        buttonPanel.add(buttons[i]);
    }
    super.addControlButtons();
}
 
Example 12
Source File: Test6437265.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void validate(JPanel panel) {
    BorderLayout layout = (BorderLayout) panel.getLayout();
    for (Component component : panel.getComponents()) {
        String name = (String) layout.getConstraints(component);
        if (name == null)
            throw new Error("The component is not layed out: " + component);

        JLabel label = (JLabel) component;
        if (!name.equals(label.getText()))
            throw new Error("The component is layed out on " + name + ": " + component);
    }
}
 
Example 13
Source File: Test6437265.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void validate(JPanel panel) {
    BorderLayout layout = (BorderLayout) panel.getLayout();
    for (Component component : panel.getComponents()) {
        String name = (String) layout.getConstraints(component);
        if (name == null)
            throw new Error("The component is not layed out: " + component);

        JLabel label = (JLabel) component;
        if (!name.equals(label.getText()))
            throw new Error("The component is layed out on " + name + ": " + component);
    }
}
 
Example 14
Source File: SecurityDDTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testExistingSecurityRoles() throws Exception {
    JPanel panel = utils.getInnerSectionPanel("security_roles");
    Component[] comp = panel.getComponents();
    SecurityRoleTableModel model = (SecurityRoleTableModel) ((DefaultTablePanel) comp[0]).getModel();
    assertEquals("Wrong number of roles", 2, model.getRowCount());
    assertEquals("Wrong role name", "admin", model.getValueAt(0, 0));
    assertEquals("Wrong role description", "administrator", model.getValueAt(0, 1));
    assertEquals("Wrong role name", "user", model.getValueAt(1, 0));
    assertEquals("Wrong role description", "testuser", model.getValueAt(1, 1));

}
 
Example 15
Source File: ChoiceRowMatcher.java    From Ardulink-2 with Apache License 2.0 5 votes vote down vote up
private String components(JPanel item) {
	StringBuilder sb = new StringBuilder();
	for (Component component : item.getComponents()) {
		sb.append(component.getClass().getName()).append("\n");
	}
	return sb.toString();
}
 
Example 16
Source File: StreamPanel.java    From moa with GNU General Public License v3.0 5 votes vote down vote up
private void drawClusteringsOnCanvas(JPanel layer, Graphics2D imageGraphics){
    for(Component comp :layer.getComponents()){
        if(comp instanceof ClusterPanel){
            ClusterPanel cp = (ClusterPanel)comp;
            cp.drawOnCanvas(imageGraphics);
        }
    }
}
 
Example 17
Source File: DownloadDialogPanel.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
private void doSetStyle(JPanel panel) {
    synchronized (panel.getTreeLock()) {
        for (Component c : panel.getComponents()) {
            if (c instanceof JPanel) {
                doSetStyle((JPanel) c);
            }
            c.setFocusable(false);
        }
        if (this != panel) {
            panel.setOpaque(false);
        }
    }
}
 
Example 18
Source File: DDTestUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public DDBeanTableModel getServletInitParamsTableModel() {
    Servlet[] servlets = webapp.getServlet();
    JellyTestCase.assertEquals("Wrong count of servlets", 1, servlets.length);
    JPanel panel = getInnerSectionPanel(servlets[0]);
    Component[] comp = panel.getComponents();
    InitParamsPanel tablePanel = ((InitParamsPanel) comp[17]);
    return (DDBeanTableModel) tablePanel.getTable().getModel();
}
 
Example 19
Source File: LootTrackerBox.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private void applyDimmer(boolean brighten, JPanel panel)
{
	for (Component component : panel.getComponents())
	{
		Color color = component.getForeground();

		component.setForeground(brighten ? color.brighter() : color.darker());
	}
}
 
Example 20
Source File: WebProjectDDTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testModifyServlet() throws Exception {
    Servlet[] servlets = webapp.getServlet();
    assertEquals("Wrong count of servlets", 1, servlets.length);
    JPanel panel = utils.getInnerSectionPanel(servlets[0]);
    Component[] comp = panel.getComponents();
    utils.setText((JTextField) comp[1], "ServletNameMod");
    comp[3].requestFocus();
    new StepIterator() {

        @Override
        public boolean step() throws Exception {
            return utils.contains(".*<servlet>.*<servlet-name>ServletNameMod</servlet-name>.*</servlet>.*");
        }

        @Override
        public void finalCheck() {
            utils.checkInDDXML(".*<servlet>.*<servlet-name>ServletNameMod</servlet-name>.*</servlet>.*");
        }
    };
    utils.setText((JTextField) comp[3], "1");
    comp[5].requestFocus();
    new StepIterator() {

        @Override
        public boolean step() throws Exception {
            return utils.contains(".*<servlet>.*<load-on-startup>1</load-on-startup>.*</servlet>.*");
        }

        @Override
        public void finalCheck() {
            utils.checkInDDXML(".*<servlet>.*<load-on-startup>1</load-on-startup>.*</servlet>.*");
        }
    };
    utils.setText((JTextArea) comp[5], "ServletDescriptionMod");
    comp[9].requestFocus();
    new StepIterator() {

        @Override
        public boolean step() throws Exception {
            return utils.contains(".*<servlet>\\s*<description>ServletDescriptionMod</description>.*</servlet>.*");
        }

        @Override
        public void finalCheck() {
            utils.checkInDDXML(".*<servlet>\\s*<description>ServletDescriptionMod</description>.*</servlet>.*");
        }
    };
    ((JRadioButton) comp[9]).setSelected(true);
    comp[10].requestFocus();
    ddObj.modelUpdatedFromUI();
    Thread.sleep(2000);
    utils.setText((JTextField) comp[10], "JSPFile.jsp");
    comp[13].requestFocus();
    new StepIterator() {

        @Override
        public boolean step() throws Exception {
            return utils.contains(".*<servlet>.*<jsp-file>JSPFile.jsp</jsp-file>.*</servlet>.*");
        }

        @Override
        public void finalCheck() {
            utils.checkInDDXML(".*<servlet>.*<jsp-file>JSPFile.jsp</jsp-file>.*</servlet>.*");
        }
    };
    utils.setText((JTextField) comp[13], "/*");
    comp[1].requestFocus();
    new StepIterator() {

        @Override
        public boolean step() throws Exception {
            return utils.contains(".*<servlet-mapping>\\s*<servlet-name>ServletNameMod</servlet-name>\\s*<url-pattern>/\\*</url-pattern>\\s*</servlet-mapping>.*");
        }

        @Override
        public void finalCheck() {
            utils.checkInDDXML(".*<servlet-mapping>\\s*<servlet-name>ServletNameMod</servlet-name>\\s*<url-pattern>/\\*</url-pattern>\\s*</servlet-mapping>.*");
        }
    };
    Servlet servlet = servlets[0];
    utils.testProperties(servlet, new String[]{"ServletName", "LoadOnStartup", "JspFile"}, new Object[]{"ServletNameMod", new java.math.BigInteger("1"), "JSPFile.jsp"});
    ServletMapping[] mappings = webapp.getServletMapping();
    assertEquals("Wrong servlet mapping", 1, mappings.length);
    utils.testProperties(mappings[0], new String[]{"ServletName", "UrlPattern"}, new Object[]{"ServletNameMod", "/*"});
    utils.checkInDDXML(".*<servlet>\\s*<description>ServletDescriptionMod</description>\\s*<servlet-name>ServletNameMod</servlet-name>\\s*<jsp-file>JSPFile.jsp</jsp-file>.*<load-on-startup>1</load-on-startup>\\s*</servlet>.*");
    utils.checkInDDXML(".*<servlet-mapping>\\s*<servlet-name>ServletNameMod</servlet-name>\\s*<url-pattern>/\\*</url-pattern>\\s*</servlet-mapping>.*");
    utils.save();
}