@Override
  public JComponent createForm() {

    JComponent component = super.createForm();

    annotationComboBox.setRenderer(
        new DefaultListCellRenderer() {
          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value != null) {
              Annotation annotation = (Annotation) value;
              this.setText(annotation.getBrief());
            } else {
              this.setText("-- select annotation --");
            }
            return this;
          }
        });

    component.setLayout(new FormLayout("right:p, 4dlu, left:p", "p, 4dlu, p, 4dlu, p, 4dlu, p"));

    CellConstraints cc = new CellConstraints();

    component.add(getLabel("annotationLabel"), cc.xy(1, 1));
    component.add(annotationComboBox, cc.xy(3, 1));
    component.add(getLabel("patternLabel"), cc.xy(1, 3));
    component.add(patternField, cc.xy(3, 3));
    component.add(getLabel("ciLabel"), cc.xy(1, 5));
    component.add(caseInsensitive, cc.xy(3, 5));
    component.add(getLabel("remove"), cc.xy(1, 7));
    component.add(removeMatched, cc.xy(3, 7));

    patternField.setEnabled(false);
    caseInsensitive.setSelected(true);
    caseInsensitive.setEnabled(false);

    // action listener will fill out a suggested pattern for selected annotation types
    annotationComboBox.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Object obj = annotationComboBox.getSelectedItem();
            if (obj == null) {
              patternField.setEnabled(false);
              caseInsensitive.setEnabled(false);
              setEnabled(false);
            } else {
              patternField.setEnabled(true);
              caseInsensitive.setEnabled(true);
              patternField.setText(getDefault(obj.getClass()));
              patternField.setCaretPosition(0);
              setEnabled(true);
            }
          }
        });

    return component;
  }
示例#2
0
  /**
   * Constructs a popup using the specified settings.
   *
   * @param content The component that represents the popup content.
   * @param hideOnClick If <code>true</code> then the popup will hide when any area outside of it is
   *     clicked (rather like a popup menu). If <code>false</code> the popup will not hide when any
   *     area outside of it is clicked.
   * @param timerDelay The number of milliseconds after which the the popup will automatically hide
   *     itself. If a value of zero is specified, then the popup will remain displayed indefinitely.
   * @param isModal If <code>true</code>, mouse listener events that occur outside the component
   *     area are forwarded to the appropriate component in the content pane i.e other components
   *     may be interacted with whilst the popup is displayed. If <code>false</code> then the popup
   *     behaves rather like a modal dialog, so that no other components can receive mouse events
   *     until the component has closed.
   */
  public PopupComponent(JComponent content, boolean hideOnClick, int timerDelay, boolean isModal) {
    glassPane = new JPanel(null);

    glassPane.setLayout(null);

    glassPane.add(content);

    glassPane.setOpaque(false);

    listeners = new ArrayList<PopupComponentListener>();

    setupListeners();

    setContent(content);

    this.HIDE_ON_CLICK = hideOnClick;

    this.POPUP_IS_MODAL = isModal;

    // Check to see if a timer delay has been
    // specified.  If so, set up the timer.
    if (timerDelay > 0) {
      HIDE_ON_TIMER = true;

      HIDE_TIMER_DELAY = timerDelay;

      timer =
          new Timer(
              HIDE_TIMER_DELAY,
              new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                  // Hide the popup if the mouse is outside
                  // the content
                  if (mouseOverGlassPane == true) {
                    hidePopup();

                    timer.stop();
                  } else {
                    timer.stop();

                    timer.start();
                  }
                }
              });
    }
  }
