Example #1
0
 /**
  * This method initializes txtDisplay
  *
  * @return javax.swing.JTextField
  */
 JTextField getTxtDisplay() {
   if (txtDisplay == null) {
     txtDisplay = new JTextField("");
     txtDisplay.setHorizontalAlignment(javax.swing.JTextField.LEFT);
     txtDisplay.setAlignmentX(0.0F);
     txtDisplay.setPreferredSize(new java.awt.Dimension(250, 20));
     txtDisplay.setText("");
     txtDisplay.setMinimumSize(new java.awt.Dimension(250, 20));
     txtDisplay.setMaximumSize(new java.awt.Dimension(250, 20));
   }
   return txtDisplay;
 }
Example #2
0
  // constructor of TextFrame
  public TextFrame() {
    // this.message = message;
    message = "Click to Edit Text";
    messageFont = new Font("Arial", Font.PLAIN, 30);
    foreground = Color.black;
    background = Color.white;

    // custom dialog (it's a private class inside TextFrame)
    cd = new CustomDialog(this);

    messageField = new JTextField();
    messageField.setPreferredSize(new Dimension(300, 200));
    messageField.setEditable(false);
    messageField.setHorizontalAlignment(SwingConstants.CENTER);
    messageField.setAlignmentX(Component.CENTER_ALIGNMENT);
    updateMessage();

    customize = new JButton("Customize");
    customize.setMaximumSize(customize.getPreferredSize());
    customize.setAlignmentX(Component.CENTER_ALIGNMENT);

    apply = new JButton("Apply");
    apply.setMaximumSize(customize.getPreferredSize());
    apply.setAlignmentX(Component.CENTER_ALIGNMENT);

    /*add the listeners*/
    customize.addActionListener(this);
    apply.addActionListener(this);
    messageField.addMouseListener(new PopUpClass());

    // customize
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    p.add(customize);
    p.add(Box.createRigidArea(new Dimension(0, 25)));
    p.add(messageField);
    p.add(Box.createRigidArea(new Dimension(0, 25)));
    p.add(apply);
    p.setBorder(BorderFactory.createEmptyBorder(25, 25, 25, 25));

    // make panel this JFrame's content pane

    this.setContentPane(p);
  }
