Ejemplo n.º 1
0
  public void buildPopulationBox() {
    rebuilding = true;
    populationBox.removeAll();
    peopleList = new ArrayList<Object>();
    famList = new ArrayList<Family>();
    peopleList.addAll(ctxt.individualCensus);
    String plur = (peopleList.size() == 1 ? "" : "s");
    populationBox.setLayout(new BoxLayout(populationBox, BoxLayout.PAGE_AXIS));
    populationBox.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createLineBorder(Color.blue), "Current Population"));
    populationBox.setAlignmentX(0.5f);
    populationBox.add(Box.createRigidArea(new Dimension(8, 0)));
    indivLabel = new JLabel("Contains " + peopleList.size() + " Individual" + plur);
    indivLabel.setAlignmentX(0.5f);
    populationBox.add(indivLabel);
    if (peopleList.size() > 0) {
      JPanel indivBtnBox = new JPanel();
      indivBtnBox.setLayout(new BoxLayout(indivBtnBox, BoxLayout.LINE_AXIS));
      Dimension sizer2 = new Dimension(350, 50);
      String[] indMenu = genIndMenu(peopleList);
      indPick = new JComboBox(indMenu);
      indPick.addActionListener(listener);
      indPick.setActionCommand("view/edit person");
      indPick.setMinimumSize(sizer2);
      indPick.setMaximumSize(sizer2);
      indPick.setBorder(
          BorderFactory.createTitledBorder(
              BorderFactory.createLineBorder(Color.blue), "View/Edit Person"));
      indivBtnBox.add(indPick);
      populationBox.add(indivBtnBox);
    } //  end of if-any-people-exist

    famList.addAll(ctxt.familyCensus); //  end of filtering deleted records
    plur = (famList.size() == 1 ? "y" : "ies");
    famLabel = new JLabel("Contains " + famList.size() + " Famil" + plur);
    famLabel.setAlignmentX(0.5f);
    populationBox.add(Box.createRigidArea(new Dimension(0, 4)));
    populationBox.add(famLabel);
    if (famList.size() > 0) {
      JPanel famBtnBox = new JPanel();
      famBtnBox.setLayout(new BoxLayout(famBtnBox, BoxLayout.LINE_AXIS));
      Dimension sizer2 = new Dimension(350, 50);
      String[] famMenu = genFamMenu(famList);
      famPick = new JComboBox(famMenu);
      famPick.addActionListener(listener);
      famPick.setActionCommand("view/edit family");
      famPick.setMinimumSize(sizer2);
      famPick.setMaximumSize(sizer2);
      famPick.setBorder(
          BorderFactory.createTitledBorder(
              BorderFactory.createLineBorder(Color.blue), "View/Edit Family"));
      famBtnBox.add(famPick);
      populationBox.add(famBtnBox);
    } //  end of if-any-families-exist
    rebuilding = false;
  } //  end of method buildPopulationBox
Ejemplo n.º 2
0
 void updateColor() {
   if (gNode.isInitial()) {
     setBackground(Color.yellow);
     setBorder(BorderFactory.createLineBorder(Color.yellow, 1));
     //  two pixels wide
   } else {
     setBackground(Color.white);
     setBorder(BorderFactory.createLineBorder(Color.black, 1));
   }
 }
Ejemplo n.º 3
0
 public void updateKeyboardUI() {
   if (Skin.VIETNAMESE_KEY.isEnabled()) {
     chkVietnamese.setText(" V ");
     chkVietnamese.setBackground(Color.yellow);
     chkVietnamese.setBorder(BorderFactory.createLineBorder(Color.red, 1));
   } else {
     chkVietnamese.setText(" E ");
     chkVietnamese.setBackground(Color.cyan);
     chkVietnamese.setBorder(BorderFactory.createLineBorder(Color.blue, 1));
   }
 }
Ejemplo n.º 4
0
  private JTextField createField(final String text) {
    final JTextField field =
        new JTextField(text) {
          public Dimension getPreferredSize() {
            Dimension preferredSize = super.getPreferredSize();
            return new Dimension(preferredSize.width, myTextHeight);
          }
        };
    field.setBackground(UIUtil.getPanelBackground());
    field.setEditable(false);
    final Border lineBorder = BorderFactory.createLineBorder(UIUtil.getPanelBackground());
    final DottedBorder dotted = new DottedBorder(UIUtil.getActiveTextColor());
    field.setBorder(lineBorder);
    // field.setFocusable(false);
    field.setHorizontalAlignment(JTextField.RIGHT);
    field.setCaretPosition(0);
    field.addFocusListener(
        new FocusAdapter() {
          public void focusGained(FocusEvent e) {
            field.setBorder(dotted);
          }

          public void focusLost(FocusEvent e) {
            field.setBorder(lineBorder);
          }
        });
    return field;
  }
  /**
   * Creates the panel that appears when there are no pages
   *
   * @return JPanel
   */
  protected JPanel createFirstPanel() {
    firstButtonPanel = new JPanel(new GridBagLayout());
    firstButtonPanel.setBorder(BorderFactory.createLineBorder(Color.black));
    firstButtonPanel.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent _evt) {
            if (OSPRuntime.isPopupTrigger(_evt))
              return; // SwingUtilities.isRightMouseButton(_evt)) return;
            if (!firstButtonPanel.isEnabled()) return;
            Object obj =
                JOptionPane.showInputDialog(
                    getComponent(),
                    res.getString("TabbedEditor.NewName"),
                    res.getString("TabbedEditor.Rename"),
                    JOptionPane.QUESTION_MESSAGE,
                    null,
                    null,
                    getUniqueName(defaultString));
            if (obj == null) return;
            String txt = obj.toString().trim();
            if (txt.length() > 0) addPage(defaultType, txt, null, true);
            else addPage(defaultType, defaultString, null, true);
          }
        });
    String label = res.getOptionalString("TabbedEditor.ClickHere." + defaultHeader);
    if (label == null) label = res.getString("TabbedEditor.ClickHere");
    firstButton = new JLabel(label);
    firstButton.setFont(firstButton.getFont().deriveFont(TabbedEditor.BUTTON_FONT_SIZE));
    firstButtonPanel.add(firstButton);

    JPanel firstPanel = new JPanel(new GridLayout(0, 1));
    firstPanel.add(firstButtonPanel);
    return firstPanel;
  }
    public void createColorPanel() {
      JPanel colorPanel = new JPanel(new GridLayout(0, 1));
      int curRow = 0;
      for (int i = 0; i < colorString.length / 5; i++) {
        JPanel row = new JPanel(new GridLayout(1, 0, 2, 1));
        row.setBorder(new EmptyBorder(2, 2, 2, 2));

        for (int j = curRow; j < curRow + 5; j++) {
          final JLabel colorLabel =
              new JLabel(null, new ColoredIcon(color[j], 14, 14), JLabel.CENTER);
          colorLabel.setOpaque(true);
          final Border emb = BorderFactory.createEmptyBorder(2, 1, 2, 1);
          final Border lnb = BorderFactory.createLineBorder(Color.black);
          final Border cmb = BorderFactory.createCompoundBorder(lnb, emb);
          colorLabel.setBorder(emb);
          colorLabel.addMouseListener(
              new MouseAdapter() {

                public void mouseClicked(MouseEvent e) {
                  JButton btn = (JButton) getTarget();
                  Color selColor = ((ColoredIcon) colorLabel.getIcon()).getCurrentColor();
                  btn.setIcon(new ColoredIcon(selColor));
                  setVisible(false);
                  btn.doClick();
                  oldLabel.setBackground(null);
                  colorLabel.setBackground(new Color(150, 150, 200));
                  colorLabel.setBorder(emb);
                  oldLabel = colorLabel;
                }

                public void mouseEntered(MouseEvent e) {
                  colorLabel.setBorder(cmb);
                  colorLabel.setBackground(new Color(150, 150, 200));
                }

                public void mouseExited(MouseEvent e) {
                  colorLabel.setBorder(emb);
                  colorLabel.setBackground(null);
                }
              });
          row.add(colorLabel);
        }
        colorPanel.add(row);
        curRow += row.getComponentCount();
        // System.out.println(curRow);
      }

      add(colorPanel, BorderLayout.CENTER);

      // More Colors Button
      moreColors = new JButton(new ColorChooserAction((JButton) target));
      moreColors.setText("More Colors...");
      moreColors.setIcon(null);
      moreColors.setFont(new Font("Verdana", Font.PLAIN, 10));
      //
      JPanel c = new JPanel(new FlowLayout(FlowLayout.CENTER));
      c.add(moreColors);
      add(c, BorderLayout.SOUTH);
    }
