public void destroyTitleBar() { int comp = nord.getComponentCount(); Component icomp; for (int i = 0; i < comp; i++) { icomp = nord.getComponent(i); if (icomp != null) { ListenerTools.removeListeners(icomp); icomp = null; } } ListenerTools.removeListeners(thisContent); comp = thisContent.getComponentCount(); for (int i = 0; i < comp; i++) { icomp = thisContent.getComponent(i); if (icomp != null) { ListenerTools.removeListeners(icomp); icomp = null; } } ListenerTools.removeListeners(inhalt); comp = inhalt.getComponentCount(); for (int i = 0; i < comp; i++) { icomp = inhalt.getComponent(i); if (icomp != null) { ListenerTools.removeListeners(icomp); icomp = null; } } }
public void testLayout() throws Exception { SwingMetawidget metawidget = new SwingMetawidget(); JComponent container = new JPanel(); // startLayout BoxLayout boxLayout = new BoxLayout(); boxLayout.startContainerLayout(container, metawidget); assertTrue(container.getLayout() instanceof javax.swing.BoxLayout); assertFalse((metawidget.getLayout() instanceof javax.swing.BoxLayout)); // layoutWidget assertEquals(0, container.getComponentCount()); Stub stub = new Stub(); boxLayout.layoutWidget(stub, PROPERTY, null, container, metawidget); assertEquals(0, container.getComponentCount()); stub.add(new JSpinner()); boxLayout.layoutWidget(stub, PROPERTY, null, container, metawidget); assertEquals(stub, container.getComponent(0)); assertEquals(1, container.getComponentCount()); boxLayout.layoutWidget(new JTextField(), PROPERTY, null, container, metawidget); assertTrue(container.getComponent(1) instanceof JTextField); assertEquals(2, container.getComponentCount()); }
protected void clear(JComponent comp) { int nCompCount = comp.getComponentCount(); ArrayList aListComps = new ArrayList(); for (int i = 0; i < comp.getComponentCount(); i++) { Component compChild = comp.getComponent(i); if (compChild instanceof JComponent) { JComponent jcomp = (JComponent) compChild; if (jcomp instanceof JCheckBox || jcomp instanceof JTextField) aListComps.add(comp); else clear(jcomp); } } clear(aListComps); }
public boolean isToDrawMacCorner() { if (!SystemInfo.isMac || myComponent.getComponentCount() <= 0) { return false; } if (myComponent.getComponentCount() > 0) { Component component = myComponent.getComponent(0); if (component instanceof JComponent && Boolean.TRUE.equals(((JComponent) component).getClientProperty(SUPPRESS_MAC_CORNER))) { return false; } } return true; }
public void testIntProperty() throws Exception { JComponent rootComponent = getInstrumentedRootComponent("TestIntProperty.form", "BindingTest"); assertEquals(1, rootComponent.getComponentCount()); JTextField textField = (JTextField) rootComponent.getComponent(0); assertEquals(37, textField.getColumns()); assertEquals(false, textField.isEnabled()); }
/** {@inheritDoc} */ @Override public Dimension getMaximumSize(JComponent c) { if (c.getComponentCount() > 0 && c.getLayout() != null) { return null; } AbstractButton b = (AbstractButton) c; SynthContext ss = getContext(c); Dimension size = ss.getStyle() .getGraphicsUtils(ss) .getMaximumSize( ss, ss.getStyle().getFont(ss), b.getText(), getSizingIcon(b), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), b.getIconTextGap(), b.getDisplayedMnemonicIndex()); return size; }
public void testCardLayoutShow() throws Exception { JComponent rootComponent = getInstrumentedRootComponent("TestCardLayoutShow.form", "BindingTest"); assertTrue(rootComponent.getLayout() instanceof CardLayout); assertEquals(rootComponent.getComponentCount(), 2); assertFalse(rootComponent.getComponent(0).isVisible()); assertTrue(rootComponent.getComponent(1).isVisible()); }
public void changeData(byte[] bytes) { if (mainPane.getComponentCount() > 0) { mainPane.removeAll(); } HexModel model = new HexModel(bytes); mainPane.add(new HexEditor(model)); mainPane.validate(); }
/** * Guarda el estado de un componente. Este proceso es recursivo. El estado se guarda en un array y * este array no es vaciado inicialmente. La idea es guardar en un disabled y recuperar en un * enabled y asegurarse que no puede ocurrir un disabled o un enabled dos veces. * * @param component */ private void saveComponentsStatus(JComponent component) { // Guardar estado StatusComponentStruct auxStatus = new StatusComponentStruct(); auxStatus.setEnabled(component.isEnabled()); auxStatus.setObject(component); statusList.add(auxStatus); for (int i = 0; i < component.getComponentCount(); i++) if (component.getComponent(i) instanceof JComponent) saveComponentsStatus((JComponent) component.getComponent(i)); }
private static int getSplitCount(JComponent component) { if (component.getComponentCount() > 0) { final JComponent firstChild = (JComponent) component.getComponent(0); if (firstChild instanceof Splitter) { final Splitter splitter = (Splitter) firstChild; return getSplitCount(splitter.getFirstComponent()) + getSplitCount(splitter.getSecondComponent()); } return 1; } return 0; }
public void setReports(JComponent menu, CreateReport cReport) { if (menu.getClass() == JMenuBar.class) { for (int i = 0; i < menu.getComponentCount(); i++) { setReports((JComponent) menu.getComponent(i), cReport); } } else if (menu.getClass() == JMenu.class) { for (int i = 0; i < ((JMenu) menu).getItemCount(); i++) { JMenuItem item = ((JMenu) menu).getItem(i); if (item.getClass() == JMenuItem.class) { Template template = new Template(); template.setDataTemplate( ToolsPrLib.getFullPath((String) item.getClientProperty("dataTemplate"))); template.setId((String) item.getClientProperty("uniqueID")); template.setName((String) item.getClientProperty("name")); template.setParams((String) item.getClientProperty("params")); template.setQuery((String) item.getClientProperty("query")); template.setRtfTemplate( ToolsPrLib.getFullPath((String) item.getClientProperty("rtfTemplate"))); String uniqueID = (String) item.getClientProperty("uniqueID"); if (uniqueID.indexOf("Export") >= 0) { String format = (String) item.getClientProperty("format"); Byte fopFormat = 0; if (format.toLowerCase().equals("excel")) { fopFormat = FOProcessor.FORMAT_EXCEL; } else if (format.toLowerCase().equals("pdf")) { fopFormat = FOProcessor.FORMAT_PDF; } else if (format.toLowerCase().equals("gif")) { fopFormat = FOProcessor.FORMAT_IMAGE_GIF; } else if (format.toLowerCase().equals("rtf")) { fopFormat = FOProcessor.FORMAT_RTF; } item.addActionListener(new ActionListenerJMenuItem(fopFormat, cReport)); } else { item.addActionListener( new ActionListenerJMenuItem(template, mainFrame.getLbActiveReport(), cReport)); } String def = (String) item.getClientProperty("default"); if ((def != null) && (def.toString().toLowerCase().equals("true"))) { mainFrame.getCreateReport().setTemplate(template); mainFrame.getLbActiveReport().setText(template.getName()); } } else if (item.getClass() == JMenu.class) { setReports((JMenu) item, cReport); } } } }
private JButton getButton(int direction) { if (_directionPanel == null) { return null; } for (int i = 0; i < _directionPanel.getComponentCount(); i++) { Component component = _directionPanel.getComponent(i); if (component instanceof DirectionButton) { if (((DirectionButton) component).getDirection() == direction) { return ((DirectionButton) component); } } } return null; }
public void testGridConstraints() throws Exception { JComponent rootComponent = getInstrumentedRootComponent("TestGridConstraints.form", "BindingTest"); assertEquals(1, rootComponent.getComponentCount()); final LayoutManager layout = rootComponent.getLayout(); assertTrue(isInstanceOf(layout, GridLayoutManager.class.getName())); final Object constraints = invokeMethod(layout, "getConstraints", new Class[] {int.class}, new Object[] {0}); assertTrue(isInstanceOf(constraints, GridConstraints.class.getName())); assertEquals(1, invokeMethod(constraints, "getColSpan")); assertEquals(1, invokeMethod(constraints, "getRowSpan")); }
/** Sets an empty border with consistent insets. */ private void configureEditorBorder(JComponent editor) { if ((editor instanceof JSpinner.DefaultEditor)) { JSpinner.DefaultEditor defaultEditor = (JSpinner.DefaultEditor) editor; JTextField editorField = defaultEditor.getTextField(); Insets insets = UIManager.getInsets("Spinner.defaultEditorInsets"); editorField.setBorder(new EmptyBorder(insets)); } else if ((editor instanceof JPanel) && (editor.getBorder() == null) && (editor.getComponentCount() > 0)) { JComponent editorField = (JComponent) editor.getComponent(0); Insets insets = UIManager.getInsets("Spinner.defaultEditorInsets"); editorField.setBorder(new EmptyBorder(insets)); } }
@Nullable private static JScrollBar findHorizontalScrollBar(Component c) { if (c == null) return null; if (c instanceof JScrollPane) { return ((JScrollPane) c).getHorizontalScrollBar(); } if (isDiagramViewComponent(c)) { final JComponent view = (JComponent) c; for (int i = 0; i < view.getComponentCount(); i++) { if (view.getComponent(i) instanceof JScrollBar) { final JScrollBar scrollBar = (JScrollBar) view.getComponent(i); if (scrollBar.getOrientation() == Adjustable.HORIZONTAL) { return scrollBar; } } } } return findHorizontalScrollBar(c.getParent()); }
/** * Recupera el estado de un componente y todos sus hijos, vaciando la pila de estados. Eso quiere * decir que no se podra volver a recuperar su estado sin haberlo guardado previamente. * * @param component */ private void restoreStatus(JComponent component) { boolean auxEnabled = false; boolean finded = false; // Buscar estado de dicho componente for (int i = 0; i < statusList.size(); i++) { StatusComponentStruct auxStatus = (StatusComponentStruct) statusList.get(i); if (auxStatus.getObject() == component) { auxEnabled = auxStatus.isEnabled(); statusList.remove(i); finded = true; break; } } // Asignar su estado if (finded) component.setEnabled(auxEnabled); for (int i = 0; i < component.getComponentCount(); i++) if (component.getComponent(i) instanceof JComponent) restoreStatus((JComponent) component.getComponent(i)); }
private void doSort() { if (mustSort && getComponentSpacing() < 0 && componentBox.getComponentCount() > 0) { setIgnoreAddRemoveNotify(true); mustSort = false; Component c; Component tc = topComponent != null ? topComponent.getComponent() : null; // componentBoxEnabled = false; // long millis = System.currentTimeMillis(); int index = 0; if (tc != null) { if (componentBox.getComponent(0) != tc) { componentBox.remove(tc); componentBox.add(tc, index); } index++; } int switc = 0; int size = layoutOrderList.size(); for (int i = 0; i < size; i++) { c = (Component) layoutOrderList.get(doReverseSort ? size - i - 1 : i); if (c != tc) { if (componentBox.getComponent(index) != c) { switc++; componentBox.remove(c); componentBox.add(c, index); } index++; } } setIgnoreAddRemoveNotify(false); /*System.out.print(" Box: "); for (int i = 0; i < componentBox.getComponentCount(); i++) System.out.print(componentBox.getComponent(i) + " "); System.out.println(); System.out.print(" Order: "); for (int i = 0; i < layoutOrderList.size(); i++) System.out.print(layoutOrderList.get(i) + " ");*/ // System.out.println(); /* long millis = System.currentTimeMillis(); componentBox.removeAll(); if (tc != null) componentBox.add(tc); int size = layoutOrderList.size(); for (int i = 0; i < size; i++) { c = (Component) layoutOrderList.get(doReverseSort ? size - i - 1 : i); if (c != tc) componentBox.add(c); }*/ // componentBoxEnabled = true; // System.out.println("Sorting " + scount++ + " time: " + (System.currentTimeMillis() - // millis) + " Sorted: " + switc); } }
public static void main(String args[]) { JComponent ch = new JComponent() {}; ch.getAccessibleContext(); ch.isFocusTraversable(); ch.setEnabled(false); ch.setEnabled(true); ch.requestFocus(); ch.requestFocusInWindow(); ch.getPreferredSize(); ch.getMaximumSize(); ch.getMinimumSize(); ch.contains(1, 2); Component c1 = ch.add(new Component() {}); Component c2 = ch.add(new Component() {}); Component c3 = ch.add(new Component() {}); Insets ins = ch.getInsets(); ch.getAlignmentY(); ch.getAlignmentX(); ch.getGraphics(); ch.setVisible(false); ch.setVisible(true); ch.setForeground(Color.red); ch.setBackground(Color.red); for (String font : Toolkit.getDefaultToolkit().getFontList()) { for (int j = 8; j < 17; j++) { Font f1 = new Font(font, Font.PLAIN, j); Font f2 = new Font(font, Font.BOLD, j); Font f3 = new Font(font, Font.ITALIC, j); Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j); ch.setFont(f1); ch.setFont(f2); ch.setFont(f3); ch.setFont(f4); ch.getFontMetrics(f1); ch.getFontMetrics(f2); ch.getFontMetrics(f3); ch.getFontMetrics(f4); } } ch.enable(); ch.disable(); ch.reshape(10, 10, 10, 10); ch.getBounds(new Rectangle(1, 1, 1, 1)); ch.getSize(new Dimension(1, 2)); ch.getLocation(new Point(1, 2)); ch.getX(); ch.getY(); ch.getWidth(); ch.getHeight(); ch.isOpaque(); ch.isValidateRoot(); ch.isOptimizedDrawingEnabled(); ch.isDoubleBuffered(); ch.getComponentCount(); ch.countComponents(); ch.getComponent(1); ch.getComponent(2); Component[] cs = ch.getComponents(); ch.getLayout(); ch.setLayout(new FlowLayout()); ch.doLayout(); ch.layout(); ch.invalidate(); ch.validate(); ch.remove(0); ch.remove(c2); ch.removeAll(); ch.preferredSize(); ch.minimumSize(); ch.getComponentAt(1, 2); ch.locate(1, 2); ch.getComponentAt(new Point(1, 2)); ch.isFocusCycleRoot(new Container()); ch.transferFocusBackward(); ch.setName("goober"); ch.getName(); ch.getParent(); ch.getGraphicsConfiguration(); ch.getTreeLock(); ch.getToolkit(); ch.isValid(); ch.isDisplayable(); ch.isVisible(); ch.isShowing(); ch.isEnabled(); ch.enable(false); ch.enable(true); ch.enableInputMethods(false); ch.enableInputMethods(true); ch.show(); ch.show(false); ch.show(true); ch.hide(); ch.getForeground(); ch.isForegroundSet(); ch.getBackground(); ch.isBackgroundSet(); ch.getFont(); ch.isFontSet(); Container c = new Container(); c.add(ch); ch.getLocale(); for (Locale locale : Locale.getAvailableLocales()) ch.setLocale(locale); ch.getColorModel(); ch.getLocation(); boolean exceptions = false; try { ch.getLocationOnScreen(); } catch (IllegalComponentStateException e) { exceptions = true; } if (!exceptions) throw new RuntimeException("IllegalComponentStateException did not occur when expected"); ch.location(); ch.setLocation(1, 2); ch.move(1, 2); ch.setLocation(new Point(1, 2)); ch.getSize(); ch.size(); ch.setSize(1, 32); ch.resize(1, 32); ch.setSize(new Dimension(1, 32)); ch.resize(new Dimension(1, 32)); ch.getBounds(); ch.bounds(); ch.setBounds(10, 10, 10, 10); ch.setBounds(new Rectangle(10, 10, 10, 10)); ch.isLightweight(); ch.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); ch.getCursor(); ch.isCursorSet(); ch.inside(1, 2); ch.contains(new Point(1, 2)); ch.isFocusable(); ch.setFocusable(true); ch.setFocusable(false); ch.transferFocus(); ch.getFocusCycleRootAncestor(); ch.nextFocus(); ch.transferFocusUpCycle(); ch.hasFocus(); ch.isFocusOwner(); ch.toString(); ch.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); ch.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); ch.setComponentOrientation(ComponentOrientation.UNKNOWN); ch.getComponentOrientation(); }
/** * Gets the number of <tt>Component</tt>s in a specific <tt>JComponent</tt> container. For * example, returns the result of <tt>getMenuComponentCount()</tt> if <tt>container</tt> is an * instance of <tt>JMenu</tt>. * * @param container the <tt>JComponent</tt> container to get the number of <tt>Component</tt>s of * @return the number of <tt>Component</tt>s in the specified <tt>container</tt> */ protected int getComponentCount(JComponent container) { return (container instanceof JMenu) ? ((JMenu) container).getMenuComponentCount() : container.getComponentCount(); }
public void testClientProp() throws Exception { // IDEA-46372 JComponent rootComponent = getInstrumentedRootComponent("TestClientProp.form", "BindingTest"); assertEquals(1, rootComponent.getComponentCount()); JTable table = (JTable) rootComponent.getComponent(0); assertSame(Boolean.TRUE, table.getClientProperty("terminateEditOnFocusLost")); }
/** * Desactivar el componente y todos sus hijos sin guardar los estados. Hay que tener cuidado con * no confundirlo con setEnabled(false). Este metodo nunca guardara el estado, asi que no se podra * recuperar despues dicho estado. * * @param component */ public static void setDisabled(JComponent component) { component.setEnabled(false); for (int i = 0; i < component.getComponentCount(); i++) if (component.getComponent(i) instanceof JComponent) setDisabled((JComponent) component.getComponent(i)); }