List of usage examples for javax.swing JSlider JSlider
public JSlider(int min, int max)
From source file:biomine.bmvis2.pipeline.SizeSliderOperation.java
@Override public JComponent getSettingsComponent(final SettingsChangeCallback v, final VisualGraph graph) { final JSlider sizeSlider; sizeSlider = new JSlider(0, graph.getAllNodes().size() + 10); sizeSlider.setValue(graph.getNodes().size()); sizeSlider.addChangeListener(new ChangeListener() { @Override/*from w w w . j a v a2 s .c o m*/ public void stateChanged(ChangeEvent arg0) { targetSize = sizeSlider.getValue(); v.settingsChanged(false); } }); return sizeSlider; }
From source file:net.chaosserver.timelord.swingui.AnnoyTimeDialog.java
/** * Constructs a annoy time dialog for setting the dialog. * * @param applicationFrame the parent frame *//*from w ww . j a va 2 s . c o m*/ public AnnoyTimeDialog(JFrame applicationFrame) { super(applicationFrame, "Set Day Start Time", true); JPanel annoyTimePanel = new JPanel(); minuteSlider = new JSlider(0, 60); minuteSlider.setMajorTickSpacing(15); minuteSlider.setMinorTickSpacing(3); minuteSlider.setPaintLabels(true); minuteSlider.setPaintTicks(true); minuteSlider.setSnapToTicks(true); Preferences preferences = Preferences.userNodeForPackage(Timelord.class); double timeIncrement = preferences.getDouble(Timelord.TIME_INCREMENT, 0.25); if (log.isDebugEnabled()) { log.debug("Loaded Time Increment Preference [" + timeIncrement + "] from preference [" + Timelord.TIME_INCREMENT + "]"); } minuteSlider.setValue((int) (timeIncrement * 60)); annoyTimePanel.add(minuteSlider); JButton okayButton = new JButton( resourceBundle.getString("net.chaosserver.timelord.swingui.TimelordMenu.okay")); okayButton.setActionCommand(ACTION_OK); okayButton.addActionListener(this); annoyTimePanel.add(okayButton); JButton cancelButton = new JButton( resourceBundle.getString("net.chaosserver.timelord.swingui.TimelordMenu.cancel")); cancelButton.setActionCommand(ACTION_CANCEL); cancelButton.addActionListener(this); annoyTimePanel.add(cancelButton); this.getContentPane().add(annoyTimePanel); this.pack(); this.setLocationRelativeTo(applicationFrame); }
From source file:de.codesourcery.flocking.ui.NumberInputField.java
/** * Create instance.//from w w w . ja v a 2 s . co m * * <p>Creates a resizable panel that holds a label, a textfield and a slider * for entering/adjusting a numeric value.</p> * * @param label the label to display * @param model the model that is used to read/write the value to be edited. If the model returns <code>null</code> values, * these will be treated as "0" (or "0.0" respectively). * @param minValue valid minimum value (inclusive) the user may enter * @param maxValue vali maximum value (inclusive) the user may enter * @param onlyIntValues whether the user may enter only integers or integers <b>and</b> floating-point numbers. */ public NumberInputField(String label, IModel<T> model, double minValue, double maxValue, final boolean onlyIntValues) { if (model == null) { throw new IllegalArgumentException("model must not be NULL."); } this.model = model; this.minValue = minValue; this.maxValue = maxValue; this.onlyIntValues = onlyIntValues; textField = new JTextField("0"); textField.setColumns(5); textField.setHorizontalAlignment(JTextField.RIGHT); slider = new JSlider(0, SLIDER_RESOLUTION); textField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (selfTriggeredEvent) { return; } final String s = textField.getText(); if (!StringUtils.isBlank(s)) { Number number = null; try { if (onlyIntValues) { number = Long.parseLong(s.trim()); } else { number = Double.parseDouble(s.trim()); } } catch (Exception ex) { textField.setText(numberToString(NumberInputField.this.model.getObject())); return; } updateModelValue(number); } } }); textField.setText(numberToString(model.getObject())); slider.getModel().setValue(calcSliderValue(model.getObject())); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (selfTriggeredEvent) { return; } final double percentage = slider.getModel().getValue() / (double) SLIDER_RESOLUTION; // 0...1 final double range = Math.abs(NumberInputField.this.maxValue - NumberInputField.this.minValue); final double newValue = NumberInputField.this.minValue + range * percentage; updateModelValue(newValue); } }); slider.setMinimumSize(new Dimension(100, 20)); slider.setPreferredSize(new Dimension(100, 20)); // do layout setLayout(new GridBagLayout()); GridBagConstraints cnstrs = new GridBagConstraints(); cnstrs.fill = GridBagConstraints.NONE; cnstrs.weightx = 0; cnstrs.weighty = 0; cnstrs.gridx = 0; cnstrs.gridy = 0; final JLabel l = new JLabel(label); l.setMinimumSize(new Dimension(1500, 20)); l.setPreferredSize(new Dimension(150, 20)); l.setVerticalAlignment(SwingConstants.TOP); add(l, cnstrs); cnstrs = new GridBagConstraints(); cnstrs.fill = GridBagConstraints.NONE; cnstrs.weightx = 0; cnstrs.weighty = 0; cnstrs.gridx = 1; cnstrs.gridy = 0; cnstrs.insets = new Insets(0, 0, 0, 10); add(textField, cnstrs); cnstrs = new GridBagConstraints(); cnstrs.fill = GridBagConstraints.HORIZONTAL; cnstrs.weightx = 1.0; cnstrs.weighty = 1.0; cnstrs.gridx = 2; cnstrs.gridy = 0; add(slider, cnstrs); }
From source file:de.codesourcery.gittimelapse.MyFrame.java
public MyFrame(File file, GitHelper gitHelper) throws RevisionSyntaxException, MissingObjectException, IncorrectObjectTypeException, AmbiguousObjectException, IOException, GitAPIException { super("GIT timelapse: " + file.getAbsolutePath()); if (gitHelper == null) { throw new IllegalArgumentException("gitHelper must not be NULL"); }//from ww w .jav a 2 s . c o m this.gitHelper = gitHelper; this.file = file; this.diffPanel = new DiffPanel(); final JDialog dialog = new JDialog((Frame) null, "Please wait...", false); dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(new JLabel("Please wait, locating revisions..."), BorderLayout.CENTER); dialog.pack(); dialog.setVisible(true); final IProgressCallback callback = new IProgressCallback() { @Override public void foundCommit(ObjectId commitId) { System.out.println("*** Found commit " + commitId); } }; System.out.println("Locating commits..."); commitList = gitHelper.findCommits(file, callback); dialog.setVisible(false); if (commitList.isEmpty()) { throw new RuntimeException("Found no commits"); } setMenuBar(createMenuBar()); diffModeChooser.setModel(new DefaultComboBoxModel<MyFrame.DiffDisplayMode>(DiffDisplayMode.values())); diffModeChooser.setSelectedItem(DiffDisplayMode.ALIGN_CHANGES); diffModeChooser.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final ObjectId commit = commitList.getCommit(revisionSlider.getValue() - 1); try { diffPanel.showRevision(commit); } catch (IOException | PatchApplyException e1) { e1.printStackTrace(); } } }); diffModeChooser.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component result = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); DiffDisplayMode mode = (DiffDisplayMode) value; switch (mode) { case ALIGN_CHANGES: setText("Align changes"); break; case REGULAR: setText("Regular"); break; default: setText(mode.toString()); } return result; } }); revisionSlider = new JSlider(1, commitList.size()); revisionSlider.setPaintLabels(true); revisionSlider.setPaintTicks(true); addKeyListener(keyListener); getContentPane().addKeyListener(keyListener); if (commitList.size() < 10) { revisionSlider.setMajorTickSpacing(1); revisionSlider.setMinorTickSpacing(1); } else { revisionSlider.setMajorTickSpacing(5); revisionSlider.setMinorTickSpacing(1); } final ObjectId latestCommit = commitList.getLatestCommit(); if (latestCommit != null) { revisionSlider.setValue(1 + commitList.indexOf(latestCommit)); revisionSlider.setToolTipText(latestCommit.getName()); } revisionSlider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (!revisionSlider.getValueIsAdjusting()) { final ObjectId commit = commitList.getCommit(revisionSlider.getValue() - 1); long time = -System.currentTimeMillis(); try { diffPanel.showRevision(commit); } catch (IOException | PatchApplyException e1) { e1.printStackTrace(); } finally { time += System.currentTimeMillis(); } if (Main.DEBUG_MODE) { System.out.println("Rendering time: " + time); } } } }); getContentPane().setLayout(new GridBagLayout()); GridBagConstraints cnstrs = new GridBagConstraints(); cnstrs.gridx = 0; cnstrs.gridy = 0; cnstrs.gridwidth = 1; cnstrs.gridheight = 1; cnstrs.weightx = 0; cnstrs.weighty = 0; cnstrs.fill = GridBagConstraints.NONE; getContentPane().add(new JLabel("Diff display mode:"), cnstrs); cnstrs = new GridBagConstraints(); cnstrs.gridx = 1; cnstrs.gridy = 0; cnstrs.gridwidth = 1; cnstrs.gridheight = 1; cnstrs.weightx = 0; cnstrs.weighty = 0; cnstrs.fill = GridBagConstraints.NONE; getContentPane().add(diffModeChooser, cnstrs); cnstrs = new GridBagConstraints(); cnstrs.gridx = 2; cnstrs.gridy = 0; cnstrs.gridwidth = 1; cnstrs.gridheight = 1; cnstrs.weightx = 1.0; cnstrs.weighty = 0; cnstrs.fill = GridBagConstraints.HORIZONTAL; getContentPane().add(revisionSlider, cnstrs); cnstrs = new GridBagConstraints(); cnstrs.gridx = 0; cnstrs.gridy = 1; cnstrs.gridwidth = 3; cnstrs.gridheight = 1; cnstrs.weightx = 1; cnstrs.weighty = 1; cnstrs.fill = GridBagConstraints.BOTH; getContentPane().add(diffPanel, cnstrs); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); if (latestCommit != null) { diffPanel.showRevision(latestCommit); } }
From source file:SoundPlayer.java
JSlider createSlider(final FloatControl c) { if (c == null) return null; final JSlider s = new JSlider(0, 1000); final float min = c.getMinimum(); final float max = c.getMaximum(); final float width = max - min; float fval = c.getValue(); s.setValue((int) ((fval - min) / width * 1000)); java.util.Hashtable labels = new java.util.Hashtable(3); labels.put(new Integer(0), new JLabel(c.getMinLabel())); labels.put(new Integer(500), new JLabel(c.getMidLabel())); labels.put(new Integer(1000), new JLabel(c.getMaxLabel())); s.setLabelTable(labels);//from w w w . jav a2 s .c o m s.setPaintLabels(true); s.setBorder(new TitledBorder(c.getType().toString() + " " + c.getUnits())); s.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { int i = s.getValue(); float f = min + (i * width / 1000.0f); c.setValue(f); } }); return s; }
From source file:SoundPlayer.java
void addMidiControls() { // Add a slider to control the tempo final JSlider tempo = new JSlider(50, 200); tempo.setValue((int) (sequencer.getTempoFactor() * 100)); tempo.setBorder(new TitledBorder("Tempo Adjustment (%)")); java.util.Hashtable labels = new java.util.Hashtable(); labels.put(new Integer(50), new JLabel("50%")); labels.put(new Integer(100), new JLabel("100%")); labels.put(new Integer(200), new JLabel("200%")); tempo.setLabelTable(labels);//from w w w.j av a 2 s . c o m tempo.setPaintLabels(true); // The event listener actually changes the tmpo tempo.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { sequencer.setTempoFactor(tempo.getValue() / 100.0f); } }); this.add(tempo); // Create rows of solo and checkboxes for each track Track[] tracks = sequence.getTracks(); for (int i = 0; i < tracks.length; i++) { final int tracknum = i; // Two checkboxes per track final JCheckBox solo = new JCheckBox("solo"); final JCheckBox mute = new JCheckBox("mute"); // The listeners solo or mute the track solo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sequencer.setTrackSolo(tracknum, solo.isSelected()); } }); mute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sequencer.setTrackMute(tracknum, mute.isSelected()); } }); // Build up a row Box box = Box.createHorizontalBox(); box.add(new JLabel("Track " + tracknum)); box.add(Box.createHorizontalStrut(10)); box.add(solo); box.add(Box.createHorizontalStrut(10)); box.add(mute); box.add(Box.createHorizontalGlue()); // And add it to this component this.add(box); } }
From source file:JXTransformer.java
private JPanel createDemoPanel() { JPanel buttonPanel = new JPanel(new GridLayout(3, 2)); TitledBorder titledBorder = BorderFactory.createTitledBorder("Try three sliders below !"); Font titleFont = titledBorder.getTitleFont(); titledBorder.setTitleFont(titleFont.deriveFont(titleFont.getSize2D() + 10)); titledBorder.setTitleJustification(TitledBorder.CENTER); buttonPanel.setBorder(titledBorder); JButton b = new JButton("JButton"); b.setPreferredSize(new Dimension(100, 50)); buttonPanel.add(createTransformer(b)); Vector<String> v = new Vector<String>(); v.add("One"); v.add("Two"); v.add("Three"); JList list = new JList(v); buttonPanel.add(createTransformer(list)); buttonPanel.add(createTransformer(new JCheckBox("JCheckBox"))); JSlider slider = new JSlider(0, 100); slider.setLabelTable(slider.createStandardLabels(25, 0)); slider.setPaintLabels(true);/*from ww w . j a v a 2 s. c o m*/ slider.setPaintTicks(true); slider.setMajorTickSpacing(10); buttonPanel.add(createTransformer(slider)); buttonPanel.add(createTransformer(new JRadioButton("JRadioButton"))); final JLabel label = new JLabel("JLabel"); label.addMouseListener(new MouseAdapter() { public void mouseEntered(MouseEvent e) { Font font = label.getFont(); label.setFont(font.deriveFont(font.getSize2D() + 10)); } public void mouseExited(MouseEvent e) { Font font = label.getFont(); label.setFont(font.deriveFont(font.getSize2D() - 10)); } }); buttonPanel.add(createTransformer(label)); return buttonPanel; }
From source file:org.forester.archaeopteryx.ControlPanel.java
private void buildJSlider(int width, int min, int max) { _color_branches_edpl_slider = new JSlider(min, max); Dimension d = _color_branches_edpl_slider.getSize(); d.width = width;/*from w ww. ja v a2s. c o m*/ d.height = 100; _color_branches_edpl_slider.setPreferredSize(d); // _color_branches_edpl_slider.setLayout(null); // slider popup with cutoff value _slider_popup = new JPopupMenu(); JLabel text = new JLabel(); text.setText(String.valueOf(_edpl_current_cutoff)); _slider_popup.add(text); if (!_configuration.isUseNativeUI()) { _color_branches_edpl_slider.setBackground(ControlPanel.jcb_background_color); _color_branches_edpl_slider.setForeground(ControlPanel.jcb_text_color); } _color_branches_edpl_slider.setToolTipText("Set cutoff for EDPL (0.5-1.0)"); _color_branches_edpl_slider.setMinorTickSpacing(10); _color_branches_edpl_slider.setMajorTickSpacing(50); _color_branches_edpl_slider.setPaintTicks(true); _color_branches_edpl_slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { // get Treepanel function final TreePanel tp = getMainPanel().getCurrentTreePanel(); if (tp == null) { return; } Phylogeny phy = tp.getPhylogeny(); _edpl_next_cutoff = ((double) ((JSlider) (e.getSource())).getValue() / 100.0); tp.edplSliderMovement(_edpl_next_cutoff, _edpl_current_cutoff); _edpl_current_cutoff = _edpl_next_cutoff; // System.out.println("Neuer Wert: "+ // ((JSlider)(e.getSource())).getValue()); } }); _color_branches_edpl_slider.addMouseMotionListener(new MouseMotionListener() { @Override public void mouseMoved(MouseEvent e) { if (_color_branches_edpl_slider.isEnabled()) { _slider_popup.setVisible(false); } } @Override public void mouseDragged(MouseEvent e) { if (_color_branches_edpl_slider.isEnabled()) { // Point p = getMainPanel().getMainFrame().getLocation(); Point p = _color_branches_edpl_slider.getLocationOnScreen(); JLabel text = (JLabel) _slider_popup.getComponent(0); text.setText(String.valueOf(_edpl_current_cutoff)); int x = (int) p.getX() + 18; int y = (int) p.getY() - 25; _slider_popup.setLocation(x, y); _slider_popup.setVisible(true); } } }); }
From source file:windows.sensorWindow.java
/** * window constructor for chart window//from w w w . j a v a 2s . c o m * * @param title * title for the new window */ public sensorWindow(final String title) { super(title); System.out.println("create sensorWindow"); // font customizing // ------------------------------------------------------- /* * Font font1 = null; try { font1 = Font.createFont(Font.TRUETYPE_FONT, * new File("U:/workspace/SWTtest/fonts/roboto/Roboto-Black.ttf")); } * catch (FontFormatException | IOException e1) { e1.printStackTrace(); * } StandardChartTheme chartTheme = new * StandardChartTheme("robotTheme"); * chartTheme.setExtraLargeFont(font1.deriveFont(24f)); * chartTheme.setLargeFont(font1.deriveFont(16f)); * chartTheme.setRegularFont(font1.deriveFont(12f)); * chartTheme.setSmallFont(font1.deriveFont(10f)); * ChartFactory.setChartTheme(chartTheme); */ Font font1 = new Font("Tahoma", Font.BOLD, 16); Font font2 = new Font("Tahoma", Font.PLAIN, 12); Font font3 = new Font("Tahoma", Font.BOLD, 16); customFonts.put("axisLabelFont", font1); customFonts.put("axisValueFont", font2); customFonts.put("titleFont", font3); // ------------------------------------------------------------------------- this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); plot = new CombinedDomainXYPlot(new DateAxis("Time")); for (int i = 0; i < connectionData.presentedBrickList.size(); i++) { Brick tmpBrick = connectionData.presentedBrickList.get(i); addPlot(tmpBrick); } final JFreeChart chart = new JFreeChart("", plot); // chart.setBorderPaint(Color.black); // chart.setBorderVisible(true); // chart.setBackgroundPaint(Color.white); chart.removeLegend(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setRenderer(renderer2); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); final ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(chartRangeSec * 1000); // chart range seconds axis.setLabelFont(customFonts.get("axisLabelFont")); axis.setTickLabelFont(customFonts.get("axisValueFont")); //final JPanel content = new JPanel(new BorderLayout()); content = new JPanel(new BorderLayout()); JScrollPane scrollPane = new JScrollPane(); JViewport viewport = scrollPane.getViewport(); viewport.setView(content); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel, BorderLayout.NORTH); // content.add(getScrollBar(xAxe), BorderLayout.SOUTH); // disable zoom chartPanel.setRangeZoomable(false); chartPanel.setDomainZoomable(false); // mouse selection chartPanel.addMouseListener(new MouseMarker(chartPanel)); chartPanel.setPreferredSize(new java.awt.Dimension(500, 470)); // chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); // setContentPane(content); // =================================================== // buttons buttonPanel = new JPanel(new FlowLayout()); for (int i = 0; i < connectionData.presentedBrickList.size(); i++) { for (int i2 = 0; i2 < 2; i2++) { Brick tmpBrick = connectionData.presentedBrickList.get(i); JButton button = new JButton(tmpBrick.uid + " start"); button.setActionCommand(buttonComAddBtn + tmpBrick.uid + i + "(" + i2 + ")"); button.addActionListener(this); tmplButtons.put(tmpBrick.uid, button); // if ((tmpBrick.ctrlTmpl[0]) || (tmpBrick.ctrlTmpl[1])) // { // buttonPanel.add(button); // } changeTmplCntrl(tmpBrick, i2); } } content.add(buttonPanel, BorderLayout.SOUTH); // =================================================== // =================================================== // scroll bar final JPanel sliderPanel = new JPanel(new FlowLayout()); slider = new JSlider(1, sliderValuesNumber); slider.setValue(sliderValuesNumber); slider.setEnabled(false); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (sliderData.sliderActive == true) { int sliderValue = slider.getValue(); if (sliderValue == sliderValuesNumber) sliderUpdate = true; else sliderUpdate = false; /* System.out.println("slider : " + sliderValue); System.out.println("Millis first: " + sliderData.getMilliseconds( sliderValue - sliderValuesNumber) .toString()); System.out.println("Millis last : " + sliderData.getMilliseconds(sliderValue) .toString()); */ DateRange range = new DateRange( sliderData.getMilliseconds(sliderValue - sliderValuesNumber).getFirstMillisecond(), sliderData.getMilliseconds(sliderValue).getFirstMillisecond()); plot.getDomainAxis().setRange(range); } } }); sliderPanel.add(slider); // chartPanel.add(slider); /* * final Panel chartPanel2 = new Panel(); chartPanel2.add(slider); * content.add(chartPanel2, BorderLayout.SOUTH); */ content.add(sliderPanel, BorderLayout.CENTER); // =================================================== // =================================================== // scrolling /* * String[] data = {"one", "two", "three", "four", "five", "six", * "seven", "eight", "nine", "ten"}; JList list = new JList(data); * * // give the list some scrollbars. // the horizontal (bottom) * scrollbar will only appear // when the screen is too wide. The * vertical // scrollbar is always present, but disabled if the // list * is small. JScrollPane jsp = new JScrollPane(list, * JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, * JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); * * // add the JScrollPane (not the list) to the window. * getContentPane().add(jsp, BorderLayout.CENTER); */ // ================================================== setContentPane(content); this.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent e) { chartPanel.setMaximumDrawWidth((int) e.getComponent().getSize().getWidth()); chartPanel.setMaximumDrawHeight((int) e.getComponent().getSize().getHeight()); //chartPanel.setPreferredSize(e.getComponent().getPreferredSize()); //chartPanel.setSize(e.getComponent().getSize()); //chartPanel.setLocation(0,0); } }); // start auto update plot autoUpdatePlot(); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.out.println("close sensor window"); functions.windowController.closeSensorWindow(); } }); }
From source file:ca.phon.ipamap.IpaMap.java
/** * Create the context menu based on source component *//*from w w w . j a va2 s.co m*/ public void setupContextMenu(JPopupMenu menu, JComponent comp) { final CommonModuleFrame parentFrame = (CommonModuleFrame) SwingUtilities .getAncestorOfClass(CommonModuleFrame.class, comp); if (parentFrame != null) { final PhonUIAction toggleAlwaysOnTopAct = new PhonUIAction(parentFrame, "setAlwaysOnTop", !parentFrame.isAlwaysOnTop()); toggleAlwaysOnTopAct.putValue(PhonUIAction.NAME, "Always on top"); toggleAlwaysOnTopAct.putValue(PhonUIAction.SELECTED_KEY, parentFrame.isAlwaysOnTop()); final JCheckBoxMenuItem toggleAlwaysOnTopItem = new JCheckBoxMenuItem(toggleAlwaysOnTopAct); menu.add(toggleAlwaysOnTopItem); } // button options first if (comp instanceof CellButton) { CellButton btn = (CellButton) comp; Cell cell = btn.cell; // copy to clipboard options String cellData = cell.getText().replaceAll("" + (char) 0x25cc, ""); PhonUIAction copyToClipboardAct = new PhonUIAction(this, "onCopyToClipboard", cellData); copyToClipboardAct.putValue(PhonUIAction.NAME, "Copy character (" + cell.getText() + ")"); JMenuItem copyToClipboardItem = new JMenuItem(copyToClipboardAct); menu.add(copyToClipboardItem); String htmlVal = new String(); for (Character c : cellData.toCharArray()) { htmlVal += "&#" + (int) c + ";"; } PhonUIAction copyHTMLToClipboardAct = new PhonUIAction(this, "onCopyToClipboard", htmlVal); copyHTMLToClipboardAct.putValue(PhonUIAction.NAME, "Copy as HTML (" + htmlVal + ")"); JMenuItem copyHTMLToClipboardItem = new JMenuItem(copyHTMLToClipboardAct); menu.add(copyHTMLToClipboardItem); String hexVal = new String(); for (Character c : cellData.toCharArray()) { hexVal += (hexVal.length() > 0 ? " " : "") + Integer.toHexString((int) c); } hexVal = hexVal.toUpperCase(); PhonUIAction copyHEXToClipboardAct = new PhonUIAction(this, "onCopyToClipboard", hexVal); copyHEXToClipboardAct.putValue(PhonUIAction.NAME, "Copy as Unicode HEX (" + hexVal + ")"); JMenuItem copyHEXToClipboardItem = new JMenuItem(copyHEXToClipboardAct); menu.add(copyHEXToClipboardItem); menu.addSeparator(); if (isInFavorites(cell)) { PhonUIAction removeFromFavAct = new PhonUIAction(this, "onRemoveCellFromFavorites", cell); removeFromFavAct.putValue(Action.NAME, "Remove from favorites"); removeFromFavAct.putValue(Action.SHORT_DESCRIPTION, "Remove button from list of favorites"); JMenuItem removeFromFavItem = new JMenuItem(removeFromFavAct); menu.add(removeFromFavItem); } else { PhonUIAction addToFavAct = new PhonUIAction(this, "onAddCellToFavorites", cell); addToFavAct.putValue(Action.NAME, "Add to favorites"); addToFavAct.putValue(Action.SHORT_DESCRIPTION, "Add button to list of favorites"); JMenuItem addToFavItem = new JMenuItem(addToFavAct); menu.add(addToFavItem); } menu.addSeparator(); } // section scroll-tos JMenuItem gotoTitleItem = new JMenuItem("Scroll to:"); gotoTitleItem.setEnabled(false); menu.add(gotoTitleItem); for (JXButton toggleBtn : toggleButtons) { PhonUIAction gotoAct = new PhonUIAction(this, "onGoto", toggleBtn); gotoAct.putValue(Action.NAME, toggleBtn.getText()); gotoAct.putValue(Action.SHORT_DESCRIPTION, "Scroll to " + toggleBtn.getText()); JMenuItem gotoItem = new JMenuItem(gotoAct); menu.add(gotoItem); } menu.addSeparator(); // setup font scaler final JLabel smallLbl = new JLabel("A"); smallLbl.setFont(getFont().deriveFont(12.0f)); smallLbl.setHorizontalAlignment(SwingConstants.CENTER); JLabel largeLbl = new JLabel("A"); largeLbl.setFont(getFont().deriveFont(24.0f)); largeLbl.setHorizontalAlignment(SwingConstants.CENTER); final JSlider scaleSlider = new JSlider(1, 101); scaleSlider.setValue((int) (scale * 100)); scaleSlider.setMajorTickSpacing(20); scaleSlider.setMinorTickSpacing(10); scaleSlider.setSnapToTicks(true); scaleSlider.setPaintTicks(true); scaleSlider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { int sliderVal = scaleSlider.getValue(); float scale = (float) sliderVal / (float) 100; _cFont = null; setSavedScale(scale); setScale(scale); } }); FormLayout scaleLayout = new FormLayout("3dlu, center:pref, fill:pref:grow, center:pref, 3dlu", "pref"); CellConstraints cc = new CellConstraints(); JPanel scalePanel = new JPanel(scaleLayout) { @Override public Insets getInsets() { Insets retVal = super.getInsets(); retVal.left += UIManager.getIcon("Tree.collapsedIcon").getIconWidth(); return retVal; } }; scalePanel.add(smallLbl, cc.xy(2, 1)); scalePanel.add(scaleSlider, cc.xy(3, 1)); scalePanel.add(largeLbl, cc.xy(4, 1)); JMenuItem scaleItem = new JMenuItem("Font size"); scaleItem.setEnabled(false); menu.add(scaleItem); menu.add(scalePanel); menu.addSeparator(); // highlighting PhonUIAction onToggleHighlightAct = new PhonUIAction(this, "onToggleHighlightRecent"); onToggleHighlightAct.putValue(PhonUIAction.NAME, "Highlight recently used"); onToggleHighlightAct.putValue(PhonUIAction.SELECTED_KEY, isHighlightRecent()); JCheckBoxMenuItem onToggleHighlightItm = new JCheckBoxMenuItem(onToggleHighlightAct); menu.add(onToggleHighlightItm); }