Ejemplo n.º 7
0
  public ComboBoxDemo2() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    String[] patternExamples = {
      "dd MMMMM yyyy",
      "dd.MM.yy",
      "MM/dd/yy",
      "yyyy.MM.dd G 'at' hh:mm:ss z",
      "EEE, MMM d, ''yy",
      "h:mm a",
      "H:mm:ss:SSS",
      "K:mm a,z",
      "yyyy.MMMMM.dd GGG hh:mm aaa"
    };

    currentPattern = patternExamples[0];

    // Set up the UI for selecting a pattern.
    JLabel patternLabel1 = new JLabel("Enter the pattern string or");
    JLabel patternLabel2 = new JLabel("select one from the list:");

    JComboBox patternList = new JComboBox(patternExamples);
    patternList.setEditable(true);
    patternList.addActionListener(this);

    // Create the UI for displaying result.
    JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEADING); // == LEFT
    result = new JLabel(" ");
    result.setForeground(Color.black);
    result.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    // Lay out everything.
    JPanel patternPanel = new JPanel();
    patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.PAGE_AXIS));
    patternPanel.add(patternLabel1);
    patternPanel.add(patternLabel2);
    patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
    patternPanel.add(patternList);

    JPanel resultPanel = new JPanel(new GridLayout(0, 1));
    resultPanel.add(resultLabel);
    resultPanel.add(result);

    patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

    add(patternPanel);
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(resultPanel);

    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    reformat();
  } // constructor
Ejemplo n.º 8
0
 ASDEditNode(ASDGrammarNode grammarNode, Container given) {
   super(" " + grammarNode.word() + " " + grammarNode.instance() + " ");
   gNode = grammarNode;
   context = given;
   addMouseListener((MouseListener) this);
   popupListener = new PopupListener(new EditNodeMenu(this));
   addMouseListener(popupListener);
   addChangeListener((ChangeListener) this);
   addMouseMotionListener((MouseMotionListener) this);
   if (grammarNode.isInitial()) {
     setBackground(Color.yellow);
     setBorder(BorderFactory.createLineBorder(Color.yellow, 1));
     //  two pixels wide
   } else {
     setBackground(Color.white);
     setBorder(BorderFactory.createLineBorder(Color.black, 1));
   }
   if (grammarNode.isFinal()) initializeRightLabel(grammarNode.phraseType());
 }
  private void initUI() {

    this.setLayout(new BorderLayout());

    JPanel infoPanel = new JPanel();
    infoPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    infoPanel.setBackground(Color.WHITE);
    infoPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

    infoPanel.add(
        new JLabel(
            new ImageIcon(
                Thread.currentThread().getContextClassLoader().getResource("siw-logo3_2.gif"))));

    JLabel infoLabel =
        new JLabel("<html>Please select a project and context<br> Version must be a number</html>");
    infoPanel.add(infoLabel);

    this.add(infoPanel, BorderLayout.NORTH);

    JPanel entryPanel = new JPanel();
    entryPanel.setLayout(null);

    projectNameField.setText("");
    JLabel projectNameLabel = new JLabel("Project Name");
    projectNameLabel.setBounds(new Rectangle(30, 80, 135, 20));
    projectNameField.setBounds(new Rectangle(180, 80, 175, 20));

    JLabel projectVersionLabel = new JLabel("Project Version");
    projectVersionLabel.setBounds(new Rectangle(30, 125, 135, 20));
    projectVersionField.setBounds(new Rectangle(180, 125, 175, 20));

    JLabel contextLabel = new JLabel("Context");
    contextLabel.setBounds(new Rectangle(30, 165, 135, 20));
    contextComboBox.setBounds(new Rectangle(180, 165, 175, 20));

    JLabel packageLabel = new JLabel("Select Package");
    packageLabel.setBounds(new Rectangle(30, 210, 135, 20));
    packageComboBox.setBounds(new Rectangle(180, 210, 250, 20));

    entryPanel.add(projectNameLabel, null);
    entryPanel.add(projectNameField, null);
    entryPanel.add(projectVersionLabel, null);
    entryPanel.add(projectVersionField, null);
    entryPanel.add(contextLabel, null);
    entryPanel.add(contextComboBox, null);
    entryPanel.add(packageLabel, null);
    entryPanel.add(packageComboBox, null);

    this.add(entryPanel, BorderLayout.CENTER);

    projectVersionField.addKeyListener(this);
    projectNameField.addKeyListener(this);
  }
Ejemplo n.º 10
0
    public PlayButton(String name) {
      super(name);
      myBorder =
          BorderFactory.createCompoundBorder(
              BorderFactory.createCompoundBorder(
                  BorderFactory.createLineBorder(Color.black),
                  BorderFactory.createLineBorder(Color.blue)),
              BorderFactory.createCompoundBorder(
                  BorderFactory.createLineBorder(Color.cyan),
                  BorderFactory.createLineBorder(Color.white)));
      addMouseListener(
          new MouseAdapter() {
            public void mouseEntered(MouseEvent e) {
              setBorder(myBorder);
            }

            public void mouseExited(MouseEvent e) {
              setBorder(null);
            }
          });
    }
Ejemplo n.º 11
0
@SuppressWarnings("serial")
class CellRenderer extends JLabel implements TableCellRenderer {

  private static int selectRow = -1;
  private static int selectCol = -1;
  private Border unselectedBorder = BorderFactory.createLineBorder(Color.BLACK, 1);
  private Border selectedBorder = BorderFactory.createLineBorder(Color.BLACK, 2);

  public CellRenderer() {

    setOpaque(true);
    setFont(getFont().deriveFont(16.0f));
  }

  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

    //		Color c = ColorUtils.fromString((String)value);
    Color c = Color.white;
    this.setBackground(c);

    if (isSelected) {
      this.setBorder(selectedBorder);
    } else {
      this.setBorder(unselectedBorder);
    }
    if (row == selectRow && column == selectCol) {
      this.setBackground(Color.yellow);
    }

    this.setText((String) value);

