/** Initialisiert die Komponenten. */
  private void initComponents() {

    setBorder(border);

    phone.setMinimumSize(new Dimension(120, 20));
    phone.setPreferredSize(new Dimension(120, 20));

    fax.setMinimumSize(new Dimension(120, 20));
    fax.setPreferredSize(new Dimension(120, 20));

    email.setMinimumSize(new Dimension(120, 20));
    email.setPreferredSize(new Dimension(120, 20));
  }
 public void addGroupComponent(JComponent component) {
   handleComponentAdded(component);
   Insets insets;
   if (currentRow == 0) {
     insets = INSETS;
   } else if (component instanceof JRadioButton) {
     insets = INSETS;
   } else if (component instanceof JCheckBox) {
     insets = INSETS;
   } else {
     insets = new Insets(4, 0, 4, 0);
   }
   backingPanel.add(
       component,
       new GridBagConstraints(
           1,
           currentRow,
           2,
           1,
           100,
           0,
           GridBagConstraints.BASELINE_LEADING,
           GridBagConstraints.NONE,
           insets,
           0,
           0));
   if (component instanceof JTextField) {
     JTextField field = (JTextField) component;
     field.setMinimumSize(field.getPreferredSize());
   }
   currentRow++;
 }
 public void addIndentedGroupComponent(JComponent component) {
   handleComponentAdded(component);
   backingPanel.add(
       component,
       new GridBagConstraints(
           1,
           currentRow,
           2,
           1,
           100,
           0,
           GridBagConstraints.BASELINE_LEADING,
           GridBagConstraints.NONE,
           new Insets(0, 50, 0, 0),
           0,
           0));
   if (component instanceof JTextField) {
     JTextField field = (JTextField) component;
     field.setMinimumSize(field.getPreferredSize());
   }
   currentRow++;
 }
Exemplo n.º 4
0
  /*
   * Create and set up a new CoreqPanel that is the correct size. Do not allow the user to modify any
   * of the characteristics of the panel; the panel will be the same for any course.
   */
  public CoreqPanel() {
    this.setMinimumSize(new Dimension(800, 25));
    this.setMaximumSize(new Dimension(2600, 26));
    this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    coreqField = new JTextField();
    coreqField.setMinimumSize(new Dimension(300, 20));
    coreqField.setMaximumSize(new Dimension(2000, 21));

    coreqType = new JComboBox();
    coreqType.addItem("Credits");
    coreqType.addItem("Course");
    coreqType.addItem("Requirement");

    coreqType.setMinimumSize(new Dimension(100, 20));
    coreqType.setMaximumSize(new Dimension(100, 21));
    JLabel coreqName = new JLabel("Name of Corequisite: ");

    this.add(coreqName);
    this.add(coreqField);
    this.add(Box.createRigidArea(new Dimension(10, 0)));
    this.add(coreqType);
    this.add(Box.createGlue());
  }
Exemplo n.º 5
0
  void jbInit() throws Exception {
    titledBorder1 =
        new TitledBorder(
            BorderFactory.createLineBorder(new Color(153, 153, 153), 2), "Assembler messages");
    this.getContentPane().setLayout(borderLayout1);

    this.setIconifiable(true);
    this.setMaximizable(true);
    this.setResizable(true);

    this.setTitle("EDIT");

    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splitPane.setDividerLocation(470);
    sourceArea.setFont(new java.awt.Font("Monospaced", 0, 12));
    controlPanel.setLayout(gridBagLayout1);
    controlPanel.setBorder(BorderFactory.createLoweredBevelBorder());
    positionPanel.setLayout(gridBagLayout2);
    fileLabel.setText("Source file:");
    fileText.setEditable(false);
    browseButton.setSelected(false);
    browseButton.setText("Browse ...");
    assembleButton.setEnabled(false);
    assembleButton.setText("Assemble file");
    saveButton.setEnabled(false);
    saveButton.setText("Save file");
    lineLabel.setText("Line:");
    lineText.setMinimumSize(new Dimension(50, 20));
    lineText.setPreferredSize(new Dimension(50, 20));
    lineText.setEditable(false);
    columnLabel.setText("Column:");
    columnText.setMinimumSize(new Dimension(41, 20));
    columnText.setPreferredSize(new Dimension(41, 20));
    columnText.setEditable(false);
    columnText.setText("");
    messageScrollPane.setBorder(titledBorder1);
    messageScrollPane.setMinimumSize(new Dimension(33, 61));
    messageScrollPane.setPreferredSize(new Dimension(60, 90));
    optionsButton.setEnabled(false);
    optionsButton.setText("Assembler options ...");
    messageScrollPane.getViewport().add(messageList, null);
    messageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    this.getContentPane().add(splitPane, BorderLayout.CENTER);
    splitPane.add(textScrollPane, JSplitPane.TOP);
    splitPane.add(controlPanel, JSplitPane.BOTTOM);
    textScrollPane.getViewport().add(sourceArea, null);

    controlPanel.add(
        fileLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        fileText,
        new GridBagConstraints(
            1,
            0,
            3,
            1,
            1.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        browseButton,
        new GridBagConstraints(
            4,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 5),
            0,
            0));
    controlPanel.add(
        optionsButton,
        new GridBagConstraints(
            2,
            1,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        assembleButton,
        new GridBagConstraints(
            3,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        saveButton,
        new GridBagConstraints(
            4,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 5),
            0,
            0));
    controlPanel.add(
        positionPanel,
        new GridBagConstraints(
            0,
            1,
            2,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    positionPanel.add(
        lineLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));
    positionPanel.add(
        lineText,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 5, 0, 0),
            0,
            0));
    positionPanel.add(
        columnLabel,
        new GridBagConstraints(
            2,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 10, 0, 0),
            0,
            0));
    positionPanel.add(
        columnText,
        new GridBagConstraints(
            3,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        messageScrollPane,
        new GridBagConstraints(
            0,
            2,
            5,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));
  }
