List of usage examples for javax.swing AbstractButton getModel
public ButtonModel getModel()
From source file:org.rdv.viz.image.ImageViz.java
/** * Select the correct radio button for the maximum number of filmstrip images. *///from w ww .ja va 2s.com private void updateMaximumFilmstripImagesRadioButtons() { int maximumFilmstripImages = filmstripPanel.getMaximumImages(); int index = Arrays.binarySearch(MAXIMUM_FILMSTRIP_IMAGES_VALUES, maximumFilmstripImages); if (index >= 0) { Enumeration<AbstractButton> elements = maximumFilmstripImagesButtonGroup.getElements(); AbstractButton button = null; while (index-- >= 0) { button = elements.nextElement(); } maximumFilmstripImagesButtonGroup.setSelected(button.getModel(), true); } else { ButtonModel buttonModel = maximumFilmstripImagesButtonGroup.getSelection(); if (buttonModel != null) { buttonModel.setSelected(false); } } }
From source file:corelyzer.ui.CorelyzerGLCanvas.java
private void updateMainFrameListSelection(final int track, final int section, final MouseEvent event) { CorelyzerApp app = CorelyzerApp.getApp(); if (app == null) { return;//from w w w.j a v a 2 s .c o m } if (track >= 0) { // Now, we need to traverse app's list model // to find match of native id // index conversion (native to java list) CRDefaultListModel sessionModel = app.getSessionListModel(); int sessionIndex = -1; TrackSceneNode trackNode = null; for (int i = 0; i < sessionModel.size(); i++) { Session session = (Session) sessionModel.elementAt(i); trackNode = session.getTrackSceneNodeWithTrackId(track); if (trackNode != null) { sessionIndex = i; } } if (sessionIndex < 0) { return; } // Set selected session app.getSessionList().setSelectedIndex(sessionIndex); // Track int ssize; boolean found = false; CRDefaultListModel tmodel = app.getTrackListModel(); // tsize = tmodel.getSize(); TrackSceneNode tt; CoreSection cs = null; for (int i = 0; i < tmodel.size() && !found; i++) { tt = (TrackSceneNode) tmodel.elementAt(i); if (track == tt.getId()) { selectedTrackIndex = i; ssize = tt.getNumCores(); for (int j = 0; j < ssize; j++) { cs = tt.getCoreSection(j); if (section == cs.getId()) { selectedTrackSectionIndex = j; found = true; break; } } } } if (!found || cs == null) { return; } // update ui CorelyzerApp.getApp().getTrackList().setSelectedIndex(selectedTrackIndex); JList secList = CorelyzerApp.getApp().getSectionList(); boolean selected = secList.isSelectedIndex(selectedTrackSectionIndex); List<Integer> indices = new ArrayList<Integer>(); indices.addAll(Arrays.asList(ArrayUtils.toObject(secList.getSelectedIndices()))); if (event.isControlDown() || (event.isMetaDown() && CorelyzerApp.MAC_OS_X)) { // toggle selection if (indices.contains(selectedTrackSectionIndex)) indices.remove(new Integer(selectedTrackSectionIndex)); else indices.add(selectedTrackSectionIndex); int[] newSelArray = ArrayUtils.toPrimitive(indices.toArray(new Integer[0])); secList.setSelectedIndices(newSelArray); } else if (event.isShiftDown()) { // select range int[] toSel = null; if (indices.size() == 0) { toSel = makeRangeArray(0, selectedTrackSectionIndex); } else { final int minSel = Collections.min(indices); final int maxSel = Collections.max(indices); if (selectedTrackSectionIndex < minSel) { toSel = makeRangeArray(selectedTrackSectionIndex, minSel); } else if (selectedTrackSectionIndex > maxSel) { toSel = makeRangeArray(maxSel, selectedTrackSectionIndex); } } secList.setSelectedIndices(toSel); } else if (!(event.isAltDown() && selected)) { // don't modify selection if Alt is down and section was already // selected...user is presumably trying to move it secList.setSelectedIndex(selectedTrackSectionIndex); } CRDefaultListModel lm = CorelyzerApp.getApp().getSectionListModel(); String secName = null; if (lm != null) { Object selSec = lm.getElementAt(selectedTrackSectionIndex); if (selSec != null) { secName = selSec.toString(); } else { System.out.println("no object at index"); } } else { System.out.println("no list model"); } JMenuItem title = (JMenuItem) this.scenePopupMenu.getComponent(0); String trackName = CorelyzerApp.getApp().getTrackListModel().getElementAt(selectedTrackIndex) .toString(); title.setText("Track: " + trackName); JMenuItem stitle = (JMenuItem) this.scenePopupMenu.getComponent(1); stitle.setText("Section: " + secName); // Enable section-based popupMenu options this.setEnableSectionBasedPopupMenuOptions(true); // 2/5/2012 brg: check Stagger Sections menu item if necessary final boolean trackIsStaggered = SceneGraph.trackIsStaggered(selectedTrack); AbstractButton ab = (AbstractButton) this.scenePopupMenu.getComponent(14); ab.getModel().setSelected(trackIsStaggered); // check section and graph lock menu items final boolean sectionIsLocked = !SceneGraph.isSectionMovable(selectedTrack, selectedTrackSection); ab = (AbstractButton) this.scenePopupMenu.getComponent(7); ab.getModel().setSelected(sectionIsLocked); final boolean sectionGraphIsLocked = !SceneGraph.isSectionGraphMovable(selectedTrack, selectedTrackSection); ab = (AbstractButton) this.scenePopupMenu.getComponent(8); ab.getModel().setSelected(sectionGraphIsLocked); CoreSectionImage csImg = cs.getCoreSectionImage(); if (csImg != null && csImg.getId() != -1) { this.propertyMenuItem.setEnabled(true); this.splitMenuItem.setEnabled(true); } else { this.propertyMenuItem.setEnabled(false); this.splitMenuItem.setEnabled(false); } // System.out.println("---> [in Java DS] Picked Track " + track + // " and Track Section " + section); // String secname = CorelyzerApp.getApp().getSectionListModel(). // getElementAt(section).toString(); // System.out.println("---> [INFO] Section " + secname + // " is selected"); } else { JMenuItem title = (JMenuItem) this.scenePopupMenu.getComponent(0); title.setText("Track: N/A"); JMenuItem stitle = (JMenuItem) this.scenePopupMenu.getComponent(1); stitle.setText("Section: N/A"); // disable section based items this.setEnableSectionBasedPopupMenuOptions(false); } }
From source file:corelyzer.ui.CorelyzerGLCanvas.java
void createPopupMenuUI() { JPopupMenu.setDefaultLightWeightPopupEnabled(false); this.scenePopupMenu = new JPopupMenu(); JMenuItem trackName = new JMenuItem("Track Name"); trackName.setEnabled(false);/*from ww w . j ava2s .co m*/ this.scenePopupMenu.add(trackName); JMenuItem sectionName = new JMenuItem("Section name"); sectionName.setEnabled(false); this.scenePopupMenu.add(sectionName); this.scenePopupMenu.addSeparator(); // Mode menu JMenu modeMenu = new JMenu("Mode"); ButtonGroup modeGroup = new ButtonGroup(); this.normalMode = new JRadioButtonMenuItem("Normal mode"); this.normalMode.setIcon(new ImageIcon(getClass().getResource("/corelyzer/ui/resources/normal.gif"))); this.normalMode.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { CorelyzerApp.getApp().getToolFrame().setMode(0); } }); this.normalMode.setSelected(true); modeGroup.add(this.normalMode); modeMenu.add(this.normalMode); this.clastMode = new JRadioButtonMenuItem("Create annotation mode"); this.clastMode.setIcon(new ImageIcon(getClass().getResource("/corelyzer/ui/resources/copyright.gif"))); this.clastMode.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { CorelyzerApp.getApp().getToolFrame().setMode(3); } }); modeGroup.add(this.clastMode); modeMenu.add(this.clastMode); this.markerMode = new JRadioButtonMenuItem("Modify annotation marker mode"); this.markerMode.setIcon(new ImageIcon(getClass().getResource("/corelyzer/ui/resources/marker.gif"))); this.markerMode.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { CorelyzerApp.getApp().getToolFrame().setMode(2); } }); modeGroup.add(this.markerMode); modeMenu.add(this.markerMode); this.measureMode = new JRadioButtonMenuItem("Measure mode"); this.measureMode.setIcon(new ImageIcon(getClass().getResource("/corelyzer/ui/resources/ruler.gif"))); this.measureMode.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { CorelyzerApp.getApp().getToolFrame().setMode(1); } }); modeGroup.add(this.measureMode); modeMenu.add(this.measureMode); this.cutMode = new JRadioButtonMenuItem("Cut mode"); this.cutMode.setIcon(new ImageIcon(getClass().getResource("/corelyzer/ui/resources/cut.gif"))); this.cutMode.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { CorelyzerApp.getApp().getToolFrame().setMode(4); } }); modeGroup.add(this.cutMode); modeMenu.add(this.cutMode); this.scenePopupMenu.add(modeMenu); JMenuItem hideTrackMenuItem = new JMenuItem("Hide track"); hideTrackMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { doHideTrack(); } }); this.scenePopupMenu.add(hideTrackMenuItem); JMenuItem exportTrackMenuItem = new JMenuItem("Export track"); exportTrackMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { doExportTrack(); } }); this.scenePopupMenu.add(exportTrackMenuItem); JMenuItem lockSectionMenuItem = new JCheckBoxMenuItem("Lock Section"); lockSectionMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { AbstractButton b = (AbstractButton) actionEvent.getSource(); doLockSection(b.getModel().isSelected()); } }); JMenuItem lockSectionGraphMenuItem = new JCheckBoxMenuItem("Lock Section Graphs"); lockSectionGraphMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { AbstractButton b = (AbstractButton) actionEvent.getSource(); doLockSectionGraph(b.getModel().isSelected()); } }); JMenuItem graphMenuItem = new JMenuItem("Graph..."); graphMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { doGraphDialog(); } }); this.propertyMenuItem = new JMenuItem("Properties..."); this.propertyMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { SectionImagePropertyDialog dialog = new SectionImagePropertyDialog(canvas); dialog.setProperties(selectedTrack, selectedTrackSection); dialog.pack(); dialog.setLocationRelativeTo(canvas); dialog.setVisible(true); dialog.dispose(); } }); splitMenuItem = new JMenuItem("Split..."); splitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { CorelyzerApp app = CorelyzerApp.getApp(); if (app != null) { app.getController().sectionSplit(); } } }); JMenuItem deleteItem = new JMenuItem("Delete..."); deleteItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { doDeleteSection(); } }); JMenuItem staggerSectionsItem = new JCheckBoxMenuItem("Stagger Sections", false); staggerSectionsItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { AbstractButton b = (AbstractButton) e.getSource(); doStaggerSections(b.getModel().isSelected()); } }); JMenuItem trimSectionsItem = new JMenuItem("Trim Sections..."); trimSectionsItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { doTrimSections(); } }); JMenuItem stackSectionsItem = new JMenuItem("Stack Sections"); stackSectionsItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { doStackSections(); } }); this.scenePopupMenu.addSeparator(); this.scenePopupMenu.add(lockSectionMenuItem); this.scenePopupMenu.add(lockSectionGraphMenuItem); this.scenePopupMenu.addSeparator(); this.scenePopupMenu.add(graphMenuItem); this.scenePopupMenu.add(splitMenuItem); this.scenePopupMenu.add(propertyMenuItem); this.scenePopupMenu.add(deleteItem); this.scenePopupMenu.add(staggerSectionsItem); this.scenePopupMenu.add(trimSectionsItem); this.scenePopupMenu.add(stackSectionsItem); CorelyzerApp.getApp().getPluginManager().addPluginPopupSubMenus(this.scenePopupMenu); }
From source file:org.yccheok.jstock.gui.JStock.java
public void createLookAndFeelMenuItems() { LookAndFeel currentlaf = UIManager.getLookAndFeel(); UIManager.LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels(); for (int i = 0; i < lafInfo.length; i++) { JMenuItem mi = (JRadioButtonMenuItem) jMenu4.add(new JRadioButtonMenuItem(lafInfo[i].getName())); buttonGroup1.add(mi);/*from ww w . j ava 2s . c o m*/ mi.addActionListener(new ChangeLookAndFeelAction(this, lafInfo[i].getClassName())); if (currentlaf != null) { if (lafInfo[i].getClassName().equals(currentlaf.getClass().getName())) { ((JRadioButtonMenuItem) mi).setSelected(true); } } } // Always on Top jMenu4.addSeparator(); this.alwaysOnTopMenuItem = jMenu4.add(new JCheckBoxMenuItem(GUIBundle.getString("MainFrame_AlwaysOnTop"))); this.alwaysOnTopMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { AbstractButton aButton = (AbstractButton) e.getSource(); boolean selected = aButton.getModel().isSelected(); JStock.this._setAlwaysOnTop(selected); } }); }