    return this;
  }

  public static void modifyColor(int row, int column) {
    selectRow = row;
    selectCol = column;
  }
}
Ejemplo n.º 12
0
  /**
   * getBorder.
   *
   * @param card a {@link forge.Card} object.
   * @return a {@link javax.swing.border.Border} object.
   */
  public static Border getBorder(Card card) {
    // color info
    if (card == null) return BorderFactory.createEmptyBorder(2, 2, 2, 2);
    java.awt.Color color;
    ArrayList<String> list = CardUtil.getColors(card);

    if (card.isFaceDown()) color = Color.gray;
    else if (list.size() > 1) color = Color.orange;
    else if (list.get(0).equals(Constant.Color.Black)) color = Color.black;
    else if (list.get(0).equals(Constant.Color.Green)) color = new Color(0, 220, 39);
    else if (list.get(0).equals(Constant.Color.White)) color = Color.white;
    else if (list.get(0).equals(Constant.Color.Red)) color = Color.red;
    else if (list.get(0).equals(Constant.Color.Blue)) color = Color.blue;
    else if (list.get(0).equals(Constant.Color.Colorless)) color = Color.gray;
    else color = new Color(200, 0, 230); // If your card has a violet border, something is wrong

    if (color != Color.gray) {

      int r = color.getRed();
      int g = color.getGreen();
      int b = color.getBlue();

      int shade = 10;

      r -= shade;
      g -= shade;
      b -= shade;

      r = Math.max(0, r);
      g = Math.max(0, g);
      b = Math.max(0, b);

      color = new Color(r, g, b);

      return BorderFactory.createLineBorder(color, 2);
    } else return BorderFactory.createLineBorder(Color.gray, 2);
  }
  /** Loads the configuration form obtained from the chat room. */
  protected void loadConfigurationForm() {
    Iterator<ChatRoomConfigurationFormField> configurationSet = configForm.getConfigurationSet();

    while (configurationSet.hasNext()) {
      ChatRoomConfigurationFormField formField = configurationSet.next();

      Iterator<?> values = formField.getValues();
      Iterator<String> options = formField.getOptions();

      JComponent field;
      JLabel label = new JLabel("", JLabel.RIGHT);

      if (formField.getLabel() != null) label.setText(formField.getLabel() + ": ");

      String fieldType = formField.getType();

      if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_BOOLEAN)) {
        // Create a check box when the field is of type boolean.
        field = new SIPCommCheckBox(formField.getLabel());
        label.setText("");

        if (values.hasNext()) {
          ((JCheckBox) field).setSelected((Boolean) values.next());
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_FIXED)) {
        field = new JLabel();

        if (values.hasNext()) {
          String value = values.next().toString();

          ((JLabel) field).setText(value);
          field.setFont(new Font(null, Font.ITALIC, 10));
          field.setForeground(Color.GRAY);
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_LIST_MULTI)) {
        field = new TransparentPanel(new GridLayout(0, 1));

        field.setBorder(BorderFactory.createLineBorder(Color.GRAY));

        Hashtable<Object, JCheckBox> optionCheckBoxes = new Hashtable<Object, JCheckBox>();

        while (options.hasNext()) {
          Object option = options.next();
          JCheckBox checkBox = new SIPCommCheckBox(option.toString());

          field.add(checkBox);
          optionCheckBoxes.put(option, checkBox);
        }

        while (values.hasNext()) {
          Object value = values.next();

          (optionCheckBoxes.get(value)).setSelected(true);
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_LIST_SINGLE)) {
        field = new JComboBox();

        while (options.hasNext()) {
          ((JComboBox) field).addItem(options.next());
        }

        if (values.hasNext()) {
          ((JComboBox) field).setSelectedItem(values.next());
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_MULTI)) {
        field = new JEditorPane();

        if (values.hasNext()) {
          String value = values.next().toString();

          ((JEditorPane) field).setText(value);
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_SINGLE)
          || fieldType.equals(ChatRoomConfigurationFormField.TYPE_ID_SINGLE)) {
        field = new JTextField();

        if (values.hasNext()) {
          String value = values.next().toString();

          ((JTextField) field).setText(value);
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_PRIVATE)) {
        field = new JPasswordField();

        if (values.hasNext()) {
          String value = values.next().toString();

          ((JPasswordField) field).setText(value);
        }
      } else if (fieldType.equals(ChatRoomConfigurationFormField.TYPE_ID_MULTI)) {
        StringBuffer buff = new StringBuffer();

        while (values.hasNext()) {
          String value = values.next().toString();
          buff.append(value);

          if (values.hasNext()) buff.append(System.getProperty("line.separator"));
        }
        field = new JTextArea(buff.toString());
      } else {
        if (label.getText() == null) continue;

        field = new JTextField();

        if (values.hasNext()) {
          String value = values.next().toString();

          ((JTextField) field).setText(value);
        }
      }

      // If the field is not fixed (i.e. could be changed) we would like
      // to save it in a list in order to use it later when user saves
      // the configuration data.
      if (!fieldType.equals(ChatRoomConfigurationFormField.TYPE_TEXT_FIXED)) {
        uiFieldsTable.put(formField.getName(), field);
      }

      JPanel fieldPanel = new TransparentPanel(new GridLayout(1, 2));
      fieldPanel.setOpaque(false);

      if (!(field instanceof JLabel))
        fieldPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
      else fieldPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 1, 0));

      fieldPanel.add(label);
      fieldPanel.add(field);

      this.mainPanel.add(fieldPanel);
    }
  }
