/** * Print Oarent of Component * * @param c component */ static void printParents(JComponent c) { if (c.getName() == null) c.setName("C" + String.valueOf(s_no++)); System.out.print(c.getName()); System.out.print(" - " + c.getClass().getName()); System.out.println( " ** " + c.isOpaque() + " bg=" + (c.getClientProperty(CompiereLookAndFeel.BACKGROUND) != null)); // Container container = c.getParent(); while (container != null) { System.out.print( " - " + container.getName() + " " + container.getClass().getName() + " ** " + container.isOpaque()); if (container instanceof JComponent) System.out.print( " bg=" + (((JComponent) container).getClientProperty(CompiereLookAndFeel.BACKGROUND) != null)); System.out.println(); container = container.getParent(); } } // printParents
private JPanel createTempPanel(JComponent... comps) { JPanel aPanel = new JPanel(new GridLayout(comps.length, 1, GAP_SIZE, GAP_SIZE)); JPanel bPanel = new JPanel(new GridLayout(comps.length, 1, GAP_SIZE, GAP_SIZE)); for (JComponent comp : comps) { JLabel label = new JLabel(String.format("%s:", comp.getName()), JLabel.RIGHT); if (comp.getName() == null) // 避免匿名组件 label.setText(null); // label.setBorder(BorderFactory.createEtchedBorder()); aPanel.add(label); bPanel.add(comp); } JPanel cPanel = new JPanel(new BorderLayout(BLANK_SIZE, BLANK_SIZE)); cPanel.add(aPanel, BorderLayout.WEST); cPanel.add(bPanel, BorderLayout.CENTER); return cPanel; }
public String toString() { String result = "ToolBarArea: WITH NUFIN IN IT"; if (component != null) { result = "ToolBarArea: " + component.hashCode() + " called " + component.getName(); } return result; }
@Override public void actionPerformed(ActionEvent e) { final JComponent source = (JComponent) e.getSource(); TabManager.createTab(source.getName()); }
/** * Constructs a default <code>JTable</code> that is initialized with a default data model, a * default column model, and a default selection model. The identifier JComponent is used to save * the state of the table columns in the actual view. Not using this one constructor may lead to * inconsistent behavior of the view if this JTable's parent component has no unique name. It is * recommended to use this constructor in Yabs. * * @see #createDefaultDataModel * @see #createDefaultColumnModel * @see #createDefaultSelectionModel */ public MPTable(JComponent identifier) { super(); setName("43"); if (identifier.getName() == null) { identifier.setName(identifier.getClass().getSimpleName()); } setPersistanceHandler(new TableViewPersistenceHandler(this, identifier)); }
@Override protected JComponent createControl() { JComponent pageComponentControl = getPageComponent().getControl(); if (pageComponentControl.getName() == null) { nameComponent(pageComponentControl, "Control"); } internalFrame = new JInternalFrame(); configureControl(); internalFrame.getContentPane().add(pageComponentControl, BorderLayout.CENTER); internalFrame.addInternalFrameListener(new InternalFrameHandler()); nameComponent(internalFrame, "Pane"); return internalFrame; }
/** Fetches any styles that match the passed into arguments into <code>matches</code>. */ private void getMatchingStyles(java.util.List matches, JComponent c, Region id) { String idName = id.getLowerCaseName(); String cName = c.getName(); if (cName == null) { cName = ""; } for (int counter = _styles.size() - 1; counter >= 0; counter--) { StyleAssociation sa = _styles.get(counter); String path; if (sa.getID() == NAME) { path = cName; } else { path = idName; } if (sa.matches(path) && matches.indexOf(sa.getStyle()) == -1) { matches.add(sa.getStyle()); } } }
@Override public Color getColor(SynthContext context, ColorType type) { JComponent c = context.getComponent(); Region id = context.getRegion(); int state = context.getComponentState(); if (c.getName() == "Table.cellRenderer") { if (type == ColorType.BACKGROUND) { return c.getBackground(); } if (type == ColorType.FOREGROUND) { return c.getForeground(); } } if (id == Region.LABEL && type == ColorType.TEXT_FOREGROUND) { type = ColorType.FOREGROUND; } // For the enabled state, prefer the widget's colors if (!id.isSubregion() && (state & SynthConstants.ENABLED) != 0) { if (type == ColorType.BACKGROUND) { return c.getBackground(); } else if (type == ColorType.FOREGROUND) { return c.getForeground(); } else if (type == ColorType.TEXT_FOREGROUND) { // If getForeground returns a non-UIResource it means the // developer has explicitly set the foreground, use it over // that of TEXT_FOREGROUND as that is typically the expected // behavior. Color color = c.getForeground(); if (color != null && !(color instanceof UIResource)) { return color; } } } return getColorForState(context, type); }
/** * Creates the menu bar * * @return Description of the Return Value */ public JToolBar createToolBar() { // Create the tool bar toolBar = new JToolBar(); toolBar.putClientProperty("jgoodies.headerStyle", "Both"); toolBar.setRollover(true); toolBar.setFloatable(false); for (int i = 0; i < beans.length; i++) { Icon icon; JButton button; try { final JComponent bean = beans[i]; URL iconURL = bean.getClass().getResource("images/" + bean.getName() + "Color16.gif"); icon = new ImageIcon(iconURL); button = new JButton(icon); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { installBean(bean); } }; button.addActionListener(actionListener); } catch (Exception e) { System.out.println("JCalendarDemo.createToolBar(): " + e); button = new JButton(beans[i].getName()); } button.setFocusPainted(false); toolBar.add(button); } return toolBar; }
/** * Installes a demo bean. * * @param bean the demo bean */ private void installBean(JComponent bean) { try { componentPanel.removeAll(); componentPanel.add(bean); BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass(), bean.getClass().getSuperclass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); propertyPanel.removeAll(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; propertyPanel.setLayout(gridbag); int count = 0; String[] types = new String[] { "class java.util.Locale", "boolean", "int", "class java.awt.Color", "class java.util.Date", "class java.lang.String" }; for (int t = 0; t < types.length; t++) { for (int i = 0; i < propertyDescriptors.length; i++) { if (propertyDescriptors[i].getWriteMethod() != null) { String type = propertyDescriptors[i].getPropertyType().toString(); final PropertyDescriptor propertyDescriptor = propertyDescriptors[i]; final JComponent currentBean = bean; final Method readMethod = propertyDescriptor.getReadMethod(); final Method writeMethod = propertyDescriptor.getWriteMethod(); if (type.equals(types[t]) && (((readMethod != null) && (writeMethod != null)) || ("class java.util.Locale".equals(type)))) { if ("boolean".equals(type)) { boolean isSelected = false; try { Boolean booleanObj = ((Boolean) readMethod.invoke(bean, (Object[]) null)); isSelected = booleanObj.booleanValue(); } catch (Exception e) { e.printStackTrace(); } final JCheckBox checkBox = new JCheckBox("", isSelected); checkBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (checkBox.isSelected()) { writeMethod.invoke(currentBean, new Object[] {new Boolean(true)}); } else { writeMethod.invoke(currentBean, new Object[] {new Boolean(false)}); } } catch (Exception e) { e.printStackTrace(); } } }); addProperty(propertyDescriptors[i], checkBox, gridbag); count += 1; } else if ("int".equals(type)) { JSpinField spinField = new JSpinField(); spinField.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { try { if (evt.getPropertyName().equals("value")) { writeMethod.invoke(currentBean, new Object[] {evt.getNewValue()}); } } catch (Exception e) { } } }); try { Integer integerObj = ((Integer) readMethod.invoke(bean, (Object[]) null)); spinField.setValue(integerObj.intValue()); } catch (Exception e) { e.printStackTrace(); } addProperty(propertyDescriptors[i], spinField, gridbag); count += 1; } else if ("class java.lang.String".equals(type)) { String string = ""; try { string = ((String) readMethod.invoke(bean, (Object[]) null)); } catch (Exception e) { e.printStackTrace(); } JTextField textField = new JTextField(string); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { writeMethod.invoke(currentBean, new Object[] {e.getActionCommand()}); } catch (Exception ex) { } } }; textField.addActionListener(actionListener); addProperty(propertyDescriptors[i], textField, gridbag); count += 1; } else if ("class java.util.Locale".equals(type)) { JLocaleChooser localeChooser = new JLocaleChooser(bean); localeChooser.setPreferredSize( new Dimension(200, localeChooser.getPreferredSize().height)); addProperty(propertyDescriptors[i], localeChooser, gridbag); count += 1; } else if ("class java.util.Date".equals(type)) { Date date = null; try { date = ((Date) readMethod.invoke(bean, (Object[]) null)); } catch (Exception e) { e.printStackTrace(); } JDateChooser dateChooser = new JDateChooser(date); dateChooser.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { try { if (evt.getPropertyName().equals("date")) { writeMethod.invoke(currentBean, new Object[] {evt.getNewValue()}); } } catch (Exception e) { } } }); addProperty(propertyDescriptors[i], dateChooser, gridbag); count += 1; } else if ("class java.awt.Color".equals(type)) { final JButton button = new JButton(); try { final Color colorObj = ((Color) readMethod.invoke(bean, (Object[]) null)); button.setText("..."); button.setBackground(colorObj); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { Color newColor = JColorChooser.showDialog( JCalendarDemo.this, "Choose Color", colorObj); button.setBackground(newColor); try { writeMethod.invoke(currentBean, new Object[] {newColor}); } catch (Exception e1) { e1.printStackTrace(); } } }; button.addActionListener(actionListener); } catch (Exception e) { e.printStackTrace(); } addProperty(propertyDescriptors[i], button, gridbag); count += 1; } } } } } URL iconURL = bean.getClass().getResource("images/" + bean.getName() + "Color16.gif"); ImageIcon icon = new ImageIcon(iconURL); componentTitlePanel.setTitle(bean.getName(), icon); bean.invalidate(); propertyPanel.invalidate(); componentPanel.invalidate(); componentPanel.repaint(); } catch (IntrospectionException e) { e.printStackTrace(); } }
/** * Returns the Insets. If <code>insets</code> is non-null the resulting insets will be placed in * it, otherwise a new Insets object will be created and returned. * * @param context SynthContext identifying requestor * @param insets Where to place Insets * @return Insets. */ @Override public Insets getInsets(SynthContext state, Insets insets) { Region id = state.getRegion(); JComponent component = state.getComponent(); String name = (id.isSubregion()) ? null : component.getName(); if (insets == null) { insets = new Insets(0, 0, 0, 0); } else { insets.top = insets.bottom = insets.left = insets.right = 0; } if (id == Region.ARROW_BUTTON || id == Region.BUTTON || id == Region.TOGGLE_BUTTON) { if ("Spinner.previousButton" == name || "Spinner.nextButton" == name) { return getSimpleInsets(state, insets, 1); } else { return getButtonInsets(state, insets); } } else if (id == Region.CHECK_BOX || id == Region.RADIO_BUTTON) { return getRadioInsets(state, insets); } else if (id == Region.MENU_BAR) { return getMenuBarInsets(state, insets); } else if (id == Region.MENU || id == Region.MENU_ITEM || id == Region.CHECK_BOX_MENU_ITEM || id == Region.RADIO_BUTTON_MENU_ITEM) { return getMenuItemInsets(state, insets); } else if (id == Region.FORMATTED_TEXT_FIELD) { return getTextFieldInsets(state, insets); } else if (id == Region.INTERNAL_FRAME) { insets = Metacity.INSTANCE.getBorderInsets(state, insets); } else if (id == Region.LABEL) { if ("TableHeader.renderer" == name) { return getButtonInsets(state, insets); } else if (component instanceof ListCellRenderer) { return getTextFieldInsets(state, insets); } else if ("Tree.cellRenderer" == name) { return getSimpleInsets(state, insets, 1); } } else if (id == Region.OPTION_PANE) { return getSimpleInsets(state, insets, 6); } else if (id == Region.POPUP_MENU) { return getSimpleInsets(state, insets, 2); } else if (id == Region.PROGRESS_BAR || id == Region.SLIDER || id == Region.TABBED_PANE || id == Region.TABBED_PANE_CONTENT || id == Region.TOOL_BAR || id == Region.TOOL_BAR_DRAG_WINDOW || id == Region.TOOL_TIP) { return getThicknessInsets(state, insets); } else if (id == Region.SCROLL_BAR) { return getScrollBarInsets(state, insets); } else if (id == Region.SLIDER_TRACK) { return getSliderTrackInsets(state, insets); } else if (id == Region.TABBED_PANE_TAB) { return getTabbedPaneTabInsets(state, insets); } else if (id == Region.TEXT_FIELD || id == Region.PASSWORD_FIELD) { if (name == "Tree.cellEditor") { return getSimpleInsets(state, insets, 1); } return getTextFieldInsets(state, insets); } else if (id == Region.SEPARATOR || id == Region.POPUP_MENU_SEPARATOR || id == Region.TOOL_BAR_SEPARATOR) { return getSeparatorInsets(state, insets); } else if (id == GTKEngine.CustomRegion.TITLED_BORDER) { return getThicknessInsets(state, insets); } return insets; }
/** @param splitPane */ public void setView(final JComponent splitPane) { this.setView(splitPane.getName()); }
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(); }
public void focusLost(FocusEvent e) { JComponent field = (JComponent) e.getComponent(); if (field.getName().compareTo("portField") == 0) { try { if (Integer.parseInt(portField.getText()) < 1) { portField.setText("1"); msgBox.append("Reset port to minimum value of 1\n"); Toolkit.getDefaultToolkit().beep(); } if (Integer.parseInt(portField.getText()) > 65535) { portField.setText(Integer.toString(65535)); msgBox.append("Reset port to maximum value of 65535\n"); Toolkit.getDefaultToolkit().beep(); } } catch (NumberFormatException e1) { msgBox.append( "Non integer '" + portField.getText() + "' in port field, restoring former value\n"); portField.setText(saveFocusString); Toolkit.getDefaultToolkit().beep(); } } // if portField else if (field.getName().compareTo("maxRecordField") == 0) { try { if (Integer.parseInt(maxRecordField.getText()) < 1) { msgBox.append("Reset Max Record to minimum value of 1\n"); maxRecordField.setText("1"); Toolkit.getDefaultToolkit().beep(); } if (Integer.parseInt(maxRecordField.getText()) > SeedSocket.MAX_RECORDS) { maxRecordField.setText(Integer.toString(SeedSocket.MAX_RECORDS)); msgBox.append("Reset Max Record to maximum value of " + SeedSocket.MAX_RECORDS + "\n"); Toolkit.getDefaultToolkit().beep(); } } catch (NumberFormatException e1) { msgBox.append( "Non integer '" + maxRecordField.getText() + "' in Max Record field, restoring former value\n"); maxRecordField.setText(saveFocusString); Toolkit.getDefaultToolkit().beep(); } } // if maxRecordField else if (field.getName().compareTo("stationField") == 0) { if (stationField.getText().length() < 1 || stationField.getText().length() > 5) { msgBox.append( "Station name '" + stationField.getText() + "' must be between 1 and 5 characters, restoring prior name.\n"); stationField.setText(saveFocusString); Toolkit.getDefaultToolkit().beep(); } } // if stationField else if (field.getName().compareTo("channelField") == 0) { if (channelField.getText().length() < 1 || channelField.getText().length() > 3) { msgBox.append( "Channel name '" + channelField.getText() + "' must be between 1 and 3 characters, restoring prior name.\n"); channelField.setText(saveFocusString); Toolkit.getDefaultToolkit().beep(); } } // if channelField else if (field.getName().compareTo("locationField") == 0) { if (locationField.getText().length() < 1 || locationField.getText().length() > 2) { msgBox.append( "Location name '" + locationField.getText() + "' must be between 1 and 2 characters, restoring prior name.\n"); locationField.setText(saveFocusString); Toolkit.getDefaultToolkit().beep(); } } // if locationField else if (field.getName().compareTo("startDateField") == 0) { if (startDateField.getText().length() != 10 || startDateField.getText().charAt(4) != '/' || startDateField.getText().charAt(7) != '/' || !Character.isDigit(startDateField.getText().charAt(0)) || !Character.isDigit(startDateField.getText().charAt(1)) || !Character.isDigit(startDateField.getText().charAt(2)) || !Character.isDigit(startDateField.getText().charAt(3)) || !Character.isDigit(startDateField.getText().charAt(5)) || !Character.isDigit(startDateField.getText().charAt(6)) || !Character.isDigit(startDateField.getText().charAt(8)) || !Character.isDigit(startDateField.getText().charAt(9))) { msgBox.append( "Invalid start date '" + startDateField.getText() + "', format is yyyy/mm/dd, restoring prior date.\n"); startDateField.setText(saveFocusString); Toolkit.getDefaultToolkit().beep(); } } // if startDateField else if (field.getName().compareTo("startTimeField") == 0) { if (startTimeField.getText().length() != 8 || startTimeField.getText().charAt(2) != ':' || startTimeField.getText().charAt(5) != ':' || !Character.isDigit(startTimeField.getText().charAt(0)) || !Character.isDigit(startTimeField.getText().charAt(1)) || !Character.isDigit(startTimeField.getText().charAt(3)) || !Character.isDigit(startTimeField.getText().charAt(4)) || !Character.isDigit(startTimeField.getText().charAt(6)) || !Character.isDigit(startTimeField.getText().charAt(7))) { msgBox.append( "Invalid start time '" + startTimeField.getText() + "', format is HH:MM:SS, restoring prior time.\n"); startTimeField.setText(saveFocusString); Toolkit.getDefaultToolkit().beep(); } } // if startTimeField else if (field.getName().compareTo("finishDateField") == 0) { if (finishDateField.getText().length() != 10 || finishDateField.getText().charAt(4) != '/' || finishDateField.getText().charAt(7) != '/' || !Character.isDigit(finishDateField.getText().charAt(0)) || !Character.isDigit(finishDateField.getText().charAt(1)) || !Character.isDigit(finishDateField.getText().charAt(2)) || !Character.isDigit(finishDateField.getText().charAt(3)) || !Character.isDigit(finishDateField.getText().charAt(5)) || !Character.isDigit(finishDateField.getText().charAt(6)) || !Character.isDigit(finishDateField.getText().charAt(8)) || !Character.isDigit(finishDateField.getText().charAt(9))) { msgBox.append( "Invalid finish date '" + finishDateField.getText() + "', format is yyyy/mm/dd, restoring prior date.\n"); finishDateField.setText(saveFocusString); Toolkit.getDefaultToolkit().beep(); } } // if finishDateField else if (field.getName().compareTo("finishTimeField") == 0) { if (finishTimeField.getText().length() != 8 || finishTimeField.getText().charAt(2) != ':' || finishTimeField.getText().charAt(5) != ':' || !Character.isDigit(finishTimeField.getText().charAt(0)) || !Character.isDigit(finishTimeField.getText().charAt(1)) || !Character.isDigit(finishTimeField.getText().charAt(3)) || !Character.isDigit(finishTimeField.getText().charAt(4)) || !Character.isDigit(finishTimeField.getText().charAt(6)) || !Character.isDigit(finishTimeField.getText().charAt(7))) { msgBox.append( "Invalid finish time '" + finishTimeField.getText() + "', format is HH:MM:SS, restoring prior time.\n"); finishTimeField.setText(saveFocusString); Toolkit.getDefaultToolkit().beep(); } } // if finishTimeField } // focusLost()