示例#1
0
  public void createviewPanel() {

    viewPanel = new JPanel();
    viewPanel.setLayout(new BorderLayout());
    // viewPanel.setPreferredSize( new Dimension(500,500 ));
    // viewPanel.setMinimumSize( new Dimension(100,50));
    // viewPanel.add( new JLabel("Notes:"),BorderLayout.NORTH );
    //		viewPanel.add( new JTextArea(), BorderLayout.CENTER );
    viewPanel.setPreferredSize(new Dimension(200, 520));
    viewPanel.setMinimumSize(new Dimension(100, 100));
    // Create columns
    CreateColumns(colcnt);
    CreateData(rowcnt, colcnt);
    setSize(300, 200);

    table =
        new JTable(dataValues, columnNames) {

          public boolean isCellEditable(int rowIndex, int vColIndex) {
            return false;
          }
        };

    table
        .getModel()
        .addTableModelListener(
            new TableModelListener() {

              public void tableChanged(TableModelEvent e) {
                System.out.println("........" + e);
              }
            });
    // table.setValueAt("1,2",0,0);

    System.out.println("Row   :" + rowcnt);
    System.out.println("Col  :" + colcnt);

    // Configure some of JTable's paramters
    table.setShowHorizontalLines(false);
    table.setShowVerticalLines(false);
    table.setRowSelectionAllowed(false);
    table.setColumnSelectionAllowed(false);

    // Change the selection colour
    table.setSelectionForeground(Color.white);
    table.setSelectionBackground(Color.red);

    // Add the table to a scrolling pane
    scrollPaneTable = JTable.createScrollPaneForTable(table);
    viewPanel.add(scrollPaneTable, BorderLayout.CENTER);
    viewPanel.add(table, BorderLayout.CENTER);
  }
  public AppointmentGUI() {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setBounds(100, 100, 500, 600); // window size
    setTitle("Appointment List"); // window title
    contentPane = new JPanel();
    contentPane.setBorder(
        new EmptyBorder(3, 6, 3, 6)); // distance the plane is from the edges of the window
    setContentPane(contentPane);
    contentPane.setLayout(new BorderLayout(0, 0));
    scrollPane = new JScrollPane();
    contentPane.add(scrollPane, BorderLayout.CENTER);

    table =
        new JTable(
            new DefaultTableModel(new Object[] {"Doctor's Name", "Location", "Date", "Time"}, 60)) {
          public boolean isCellEditable(
              int row,
              int column) { // prevents user from editing cells; there apparently is not a cleaner
            // way of doing this
            return false;
          }
        };
    table.setShowHorizontalLines(false);
    table.setShowVerticalLines(false);
    table.setShowGrid(false);
    table.getTableHeader().setReorderingAllowed(false); // prevent user from swapping columns
    table.getTableHeader().setResizingAllowed(false); // prevent user from resizing columns
    table.setSelectionMode(
        ListSelectionModel
            .SINGLE_INTERVAL_SELECTION); // prevent user from selecting multiple doctors
    table.setAutoCreateColumnsFromModel(
        false); // forgot why I have this here; it's probably important

    scrollPane.setViewportView(table); // lets table be scroll able

    btnPane = new JPanel();
    btnPane.setLayout(new GridLayout(0, 2, 0, 0));
    contentPane.add(btnPane, BorderLayout.SOUTH);

    btnViewAppointment = new JButton("View Appointment");
    btnPane.add(btnViewAppointment);

    btnCancelAppointment = new JButton("Cancel Appointment");
    btnPane.add(btnCancelAppointment);

    btnUpdateAppointment = new JButton("Update Appointment");
    btnPane.add(btnUpdateAppointment);

    btnGoBack = new JButton("Go Back");
    btnPane.add(btnGoBack);
  }
  public JComponent createComponentImpl() {
    final DefaultTableModel tableModel = createModel();
    myTable = new JBTable(tableModel);
    myTable.setIntercellSpacing(new Dimension(0, 0));
    myTable.setDefaultRenderer(TableItem.class, new MyRenderer());
    myTable.setShowGrid(false);
    myTable.setDragEnabled(false);
    myTable.setShowHorizontalLines(false);
    myTable.setShowVerticalLines(false);
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    JPanel tablePanel =
        ToolbarDecorator.createDecorator(myTable)
            .setAddAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    FileChooserDescriptor myDescriptor =
                        FileChooserDescriptorFactory.createSingleFolderDescriptor();
                    myDescriptor.setTitle(
                        ProjectBundle.message("add.external.annotations.path.title"));
                    myDescriptor.setDescription(
                        ProjectBundle.message("add.external.annotations.path.description"));
                    VirtualFile[] files =
                        FileChooser.chooseFiles(myDescriptor, myTable, myProject, null);
                    final MyTableModel tableModel = (MyTableModel) myTable.getModel();
                    boolean changes = false;
                    for (final VirtualFile file : files) {
                      if (file != null) {
                        tableModel.addTableItem(new TableItem(file));
                        changes = true;
                      }
                    }
                    if (changes) {
                      saveData();
                      TableUtil.selectRows(myTable, new int[] {tableModel.getRowCount() - 1});
                    }
                  }
                })
            .setRemoveAction(
                new AnActionButtonRunnable() {
                  @Override
                  public void run(AnActionButton button) {
                    final List removedItems = TableUtil.removeSelectedItems(myTable);
                    if (removedItems.size() > 0) {
                      saveData();
                    }
                  }
                })
            .createPanel();

    final JPanel mainPanel = new JPanel(new BorderLayout());

    mainPanel.add(tablePanel, BorderLayout.CENTER);
    mainPanel.add(
        new JBLabel(
            ProjectBundle.message("project.roots.external.annotations.description"),
            UIUtil.ComponentStyle.SMALL,
            UIUtil.FontColor.BRIGHTER),
        BorderLayout.NORTH);
    return mainPanel;
  }
  @NotNull
  private JBPopup createUsagePopup(
      @NotNull final List<Usage> usages,
      @NotNull final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor,
      @NotNull Set<UsageNode> visibleNodes,
      @NotNull final FindUsagesHandler handler,
      final Editor editor,
      @NotNull final RelativePoint popupPosition,
      final int maxUsages,
      @NotNull final UsageViewImpl usageView,
      @NotNull final FindUsagesOptions options,
      @NotNull final JTable table,
      @NotNull final UsageViewPresentation presentation,
      @NotNull final AsyncProcessIcon processIcon,
      boolean hadMoreSeparator) {
    table.setRowHeight(PlatformIcons.CLASS_ICON.getIconHeight() + 2);
    table.setShowGrid(false);
    table.setShowVerticalLines(false);
    table.setShowHorizontalLines(false);
    table.setTableHeader(null);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    table.setIntercellSpacing(new Dimension(0, 0));

    PopupChooserBuilder builder = new PopupChooserBuilder(table);
    final String title = presentation.getTabText();
    if (title != null) {
      String result = getFullTitle(usages, title, hadMoreSeparator, visibleNodes.size() - 1, true);
      builder.setTitle(result);
      builder.setAdText(getSecondInvocationTitle(options, handler));
    }

    builder.setMovable(true).setResizable(true);
    builder.setItemChoosenCallback(
        new Runnable() {
          @Override
          public void run() {
            int[] selected = table.getSelectedRows();
            for (int i : selected) {
              Object value = table.getValueAt(i, 0);
              if (value instanceof UsageNode) {
                Usage usage = ((UsageNode) value).getUsage();
                if (usage == MORE_USAGES_SEPARATOR) {
                  appendMoreUsages(editor, popupPosition, handler, maxUsages);
                  return;
                }
                navigateAndHint(usage, null, handler, popupPosition, maxUsages, options);
              }
            }
          }
        });
    final JBPopup[] popup = new JBPopup[1];

    KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
    if (shortcut != null) {
      new DumbAwareAction() {
        @Override
        public void actionPerformed(AnActionEvent e) {
          popup[0].cancel();
          showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
        }
      }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table);
    }
    shortcut = getShowUsagesShortcut();
    if (shortcut != null) {
      new DumbAwareAction() {
        @Override
        public void actionPerformed(AnActionEvent e) {
          popup[0].cancel();
          searchEverywhere(options, handler, editor, popupPosition, maxUsages);
        }
      }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table);
    }

    InplaceButton settingsButton =
        createSettingsButton(
            handler,
            popupPosition,
            editor,
            maxUsages,
            new Runnable() {
              @Override
              public void run() {
                popup[0].cancel();
              }
            });

    ActiveComponent spinningProgress =
        new ActiveComponent() {
          @Override
          public void setActive(boolean active) {}

          @Override
          public JComponent getComponent() {
            return processIcon;
          }
        };
    builder.setCommandButton(new CompositeActiveComponent(spinningProgress, settingsButton));

    DefaultActionGroup toolbar = new DefaultActionGroup();
    usageView.addFilteringActions(toolbar);

    toolbar.add(UsageGroupingRuleProviderImpl.createGroupByFileStructureAction(usageView));
    toolbar.add(
        new AnAction(
            "Open Find Usages Toolwindow",
            "Show all usages in a separate toolwindow",
            AllIcons.Toolwindows.ToolWindowFind) {
          {
            AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_USAGES);
            setShortcutSet(action.getShortcutSet());
          }

          @Override
          public void actionPerformed(AnActionEvent e) {
            hideHints();
            popup[0].cancel();
            FindUsagesManager findUsagesManager =
                ((FindManagerImpl) FindManager.getInstance(usageView.getProject()))
                    .getFindUsagesManager();

            findUsagesManager.findUsages(
                handler.getPrimaryElements(),
                handler.getSecondaryElements(),
                handler,
                options,
                FindSettings.getInstance().isSkipResultsWithOneUsage());
          }
        });

    ActionToolbar actionToolbar =
        ActionManager.getInstance()
            .createActionToolbar(ActionPlaces.USAGE_VIEW_TOOLBAR, toolbar, true);
    actionToolbar.setReservePlaceAutoPopupIcon(false);
    final JComponent toolBar = actionToolbar.getComponent();
    toolBar.setOpaque(false);
    builder.setSettingButton(toolBar);

    popup[0] = builder.createPopup();
    JComponent content = popup[0].getContent();

    myWidth =
        (int)
            (toolBar.getPreferredSize().getWidth()
                + new JLabel(
                        getFullTitle(
                            usages, title, hadMoreSeparator, visibleNodes.size() - 1, true))
                    .getPreferredSize()
                    .getWidth()
                + settingsButton.getPreferredSize().getWidth());
    myWidth = -1;
    for (AnAction action : toolbar.getChildren(null)) {
      action.unregisterCustomShortcutSet(usageView.getComponent());
      action.registerCustomShortcutSet(action.getShortcutSet(), content);
    }

    return popup[0];
  }
