Ejemplo n.º 1
0
  public void refreshSupplier(boolean remove) {

    if (remove) panel.remove(supplierCombo);

    try {
      model =
          new DefaultComboBoxModel(
              Manager.getInstance().getSupplierManager().getSuppliers().toArray());
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    supplierCombo = new JComboBox(model);
    supplierCombo.setUI(ColorArrowUI.createUI(this));
    supplierCombo.setEditable(true);
    supplierComboField = (JTextField) supplierCombo.getEditor().getEditorComponent();
    supplierComboField.setText("");
    supplierComboField.setOpaque(false);
    supplierComboField.setBorder(BorderFactory.createEmptyBorder());
    supplierComboField.addKeyListener(new ComboKeyHandler(supplierCombo));

    supplierCombo.setFont(new Font("Arial Narrow", Font.PLAIN, 14));
    supplierCombo.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
    supplierCombo.setOpaque(false);

    supplierCombo.setSelectedIndex(-1);

    supplierCombo.setVisible(supplierLabel.isVisible());

    supplierCombo.setBounds(85, 56, 220, 20);

    panel.add(supplierCombo);
  }
Ejemplo n.º 2
0
  private void createComponents(JPanel p) {
    String tt = "Any of these:  45.5 -120.2   or   45 30 0 n 120 12 0 w   or   Seattle";

    JComboBox field = new JComboBox();
    field.setOpaque(false);
    field.setEditable(true);
    field.setLightWeightPopupEnabled(false);
    field.setPreferredSize(new Dimension(200, field.getPreferredSize().height));
    field.setToolTipText(tt);

    JLabel label = new JLabel(ImageLibrary.getIcon("gov/nasa/worldwindow/images/safari-24x24.png"));
    //            new
    // ImageIcon(getClass().getResource("gov/nasa/worldwindow/images/safari-24x24.png")));
    label.setOpaque(false);
    label.setToolTipText(tt);

    p.add(label, BorderLayout.WEST);
    p.add(field, BorderLayout.CENTER);

    field.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            performGazeteerAction(actionEvent);
          }
        });
  }
Ejemplo n.º 3
0
 private void creaBox() {
   for (int i = 0; i < 4; i++) {
     JComboBox box = new JComboBox<>(ColoriDisponibili.disponibili.getColori().keySet().toArray());
     box.setRenderer(new ColorRender());
     box.setOpaque(true);
     boxes.add(box);
   }
 }
Ejemplo n.º 4
0
 // implement an abstract member to set colors
 void setColor(Color c) {
   if (c != null) {
     _value.setBackground(c);
   } else {
     _value.setBackground(_defaultColor);
   }
   _value.setOpaque(true);
 }
Ejemplo n.º 5
0
 private void initJComboBox(JComboBox jcb) {
   jcb.setSize(120, 20);
   jcb.setOpaque(false);
   jcb.setFocusable(false);
   jcb.setRenderer(new StarComboBoxRender());
   jcb.setUI((ComboBoxUI) StarComboBoxUI.createUI(jcb));
   jcb.setBorder(new RoundBorder(Color.red));
   add(jcb);
 }
  /**
   * Construct with the given dimensions
   *
   * @param width the width
   * @param height the height
   * @throws VideoCaptureException
   */
  public VideoCaptureComponent(int width, int height, String devName) throws VideoCaptureException {
    super(BoxLayout.Y_AXIS);

    this.setOpaque(false);

    this.width = width;
    this.height = height;
    final List<Device> devices = VideoCapture.getVideoDevices();

    Video<MBFImage> vc = null;
    if (devices == null || devices.size() == 0) {
      currentDevice = null;

      final MBFImage[] frames = {new MBFImage(width, height, ColourSpace.RGB)};
      frames[0].fill(RGBColour.RED);
      vc = new ArrayBackedVideo<MBFImage>(frames);
    } else {
      for (final Device d : devices) {
        if (d.getNameStr().contains(devName)) {
          currentDevice = d;
          break;
        }
      }

      if (currentDevice == null) currentDevice = devices.get(0);

      vc = new VideoCapture(width, height, currentDevice);
    }

    final JPanel videoDisplayPanel = new JPanel();
    videoDisplayPanel.setMinimumSize(new Dimension(width, height));
    videoDisplayPanel.setOpaque(false);
    display = VideoDisplay.createVideoDisplay(vc, videoDisplayPanel);
    add(videoDisplayPanel);

    final JPanel sourcesPanel = new JPanel();
    sourcesPanel.setOpaque(false);
    sources = new JComboBox<String>();
    sources.setOpaque(false);
    if (devices == null || devices.size() == 0) {
      sources.addItem("No cameras found");
      sources.setEnabled(false);
    } else {
      for (final Device s : devices) sources.addItem(s.getNameStr());
    }

    sources.setSelectedItem(currentDevice.getNameStr());

    sources.addItemListener(this);
    sourcesPanel.add(sources);
    add(sourcesPanel);
  }
