Example #1
0
 @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;
 }
Example #2
0
  @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);
  }
Example #3
0
  /**
   * 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;
  }
  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();
  }