示例#3
0
 /**
  * Called by the constructor methods to create the default <code>contentPane</code>. By default
  * this method creates a new <code>JComponent</code> add sets a <code>BorderLayout</code> as its
  * <code>LayoutManager</code>.
  *
  * @return the default <code>contentPane</code>
  */
 protected Container createContentPane() {
   JComponent c = new JPanel();
   c.setName(this.getName() + ".contentPane");
   c.setLayout(
       new BorderLayout() {
         /* This BorderLayout subclass maps a null constraint to CENTER.
          * Although the reference BorderLayout also does this, some VMs
          * throw an IllegalArgumentException.
          */
         public void addLayoutComponent(Component comp, Object constraints) {
           if (constraints == null) {
             constraints = BorderLayout.CENTER;
           }
           super.addLayoutComponent(comp, constraints);
         }
       });
   return c;
 }
  private void initProblemDefinition() {
    this.m_Mocco.m_JPanelParameters.removeAll();
    this.m_ProblemChooser = new JComboBox();
    JComponent tmpC = new JPanel();
    tmpC.setLayout(new BorderLayout());

    Class[] altern = null;
    try {
      altern =
          ReflectPackage.getAssignableClassesInPackage(
              "eva2.server.go.problems",
              Class.forName("eva2.server.go.problems.InterfaceMultiObjectiveDeNovoProblem"),
              true,
              true);
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    this.m_ProblemChooser.setModel(new DefaultComboBoxModel(altern));

    String objectName = (this.m_Mocco.m_State.m_OriginalProblem.getClass().getName());
    this.m_ProblemChooser.getModel().setSelectedItem(objectName);
    this.m_ProblemChooser.addActionListener(problemChanged);
    JPanel tmpP = new JPanel();
    tmpP.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 0;
    gbc.gridy = 0;
    tmpP.add(
        this.makeHelpText(
            "Choose and parameterize the optimization problem to solve by means of MOCCO. "
                + "Please note that it is not necessary to include MOSO converters yet and that only problems complying "
                + "with the InterfaceMultiObjectiveDeNovoProblem can be optimized using the MOCCO approach."),
        gbc);
    gbc.gridx = 0;
    gbc.gridy = 1;
    tmpP.add(this.m_ProblemChooser, gbc);
    this.m_Mocco.m_JPanelParameters.setLayout(new BorderLayout());
    this.m_Mocco.m_JPanelParameters.add(tmpP, BorderLayout.NORTH);
    JParaPanel paraPanel = new JParaPanel(this.m_Mocco.m_State.m_OriginalProblem, "MyGUI");
    this.m_Mocco.m_JPanelParameters.add(paraPanel.makePanel(), BorderLayout.CENTER);
  }
示例#5
0
文件: JSheet.java 项目: karlvr/Quaqua
  private static JSheet createSheet(final JOptionPane pane, Component parentComponent, int style) {
    Window window = getWindowForComponent(parentComponent);
    final JSheet sheet;
    if (window instanceof Frame) {
      sheet = new JSheet((Frame) window);
    } else {
      sheet = new JSheet((Dialog) window);
    }

    JComponent contentPane = (JComponent) sheet.getContentPane();
    contentPane.setLayout(new BorderLayout());

    if (isNativeSheetSupported()) {
      contentPane.setBorder(new EmptyBorder(12, 0, 0, 0));
    }

    contentPane.add(pane, BorderLayout.CENTER);
    sheet.setResizable(false);
    sheet.addWindowListener(
        new WindowAdapter() {

          private boolean gotFocus = false;

          @Override
          public void windowClosing(WindowEvent we) {
            pane.setValue(null);
          }

          @Override
          public void windowClosed(WindowEvent we) {
            if (pane.getValue() == JOptionPane.UNINITIALIZED_VALUE) {
              sheet.fireOptionSelected(pane);
            }
          }

          @Override
          public void windowGainedFocus(WindowEvent we) {
            // Once window gets focus, set initial focus
            if (!gotFocus) {
              // Ugly dirty hack: JOptionPane.selectInitialValue() is protected.
              // So we call directly into the UI. This may cause mayhem,
              // because we override the encapsulation.
              // pane.selectInitialValue();
              OptionPaneUI ui = pane.getUI();
              if (ui != null) {
                ui.selectInitialValue(pane);
              }
              gotFocus = true;
            }
          }
        });
    sheet.addComponentListener(
        new ComponentAdapter() {

          @Override
          public void componentShown(ComponentEvent ce) {
            // reset value to ensure closing works properly
            pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
          }
        });
    pane.addPropertyChangeListener(
        new PropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent event) {
            // Let the defaultCloseOperation handle the closing
            // if the user closed the window without selecting a button
            // (newValue = null in that case).  Otherwise, close the sheet.
            if (sheet.isVisible()
                && event.getSource() == pane
                && (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY))
                && event.getNewValue() != null
                && event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) {
              sheet.setVisible(false);
              sheet.fireOptionSelected(pane);
            }
          }
        });
    sheet.pack();
    return sheet;
  }
示例#6
0
 /**
  * This method sets the layout manager to be used with the JToolBar.
  *
  * @param mgr The Layout Manager used with the JToolBar.
  */
 public void setLayout(LayoutManager mgr) {
   super.setLayout(mgr);
   revalidate();
   repaint();
 } // setLayout()
  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();
  }
 protected void initLayout() {
   super.setLayout(new GridLayout(1, 1));
   super.add(_splitPane);
   _splitPane.setLayout(new SplitLayout(_orientation));
 }
  public BundleOptionsFrame(String displayName, String instanceName, List<OptionGroup> options) {
    setResizable(false);
    this.displayName = displayName;
    content = (JComponent) getContentPane();
    content.setLayout(new GridBagLayout());

    final BundleOptionsFrame frame = this;

    // Close button
    Action closeAction =
        new AbstractAction("Close") {
          @Override
          public void actionPerformed(ActionEvent e) {
            frame.setVisible(false);
          }
        };
    JButton close_button = new JButton(closeAction);
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = currentRow++;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(2, 2, 2, 2);
    content.add(close_button, c);

    // Escape key binding
    JComponent root = frame.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close");
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke("ctrl W"), "close");
    root.getActionMap().put("close", closeAction);

    if (instanceName != null) {
      // Predicate name
      StringOption opt = new StringOption();
      opt.setDisplayName("Predicate name");
      opt.setDefault(instanceName);
      instanceNameField = new StringField(opt);
      instanceNameField.addChangeListener(
          new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
              updateTitle();
            }
          });
      addField(instanceNameField);
      JTextField tf = (JTextField) instanceNameField.getComponent();
      tf.selectAll();
      tf.requestFocusInWindow();
    } else {
      // We're a codec; no instance name
      instanceNameField = null;
    }
    updateTitle();

    // Options
    ExampleField example = null;
    for (OptionGroup group : options) {
      addSeparator(group.getDisplayName());
      for (Option option : group.getOptions()) {
        OptionField field;
        if (option instanceof BooleanOption) {
          field = new BooleanField((BooleanOption) option);
        } else if (option instanceof StringOption) {
          field = new StringField((StringOption) option);
        } else if (option instanceof NumberOption) {
          field = new NumberField((NumberOption) option);
        } else if (option instanceof ChoiceOption) {
          field = new ChoiceField((ChoiceOption) option);
        } else if (option instanceof ExampleOption) {
          if (example != null) {
            throw new IllegalArgumentException("Cannot display more than one ExampleOption");
          }
          example = new ExampleField((ExampleOption) option);
          field = example;
        } else {
          throw new IllegalArgumentException("Unknown option type");
        }
        addField(field);
        optionFields.add(field);
      }
    }
    this.exampleField = example;

    pack();
  }