List of usage examples for javax.swing.event ChangeListener ChangeListener
ChangeListener
From source file:mergedoc.ui.MergeDocFrame.java
/** * ????//from ww w. ja v a2s.co m */ private void initListener() { // ? buttonBar.setRunListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { mergeExecutor.submit(new Runnable() { @Override public void run() { execute(); } }); } }); // ? buttonBar.setCancelListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { buttonBar.setEnabled(false); mergeManager.getWorkingState().cancel(); } }); // ? buttonBar.setBackListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { back(); } }); // ? buttonBar.setEndListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { end(); } }); // ?? mergeManager.setChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { WorkingState state = mergeManager.getWorkingState(); progressPanel.addListText(state.getWorkingText()); setTitle(progressPanel.getBarText()); } }); // ? addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { persistent(); } }); // ? addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { end(); } }); }
From source file:com.mirth.connect.client.ui.DashboardPanel.java
public DashboardPanel() { this.parent = PlatformUI.MIRTH_FRAME; haltableStates.add(DeployedState.DEPLOYING); haltableStates.add(DeployedState.UNDEPLOYING); haltableStates.add(DeployedState.STARTING); haltableStates.add(DeployedState.STOPPING); haltableStates.add(DeployedState.PAUSING); haltableStates.add(DeployedState.SYNCING); haltableStates.add(DeployedState.UNKNOWN); initComponents();/*from w w w. j a v a 2 s.c o m*/ initLayout(); loadTabPlugins(); ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource(); int index = sourceTabbedPane.getSelectedIndex(); if (LoadedExtensions.getInstance().getDashboardTabPlugins().size() > 0) { loadPanelPlugin(LoadedExtensions.getInstance().getDashboardTabPlugins() .get(sourceTabbedPane.getTitleAt(index))); } } }; tabPane.addChangeListener(changeListener); defaultVisibleColumns = new LinkedHashSet<String>(); makeStatusTable(); loadTablePlugins(); this.setDoubleBuffered(true); DashboardTreeTableModel model = (DashboardTreeTableModel) dashboardTable.getTreeTableModel(); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("channelGroupViewEnabled", true)) { tableModeGroupsButton.setSelected(true); tableModeGroupsButton.setContentFilled(true); tableModeChannelsButton.setContentFilled(false); model.setGroupModeEnabled(true); } else { tableModeChannelsButton.setSelected(true); tableModeChannelsButton.setContentFilled(true); tableModeGroupsButton.setContentFilled(false); model.setGroupModeEnabled(false); } }
From source file:edu.ku.brc.af.ui.forms.validation.ValComboBox.java
/** * Constructor with dbAdapter.//ww w. j a v a2s. c o m * @param dbAdapter the adaptor for enabling auto complete */ public ValComboBox(final PickListDBAdapterIFace adapter) { if (!adapter.isReadOnly()) { Java2sAutoComboBox cbx = new Java2sAutoComboBox(adapter.getList()); adapter.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (ValComboBox.this.comboBox instanceof Java2sAutoComboBox) { final Java2sAutoComboBox c = (Java2sAutoComboBox) ValComboBox.this.comboBox; if (SwingUtilities.isEventDispatchThread()) { c.setDataList(adapter.getList()); } else { SwingUtilities.invokeLater(new Runnable() { /* (non-Javadoc) * @see java.lang.Runnable#run() */ @Override public void run() { c.setDataList(adapter.getList()); } }); } } } }); comboBox = cbx; setControlSize(comboBox); cbx.setStrict(false); } else if (adapter instanceof ComboBoxModel) { comboBox = new ClearableComboBox((ComboBoxModel) adapter); setControlSize(comboBox); } else { String msg = "PickListDBAdapterIFace is not an instanceof ComboBoxModel and MUST BE!"; FormDevHelper.appendFormDevError(msg); } this.adapter = adapter; adapter.setAutoSaveOnAdd(false); init(!adapter.isReadOnly()); }
From source file:edu.ku.brc.specify.ui.SelectPrepsDlg.java
@Override public void createUI() { applyLabel = getResourceString("SELECTALL");//$NON-NLS-1$ super.createUI(); Vector<ColObjInfo> coList = new Vector<ColObjInfo>(coToPrepHash.values()); Collections.sort(coList, new Comparator<ColObjInfo>() { @Override/* w w w . ja v a2s . c o m*/ public int compare(ColObjInfo o1, ColObjInfo o2) { return o1.getCatNo().compareTo(o2.getCatNo()); } }); int cnt = 0; Vector<ColObjInfo> coFilteredList = new Vector<ColObjInfo>(); for (ColObjInfo colObjInfo : coList) { if (StringUtils.isNotEmpty(colObjInfo.getCatNo()) && colObjInfo.getPreps() != null && colObjInfo.getPreps().size() > 0) { coFilteredList.add(colObjInfo); cnt += colObjInfo.getPreps().size(); } } String rowDef = UIHelper.createDuplicateJGoodiesDef("p", "1px,p,4px", (cnt * 2) - 1) + ",10px,p"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ PanelBuilder pbuilder = new PanelBuilder(new FormLayout("f:p:g", rowDef)); //$NON-NLS-1$ CellConstraints cc = new CellConstraints(); ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent ae) { doEnableOKBtn(); } }; ChangeListener cl = new ChangeListener() { public void stateChanged(ChangeEvent ae) { doEnableOKBtn(); } }; DBTableInfo colObjTI = DBTableIdMgr.getInstance().getInfoById(CollectionObject.getClassTableId()); DBFieldInfo colObjFI = colObjTI.getFieldByColumnName("CatalogNumber"); int i = 0; int y = 1; for (ColObjInfo colObjInfo : coFilteredList) { if (i > 0) { pbuilder.addSeparator("", cc.xy(1, y)); //$NON-NLS-1$ } y += 2; colObjInfo.setCatNo((String) colObjFI.getFormatter().formatToUI(colObjInfo.getCatNo())); ColObjPanel panel = new ColObjPanel(this, colObjInfo); colObjPanels.add(panel); panel.addActionListener(al, cl); pbuilder.add(panel, cc.xy(1, y)); y += 2; i++; } applyBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { selectAllItems(); } }); JPanel tPanel = new JPanel(new BorderLayout()); summaryLabel = createLabel(""); //$NON-NLS-1$ tPanel.setBorder(BorderFactory.createEmptyBorder(5, 1, 5, 1)); tPanel.add(summaryLabel, BorderLayout.NORTH); JScrollPane sp = new JScrollPane(pbuilder.getPanel(), ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); tPanel.add(sp, BorderLayout.CENTER); contentPanel = tPanel; mainPanel.add(contentPanel, BorderLayout.CENTER); pack(); doEnableOKBtn(); Dimension size = getPreferredSize(); size.width += 20; size.height = size.height > 500 ? 500 : size.height; setSize(size); }
From source file:compecon.dashboard.panel.IndustriesPanel.java
public IndustriesPanel() { this.setLayout(new BorderLayout()); for (Currency currency : Currency.values()) { IndustriesPanelForCurrency panelForCurrency = new IndustriesPanelForCurrency(currency); jTabbedPaneCurrency.addTab(currency.getIso4217Code(), panelForCurrency); }//from w w w . java 2 s .c om jTabbedPaneCurrency.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (e.getSource() instanceof JTabbedPane) { JTabbedPane pane = (JTabbedPane) e.getSource(); IndustriesPanelForCurrency selectedComponent = (IndustriesPanelForCurrency) pane .getSelectedComponent(); selectedComponent.notifyListener(); } } }); add(jTabbedPaneCurrency, BorderLayout.CENTER); }
From source file:edu.ucla.stat.SOCR.applications.demo.BinomialTradingApplication.java
/** * This method initializes the application. *//*from w w w . j a v a2 s. co m*/ public void init() { tabbedPanelContainer = new JTabbedPane(); initJGraphPanel(); initGraphPanel2(); addTabbedPane(GRAPH, jgraphPanel); //addTabbedPane("GRAPH2", graphPanel2); tabbedPanelContainer.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) == GRAPH) { jgraphPanel.removeAll(); //setChart(); } /*else if( tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex())==GRAPH2) { // //setInputPanel(); }*/ } }); /* The following components need to be set * 1. Control JPanel * 1.a Floating-point Text-Field for So = Price of the stock at time zero, So>=0. * 1.b Floating-Point Text-Field for EP = Exercise price (it is exercised at the end if price of stock at the end > EP), EP>=0. * 1.c Integer Slider for t = Time until expiration in years, 0<=t<=365. * 1.d Floating-Point Text-Field for r = Interest rate per year (0.000<=r). * 1.e Floating Point Text-Field for sigma = Annual volatility (0.000<=sigma). * 1.f Integer Slider for n = Number of periods that we divide the time to expiration (0<=n<=1000). * * 2. Graph JPanel * 2.a For now, make this Graph panel just include a JTextArea where we will print out results * for debugging the calculator. Later, we'll replace this by a (Node, Edge)-Graph object * */ /*masterPanel = new JPanel(); masterPanel.setSize(new Dimension (500,500)); controlPanel.add(new JTextArea("Control Panel")); graphPanel.add(new JTextArea("Graph Panel")); vSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(controlPanel), new JScrollPane(graphPanel)); vSplitPane.setOneTouchExpandable(true); vSplitPane.setDividerLocation(150); //add(vSplitPane); // What should this be - how/where can we attach this pane to the main Panel? masterPanel.add(vSplitPane); masterPanel.validate(); getDisplayPane().removeAll(); getDisplayPane().add(masterPanel, BorderLayout.CENTER);*/ upContainer = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(leftPanel), new JScrollPane(tabbedPanelContainer)); this.getMainPanel().removeAll(); this.getMainPanel().add(new JScrollPane(upContainer), BorderLayout.CENTER); this.getMainPanel().validate(); //initGraph(); updateAllNodes(); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.FormPane.java
/** * Creates a Pane for editing a Workbench as a form. * @param workbenchPane the workbench pane to be parented into * @param workbench the workbench/*from w ww . j av a 2 s . c o m*/ */ public FormPane(final WorkbenchPaneSS workbenchPane, final Workbench workbench, final boolean readOnly) { setLayout(null); this.workbenchPane = workbenchPane; this.workbench = workbench; this.readOnly = readOnly; dropFlavors.add(InputPanel.INPUTPANEL_FLAVOR); docListener = new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { stateChange(); } }; changeListener = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { stateChange(); } }; buildUI(); scrollPane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); }
From source file:com.digitalgeneralists.assurance.ui.MainWindow.java
private void initializeComponent() { if (!this.initialized) { logger.info("Initializing the main window."); if (AssuranceUtils.getPlatform() == Platform.MAC) { System.setProperty("apple.laf.useScreenMenuBar", "true"); com.apple.eawt.Application macApplication = com.apple.eawt.Application.getApplication(); MacApplicationAdapter macAdapter = new MacApplicationAdapter(this); macApplication.addApplicationListener(macAdapter); macApplication.setEnabledPreferencesMenu(true); }/*from w w w .java 2s .com*/ this.setTitle(Application.applicationShortName); this.setDefaultCloseOperation(EXIT_ON_CLOSE); GridBagLayout gridbag = new GridBagLayout(); this.setLayout(gridbag); this.topArea = new JTabbedPane(); this.scanLaunchPanel.setPreferredSize(new Dimension(600, 150)); this.scanHistoryPanel.setPreferredSize(new Dimension(600, 150)); this.topArea.addTab("Scan", this.scanLaunchPanel); this.topArea.addTab("History", this.scanHistoryPanel); this.resultsPanel.setPreferredSize(new Dimension(600, 400)); this.topArea.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { resultsPanel.resetPanel(); // NOTE: This isn't ideal. It feels brittle. if (topArea.getSelectedIndex() == viewHistoryMenuItemIndex) { viewHistoryMenuItem.setSelected(true); } else { viewScanMenuItem.setSelected(true); } } }); GridBagConstraints topPanelConstraints = new GridBagConstraints(); topPanelConstraints.anchor = GridBagConstraints.NORTH; topPanelConstraints.fill = GridBagConstraints.BOTH; topPanelConstraints.gridx = 0; topPanelConstraints.gridy = 0; topPanelConstraints.weightx = 1.0; topPanelConstraints.weighty = 0.33; topPanelConstraints.gridheight = 1; topPanelConstraints.gridwidth = 1; topPanelConstraints.insets = new Insets(0, 0, 0, 0); this.getContentPane().add(this.topArea, topPanelConstraints); GridBagConstraints resultsPanelConstraints = new GridBagConstraints(); resultsPanelConstraints.anchor = GridBagConstraints.SOUTH; resultsPanelConstraints.fill = GridBagConstraints.BOTH; resultsPanelConstraints.gridx = 0; resultsPanelConstraints.gridy = 1; resultsPanelConstraints.weightx = 1.0; resultsPanelConstraints.weighty = 0.67; resultsPanelConstraints.gridheight = 1; resultsPanelConstraints.gridwidth = 1; resultsPanelConstraints.insets = new Insets(0, 0, 0, 0); this.getContentPane().add(this.resultsPanel, resultsPanelConstraints); this.applicationDelegate.addEventObserver(ScanStartedEvent.class, this); this.applicationDelegate.addEventObserver(ScanCompletedEvent.class, this); this.applicationDelegate.addEventObserver(SetScanDefinitionMenuStateEvent.class, this); this.applicationDelegate.addEventObserver(SetScanResultsMenuStateEvent.class, this); this.applicationDelegate.addEventObserver(ApplicationConfigurationLoadedEvent.class, this); JMenu menu; JMenuItem menuItem; menuBar = new JMenuBar(); StringBuilder accessiblityLabel = new StringBuilder(128); if (AssuranceUtils.getPlatform() != Platform.MAC) { menu = new JMenu(Application.applicationShortName); menu.getAccessibleContext().setAccessibleDescription(accessiblityLabel.append("Actions for ") .append(Application.applicationShortName).append(" application").toString()); accessiblityLabel.setLength(0); menuBar.add(menu); menuItem = new JMenuItem(MainWindow.quitApplicationMenuLabel, KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription(accessiblityLabel.append("Close the ") .append(Application.applicationShortName).append(" application").toString()); accessiblityLabel.setLength(0); menuItem.addActionListener(this); menuItem.setActionCommand(AssuranceActions.quitApplicationAction); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(MainWindow.aboutApplicationMenuLabel); menuItem.getAccessibleContext().setAccessibleDescription( accessiblityLabel.append("Display information about this version of ") .append(Application.applicationShortName).append(".").toString()); accessiblityLabel.setLength(0); menuItem.addActionListener(this); menuItem.setActionCommand(AssuranceActions.aboutApplicationAction); menu.add(menuItem); } menu = new JMenu("Scan"); menu.setMnemonic(KeyEvent.VK_S); menu.getAccessibleContext().setAccessibleDescription("Actions for file scans"); menuBar.add(menu); menuItem = new JMenuItem(MainWindow.newScanDefinitonMenuLabel, KeyEvent.VK_N); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Create a new scan definition"); menuItem.addActionListener(this.scanLaunchPanel); menuItem.setActionCommand(AssuranceActions.newScanDefinitonAction); menu.add(menuItem); menuItem = new JMenuItem(MainWindow.deleteScanDefinitonMenuLabel, KeyEvent.VK_D); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("Delete the selected scan definition"); menuItem.addActionListener(this.scanLaunchPanel); menuItem.setActionCommand(AssuranceActions.deleteScanDefinitonAction); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(MainWindow.scanMenuLabel, KeyEvent.VK_S); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext() .setAccessibleDescription("Launch a scan using the selected scan definition"); menuItem.addActionListener(this.scanLaunchPanel); menuItem.setActionCommand(AssuranceActions.scanAction); menu.add(menuItem); menuItem = new JMenuItem(MainWindow.scanAndMergeMenuLabel, KeyEvent.VK_M); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext().setAccessibleDescription( "Launch a scan using the selected scan definition and merge the results"); menuItem.addActionListener(this.scanLaunchPanel); menuItem.setActionCommand(AssuranceActions.scanAndMergeAction); menu.add(menuItem); menu = new JMenu("Results"); menu.setMnemonic(KeyEvent.VK_R); menu.getAccessibleContext().setAccessibleDescription("Actions for scan results"); menuBar.add(menu); menuItem = new JMenuItem(MainWindow.replaceSourceMenuLabel, KeyEvent.VK_O); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext() .setAccessibleDescription("Replace the source file with the target file"); menuItem.addActionListener(this.resultsPanel.getResultMenuListener()); menuItem.setActionCommand(AssuranceActions.replaceSourceAction); menu.add(menuItem); menuItem = new JMenuItem(MainWindow.replaceTargetMenuLabel, KeyEvent.VK_T); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext() .setAccessibleDescription("Replace the target file with the source file"); menuItem.addActionListener(this.resultsPanel.getResultMenuListener()); menuItem.setActionCommand(AssuranceActions.replaceTargetAction); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(MainWindow.sourceAttributesMenuLabel); menuItem.getAccessibleContext().setAccessibleDescription("View the source file attributes"); menuItem.addActionListener(this.resultsPanel.getResultMenuListener()); menuItem.setActionCommand(AssuranceActions.sourceAttributesAction); menu.add(menuItem); menuItem = new JMenuItem(MainWindow.targetAttributesMenuLabel); menuItem.getAccessibleContext().setAccessibleDescription("View the target file attributes"); menuItem.addActionListener(this.resultsPanel.getResultMenuListener()); menuItem.setActionCommand(AssuranceActions.targetAttributesAction); menu.add(menuItem); menu = new JMenu("View"); menu.setMnemonic(KeyEvent.VK_V); menu.getAccessibleContext().setAccessibleDescription( accessiblityLabel.append("Views within ").append(Application.applicationShortName).toString()); accessiblityLabel.setLength(0); menuBar.add(menu); ButtonGroup group = new ButtonGroup(); this.viewScanMenuItem = new JRadioButtonMenuItem(MainWindow.viewScanMenuLabel); this.viewScanMenuItem.addActionListener(this); this.viewScanMenuItem.setActionCommand(AssuranceActions.viewScanAction); this.viewScanMenuItem.setSelected(true); group.add(this.viewScanMenuItem); menu.add(this.viewScanMenuItem); this.viewHistoryMenuItem = new JRadioButtonMenuItem(MainWindow.viewHistoryMenuLabel); this.viewHistoryMenuItem.addActionListener(this); this.viewHistoryMenuItem.setActionCommand(AssuranceActions.viewHistoryAction); this.viewHistoryMenuItem.setSelected(true); group.add(this.viewHistoryMenuItem); menu.add(this.viewHistoryMenuItem); if (AssuranceUtils.getPlatform() != Platform.MAC) { menu = new JMenu("Tools"); menu.getAccessibleContext() .setAccessibleDescription(accessiblityLabel.append("Additional actions for ") .append(Application.applicationShortName).append(" application").toString()); accessiblityLabel.setLength(0); menuBar.add(menu); menuItem = new JMenuItem(MainWindow.settingsMenuLabel, KeyEvent.VK_COMMA); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, ActionEvent.CTRL_MASK)); menuItem.getAccessibleContext() .setAccessibleDescription(accessiblityLabel.append("Change settings for the ") .append(Application.applicationShortName).append(" application").toString()); accessiblityLabel.setLength(0); menuItem.addActionListener(this); menuItem.setActionCommand(AssuranceActions.displaySettingsAction); menu.add(menuItem); } this.setJMenuBar(menuBar); this.initialized = true; } }
From source file:edu.uci.ics.jung.samples.PerspectiveTransformerDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom and perspective features. * //from w ww . j a v a2 s . co m */ @SuppressWarnings("serial") public PerspectiveTransformerDemo() { // create a simple graph for the demo graph = TestGraphs.getOneComponentGraph(); graphLayout = new FRLayout<String, Number>(graph); ((FRLayout<String, Number>) graphLayout).setMaxIterations(1000); Dimension preferredSize = new Dimension(600, 600); Map<String, Point2D> map = new HashMap<String, Point2D>(); Transformer<String, Point2D> vlf = TransformerUtils.mapTransformer(map); grid = this.generateVertexGrid(map, preferredSize, 25); gridLayout = new StaticLayout<String, Number>(grid, vlf, preferredSize); final VisualizationModel<String, Number> visualizationModel = new DefaultVisualizationModel<String, Number>( graphLayout, preferredSize); vv = new VisualizationViewer<String, Number>(visualizationModel, preferredSize); PickedState<Number> pes = vv.getPickedEdgeState(); vv.getRenderContext() .setEdgeDrawPaintTransformer(new PickableEdgePaintTransformer<Number>(pes, Color.black, Color.red)); vv.getRenderContext().setVertexShapeTransformer(new Transformer<String, Shape>() { public Shape transform(String v) { return new Rectangle2D.Float(-10, -10, 20, 20); } }); vv.setBackground(Color.white); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<String>()); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse<Number, Number> graphMouse = new DefaultModalGraphMouse<Number, Number>(); vv.setGraphMouse(graphMouse); viewSupport = new PerspectiveViewTransformSupport<String, Number>(vv); layoutSupport = new PerspectiveLayoutTransformSupport<String, Number>(vv); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 0.9f, vv.getCenter()); } }); final JSlider horizontalSlider = new JSlider(-120, 120, 0) { /* (non-Javadoc) * @see javax.swing.JComponent#getPreferredSize() */ @Override public Dimension getPreferredSize() { return new Dimension(80, super.getPreferredSize().height); } }; final JSlider verticalSlider = new JSlider(-120, 120, 0) { /* (non-Javadoc) * @see javax.swing.JComponent#getPreferredSize() */ @Override public Dimension getPreferredSize() { return new Dimension(super.getPreferredSize().width, 80); } }; verticalSlider.setOrientation(JSlider.VERTICAL); final ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent e) { int vval = -verticalSlider.getValue(); int hval = horizontalSlider.getValue(); Dimension d = vv.getSize(); PerspectiveTransform pt = null; pt = PerspectiveTransform.getQuadToQuad(vval, hval, d.width - vval, -hval, d.width + vval, d.height + hval, -vval, d.height - hval, 0, 0, d.width, 0, d.width, d.height, 0, d.height); viewSupport.getPerspectiveTransformer().setPerspectiveTransform(pt); layoutSupport.getPerspectiveTransformer().setPerspectiveTransform(pt); vv.repaint(); } }; horizontalSlider.addChangeListener(changeListener); verticalSlider.addChangeListener(changeListener); JPanel perspectivePanel = new JPanel(new BorderLayout()); JPanel perspectiveCenterPanel = new JPanel(new BorderLayout()); perspectivePanel.setBorder(BorderFactory.createTitledBorder("Perspective Controls")); final JButton center = new JButton("Center"); center.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { horizontalSlider.setValue(0); verticalSlider.setValue(0); } }); ButtonGroup radio = new ButtonGroup(); JRadioButton normal = new JRadioButton("None"); normal.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { boolean selected = e.getStateChange() == ItemEvent.SELECTED; if (selected) { if (viewSupport != null) { viewSupport.deactivate(); } if (layoutSupport != null) { layoutSupport.deactivate(); } } center.setEnabled(!selected); horizontalSlider.setEnabled(!selected); verticalSlider.setEnabled(!selected); } }); final JRadioButton perspectiveView = new JRadioButton("In View"); perspectiveView.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { viewSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); final JRadioButton perspectiveModel = new JRadioButton("In Layout"); perspectiveModel.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { layoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); radio.add(normal); radio.add(perspectiveModel); radio.add(perspectiveView); normal.setSelected(true); ButtonGroup graphRadio = new ButtonGroup(); JRadioButton graphButton = new JRadioButton("Graph"); graphButton.setSelected(true); graphButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { visualizationModel.setGraphLayout(graphLayout); vv.repaint(); } } }); JRadioButton gridButton = new JRadioButton("Grid"); gridButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { visualizationModel.setGraphLayout(gridLayout); vv.repaint(); } } }); graphRadio.add(graphButton); graphRadio.add(gridButton); JPanel modePanel = new JPanel(new GridLayout(2, 1)); modePanel.setBorder(BorderFactory.createTitledBorder("Display")); modePanel.add(graphButton); modePanel.add(gridButton); JMenuBar menubar = new JMenuBar(); menubar.add(graphMouse.getModeMenu()); gzsp.setCorner(menubar); Container controls = new JPanel(new BorderLayout()); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel perspectiveControls = new JPanel(new GridLayout(3, 1)); zoomControls.add(plus); zoomControls.add(minus); perspectiveControls.add(normal); perspectiveControls.add(perspectiveModel); perspectiveControls.add(perspectiveView); controls.add(zoomControls, BorderLayout.WEST); controls.add(modePanel); perspectivePanel.add(perspectiveControls, BorderLayout.WEST); perspectiveCenterPanel.add(horizontalSlider, BorderLayout.SOUTH); perspectivePanel.add(verticalSlider, BorderLayout.EAST); perspectiveCenterPanel.add(center); perspectivePanel.add(perspectiveCenterPanel); controls.add(perspectivePanel, BorderLayout.EAST); content.add(controls, BorderLayout.SOUTH); }
From source file:SoundPlayer.java
public SoundPlayer(File f, boolean isMidi) throws IOException, UnsupportedAudioFileException, LineUnavailableException, MidiUnavailableException, InvalidMidiDataException { if (isMidi) { // The file is a MIDI file midi = true;//w ww .j a va 2 s. c om // First, get a Sequencer to play sequences of MIDI events // That is, to send events to a Synthesizer at the right time. sequencer = MidiSystem.getSequencer(); // Used to play sequences sequencer.open(); // Turn it on. // Get a Synthesizer for the Sequencer to send notes to Synthesizer synth = MidiSystem.getSynthesizer(); synth.open(); // acquire whatever resources it needs // The Sequencer obtained above may be connected to a Synthesizer // by default, or it may not. Therefore, we explicitly connect it. Transmitter transmitter = sequencer.getTransmitter(); Receiver receiver = synth.getReceiver(); transmitter.setReceiver(receiver); // Read the sequence from the file and tell the sequencer about it sequence = MidiSystem.getSequence(f); sequencer.setSequence(sequence); audioLength = (int) sequence.getTickLength(); // Get sequence length } else { // The file is sampled audio midi = false; // Getting a Clip object for a file of sampled audio data is kind // of cumbersome. The following lines do what we need. AudioInputStream ain = AudioSystem.getAudioInputStream(f); try { DataLine.Info info = new DataLine.Info(Clip.class, ain.getFormat()); clip = (Clip) AudioSystem.getLine(info); clip.open(ain); } finally { // We're done with the input stream. ain.close(); } // Get the clip length in microseconds and convert to milliseconds audioLength = (int) (clip.getMicrosecondLength() / 1000); } // Now create the basic GUI play = new JButton("Play"); // Play/stop button progress = new JSlider(0, audioLength, 0); // Shows position in sound time = new JLabel("0"); // Shows position as a # // When clicked, start or stop playing the sound play.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (playing) stop(); else play(); } }); // Whenever the slider value changes, first update the time label. // Next, if we're not already at the new position, skip to it. progress.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { int value = progress.getValue(); // Update the time label if (midi) time.setText(value + ""); else time.setText(value / 1000 + "." + (value % 1000) / 100); // If we're not already there, skip there. if (value != audioPosition) skip(value); } }); // This timer calls the tick() method 10 times a second to keep // our slider in sync with the music. timer = new javax.swing.Timer(100, new ActionListener() { public void actionPerformed(ActionEvent e) { tick(); } }); // put those controls in a row Box row = Box.createHorizontalBox(); row.add(play); row.add(progress); row.add(time); // And add them to this component. setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); this.add(row); // Now add additional controls based on the type of the sound if (midi) addMidiControls(); else addSampledControls(); }