Exemplo n.º 6
0
 void jbInit() throws Exception {
   border1 = BorderFactory.createEmptyBorder(10, 10, 5, 5);
   panel1.setLayout(borderLayout1);
   jPanel1.setLayout(borderLayout2);
   jScrollPane1.getViewport().setBackground(Color.white);
   jPanel2.setLayout(gridBagLayout1);
   jLabel1.setText("Profile Name : ");
   nameTextField.setMinimumSize(new Dimension(4, 18));
   nameTextField.setPreferredSize(new Dimension(63, 18));
   jLabel2.setText("Profile Type : ");
   openButton.setMaximumSize(new Dimension(73, 24));
   openButton.setMinimumSize(new Dimension(73, 24));
   openButton.setPreferredSize(new Dimension(73, 24));
   openButton.setText("Open");
   openButton.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           openButton_actionPerformed(e);
         }
       });
   cancelButton.setMaximumSize(new Dimension(73, 24));
   cancelButton.setMinimumSize(new Dimension(73, 24));
   cancelButton.setPreferredSize(new Dimension(73, 24));
   cancelButton.setMargin(new Insets(0, 5, 0, 5));
   cancelButton.setText("Cancel");
   cancelButton.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           cancelButton_actionPerformed(e);
         }
       });
   profileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   profileList.addMouseListener(
       new java.awt.event.MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
           profileList_mouseClicked(e);
         }
       });
   jPanel2.setBorder(border1);
   typeComboBox.setMaximumSize(new Dimension(32767, 18));
   typeComboBox.setMinimumSize(new Dimension(122, 18));
   typeComboBox.setPreferredSize(new Dimension(176, 18));
   getContentPane().add(panel1);
   panel1.add(jPanel1, BorderLayout.CENTER);
   jPanel1.add(jScrollPane1, BorderLayout.CENTER);
   panel1.add(jPanel2, BorderLayout.SOUTH);
   jPanel2.add(
       jLabel1,
       new GridBagConstraints(
           0,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.HORIZONTAL,
           new Insets(0, 0, 7, 0),
           0,
           0));
   jPanel2.add(
       nameTextField,
       new GridBagConstraints(
           1,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.HORIZONTAL,
           new Insets(0, 11, 7, 0),
           0,
           0));
   jPanel2.add(
       jLabel2,
       new GridBagConstraints(
           0,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.HORIZONTAL,
           new Insets(0, 0, 17, 0),
           0,
           0));
   jScrollPane1.getViewport().add(profileList, null);
   jPanel2.add(
       openButton,
       new GridBagConstraints(
           3,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.NONE,
           new Insets(0, 11, 2, 10),
           0,
           0));
   jPanel2.add(
       cancelButton,
       new GridBagConstraints(
           3,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.NONE,
           new Insets(0, 11, 9, 10),
           0,
           0));
   jPanel2.add(
       typeComboBox,
       new GridBagConstraints(
           1,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.HORIZONTAL,
           new Insets(0, 11, 17, 0),
           0,
           0));
 }
