Exemplo n.º 1
0
  @NotNull
  public static <T extends PsiElement> JBPopup getPsiElementPopup(
      @NotNull T[] elements,
      @NotNull final PsiElementListCellRenderer<T> renderer,
      @Nullable final String title,
      @NotNull final PsiElementProcessor<T> processor,
      @Nullable final T selection) {
    final JList list =
        new JBListWithHintProvider(elements) {
          @Nullable
          @Override
          protected PsiElement getPsiElementForHint(Object selectedValue) {
            return (PsiElement) selectedValue;
          }
        };
    list.setCellRenderer(renderer);

    list.setFont(EditorUtil.getEditorFont());

    if (selection != null) {
      list.setSelectedValue(selection, true);
    }

    final Runnable runnable =
        () -> {
          int[] ids = list.getSelectedIndices();
          if (ids == null || ids.length == 0) return;
          for (Object element : list.getSelectedValues()) {
            if (element != null) {
              processor.execute((T) element);
            }
          }
        };

    PopupChooserBuilder builder = new PopupChooserBuilder(list);
    if (title != null) {
      builder.setTitle(title);
    }
    renderer.installSpeedSearch(builder, true);

    JBPopup popup = builder.setItemChoosenCallback(runnable).createPopup();

    builder.getScrollPane().setBorder(null);
    builder.getScrollPane().setViewportBorder(null);

    return popup;
  }
Exemplo n.º 2
0
  ////////////////////////////////////////////////////////////////
  // contructors
  public PropPanelInterface() {
    super("Interface", _interfaceIcon, 3);

    Class mclass = MInterface.class;

    addCaption("Name:", 1, 0, 0);
    addField(nameField, 1, 0, 0);

    addCaption("Stereotype:", 2, 0, 0);
    //    stereotypeBox.setEnabled(false);
    addField(new UMLComboBoxNavigator(this, "NavStereo", stereotypeBox), 2, 0, 0);

    addCaption("Namespace:", 3, 0, 0);
    addField(namespaceScroll, 3, 0, 0);

    addCaption("Extends:", 4, 0, 0);
    addField(extendsScroll, 4, 0, 0);

    addCaption("Modifiers:", 5, 0, 1);
    JPanel modifiersPanel = new JPanel(new GridLayout(0, 2));
    modifiersPanel.add(
        new UMLCheckBox(
            localize("Public"),
            this,
            new UMLEnumerationBooleanProperty(
                "visibility",
                mclass,
                "getVisibility",
                "setVisibility",
                MVisibilityKind.class,
                MVisibilityKind.PUBLIC,
                null)));
    modifiersPanel.add(
        new UMLCheckBox(
            localize("Abstract"),
            this,
            new UMLReflectionBooleanProperty("isAbstract", mclass, "isAbstract", "setAbstract")));
    modifiersPanel.add(
        new UMLCheckBox(
            localize("Final"),
            this,
            new UMLReflectionBooleanProperty("isLeaf", mclass, "isLeaf", "setLeaf")));
    modifiersPanel.add(
        new UMLCheckBox(
            localize("Root"),
            this,
            new UMLReflectionBooleanProperty("isRoot", mclass, "isRoot", "setRoot")));
    addField(modifiersPanel, 5, 0, 1);

    addCaption("Associations:", 0, 1, 0.3);
    addField(connectScroll, 0, 1, 0.3);

    addCaption("Implementations:", 1, 1, 0.4);
    JList implementations = new UMLList(new UMLSupplierDependencyListModel(this, null, true), true);
    implementations.setForeground(Color.blue);
    implementations.setVisibleRowCount(1);
    implementations.setFont(smallFont);
    addField(new JScrollPane(implementations), 1, 1, 0.4);

    addCaption("Derived:", 2, 1, 0.3);
    addField(derivedScroll, 2, 1, 0.3);

    addCaption("Operations:", 0, 2, 0.5);
    addField(opsScroll, 0, 2, 0.5);

    addCaption("Attributes:", 1, 2, 0.5);
    addField(attrScroll, 1, 2, 0.5);

    new PropPanelButton(
        this, buttonPanel, _navUpIcon, localize("Go up"), "navigateNamespace", null);
    new PropPanelButton(
        this,
        buttonPanel,
        _navBackIcon,
        localize("Go back"),
        "navigateBackAction",
        "isNavigateBackEnabled");
    new PropPanelButton(
        this,
        buttonPanel,
        _navForwardIcon,
        localize("Go forward"),
        "navigateForwardAction",
        "isNavigateForwardEnabled");
    new PropPanelButton(
        this, buttonPanel, _addOpIcon, localize("Add operation"), "addOperation", null);
    // new PropPanelButton(this,buttonPanel,_generalizationIcon,localize("Add
    // generalization"),"addGeneralization",null);
    // new PropPanelButton(this,buttonPanel,_realizationIcon,localize("Add
    // realization"),"addRealization",null);
    new PropPanelButton(
        this, buttonPanel, _deleteIcon, localize("Delete interface"), "removeElement", null);
    // does this make sense?? new PropPanelButton(this,buttonPanel,_interfaceIcon,localize("New
    // interface"),"newInterface",null);

  }