Example #3
0
  void init() {

    /* ============
     *     Windows
     * ============ */

    this.setResizable(false);
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container con = this.getContentPane(); // inherit main frame
    con.add(panel); // add the panel to frame

    /* ============
     *     Menu
     * ============ */

    this.setIconImage(new ImageIcon("img/title_img.png").getImage());
    // Where the GUI is created:
    JMenuBar menuBar;
    JMenu menu;
    JMenuItem menuItem;

    // Create the menu bar.
    menuBar = new JMenuBar();

    // Build the first menu.
    menu = new JMenu("File");
    menu.setMnemonic(KeyEvent.VK_A);
    menuBar.add(menu);

    // a group of JMenuItems
    menuItem = new JMenuItem("About", new ImageIcon("img/about.png"));
    menu.add(menuItem);

    this.setJMenuBar(menuBar);

    /* ============
     *    Content
     * ============ */

    JLabel logo = new JLabel(new ImageIcon("img/title_img.png"));
    logo.setAlignmentX(CENTER_ALIGNMENT);
    final JTextField nickname = new JTextField();
    final Border defaultBorder = nickname.getBorder();

    nickname.setText("Enter a nickname");
    nickname.setPreferredSize(new Dimension(250, 30));
    nickname.setMaximumSize(nickname.getPreferredSize());
    nickname.setAlignmentX(CENTER_ALIGNMENT);

    // nickname.addFocusListener(this);
    nickname.addFocusListener(
        new FocusListener() {
          @Override
          public void focusLost(FocusEvent e) {
            // TODO Auto-generated method stub
            if (!nickname.getText().equals("Enter a nickname")) {
              nickname.setText(nickname.getText().replace(" ", ""));
            }

            if (nickname.getText().equals("") || nickname.getText().equals("Enter a nickname")) {
              nickname.setText("Enter a nickname");
              goodNickname = false;
            }
          }

          @Override
          public void focusGained(FocusEvent e) {
            // TODO Auto-generated method stub
            goodNickname = true;
          }
        });

    nickname.addMouseListener(
        new MouseListener() {

          @Override
          public void mouseReleased(MouseEvent arg0) {
            // TODO Auto-generated method stub

          }

          @Override
          public void mousePressed(MouseEvent arg0) {
            // TODO Auto-generated method stub
            if (nickname.getText().equals("Enter a nickname")) {
              nickname.setText("");
              nickname.setBorder(defaultBorder);
            }
          }

          @Override
          public void mouseExited(MouseEvent arg0) {
            // TODO Auto-generated method stub

          }

          @Override
          public void mouseEntered(MouseEvent arg0) {
            // TODO Auto-generated method stub

          }

          @Override
          public void mouseClicked(MouseEvent arg0) {
            // TODO Auto-generated method stub

          }
        });

    final JButton connect = new JButton("Connect");
    connect.setPreferredSize(new Dimension(250, 30));
    connect.setMaximumSize(connect.getPreferredSize());
    connect.setAlignmentX(CENTER_ALIGNMENT);

    connect.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
            if (goodNickname) {
              openChatGUI(nickname);
            } else {
              nickname.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.red));
            }
          }
        });

    nickname.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
            if (goodNickname) {
              openChatGUI(nickname);
            } else {
              nickname.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.red));
            }
          }
        });

    panel.add(Box.createRigidArea(new Dimension(0, 15)));
    panel.add(logo);
    panel.add(Box.createRigidArea(new Dimension(0, 30)));
    panel.add(nickname);
    panel.add(Box.createRigidArea(new Dimension(0, 10)));
    panel.add(connect);

    setVisible(true); // display this frame
  }
Example #4
0
  private void initComponents() {
    final TitledBorder border = BorderFactory.createTitledBorder(label);
    final Font titleFont = border.getTitleFont();
    if (titleFont != null) {
      border.setTitleFont(titleFont.deriveFont(Font.BOLD));
    }
    setBorder(border);

    jtext = new JTextField();
    // jtext.setText(defalt.getFile().getPath());
    jRelativneKProgramu = new JCheckBox("Relativně k umístění programu");
    jRelativneKProgramu.setEnabled(FConst.JAR_DIR_EXISTUJE);
    jActive = new JCheckBox("Aktivní");
    jActive.setEnabled(lzeDeaktivovat);
    jCurrVal = new JTextField();
    jCurrVal.setForeground(Color.BLUE);
    jCurrVal.setEditable(false);
    jCurrVal.setBorder(null);
    final JButton jbut = new JButton("...");
    // jtext.setText(defalt.getFile().getPath());
    jtext.setColumns(50);
    if (editovatelne) {
      final Box box2 = Box.createHorizontalBox();
      box2.setAlignmentX(LEFT_ALIGNMENT);
      box2.add(jtext);
      box2.add(jbut);
      final Box panel3 = Box.createHorizontalBox();
      if (FConst.JAR_DIR_EXISTUJE) {
        panel3.add(jRelativneKProgramu);
      }
      if (jActive.isEnabled()) {
        panel3.add(jActive);
      }
      if (panel3.getComponentCount() > 0) {
        add(panel3);
      }
      panel3.setAlignmentX(LEFT_ALIGNMENT);
      add(box2);
    }
    // panel.add(Box.createVerticalStrut(20));
    jCurrVal.setAlignmentX(LEFT_ALIGNMENT);
    add(jCurrVal);
    // add(panel);
    // add(Box.createVerticalStrut(20));
    jbut.addActionListener(
        new ActionListener() {
          private JFileChooser fc;

          @Override
          public void actionPerformed(final ActionEvent ae) {
            if (fc == null) { // dlouho to trvá, tak vytvoříme vždy nový
              fc = new JFileChooser();
            }
            fc.setCurrentDirectory(new File(jtext.getText()));
            if (jenAdresare) {
              fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            }
            final int result = fc.showDialog(JJedenSouborPanel.this, "Vybrat");
            if (result == JFileChooser.APPROVE_OPTION) {
              jtext.setText(fc.getSelectedFile().getPath());
            }
          }
        });

    prepocitej();
    jtext.getDocument().addDocumentListener(this);

    jRelativneKProgramu.addActionListener(e -> prepocitej());
    jActive.addActionListener(e -> prepocitej());
  }