Ejemplo n.º 7
0
  DropdownImp() {
    b.setOpaque(false);

    b.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent ie) {
            if (ie.getStateChange() != ItemEvent.SELECTED
                && onSelectionChange != null
                && !selecting) {
              getInterface().getOwner().getCallbackHandler().callHandleErrors(onSelectionChange);
            }
          }
        });
    add(b);
  }
  /**
   * Constructeur de la classe
   *
   * @param numJoueur rang du joueur dans la liste des joueurs
   */
  public CadranSaisieInfoOrdinateur(int numJoueur) {

    this.setOpaque(false);
    this.setLayout(null);

    imageCadran.setIcon(
        new ImageIcon(getClass().getResource("/CadranJoueur" + numJoueur + ".png")));
    this.add(imageCadran);
    imageCadran.setBounds(0, 0, 160, 150);

    strategie.setOpaque(false);
    strategie.setFont(new java.awt.Font("Wawati SC", 0, 13));
    strategie.setBounds(3, 112, 150, 33);
    this.add(strategie, 0);

    strategie.setModel(
        new javax.swing.DefaultComboBoxModel(
            new String[] {"Agressif", "Agressif avec Bluff", "Normal", "Passif"}));
  }
Ejemplo n.º 9
0
  @Override
  public void createSubcomponents() {
    super.createSubcomponents();

    m_patternChooser = new JComboBox<HandSymbolGenerator.Pattern>(m_soul.m_patterns);
    m_patternChooser.setOpaque(false);
    m_patternChooser.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            m_soul.m_currentPattern = m_patternChooser.getSelectedIndex();
          }
        });

    m_handModeChooser = new JComboBox<String>(HandSymbolGenerator.m_handModes);
    m_handModeChooser.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            m_soul.m_currentHandMode = m_handModeChooser.getSelectedIndex();
          }
        });
  }