Exemplo n.º 3
0
  public SQLiteDataBrowser() {
    SQLiteDbManager dbManager = new SQLiteDbManager();

    setLayout(new BorderLayout());

    showTablesList = new JList();
    showTablesList.setLayoutOrientation(JList.VERTICAL_WRAP);
    showTablesList.setSelectedIndex(ListSelectionModel.SINGLE_SELECTION);
    showTablesList.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    showTablesList.setFont(new Font("Times New Roman", Font.PLAIN, 13));
    showTablesList.setDragEnabled(false);
    showTablesList.setFixedCellWidth(150);
    showTablesList.setVisibleRowCount(-1);
    showTablesList.setEnabled(false);

    showTablesListScroller = new JScrollPane(showTablesList);
    showTablesListScroller.setBorder(
        BorderFactory.createTitledBorder(new LineBorder(Color.BLACK), "List of Tables"));
    showTablesListScroller.setPreferredSize(new Dimension(160, this.getHeight()));

    add(showTablesListScroller, BorderLayout.EAST);

    loadDbPanel = new JPanel(new FlowLayout());
    loadDbPanel.setBackground(new Color(0xe8e8e8));
    loadDbPanel.setPreferredSize(new Dimension(getWidth(), 40));

    loadDbLabel = new JLabel("Load SQLite Database: ");
    loadDbLabel.setToolTipText("Possible extensions being .sqlite|.sqlite3|.db|.db3");

    loadedDbPath = new JTextField("Click browse to choose the database file.", 60);
    loadedDbPath.setForeground(Color.GRAY);
    loadedDbPath.setFont(new Font("Times New Roman", Font.ITALIC, 13));
    loadedDbPath.setEditable(false);

    lastFolderLocation = new File(Utils.getUserHome());
    fc = new JFileChooser(lastFolderLocation);

    browseDb = new JButton("Browse");
    browseDb.addActionListener(
        actionEvent -> {
          int retVal = fc.showOpenDialog(SQLiteDataBrowser.this);
          if (retVal == JFileChooser.APPROVE_OPTION) {
            File dbPath = fc.getSelectedFile();
            if (Utils.checkIfSQLiteDb(dbPath)) {
              loadedDbPath.setText(dbPath.toString());
              lastFolderLocation = fc.getCurrentDirectory();
              new SwingWorker<Void, Void>() {

                @Override
                protected Void doInBackground() throws Exception {
                  try {
                    dbManager.setDbPath(dbPath.toString());
                    dbManager.initialize();
                    showTablesList.setListData(dbManager.getTables().toArray());
                    showTablesList.setEnabled(true);
                  } catch (SQLException e) {
                    e.printStackTrace();
                  }
                  return null;
                }
              }.execute();
            } else {
              JOptionPane.showMessageDialog(
                  SQLiteDataBrowser.this,
                  "The Selected file is not in SQLite Format",
                  "File Format Error",
                  JOptionPane.ERROR_MESSAGE);
              loadedDbPath.setText("Click browse to choose the database file.");
            }
          }
        });

    loadDbPanel.add(loadDbLabel);
    loadDbPanel.add(loadedDbPath);
    loadDbPanel.add(browseDb);

    loadDbRecords = new JLabel("Records Fetched (Rows x Cols): ");
    loadDbRecords.setFont(new Font("Times New Roman", Font.ITALIC, 12));
    loadDbPanel.add(loadDbRecords);

    loadDbRecordsCount = new JLabel();
    loadDbRecordsCount.setFont(new Font("Times New Roman", Font.ITALIC, 12));
    loadDbPanel.add(loadDbRecordsCount);

    final class DataBrowserTableModal extends DefaultTableModel {

      public DataBrowserTableModal() {}

      public DataBrowserTableModal(Object[][] tableData, Object[] colNames) {
        super(tableData, colNames);
      }

      @Override
      public void setDataVector(Object[][] tableData, Object[] colNames) {
        super.setDataVector(tableData, colNames);
      }

      @Override
      public boolean isCellEditable(int row, int column) {
        return false;
      }
    }

    DataBrowserTableModal tableModal = new DataBrowserTableModal();
    defaultTableModel = tableModal;

    table = new JTable();
    table.setModel(defaultTableModel);

    showTablesList.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent evt) {
            JList list = (JList) evt.getSource();
            if (evt.getClickCount() == 2) {
              String tableName = list.getSelectedValue().toString();

              new SwingWorker<Void, Void>() {

                @Override
                protected Void doInBackground() throws Exception {
                  try {
                    ResultSet rs = dbManager.executeQuery("SELECT * from " + tableName);
                    Vector<String> columnNames = dbManager.getColumnNames(rs);
                    Vector<Vector<Object>> tableData = new Vector<>();
                    while (rs.next()) {
                      Vector<Object> vector = new Vector<>();

                      for (int i = 1; i <= columnNames.size(); i++) {
                        vector.add(rs.getObject(i));
                      }
                      tableData.add(vector);
                    }
                    defaultTableModel.setDataVector(tableData, columnNames);
                  } catch (SQLException e) {
                    e.printStackTrace();
                  }

                  loadDbRecordsCount.setText(
                      defaultTableModel.getRowCount() + " x " + defaultTableModel.getColumnCount());

                  if (defaultTableModel.getColumnCount() < 5) {
                    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
                  } else {
                    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                  }

                  return null;
                }
              }.execute();
            }
          }
        });

    tableScrollPane = new JScrollPane(table);
    tableScrollPane.setHorizontalScrollBarPolicy(
        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    tableScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    tableScrollPane.setPreferredSize(new Dimension(getWidth(), getHeight()));
    add(tableScrollPane, BorderLayout.CENTER);

    add(loadDbPanel, BorderLayout.NORTH);
  }