Example #5
0
  private void makeUi() {
    setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

    JPanel loginPane = createPane();
    loginPane.setLayout(new BoxLayout(loginPane, BoxLayout.Y_AXIS));
    add(loginPane);
    JLabel label = new JLabel("Login");
    loginPane.add(label);
    login = new JTextField();
    login.setAlignmentX(LEFT_ALIGNMENT);
    login.setPreferredSize(new Dimension(225, 25));
    loginPane.add(login);

    JPanel passwordPane = createPane();
    passwordPane.setLayout(new BoxLayout(passwordPane, BoxLayout.Y_AXIS));
    add(passwordPane);
    passwordPane.add(new JLabel("Password"));
    password = new JTextField();
    password.setAlignmentX(LEFT_ALIGNMENT);
    ;
    password.setPreferredSize(new Dimension(225, 25));
    passwordPane.add(password);

    JPanel dirPane = createPane();
    add(dirPane);
    dirPane.add(new JLabel("Directory"));
    JPanel dirSelectPane = new JPanel();
    dirSelectPane.setAlignmentX(LEFT_ALIGNMENT);
    dirPane.add(dirSelectPane);
    dirSelectPane.setLayout(new BoxLayout(dirSelectPane, BoxLayout.X_AXIS));
    directory = new JTextField();
    dirSelectPane.add(directory);
    JButton dirSelBtn = new JButton("...");
    dirSelectPane.add(dirSelBtn);

    final JDialog self = this;
    dirSelBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showOpenDialog(self);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
              directory.setText(chooser.getSelectedFile().getAbsolutePath());
            }
          }
        });

    JPanel buttonsPane = new JPanel();
    buttonsPane.setLayout(new BoxLayout(buttonsPane, BoxLayout.X_AXIS));
    buttonsPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    buttonsPane.setAlignmentX(LEFT_ALIGNMENT);
    buttonsPane.add(Box.createHorizontalGlue());

    JButton okBtn = new JButton("OK");
    okBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            isOk = true;
            setVisible(false);
          }
        });
    buttonsPane.add(okBtn);

    JButton cancelBtn = new JButton("Cancel");
    cancelBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            isOk = false;
            setVisible(false);
          }
        });
    buttonsPane.add(cancelBtn);
    add(buttonsPane);
  }
  public void addComponents(javax.swing.JLayeredPane pane) {
    // draw score area
    JLabel scoreHeader = new JLabel("Scores:"); // header label
    scoreHeader.setAlignmentX(Component.CENTER_ALIGNMENT);
    scoreHeader.setSize(scoreHeader.getPreferredSize());
    scoreHeader.setLocation(680, 0);
    scoreContainer.add(scoreHeader, JLayeredPane.DEFAULT_LAYER);

    for (int i = 0; i < numPlayers; i++) {
      playerScores[i] = 0;
      scoreLabels[i] = new JLabel("Player " + i + ": " + playerScores[i]);
      scoreLabels[i].setAlignmentX(Component.CENTER_ALIGNMENT);
      scoreLabels[i].setSize(scoreLabels[i].getPreferredSize());
      scoreLabels[i].setLocation(675, 10 * i);
      scoreContainer.add(scoreLabels[i], JLayeredPane.DEFAULT_LAYER);
    }

    turnSubmit.setAlignmentX(Component.CENTER_ALIGNMENT);
    turnSubmit.addActionListener(this);
    turnSubmit.setActionCommand("submit");

    pass.setAlignmentX(Component.CENTER_ALIGNMENT);
    pass.addActionListener(this);
    pass.setActionCommand("pass");

    currentTurnScore.setAlignmentX(Component.CENTER_ALIGNMENT);

    wordToCheck.setAlignmentX(Component.CENTER_ALIGNMENT);
    wordToCheck.setMaximumSize(new Dimension(150, 25));

    checkResult.setAlignmentX(Component.CENTER_ALIGNMENT);
    bagTiles.setAlignmentX(Component.CENTER_ALIGNMENT);
    turnTime.setAlignmentX(Component.CENTER_ALIGNMENT);
    timeHead.setAlignmentX(Component.CENTER_ALIGNMENT);

    resetHand.setAlignmentX(Component.CENTER_ALIGNMENT);
    resetHand.addActionListener(this);
    resetHand.setActionCommand("reset");

    checkWord.setAlignmentX(Component.CENTER_ALIGNMENT);
    checkWord.addActionListener(this);
    checkWord.setActionCommand("check");

    quit.setAlignmentX(Component.CENTER_ALIGNMENT);
    quit.addActionListener(this);
    quit.setActionCommand("quit");

    hint.setAlignmentX(Component.CENTER_ALIGNMENT);
    hint.addActionListener(this);
    hint.setActionCommand("hint");

    menu.setAlignmentX(Component.CENTER_ALIGNMENT);
    menu.addActionListener(this);
    menu.setActionCommand("back");

    JLabel checkHeader = new JLabel("Check the validity of a word:");
    checkHeader.setAlignmentX(Component.CENTER_ALIGNMENT);

    scoreContainer.add(Box.createVerticalStrut(10));
    scoreContainer.add(turnSubmit, JLayeredPane.DEFAULT_LAYER);
    scoreContainer.add(Box.createVerticalStrut(10));
    scoreContainer.add(pass, JLayeredPane.DEFAULT_LAYER);
    scoreContainer.add(Box.createVerticalStrut(10));
    scoreContainer.add(resetHand, JLayeredPane.DEFAULT_LAYER);
    scoreContainer.add(Box.createVerticalStrut(10));
    scoreContainer.add(hint, JLayeredPane.DEFAULT_LAYER);
    scoreContainer.add(Box.createVerticalStrut(10));
    scoreContainer.add(currentTurnScore, JLayeredPane.DEFAULT_LAYER);
    scoreContainer.add(Box.createVerticalStrut(10));
    scoreContainer.add(timeHead, JLayeredPane.DEFAULT_LAYER);
    scoreContainer.add(turnTime, JLayeredPane.DEFAULT_LAYER);
    scoreContainer.add(Box.createVerticalStrut(10));
    scoreContainer.add(checkHeader, JLayeredPane.DEFAULT_LAYER);
    scoreContainer.add(wordToCheck, JLayeredPane.DEFAULT_LAYER);
    scoreContainer.add(checkWord, JLayeredPane.DEFAULT_LAYER);
    scoreContainer.add(checkResult, JLayeredPane.DEFAULT_LAYER);
    scoreContainer.add(Box.createVerticalStrut(10));
    scoreContainer.add(bagTiles, JLayeredPane.DEFAULT_LAYER);
    scoreContainer.add(Box.createVerticalStrut(30));
    scoreContainer.add(menu, JLayeredPane.DEFAULT_LAYER);
    scoreContainer.add(Box.createVerticalStrut(30));
    scoreContainer.add(quit, JLayeredPane.DEFAULT_LAYER);

    scoreContainer.setSize(scoreContainer.getPreferredSize());
    scoreContainer.setLocation(675, 0);

    pane.add(scoreContainer, BorderLayout.EAST, JLayeredPane.DEFAULT_LAYER);
  }
    public TextBox(int position) {
      super();
      fieldNumber = position;

      this.setLayout(new GridLayout(1, 2));
      fieldTitle = new JLabel();
      fieldTitle.setAlignmentX(LEFT_ALIGNMENT);

      text = new JTextField(20);
      text.setMinimumSize(text.getPreferredSize());
      text.setAlignmentX(LEFT_ALIGNMENT);

      text.addFocusListener(
          new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
              String temp = text.getText();
              batchState.addText(fieldNumber - 1, batchState.getCurrentCell().getRecordNum(), temp);
            }

            @Override
            public void focusGained(FocusEvent e) {
              // TODO Auto-generated method stub
              batchState.updateCell(fieldNumber, -1);
            }
          });

      text.addMouseListener(
          new MouseListener() {

            @Override
            public void mouseReleased(MouseEvent e) {
              // TODO Auto-generated method stub

            }

            @Override
            public void mousePressed(MouseEvent e) {
              // TODO Auto-generated method stub

            }

            @Override
            public void mouseExited(MouseEvent e) {
              // TODO Auto-generated method stub

            }

            @Override
            public void mouseEntered(MouseEvent e) {
              // TODO Auto-generated method stub

            }

            @Override
            public void mouseClicked(MouseEvent e) {
              if (e.getButton() == 3) {

                if (text.getBackground() == Color.RED) {

                  final JPopupMenu suggestion = new JPopupMenu();
                  JMenuItem item = new JMenuItem("see suggestion");
                  item.addActionListener(
                      new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {

                          ArrayList<String> list =
                              batchState.getSuggestions(text.getText(), fieldNumber - 1);
                          int column = fieldNumber;
                          int row = recordList.getSelectedIndex();
                          SuggestionWindow suggestionWindow =
                              new SuggestionWindow(list, column, row, batchState);

                          suggestionWindow.setSize(new Dimension(300, 200));
                          suggestionWindow.setResizable(false);
                          suggestionWindow.setLocationRelativeTo(null);
                          suggestionWindow.setVisible(true);
                        }
                      });
                  suggestion.add(item);
                  suggestion.show(e.getComponent(), e.getX(), e.getY());
                }
              }
            }
          });

      this.add(fieldTitle);
      this.add(text);
    }