Ejemplo n.º 10
0
  /**
   * Create a choicebox for link line style options and return the panel it is in.
   *
   * @return JPanel the panel holding the new choicebox for the link style options.
   */
  private JPanel createLinkDashedChoiceBox() {

    JPanel drawPanel = new JPanel(new BorderLayout());
    CSH.setHelpIDString(drawPanel, "toolbars.formatlink"); // $NON-NLS-1$

    cbLinkDashed = new JComboBox();
    cbLinkDashed.setToolTipText(
        LanguageProperties.getString(
            LanguageProperties.TOOLBARS_BUNDLE, "UIToolBarFormatLink.selectDashed")); // $NON-NLS-1$
    cbLinkDashed.setOpaque(true);
    cbLinkDashed.setEditable(false);
    cbLinkDashed.setEnabled(false);
    cbLinkDashed.setMaximumRowCount(10);
    cbLinkDashed.setFont(new Font("Dialog", Font.PLAIN, 10)); // $NON-NLS-1$

    cbLinkDashed.addItem(
        new String(
            LanguageProperties.getString(
                LanguageProperties.TOOLBARS_BUNDLE,
                "UIToolBarFormatLink.plainLine"))); //$NON-NLS-1$
    cbLinkDashed.addItem(
        new String(
            LanguageProperties.getString(
                LanguageProperties.TOOLBARS_BUNDLE,
                "UIToolBarFormatLink.largeDashes"))); //$NON-NLS-1$
    cbLinkDashed.addItem(
        new String(
            LanguageProperties.getString(
                LanguageProperties.TOOLBARS_BUNDLE,
                "UIToolBarFormatLink.smallDashes"))); //$NON-NLS-1$

    cbLinkDashed.validate();

    cbLinkDashed.setSelectedIndex(0);

    DefaultListCellRenderer drawRenderer =
        new DefaultListCellRenderer() {
          public Component getListCellRendererComponent(
              JList list, Object value, int modelIndex, boolean isSelected, boolean cellHasFocus) {
            if (list != null) {
              if (isSelected) {
                setBackground(list.getSelectionBackground());
                setForeground(list.getSelectionForeground());
              } else {
                setBackground(list.getBackground());
                setForeground(list.getForeground());
              }
            }

            setText((String) value);
            return this;
          }
        };

    cbLinkDashed.setRenderer(drawRenderer);

    ActionListener drawActionListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            onUpdateLinkDashed(cbLinkDashed.getSelectedIndex());
          }
        };
    cbLinkDashed.addActionListener(drawActionListener);

    drawPanel.add(new JLabel(" "), BorderLayout.WEST); // $NON-NLS-1$
    drawPanel.add(cbLinkDashed, BorderLayout.CENTER);
    return drawPanel;
  }
Ejemplo n.º 11
0
  /**
   * Create a choicbox for link line thickness options and return the panel it is in.
   *
   * @return JPanel the panel holding the new choicebox for the line thickness options.
   */
  private JPanel createWeightChoiceBox() {

    JPanel drawPanel = new JPanel(new BorderLayout());
    CSH.setHelpIDString(drawPanel, "toolbars.formatlink"); // $NON-NLS-1$

    cbLineWeight = new JComboBox();
    cbLineWeight.setToolTipText(
        LanguageProperties.getString(
            LanguageProperties.TOOLBARS_BUNDLE, "UIToolBarFormatLink.selectWeight")); // $NON-NLS-1$
    cbLineWeight.setOpaque(true);
    cbLineWeight.setEditable(false);
    cbLineWeight.setEnabled(false);
    cbLineWeight.setMaximumRowCount(10);
    cbLineWeight.setFont(new Font("Dialog", Font.PLAIN, 10)); // $NON-NLS-1$

    cbLineWeight.addItem(new String("1 px")); // $NON-NLS-1$
    cbLineWeight.addItem(new String("2 px")); // $NON-NLS-1$
    cbLineWeight.addItem(new String("3 px")); // $NON-NLS-1$
    cbLineWeight.addItem(new String("4 px")); // $NON-NLS-1$
    cbLineWeight.addItem(new String("5 px")); // $NON-NLS-1$
    cbLineWeight.addItem(new String("6 px")); // $NON-NLS-1$
    cbLineWeight.addItem(new String("7 px")); // $NON-NLS-1$
    cbLineWeight.addItem(new String("8 px")); // $NON-NLS-1$
    cbLineWeight.addItem(new String("9 px")); // $NON-NLS-1$
    cbLineWeight.addItem(new String("10 px")); // $NON-NLS-1$

    cbLineWeight.validate();

    cbLineWeight.setSelectedIndex(0);

    DefaultListCellRenderer drawRenderer =
        new DefaultListCellRenderer() {
          public Component getListCellRendererComponent(
              JList list, Object value, int modelIndex, boolean isSelected, boolean cellHasFocus) {
            if (list != null) {
              if (isSelected) {
                setBackground(list.getSelectionBackground());
                setForeground(list.getSelectionForeground());
              } else {
                setBackground(list.getBackground());
                setForeground(list.getForeground());
              }
            }

            setText((String) value);
            return this;
          }
        };

    cbLineWeight.setRenderer(drawRenderer);

    ActionListener drawActionListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            int ind = cbLineWeight.getSelectedIndex();

            if (ind == 0) onUpdateLinkWeight(1);
            else if (ind == 1) onUpdateLinkWeight(2);
            else if (ind == 2) onUpdateLinkWeight(3);
            else if (ind == 3) onUpdateLinkWeight(4);
            else if (ind == 4) onUpdateLinkWeight(5);
            else if (ind == 5) onUpdateLinkWeight(6);
            else if (ind == 6) onUpdateLinkWeight(7);
            else if (ind == 7) onUpdateLinkWeight(8);
            else if (ind == 8) onUpdateLinkWeight(9);
            else if (ind == 9) onUpdateLinkWeight(10);
          }
        };
    cbLineWeight.addActionListener(drawActionListener);

    drawPanel.add(new JLabel(" "), BorderLayout.WEST); // $NON-NLS-1$
    drawPanel.add(cbLineWeight, BorderLayout.CENTER);
    return drawPanel;
  }