Exemplo n.º 7
0
  public void show(List<Rule> rules) {
    if (original != null) config.restoreState(original);
    dialog = new JDialog(owner, true);
    dialog.setTitle(messages.getString("guiConfigWindowTitle"));

    Collections.sort(rules, new CategoryComparator());

    // close dialog when user presses Escape key:
    final KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    final ActionListener actionListener =
        new ActionListener() {
          @Override
          public void actionPerformed(@SuppressWarnings("unused") ActionEvent actionEvent) {
            dialog.setVisible(false);
          }
        };
    final JRootPane rootPane = dialog.getRootPane();
    rootPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);

    // JPanel
    final JPanel checkBoxPanel = new JPanel();
    checkBoxPanel.setLayout(new GridBagLayout());
    GridBagConstraints cons = new GridBagConstraints();
    cons.anchor = GridBagConstraints.NORTHWEST;
    cons.gridx = 0;
    cons.weightx = 1.0;
    cons.weighty = 1.0;
    cons.fill = GridBagConstraints.BOTH;
    DefaultMutableTreeNode rootNode = createTree(rules);
    DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
    treeModel.addTreeModelListener(
        new TreeModelListener() {

          @Override
          public void treeNodesChanged(TreeModelEvent e) {
            DefaultMutableTreeNode node =
                (DefaultMutableTreeNode) e.getTreePath().getLastPathComponent();
            int index = e.getChildIndices()[0];
            node = (DefaultMutableTreeNode) (node.getChildAt(index));
            if (node instanceof RuleNode) {
              RuleNode o = (RuleNode) node;
              if (o.getRule().isDefaultOff()) {
                if (o.isEnabled()) {
                  config.getEnabledRuleIds().add(o.getRule().getId());
                } else {
                  config.getEnabledRuleIds().remove(o.getRule().getId());
                }
              } else {
                if (o.isEnabled()) {
                  config.getDisabledRuleIds().remove(o.getRule().getId());
                } else {
                  config.getDisabledRuleIds().add(o.getRule().getId());
                }
              }
            }
            if (node instanceof CategoryNode) {
              CategoryNode o = (CategoryNode) node;
              if (o.isEnabled()) {
                config.getDisabledCategoryNames().remove(o.getCategory().getName());
              } else {
                config.getDisabledCategoryNames().add(o.getCategory().getName());
              }
            }
          }

          @Override
          public void treeNodesInserted(TreeModelEvent e) {}

          @Override
          public void treeNodesRemoved(TreeModelEvent e) {}

          @Override
          public void treeStructureChanged(TreeModelEvent e) {}
        });
    configTree = new JTree(treeModel);
    configTree.setRootVisible(false);
    configTree.setEditable(false);
    configTree.setCellRenderer(new CheckBoxTreeCellRenderer());
    TreeListener.install(configTree);
    checkBoxPanel.add(configTree, cons);

    MouseAdapter ma =
        new MouseAdapter() {
          private void handlePopupEvent(MouseEvent e) {
            final JTree tree = (JTree) e.getSource();

            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
              return;
            }

            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();

            TreePath[] paths = tree.getSelectionPaths();

            boolean isSelected = false;
            if (paths != null) {
              for (TreePath selectionPath : paths) {
                if (selectionPath.equals(path)) {
                  isSelected = true;
                }
              }
            }
            if (!isSelected) {
              tree.setSelectionPath(path);
            }
            if (node.isLeaf()) {
              JPopupMenu popup = new JPopupMenu();
              final JMenuItem aboutRuleMenuItem =
                  new JMenuItem(messages.getString("guiAboutRuleMenu"));
              aboutRuleMenuItem.addActionListener(
                  new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                      RuleNode node = (RuleNode) tree.getSelectionPath().getLastPathComponent();
                      Rule rule = node.getRule();
                      Language lang = config.getLanguage();
                      if (lang == null) {
                        lang = Language.getLanguageForLocale(Locale.getDefault());
                      }
                      Tools.showRuleInfoDialog(
                          tree,
                          messages.getString("guiAboutRuleTitle"),
                          rule.getDescription(),
                          rule,
                          messages,
                          lang.getShortNameWithCountryAndVariant());
                    }
                  });
              popup.add(aboutRuleMenuItem);
              popup.show(tree, e.getX(), e.getY());
            }
          }

          @Override
          public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
              handlePopupEvent(e);
            }
          }

          @Override
          public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
              handlePopupEvent(e);
            }
          }
        };
    configTree.addMouseListener(ma);
    final JPanel treeButtonPanel = new JPanel();
    cons = new GridBagConstraints();
    cons.gridx = 0;
    cons.gridy = 0;
    final JButton expandAllButton = new JButton(messages.getString("guiExpandAll"));
    treeButtonPanel.add(expandAllButton, cons);
    expandAllButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            TreeNode root = (TreeNode) configTree.getModel().getRoot();
            TreePath parent = new TreePath(root);
            for (Enumeration categ = root.children(); categ.hasMoreElements(); ) {
              TreeNode n = (TreeNode) categ.nextElement();
              TreePath child = parent.pathByAddingChild(n);
              configTree.expandPath(child);
            }
          }
        });

    cons.gridx = 1;
    cons.gridy = 0;
    final JButton collapseAllbutton = new JButton(messages.getString("guiCollapseAll"));
    treeButtonPanel.add(collapseAllbutton, cons);
    collapseAllbutton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            TreeNode root = (TreeNode) configTree.getModel().getRoot();
            TreePath parent = new TreePath(root);
            for (Enumeration categ = root.children(); categ.hasMoreElements(); ) {
              TreeNode n = (TreeNode) categ.nextElement();
              TreePath child = parent.pathByAddingChild(n);
              configTree.collapsePath(child);
            }
          }
        });

    final JPanel motherTonguePanel = new JPanel();
    motherTonguePanel.add(new JLabel(messages.getString("guiMotherTongue")), cons);
    motherTongueBox = new JComboBox(getPossibleMotherTongues());
    if (config.getMotherTongue() != null) {
      motherTongueBox.setSelectedItem(config.getMotherTongue().getTranslatedName(messages));
    }
    motherTongueBox.addItemListener(
        new ItemListener() {

          @Override
          public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
              Language motherTongue;
              if (motherTongueBox.getSelectedItem() instanceof String) {
                motherTongue =
                    getLanguageForLocalizedName(motherTongueBox.getSelectedItem().toString());
              } else {
                motherTongue = (Language) motherTongueBox.getSelectedItem();
              }
              config.setMotherTongue(motherTongue);
            }
          }
        });
    motherTonguePanel.add(motherTongueBox, cons);

    final JPanel portPanel = new JPanel();
    portPanel.setLayout(new GridBagLayout());
    // TODO: why is this now left-aligned?!?!
    cons = new GridBagConstraints();
    cons.insets = new Insets(0, 4, 0, 0);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.anchor = GridBagConstraints.WEST;
    cons.fill = GridBagConstraints.NONE;
    cons.weightx = 0.0f;
    if (!insideOOo) {
      serverCheckbox = new JCheckBox(Tools.getLabel(messages.getString("guiRunOnPort")));
      serverCheckbox.setMnemonic(Tools.getMnemonic(messages.getString("guiRunOnPort")));
      serverCheckbox.setSelected(config.getRunServer());
      portPanel.add(serverCheckbox, cons);
      serverCheckbox.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
              serverPortField.setEnabled(serverCheckbox.isSelected());
              serverSettingsCheckbox.setEnabled(serverCheckbox.isSelected());
            }
          });
      serverCheckbox.addItemListener(
          new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
              config.setRunServer(serverCheckbox.isSelected());
            }
          });

      serverPortField = new JTextField(Integer.toString(config.getServerPort()));
      serverPortField.setEnabled(serverCheckbox.isSelected());
      serverSettingsCheckbox = new JCheckBox(Tools.getLabel(messages.getString("useGUIConfig")));
      // TODO: without this the box is just a few pixels small, but why??:
      serverPortField.setMinimumSize(new Dimension(100, 25));
      cons.gridx = 1;
      portPanel.add(serverPortField, cons);
      serverPortField
          .getDocument()
          .addDocumentListener(
              new DocumentListener() {

                @Override
                public void insertUpdate(DocumentEvent e) {
                  changedUpdate(e);
                }

                @Override
                public void removeUpdate(DocumentEvent e) {
                  changedUpdate(e);
                }

                @Override
                public void changedUpdate(DocumentEvent e) {
                  try {
                    int serverPort = Integer.parseInt(serverPortField.getText());
                    if (serverPort > -1 && serverPort < 65536) {
                      serverPortField.setForeground(null);
                      config.setServerPort(serverPort);
                    } else {
                      serverPortField.setForeground(Color.RED);
                    }
                  } catch (NumberFormatException ex) {
                    serverPortField.setForeground(Color.RED);
                  }
                }
              });

      cons.gridx = 0;
      cons.gridy = 10;
      serverSettingsCheckbox.setMnemonic(Tools.getMnemonic(messages.getString("useGUIConfig")));
      serverSettingsCheckbox.setSelected(config.getUseGUIConfig());
      serverSettingsCheckbox.setEnabled(config.getRunServer());
      serverSettingsCheckbox.addItemListener(
          new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
              config.setUseGUIConfig(serverSettingsCheckbox.isSelected());
            }
          });
      portPanel.add(serverSettingsCheckbox, cons);
    }

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    okButton = new JButton(Tools.getLabel(messages.getString("guiOKButton")));
    okButton.setMnemonic(Tools.getMnemonic(messages.getString("guiOKButton")));
    okButton.addActionListener(this);
    cancelButton = new JButton(Tools.getLabel(messages.getString("guiCancelButton")));
    cancelButton.setMnemonic(Tools.getMnemonic(messages.getString("guiCancelButton")));
    cancelButton.addActionListener(this);
    cons = new GridBagConstraints();
    cons.insets = new Insets(0, 4, 0, 0);
    buttonPanel.add(okButton, cons);
    buttonPanel.add(cancelButton, cons);

    final Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new GridBagLayout());
    cons = new GridBagConstraints();
    cons.insets = new Insets(4, 4, 4, 4);
    cons.gridx = 0;
    cons.gridy = 0;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.fill = GridBagConstraints.BOTH;
    contentPane.add(new JScrollPane(checkBoxPanel), cons);

    cons.gridx = 0;
    cons.gridy = 1;
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.LINE_END;
    contentPane.add(treeButtonPanel, cons);

    cons.gridx = 0;
    cons.gridy = 2;
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.WEST;
    contentPane.add(motherTonguePanel, cons);

    cons.gridx = 0;
    cons.gridy = 3;
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.WEST;
    contentPane.add(portPanel, cons);

    cons.gridx = 0;
    cons.gridy = 4;
    cons.weightx = 0.0f;
    cons.weighty = 0.0f;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.EAST;
    contentPane.add(buttonPanel, cons);

    dialog.pack();
    dialog.setSize(500, 500);
    // center on screen:
    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    final Dimension frameSize = dialog.getSize();
    dialog.setLocation(
        screenSize.width / 2 - frameSize.width / 2, screenSize.height / 2 - frameSize.height / 2);
    dialog.setLocationByPlatform(true);
    dialog.setVisible(true);
  }
