public void setSelectedIndex(Integer selectedIndex) { if (selectedIndex == null) selectedIndex = -1; myTable.setSelectedIndex(selectedIndex); updateGUI(); }
public void setSliderValue(int value) { mySlider.removeChangeListener(this); mySlider.setValue(value); mySlider.addChangeListener(this); if (hasTable) myTable.setSliderValue(value); updateGUI(); }
private void updateGUI() { if (isIniting) return; setIcon(getButtonIcon()); if (hasTable) { myTable.repaint(); } repaint(); }
public ImageIcon getButtonIcon() { ImageIcon icon = (ImageIcon) this.getIcon(); if (isFixedIcon) return icon; // draw the icon for the current table selection if (hasTable) { switch (mode) { case SelectionTable.MODE_TEXT: // Strings are converted to icons. We don't use setText so that the button size can be // controlled // regardless of the layout manager. icon = GeoGebraIcon.createStringIcon( (String) data[getSelectedIndex()], app.getPlainFont(), false, false, true, iconSize, Color.BLACK, null); break; case SelectionTable.MODE_ICON: case SelectionTable.MODE_LATEX: icon = (ImageIcon) myTable.getSelectedValue(); break; default: icon = myTable.getDataIcon(data[getSelectedIndex()]); } } return icon; }
/** Create our JSlider */ private void initSlider() { mySlider = new JSlider(0, 100); mySlider.setMajorTickSpacing(25); mySlider.setMinorTickSpacing(5); mySlider.setPaintTicks(false); mySlider.setPaintLabels(false); // mySlider.setSnapToTicks(true); mySlider.addChangeListener(this); // set slider dimensions Dimension d = mySlider.getPreferredSize(); if (hasTable) d.width = myTable.getPreferredSize().width; else d.width = 110; mySlider.setPreferredSize(d); mySlider.setBackground(myPopup.getBackground()); myPopup.add(mySlider); }
public void setIndex(int mode) { myTable.setSelectedIndex(mode); }
/** * sets the tooTip strings for the menu selection table; the toolTipArray should have a 1-1 * correspondence with the data array * * @param toolTipArray */ public void setToolTipArray(String[] toolTipArray) { myTable.setToolTipArray(toolTipArray); }
public Object getSelectedValue() { return myTable.getSelectedValue(); }
public int getSelectedIndex() { return myTable.getSelectedIndex(); }
public PopupMenuButton( Application app, Object[] data, Integer rows, Integer columns, Dimension iconSize, Integer mode, final boolean hasTable, boolean hasSlider) { super(); this.app = app; this.hasTable = hasTable; this.mode = mode; this.iconSize = iconSize; this.thisButton = this; this.setFocusable(false); // create the popup myPopup = new JPopupMenu(); myPopup.setFocusable(false); myPopup.setBackground(Color.WHITE); myPopup.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(Color.GRAY), BorderFactory.createEmptyBorder(3, 3, 3, 3))); // add a mouse listener to our button that triggers the popup addMouseListener( new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { popupIsVisible = myPopup.isShowing(); } @Override public void mousePressed(MouseEvent e) { if (!thisButton.isEnabled()) return; if (popupIsVisible == true && !myPopup.isVisible()) { popupIsVisible = false; return; } if (prepareToShowPopup() == false) return; Point locButton = getLocation(); // trigger popup // default: trigger only when the mouse is over the right side of the button // if isStandardButton: pressing anywhere triggers the popup if (isStandardButton || e.getX() >= getWidth() - 16 && e.getX() <= getWidth()) { if (hasTable) myTable.updateFonts(); if (isDownwardPopup) // popup appears below the button myPopup.show(getParent(), locButton.x, locButton.y + getHeight()); else // popup appears above the button myPopup.show( getParent(), locButton.x - myPopup.getPreferredSize().width + thisButton.getWidth(), locButton.y - myPopup.getPreferredSize().height - 2); } popupIsVisible = myPopup.isShowing(); } }); // place text to the left of drop down icon this.setHorizontalTextPosition(SwingConstants.LEFT); this.setHorizontalAlignment(SwingConstants.LEFT); // create selection table if (hasTable) { this.data = data; myTable = new SelectionTable(app, data, rows, columns, iconSize, mode); setSelectedIndex(0); // add a mouse listener to handle table selection myTable.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { handlePopupActionEvent(); } }); /* // if displaying text only, then adjust the width if(mode == SelectionTable.MODE_TEXT){ Dimension d = this.getPreferredSize(); d.width = myTable.getColumnWidth(); setMinimumSize(d); setMaximumSize(d); } */ myTable.setBackground(myPopup.getBackground()); myPopup.add(myTable); } // create slider if (hasSlider) getMySlider(); isIniting = false; if (mode == SelectionTable.MODE_TEXT && iconSize.width == -1) { iconSize.width = myTable.getColumnWidth() - 4; iconSize.height = myTable.getRowHeight() - 4; } }