Ejemplo n.º 12
0
  /** Create the arrow head choicebox. */
  private JPanel createArrowChoiceBox() {

    JPanel drawPanel = new JPanel(new BorderLayout());
    CSH.setHelpIDString(drawPanel, "toolbars.formatlink"); // $NON-NLS-1$

    cbArrows = new JComboBox();
    cbArrows.setToolTipText(
        LanguageProperties.getString(
            LanguageProperties.TOOLBARS_BUNDLE, "UIToolBarFormatLink.selectArrow")); // $NON-NLS-1$
    cbArrows.setOpaque(true);
    cbArrows.setEditable(false);
    cbArrows.setEnabled(false);
    cbArrows.setMaximumRowCount(4);
    cbArrows.setFont(new Font("Dialog", Font.PLAIN, 10)); // $NON-NLS-1$

    Vector arrows = new Vector(5);
    arrows.insertElementAt(
        LanguageProperties.getString(
            LanguageProperties.DIALOGS_BUNDLE, "UILinkEditDialog.noArrows"),
        0); //$NON-NLS-1$
    arrows.insertElementAt(
        LanguageProperties.getString(LanguageProperties.DIALOGS_BUNDLE, "UILinkEditDialog.fromTo"),
        1); //$NON-NLS-1$
    arrows.insertElementAt(
        LanguageProperties.getString(LanguageProperties.DIALOGS_BUNDLE, "UILinkEditDialog.toFfrom"),
        2); //$NON-NLS-1$
    arrows.insertElementAt(
        LanguageProperties.getString(
            LanguageProperties.DIALOGS_BUNDLE, "UILinkEditDialog.bothWays"),
        3); //$NON-NLS-1$
    DefaultComboBoxModel comboModel = new DefaultComboBoxModel(arrows);
    cbArrows.setModel(comboModel);
    cbArrows.setSelectedIndex(0);

    DefaultListCellRenderer comboRenderer =
        new DefaultListCellRenderer() {
          public Component getListCellRendererComponent(
              JList list, Object value, int modelIndex, boolean isSelected, boolean cellHasFocus) {
            if (isSelected) {
              setBackground(list.getSelectionBackground());
              setForeground(list.getSelectionForeground());
            } else {
              setBackground(list.getBackground());
              setForeground(list.getForeground());
            }

            setText((String) value);

            return this;
          }
        };
    cbArrows.setRenderer(comboRenderer);

    cbArrows.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            onUpdateArrowType(cbArrows.getSelectedIndex());
          }
        });

    drawPanel.add(new JLabel(" "), BorderLayout.WEST); // $NON-NLS-1$
    drawPanel.add(cbArrows, BorderLayout.CENTER);
    return drawPanel;
  }