Ejemplo n.º 14
0
 private void jbInit() throws Exception {
   titledBorder1 =
       new TitledBorder(BorderFactory.createLineBorder(new Color(153, 153, 153), 2), "New User");
   titledBorder2 =
       new TitledBorder(
           BorderFactory.createLineBorder(new Color(153, 153, 153), 2), "User accounts");
   this.setLayout(borderLayout1);
   jPanelNewUser.setBorder(titledBorder1);
   jPanelNewUser.setLayout(gridBagLayout1);
   jLabel1.setText("Account name: ");
   jTextFieldAccountname.setColumns(10);
   jLabel2.setText("Password: "******"Repeat Password: "******"Full name: ");
   jTextFieldFullname.setColumns(20);
   addButton.setText("Add");
   addButton.addActionListener(
       new charva.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           addButton_actionPerformed(e);
         }
       });
   jPanel1.setLayout(gridBagLayout2);
   deleteButton.setText("Delete");
   deleteButton.addActionListener(
       new charva.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
           deleteButton_actionPerformed(e);
         }
       });
   jPanel1.setBorder(titledBorder2);
   this.add(jPanelNewUser, BorderLayout.NORTH);
   jPanelNewUser.add(
       jLabel1,
       new GridBagConstraints(
           0,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.EAST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jTextFieldAccountname,
       new GridBagConstraints(
           1,
           0,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.WEST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jLabel4,
       new GridBagConstraints(
           0,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.EAST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jTextFieldFullname,
       new GridBagConstraints(
           1,
           1,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.WEST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jLabel2,
       new GridBagConstraints(
           0,
           2,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.EAST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jPasswordField1,
       new GridBagConstraints(
           1,
           2,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.WEST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jLabel3,
       new GridBagConstraints(
           0,
           3,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.EAST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       jPasswordField2,
       new GridBagConstraints(
           1,
           3,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.WEST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanelNewUser.add(
       addButton,
       new GridBagConstraints(
           0,
           4,
           1,
           1,
           0.0,
           0.0,
           GridBagConstraints.WEST,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   this.add(jPanel1, BorderLayout.CENTER);
   jPanel1.add(
       jPanelUsers,
       new GridBagConstraints(
           0,
           0,
           1,
           1,
           100.0,
           100.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
   jPanel1.add(
       deleteButton,
       new GridBagConstraints(
           1,
           0,
           1,
           1,
           10.0,
           10.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.NONE,
           new Insets(0, 0, 0, 0),
           0,
           0));
 }
Ejemplo n.º 15
0
 private TitledBorder createTitledBorder(final String title) {
   return BorderFactory.createTitledBorder(
       BorderFactory.createLineBorder(SystemColor.controlDkShadow), title);
 }
Ejemplo n.º 16
0
  static void buildGUI() {
    // Need this size to balance axes.
    frame.setSize(520, 690);
    frame.setTitle("DrawTool");
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    Container cPane = frame.getContentPane();

    // Status label on top. Unused for now.
    statusLabel.setOpaque(true);
    statusLabel.setBackground(Color.white);
    cPane.add(statusLabel, BorderLayout.NORTH);

    // Build the input/output elements at the bottom.
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createLineBorder(Color.black));
    panel.setBackground(inputPanelColor);
    panel.setLayout(new GridLayout(2, 1));
    panel.add(outputLabel);
    JPanel bottomPanel = new JPanel();
    bottomPanel.setBackground(inputPanelColor);
    bottomPanel.add(inputField);
    bottomPanel.add(new JLabel("   "));
    JButton enterButton = new JButton("Enter");
    enterButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent a) {
            hasEntered = true;
          }
        });
    bottomPanel.add(enterButton);
    panel.add(bottomPanel);
    if (!sequencingOn) {
      cPane.add(panel, BorderLayout.SOUTH);
    }

    // Drawing in the center.
    drawArea = new DrawTool();
    if (sequencingOn) {
      frame.addKeyListener(
          new KeyAdapter() {
            public void keyTyped(KeyEvent e) {
              handleKeyTyped(e);
            }
          });
    }
    cPane.add(drawArea, BorderLayout.CENTER);

    drawArea.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            handleMouseClick(e);
          }

          public void mouseReleased(MouseEvent e) {
            handleMouseReleased(e);
          }
        });

    drawArea.addMouseMotionListener(
        new MouseMotionAdapter() {
          public void mouseDragged(MouseEvent e) {
            handleMouseDragged(e);
          }
        });
  }
Ejemplo n.º 17
0
  public PlayerWaitingView() {

    this.setOpaque(true);
    this.setLayout(new BorderLayout());
    this.setBorder(BorderFactory.createLineBorder(Color.black, BORDER_WIDTH));

    // set the heading at the top of the pane
    label = new JLabel("Player Waiting View");
    FontUtils.setFont(label, LABEL_TEXT_SIZE);
    this.add(label, BorderLayout.NORTH);

    // create the center panel that displays player info
    center = new JPanel();
    center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
    this.add(center, BorderLayout.CENTER);

    // create the AI panel for the bottom of the pane
    aiPanel = new JPanel();
    aiPanel.setLayout(new BoxLayout(aiPanel, BoxLayout.Y_AXIS));

    // create the AI type panel
    JPanel aiTypePanel = new JPanel();
    aiTypePanel.setLayout(new BoxLayout(aiTypePanel, BoxLayout.X_AXIS));

    aiTypePanel.add(Box.createHorizontalGlue());

    JLabel aiTypeLabel = new JLabel("Select AI Type:");
    FontUtils.setFont(aiTypeLabel, AI_TEXT_SIZE);
    aiTypePanel.add(aiTypeLabel);

    aiTypePanel.add(Box.createRigidArea(new Dimension(5, 0)));

    aiModel = new SpinnerListModel();
    aiChoices = new JSpinner(aiModel);
    ((JSpinner.DefaultEditor) aiChoices.getEditor()).getTextField().setEditable(false);
    FontUtils.setFont(aiChoices, AI_TEXT_SIZE);
    aiTypePanel.add(aiChoices);

    aiTypePanel.add(Box.createHorizontalGlue());

    aiPanel.add(aiTypePanel);

    aiPanel.add(Box.createRigidArea(new Dimension(0, 10)));

    // create the AI button panel
    JPanel aiButtonPanel = new JPanel();
    aiButtonPanel.setLayout(new BoxLayout(aiButtonPanel, BoxLayout.X_AXIS));

    aiButtonPanel.add(Box.createHorizontalGlue());

    addAiButton = new JButton("Add a computer player");
    addAiButton.addActionListener(actionListener);
    FontUtils.setFont(addAiButton, BUTTON_TEXT_SIZE);
    aiButtonPanel.add(addAiButton);

    aiButtonPanel.add(Box.createHorizontalGlue());

    aiPanel.add(aiButtonPanel);

    aiPanel.add(Box.createRigidArea(new Dimension(0, 10)));

    // add the AI panel
    this.add(aiPanel, BorderLayout.SOUTH);
  }
public class ParameterInfoComponent extends JPanel {
  private final Object[] myObjects;
  private int myCurrentParameterIndex;

  private PsiElement myParameterOwner;
  private Object myHighlighted;
  @NotNull private final ParameterInfoHandler myHandler;

  private final OneElementComponent[] myPanels;

  private static final Color BACKGROUND_COLOR = HintUtil.INFORMATION_COLOR;
  private static final Color HIGHLIGHTED_BORDER_COLOR =
      new JBColor(new Color(231, 254, 234), Gray._100);
  private final Font NORMAL_FONT;
  private final Font BOLD_FONT;

  private static final Border BACKGROUND_BORDER = BorderFactory.createLineBorder(BACKGROUND_COLOR);

  protected int myWidthLimit = 500;

  private static final Map<ParameterInfoUIContextEx.Flag, String> FLAG_TO_TAG =
      ImmutableMap.of(
          ParameterInfoUIContextEx.Flag.HIGHLIGHT,
          "b",
          ParameterInfoUIContextEx.Flag.DISABLE,
          "font color=gray",
          ParameterInfoUIContextEx.Flag.STRIKEOUT,
          "strike");

  private static final Comparator<TextRange> TEXT_RANGE_COMPARATOR =
      new Comparator<TextRange>() {
        @Override
        public int compare(TextRange o1, TextRange o2) {
          if (o1.getStartOffset() == o2.getStartOffset()) {
            return o1.getEndOffset() > o2.getEndOffset() ? 1 : -1;
          }
          if (o1.getStartOffset() > o2.getStartOffset()) return 1;
          if (o1.getEndOffset() > o2.getEndOffset()) return 1;
          return -1;
        }
      };

  @TestOnly
  public static ParameterInfoUIContextEx createContext(
      Object[] objects,
      Editor editor,
      @NotNull ParameterInfoHandler handler,
      int currentParameterIndex) {
    return createContext(objects, editor, handler, currentParameterIndex, null);
  }

  @TestOnly
  public static ParameterInfoUIContextEx createContext(
      Object[] objects,
      Editor editor,
      @NotNull ParameterInfoHandler handler,
      int currentParameterIndex,
      @Nullable PsiElement parameterOwner) {
    final ParameterInfoComponent infoComponent =
        new ParameterInfoComponent(objects, editor, handler);
    infoComponent.setCurrentParameterIndex(currentParameterIndex);
    infoComponent.setParameterOwner(parameterOwner);
    return infoComponent.new MyParameterContext();
  }

  ParameterInfoComponent(Object[] objects, Editor editor, @NotNull ParameterInfoHandler handler) {
    super(new BorderLayout());

    if (!ApplicationManager.getApplication().isUnitTestMode()) {
      JComponent editorComponent = editor.getComponent();
      JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
      myWidthLimit = layeredPane.getWidth();
    }

    NORMAL_FONT = UIUtil.getLabelFont();
    BOLD_FONT = NORMAL_FONT.deriveFont(Font.BOLD);

    myObjects = objects;

    setBackground(BACKGROUND_COLOR);

    myHandler = handler;
    myPanels = new OneElementComponent[myObjects.length];
    final JPanel panel = new JPanel(new GridBagLayout());
    for (int i = 0; i < myObjects.length; i++) {
      myPanels[i] = new OneElementComponent();
      panel.add(
          myPanels[i],
          new GridBagConstraints(
              0,
              i,
              1,
              1,
              1,
              0,
              GridBagConstraints.WEST,
              GridBagConstraints.HORIZONTAL,
              new Insets(0, 0, 0, 0),
              0,
              0));
    }

    final JScrollPane pane = ScrollPaneFactory.createScrollPane(panel);
    pane.setBorder(null);
    pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    add(pane, BorderLayout.CENTER);

    myCurrentParameterIndex = -1;
  }

  @Override
  public Dimension getPreferredSize() {
    int size = myPanels.length;
    final Dimension preferredSize = super.getPreferredSize();
    if (size >= 0 && size <= 20) {
      return preferredSize;
    } else {
      return new Dimension(preferredSize.width + 20, 200);
    }
  }

  public Object getHighlighted() {
    return myHighlighted;
  }

  class MyParameterContext implements ParameterInfoUIContextEx {
    private int i;

    @Override
    public String setupUIComponentPresentation(
        String text,
        int highlightStartOffset,
        int highlightEndOffset,
        boolean isDisabled,
        boolean strikeout,
        boolean isDisabledBeforeHighlight,
        Color background) {
      final String resultedText =
          myPanels[i].setup(
              text,
              highlightStartOffset,
              highlightEndOffset,
              isDisabled,
              strikeout,
              isDisabledBeforeHighlight,
              background);
      myPanels[i].setBorder(
          isLastParameterOwner()
              ? BACKGROUND_BORDER
              : new SideBorder(new JBColor(JBColor.LIGHT_GRAY, Gray._90), SideBorder.BOTTOM));
      return resultedText;
    }

    @Override
    public String setupUIComponentPresentation(
        final String[] texts, final EnumSet<Flag>[] flags, final Color background) {
      final String resultedText = myPanels[i].setup(texts, flags, background);
      myPanels[i].setBorder(
          isLastParameterOwner()
              ? BACKGROUND_BORDER
              : new SideBorder(new JBColor(JBColor.LIGHT_GRAY, Gray._90), SideBorder.BOTTOM));
      return resultedText;
    }

    @Override
    public boolean isUIComponentEnabled() {
      return isEnabled(i);
    }

    @Override
    public void setUIComponentEnabled(boolean enabled) {
      setEnabled(i, enabled);
    }

    public boolean isLastParameterOwner() {
      return i == myPanels.length - 1;
    }

    @Override
    public int getCurrentParameterIndex() {
      return myCurrentParameterIndex;
    }

    @Override
    public PsiElement getParameterOwner() {
      return myParameterOwner;
    }

    @Override
    public Color getDefaultParameterColor() {
      return myObjects[i].equals(myHighlighted) ? HIGHLIGHTED_BORDER_COLOR : BACKGROUND_COLOR;
    }
  }

  public void update() {
    MyParameterContext context = new MyParameterContext();

    for (int i = 0; i < myObjects.length; i++) {
      context.i = i;
      final Object o = myObjects[i];

      //noinspection unchecked
      myHandler.updateUI(o, context);
    }

    invalidate();
    validate();
    repaint();
  }

  public Object[] getObjects() {
    return myObjects;
  }

  void setEnabled(int index, boolean enabled) {
    myPanels[index].setEnabled(enabled);
  }

  boolean isEnabled(int index) {
    return myPanels[index].isEnabled();
  }

  public void setCurrentParameterIndex(int currentParameterIndex) {
    myCurrentParameterIndex = currentParameterIndex;
  }

  public int getCurrentParameterIndex() {
    return myCurrentParameterIndex;
  }

  public void setParameterOwner(PsiElement element) {
    myParameterOwner = element;
  }

  public PsiElement getParameterOwner() {
    return myParameterOwner;
  }

  public void setHighlightedParameter(Object element) {
    myHighlighted = element;
  }

  private class OneElementComponent extends JPanel {
    private OneLineComponent[] myOneLineComponents;

    public OneElementComponent() {
      super(new GridBagLayout());
      myOneLineComponents = new OneLineComponent[0]; // TODO ???
    }

    private String setup(
        String text,
        int highlightStartOffset,
        int highlightEndOffset,
        boolean isDisabled,
        boolean strikeout,
        boolean isDisabledBeforeHighlight,
        Color background) {
      StringBuilder buf = new StringBuilder();
      removeAll();

      String[] lines = UIUtil.splitText(text, getFontMetrics(BOLD_FONT), myWidthLimit, ',');

      myOneLineComponents = new OneLineComponent[lines.length];

      int lineOffset = 0;

      boolean hasHighlighting =
          highlightStartOffset >= 0 && highlightEndOffset > highlightStartOffset;
      TextRange highlightingRange =
          hasHighlighting ? new TextRange(highlightStartOffset, highlightEndOffset) : null;

      for (int i = 0; i < lines.length; i++) {
        String line = lines[i];

        myOneLineComponents[i] = new OneLineComponent();

        TextRange lRange = new TextRange(lineOffset, lineOffset + line.length());
        TextRange hr = highlightingRange == null ? null : lRange.intersection(highlightingRange);
        hr = hr == null ? null : hr.shiftRight(-lineOffset);

        String before = escapeString(hr == null ? line : line.substring(0, hr.getStartOffset()));
        String in = hr == null ? "" : escapeString(hr.substring(line));
        String after =
            hr == null ? "" : escapeString(line.substring(hr.getEndOffset(), line.length()));

        TextRange escapedHighlightingRange =
            in.isEmpty() ? null : TextRange.create(before.length(), before.length() + in.length());
        buf.append(
            myOneLineComponents[i].setup(
                before + in + after, isDisabled, strikeout, background, escapedHighlightingRange));

        if (isDisabledBeforeHighlight) {
          if (highlightStartOffset < 0 || highlightEndOffset > lineOffset) {
            myOneLineComponents[i].setDisabledBeforeHighlight();
          }
        }

        add(
            myOneLineComponents[i],
            new GridBagConstraints(
                0,
                i,
                1,
                1,
                1,
                0,
                GridBagConstraints.WEST,
                GridBagConstraints.HORIZONTAL,
                new Insets(0, 0, 0, 0),
                0,
                0));

        lineOffset += line.length();
      }
      return buf.toString();
    }

    private String escapeString(String line) {
      return XmlStringUtil.escapeString(line);
    }

    public String setup(
        final String[] texts,
        final EnumSet<ParameterInfoUIContextEx.Flag>[] flags,
        final Color background) {
      StringBuilder buf = new StringBuilder();
      removeAll();
      final String[] lines =
          UIUtil.splitText(StringUtil.join(texts), getFontMetrics(BOLD_FONT), myWidthLimit, ',');

      int index = 0;
      int curOffset = 0;

      myOneLineComponents = new OneLineComponent[lines.length];

      Map<TextRange, ParameterInfoUIContextEx.Flag> flagsMap =
          new TreeMap<TextRange, ParameterInfoUIContextEx.Flag>(TEXT_RANGE_COMPARATOR);

      int added = 0;
      for (int i = 0; i < texts.length; i++) {
        String line = escapeString(texts[i]);
        if (lines.length <= index) break;
        String text = lines[index];
        final int paramCount = StringUtil.split(text, ", ").size();
        final EnumSet<ParameterInfoUIContextEx.Flag> flag = flags[i];
        if (flag.contains(ParameterInfoUIContextEx.Flag.HIGHLIGHT)) {
          flagsMap.put(
              TextRange.create(curOffset, curOffset + line.trim().length()),
              ParameterInfoUIContextEx.Flag.HIGHLIGHT);
        }

        if (flag.contains(ParameterInfoUIContextEx.Flag.DISABLE)) {
          flagsMap.put(
              TextRange.create(curOffset, curOffset + line.trim().length()),
              ParameterInfoUIContextEx.Flag.DISABLE);
        }

        if (flag.contains(ParameterInfoUIContextEx.Flag.STRIKEOUT)) {
          flagsMap.put(
              TextRange.create(curOffset, curOffset + line.trim().length()),
              ParameterInfoUIContextEx.Flag.STRIKEOUT);
        }

        curOffset += line.length();
        if (i == paramCount + added - 1) {
          myOneLineComponents[index] = new OneLineComponent();
          setBackground(background);
          buf.append(myOneLineComponents[index].setup(escapeString(text), flagsMap, background));
          add(
              myOneLineComponents[index],
              new GridBagConstraints(
                  0,
                  index,
                  1,
                  1,
                  1,
                  0,
                  GridBagConstraints.WEST,
                  GridBagConstraints.NONE,
                  new Insets(0, 0, 0, 0),
                  0,
                  0));
          index += 1;
          flagsMap.clear();
          curOffset = 1;
          added += paramCount;
        }
      }
      return buf.toString();
    }
  }

  private class OneLineComponent extends JPanel {
    JLabel myLabel = new JLabel("", SwingConstants.LEFT);
    private boolean isDisabledBeforeHighlight = false;

    private OneLineComponent() {
      super(new GridBagLayout());

      myLabel.setOpaque(true);
      myLabel.setFont(NORMAL_FONT);

      add(
          myLabel,
          new GridBagConstraints(
              0,
              0,
              1,
              1,
              1,
              1,
              GridBagConstraints.WEST,
              GridBagConstraints.NONE,
              new Insets(0, 0, 0, 0),
              0,
              0));
    }

    private String setup(
        String text,
        boolean isDisabled,
        boolean isStrikeout,
        Color background,
        @Nullable TextRange range) {
      Map<TextRange, ParameterInfoUIContextEx.Flag> flagsMap =
          new TreeMap<TextRange, ParameterInfoUIContextEx.Flag>(TEXT_RANGE_COMPARATOR);
      if (range != null) flagsMap.put(range, ParameterInfoUIContextEx.Flag.HIGHLIGHT);
      if (isDisabled)
        flagsMap.put(TextRange.create(0, text.length()), ParameterInfoUIContextEx.Flag.DISABLE);
      if (isStrikeout)
        flagsMap.put(TextRange.create(0, text.length()), ParameterInfoUIContextEx.Flag.STRIKEOUT);
      return setup(text, flagsMap, background);
    }

    private String setup(
        @NotNull String text,
        @NotNull Map<TextRange, ParameterInfoUIContextEx.Flag> flagsMap,
        @NotNull Color background) {
      myLabel.setBackground(background);
      setBackground(background);

      myLabel.setForeground(JBColor.foreground());

      if (flagsMap.isEmpty()) {
        myLabel.setText(XmlStringUtil.wrapInHtml(text));
      } else {
        String labelText = buildLabelText(text, flagsMap);
        myLabel.setText(labelText);
      }

      // IDEA-95904 Darcula parameter info pop-up colors hard to read
      if (UIUtil.isUnderDarcula()) {
        myLabel.setText(myLabel.getText().replace("<b>", "<b color=ffC800>"));
      }
      return myLabel.getText();
    }

    private String buildLabelText(
        @NotNull final String text,
        @NotNull final Map<TextRange, ParameterInfoUIContextEx.Flag> flagsMap) {
      final StringBuilder labelText = new StringBuilder(text);
      final String disabledTag = FLAG_TO_TAG.get(ParameterInfoUIContextEx.Flag.DISABLE);

      final Map<Integer, Integer> faultMap = new HashMap<Integer, Integer>();
      if (isDisabledBeforeHighlight) {
        final String tag = getTag(disabledTag);
        labelText.insert(0, tag);
        faultMap.put(0, tag.length());
      }

      for (Map.Entry<TextRange, ParameterInfoUIContextEx.Flag> entry : flagsMap.entrySet()) {
        final TextRange highlightRange = entry.getKey();
        final ParameterInfoUIContextEx.Flag flag = entry.getValue();

        final String tagValue = FLAG_TO_TAG.get(flag);
        final String tag = getTag(tagValue);

        int startOffset = highlightRange.getStartOffset();
        int endOffset = highlightRange.getEndOffset() + tag.length();

        for (Map.Entry<Integer, Integer> entry1 : faultMap.entrySet()) {
          if (entry1.getKey() < highlightRange.getStartOffset()) {
            startOffset += entry1.getValue();
          }
          if (entry1.getKey() < highlightRange.getEndOffset()) {
            endOffset += entry1.getValue();
          }
        }

        if (flag == ParameterInfoUIContextEx.Flag.HIGHLIGHT && isDisabledBeforeHighlight) {
          final String disableCloseTag = getClosingTag(disabledTag);
          labelText.insert(startOffset, disableCloseTag);
          faultMap.put(highlightRange.getStartOffset(), disableCloseTag.length());
        }

        labelText.insert(startOffset, tag);
        faultMap.put(highlightRange.getStartOffset(), tag.length());

        final String endTag = getClosingTag(tagValue);
        labelText.insert(endOffset, endTag);
        faultMap.put(highlightRange.getEndOffset(), endTag.length());
      }
      return XmlStringUtil.wrapInHtml(labelText);
    }

    private String getTag(@NotNull final String tagValue) {
      return "<" + tagValue + ">";
    }

    private String getClosingTag(@NotNull final String tagValue) {
      return "</" + tagValue + ">";
    }

    public void setDisabledBeforeHighlight() {
      isDisabledBeforeHighlight = true;
    }
  }
}
Ejemplo n.º 19
0
  public InterpreterFrame() {
    super("Simple Lisp Interpreter");

    // Create the menu
    menubar = buildMenuBar();
    setJMenuBar(menubar);
    // Create the toolbar
    toolbar = buildToolBar();
    // disable cut and copy actions
    cutAction.setEnabled(false);
    copyAction.setEnabled(false);
    // Setup text area for editing source code
    // and setup document listener so interpreter
    // is notified when current file modified and
    // when the cursor is moved.
    textView = buildEditor();
    textView.getDocument().addDocumentListener(this);
    textView.addCaretListener(this);

    // set default key bindings
    bindKeyToCommand("ctrl C", "(buffer-copy)");
    bindKeyToCommand("ctrl X", "(buffer-cut)");
    bindKeyToCommand("ctrl V", "(buffer-paste)");
    bindKeyToCommand("ctrl E", "(buffer-eval)");
    bindKeyToCommand("ctrl O", "(file-open)");
    bindKeyToCommand("ctrl S", "(file-save)");
    bindKeyToCommand("ctrl Q", "(exit)");

    // Give text view scrolling capability
    Border border =
        BorderFactory.createCompoundBorder(
            BorderFactory.createEmptyBorder(3, 3, 3, 3),
            BorderFactory.createLineBorder(Color.gray));
    JScrollPane topSplit = addScrollers(textView);
    topSplit.setBorder(border);

    // Create tabbed pane for console/problems
    consoleView = makeConsoleArea(10, 50, true);
    problemsView = makeConsoleArea(10, 50, false);
    tabbedPane = buildProblemsConsole();

    // Plug the editor and problems/console together
    // using a split pane. This allows one to change
    // their relative size using the split-bar in
    // between them.
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topSplit, tabbedPane);

    // Create status bar
    statusView = new JLabel(" Status");
    lineNumberView = new JLabel("0:0");
    statusbar = buildStatusBar();

    // Now, create the outer panel which holds
    // everything together
    outerpanel = new JPanel();
    outerpanel.setLayout(new BorderLayout());
    outerpanel.add(toolbar, BorderLayout.PAGE_START);
    outerpanel.add(splitPane, BorderLayout.CENTER);
    outerpanel.add(statusbar, BorderLayout.SOUTH);
    getContentPane().add(outerpanel);

    // tell frame to fire a WindowsListener event
    // but not to close when "x" button clicked.
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(this);
    // set minimised icon to use
    setIconImage(makeImageIcon("spi.png").getImage());

    // setup additional internal functions
    InternalFunctions.setup_internals(interpreter, this);

    // set default window size
    Component top = splitPane.getTopComponent();
    Component bottom = splitPane.getBottomComponent();
    top.setPreferredSize(new Dimension(100, 400));
    bottom.setPreferredSize(new Dimension(100, 200));
    pack();

    // load + run user configuration file (if there is one)
    String homedir = System.getProperty("user.home");
    try {
      interpreter.load(homedir + "/.simplelisp");
    } catch (FileNotFoundException e) {
      // do nothing if file does not exist!
      System.out.println("Didn't find \"" + homedir + "/.simplelisp\"");
    }

    textView.grabFocus();
    setVisible(true);

    // redirect all I/O to problems/console
    redirectIO();

    // start highlighter thread
    highlighter = new DisplayThread(250);
    highlighter.setDaemon(true);
    highlighter.start();
  }
Ejemplo n.º 20
0
  public CellarGUI(Cellar model) {
    this.model = model;
    setTitle("Cellar");
    setSize(new Dimension(1000, 600));
    setResizable(false);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(new BorderLayout());
    health.setPreferredSize(new Dimension(200, 10));
    exp.setPreferredSize(new Dimension(200, 10));
    currentRoom.setPreferredSize(new Dimension(200, 10));
    spacer.setPreferredSize(new Dimension(200, 115));
    magicLabel.setPreferredSize(new Dimension(200, 10));
    magicLabel.setHorizontalAlignment(JLabel.CENTER);
    playerItemLabel.setText("Player's Items (Max 1)");
    setLabels();

    JScrollPane playerItemsPane = new JScrollPane();
    playerItemsList.setListData(model.getPlayer().getItemList().toArray());
    playerItemsPane.setViewportView(playerItemsList);
    playerItemsPane.setPreferredSize(new Dimension(200, 125));
    JButton drop = new JButton("Drop Item");
    drop.addActionListener(this);
    drop.setPreferredSize(new Dimension(200, 25));

    JScrollPane roomItemsPane = new JScrollPane();
    roomItemsList = new JList(getRoomItems());
    roomItemsPane.setViewportView(roomItemsList);
    roomItemsPane.setPreferredSize(new Dimension(200, 125));
    JButton pickUp = new JButton("Pick Up");
    pickUp.addActionListener(this);
    pickUp.setPreferredSize(new Dimension(200, 25));

    JScrollPane hallsPane = new JScrollPane();
    hallList = new JList(getHalls());
    hallsPane.setViewportView(hallList);
    hallsPane.setPreferredSize(new Dimension(200, 200));
    JButton enterHall = new JButton("Enter Hallway");
    enterHall.setPreferredSize(new Dimension(200, 25));
    enterHall.addActionListener(this);

    JScrollPane outputPane = new JScrollPane();
    output = new JTextArea();
    outputPane.setPreferredSize(new Dimension(550, 550));
    output.setEditable(false);
    output.setBorder(BorderFactory.createLineBorder(Color.black));
    outputPane.setViewportView(output);

    JLabel roomItemLabel = new JLabel("Items in the Room");
    JLabel hallsLabel = new JLabel("Hallways");
    JPanel rightPanel = new JPanel();
    JPanel leftPanel = new JPanel();
    rightPanel.add(playerItemLabel);
    rightPanel.add(playerItemsPane);
    rightPanel.add(drop);
    rightPanel.add(roomItemLabel);
    rightPanel.add(roomItemsPane);
    rightPanel.add(pickUp);
    rightPanel.add(magicLabel);
    rightPanel.add(magic);
    rightPanel.add(spacer);
    rightPanel.add(health);
    rightPanel.add(exp);
    rightPanel.add(currentRoom);
    rightPanel.setPreferredSize(new Dimension(200, 600));
    rightPanel.setBackground(Color.WHITE);
    leftPanel.add(hallsLabel);
    leftPanel.add(hallsPane);
    leftPanel.add(enterHall);
    leftPanel.setPreferredSize(new Dimension(200, 600));
    leftPanel.setBackground(Color.WHITE);
    add(outputPane, BorderLayout.CENTER);
    add(rightPanel, BorderLayout.WEST);
    add(leftPanel, BorderLayout.EAST);
  }
Ejemplo n.º 21
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));
  }
Ejemplo n.º 22
0
  public ContextEditor(Context cntxt) {
    super("Edit User Context: " + localFileName(cntxt));
    ctxt = cntxt;
    windowNum = ctxt.languageName + " Context Editor";
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    listener = new CEListener(this);

    JPanel nameBox = new JPanel();
    nameBox.setLayout(new BoxLayout(nameBox, BoxLayout.LINE_AXIS));
    name = new JTextField(ctxt.languageName, 28);
    name.setMaximumSize(new Dimension(225, 22));
    name.addFocusListener(
        new java.awt.event.FocusAdapter() {

          public void focusLost(java.awt.event.FocusEvent evt) {
            nameFocusLost(evt);
          }
        });

    JLabel nameLabel = new JLabel("Language Name: ");
    nameBox.add(nameLabel);
    nameBox.add(name);

    JPanel folderBox = new JPanel();
    folderBox.setLayout(new BoxLayout(folderBox, BoxLayout.LINE_AXIS));
    folder = new JTextField(ctxt.editDirectory);
    folder.setMaximumSize(new Dimension(225, 22));
    //        folder.addActionListener(listener);
    //        folder.setActionCommand("folder edit");
    folder.addFocusListener(
        new java.awt.event.FocusAdapter() {

          public void focusLost(java.awt.event.FocusEvent evt) {
            folderFocusLost(evt);
          }
        });

    JLabel folderLabel = new JLabel("SILK file folder: ");
    folderBox.add(folderLabel);
    folderBox.add(folder);

    JPanel nameFolderBox = new JPanel();
    nameFolderBox.setLayout(new BoxLayout(nameFolderBox, BoxLayout.PAGE_AXIS));
    nameBox.setAlignmentX(0.5f);
    nameFolderBox.add(nameBox);
    nameFolderBox.add(Box.createRigidArea(new Dimension(0, 4)));
    nameFolderBox.add(folderBox);
    nameFolderBox.setAlignmentX(0.5f);

    buildPopulationBox();

    JPanel btnBoxUDPs = new JPanel(), subBoxUDP = new JPanel();
    btnBoxUDPs.setLayout(new BoxLayout(btnBoxUDPs, BoxLayout.PAGE_AXIS));
    subBoxUDP.setLayout(new BoxLayout(subBoxUDP, BoxLayout.LINE_AXIS));
    int numUDPs = 0;
    if (ctxt.userDefinedProperties != null) {
      numUDPs = ctxt.userDefinedProperties.size();
    }
    String plur = "ies";
    if (numUDPs == 1) {
      plur = "y";
    }
    JLabel udpLabel = new JLabel("Has " + numUDPs + " User-Defined Propert" + plur);
    subBoxUDP.add(udpLabel);
    JButton addUDP = new JButton("Add UDP");
    addUDP.setActionCommand("add UDP");
    addUDP.addActionListener(listener);
    subBoxUDP.add(addUDP);
    btnBoxUDPs.add(subBoxUDP);
    if (numUDPs > 0) {
      Dimension sizer = new Dimension(250, 50);
      String[] udpMenu = genUDPMenu();
      UDPick = new JComboBox(udpMenu);
      UDPick.addActionListener(listener);
      UDPick.setActionCommand("view/edit UDP");
      UDPick.setMinimumSize(sizer);
      UDPick.setMaximumSize(sizer);
      UDPick.setBorder(
          BorderFactory.createTitledBorder(
              BorderFactory.createLineBorder(Color.blue), "View/Edit UDPs"));
      btnBoxUDPs.add(UDPick);
    } //  end of if-any-UDPs-exist

    JPanel domThs = new JPanel();
    domThs.setLayout(new BoxLayout(domThs, BoxLayout.PAGE_AXIS));
    domThs.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createLineBorder(Color.blue), "Kinship System Domain Theories"));
    domThs.setAlignmentX(0.5f);
    JPanel dtRefBtnBox = new JPanel();
    dtRefBtnBox.setLayout(new BoxLayout(dtRefBtnBox, BoxLayout.LINE_AXIS));
    dtRefBtnBox.setAlignmentX(0.0f);
    JLabel dtRefLabel = new JLabel("Terms of Reference ");
    dtRefBtnBox.add(dtRefLabel);
    if (ctxt.domTheoryRefExists()) {
      JButton dtRefEdit = new JButton("Edit Theory");
      dtRefEdit.setActionCommand("edit dtRef");
      dtRefEdit.addActionListener(listener);
      dtRefBtnBox.add(dtRefEdit);
      //            JButton dtRefDelete = new JButton("Delete Theory");
      //            dtRefDelete.setActionCommand("dtRef delete");
      //            dtRefDelete.addActionListener(listener);
      //            dtRefBtnBox.add(dtRefDelete);
    } //  end of if-dt-exists
    else { //  if does not exist
      JLabel dtRefNone = new JLabel("< None >");
      dtRefBtnBox.add(dtRefNone);
      //            JButton dtRefAdd = new JButton("Add Theory");
      //            dtRefAdd.setActionCommand("dtRef add");
      //            dtRefAdd.addActionListener(listener);
      //            dtRefBtnBox.add(dtRefAdd);
    } //  end of does-not-exist
    domThs.add(dtRefBtnBox);

    JPanel dtAddrBtnBox = new JPanel();
    dtAddrBtnBox.setLayout(new BoxLayout(dtAddrBtnBox, BoxLayout.LINE_AXIS));
    dtAddrBtnBox.setAlignmentX(0.0f);
    JLabel dtAddrLabel = new JLabel("Terms of Address ");
    dtAddrBtnBox.add(dtAddrLabel);
    if (ctxt.domTheoryAdrExists()) {
      JButton dtAddrEdit = new JButton("Edit Theory");
      dtAddrEdit.setActionCommand("edit dtAddr");
      dtAddrEdit.addActionListener(listener);
      dtAddrBtnBox.add(dtAddrEdit);
      //            JButton dtAddrViewList = new JButton("Delete Theory");
      //            dtAddrViewList.setActionCommand("dtAddr delete");
      //            dtAddrViewList.addActionListener(listener);
      //            dtAddrBtnBox.add(dtAddrViewList);
    } //  end of if-dt-exists
    else { //  if does not exist
      JLabel dtAddrNone = new JLabel("< None >");
      dtAddrBtnBox.add(dtAddrNone);
      //            JButton dtAddrAdd = new JButton("Add Theory");
      //            dtAddrAdd.setActionCommand("dtAddr add");
      //            dtAddrAdd.addActionListener(listener);
      //            dtAddrBtnBox.add(dtAddrAdd);
    } //  end of does-not-exist
    domThs.add(dtAddrBtnBox);
    // End of the left hand portion
    // Right hand portion follows. it is narrower.

    JPanel polyBox = new JPanel();
    polyBox.setLayout(new BoxLayout(polyBox, BoxLayout.PAGE_AXIS));
    polyBox.setAlignmentX(0.5f);
    JLabel polyLabelA = new JLabel("Polygamy");
    JLabel polyLabelB = new JLabel("Permitted?");
    JRadioButton yesPoly = new JRadioButton("Yes");
    yesPoly.setActionCommand("polygamy yes");
    yesPoly.addActionListener(listener);
    JRadioButton noPoly = new JRadioButton("No");
    noPoly.setActionCommand("polygamy no");
    noPoly.addActionListener(listener);
    if (cntxt.polygamyPermit) {
      yesPoly.setSelected(true);
    } else {
      noPoly.setSelected(true);
    }
    ButtonGroup polyBtns = new ButtonGroup();
    polyBtns.add(yesPoly);
    polyBtns.add(noPoly);
    polyBox.add(polyLabelA);
    polyBox.add(polyLabelB);
    polyBox.add(yesPoly);
    polyBox.add(noPoly);

    JPanel matrixBox = new JPanel();
    matrixBox.setLayout(new BoxLayout(matrixBox, BoxLayout.PAGE_AXIS));
    matrixBox.setAlignmentX(0.5f);
    JLabel matrixLabelA = new JLabel("Kin Term Matrix");
    JLabel matrixLabelC = new JLabel(ctxt.indSerNumGen + " rows");
    JLabel matrixLabelD = new JLabel(ctxt.ktm.numberOfKinTerms() + " terms");
    matrixLabelA.setAlignmentX(0.5f);
    matrixLabelC.setAlignmentX(0.5f);
    matrixLabelD.setAlignmentX(0.5f);
    JButton matrixEditBtn = new JButton("Edit Matrix");
    matrixEditBtn.setEnabled(false);
    matrixEditBtn.setActionCommand("edit matrix");
    matrixEditBtn.addActionListener(listener);
    matrixEditBtn.setAlignmentX(0.5f);
    matrixBox.add(matrixLabelA);
    matrixBox.add(matrixLabelC);
    matrixBox.add(matrixLabelD);
    matrixBox.add(matrixEditBtn);

    JPanel distinctBox = new JPanel();
    distinctBox.setLayout(new BoxLayout(distinctBox, BoxLayout.PAGE_AXIS));
    distinctBox.setAlignmentX(0.5f);
    JLabel distinctLabelA = new JLabel("Distinct Terms");
    JLabel distinctLabelB = new JLabel("of Address");
    distinctLabelA.setAlignmentX(0.5f);
    distinctLabelB.setAlignmentX(0.5f);
    JRadioButton yesDistinct = new JRadioButton("Yes");
    yesDistinct.setActionCommand("distinct yes");
    yesDistinct.addActionListener(listener);
    JRadioButton noDistinct = new JRadioButton("No");
    noDistinct.setActionCommand("distinct no");
    noDistinct.addActionListener(listener);
    yesDistinct.setAlignmentX(0.5f);
    noDistinct.setAlignmentX(0.5f);
    if (ctxt.distinctAdrTerms) {
      yesDistinct.setSelected(true);
    } else {
      noDistinct.setSelected(true);
    }
    ButtonGroup distinctBtns = new ButtonGroup();
    distinctBtns.add(yesDistinct);
    distinctBtns.add(noDistinct);
    distinctBox.add(distinctLabelA);
    distinctBox.add(distinctLabelB);
    distinctBox.add(yesDistinct);
    distinctBox.add(noDistinct);

    /*
     * NOTE: It should be possible to put all these elements directly into
     * the ContentPane. But that doesn't work; the layout is truly ugly and
     * stuff gets stacked on top of other stuff. What works is to put
     * everything into a JPanel with BoxLayout. Then put the JPanel into
     * ContentPane.
     */
    JPanel leftCol = new JPanel();
    leftCol.setLayout(new BoxLayout(leftCol, BoxLayout.PAGE_AXIS));
    leftCol.add(nameFolderBox);
    leftCol.add(Box.createRigidArea(new Dimension(0, 4)));
    leftCol.add(populationBox);
    leftCol.add(Box.createRigidArea(new Dimension(0, 8)));
    leftCol.add(btnBoxUDPs);
    leftCol.add(Box.createRigidArea(new Dimension(0, 8)));
    leftCol.add(domThs);
    leftCol.add(new JLabel(" "));

    JPanel rightCol = new JPanel();
    rightCol.setLayout(new BoxLayout(rightCol, BoxLayout.PAGE_AXIS));
    rightCol.setBorder(
        BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.blue), "Options"));
    rightCol.add(Box.createRigidArea(new Dimension(0, 20)));
    rightCol.add(polyBox);
    rightCol.add(Box.createRigidArea(new Dimension(0, 20)));
    rightCol.add(matrixBox);
    int high = (numUDPs > 0 ? 120 : 20);
    rightCol.add(Box.createRigidArea(new Dimension(0, high)));
    rightCol.add(distinctBox);

    JPanel commentBox = new JPanel();
    commentBox.setLayout(new BoxLayout(commentBox, BoxLayout.PAGE_AXIS));
    commentBox.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createLineBorder(Color.blue), "Notes on this culture:"));
    JScrollPane commentsPane = new JScrollPane();
    comments = new JTextArea();
    comments.setColumns(20);
    comments.setEditable(true);
    comments.setRows(3);
    comments.setText(PersonPanel.restoreLineBreaks(ctxt.comments));
    comments.getDocument().addDocumentListener(new CommentListener());
    commentsPane.setViewportView(comments);
    commentBox.add(commentsPane);

    JPanel guts = new JPanel(); // Holds the guts of this window
    guts.setLayout(new BoxLayout(guts, BoxLayout.LINE_AXIS));
    guts.add(leftCol);
    guts.add(Box.createRigidArea(new Dimension(10, 4)));
    guts.add(rightCol);

    JPanel wholeThing = new JPanel();
    wholeThing.setLayout(new BoxLayout(wholeThing, BoxLayout.PAGE_AXIS));
    wholeThing.add(Box.createRigidArea(new Dimension(0, 4)));
    wholeThing.add(guts);
    wholeThing.add(Box.createRigidArea(new Dimension(0, 8)));
    wholeThing.add(commentBox);
    wholeThing.add(Box.createRigidArea(new Dimension(0, 4)));

    getContentPane().add(wholeThing);

    addInternalFrameListener(this);
    setSize(600, 620);
    setVisible(true);
  } //  end of ContextEditor constructor