Exemplo n.º 8
0
  /**
   * This method represents the window in which the preferred parameters for the obix components can
   * be chosen.
   *
   * @param chosenComponents The list of {@link ObixObject} which have been chosen in the previous
   *     window.
   * @return The container in which the preferred parameters for the obix components can be chosen.
   */
  private Container chooseParameters(List<ObixObject> chosenComponents) {
    Container pane = new Container();
    pane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    pane.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    Font titelF = new Font("Courier", Font.BOLD, 30);
    title = new JLabel("Please choose the appropriate Parameters for the datapoints");
    title.setFont(titelF);

    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridwidth = 10;
    c.gridx = 0;
    c.gridy = 0;
    pane.add(title, c);

    List<String> parametersList = Configurator.getInstance().getAvailableParameterTypes();
    String[] parameterTypes = new String[parametersList.size()];
    parameterTypes = parametersList.toArray(parameterTypes);

    for (ObixObject o : chosenComponents) {
      c.gridy++;
      c.insets = new Insets(30, 10, 0, 0);

      JLabel uriLabel = new JLabel(o.getObixUri());
      uriLabel.setFont(new Font("Courier", Font.ITALIC, 15));
      c.gridx = 0;
      c.gridwidth = 10;
      pane.add(uriLabel, c);

      c.gridwidth = 1;
      c.insets = new Insets(10, 10, 0, 0);

      JLabel parameter1Label = new JLabel("Parameter 1 Type:");
      c.gridy++;
      pane.add(parameter1Label, c);

      JLabel parameter1ObixUnitLabel = new JLabel("OBIX unit: " + o.getObixUnitUri());
      c.gridx++;
      pane.add(parameter1ObixUnitLabel, c);

      JComboBox parameter1comboBox = new JComboBox(parameterTypes);
      c.gridx++;
      pane.add(parameter1comboBox, c);

      JButton param1AddStateButton = new JButton("Add State");
      Box vBox1 = Box.createVerticalBox();
      vBox1.setBorder(BorderFactory.createLineBorder(Color.black));

      JLabel parameter1UnitLabel = new JLabel("Set Parameter 1 Unit:");
      c.gridx++;
      pane.add(parameter1UnitLabel, c);

      JTextField parameter1UnitTextField = new JTextField(o.getParameter1().getParameterUnit());
      parameter1UnitTextField.setPreferredSize(new Dimension(500, 20));
      parameter1UnitTextField.setMinimumSize(new Dimension(500, 20));
      c.gridx++;
      pane.add(parameter1UnitTextField, c);

      JLabel parameter1ValueTypeLabel =
          new JLabel("valueType: " + o.getParameter1().getValueType());
      c.gridx++;
      pane.add(parameter1ValueTypeLabel, c);

      int param1UnitLabelxPosition = c.gridx;
      int param1UnitLabelyPosition = c.gridy;

      for (StateDescription s : o.getParameter1().getStateDescriptions()) {
        JLabel stateNameLabel = new JLabel("State Name: ");
        JTextField stateNameTextfield = new JTextField(20);
        stateNameTextfield.setText(s.getName().getName());
        vBox1.add(stateNameLabel);
        vBox1.add(stateNameTextfield);

        JLabel stateValueLabel = new JLabel("State Value: ");
        JTextField stateValueTextfield = new JTextField(20);
        stateValueTextfield.setText(s.getValue().getValue());
        vBox1.add(stateValueLabel);
        vBox1.add(stateValueTextfield);

        JLabel stateURILabel = new JLabel("State URI: ");
        JTextField stateURITextfield = new JTextField(20);
        stateURITextfield.setText(s.getStateDescriptionUri());
        vBox1.add(stateURILabel);
        vBox1.add(stateURITextfield);

        JButton deleteStateButton = new JButton("Delete State");
        vBox1.add(deleteStateButton);

        JSeparator horizontalLine = new JSeparator(JSeparator.HORIZONTAL);
        vBox1.add(horizontalLine);
        vBox1.add(horizontalLine);

        StateRepresentation stateRepresentation =
            (new StateRepresentation(
                param1AddStateButton,
                deleteStateButton,
                stateNameLabel,
                stateNameTextfield,
                stateValueLabel,
                stateValueTextfield,
                stateURILabel,
                stateURITextfield,
                horizontalLine,
                vBox1,
                o.getParameter1()));

        addDeleteStateListener(stateRepresentation);
        listOfStateRepresentations.add(stateRepresentation);

        pane.revalidate();
        pane.repaint();
      }

      addParameterBoxListener(
          parameter1comboBox,
          param1UnitLabelxPosition,
          param1UnitLabelyPosition,
          parameter1UnitLabel,
          parameter1UnitTextField,
          pane,
          param1AddStateButton,
          vBox1);

      /** Add state to parameter 1 function listener */
      param1AddStateButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              JLabel stateNameLabel = new JLabel("State Name: ");
              JTextField stateNameTextfield = new JTextField(20);
              vBox1.add(stateNameLabel);
              vBox1.add(stateNameTextfield);
              JLabel stateValueLabel = new JLabel("State Value: ");

              JTextField stateValueTextfield = new JTextField(20);
              vBox1.add(stateValueLabel);
              vBox1.add(stateValueTextfield);

              JLabel stateURILabel = new JLabel("State URI: ");
              JTextField stateURITextfield = new JTextField(20);
              vBox1.add(stateURILabel);
              vBox1.add(stateURITextfield);

              JButton deleteStateButton = new JButton("Delete State");
              vBox1.add(deleteStateButton);

              JSeparator horizontalLine = new JSeparator(JSeparator.HORIZONTAL);
              vBox1.add(horizontalLine);
              vBox1.add(horizontalLine);

              StateRepresentation stateRepresentation =
                  (new StateRepresentation(
                      param1AddStateButton,
                      deleteStateButton,
                      stateNameLabel,
                      stateNameTextfield,
                      stateValueLabel,
                      stateValueTextfield,
                      stateURILabel,
                      stateURITextfield,
                      horizontalLine,
                      vBox1,
                      o.getParameter1()));

              addDeleteStateListener(stateRepresentation);
              listOfStateRepresentations.add(stateRepresentation);
              pane.revalidate();
              pane.repaint();
            }
          });

      c.gridy++;
      c.gridx = 0;
      JLabel parameter2Label = new JLabel("Parameter 2 Type:");
      pane.add(parameter2Label, c);

      JComboBox parameter2comboBox = new JComboBox(parameterTypes);
      c.gridx++;
      c.gridx++;
      pane.add(parameter2comboBox, c);

      JLabel parameter2UnitLabel = new JLabel("Set Parameter 2 Unit: ");
      c.gridx++;
      pane.add(parameter2UnitLabel, c);

      JTextField parameter2UnitTextField = new JTextField(o.getParameter2().getParameterUnit());
      parameter2UnitTextField.setPreferredSize(new Dimension(500, 20));
      parameter2UnitTextField.setMinimumSize(new Dimension(500, 20));
      c.gridx++;
      pane.add(parameter2UnitTextField, c);

      JLabel parameter2ValueTypeLabel =
          new JLabel("valueType: " + o.getParameter2().getValueType());
      c.gridx++;
      pane.add(parameter2ValueTypeLabel, c);

      JButton param2AddStateButton = new JButton("Add State");
      Box vBox2 = Box.createVerticalBox();
      vBox2.setBorder(BorderFactory.createLineBorder(Color.black));

      int param2UnitLabelxPosition = c.gridx;
      int param2UnitLabelyPosition = c.gridy;

      addParameterBoxListener(
          parameter2comboBox,
          param2UnitLabelxPosition,
          param2UnitLabelyPosition,
          parameter2UnitLabel,
          parameter2UnitTextField,
          pane,
          param2AddStateButton,
          vBox2);

      /** Add state to parameter 2 function listener */
      param2AddStateButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              JLabel stateNameLabel = new JLabel("State Name: ");
              JTextField stateNameTextfield = new JTextField(20);
              vBox2.add(stateNameLabel);
              vBox2.add(stateNameTextfield);
              JLabel stateValueLabel = new JLabel("State Value: ");

              JTextField stateValueTextfield = new JTextField(20);
              vBox2.add(stateValueLabel);
              vBox2.add(stateValueTextfield);

              JLabel stateURILabel = new JLabel("State URI: ");
              JTextField stateURITextfield = new JTextField(20);
              vBox2.add(stateURILabel);
              vBox2.add(stateURITextfield);

              JButton deleteStateButton = new JButton("Delete State");
              vBox2.add(deleteStateButton);

              JSeparator horizontalLine = new JSeparator(JSeparator.HORIZONTAL);
              vBox2.add(horizontalLine);
              vBox2.add(horizontalLine);

              StateRepresentation stateRepresentation =
                  (new StateRepresentation(
                      param2AddStateButton,
                      deleteStateButton,
                      stateNameLabel,
                      stateNameTextfield,
                      stateValueLabel,
                      stateValueTextfield,
                      stateURILabel,
                      stateURITextfield,
                      horizontalLine,
                      vBox2,
                      o.getParameter2()));

              addDeleteStateListener(stateRepresentation);
              listOfStateRepresentations.add(stateRepresentation);

              pane.revalidate();
              pane.repaint();
            }
          });

      parameter1comboBox.setSelectedItem(o.getParameter1().getParameterType());
      parameter2comboBox.setSelectedItem(o.getParameter2().getParameterType());

      representationRows.add(
          new RepresentationRow(
              o,
              parameter1comboBox,
              parameter2comboBox,
              parameter1UnitTextField,
              parameter2UnitTextField));
    }

    JButton acceptButton = new JButton("Accept");
    c.insets = new Insets(50, 0, 0, 0);
    c.gridwidth = 10;
    c.gridx = 0;
    c.gridy++;
    pane.add(acceptButton, c);

    /** Accept button listener */
    Action acceptAction =
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            for (StateRepresentation s : listOfStateRepresentations) {
              if (s.getStateNameTextField().getText().isEmpty()
                  || s.getStateUriTextField().getText().isEmpty()
                  || s.getStateValueTextField().getText().isEmpty()) {
                JOptionPane.showMessageDialog(
                    null,
                    "Each state parameter field must contain a text! "
                        + "There are some empty parameter fields, please change them before proceeding.");
                return;
              }
            }

            for (ObixObject o : chosenComponents) {
              o.getParameter1().getStateDescriptions().clear();
              o.getParameter2().getStateDescriptions().clear();
            }

            for (StateRepresentation s : listOfStateRepresentations) {
              // Save created State
              ArrayList<String> types = new ArrayList<String>();
              types.add("&colibri;AbsoluteState");
              types.add("&colibri;DiscreteState");

              Value val = new Value();
              val.setValue(s.getStateValueTextField().getText());
              val.setDatatype(s.getParameter().getValueType());

              Name name = new Name();
              name.setName(s.getStateNameTextField().getText());

              StateDescription state =
                  new StateDescription(s.getStateUriTextField().getText(), types, val, name);

              s.getParameter().addStateDescription(state);
            }
            List<ObixObject> chosenObjects = Collections.synchronizedList(new ArrayList<>());
            for (RepresentationRow r : GuiUtility.this.getRepresentationRows()) {
              r.getObixObject()
                  .getParameter1()
                  .setParameterType((String) r.getParam1TypeComboBox().getSelectedItem());
              r.getObixObject()
                  .getParameter2()
                  .setParameterType((String) r.getParam2TypeComboBox().getSelectedItem());
              chosenObjects.add(r.getObixObject());
              if (!r.getParam1UnitTextField().getText().isEmpty()) {
                r.getObixObject()
                    .getParameter1()
                    .setParameterUnit(r.getParam1UnitTextField().getText());
              }
              if (!r.getParam2UnitTextField().getText().isEmpty()) {
                r.getObixObject()
                    .getParameter2()
                    .setParameterUnit(r.getParam2UnitTextField().getText());
              }
            }
            representationRows.clear();
            cards.removeAll();
            JScrollPane scrollPane = new JScrollPane(interactionWindow(chosenObjects));
            scrollPane.getVerticalScrollBar().setUnitIncrement(16);
            scrollPane.setBorder(new EmptyBorder(20, 20, 20, 20));
            cards.add(scrollPane);
            // Display the window.
            mainFrame.pack();
          }
        };
    acceptButton.addActionListener(acceptAction);

    return pane;
  }
  public WizStepManyTextFields(Wizard w, String instr, Vector strings) {
    // store wizard?
    _instructions.setText(instr);
    _instructions.setWrapStyleWord(true);
    _instructions.setEditable(false);
    _instructions.setBorder(null);
    _instructions.setBackground(_mainPanel.getBackground());

    _mainPanel.setBorder(new EtchedBorder());

    GridBagLayout gb = new GridBagLayout();
    _mainPanel.setLayout(gb);

    GridBagConstraints c = new GridBagConstraints();
    c.ipadx = 3;
    c.ipady = 3;
    c.weightx = 0.0;
    c.weighty = 0.0;
    c.anchor = GridBagConstraints.EAST;

    JLabel image = new JLabel("");
    // image.setMargin(new Insets(0, 0, 0, 0));
    image.setIcon(WIZ_ICON);
    image.setBorder(null);
    c.gridx = 0;
    c.gridheight = GridBagConstraints.REMAINDER;
    c.gridy = 0;
    c.anchor = GridBagConstraints.NORTH;
    gb.setConstraints(image, c);
    _mainPanel.add(image);

    c.weightx = 0.0;
    c.gridx = 2;
    c.gridheight = 1;
    c.gridwidth = 3;
    c.gridy = 0;
    c.fill = GridBagConstraints.NONE;
    gb.setConstraints(_instructions, c);
    _mainPanel.add(_instructions);

    c.gridx = 1;
    c.gridy = 1;
    c.weightx = 0.0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    SpacerPanel spacer = new SpacerPanel();
    gb.setConstraints(spacer, c);
    _mainPanel.add(spacer);

    c.gridx = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    int size = strings.size();
    for (int i = 0; i < size; i++) {
      c.gridy = 2 + i;
      String s = (String) strings.elementAt(i);
      JTextField tf = new JTextField(s, 50);
      tf.setMinimumSize(new Dimension(200, 20));
      tf.getDocument().addDocumentListener(this);
      _fields.addElement(tf);
      gb.setConstraints(tf, c);
      _mainPanel.add(tf);
    }

    c.gridx = 1;
    c.gridy = 3 + strings.size();
    c.weightx = 0.0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    SpacerPanel spacer2 = new SpacerPanel();
    gb.setConstraints(spacer2, c);
    _mainPanel.add(spacer2);
  }
  public JComponent createComponent() {
    myPanel = new JPanel(new GridBagLayout());

    myStartIndex = new JTextField(5);
    myEndIndex = new JTextField(5);
    myEntriesLimit = new JTextField(5);

    final FontMetrics fontMetrics = myStartIndex.getFontMetrics(myStartIndex.getFont());
    final Dimension minSize = new Dimension(myStartIndex.getPreferredSize());
    //noinspection HardCodedStringLiteral
    minSize.width = fontMetrics.stringWidth("AAAAA");
    myStartIndex.setMinimumSize(minSize);
    myEndIndex.setMinimumSize(minSize);
    myEntriesLimit.setMinimumSize(minSize);

    JLabel startIndexLabel =
        new JLabel(DebuggerBundle.message("label.array.renderer.configurable.start.index"));
    startIndexLabel.setLabelFor(myStartIndex);

    JLabel endIndexLabel =
        new JLabel(DebuggerBundle.message("label.array.renderer.configurable.end.index"));
    endIndexLabel.setLabelFor(myEndIndex);

    JLabel entriesLimitLabel =
        new JLabel(DebuggerBundle.message("label.array.renderer.configurable.max.count1"));
    entriesLimitLabel.setLabelFor(myEntriesLimit);

    myPanel.add(
        startIndexLabel,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 8),
            0,
            0));
    myPanel.add(
        myStartIndex,
        new GridBagConstraints(
            1,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 8),
            0,
            0));
    myPanel.add(
        endIndexLabel,
        new GridBagConstraints(
            2,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 8),
            0,
            0));
    myPanel.add(
        myEndIndex,
        new GridBagConstraints(
            3,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));

    myPanel.add(
        entriesLimitLabel,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(4, 0, 0, 8),
            0,
            0));
    myPanel.add(
        myEntriesLimit,
        new GridBagConstraints(
            1,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(4, 0, 0, 8),
            0,
            0));
    myPanel.add(
        new JLabel(DebuggerBundle.message("label.array.renderer.configurable.max.count2")),
        new GridBagConstraints(
            2,
            GridBagConstraints.RELATIVE,
            2,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(4, 0, 0, 0),
            0,
            0));

    // push other components up
    myPanel.add(
        new JLabel(),
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));

    final DocumentListener listener =
        new DocumentListener() {
          private void updateEntriesLimit() {
            final boolean state = myIndexUpdateEnabled;
            myIndexUpdateEnabled = false;
            try {
              if (myEntriesLimitUpdateEnabled) {
                myEntriesLimit.setText(
                    String.valueOf(getInt(myEndIndex) - getInt(myStartIndex) + 1));
              }
            } finally {
              myIndexUpdateEnabled = state;
            }
          }

          public void changedUpdate(DocumentEvent e) {
            updateEntriesLimit();
          }

          public void insertUpdate(DocumentEvent e) {
            updateEntriesLimit();
          }

          public void removeUpdate(DocumentEvent e) {
            updateEntriesLimit();
          }
        };
    myStartIndex.getDocument().addDocumentListener(listener);
    myEndIndex.getDocument().addDocumentListener(listener);
    myEntriesLimit
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              private void updateEndIndex() {
                final boolean state = myEntriesLimitUpdateEnabled;
                myEntriesLimitUpdateEnabled = false;
                try {
                  if (myIndexUpdateEnabled) {
                    myEndIndex.setText(
                        String.valueOf(getInt(myEntriesLimit) + getInt(myStartIndex) - 1));
                  }
                } finally {
                  myEntriesLimitUpdateEnabled = state;
                }
              }

              public void insertUpdate(DocumentEvent e) {
                updateEndIndex();
              }

              public void removeUpdate(DocumentEvent e) {
                updateEndIndex();
              }

              public void changedUpdate(DocumentEvent e) {
                updateEndIndex();
              }
            });
    return myPanel;
  }