Exemplo n.º 4
0
 private static <E> JList<E> newList(DefaultListModel<E> listModel) {
   JList<E> list = new JList<>(listModel);
   list.setFont(f13);
   list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   return list;
 }
Exemplo n.º 5
0
  public static void ConfigureMainWindow() {
    userNameLabel.setFont(new Font("Lucida Console", 0, 14));
    userNameLabel.setForeground(new Color(255, 255, 255));

    mainWindow.getContentPane().setBackground(new Color(4, 3, 10));
    mainWindow.setSize(800, 600);
    mainWindow.getContentPane().setLayout(null);
    connectButton.setBackground(new Color(255, 255, 255));
    connectButton.setForeground(new Color(4, 3, 10));
    connectButton.setFont(new Font("Lucida Console", 0, 14));

    connectButton.setText("Anslut");
    connectButton.setToolTipText("");
    mainWindow.getContentPane().add(connectButton);
    connectButton.setBounds(455, 10, 100, 25);

    conversation.setColumns(20);
    conversation.setFont(new Font("Lucida Console", 0, 14));
    conversation.setForeground(new Color(4, 3, 10));
    conversation.setLineWrap(true);
    conversation.setRows(5);
    // conversation.setEditable(false);

    tpConversation.setForeground(new Color(255, 255, 255));
    tpConversation.setBounds(10, 10, 600, 500);
    tpConversation.setBackground(new Color(4, 3, 10));
    tpConversation.setFont(new Font("Lucida Console", 0, 14));

    spConversation.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    spConversation.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    spConversation.setViewportView(tpConversation);
    mainWindow.getContentPane().add(spConversation);
    spConversation.setBounds(10, 10, 600, 500);

    userNameBox.setBounds(120, 10, 325, 25);
    userNameLabel.setBounds(10, 10, 130, 25);
    mainWindow.getContentPane().add(userNameBox);
    mainWindow.getContentPane().add(userNameLabel);

    usersOnline.setForeground(new Color(0, 180, 255));
    usersOnline.setBackground(new Color(4, 3, 10));
    usersOnline.setFont(new Font("Lucida Console", 0, 14));
    spUsersOnline.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    spUsersOnline.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    spUsersOnline.setViewportView(usersOnline);
    mainWindow.getContentPane().add(spUsersOnline);
    spUsersOnline.setBounds(620, 10, 165, 300);

    messageField.setForeground(new Color(255, 255, 255));
    messageField.setBackground(new Color(4, 3, 10));
    messageField.requestFocus();
    messageField.addActionListener(action);
    mainWindow.getContentPane().add(messageField);
    messageField.setBounds(10, 520, 600, 30);

    send.setBackground(new Color(255, 255, 255));
    send.setForeground(new Color(4, 3, 10));
    send.setText("Skicka");
    send.setFont(new Font("Lucida Console", 0, 14));
    mainWindow.getContentPane().add(send);
    send.setBounds(620, 520, 165, 30);

    disconnect.setBackground(new Color(255, 255, 255));
    disconnect.setForeground(new Color(4, 3, 10));
    disconnect.setText("Avsluta chatten");
    disconnect.setFont(new Font("Lucida Console", 0, 14));
    mainWindow.getContentPane().add(disconnect);
    disconnect.setBounds(620, 320, 165, 30);

    error.setFont(new Font("Lucida Console", 0, 14));
    error.setForeground(new Color(255, 0, 23));
    error.setBounds(120, 40, 525, 25);

    mainWindow.getContentPane().add(error);
  }