示例#5
0
  public JComponent createComponentImpl() {
    final JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
    mainPanel.setPreferredSize(new Dimension(-1, 200));
    final DefaultTableModel tableModel = createModel();
    myTable = new Table(tableModel);
    myTable.setIntercellSpacing(new Dimension(0, 0));
    myTable.setDefaultRenderer(TableItem.class, new MyRenderer());
    myTable.setShowGrid(false);
    myTable.setDragEnabled(false);
    myTable.setShowHorizontalLines(false);
    myTable.setShowVerticalLines(false);
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    myAddPathButton = new JButton(ProjectBundle.message("module.javadoc.add.path.button"));
    myAddPathButton.addActionListener(new AddPathActionListener());

    myRemoveButton = new JButton(ProjectBundle.message("module.javadoc.remove.button"));
    myRemoveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            final List removedItems = TableUtil.removeSelectedItems(myTable);
            if (removedItems.size() > 0) {
              saveData();
            }
          }
        });

    final JPanel panel = new JPanel(new GridBagLayout());
    panel.add(
        myAddPathButton,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.NORTH,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 6, 0, 0),
            0,
            0));
    panel.add(
        myRemoveButton,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTH,
            GridBagConstraints.HORIZONTAL,
            new Insets(6, 6, 0, 0),
            0,
            0));

    mainPanel.add(ScrollPaneFactory.createScrollPane(myTable), BorderLayout.CENTER);
    mainPanel.add(panel, BorderLayout.EAST);
    final PanelWithText panelWithText =
        new PanelWithText(ProjectBundle.message("project.roots.external.annotations.description"));
    panelWithText.setBorder(null);
    mainPanel.add(panelWithText, BorderLayout.NORTH);

    myTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) {
                  return;
                }
                final int selectedIndex = myTable.getSelectedRow();
                myRemoveButton.setEnabled(selectedIndex >= 0);
              }
            });
    if (tableModel.getRowCount() > 0) {
      TableUtil.selectRows(myTable, new int[] {0});
    } else {
      myRemoveButton.setEnabled(false);
    }
    return mainPanel;
  }