List of usage examples for java.awt.event MouseAdapter MouseAdapter
MouseAdapter
From source file:ucar.unidata.idv.flythrough.Flythrough.java
/** * _more_/*from w ww. j a v a 2 s .c om*/ * * @return _more_ */ public JComponent doMakeDashboardPanel() { dashboardImage = GuiUtils.getImage("/auxdata/ui/icons/cockpit.gif", getClass(), false); pipPanel = new PipPanel(viewManager); pipPanel.getNavigatedPanel().setBorder(null); pipPanel.setPreferredSize(new Dimension(100, 100)); pipPanel.doLayout(); pipPanel.validate(); pipFrame = new JFrame("Show remain invisible"); pipFrame.setContentPane(pipPanel); pipFrame.pack(); dashboardLbl = new JLabel(new ImageIcon(dashboardImage)) { public void paint(Graphics g) { // readPts(); paintDashboardBackground(g, dashboardLbl); super.paint(g); paintDashboardAfter(g, dashboardLbl); } }; dashboardLbl.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { pipPanel.keyPressedInMap(e); updateDashboard(); } }); dashboardLbl.setVerticalAlignment(SwingConstants.BOTTOM); MouseAdapter mouseAdapter = new MouseAdapter() { Point mouseStart = new Point(0, 0); Point originalOffset = new Point(0, 0); public void mouseClicked(MouseEvent me) { if (pipRect == null) { return; } if (goToClick && pipRect.contains(new Point(me.getX(), me.getY()))) { try { int x = me.getX() - pipRect.x; int y = me.getY() - pipRect.y; // System.err.println ("x:" + x +" y:" + y); LatLonPoint llp = pipPanel.screenToLatLon(x, y); location = makePoint(llp.getLatitude(), llp.getLongitude(), 0); doDrive(false, heading); } catch (Exception exc) { logException("Driving", exc); } } } public void mousePressed(MouseEvent me) { dashboardLbl.requestFocus(); originalOffset = new Point(dashboardImageOffset); mouseStart.x = me.getX(); mouseStart.y = me.getY(); Rectangle b = dashboardLbl.getBounds(); int w = dashboardImage.getWidth(null); int h = dashboardImage.getHeight(null); Point ul = new Point(b.width / 2 - w / 2, b.height - h); // System.out.println("{" + (me.getX()-ul.x) +", " + (me.getY()-ul.y)+"}"); } public void mouseDragged(MouseEvent me) { dashboardImageOffset.x = originalOffset.x + me.getX() - mouseStart.x; dashboardImageOffset.y = originalOffset.y + me.getY() - mouseStart.y; updateDashboard(); } }; dashboardLbl.addMouseListener(mouseAdapter); dashboardLbl.addMouseMotionListener(mouseAdapter); //Create ome charts to force classloading (which takes some time) in a thread //So the gui shows quicker Misc.run(new Runnable() { public void run() { try { MeterPlot plot = new MeterPlot(new DefaultValueDataset(new Double(1))); createChart(new XYSeriesCollection()); } catch (Exception ignore) { } } }); return dashboardLbl; }
From source file:de.codesourcery.jasm16.ide.ui.views.SourceEditorView.java
protected JPanel createPanel() { // button panel final JToolBar toolbar = new JToolBar(); toolbar.setLayout(new GridBagLayout()); setColors(toolbar);//from w w w . j a v a 2 s . c om final JButton showASTButton = new JButton("Show AST"); setColors(showASTButton); showASTButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final boolean currentlyVisible = isASTInspectorVisible(); if (currentlyVisible) { showASTButton.setText("Show AST"); } else { showASTButton.setText("Hide AST"); } if (currentlyVisible) { astInspector.setVisible(false); } else { showASTInspector(); } } }); GridBagConstraints cnstrs = constraints(0, 0, false, true, GridBagConstraints.NONE); toolbar.add(showASTButton, cnstrs); // navigation history back button cnstrs = constraints(1, 0, false, true, GridBagConstraints.NONE); toolbar.add(navigationHistoryBack, cnstrs); navigationHistoryBack.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { navigationHistoryBack(); } }); navigationHistoryBack.setEnabled(false); // navigation history forward button cnstrs = constraints(2, 0, true, true, GridBagConstraints.NONE); toolbar.add(navigationHistoryForward, cnstrs); navigationHistoryForward.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { navigationHistoryForward(); } }); navigationHistoryForward.setEnabled(false); // create status area statusArea.setPreferredSize(new Dimension(400, 100)); statusArea.setModel(statusModel); setColors(statusArea); /** * TOOLBAR * SOURCE * cursor position * status area */ final JPanel topPanel = new JPanel(); topPanel.setLayout(new GridBagLayout()); cnstrs = constraints(0, 0, GridBagConstraints.HORIZONTAL); cnstrs.gridwidth = GridBagConstraints.REMAINDER; cnstrs.weighty = 0; topPanel.add(toolbar, cnstrs); cnstrs = constraints(0, 1, GridBagConstraints.BOTH); cnstrs.gridwidth = GridBagConstraints.REMAINDER; cnstrs.weighty = 1.0; topPanel.add(super.getPanel(), cnstrs); final JPanel bottomPanel = new JPanel(); bottomPanel.setLayout(new GridBagLayout()); statusArea.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); statusArea.addMouseListener(new MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { final int viewRow = statusArea.rowAtPoint(e.getPoint()); if (viewRow != -1) { final int modelRow = statusArea.convertRowIndexToModel(viewRow); StatusMessage message = statusModel.getMessage(modelRow); if (message.getLocation() != null) { moveCursorTo(message.getLocation(), true); } } } }; }); EditorContainer.addEditorCloseKeyListener(statusArea, this); statusArea.setFillsViewportHeight(true); statusArea.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); final JScrollPane statusPane = new JScrollPane(statusArea); setColors(statusPane); statusPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); statusPane.setPreferredSize(new Dimension(400, 100)); statusPane.setMinimumSize(new Dimension(100, 20)); cnstrs = constraints(0, 0, GridBagConstraints.BOTH); cnstrs.weightx = 1; cnstrs.weighty = 1; cnstrs.gridwidth = GridBagConstraints.REMAINDER; cnstrs.gridheight = GridBagConstraints.REMAINDER; bottomPanel.add(statusPane, cnstrs); // setup result panel final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, bottomPanel); setColors(splitPane); final JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); setColors(panel); cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH); panel.add(splitPane, cnstrs); final AncestorListener l = new AncestorListener() { @Override public void ancestorRemoved(AncestorEvent event) { } @Override public void ancestorMoved(AncestorEvent event) { } @Override public void ancestorAdded(AncestorEvent event) { splitPane.setDividerLocation(0.8d); } }; panel.addAncestorListener(l); return panel; }
From source file:com.diversityarrays.kdxplore.curate.TrialDataEditor.java
public TrialDataEditor(CurationData cd, WindowOpener<JFrame> windowOpener, MessageLogger messageLogger, KdxploreDatabase kdxdb, IntFunction<Trait> traitProvider, SampleType[] sampleTypes) throws IOException { super(new BorderLayout()); this.traitProvider = traitProvider; this.windowOpener = windowOpener; this.curationData = cd; this.curationData.setChangeManager(changeManager); this.curationData.setKDSmartDatabase(kdxdb.getKDXploreKSmartDatabase()); inactiveTagFilterIcon = KDClientUtils.getIcon(ImageId.TAG_FILTER_24); activeTagFilterIcon = KDClientUtils.getIcon(ImageId.TAG_FILTER_ACTIVE_24); inactivePlotOrSpecimenFilterIcon = KDClientUtils.getIcon(ImageId.FILTER_PLOT_SPEC_INACTIVE); activePlotFilterIcon = KDClientUtils.getIcon(ImageId.FILTER_PLOT_ACTIVE); activeSpecimenFilterIcon = KDClientUtils.getIcon(ImageId.FILTER_SPEC_ACTIVE); updatePlotSpecimenIcon();// w w w .j a va 2 s .com TraitColorProvider traitColourProvider = new TraitColorProvider(false); this.curationData.setTraitColorProvider(traitColourProvider); curationData.addCurationDataChangeListener(new CurationDataChangeListener() { @Override public void plotActivationChanged(Object source, boolean activated, List<Plot> plots) { updateRowFilter(); if (toolController != null) { toolController.plotActivationsChanged(activated, plots); } } @Override public void editedSamplesChanged(Object source, List<CurationCellId> curationCellIds) { if (toolController != null) { toolController.editedSamplesChanged(); } } }); this.selectedValueStore = new SelectedValueStore(curationData.getTrial().getTrialName()); this.messageLogger = messageLogger; smallFont = KDClientUtils.makeSmallFont(this); // undockViewAction.putValue(Action.SHORT_DESCRIPTION, "Click to undock // this view"); KDClientUtils.initAction(ImageId.HELP_24, curationHelpAction, Msg.TOOLTIP_HELP_DATA_CURATION(), false); KDClientUtils.initAction(ImageId.SAVE_24, saveChangesAction, Msg.TOOLTIP_SAVE_CHANGES(), true); KDClientUtils.initAction(ImageId.EXPORT_24, exportCuratedData, Msg.TOOLTIP_EXPORT(), true); KDClientUtils.initAction(ImageId.UNDO_24, undoAction, Msg.TOOLTIP_UNDO(), true); KDClientUtils.initAction(ImageId.REDO_24, redoAction, Msg.TOOLTIP_REDO(), true); KDClientUtils.initAction(ImageId.FIELD_VIEW_24, showFieldViewAction, Msg.TOOLTIP_FIELD_VIEW(), false); KDClientUtils.initAction(ImageId.GET_TRIALINFO_24, importCuratedData, Msg.TOOLTIP_IMPORT_DATA(), true); Function<TraitInstance, List<KdxSample>> sampleProvider = new Function<TraitInstance, List<KdxSample>>() { @Override public List<KdxSample> apply(TraitInstance ti) { return curationData.getSampleMeasurements(ti); } }; tivrByTi = VisToolUtil.buildTraitInstanceValueRetrieverMap(curationData.getTrial(), curationData.getTraitInstances(), sampleProvider); // = = = = = = = = boolean readOnly = false; // FIXME work out if the Trial can be edited or not curationTableModel = new CurationTableModel(curationData, readOnly); // See FIXME comment in CurationTableModel.isReadOnly() curationTableSelectionModel = new CurationTableSelectionModelImpl(selectedValueStore, curationTableModel); curationTableSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); curationTable = new CurationTable("CurationTable-" + (++UNIQUE_CURATION_TABLE_ID), //$NON-NLS-1$ curationTableModel, curationTableSelectionModel); curationTable.setCellSelectionEnabled(true); curationTable.setAutoCreateRowSorter(true); // = = = = = = = = this.sampleSourcesTablePanel = new SampleSourcesTablePanel(curationData, curationTableModel, handler); @SuppressWarnings("unchecked") TableRowSorter<CurationTableModel> rowSorter = (TableRowSorter<CurationTableModel>) curationTable .getRowSorter(); rowSorter.setSortsOnUpdates(true); rowSorter.addRowSorterListener(rowSorterListener); curationCellRenderer = new CurationTableCellRenderer(curationTableModel, colorProviderFactory, curationTableSelectionModel); curationTable.setDefaultRenderer(Object.class, curationCellRenderer); curationTable.setDefaultRenderer(Integer.class, curationCellRenderer); curationTable.setDefaultRenderer(String.class, curationCellRenderer); curationTable.setDefaultRenderer(CurationCellValue.class, curationCellRenderer); curationTable.setDefaultRenderer(Double.class, curationCellRenderer); curationTable.setDefaultRenderer(TraitValue.class, curationCellRenderer); // If either the rows selected change or the columns selected change // then we // need to inform the visualisation tools. curationTable.getSelectionModel().addListSelectionListener(curationTableCellSelectionListener); curationTable.getColumnModel().addColumnModelListener(curationTableCellSelectionListener); fieldLayoutView = new InterceptFieldLayoutView(); this.curationCellEditor = new CurationCellEditorImpl(curationTableModel, fieldLayoutView, curationData, refreshFieldLayoutView, kdxdb, traitProvider, sampleTypes); SuppressionInfoProvider suppressionInfoProvider = new SuppressionInfoProvider(curationData, curationTableModel, curationTable); suppressionHandler = new SuppressionHandler(curationContext, curationData, curationCellEditor, suppressionInfoProvider); loadVisualisationTools(); curationMenuProvider = new CurationMenuProvider(curationContext, curationData, messages, visualisationTools, suppressionHandler); curationMenuProvider.setSuppressionInfoProvider(suppressionInfoProvider); fieldLayoutView.addTraitInstanceSelectionListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (ItemEvent.SELECTED == e.getStateChange()) { TraitInstance traitInstance = fieldLayoutView.getActiveTraitInstance(true); if (traitInstance == null) { curationCellEditor.setCurationCellValue(null); } else { // startEdit(HowStarted.FIELD_VIEW_CHANGED_ACTIVE_TRAIT_INSTANCE); } fieldLayoutView.updateSamplesSelectedInTable(); } } }); // = = = = = = = curationData.addUnsavedChangesListener(new UnsavedChangesListener() { @Override public void unsavedChangesExist(Object source, int nChanges) { int unsavedCount = curationData.getUnsavedChangesCount(); saveChangesAction.setEnabled(unsavedCount > 0); if (unsavedCount > 0) { statusInfoLine.setMessage("Unsaved changes: " + unsavedCount); } else { statusInfoLine.setMessage("No Unsaved changes"); } } }); // curationData.addEditedSampleChangeListener(new ChangeListener() { // @Override // public void stateChanged(ChangeEvent e) { // handleEditedSampleChanges(); // } // }); saveChangesAction.setEnabled(false); changeManager.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { updateUndoRedoActions(); } }); undoAction.setEnabled(false); redoAction.setEnabled(false); // = = = = = = = = // TODO provide one of these for each relevant device type DeviceType deviceTypeForSamples = null; StatsData statsData = curationData.getStatsData(deviceTypeForSamples); TIStatsTableModel statsTableModel = new TIStatsTableModel2(curationData, statsData, deviceTypeForSamples); traitColourProvider.generateColorMap(statsData.getTraitInstancesWithData()); Set<Integer> instanceNumbers = statsData.getInstanceNumbers(); String nonHtmlLabel; if (instanceNumbers.size() > 1) { tAndIpanelLabel = "<HTML><i>Plot Info</i> & Trait Instances"; nonHtmlLabel = "Plot Info & Trait Instances"; } else { tAndIpanelLabel = "<HTML><i>Plot Info</i> & Traits"; nonHtmlLabel = "Plot Info & Traits"; } traitsAndInstancesPanel = new TraitsAndInstancesPanel2(curationContext, smallFont, statsTableModel, instanceNumbers.size() > 1, statsData.getInvalidRuleCount(), nonHtmlLabel, curationMenuProvider, outlierConsumer); traitsAndInstancesPanel.addTraitInstanceStatsItemListener(new ItemListener() { boolean busy; @Override public void itemStateChanged(ItemEvent e) { // NOTE: we want to process both SELECTED and DESELECTED // variants if (busy) { Shared.Log.d(TAG, "***** LOOPED in traitsAndInstancesPanel.ItemListener"); //$NON-NLS-1$ } else { Shared.Log.d(TAG, "traitsAndInstancesPanel.ItemListener BEGIN"); //$NON-NLS-1$ busy = true; try { updateViewedTraitInstances(e); // !!!!! } finally { busy = false; Shared.Log.d(TAG, "traitsAndInstancesPanel.ItemListener END\n"); //$NON-NLS-1$ } } } }); // = = = = = = = = plotCellChoicesPanel = new PlotCellChoicesPanel(curationContext, curationData, deviceTypeForSamples, tAndIpanelLabel, curationMenuProvider, colorProviderFactory); // plotCellChoicesPanel.setData( // curationData.getPlotAttributes(), // traitsAndInstancesPanel.getTraitInstancesWithData()); plotCellChoicesPanel.addPlotCellChoicesListener(new PlotCellChoicesListener() { @Override public void traitInstanceChoicesChanged(Object source, boolean choiceAdded, TraitInstance[] choice, Map<Integer, Set<TraitInstance>> traitInstancesByTraitId) { traitsAndInstancesPanel.changeTraitInstanceChoice(choiceAdded, choice); } @Override public void plotAttributeChoicesChanged(Object source, List<ValueRetriever<?>> vrList) { curationTableModel.setSelectedPlotAttributes(vrList); } }); // = = = = = = = = statsAndSamplesSplit = createStatsAndSamplesTable(traitsAndInstancesPanel.getComponent()); mainTabbedPane.addTab(TAB_SAMPLES, samplesTableIcon, statsAndSamplesSplit, Msg.TOOLTIP_SAMPLES_TABLE()); // = = = = = = = = checkForInvalidTraits(); leftSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, createCurationCellEditorComponent(), plotCellChoicesPanel); leftSplit.setResizeWeight(0.5); // traitToDoTaskPaneContainer); // rightSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, // traitsAndInstancesPanel, fieldViewAndPlots); // rightSplit.setResizeWeight(0.5); // rightSplit.setOneTouchExpandable(true); leftAndRightSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftSplit, mainTabbedPane); leftAndRightSplit.setOneTouchExpandable(true); mainVerticalSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, messages, leftAndRightSplit); mainVerticalSplit.setOneTouchExpandable(true); mainVerticalSplit.setResizeWeight(0.0); add(statusInfoLine, BorderLayout.NORTH); add(mainVerticalSplit, BorderLayout.CENTER); fieldLayoutView.addCellSelectionListener(fieldViewCellSelectionListener); curationTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { if (SwingUtilities.isRightMouseButton(me) && 1 == me.getClickCount()) { me.consume(); displayPopupMenu(me); } } }); }
From source file:net.rptools.maptool.client.ui.MapToolFrame.java
private JComponent createDrawTreePanel() { final JTree tree = new JTree(); drawablesPanel = new DrawablesPanel(); drawPanelTreeModel = new DrawPanelTreeModel(tree); tree.setModel(drawPanelTreeModel);//from w w w . ja v a2s . com tree.setCellRenderer(new DrawPanelTreeCellRenderer()); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setContinuousLayout(true); splitPane.setTopComponent(new JScrollPane(tree)); splitPane.setBottomComponent(drawablesPanel); splitPane.setDividerLocation(100); // Add mouse Event for right click menu tree.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } Object row = path.getLastPathComponent(); int rowIndex = tree.getRowForLocation(e.getX(), e.getY()); if (SwingUtilities.isLeftMouseButton(e)) { if (!SwingUtil.isShiftDown(e) && !SwingUtil.isControlDown(e)) { tree.clearSelection(); } tree.addSelectionInterval(rowIndex, rowIndex); if (row instanceof DrawnElement) { if (e.getClickCount() == 2) { DrawnElement de = (DrawnElement) row; getCurrentZoneRenderer() .centerOn(new ZonePoint((int) de.getDrawable().getBounds().getCenterX(), (int) de.getDrawable().getBounds().getCenterY())); } } int[] treeRows = tree.getSelectionRows(); java.util.Arrays.sort(treeRows); drawablesPanel.clearSelectedIds(); for (int i = 0; i < treeRows.length; i++) { TreePath p = tree.getPathForRow(treeRows[i]); if (p.getLastPathComponent() instanceof DrawnElement) { DrawnElement de = (DrawnElement) p.getLastPathComponent(); drawablesPanel.addSelectedId(de.getDrawable().getId()); } } } if (SwingUtilities.isRightMouseButton(e)) { if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) { tree.clearSelection(); tree.addSelectionInterval(rowIndex, rowIndex); drawablesPanel.clearSelectedIds(); } final int x = e.getX(); final int y = e.getY(); EventQueue.invokeLater(new Runnable() { public void run() { DrawnElement firstElement = null; Set<GUID> selectedDrawSet = new HashSet<GUID>(); for (TreePath path : tree.getSelectionPaths()) { if (path.getLastPathComponent() instanceof DrawnElement) { DrawnElement de = (DrawnElement) path.getLastPathComponent(); if (firstElement == null) { firstElement = de; } selectedDrawSet.add(de.getDrawable().getId()); } } if (!selectedDrawSet.isEmpty()) { try { new DrawPanelPopupMenu(selectedDrawSet, x, y, getCurrentZoneRenderer(), firstElement).showPopup(tree); } catch (IllegalComponentStateException icse) { log.info(tree.toString(), icse); } } } }); } } }); // Add Zone Change event MapTool.getEventDispatcher().addListener(new AppEventListener() { public void handleAppEvent(AppEvent event) { drawPanelTreeModel.setZone((Zone) event.getNewValue()); } }, MapTool.ZoneEvent.Activated); return splitPane; }
From source file:info.puzz.trackprofiler.gui.TrackProfilerFrame.java
private JTable getTrackTable() { if (trackTable == null) { trackTable = new JTable(); trackTable.setModel(new TrackTableModel(this)); trackTable.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { TrackProfilerFrame.this.setSelectedPoint(); }/*w ww .ja va2s .c o m*/ // public void mouseClicked(MouseEvent evt) { // TrackProfilerFrame.this.setSelectedPoint(); // } }); trackTable.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent evt) { TrackProfilerFrame.this.setSelectedPoint(); } }); } return trackTable; }
From source file:edu.pdi2.visual.PDI.java
private JMenuItem getJMenuItemExit() { if (jMenuItemExit == null) { jMenuItemExit = new JMenuItem(); jMenuItemExit.setText("Exit"); jMenuItemExit.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { jMenuItemExitMouseReleased(evt); }//from w ww . j av a2 s .c o m }); } return jMenuItemExit; }
From source file:convcao.com.agent.ConvcaoNeptusInteraction.java
@Override public void initSubPanel() { jPanelMain = new JPanel(); jPanel1 = new JPanel(); jPanel2 = new JPanel(); jLabel2 = new JLabel(); jScrollPane1 = new JScrollPane(); jTextPane1 = new JTextPane(); renewButton = new JButton(); jLabel4 = new JLabel(); jTextField1 = new JTextField(); jLabel5 = new JLabel(); jPasswordField1 = new JPasswordField(); connectButton = new JButton(); jScrollPane2 = new JScrollPane(); jTextArea1 = new JTextArea(); jLabel7 = new JLabel(); jLabel8 = new JLabel(); jButton1 = new JButton(); jButton2 = new JButton(); jLabel1 = new JLabel(); jLabel9 = new JLabel(); jLabel10 = new JLabel(); jLabel11 = new JLabel(); jLabel12 = new JLabel(); jLabel6 = new JLabel(); jLabel3 = new JLabel(); jLabel11.setIcon(noptilusLogo);/*from ww w . j av a 2s . c o m*/ jLabel12.setHorizontalAlignment(SwingConstants.LEFT); jLabel12.setText("<html>www.convcao.com<br>version 0.01</html>"); jLabel12.setToolTipText(""); jLabel12.setHorizontalTextPosition(SwingConstants.RIGHT); GroupLayout jPanel1Layout = new GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(jLabel11, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup().addGap(0, 19, Short.MAX_VALUE).addComponent(jLabel12, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel11, GroupLayout.PREFERRED_SIZE, 45, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jLabel12, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))); jLabel2.setFont(new Font("Tahoma", 0, 10)); // NOI18N jLabel2.setText("Unique ID"); jTextPane1.setEditable(true); jScrollPane1.setViewportView(jTextPane1); //jTextPane1.getAccessibleContext().setAccessibleName(""); renewButton.setText("RENEW"); renewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { renewButtonActionPerformed(evt); } }); jLabel4.setFont(new Font("Tahoma", 0, 12)); // NOI18N jLabel4.setText("Username"); jTextField1.setText("FTPUser"); jLabel5.setFont(new Font("Tahoma", 0, 12)); // NOI18N jLabel5.setText("Password"); jPasswordField1.setText("FTPUser123"); connectButton.setText("Connect"); connectButton.setEnabled(false); connectButton.setActionCommand("connect"); connectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { connectButtonActionPerformed(evt); } catch (FileNotFoundException | UnsupportedEncodingException e) { e.printStackTrace(); } catch (SocketException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }); jTextArea1.setEditable(false); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane2.setViewportView(jTextArea1); jLabel7.setFont(new Font("Tahoma", 0, 12)); // NOI18N jLabel7.setText("Command Monitor"); jButton1.setFont(new Font("Tahoma", 1, 12)); // NOI18N jButton1.setText("START"); jButton1.setEnabled(false); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { startButtonActionPerformed(evt); } }); jButton2.setFont(new Font("Tahoma", 1, 12)); // NOI18N jButton2.setText("STOP"); jButton2.setEnabled(false); jButton2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { stopButtonActionPerformed(evt); } }); jLabel1.setForeground(new Color(255, 0, 0)); jLabel1.setHorizontalAlignment(SwingConstants.CENTER); jLabel1.setText( "<html>Click HERE to activate the web service using your ID<br>When the web application is ready, press Start </html>"); jLabel1.setCursor(new Cursor(Cursor.HAND_CURSOR)); jLabel1.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { try { jLabel1MouseClicked(evt); } catch (URISyntaxException | IOException e) { e.printStackTrace(); } } }); //jLabel9.setText("Working..."); jLabel9.setIcon(runIcon); jLabel9.setVisible(false); jLabel10.setText("---"); jLabel6.setForeground(new Color(0, 204, 0)); jLabel6.setHorizontalAlignment(SwingConstants.CENTER); jLabel6.setText("---"); GroupLayout jPanel2Layout = new GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup( GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout .createParallelGroup(GroupLayout.Alignment.TRAILING) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(jLabel6, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGap(126, 126, 126) .addComponent(jLabel7, GroupLayout.PREFERRED_SIZE, 110, GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel2Layout.createSequentialGroup().addGap(23, 23, 23) .addGroup(jPanel2Layout .createParallelGroup(GroupLayout.Alignment.TRAILING) .addGroup(jPanel2Layout .createParallelGroup(GroupLayout.Alignment.LEADING, false) .addGroup(GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addComponent(jLabel9, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE) .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE) .addGap(29, 29, 29) .addComponent(jButton2, GroupLayout.PREFERRED_SIZE, 77, GroupLayout.PREFERRED_SIZE)) .addComponent(jScrollPane2, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 308, GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel10, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 299, GroupLayout.PREFERRED_SIZE)))) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(jPanel2Layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup( GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(renewButton)) .addGroup(GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout .createParallelGroup(GroupLayout.Alignment.LEADING, false) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel4, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(jTextField1, GroupLayout.PREFERRED_SIZE, 130, GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel5, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(jPasswordField1))) .addGap(14, 14, 14).addComponent(connectButton))))) .addContainerGap())); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false) .addComponent(renewButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jScrollPane1) .addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(jLabel4, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jTextField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(jLabel5, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPasswordField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(connectButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel6, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel1) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel7, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 113, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false) .addComponent(jButton2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel9, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel10, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE) .addGap(5, 5, 5))); jLabel1.getAccessibleContext().setAccessibleName("jLabel1"); jLabel3.setFont(new Font("Tahoma", 1, 22)); // NOI18N jLabel3.setText("Real Time Navigation"); jLabel8.setIcon(appLogo); GroupLayout layout = new GroupLayout(jPanelMain); jPanelMain.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel3) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel8, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel2, GroupLayout.PREFERRED_SIZE, 331, GroupLayout.PREFERRED_SIZE) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addComponent(jLabel3) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel8, GroupLayout.PREFERRED_SIZE, 110, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(jPanel2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap())); addMenuItem("Settings>Noptilus>Coordinate Settings", ImageUtils.getIcon(PluginUtils.getPluginIcon(getClass())), new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PluginUtils.editPluginProperties(coords, true); coords.saveProps(); } }); addMenuItem("Settings>Noptilus>ConvCAO Settings", ImageUtils.getIcon(PluginUtils.getPluginIcon(getClass())), new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PluginUtils.editPluginProperties(ConvcaoNeptusInteraction.this, true); } }); addMenuItem("Settings>Noptilus>Force vehicle depth", ImageUtils.getIcon(PluginUtils.getPluginIcon(getClass())), new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (positions.isEmpty()) { GuiUtils.errorMessage(getConsole(), "Force vehicle depth", "ConvCAO control is not active"); return; } String[] choices = nameTable.values().toArray(new String[0]); String vehicle = (String) JOptionPane.showInputDialog(getConsole(), "Force vehicle depth", "Choose vehicle", JOptionPane.QUESTION_MESSAGE, null, choices, choices[0]); if (vehicle != null) { double depth = depths.get(vehicle); String newDepth = JOptionPane.showInputDialog(getConsole(), "New depth", "" + depth); try { double dd = Double.parseDouble(newDepth); depths.put(vehicle, dd); } catch (Exception ex) { GuiUtils.errorMessage(getConsole(), ex); } } } }); add(jPanelMain); renewButtonActionPerformed(null); }
From source file:userinterface.properties.GUIGraphHandler.java
public void plotNewFunction() { JDialog dialog;//from w ww . jav a 2 s . co m JRadioButton radio2d, radio3d, newGraph, existingGraph; JTextField functionField, seriesName; JButton ok, cancel; JComboBox<String> chartOptions; JLabel example; //init all the fields of the dialog dialog = new JDialog(GUIPrism.getGUI()); radio2d = new JRadioButton("2D"); radio3d = new JRadioButton("3D"); newGraph = new JRadioButton("New Graph"); existingGraph = new JRadioButton("Exisiting"); chartOptions = new JComboBox<String>(); functionField = new JTextField(); ok = new JButton("Plot"); cancel = new JButton("Cancel"); seriesName = new JTextField(); example = new JLabel("<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>"); example.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { example.setCursor(new Cursor(Cursor.HAND_CURSOR)); example.setForeground(Color.BLUE); } @Override public void mouseExited(MouseEvent e) { example.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); example.setForeground(Color.BLACK); } @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (radio2d.isSelected()) { functionField.setText("x/2 + 5"); } else { functionField.setText("x+y+5"); } functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15)); functionField.setForeground(Color.BLACK); } } }); //set dialog properties dialog.setSize(400, 350); dialog.setTitle("Plot a new function"); dialog.setModal(true); dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS)); dialog.setLocationRelativeTo(GUIPrism.getGUI()); //add every component to their dedicated panels JPanel graphTypePanel = new JPanel(new FlowLayout()); graphTypePanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function type")); graphTypePanel.add(radio2d); graphTypePanel.add(radio3d); JPanel functionFieldPanel = new JPanel(new BorderLayout()); functionFieldPanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function")); functionFieldPanel.add(functionField, BorderLayout.CENTER); functionFieldPanel.add(example, BorderLayout.SOUTH); JPanel chartSelectPanel = new JPanel(); chartSelectPanel.setLayout(new BoxLayout(chartSelectPanel, BoxLayout.Y_AXIS)); chartSelectPanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Plot function to")); JPanel radioPlotPanel = new JPanel(new FlowLayout()); radioPlotPanel.add(newGraph); radioPlotPanel.add(existingGraph); JPanel chartOptionsPanel = new JPanel(new FlowLayout()); chartOptionsPanel.add(chartOptions); chartSelectPanel.add(radioPlotPanel); chartSelectPanel.add(chartOptionsPanel); JPanel bottomControlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); bottomControlPanel.add(ok); bottomControlPanel.add(cancel); JPanel seriesNamePanel = new JPanel(new BorderLayout()); seriesNamePanel.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Series name")); seriesNamePanel.add(seriesName, BorderLayout.CENTER); // add all the panels to the dialog dialog.add(graphTypePanel); dialog.add(functionFieldPanel); dialog.add(chartSelectPanel); dialog.add(seriesNamePanel); dialog.add(bottomControlPanel); // do all the enables and set properties radio2d.setSelected(true); newGraph.setSelected(true); chartOptions.setEnabled(false); functionField.setText("Add function expression here...."); functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15)); functionField.setForeground(Color.GRAY); seriesName.setText("New function"); ok.setMnemonic('P'); cancel.setMnemonic('C'); example.setToolTipText("click to try out"); ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok"); ok.getActionMap().put("ok", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { ok.doClick(); } }); cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); cancel.getActionMap().put("cancel", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cancel.doClick(); } }); boolean found = false; for (int i = 0; i < theTabs.getTabCount(); i++) { if (theTabs.getComponentAt(i) instanceof Graph) { chartOptions.addItem(getGraphName(i)); found = true; } } if (!found) { existingGraph.setEnabled(false); chartOptions.setEnabled(false); } //add all the action listeners radio2d.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (radio2d.isSelected()) { radio3d.setSelected(false); if (chartOptions.getItemCount() > 0) { existingGraph.setEnabled(true); chartOptions.setEnabled(true); } example.setText( "<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>"); } } }); radio3d.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (radio3d.isSelected()) { radio2d.setSelected(false); newGraph.setSelected(true); existingGraph.setEnabled(false); chartOptions.setEnabled(false); example.setText("<html><font size=3 color=red>Example:</font><font size=3>x+y+5</font></html>"); } } }); newGraph.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (newGraph.isSelected()) { existingGraph.setSelected(false); chartOptions.setEnabled(false); } } }); existingGraph.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (existingGraph.isSelected()) { newGraph.setSelected(false); chartOptions.setEnabled(true); } } }); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String function = functionField.getText(); Expression expr = null; try { expr = GUIPrism.getGUI().getPrism().parseSingleExpressionString(function); expr = (Expression) expr.accept(new ASTTraverseModify() { @Override public Object visit(ExpressionIdent e) throws PrismLangException { return new ExpressionConstant(e.getName(), TypeDouble.getInstance()); } }); expr.typeCheck(); expr.semanticCheck(); } catch (PrismLangException e1) { // for copying style JLabel label = new JLabel(); // html content in our case the error we want to show JEditorPane ep = new JEditorPane("text/html", "<html> There was an error parsing the function. To read about what built-in" + " functions are supported <br>and some more information on the functions, visit " + "<a href='http://www.prismmodelchecker.org/manual/ThePRISMLanguage/Expressions'>Prism expressions site</a>." + "<br><br><font color=red>Error: </font>" + e1.getMessage() + " </html>"); // handle link events ep.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) { try { Desktop.getDesktop().browse(e.getURL().toURI()); } catch (IOException | URISyntaxException e1) { e1.printStackTrace(); } } } }); ep.setEditable(false); ep.setBackground(label.getBackground()); // show the error dialog JOptionPane.showMessageDialog(dialog, ep, "Parse Error", JOptionPane.ERROR_MESSAGE); return; } if (radio2d.isSelected()) { ParametricGraph graph = null; if (newGraph.isSelected()) { graph = new ParametricGraph(""); } else { for (int i = 0; i < theTabs.getComponentCount(); i++) { if (theTabs.getTitleAt(i).equals(chartOptions.getSelectedItem())) { graph = (ParametricGraph) theTabs.getComponent(i); } } } dialog.dispose(); defineConstantsAndPlot(expr, graph, seriesName.getText(), newGraph.isSelected(), true); } else if (radio3d.isSelected()) { try { expr = (Expression) expr.accept(new ASTTraverseModify() { @Override public Object visit(ExpressionIdent e) throws PrismLangException { return new ExpressionConstant(e.getName(), TypeDouble.getInstance()); } }); expr.semanticCheck(); expr.typeCheck(); } catch (PrismLangException e1) { e1.printStackTrace(); } if (expr.getAllConstants().size() < 2) { JOptionPane.showMessageDialog(dialog, "There are not enough variables in the function to plot a 3D chart!", "Error", JOptionPane.ERROR_MESSAGE); return; } // its always a new graph ParametricGraph3D graph = new ParametricGraph3D(expr); dialog.dispose(); defineConstantsAndPlot(expr, graph, seriesName.getText(), true, false); } dialog.dispose(); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); // we will show info about the function when field is out of focus functionField.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { if (!functionField.getText().equals("")) { return; } functionField.setText("Add function expression here...."); functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15)); functionField.setForeground(Color.GRAY); } @Override public void focusGained(FocusEvent e) { if (!functionField.getText().equals("Add function expression here....")) { return; } functionField.setForeground(Color.BLACK); functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15)); functionField.setText(""); } }); // show the dialog dialog.setVisible(true); }
From source file:com.t3.client.ui.T3Frame.java
private AssetPanel createAssetPanel() { final AssetPanel panel = new AssetPanel("mainAssetPanel"); panel.addImagePanelMouseListener(new MouseAdapter() { @Override/* w w w . j a v a2s. co m*/ public void mouseReleased(MouseEvent e) { // TODO use for real popup logic // if (SwingUtilities.isLeftMouseButton(e)) { // if (e.getClickCount() == 2) { // // List<Object> idList = panel.getSelectedIds(); // if (idList == null || idList.size() == 0) { // return; // } // // final int index = (Integer) idList.get(0); // createZone(panel.getAsset(index)); // } // } if (SwingUtilities.isRightMouseButton(e) && TabletopTool.getPlayer().isGM()) { List<Object> idList = panel.getSelectedIds(); if (idList == null || idList.size() == 0) { return; } final int index = (Integer) idList.get(0); JPopupMenu menu = new JPopupMenu(); menu.add(new JMenuItem(new AbstractAction() { { putValue(NAME, I18N.getText("action.newMap")); } @Override public void actionPerformed(ActionEvent e) { createZone(panel.getAsset(index)); } })); panel.showImagePanelPopup(menu, e.getX(), e.getY()); } } private void createZone(Asset asset) { Zone zone = ZoneFactory.createZone(); zone.setName(asset.getName()); BufferedImage image = ImageManager.getImageAndWait(asset.getId()); if (image.getWidth() < 200 || image.getHeight() < 200) { zone.setBackgroundPaint(new DrawableTexturePaint(asset)); } else { zone.setMapAsset(asset.getId()); zone.setBackgroundPaint(new DrawableColorPaint(Color.black)); } MapPropertiesDialog newMapDialog = new MapPropertiesDialog(TabletopTool.getFrame()); newMapDialog.setZone(zone); newMapDialog.setVisible(true); if (newMapDialog.getStatus() == MapPropertiesDialog.Status.OK) { TabletopTool.addZone(zone); } } }); return panel; }