Exemplo n.º 6
0
  public SaveDialog(Frame parent) {
    super(parent, true);
    this.setLayout(new BorderLayout());
    // gather unsaved tab
    Set<Tab> unsaved = new LinkedHashSet<>();
    for (Tab tab : MainPanel.getAllTab()) {
      if (!tab.isSaved()) {
        unsaved.add(tab);
      }
    }
    if (unsaved.isEmpty()) {
      // close directly
      this.setTitle("Confirm close");
      // upper labels
      JPanel labels = new JPanel(new FlowLayout(FlowLayout.LEFT, 11, 7));
      labels.add(iconLabel);
      labels.add(new MyLabel(" Do you really want to close RefluxEdit?"));
      // buttons
      JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 7));
      buttons.add(
          new MyButton("YES") {
            {
              SaveDialog.this.getRootPane().setDefaultButton(this);
              this.setFocusPainted(true);
            }

            @Override
            public void actionPerformed(ActionEvent ev) {
              close = true;
              SaveDialog.this.setVisible(false);
            }
          });
      buttons.add(
          new MyButton("NO") {
            {
              this.setFocusPainted(true);
            }

            @Override
            public void actionPerformed(ActionEvent ev) {
              close = false;
              SaveDialog.this.setVisible(false);
            }
          });
      buttons.setBorder(new EmptyBorder(0, 0, 5, 0));
      //
      this.add(labels, BorderLayout.CENTER);
      this.add(buttons, BorderLayout.PAGE_END);
    } else {
      // ask save changes
      this.setTitle("Unsaved changes");
      // upper components: icon and list
      JPanel upper = new JPanel(new GridBagLayout());
      JPanel listPane = new JPanel(new BorderLayout());
      final DefaultListModel<Tab> listModel = new DefaultListModel<>();
      final JList<Tab> tabList = new JList<>(listModel);
      tabList.setFont(f13);
      tabList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
      tabList.setCellRenderer(
          new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(
                JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
              JLabel label =
                  (JLabel)
                      (super.getListCellRendererComponent(
                          list, value, index, isSelected, cellHasFocus));
              if (value instanceof Tab) {
                String text = ((Tab) value).getTabLabel().getText();
                label.setText(text.substring(1)); // remove "*"
              }
              return label;
            }
          });
      for (Tab tab : unsaved) {
        listModel.addElement(tab);
      }
      tabList.getSelectionModel().setSelectionInterval(0, listModel.size() - 1);
      JScrollPane scrollPane = new JScrollPane(tabList);
      scrollPane.setPreferredSize(new Dimension(350, 170));
      listPane.add(new MyLabel("The following tabs are unsaved:"), BorderLayout.PAGE_START);
      listPane.add(scrollPane, BorderLayout.CENTER);
      // setup upper
      GridBagConstraints c = new GridBagConstraints();
      c.gridx = 0;
      c.gridy = 0;
      c.weightx = 0;
      c.weighty = 1;
      c.insets = new Insets(5, 5, 5, 5);
      c.anchor = GridBagConstraints.FIRST_LINE_START;
      upper.add(iconLabel, c);
      //
      c.gridx = 1;
      c.weightx = 1;
      c.fill = GridBagConstraints.BOTH;
      upper.add(listPane, c);
      // lower components: buttons
      JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 7));
      buttons.add(
          new MyButton("Save") {
            {
              this.setFocusPainted(true);
              this.setToolTipText("Save selected tab(s)");
              SaveDialog.this.getRootPane().setDefaultButton(this);
              if (isMetal) {
                this.setPreferredSize(METAL_BUTTON_DIZE);
              }
            }

            @Override
            public void actionPerformed(ActionEvent ev) {
              for (Tab tab : tabList.getSelectedValuesList()) {
                if (tab.getFile() != null) {
                  try {
                    tab.save();
                    MainPanel.close(tab);
                    listModel.removeElement(tab);
                  } catch (Exception ex) {
                    exception(ex);
                    break;
                  }
                } else {
                  File file =
                      FileChooser.showPreferredFileDialog(
                          RefluxEdit.getInstance(), FileChooser.SAVE, new String[0]);
                  if (file != null) {
                    try {
                      tab.save(file, false);
                      MainPanel.close(tab);
                      listModel.removeElement(tab);
                    } catch (Exception ex) {
                      exception(ex);
                      break;
                    }
                  }
                }
              }
              if (listModel.size() == 0) {
                RefluxEdit.getInstance().close();
              }
            }
          });
      buttons.add(
          new MyButton("Discard") {
            {
              this.setFocusPainted(true);
              this.setToolTipText("Discard selected tab(s)");
              if (isMetal) {
                this.setPreferredSize(METAL_BUTTON_DIZE);
              }
            }

            @Override
            public void actionPerformed(ActionEvent ev) {
              for (Tab tab : tabList.getSelectedValuesList()) {
                MainPanel.close(tab);
                listModel.removeElement(tab);
              }
              if (listModel.size() == 0) {
                RefluxEdit.getInstance().close();
              }
            }
          });
      buttons.add(
          new MyButton("Close") {
            {
              this.setFocusPainted(true);
              this.setToolTipText("Close RefluxEdit");
              if (isMetal) {
                this.setPreferredSize(METAL_BUTTON_DIZE);
              }
            }

            @Override
            public void actionPerformed(ActionEvent ev) {
              SaveDialog.this.close = true;
              SaveDialog.this.setVisible(false);
            }
          });
      buttons.add(
          new MyButton("Cancel") {
            {
              this.setFocusPainted(true);
              if (isMetal) {
                this.setPreferredSize(METAL_BUTTON_DIZE);
              }
            }

            @Override
            public void actionPerformed(ActionEvent ev) {
              SaveDialog.this.close = false;
              SaveDialog.this.setVisible(false);
            }
          });
      this.add(upper, BorderLayout.CENTER);
      this.add(buttons, BorderLayout.PAGE_END);
    }
  }