Example #8
0
  public BreakoutServer() {
    super();

    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent evt) {
            dispose();
            System.exit(0);
          }
        });

    // prevents version info from printing
    // comment these out when debugging
    PipedOutputStream pipeOut = new PipedOutputStream();
    System.setOut(new PrintStream(pipeOut));

    fc = new JFileChooser();
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    // get a references to the user preferences
    prefs = Preferences.userRoot().node(this.getClass().getName());
    netPort = prefs.getInt(PORT_KEY, DEFAULT_PORT);
    webRoot = prefs.get(ROOT_KEY, DEFAULT_ROOT);

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    JTabbedPane tabbedPane = new JTabbedPane();

    JPanel settingsPane = new JPanel();
    JPanel statusPane = new JPanel(new BorderLayout());
    JPanel portSelectionPane = new JPanel(new FlowLayout(FlowLayout.LEFT));

    setTitle("Breakout Server");
    setSize(WIDTH, HEIGHT);
    setResizable(false);

    loggingArea = new JTextArea(16, 40);
    loggingArea.setEditable(false);
    loggingArea.setFont(new Font("Monospaced", Font.PLAIN, 12));
    loggingArea.setMargin(new Insets(5, 5, 5, 5));
    loggingArea.append(buildName + "\n\n");

    JScrollPane listScroller =
        new JScrollPane(
            loggingArea,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    listScroller.setPreferredSize(new Dimension(WIDTH, LOGGING_AREA_HEIGHT));
    statusPane.add(listScroller, BorderLayout.CENTER);

    webRootField = new JTextField(webRoot);
    webRootField.setEditable(false);
    // webRootField.setColumns(5);
    webRootField.setHorizontalAlignment(JTextField.LEADING);
    webRootLabel = new JLabel("Webserver Root Directory:");
    webRootField.addActionListener(this);

    rootBtn = new JButton("Choose New Webserver Root");
    rootBtn.addActionListener(this);

    serialLabel = new JLabel("Serial");
    serialPorts = new JComboBox();
    createPortList();

    serialPorts.addActionListener(this);

    portField = new JTextField(Integer.toString(netPort));
    portField.setColumns(5);
    portField.addActionListener(this);

    portLabel = new JLabel("Port");

    multiClientCB = new JCheckBox("Enable Multi-Client Connections");
    multiClientCB.addActionListener(this);

    connectBtn = new JButton("Connect");
    connectBtn.addActionListener(this);
    connectBtn.setActionCommand("connect");
    connectBtn.setMaximumSize(new Dimension(350, 25));

    portSelectionPane.add(serialLabel);
    portSelectionPane.add(serialPorts);
    portSelectionPane.add(portLabel);
    portSelectionPane.add(portField);

    webRootField.setAlignmentX(Component.LEFT_ALIGNMENT);
    webRootField.setMaximumSize(new Dimension(450, 20));
    portField.setAlignmentX(Component.LEFT_ALIGNMENT);
    portField.setMaximumSize(new Dimension(100, 20));

    settingsPane.setLayout(new BoxLayout(settingsPane, BoxLayout.PAGE_AXIS));
    settingsPane.setBorder(BorderFactory.createEmptyBorder(15, 10, 10, 10));
    settingsPane.add(webRootLabel);
    settingsPane.add(webRootField);
    settingsPane.add(Box.createRigidArea(new Dimension(0, 5)));
    settingsPane.add(rootBtn);
    settingsPane.add(Box.createRigidArea(new Dimension(0, 30)));
    settingsPane.add(multiClientCB);

    statusPane.add(portSelectionPane, BorderLayout.NORTH);

    tabbedPane.addTab("status", statusPane);
    tabbedPane.addTab("settings", settingsPane);

    contentPane.add(tabbedPane, BorderLayout.NORTH);
    contentPane.add(connectBtn, BorderLayout.AFTER_LAST_LINE);

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setVisible(true);

    startPortListTimer();
  }
  public void installComponents(JFileChooser fc) {
    fc.setLayout(new BorderLayout(10, 10));
    fc.setAlignmentX(JComponent.CENTER_ALIGNMENT);

    JPanel interior =
        new JPanel() {
          public Insets getInsets() {
            return insets;
          }
        };
    align(interior);
    interior.setLayout(new BoxLayout(interior, BoxLayout.PAGE_AXIS));

    fc.add(interior, BorderLayout.CENTER);

    // PENDING(jeff) - I18N
    JLabel l = new JLabel(pathLabelText);
    l.setDisplayedMnemonic(pathLabelMnemonic);
    align(l);
    interior.add(l);

    File currentDirectory = fc.getCurrentDirectory();
    String curDirName = null;
    if (currentDirectory != null) {
      curDirName = currentDirectory.getPath();
    }
    pathField =
        new JTextField(curDirName) {
          public Dimension getMaximumSize() {
            Dimension d = super.getMaximumSize();
            d.height = getPreferredSize().height;
            return d;
          }
        };
    l.setLabelFor(pathField);
    align(pathField);

    // Change to folder on return
    pathField.addActionListener(getUpdateAction());
    interior.add(pathField);

    interior.add(Box.createRigidArea(vstrut10));

    // CENTER: left, right accessory
    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.LINE_AXIS));
    align(centerPanel);

    // left panel - Filter & folderList
    JPanel leftPanel = new JPanel();
    leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
    align(leftPanel);

    // add the filter PENDING(jeff) - I18N
    l = new JLabel(filterLabelText);
    l.setDisplayedMnemonic(filterLabelMnemonic);
    align(l);
    leftPanel.add(l);

    filterComboBox =
        new JComboBox() {
          public Dimension getMaximumSize() {
            Dimension d = super.getMaximumSize();
            d.height = getPreferredSize().height;
            return d;
          }
        };
    l.setLabelFor(filterComboBox);
    filterComboBoxModel = createFilterComboBoxModel();
    filterComboBox.setModel(filterComboBoxModel);
    filterComboBox.setRenderer(createFilterComboBoxRenderer());
    fc.addPropertyChangeListener(filterComboBoxModel);
    align(filterComboBox);
    leftPanel.add(filterComboBox);

    // leftPanel.add(Box.createRigidArea(vstrut10));

    // Add the Folder List PENDING(jeff) - I18N
    l = new JLabel(foldersLabelText);
    l.setDisplayedMnemonic(foldersLabelMnemonic);
    align(l);
    leftPanel.add(l);
    JScrollPane sp = createDirectoryList();
    sp.getVerticalScrollBar().setFocusable(false);
    sp.getHorizontalScrollBar().setFocusable(false);
    l.setLabelFor(sp.getViewport().getView());
    leftPanel.add(sp);

    // create files list
    JPanel rightPanel = new JPanel();
    align(rightPanel);
    rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.PAGE_AXIS));

    l = new JLabel(filesLabelText);
    l.setDisplayedMnemonic(filesLabelMnemonic);
    align(l);
    rightPanel.add(l);
    sp = createFilesList();
    l.setLabelFor(sp);
    rightPanel.add(sp);

    centerPanel.add(leftPanel);
    centerPanel.add(Box.createRigidArea(hstrut10));
    centerPanel.add(rightPanel);

    JComponent accessoryPanel = getAccessoryPanel();
    JComponent accessory = fc.getAccessory();
    if (accessoryPanel != null) {
      if (accessory == null) {
        accessoryPanel.setPreferredSize(ZERO_ACC_SIZE);
        accessoryPanel.setMaximumSize(ZERO_ACC_SIZE);
      } else {
        getAccessoryPanel().add(accessory, BorderLayout.CENTER);
        accessoryPanel.setPreferredSize(PREF_ACC_SIZE);
        accessoryPanel.setMaximumSize(MAX_SIZE);
      }
      align(accessoryPanel);
      centerPanel.add(accessoryPanel);
    }
    interior.add(centerPanel);
    interior.add(Box.createRigidArea(vstrut10));

    // add the filename field PENDING(jeff) - I18N
    l = new JLabel(enterFileNameLabelText);
    l.setDisplayedMnemonic(enterFileNameLabelMnemonic);
    align(l);
    interior.add(l);

    filenameTextField =
        new JTextField() {
          public Dimension getMaximumSize() {
            Dimension d = super.getMaximumSize();
            d.height = getPreferredSize().height;
            return d;
          }
        };
    l.setLabelFor(filenameTextField);
    filenameTextField.addActionListener(getApproveSelectionAction());
    align(filenameTextField);
    filenameTextField.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    interior.add(filenameTextField);

    bottomPanel = getBottomPanel();
    bottomPanel.add(new JSeparator(), BorderLayout.NORTH);

    // Add buttons
    JPanel buttonPanel = new JPanel();
    align(buttonPanel);
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
    buttonPanel.add(Box.createGlue());

    approveButton =
        new JButton(getApproveButtonText(fc)) {
          public Dimension getMaximumSize() {
            return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
          }
        };
    approveButton.setMnemonic(getApproveButtonMnemonic(fc));
    approveButton.setToolTipText(getApproveButtonToolTipText(fc));
    align(approveButton);
    approveButton.setMargin(buttonMargin);
    approveButton.addActionListener(getApproveSelectionAction());
    buttonPanel.add(approveButton);
    buttonPanel.add(Box.createGlue());

    JButton updateButton =
        new JButton(updateButtonText) {
          public Dimension getMaximumSize() {
            return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
          }
        };
    updateButton.setMnemonic(updateButtonMnemonic);
    updateButton.setToolTipText(updateButtonToolTipText);
    align(updateButton);
    updateButton.setMargin(buttonMargin);
    updateButton.addActionListener(getUpdateAction());
    buttonPanel.add(updateButton);
    buttonPanel.add(Box.createGlue());

    JButton cancelButton =
        new JButton(cancelButtonText) {
          public Dimension getMaximumSize() {
            return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
          }
        };
    cancelButton.setMnemonic(cancelButtonMnemonic);
    cancelButton.setToolTipText(cancelButtonToolTipText);
    align(cancelButton);
    cancelButton.setMargin(buttonMargin);
    cancelButton.addActionListener(getCancelSelectionAction());
    buttonPanel.add(cancelButton);
    buttonPanel.add(Box.createGlue());

    JButton helpButton =
        new JButton(helpButtonText) {
          public Dimension getMaximumSize() {
            return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
          }
        };
    helpButton.setMnemonic(helpButtonMnemonic);
    helpButton.setToolTipText(helpButtonToolTipText);
    align(helpButton);
    helpButton.setMargin(buttonMargin);
    helpButton.setEnabled(false);
    buttonPanel.add(helpButton);
    buttonPanel.add(Box.createGlue());

    bottomPanel.add(buttonPanel, BorderLayout.SOUTH);
    if (fc.getControlButtonsAreShown()) {
      fc.add(bottomPanel, BorderLayout.SOUTH);
    }
  }