Ejemplo n.º 13
0
  public JPanel Panel() throws IOException {
    new ImageGet();
    Image bgp = ImageGet.getImageByState("adduser");
    background = new ImageIcon(bgp);

    p1.setBounds(0, 0, 988, 756);

    final MTextfield t1 = new MTextfield();
    final MTextfield t2 = new MTextfield();
    final MTextfield t3 = new MTextfield();
    Color text = new Color(0, 0, 0);

    final String[] jobs = {"营业厅业务员", "快递员", "中转中心业务员", "中转中心库存管理人员", "总经理", "财务人员", "管理员"};
    final JComboBox job = new JComboBox(jobs);
    job.setOpaque(false);
    job.setUI(
        new BasicComboBoxUI() {
          public void installUI(JComponent job) {
            super.installUI(job);
            //                listBox.setBackground();
            listBox.setSelectionForeground(Color.BLACK);
          }

          protected JButton createArrowButton() {
            return super.createArrowButton();
          }
        });

    t1.setOpaque(false);
    t2.setOpaque(false);
    t3.setOpaque(false);
    t1.setBorder(BorderFactory.createEmptyBorder());
    t2.setBorder(BorderFactory.createEmptyBorder());
    t3.setBorder(BorderFactory.createEmptyBorder());

    JButton b5 = new JButton();
    b5.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            boolean idisempty = t1.getText().equals("");
            boolean nameisempty = t2.getText().equals("");
            boolean passwordisempty = t3.getText().equals("");
            boolean isempty = idisempty || nameisempty || passwordisempty;

            if (!isempty) {
              UserInfoPO user =
                  new UserInfoPO(
                      t1.getText(), t3.getText(), t2.getText(), job.getSelectedItem().toString());
              //					System.out.println(t1.getText());
              //					System.out.println(t3.getText());
              //					System.out.println(t2.getText());
              //					System.out.println(job.getSelectedItem().toString());
              UserBl userbl = new UserBl(oos, ois);
              if (userbl.AddUser(user)) Mdialog.showMessageDialog("新建成功!");
              else Mdialog.showMessageDialog("抱歉,新建失败!");
            } else Mdialog.showMessageDialog("新建失败,请确认信息填写完整!");
          }
        });

    p1.setOpaque(false);
    p1.setLayout(null);

    p1.add(t1);
    p1.add(t2);
    p1.add(t3);
    p1.add(job);

    p1.add(b5);

    int length = 174, width = 43;

    t1.setBounds(194, 319, length, width);
    t1.settextFont();
    t2.setBounds(194, 409, length, width);
    t2.settextFont();
    t3.setBounds(600, 319, length, width);
    t3.settextFont();
    job.setBounds(600, 409, length, width);

    b5.setContentAreaFilled(false);
    b5.setBorder(BorderFactory.createEmptyBorder());
    b5.setBounds(582, 606, 200, 54);
    return p1;
  }
