protected void configureDetailsButton(boolean expanded) { if (expanded) { detailButton.setText( UIManagerExt.getString(CLASS_NAME + ".details_contract_text", detailButton.getLocale())); } else { detailButton.setText( UIManagerExt.getString(CLASS_NAME + ".details_expand_text", detailButton.getLocale())); } }
private void configureAbstractButton(AbstractButton button, String resource) { String title = resources.getString(resource); int i = title.indexOf('&'); int mnemonic = 0; if (i >= 0) { mnemonic = title.charAt(i + 1); title = title.substring(0, i) + title.substring(i + 1); button.setText(title); button.setMnemonic(Character.toUpperCase(mnemonic)); button.setDisplayedMnemonicIndex(i); } else button.setText(title); }
private JComponent addItem( final Component pComponent, final KToolbarImpl pToolbar, final Action pAction) { JComponent item = null; final String key = (String) pAction.getValue(Action.NAME); if (pAction instanceof KMenu) { final KMenu actionMenu = (KMenu) pAction; item = actionMenu.create(pComponent); pToolbar.add(item); } else if (pAction == KAction.SEPARATOR) { pToolbar.addSeparator(); } else if (pAction instanceof KComponentAction) { item = ((KComponentAction) pAction).getComponent(); pToolbar.add(item); } else { AbstractButton button; ActionGroup group = (ActionGroup) pAction.getValue(KAction.KEY_GROUP); if (group != null) { button = new JToggleButton(pAction); ((JToggleButton) button).setSelected(group.getSelected() == pAction); ButtonGroup bg = group.getButtonGroup(ResKey.TOOLBAR); bg.add(button); } else { button = new JButton(pAction); } item = button; final WidgetResources wr = ResourceAdapter.getInstance().getWidget(key, ResKey.TOOLBAR); Icon icon = wr.getIcon(); if (icon == null) { icon = DEF_ICON; } button.setIcon(icon); button.setToolTipText(wr.getToolTip()); button.setMargin(ZERO_INSETS); button.setRequestFocusEnabled(false); button.setFocusable(false); if (false) { button.setText(wr.getText()); button.setMnemonic(wr.getMnenomnic()); button.setDisplayedMnemonicIndex(wr.getMnenomnicIndex()); } else { button.setText(null); } } if (item != null) { pToolbar.add(item); } return item; }
private AbstractButton createButton() { final String action = getAction(); final AbstractButton button; if (toggleButton) { button = new CToggleButton(this); button.setSelectedIcon(iconPressed); } else { final CButton cbutton = new CButton(this); if (buttonDefaultCapable != null) { cbutton.setDefaultCapable(buttonDefaultCapable); } button = cbutton; } button.setName(action); button.setIcon(icon); button.setText(buttonText); button.setActionCommand(action); button.setMargin(buttonInsets); button.setSize(BUTTON_SIZE); // // Action button.getActionMap().put(action, this); // // Update button state from this action updateButtonPressedState(button); replaceAcceleratorKey(button, getAccelerator(), null); return button; }
/** * Maybe a lengthy operation depending on the passed in Runnable. * * @param resultCode * @param cliOutputLines * @param cliErrorLines */ @Override public void cliProcessCompleted( final int resultCode, final String[] cliOutputLines, final String[] cliErrorLines) { if (cliErrorLines.length != 0) { final JLabel jLabel_Error = new JLabel(); jLabel_Error.setForeground(Color.RED); jLabel_Error.setOpaque( true); // BorderLayout functions as a NullLayout inside each compass constraint jLabel_Error.setText("<HTML>" + StringsUtil_.concatenate("<BR>", cliErrorLines)); jLabel_Error.setVerticalAlignment(JLabel.TOP); fWindowToClose.add(jLabel_Error, BorderLayout.WEST); } jProgressBar.setVisible(false); ab_Done.setText("OK"); ab_Done.setEnabled(true); ab_Done.requestFocusInWindow(); // hilite it final Thread postProcessCompletionThread = new Thread( new Runnable() // anonymous class { @Override public void run() { // cause notification fResultCodeCompletionCallback.listen(resultCode); // autobox } }, this.getClass().getCanonicalName()); postProcessCompletionThread .start(); // runs completion in another thread so Swing can update the pending JList paint }
private void assertFindByName(AbstractButton comp) { GuiComponent guiComponent = GuiComponentFactory.newGuiComponent(comp); assertFalse("Composant inretrouvable", guiComponent.isFindable()); comp.setText("Bobo"); assertTrue("Composant retrouvable par le label", guiComponent.isFindable()); assertEquals(FindStrategyId.BY_LABEL, guiComponent.getBestFindStrategyId()); assertEquals("Bobo", guiComponent.getLabel()); }
/** * Constructs a toolbar button for the given action and returns it. * * @param action The action to create a toolbar button for. * @param toggle If set to <code>true</code>, indicates that a <code>JToggleButton</code> shall be * returned rather than a <code>JButton</code>. * @return The according <code>AbstractButton</code>. */ public static AbstractButton createToolbarButton(Action action, boolean toggle) { AbstractButton butt = null; if (action instanceof ViewAction) { if (((ViewAction) action).getView().isMultipleInstancePerSessionElementAllowed()) { butt = new JButton(action); } else { butt = new JToggleButton(action); } butt.setText(null); ((ViewAction) action).addButton(butt); } if (butt == null) { if (toggle) { butt = new JButton(action); } else { butt = new JButton(action /*(Icon) action.getValue( Action.SMALL_ICON )*/); } butt.setText(null); action.putValue("button", butt); if (action instanceof ViewAction) { ((ViewAction) action).addButton(butt); butt.setDisabledIcon(SPACER); } else { action.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if ("enabled".equals(e.getPropertyName())) { ((AbstractButton) ((Action) e.getSource()).getValue("button")) .setEnabled(((Boolean) e.getNewValue()).booleanValue()); } } }); } } // butt.addActionListener( action ); butt.setEnabled(action.isEnabled()); butt.setMaximumSize(new Dimension(22, 22)); butt.setToolTipText((String) action.getValue("toolTipText")); butt.setMargin(new Insets(2, 2, 2, 2)); butt.setFocusable(false); return butt; }
/** * Make an {@link AbstractButton} be configured in a "toolbar-like" way, for instance showing only * the icon. * * @param actionButton Button to toolbarise */ protected void toolbarizeButton(AbstractButton actionButton) { Action action = actionButton.getAction(); if (action.getValue(SHORT_DESCRIPTION) == null) action.putValue(SHORT_DESCRIPTION, action.getValue(NAME)); actionButton.setBorder(new EmptyBorder(0, 2, 0, 2)); // actionButton.setHorizontalTextPosition(JButton.CENTER); // actionButton.setVerticalTextPosition(JButton.BOTTOM); if (action.getValue(Action.SMALL_ICON) != null) { // Don't show the text actionButton.putClientProperty("hideActionText", true); // Since hideActionText seems to be broken in Java 5 and/or OS X actionButton.setText(null); } }
public static AbstractButton makeToolBarButton(Command cmd) { AbstractButton b; if (cmd instanceof ToggleCommand) { b = new JToggleButton(cmd); b.setSelected(((ToggleCommand) cmd).isSelected()); } else { b = new JButton(cmd); } b.setFocusable(false); b.setText(null); // b.setMargin(new Insets(2, 2, 2, 2)); b.setBorderPainted(false); cmd.bind(b); return b; }
public static AbstractButton makeCustomButton(CustomAction customAction, boolean flip) { AbstractButton btn; CustomActionType type = customAction.getType(); if (type != null) { btn = makeCustomButton(type.resourceName(), null, flip); btn.setEnabled(true); } else { btn = new RolloverButton(); String name = customAction.getValue(Action.NAME).toString(); btn.setName(name); btn.setText(name); } btn.setAction(customAction); return btn; }
private void prepareButton( AbstractButton button, String actionKey, String buttonLabelText, String toolTipText, URL url) { Action action = new AbstractAction(actionKey) { public void actionPerformed(ActionEvent evt) {} }; button.setAction(action); button.setActionCommand(actionKey); button.setIcon(new ImageIcon(url)); button.setText(buttonLabelText); button.setToolTipText(toolTipText); button.addActionListener(this); }
/** * Shifts the screen view to the left. * * @return */ protected AbstractButton getLeftButton() { if (leftButton == null) { leftButton = new JButton("Left"); ImageIcon leftIcon = null; java.net.URL imgURL = null; try { imgURL = this.getClass().getResource("/images/leftArrow20.jpg"); leftIcon = new ImageIcon(imgURL); leftButton.setIcon(leftIcon); leftButton.setText(null); } catch (NullPointerException npe) { System.out.println("Failed to load in the icon [" + imgURL + "]"); } leftButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { view.shiftLeft(); } }); } return leftButton; }
protected void initialiseButton(Action action, AbstractButton btn) { if (btn != null) { btn.setRequestFocusEnabled(false); btn.setText(""); String tt = null; if (action != null) { tt = (String) action.getValue(Action.SHORT_DESCRIPTION); } btn.setToolTipText(tt != null ? tt : ""); if (action != null) { Icon icon = getIconFromAction(action, BaseAction.IBaseActionPropertyNames.ROLLOVER_ICON); if (icon != null) { btn.setRolloverIcon(icon); btn.setRolloverSelectedIcon(icon); } icon = getIconFromAction(action, BaseAction.IBaseActionPropertyNames.DISABLED_ICON); if (icon != null) { btn.setDisabledIcon(icon); } } } }
/** @noinspection ALL */ private void $$$loadButtonText$$$(AbstractButton component, String text) { StringBuffer result = new StringBuffer(); boolean haveMnemonic = false; char mnemonic = '\0'; int mnemonicIndex = -1; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '&') { i++; if (i == text.length()) break; if (!haveMnemonic && text.charAt(i) != '&') { haveMnemonic = true; mnemonic = text.charAt(i); mnemonicIndex = result.length(); } } result.append(text.charAt(i)); } component.setText(result.toString()); if (haveMnemonic) { component.setMnemonic(mnemonic); component.setDisplayedMnemonicIndex(mnemonicIndex); } }
public synchronized void execute() { long start = System.currentTimeMillis(); // For calculating render time fileProgress.setStringPainted(true); fileProgress.setMinimum(0); fileProgress.setMaximum(((CTWorld) Simulator.pworld).getNumConfigs()); fileProgress.setValue(((CTWorld) Simulator.pworld).getConfigNum()); fileProgress.setString( ((CTWorld) Simulator.pworld).getConfigNum() + "/" + ((CTWorld) Simulator.pworld).getNumConfigs()); iterationProgress.setStringPainted(true); iterationProgress.setMinimum(0); iterationProgress.setMaximum(((CTWorld) Simulator.pworld).getNumIterations()); iterationProgress.setValue(((CTWorld) Simulator.pworld).getIterationNum()); iterationProgress.setString( ((CTWorld) Simulator.pworld).getIterationNum() + "/" + ((CTWorld) Simulator.pworld).getNumIterations()); cycleProgress.setStringPainted(true); cycleProgress.setMinimum(0); cycleProgress.setMaximum(Simulator.experimentLength); cycleProgress.setValue(Simulator.cycle); cycleProgress.setString(Simulator.cycle + "/" + Simulator.experimentLength); commentLabel.setText(((CTWorld) Simulator.pworld).getComment()); phaseLabel.setText(getPhase()); turnProgress.setStringPainted(true); turnProgress.setMinimum(0); turnProgress.setMaximum(((CTWorld) Simulator.pworld).getTimeout()); turnProgress.setValue(((CTWorld) Simulator.pworld).getTurn()); turnProgress.setString( ((CTWorld) Simulator.pworld).getTurn() + "/" + ((CTWorld) Simulator.pworld).getTimeout()); if (initialise) initialise(); // Draw the viewer components in background-foreground order // updating certain elements for different phases if (((CTWorld) Simulator.pworld).getCurrentPhase().equals(CTWorld.REG_PHASE)) { // Registration phase showSpinner(); } else if (((CTWorld) Simulator.pworld).getCurrentPhase().equals(CTWorld.INIT_PHASE)) { if (Simulator.controlPanel.paused) { playButton.setText("Play"); } else { playButton.setText("Pause"); } updateInspectorTree(); // Initiation phase getAgentIcons(); updateImageBuffer(); addAgentPaths(); clearBuffer(); drawHexagons(); drawGoals(); drawAgents(); } else if (((CTWorld) Simulator.pworld).getCurrentPhase().equals(CTWorld.COMM_PHASE)) { // Communication phase if (resize) { // If a resize event has happened, we need to re-render resize = false; updateImageBuffer(); clearBuffer(); drawHexagons(); drawPaths(); drawGoals(); drawAgents(); } } else if (((CTWorld) Simulator.pworld).getCurrentPhase().equals(CTWorld.MOVE_PHASE)) { // Moving phase addAgentPaths(); clearBuffer(); drawHexagons(); drawPaths(); drawGoals(); drawAgents(); } else if (((CTWorld) Simulator.pworld).getCurrentPhase().equals(CTWorld.RESET_PHASE)) { agentPaths = new HashMap<String, ArrayList<Coord>>(); initialise = true; } else { logger.debug("Perhaps I could use this unknown phase for something..."); } // backBuffer ready for display worldMap.getGraphics().drawImage(backBufferImage, 0, 0, this); long finish = System.currentTimeMillis(); // For calculating render time String renderSpeed = dp.format(1000.0 / (finish - start)); // TODO claim james wrote something that "renders" at 3k fps or more? if (finish == start) { logger.trace("Rendering speed: <1ms."); } else { logger.trace("Rendering speed: " + renderSpeed + "fps."); } }
private void setMnemonic(final AbstractButton button) { final int existingMnemonic = button.getMnemonic(); if (existingMnemonic != 0) { m_existingMnemonics.add(existingMnemonic, button); return; } final String text = button.getText(); if (text == null) { return; } // Remove our text changed listener whilst changing text to prevent // recursion. m_textChangedListener.remove(button); button.setText(removeMnemonicMarkers(text)); m_textChangedListener.add(button); // Look for explicit mnemonic indicated by an underscore in the button's // text. We remove the underscores. int underscore = text.indexOf('_'); int numberOfUnderscores = 0; while (underscore >= 0 && underscore < text.length() - 1) { final int explicitMnemonic = toKey(text.charAt(underscore + 1), false); final AbstractButton existingExplicit = m_existingMnemonics.getExplicit(explicitMnemonic); // If there is an existing button with the same explicit mnemonic, it // takes precedence and we fall back to other heuristics. if (explicitMnemonic != 0 && existingExplicit == null || existingExplicit == button) { final AbstractButton oldButton = m_existingMnemonics.remove(explicitMnemonic); button.setMnemonic(explicitMnemonic); // Calling setDisplayedIndex() directly here doesn't work for text // change events since it is overwritten by AbstractButton.setText(), // based on the original text. I've submitted a bug to Sun. // // Instead, we dispatch the change in the AWT event dispatching thread, // which works for the common case that setText() is called from that // thread. final int index = underscore - numberOfUnderscores; SwingUtilities.invokeLater( new Runnable() { public void run() { button.setDisplayedMnemonicIndex(index); } }); m_existingMnemonics.addExplicit(explicitMnemonic, button); // If there is a different existing button with an implicit mnemonic, // we take precedence and we calculate a new mnemonic for it. if (oldButton != null && oldButton != button) { oldButton.setMnemonic(0); setMnemonic(oldButton); } return; } // Treat subsequent underscores as indications of alternative mnemonics. underscore = text.indexOf('_', underscore + 1); ++numberOfUnderscores; } // No explicit mnemonic, use heuristics. for (int i = 0; i < m_heuristics.length; ++i) { final int result = m_heuristics[i].apply(button.getText()); if (result != 0) { button.setMnemonic(result); m_existingMnemonics.add(result, button); return; } } }
public void setButtonLabel(String bl) { button.setText(bl); }
public TrayIconPopup(TrayExtension trayExtension) { super(); this.extension = trayExtension; // resizecomps = new ArrayList<AbstractButton>(); setVisible(false); setLayout(new MigLayout("ins 0", "[grow,fill]", "[grow,fill]")); addMouseListener(this); this.setUndecorated(true); // initEntryPanel(); // initQuickConfigPanel(); // initBottomPanel(); // initExitPanel(); JPanel content = new JPanel(new MigLayout("ins 5, wrap 1", "[fill]", "[]5[]")); add(content); JButton header; content.add( header = new JButton("<html><b>" + JDUtilities.getJDTitle(0) + "</b></html>"), "align center"); header.setBorderPainted(false); header.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JDGui.getInstance().setWindowToTray(false); dispose(); } }); AbstractButton ab; // System.out.println(this.getColConstraints(list.length)); MenuItemData last = null; for (final MenuItemData menudata : MenuManagerTrayIcon.getInstance().getMenuData().getItems()) { AbstractButton bt = null; AppAction action; try { if (!menudata.isVisible()) { continue; } if (menudata instanceof SeparatorData) { if (last != null && last instanceof SeparatorData) { // no separator dupes continue; } content.add(new JSeparator(SwingConstants.HORIZONTAL), "growx,spanx"); last = menudata; continue; } if (menudata._getValidateException() != null) { continue; } if (menudata.getType() == org.jdownloader.controlling.contextmenu.MenuItemData.Type.CONTAINER) { bt = new JToggleButton() { protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); g2.setColor(Color.BLACK); g2.fillPolygon( new int[] {getWidth() - 5, getWidth() - 5 - 6, getWidth() - 5 - 6}, new int[] {getHeight() / 2, getHeight() / 2 - 4, getHeight() / 2 + 4}, 3); } }; bt.setText(menudata.getName()); bt.setOpaque(false); bt.setContentAreaFilled(false); bt.setBorderPainted(false); bt.addActionListener( new ActionListener() { private ExtPopupMenu root = null; public void actionPerformed(ActionEvent e) { hideThreadrunning = false; if (root != null && root.isShowing()) { return; } root = new ExtPopupMenu(); new MenuBuilder( MenuManagerMainToolbar.getInstance(), root, (MenuContainer) menudata) { protected void addAction( final JComponent root, final MenuItemData inst, int index, int size) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException, ExtensionNotLoadedException { final JComponent ret = inst.addTo(root); if (ret instanceof AbstractButton) { ((AbstractButton) ret) .addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { ((AbstractButton) ret).getAction().actionPerformed(evt); TrayIconPopup.this.dispose(); } }); } } }.run(); Object src = e.getSource(); if (e.getSource() instanceof Component) { Component button = (Component) e.getSource(); Dimension prefSize = root.getPreferredSize(); int[] insets = LAFOptions.getInstance().getPopupBorderInsets(); root.show(button, button.getWidth(), -insets[0]); } } }); bt.setIcon(MenuItemData.getIcon(menudata.getIconKey(), ICON_SIZE)); bt.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); bt.setFocusPainted(false); bt.setHorizontalAlignment(JButton.LEFT); bt.setIconTextGap(5); bt.addMouseListener(new HoverEffect(bt)); final AbstractButton finalBt = bt; bt.addMouseListener( new MouseListener() { private Timer timer; @Override public void mouseReleased(MouseEvent e) { if (timer != null) { timer.stop(); timer = null; } } @Override public void mousePressed(MouseEvent e) { if (timer != null) { timer.stop(); timer = null; } } @Override public void mouseExited(MouseEvent e) { if (timer != null) { timer.stop(); timer = null; } } @Override public void mouseEntered(MouseEvent e) { timer = new Timer( 500, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { finalBt.doClick(); } }); timer.setRepeats(false); timer.start(); } @Override public void mouseClicked(MouseEvent e) { if (timer != null) { timer.stop(); timer = null; } } }); content.add(bt); continue; } else if (menudata instanceof MenuLink) { final JComponent item = menudata.createItem(); if (StringUtils.isNotEmpty(menudata.getIconKey())) { if (item instanceof AbstractButton) { ((AbstractButton) item) .setIcon(MenuItemData.getIcon(menudata.getIconKey(), ICON_SIZE)); } } content.add(item, ""); } else if (menudata.getActionData() != null) { action = menudata.createAction(); if (!action.isVisible()) { continue; } if (StringUtils.isNotEmpty(menudata.getShortcut()) && KeyStroke.getKeyStroke(menudata.getShortcut()) != null) { action.setAccelerator(KeyStroke.getKeyStroke(menudata.getShortcut())); } else if (MenuItemData.isEmptyValue(menudata.getShortcut())) { action.setAccelerator(null); } content.add(getMenuEntry(action)); last = menudata; } } catch (Exception e) { e.printStackTrace(); } } // content.add(new JSeparator(), "growx, spanx"); // content.add(entryPanel); // content.add(new JSeparator(), "growx, spanx"); // content.add(quickConfigPanel); // content.add(new JSeparator(), "growx, spanx"); // content.add(bottomPanel, "pushx,growx"); // content.add(new JSeparator(), "growx, spanx"); // content.add(exitPanel); // content.setBorder(BorderFactory.createLineBorder(content.getBackground().darker())); // Dimension size = new Dimension(getPreferredSize().width, // resizecomps.get(0).getPreferredSize().height); // for (AbstractButton c : resizecomps) { // c.setPreferredSize(size); // c.setMinimumSize(size); // c.setMaximumSize(size); // } setAlwaysOnTop(true); pack(); hideThread = new Thread() { /* * this thread handles closing of popup because enter/exit/move events are too slow and can miss the exitevent */ public void run() { while (true && hideThreadrunning) { try { sleep(500); } catch (InterruptedException e) { } if (enteredPopup && hideThreadrunning) { PointerInfo mouse = MouseInfo.getPointerInfo(); Point current = TrayIconPopup.this.getLocation(); if (mouse.getLocation().x < current.x || mouse.getLocation().x > current.x + TrayIconPopup.this.getSize().width) { dispose(); break; } else if (mouse.getLocation().y < current.y || mouse.getLocation().y > current.y + TrayIconPopup.this.getSize().height) { dispose(); break; } } } } }; hideThreadrunning = true; hideThread.start(); }
public void setTitleComponentText(String text) { if (titleComponent instanceof JButton) { titleComponent.setText(text); } placeTitleComponent(); }