Example #10
0
  @Override
  public void actionPerformed(ActionEvent e) {

    currentOnto = owlManager.getActiveOntology();
    currentModel = modelManager.getActiveOBDAModel();

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    JLabel dsource = new JLabel("Choose a datasource to bootstrap: ");
    dsource.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(dsource);
    List<String> options = new ArrayList<String>();
    for (OBDADataSource source : currentModel.getSources())
      options.add(source.getSourceID().toString());
    JComboBox combo = new JComboBox(options.toArray());
    combo.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(combo);
    Dimension minsize = new Dimension(10, 10);
    panel.add(new Box.Filler(minsize, minsize, minsize));
    JLabel ouri =
        new JLabel("Base URI - the prefix to be used for all generated classes and properties: ");
    ouri.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(ouri);
    JTextField base_uri = new JTextField();
    base_uri.setText(currentModel.getPrefixManager().getDefaultPrefix().replace("#", "/"));
    base_uri.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(base_uri);
    int res =
        JOptionPane.showOptionDialog(
            workspace,
            panel,
            "Bootstrapping",
            JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            null,
            null);
    if (res == JOptionPane.OK_OPTION) {
      int index = combo.getSelectedIndex();
      currentSource = currentModel.getSources().get(index);
      if (currentSource != null) {
        this.baseUri = base_uri.getText().trim();
        if (baseUri.contains("#")) {
          JOptionPane.showMessageDialog(workspace, "Base Uri cannot contain the character '#'");
          throw new RuntimeException("Base URI " + baseUri + " contains '#' character!");
        } else {
          Thread th =
              new Thread(
                  new Runnable() {
                    @Override
                    public void run() {
                      try {
                        OBDAProgessMonitor monitor =
                            new OBDAProgessMonitor("Bootstrapping ontology and mappings...");
                        BootstrapperThread t = new BootstrapperThread();
                        monitor.addProgressListener(t);
                        monitor.start();
                        t.run(baseUri, currentOnto, currentModel, currentSource);
                        currentModel.fireSourceParametersUpdated();
                        monitor.stop();
                        JOptionPane.showMessageDialog(
                            workspace,
                            "Task is completed.",
                            "Done",
                            JOptionPane.INFORMATION_MESSAGE);
                      } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        JOptionPane.showMessageDialog(
                            null, "Error occured during bootstrapping data source.");
                      }
                    }
                  });
          th.start();
        }
      }
    }
  }