Ejemplo n.º 14
0
  /** Display a frame for browsing issues. */
  private JPanel constructView() {
    // sort the original issues list
    final SortedList<Issue> issuesSortedList = new SortedList<Issue>(issuesEventList, null);

    // filter the sorted issues
    FilterList<Issue> filteredIssues =
        new FilterList<Issue>(issuesSortedList, filterPanel.getMatcherEditor());

    SeparatorList<Issue> separatedIssues =
        new SeparatorList<Issue>(
            filteredIssues,
            GlazedLists.beanPropertyComparator(Issue.class, "subcomponent"),
            0,
            Integer.MAX_VALUE);
    EventList<Issue> separatedIssuesProxyList =
        GlazedListsSwing.swingThreadProxyList(separatedIssues);
    // build the issues table
    issuesTableModel =
        GlazedListsSwing.eventTableModel(separatedIssuesProxyList, new IssueTableFormat());
    final TableColumnModel issuesTableColumnModel =
        new EventTableColumnModel<TableColumn>(new BasicEventList<TableColumn>());
    JSeparatorTable issuesJTable = new JSeparatorTable(issuesTableModel, issuesTableColumnModel);
    issuesJTable.setAutoCreateColumnsFromModel(true);

    issuesJTable.setSeparatorRenderer(new IssueSeparatorTableCell(separatedIssues));
    issuesJTable.setSeparatorEditor(new IssueSeparatorTableCell(separatedIssues));
    issuesSelectionModel = GlazedListsSwing.eventSelectionModel(separatedIssuesProxyList);
    issuesSelectionModel.setSelectionMode(
        ListSelection
            .MULTIPLE_INTERVAL_SELECTION_DEFENSIVE); // multi-selection best demos our awesome
                                                     // selection management
    issuesSelectionModel.addListSelectionListener(new IssuesSelectionListener());
    issuesJTable.setSelectionModel(issuesSelectionModel);
    issuesJTable.getColumnModel().getColumn(0).setPreferredWidth(150);
    issuesJTable.getColumnModel().getColumn(1).setPreferredWidth(400);
    issuesJTable.getColumnModel().getColumn(2).setPreferredWidth(300);
    issuesJTable.getColumnModel().getColumn(3).setPreferredWidth(300);
    issuesJTable.getColumnModel().getColumn(4).setPreferredWidth(250);
    issuesJTable.getColumnModel().getColumn(5).setPreferredWidth(300);
    issuesJTable.getColumnModel().getColumn(6).setPreferredWidth(300);
    issuesJTable.getColumnModel().getColumn(7).setPreferredWidth(1000);
    // turn off cell focus painting
    issuesJTable.setDefaultRenderer(
        String.class, new NoFocusRenderer(issuesJTable.getDefaultRenderer(String.class)));
    issuesJTable.setDefaultRenderer(
        Integer.class, new NoFocusRenderer(issuesJTable.getDefaultRenderer(Integer.class)));
    issuesJTable.setDefaultRenderer(
        Priority.class, new NoFocusRenderer(new PriorityTableCellRenderer()));
    LookAndFeelTweaks.tweakTable(issuesJTable);
    TableComparatorChooser.install(
        issuesJTable, issuesSortedList, TableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD);
    JScrollPane issuesTableScrollPane =
        new JScrollPane(
            issuesJTable,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    issuesTableScrollPane.getViewport().setBackground(UIManager.getColor("EditorPane.background"));
    issuesTableScrollPane.setBorder(BorderFactory.createEmptyBorder());

    issueDetails = new IssueDetailsComponent(filteredIssues);

    // projects
    EventList<Project> projects = Project.getProjects();
    TransformedList<Project, Project> projectsProxyList =
        GlazedListsSwing.swingThreadProxyList(projects);
    // project select combobox
    DefaultEventComboBoxModel projectsComboModel =
        new DefaultEventComboBoxModel<Project>(projectsProxyList);
    JComboBox projectsCombo = new JComboBox(projectsComboModel);
    projectsCombo.setEditable(false);
    projectsCombo.setOpaque(false);
    projectsCombo.addItemListener(new ProjectChangeListener());
    projectsComboModel.setSelectedItem(new Project(null, "Select a Java.net project..."));

    // build a label to display the number of issues in the issue table
    issueCounter = new IssueCounterLabel(filteredIssues);
    issueCounter.setHorizontalAlignment(SwingConstants.CENTER);
    issueCounter.setForeground(Color.WHITE);

    // throbber
    throbber = new JLabel(THROBBER_STATIC);
    throbber.setHorizontalAlignment(SwingConstants.RIGHT);

    // header bar
    JPanel iconBar = new GradientPanel(GLAZED_LISTS_MEDIUM_BROWN, GLAZED_LISTS_DARK_BROWN, true);
    iconBar.setLayout(new GridLayout(1, 3));
    iconBar.add(projectsCombo);
    iconBar.add(issueCounter);
    iconBar.add(throbber);
    iconBar.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    // assemble all data components on a common panel
    JPanel dataPanel = new JPanel();
    JComponent issueDetailsComponent = issueDetails;
    dataPanel.setLayout(new GridLayout(2, 1));
    dataPanel.add(issuesTableScrollPane);
    dataPanel.add(issueDetailsComponent);

    // draw lines between components
    JComponent filtersPanel = filterPanel.getComponent();
    filtersPanel.setBorder(BorderFactory.createEmptyBorder());
    // filtersPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1,
    // IssuesBrowser.GLAZED_LISTS_DARK_BROWN));
    issueDetailsComponent.setBorder(
        BorderFactory.createMatteBorder(1, 0, 0, 0, GLAZED_LISTS_DARK_BROWN));

    // the outermost panel to layout the icon bar with the other panels
    final JPanel mainPanel = new JPanel(new GridBagLayout());
    mainPanel.add(
        iconBar,
        new GridBagConstraints(
            0,
            0,
            2,
            1,
            1.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    mainPanel.add(
        filtersPanel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    mainPanel.add(
        Box.createHorizontalStrut(240),
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    mainPanel.add(
        dataPanel,
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));

    return mainPanel;
  }
Ejemplo n.º 15
0
  public ParameterTablePanel(
      Project project, VariableData[] variableData, final PsiElement... scopeElements) {
    super(new BorderLayout());
    myProject = project;
    myVariableData = variableData;

    myTableModel = new MyTableModel();
    myTable = new JBTable(myTableModel);
    DefaultCellEditor defaultEditor = (DefaultCellEditor) myTable.getDefaultEditor(Object.class);
    defaultEditor.setClickCountToStart(1);

    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myTable.setCellSelectionEnabled(true);
    TableColumn checkboxColumn = myTable.getColumnModel().getColumn(MyTableModel.CHECKMARK_COLUMN);
    TableUtil.setupCheckboxColumn(checkboxColumn);
    checkboxColumn.setCellRenderer(new CheckBoxTableCellRenderer());
    myTable
        .getColumnModel()
        .getColumn(MyTableModel.PARAMETER_NAME_COLUMN)
        .setCellRenderer(
            new DefaultTableCellRenderer() {
              public Component getTableCellRendererComponent(
                  JTable table,
                  Object value,
                  boolean isSelected,
                  boolean hasFocus,
                  int row,
                  int column) {
                super.getTableCellRendererComponent(
                    table, value, isSelected, hasFocus, row, column);
                VariableData data = getVariableData()[row];
                setText(data.name);
                return this;
              }
            });

    myParameterTypeSelectors = new TypeSelector[getVariableData().length];
    for (int i = 0; i < myParameterTypeSelectors.length; i++) {
      final PsiVariable variable = getVariableData()[i].variable;
      final PsiExpression[] occurrences = findVariableOccurrences(scopeElements, variable);
      final TypeSelectorManager manager =
          new TypeSelectorManagerImpl(
              myProject, getVariableData()[i].type, occurrences, areTypesDirected()) {
            @Override
            protected boolean isUsedAfter() {
              return ParameterTablePanel.this.isUsedAfter(variable);
            }
          };
      myParameterTypeSelectors[i] = manager.getTypeSelector();
      getVariableData()[i].type = myParameterTypeSelectors[i].getSelectedType(); // reverse order
    }

    myTypeRendererCombo = new JComboBox(getVariableData());
    myTypeRendererCombo.setOpaque(true);
    myTypeRendererCombo.setBorder(null);
    myTypeRendererCombo.setRenderer(
        new ListCellRendererWrapper<VariableData>() {
          @Override
          public void customize(
              JList list, VariableData value, int index, boolean selected, boolean hasFocus) {
            if (value != null) {
              setText(value.type.getPresentableText());
            }
          }
        });

    final TableColumn typeColumn =
        myTable.getColumnModel().getColumn(MyTableModel.PARAMETER_TYPE_COLUMN);
    typeColumn.setCellEditor(
        new AbstractTableCellEditor() {
          TypeSelector myCurrentSelector;
          final JBComboBoxTableCellEditorComponent myEditorComponent =
              new JBComboBoxTableCellEditorComponent();

          @Nullable
          public Object getCellEditorValue() {
            return myEditorComponent.getEditorValue();
          }

          public Component getTableCellEditorComponent(
              final JTable table,
              final Object value,
              final boolean isSelected,
              final int row,
              final int column) {
            myEditorComponent.setCell(table, row, column);
            myEditorComponent.setOptions(myParameterTypeSelectors[row].getTypes());
            myEditorComponent.setDefaultValue(getVariableData()[row].type);
            myEditorComponent.setToString(
                new Function<Object, String>() {
                  @Override
                  public String fun(Object o) {
                    return ((PsiType) o).getPresentableText();
                  }
                });

            myCurrentSelector = myParameterTypeSelectors[row];
            return myEditorComponent;
          }
        });

    myTable
        .getColumnModel()
        .getColumn(MyTableModel.PARAMETER_TYPE_COLUMN)
        .setCellRenderer(
            new DefaultTableCellRenderer() {
              private JBComboBoxLabel myLabel = new JBComboBoxLabel();

              public Component getTableCellRendererComponent(
                  JTable table,
                  Object value,
                  boolean isSelected,
                  boolean hasFocus,
                  int row,
                  int column) {
                myLabel.setText(String.valueOf(value));
                myLabel.setBackground(
                    isSelected ? table.getSelectionBackground() : table.getBackground());
                myLabel.setForeground(
                    isSelected ? table.getSelectionForeground() : table.getForeground());
                if (isSelected) {
                  myLabel.setSelectionIcon();
                } else {
                  myLabel.setRegularIcon();
                }
                return myLabel;
              }
            });

    myTable.setPreferredScrollableViewportSize(new Dimension(250, myTable.getRowHeight() * 5));
    myTable.setShowGrid(false);
    myTable.setIntercellSpacing(new Dimension(0, 0));
    @NonNls final InputMap inputMap = myTable.getInputMap();
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "enable_disable");
    @NonNls final ActionMap actionMap = myTable.getActionMap();
    actionMap.put(
        "enable_disable",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            if (myTable.isEditing()) return;
            int[] rows = myTable.getSelectedRows();
            if (rows.length > 0) {
              boolean valueToBeSet = false;
              for (int row : rows) {
                if (!getVariableData()[row].passAsParameter) {
                  valueToBeSet = true;
                  break;
                }
              }
              for (int row : rows) {
                getVariableData()[row].passAsParameter = valueToBeSet;
              }
              myTableModel.fireTableRowsUpdated(rows[0], rows[rows.length - 1]);
              TableUtil.selectRows(myTable, rows);
            }
          }
        });
    //// F2 should edit the name
    // inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), "edit_parameter_name");
    // actionMap.put("edit_parameter_name", new AbstractAction() {
    //  public void actionPerformed(ActionEvent e) {
    //    if (!myTable.isEditing()) {
    //      int row = myTable.getSelectedRow();
    //      if (row >= 0 && row < myTableModel.getRowCount()) {
    //        TableUtil.editCellAt(myTable, row, MyTableModel.PARAMETER_NAME_COLUMN);
    //      }
    //    }
    //  }
    // });

    //// make ENTER work when the table has focus
    // inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "invokeImpl");
    // actionMap.put("invokeImpl", new AbstractAction() {
    //  public void actionPerformed(ActionEvent e) {
    //    TableCellEditor editor = myTable.getCellEditor();
    //    if (editor != null) {
    //      editor.stopCellEditing();
    //    }
    //    else {
    //      doEnterAction();
    //    }
    //  }
    // });

    // make ESCAPE work when the table has focus
    actionMap.put(
        "doCancel",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            TableCellEditor editor = myTable.getCellEditor();
            if (editor != null) {
              editor.stopCellEditing();
            } else {
              doCancelAction();
            }
          }
        });

    JPanel listPanel =
        ToolbarDecorator.createDecorator(myTable)
            .disableAddAction()
            .disableRemoveAction()
            .createPanel();
    add(listPanel, BorderLayout.CENTER);

    if (getVariableData().length > 1) {
      myTable.getSelectionModel().setSelectionInterval(0, 0);
    }
  }