List of usage examples for java.awt.event MouseAdapter MouseAdapter
MouseAdapter
From source file:jatoo.app.App.java
public App(final String title) { this.title = title; ///* w w w . ja v a 2 s .c om*/ // load properties properties = new AppProperties(new File(getWorkingDirectory(), "app.properties")); properties.loadSilently(); // // resources texts = new ResourcesTexts(getClass(), new ResourcesTexts(App.class)); images = new ResourcesImages(getClass(), new ResourcesImages(App.class)); // // create & initialize the window if (isDialog()) { window = new JDialog((Frame) null, getTitle()); if (isUndecorated()) { ((JDialog) window).setUndecorated(true); ((JDialog) window).setBackground(new Color(0, 0, 0, 0)); } ((JDialog) window).setResizable(isResizable()); } else { window = new JFrame(getTitle()); if (isUndecorated()) { ((JFrame) window).setUndecorated(true); ((JFrame) window).setBackground(new Color(0, 0, 0, 0)); } ((JFrame) window).setResizable(isResizable()); } window.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { System.exit(0); } @Override public void windowIconified(final WindowEvent e) { if (isHideWhenMinimized()) { hide(); } } }); // // set icon images // is either all icons from initializer package // or all icons from app package List<Image> windowIconImages = new ArrayList<>(); String[] windowIconImagesNames = new String[] { "016", "020", "022", "024", "032", "048", "064", "128", "256", "512" }; for (String size : windowIconImagesNames) { try { windowIconImages.add(new ImageIcon(getClass().getResource("app-icon-" + size + ".png")).getImage()); } catch (Exception e) { } } if (windowIconImages.size() == 0) { for (String size : windowIconImagesNames) { try { windowIconImages .add(new ImageIcon(App.class.getResource("app-icon-" + size + ".png")).getImage()); } catch (Exception e) { } } } window.setIconImages(windowIconImages); // // this is the place for to call init method // after all local components are created // from now (after init) is only configuration init(); // // set content pane ( and ansure transparency ) JComponent contentPane = getContentPane(); contentPane.setOpaque(false); ((RootPaneContainer) window).setContentPane(contentPane); // // pack the window right after the set of the content pane window.pack(); // // center window (as default in case restore fails) // and try to restore the last location window.setLocationRelativeTo(null); window.setLocation(properties.getLocation(window.getLocation())); if (!isUndecorated()) { if (properties.getLastUndecorated(isUndecorated()) == isUndecorated()) { if (isResizable() && isSizePersistent()) { final String currentLookAndFeel = String.valueOf(UIManager.getLookAndFeel()); if (properties.getLastLookAndFeel(currentLookAndFeel).equals(currentLookAndFeel)) { window.setSize(properties.getSize(window.getSize())); } } } } // // fix location if out of screen Rectangle intersection = window.getGraphicsConfiguration().getBounds().intersection(window.getBounds()); if ((intersection.width < window.getWidth() * 1 / 2) || (intersection.height < window.getHeight() * 1 / 2)) { UIUtils.setWindowLocationRelativeToScreen(window); } // // restore some properties setAlwaysOnTop(properties.isAlwaysOnTop()); setHideWhenMinimized(properties.isHideWhenMinimized()); setTransparency(properties.getTransparency(transparency)); // // null is also a good value for margins glue gaps (is [0,0,0,0]) Insets marginsGlueGaps = getMarginsGlueGaps(); if (marginsGlueGaps == null) { marginsGlueGaps = new Insets(0, 0, 0, 0); } // // glue to margins on Ctrl + ARROWS if (isGlueToMarginsOnCtrlArrows()) { UIUtils.setActionForCtrlDownKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginBottom(window, marginsGlueGaps.bottom)); UIUtils.setActionForCtrlLeftKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginLeft(window, marginsGlueGaps.left)); UIUtils.setActionForCtrlRightKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginRight(window, marginsGlueGaps.right)); UIUtils.setActionForCtrlUpKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginTop(window, marginsGlueGaps.top)); } // // drag to move ( when provided component is not null ) JComponent dragToMoveComponent = getDragToMoveComponent(); if (dragToMoveComponent != null) { // // move the window by dragging the UI component int marginsGlueRange = Math.min(window.getGraphicsConfiguration().getBounds().width, window.getGraphicsConfiguration().getBounds().height); marginsGlueRange /= 60; marginsGlueRange = Math.max(marginsGlueRange, 15); UIUtils.forwardDragAsMove(dragToMoveComponent, window, marginsGlueRange, marginsGlueGaps); // // window popup dragToMoveComponent.addMouseListener(new MouseAdapter() { public void mouseReleased(final MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { windowPopup = getWindowPopup(e.getLocationOnScreen()); windowPopup.setVisible(true); } } }); // // always dispose the popup when window lose the focus window.addFocusListener(new FocusAdapter() { public void focusLost(final FocusEvent e) { if (windowPopup != null) { windowPopup.setVisible(false); windowPopup = null; } } }); } // // tray icon if (hasTrayIcon()) { if (SystemTray.isSupported()) { Image trayIconImage = windowIconImages.get(0); Dimension trayIconSize = SystemTray.getSystemTray().getTrayIconSize(); for (Image windowIconImage : windowIconImages) { if (Math.abs(trayIconSize.width - windowIconImage.getWidth(null)) < Math .abs(trayIconImage.getWidth(null) - windowIconImage.getWidth(null))) { trayIconImage = windowIconImage; } } final TrayIcon trayIcon = new TrayIcon(trayIconImage); trayIcon.setPopupMenu(getTrayIconPopup()); trayIcon.addMouseListener(new MouseAdapter() { public void mouseClicked(final MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() >= 2) { if (window.isVisible()) { hide(); } else { show(); } } } } }); try { SystemTray.getSystemTray().add(trayIcon); } catch (AWTException e) { logger.error( "unexpected exception trying to add the tray icon ( the desktop system tray is missing? )", e); } } else { logger.error("the system tray is not supported on the current platform"); } } // // hidden or not if (properties.isVisible()) { window.setVisible(true); } // // close the splash screen // if there is one try { SplashScreen splash = SplashScreen.getSplashScreen(); if (splash != null) { splash.close(); } } catch (UnsupportedOperationException e) { getLogger().info("splash screen not supported", e); } // // add shutdown hook for #destroy() Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { App.this.destroy(); } }); // // after init afterInit(); }
From source file:net.sf.jabref.openoffice.StyleSelectDialog.java
private void init(String inSelection) { this.initSelection = inSelection; ButtonGroup bg = new ButtonGroup(); bg.add(useDefaultAuthoryear);//from w ww.j av a 2 s. co m bg.add(useDefaultNumerical); bg.add(chooseDirectly); bg.add(setDirectory); if (Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_AUTHORYEAR_STYLE)) { useDefaultAuthoryear.setSelected(true); } else if (Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_NUMERICAL_STYLE)) { useDefaultNumerical.setSelected(true); } else { if (Globals.prefs.getBoolean(JabRefPreferences.OO_CHOOSE_STYLE_DIRECTLY)) { chooseDirectly.setSelected(true); } else { setDirectory.setSelected(true); } } directFile.setText(Globals.prefs.get(JabRefPreferences.OO_DIRECT_FILE)); styleDir.setText(Globals.prefs.get(JabRefPreferences.OO_STYLE_DIRECTORY)); directFile.setEditable(false); styleDir.setEditable(false); popup.add(edit); BrowseAction dfBrowse = BrowseAction.buildForFile(directFile, directFile); browseDirectFile.addActionListener(dfBrowse); BrowseAction sdBrowse = BrowseAction.buildForDir(styleDir, setDirectory); browseStyleDir.addActionListener(sdBrowse); showDefaultAuthoryearStyle.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { displayDefaultStyle(true); } }); showDefaultNumericalStyle.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { displayDefaultStyle(false); } }); // Add action listener to "Edit" menu item, which is supposed to open the style file in an external editor: edit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { int i = table.getSelectedRow(); if (i == -1) { return; } ExternalFileType type = ExternalFileTypes.getInstance().getExternalFileTypeByExt("jstyle"); String link = tableModel.getElementAt(i).getFile().getPath(); try { if (type == null) { JabRefDesktop.openExternalFileUnknown(frame, new BibEntry(), new MetaData(), link, new UnknownExternalFileType("jstyle")); } else { JabRefDesktop.openExternalFileAnyFormat(new MetaData(), link, type); } } catch (IOException e) { LOGGER.warn("Problem open style file editor", e); } } }); diag = new JDialog(frame, Localization.lang("Styles"), true); styles = new BasicEventList<>(); EventList<OOBibStyle> sortedStyles = new SortedList<>(styles); // Create a preview panel for previewing styles: preview = new PreviewPanel(null, new MetaData(), ""); // Use the test entry from the Preview settings tab in Preferences: preview.setEntry(prevEntry); tableModel = (DefaultEventTableModel<OOBibStyle>) GlazedListsSwing .eventTableModelWithThreadProxyList(sortedStyles, new StyleTableFormat()); table = new JTable(tableModel); TableColumnModel cm = table.getColumnModel(); cm.getColumn(0).setPreferredWidth(100); cm.getColumn(1).setPreferredWidth(200); cm.getColumn(2).setPreferredWidth(80); selectionModel = (DefaultEventSelectionModel<OOBibStyle>) GlazedListsSwing .eventSelectionModelWithThreadProxyList(sortedStyles); table.setSelectionModel(selectionModel); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent mouseEvent) { if (mouseEvent.isPopupTrigger()) { tablePopup(mouseEvent); } } @Override public void mouseReleased(MouseEvent mouseEvent) { if (mouseEvent.isPopupTrigger()) { tablePopup(mouseEvent); } } }); selectionModel.getSelected().addListEventListener(new EntrySelectionListener()); styleDir.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent documentEvent) { readStyles(); setDirectory.setSelected(true); } @Override public void removeUpdate(DocumentEvent documentEvent) { readStyles(); setDirectory.setSelected(true); } @Override public void changedUpdate(DocumentEvent documentEvent) { readStyles(); setDirectory.setSelected(true); } }); directFile.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent documentEvent) { chooseDirectly.setSelected(true); } @Override public void removeUpdate(DocumentEvent documentEvent) { chooseDirectly.setSelected(true); } @Override public void changedUpdate(DocumentEvent documentEvent) { chooseDirectly.setSelected(true); } }); contentPane.setTopComponent(new JScrollPane(table)); contentPane.setBottomComponent(preview); readStyles(); DefaultFormBuilder b = new DefaultFormBuilder( new FormLayout("fill:pref,4dlu,fill:150dlu,4dlu,fill:pref", "")); b.append(useDefaultAuthoryear, 3); b.append(showDefaultAuthoryearStyle); b.nextLine(); b.append(useDefaultNumerical, 3); b.append(showDefaultNumericalStyle); b.nextLine(); b.append(chooseDirectly); b.append(directFile); b.append(browseDirectFile); b.nextLine(); b.append(setDirectory); b.append(styleDir); b.append(browseStyleDir); b.nextLine(); DefaultFormBuilder b2 = new DefaultFormBuilder( new FormLayout("fill:1dlu:grow", "fill:pref, fill:pref, fill:270dlu:grow")); b2.nextLine(); b2.append(new JLabel("<html>" + Localization.lang("This is the list of available styles. Select the one you want to use.") + "</html>")); b2.nextLine(); b2.append(contentPane); b.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); b2.getPanel().setBorder(BorderFactory.createEmptyBorder(15, 5, 5, 5)); diag.add(b.getPanel(), BorderLayout.NORTH); diag.add(b2.getPanel(), BorderLayout.CENTER); AbstractAction okListener = new AbstractAction() { @Override public void actionPerformed(ActionEvent event) { if (!useDefaultAuthoryear.isSelected() && !useDefaultNumerical.isSelected()) { if (chooseDirectly.isSelected()) { File f = new File(directFile.getText()); if (!f.exists()) { JOptionPane.showMessageDialog(diag, Localization.lang( "You must select either a valid style file, or use a default style."), Localization.lang("Style selection"), JOptionPane.ERROR_MESSAGE); return; } } else { if ((table.getRowCount() == 0) || (table.getSelectedRowCount() == 0)) { JOptionPane.showMessageDialog(diag, Localization.lang( "You must select either a valid style file, or use a default style."), Localization.lang("Style selection"), JOptionPane.ERROR_MESSAGE); return; } } } okPressed = true; storeSettings(); diag.dispose(); } }; ok.addActionListener(okListener); Action cancelListener = new AbstractAction() { @Override public void actionPerformed(ActionEvent event) { diag.dispose(); } }; cancel.addActionListener(cancelListener); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); bb.addButton(ok); bb.addButton(cancel); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); diag.add(bb.getPanel(), BorderLayout.SOUTH); ActionMap am = bb.getPanel().getActionMap(); InputMap im = bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", cancelListener); im.put(KeyStroke.getKeyStroke("ENTER"), "enterOk"); am.put("enterOk", okListener); diag.pack(); diag.setLocationRelativeTo(frame); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { contentPane.setDividerLocation(contentPane.getSize().height - 150); } }); }
From source file:com.rapidminer.gui.properties.OperatorPropertyPanel.java
public OperatorPropertyPanel(final MainFrame mainFrame) { super();/*from ww w . jav a2s . c o m*/ this.mainFrame = mainFrame; breakpointButton = new BreakpointButton(); headerLabel.setHorizontalAlignment(SwingConstants.CENTER); expertModeHintLabel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); expertModeHintLabel.setIcon(WARNING_ICON); expertModeHintLabel.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { mainFrame.TOGGLE_EXPERT_MODE_ACTION.actionPerformed(null); } }); expertModeHintLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); expertModeHintLabel.setHorizontalAlignment(SwingConstants.LEFT); setupComponents(); compatibilityLevelSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { // compatibility level OperatorVersion[] versionChanges = operator.getIncompatibleVersionChanges(); // sort to have an ascending order Arrays.sort(versionChanges); if (versionChanges.length != 0) { OperatorVersion latestChange = versionChanges[versionChanges.length - 1]; if (latestChange.isAtLeast(operator.getCompatibilityLevel())) { compatibilityLabel.setIcon(WARNING_ICON); } else { compatibilityLabel.setIcon(SwingTools.createIcon("16/ok.png")); } } } }); showHelpAction = new ToggleAction(true, "show_parameter_help") { private static final long serialVersionUID = 1L; @Override public void actionToggled(ActionEvent e) { setShowParameterHelp(isSelected()); mainFrame.getPropertyPanel().setupComponents(); } }; }
From source file:com.net2plan.gui.tools.GUINetworkDesign.java
@Override public void configure(JPanel contentPane) { this.currentNetPlan = new NetPlan(); BidiMap<NetworkLayer, Integer> mapLayer2VisualizationOrder = new DualHashBidiMap<>(); Map<NetworkLayer, Boolean> layerVisibilityMap = new HashMap<>(); for (NetworkLayer layer : currentNetPlan.getNetworkLayers()) { mapLayer2VisualizationOrder.put(layer, mapLayer2VisualizationOrder.size()); layerVisibilityMap.put(layer, true); }/* w w w. j av a 2s .com*/ this.vs = new VisualizationState(currentNetPlan, mapLayer2VisualizationOrder, layerVisibilityMap, MAXSIZEUNDOLISTPICK); topologyPanel = new TopologyPanel(this, JUNGCanvas.class); JPanel leftPane = new JPanel(new BorderLayout()); JPanel logSection = configureLeftBottomPanel(); if (logSection == null) { leftPane.add(topologyPanel, BorderLayout.CENTER); } else { JSplitPane splitPaneTopology = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPaneTopology.setTopComponent(topologyPanel); splitPaneTopology.setBottomComponent(logSection); splitPaneTopology.addPropertyChangeListener(new ProportionalResizeJSplitPaneListener()); splitPaneTopology.setBorder(new LineBorder(contentPane.getBackground())); splitPaneTopology.setOneTouchExpandable(true); splitPaneTopology.setDividerSize(7); leftPane.add(splitPaneTopology, BorderLayout.CENTER); } contentPane.add(leftPane, "grow"); viewEditTopTables = new ViewEditTopologyTablesPane(GUINetworkDesign.this, new BorderLayout()); reportPane = new ViewReportPane(GUINetworkDesign.this, JSplitPane.VERTICAL_SPLIT); setCurrentNetPlanDoNotUpdateVisualization(currentNetPlan); Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = VisualizationState .generateCanvasDefaultVisualizationLayerInfo(getDesign()); vs.setCanvasLayerVisibilityAndOrder(getDesign(), res.getFirst(), res.getSecond()); /* Initialize the undo/redo manager, and set its initial design */ this.undoRedoManager = new UndoRedoManager(this, MAXSIZEUNDOLISTCHANGES); this.undoRedoManager.addNetPlanChange(); onlineSimulationPane = new OnlineSimulationPane(this); executionPane = new OfflineExecutionPanel(this); whatIfAnalysisPane = new WhatIfAnalysisPane(this); // Closing windows WindowUtils.clearFloatingWindows(); final JTabbedPane tabPane = new JTabbedPane(); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.network), viewEditTopTables); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.offline), executionPane); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.online), onlineSimulationPane); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.whatif), whatIfAnalysisPane); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.report), reportPane); // Installing customized mouse listener MouseListener[] ml = tabPane.getListeners(MouseListener.class); for (int i = 0; i < ml.length; i++) { tabPane.removeMouseListener(ml[i]); } // Left click works as usual, right click brings up a pop-up menu. tabPane.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { JTabbedPane tabPane = (JTabbedPane) e.getSource(); int tabIndex = tabPane.getUI().tabForCoordinate(tabPane, e.getX(), e.getY()); if (tabIndex >= 0 && tabPane.isEnabledAt(tabIndex)) { if (tabIndex == tabPane.getSelectedIndex()) { if (tabPane.isRequestFocusEnabled()) { tabPane.requestFocus(); tabPane.repaint(tabPane.getUI().getTabBounds(tabPane, tabIndex)); } } else { tabPane.setSelectedIndex(tabIndex); } if (!tabPane.isEnabled() || SwingUtilities.isRightMouseButton(e)) { final JPopupMenu popupMenu = new JPopupMenu(); final JMenuItem popWindow = new JMenuItem("Pop window out"); popWindow.addActionListener(e1 -> { final int selectedIndex = tabPane.getSelectedIndex(); final String tabName = tabPane.getTitleAt(selectedIndex); final JComponent selectedComponent = (JComponent) tabPane.getSelectedComponent(); // Pops up the selected tab. final WindowController.WindowToTab windowToTab = WindowController.WindowToTab .parseString(tabName); if (windowToTab != null) { switch (windowToTab) { case offline: WindowController.buildOfflineWindow(selectedComponent); WindowController.showOfflineWindow(true); break; case online: WindowController.buildOnlineWindow(selectedComponent); WindowController.showOnlineWindow(true); break; case whatif: WindowController.buildWhatifWindow(selectedComponent); WindowController.showWhatifWindow(true); break; case report: WindowController.buildReportWindow(selectedComponent); WindowController.showReportWindow(true); break; default: return; } } tabPane.setSelectedIndex(0); }); // Disabling the pop up button for the network state tab. if (WindowController.WindowToTab.parseString(tabPane .getTitleAt(tabPane.getSelectedIndex())) == WindowController.WindowToTab.network) { popWindow.setEnabled(false); } popupMenu.add(popWindow); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } } }); // Building windows WindowController.buildTableControlWindow(tabPane); WindowController.showTablesWindow(false); addAllKeyCombinationActions(); updateVisualizationAfterNewTopology(); }
From source file:edu.ku.brc.specify.ui.treetables.TreeDefinitionEditor.java
/** * @param treeDef//from w ww . ja v a2 s . c om */ protected void initTreeDefEditorComponent(final D treeDef) { Set<I> defItems = treeDef.getTreeDefItems(); tableModel = new TreeDefEditorTableModel<T, D, I>(defItems); defItemsTable = new JTable(tableModel); defItemsTable.setDefaultRenderer(String.class, new BiColorTableCellRenderer(false)); defItemsTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { SwingUtilities.invokeLater(new Runnable() { /* (non-Javadoc) * @see java.lang.Runnable#run() */ @Override public void run() { editTreeDefItem(defItemsTable.getSelectedRow()); } }); } } }); defItemsTable.setRowHeight(24); // Center the boolean Columns BiColorTableCellRenderer centeredRenderer = new BiColorTableCellRenderer(); TableColumn tc = defItemsTable.getColumnModel().getColumn(2); tc.setCellRenderer(centeredRenderer); tc = defItemsTable.getColumnModel().getColumn(3); tc.setCellRenderer(centeredRenderer); if (isEditMode) { defItemsTable.setRowSelectionAllowed(true); defItemsTable.setColumnSelectionAllowed(false); defItemsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else { defItemsTable.setRowSelectionAllowed(false); } UIHelper.makeTableHeadersCentered(defItemsTable, false); defNameLabel.setText(treeDef.getName()); Font f = defNameLabel.getFont(); Font boldF = f.deriveFont(Font.BOLD); defNameLabel.setFont(boldF); // put everything in the main panel this.add(UIHelper.createScrollPane(defItemsTable), BorderLayout.CENTER); this.add(titlePanel, BorderLayout.NORTH); // Only add selection listener if the botton panel is there for editing if (edaPanel != null) { PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,p,10px", "p")); //$NON-NLS-1$ //$NON-NLS-2$ pb.add(edaPanel, new CellConstraints().xy(2, 1)); add(pb.getPanel(), BorderLayout.SOUTH); addSelectionListener(); } repaint(); }
From source file:gtu._work.ui.RegexReplacer.java
private void initGUI() { try {//from ww w.j a v a2s .c om BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jTabbedPane1 = new JTabbedPane(); jTabbedPane1.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { try { if (configHandler != null && jTabbedPane1.getSelectedIndex() == TabIndex.TEMPLATE.ordinal()) { System.out.println("-------ChangeEvent[" + jTabbedPane1.getSelectedIndex() + "]"); configHandler.reloadTemplateList(); } } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("source", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); { replaceArea = new JTextArea(); jScrollPane1.setViewportView(replaceArea); } } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("param", null, jPanel2, null); { exeucte = new JButton(); jPanel2.add(exeucte, BorderLayout.SOUTH); exeucte.setText("exeucte"); exeucte.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { exeucteActionPerformed(evt); } }); } { jPanel3 = new JPanel(); jPanel2.add(JCommonUtil.createScrollComponent(jPanel3), BorderLayout.CENTER); jPanel3.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, RowSpec.decode("default:grow"), })); { lblNewLabel = new JLabel("key"); jPanel3.add(lblNewLabel, "2, 2, right, default"); } { configKeyText = new JTextField(); jPanel3.add(configKeyText, "4, 2, fill, default"); configKeyText.setColumns(10); } { lblNewLabel_1 = new JLabel("from"); jPanel3.add(lblNewLabel_1, "2, 4, right, default"); } { repFromText = new JTextArea(); repFromText.setRows(3); jPanel3.add(JCommonUtil.createScrollComponent(repFromText), "4, 4, fill, default"); repFromText.setColumns(10); } { lblNewLabel_2 = new JLabel("to"); jPanel3.add(lblNewLabel_2, "2, 6, right, default"); } { repToText = new JTextArea(); repToText.setRows(3); // repToText.setPreferredSize(new Dimension(0, 50)); jPanel3.add(JCommonUtil.createScrollComponent(repToText), "4, 6, fill, default"); } } { addToTemplate = new JButton(); jPanel2.add(addToTemplate, BorderLayout.NORTH); addToTemplate.setText("add to template"); addToTemplate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { configHandler.put(configKeyText.getText(), repFromText.getText(), repToText.getText(), tradeOffArea.getText()); configHandler.reloadTemplateList(); } }); } } { jPanel5 = new JPanel(); BorderLayout jPanel5Layout = new BorderLayout(); jPanel5.setLayout(jPanel5Layout); jTabbedPane1.addTab("template", null, jPanel5, null); { jScrollPane3 = new JScrollPane(); jPanel5.add(jScrollPane3, BorderLayout.CENTER); { templateList = new JList(); jScrollPane3.setViewportView(templateList); } templateList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (templateList.getLeadSelectionIndex() == -1) { return; } PropConfigHandler.Config config = (PropConfigHandler.Config) JListUtil .getLeadSelectionObject(templateList); configKeyText.setText(config.configKeyText); repFromText.setText(config.fromVal); repToText.setText(config.toVal); tradeOffArea.setText(config.tradeOff); templateList.setToolTipText(config.fromVal + " <----> " + config.toVal); if (JMouseEventUtil.buttonLeftClick(2, evt)) { String replaceText = StringUtils.defaultString(replaceArea.getText()); replaceText = replacer(config.fromVal, config.toVal, replaceText); resultArea.setText(replaceText); jTabbedPane1.setSelectedIndex(TabIndex.RESULT.ordinal()); // pasteTextToClipboard(); } } }); templateList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(templateList).defaultJListKeyPressed(evt); } }); // ? JListUtil.newInstance(templateList).setItemColorTextProcess(new ItemColorTextHandler() { public Pair<String, Color> setColorAndText(Object value) { PropConfigHandler.Config config = (PropConfigHandler.Config) value; if (config.tradeOffScore != 0) { return Pair.of(null, Color.GREEN); } return null; } }); // ? } { scheduleExecute = new JButton(); jPanel5.add(scheduleExecute, BorderLayout.SOUTH); scheduleExecute.setText("schedule execute"); scheduleExecute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { scheduleExecuteActionPerformed(evt); } }); } } { jPanel4 = new JPanel(); BorderLayout jPanel4Layout = new BorderLayout(); jPanel4.setLayout(jPanel4Layout); jTabbedPane1.addTab("result", null, jPanel4, null); { jScrollPane2 = new JScrollPane(); jPanel4.add(jScrollPane2, BorderLayout.CENTER); { resultArea = new JTextArea(); jScrollPane2.setViewportView(resultArea); } } } } { configHandler = new PropConfigHandler(prop, propFile, templateList, replaceArea); JCommonUtil.setFont(repToText, repFromText, replaceArea, templateList); { tradeOffArea = new JTextArea(); tradeOffArea.setRows(3); // tradeOffArea.setPreferredSize(new Dimension(0, 50)); tradeOffArea.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { if (JMouseEventUtil.buttonLeftClick(2, e)) { String tradeOff = StringUtils.trimToEmpty(tradeOffArea.getText()); JSONObject json = null; if (StringUtils.isBlank(tradeOff)) { json = new JSONObject(); json.put(CONTAIN_ARRY_KEY, new JSONArray()); json.put(NOT_CONTAIN_ARRY_KEY, new JSONArray()); tradeOff = json.toString(); } else { json = JSONObject.fromObject(tradeOff); } // String selectItem = (String) JCommonUtil._JOptionPane_showInputDialog( "?!", "?", new Object[] { "NA", "equal", "not_equal", "ftl" }, "NA"); if ("NA".equals(selectItem)) { return; } String string = StringUtils.trimToEmpty( JCommonUtil._jOptionPane_showInputDialog(":")); string = StringUtils.trimToEmpty(string); if (StringUtils.isBlank(string)) { tradeOffArea.setText(json.toString()); return; } String arryKey = ""; String boolKey = ""; String strKey = ""; String intKey = ""; if (selectItem.equals("equal")) { arryKey = CONTAIN_ARRY_KEY; } else if (selectItem.equals("not_equal")) { arryKey = NOT_CONTAIN_ARRY_KEY; } else if (selectItem.equals("ftl")) { strKey = FREEMARKER_KEY; } else { throw new RuntimeException(" : " + selectItem); } if (StringUtils.isNotBlank(arryKey)) { if (!json.containsKey(arryKey)) { json.put(arryKey, new JSONArray()); } JSONArray arry = (JSONArray) json.get(arryKey); boolean findOk = false; for (int ii = 0; ii < arry.size(); ii++) { if (StringUtils.equalsIgnoreCase(arry.getString(ii), string)) { findOk = true; break; } } if (!findOk) { arry.add(string); } } else if (StringUtils.isNotBlank(strKey)) { json.put(strKey, string); } else if (StringUtils.isNotBlank(intKey)) { json.put(intKey, Integer.parseInt(string)); } else if (StringUtils.isNotBlank(boolKey)) { json.put(boolKey, Boolean.valueOf(string)); } tradeOffArea.setText(json.toString()); JCommonUtil._jOptionPane_showMessageDialog_info("?!"); } } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); { panel = new JPanel(); jPanel3.add(panel, "4, 8, fill, fill"); { multiLineCheckBox = new JCheckBox(""); panel.add(multiLineCheckBox); } { autoPasteToClipboardCheckbox = new JCheckBox(""); panel.add(autoPasteToClipboardCheckbox); } } { lblNewLabel_3 = new JLabel("? "); jPanel3.add(lblNewLabel_3, "2, 10"); } jPanel3.add(JCommonUtil.createScrollComponent(tradeOffArea), "4, 10, fill, fill"); } configHandler.reloadTemplateList(); } this.setSize(512, 350); JCommonUtil.setJFrameCenter(this); JCommonUtil.defaultToolTipDelay(); JCommonUtil.frameCloseDo(this, new WindowAdapter() { public void windowClosing(WindowEvent paramWindowEvent) { try { prop.store(new FileOutputStream(propFile), "regexText"); } catch (Exception e) { JCommonUtil.handleException("properties store error!", e); } setVisible(false); dispose(); } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.harvard.mcz.imagecapture.SpecimenPartAttributeDialog.java
private void init() { thisDialog = this; setBounds(100, 100, 820, 335);//from w w w.j a va2 s . c o m getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); JPanel panel = new JPanel(); panel.setLayout(new FormLayout( new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, })); { JLabel lblAttributeType = new JLabel("Attribute Type"); panel.add(lblAttributeType, "2, 2, right, default"); } { comboBoxType = new JComboBox(); comboBoxType.setModel(new DefaultComboBoxModel( new String[] { "caste", "scientific name", "sex", "life stage", "part association" })); comboBoxType.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String item = comboBoxType.getSelectedItem().toString(); if (item != null) { comboBoxValue.setEditable(false); if (item.equals("scientific name")) { comboBoxValue.setEditable(true); } if (item.equals("sex")) { comboBoxValue.setModel(new DefaultComboBoxModel(Sex.getSexValues())); } if (item.equals("life stage")) { comboBoxValue.setModel(new DefaultComboBoxModel(LifeStage.getLifeStageValues())); } if (item.equals("caste")) { comboBoxValue.setModel(new DefaultComboBoxModel(Caste.getCasteValues())); } if (item.equals("part association")) { comboBoxValue .setModel(new DefaultComboBoxModel(PartAssociation.getPartAssociationValues())); } } } }); panel.add(comboBoxType, "4, 2, fill, default"); } { JLabel lblValue = new JLabel("Value"); panel.add(lblValue, "2, 4, right, default"); } { comboBoxValue = new JComboBox(); comboBoxValue.setModel(new DefaultComboBoxModel(Caste.getCasteValues())); panel.add(comboBoxValue, "4, 4, fill, default"); } { JLabel lblUnits = new JLabel("Units"); panel.add(lblUnits, "2, 6, right, default"); } { textFieldUnits = new JTextField(); panel.add(textFieldUnits, "4, 6, fill, default"); textFieldUnits.setColumns(10); } { JLabel lblRemarks = new JLabel("Remarks"); panel.add(lblRemarks, "2, 8, right, default"); } contentPanel.setLayout(new BorderLayout(0, 0)); contentPanel.add(panel, BorderLayout.WEST); { textFieldRemarks = new JTextField(); panel.add(textFieldRemarks, "4, 8, fill, default"); textFieldRemarks.setColumns(10); } { JButton btnAdd = new JButton("Add"); btnAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SpecimenPartAttribute newAttribs = new SpecimenPartAttribute(); newAttribs.setAttributeType(comboBoxType.getSelectedItem().toString()); newAttribs.setAttributeValue(comboBoxValue.getSelectedItem().toString()); newAttribs.setAttributeUnits(textFieldUnits.getText()); newAttribs.setAttributeRemark(textFieldRemarks.getText()); newAttribs.setSpecimenPartId(parentPart); newAttribs.setAttributeDeterminer(Singleton.getSingletonInstance().getUserFullName()); parentPart.getAttributeCollection().add(newAttribs); SpecimenPartAttributeLifeCycle sls = new SpecimenPartAttributeLifeCycle(); try { sls.attachDirty(newAttribs); } catch (SaveFailedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ((AbstractTableModel) table.getModel()).fireTableDataChanged(); } }); panel.add(btnAdd, "4, 10"); } try { JLabel lblNewLabel = new JLabel(parentPart.getSpecimenId().getBarcode() + ":" + parentPart.getPartName() + " " + parentPart.getPreserveMethod() + " (" + parentPart.getLotCount() + ") Right click on table to edit attributes."); contentPanel.add(lblNewLabel, BorderLayout.NORTH); } catch (Exception e) { JLabel lblNewLabel = new JLabel("No Specimen"); contentPanel.add(lblNewLabel, BorderLayout.NORTH); } JComboBox comboBox = new JComboBox(); comboBox.addItem("caste"); JComboBox comboBox1 = new JComboBox(); for (int i = 0; i < Caste.getCasteValues().length; i++) { comboBox1.addItem(Caste.getCasteValues()[i]); } JScrollPane scrollPane = new JScrollPane(); table = new JTable(new SpecimenPartsAttrTableModel( (Collection<SpecimenPartAttribute>) parentPart.getAttributeCollection())); //table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(comboBox)); table.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnRow = ((JTable) e.getComponent()).getSelectedRow(); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnRow = ((JTable) e.getComponent()).getSelectedRow(); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }); popupMenu = new JPopupMenu(); JMenuItem mntmCloneRow = new JMenuItem("Edit Row"); mntmCloneRow.setMnemonic(KeyEvent.VK_E); mntmCloneRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { // Launch a dialog to edit the selected row. SpecimenPartAttribEditDialog popup = new SpecimenPartAttribEditDialog( ((SpecimenPartsAttrTableModel) table.getModel()).getRowObject(clickedOnRow)); popup.setVisible(true); } catch (Exception ex) { log.error(ex.getMessage()); JOptionPane.showMessageDialog(thisDialog, "Failed to edit a part attribute row. " + ex.getMessage()); } } }); popupMenu.add(mntmCloneRow); JMenuItem mntmDeleteRow = new JMenuItem("Delete Row"); mntmDeleteRow.setMnemonic(KeyEvent.VK_D); mntmDeleteRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (clickedOnRow >= 0) { ((SpecimenPartsAttrTableModel) table.getModel()).deleteRow(clickedOnRow); } } catch (Exception ex) { log.error(ex.getMessage()); JOptionPane.showMessageDialog(thisDialog, "Failed to delete a part attribute row. " + ex.getMessage()); } } }); popupMenu.add(mntmDeleteRow); // TODO: Enable controlled value editing of selected row. // table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox1)); scrollPane.setViewportView(table); contentPanel.add(scrollPane, BorderLayout.EAST); { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okButton.grabFocus(); thisDialog.setVisible(false); } }); okButton.setActionCommand("OK"); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } { JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { thisDialog.setVisible(false); } }); cancelButton.setActionCommand("Cancel"); buttonPane.add(cancelButton); } } }
From source file:com.mirth.connect.client.ui.NotificationDialog.java
private void initComponents() { setLayout(new MigLayout("insets 12", "[]", "[fill][]")); notificationPanel = new JPanel(); notificationPanel.setLayout(new MigLayout("insets 0 0 0 0, fill", "[200!][]", "[25!]0[]")); notificationPanel.setBackground(UIConstants.BACKGROUND_COLOR); archiveAll = new JLabel("Archive All"); archiveAll.setForeground(java.awt.Color.blue); archiveAll.setText("<html><u>Archive All</u></html>"); archiveAll.setToolTipText("Archive all notifications below."); archiveAll.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); newNotificationsLabel = new JLabel(); newNotificationsLabel.setFont(newNotificationsLabel.getFont().deriveFont(Font.BOLD)); headerListPanel = new JPanel(); headerListPanel.setBackground(UIConstants.HIGHLIGHTER_COLOR); headerListPanel.setLayout(new MigLayout("insets 2, fill")); headerListPanel.setBorder(BorderFactory.createLineBorder(borderColor)); list = new JList(); list.setCellRenderer(new NotificationListCellRenderer()); list.addListSelectionListener(new ListSelectionListener() { @Override/*from ww w .j a v a 2 s . co m*/ public void valueChanged(ListSelectionEvent event) { if (!event.getValueIsAdjusting()) { currentNotification = (Notification) list.getSelectedValue(); if (currentNotification != null) { notificationNameTextField.setText(currentNotification.getName()); contentTextPane.setText(currentNotification.getContent()); archiveSelected(); } } } }); listScrollPane = new JScrollPane(); listScrollPane.setBackground(UIConstants.BACKGROUND_COLOR); listScrollPane.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, borderColor)); listScrollPane.setViewportView(list); listScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); archiveLabel = new JLabel(); archiveLabel.setForeground(java.awt.Color.blue); archiveLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); notificationNameTextField = new JTextField(); notificationNameTextField.setFont(notificationNameTextField.getFont().deriveFont(Font.BOLD)); notificationNameTextField.setEditable(false); notificationNameTextField.setFocusable(false); notificationNameTextField.setBorder(BorderFactory.createEmptyBorder()); notificationNameTextField.setBackground(UIConstants.HIGHLIGHTER_COLOR); DefaultCaret nameCaret = (DefaultCaret) notificationNameTextField.getCaret(); nameCaret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); headerContentPanel = new JPanel(); headerContentPanel.setLayout(new MigLayout("insets 2, fill")); headerContentPanel.setBorder(BorderFactory.createLineBorder(borderColor)); headerContentPanel.setBackground(UIConstants.HIGHLIGHTER_COLOR); contentTextPane = new JTextPane(); contentTextPane.setContentType("text/html"); contentTextPane.setEditable(false); contentTextPane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { if (evt.getEventType() == EventType.ACTIVATED && Desktop.isDesktopSupported()) { try { if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse(evt.getURL().toURI()); } else { BareBonesBrowserLaunch.openURL(evt.getURL().toString()); } } catch (Exception e) { e.printStackTrace(); } } } }); DefaultCaret contentCaret = (DefaultCaret) contentTextPane.getCaret(); contentCaret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); contentScrollPane = new JScrollPane(); contentScrollPane.setViewportView(contentTextPane); contentScrollPane.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, borderColor)); archiveLabel.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { int index = list.getSelectedIndex(); if (currentNotification.isArchived()) { notificationModel.setArchived(false, index); unarchivedCount++; } else { notificationModel.setArchived(true, index); unarchivedCount--; } archiveSelected(); updateUnarchivedCountLabel(); } }); archiveAll.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { for (int i = 0; i < notificationModel.getSize(); i++) { notificationModel.setArchived(true, i); } unarchivedCount = 0; archiveSelected(); updateUnarchivedCountLabel(); } }); notificationCheckBox = new JCheckBox("Show new notifications on login"); notificationCheckBox.setBackground(UIConstants.BACKGROUND_COLOR); if (checkForNotifications == null || BooleanUtils.toBoolean(checkForNotifications)) { checkForNotificationsSetting = true; if (showNotificationPopup == null || BooleanUtils.toBoolean(showNotificationPopup)) { notificationCheckBox.setSelected(true); } else { notificationCheckBox.setSelected(false); } } else { notificationCheckBox.setSelected(false); } notificationCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (notificationCheckBox.isSelected() && !checkForNotificationsSetting) { alertSettingsChange(); } } }); closeButton = new JButton("Close"); closeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doSave(); } }); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { doSave(); } }); }
From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java
private void buildMenu() { JXTaskPane editPane = new JXTaskPane(); editPane.setTitle("Bearbeiten"); JXButton filterRetimes = new JXButton( new ImageIcon(DSWorkbenchTagFrame.class.getResource("/res/ui/filter_strength.png"))); filterRetimes.setToolTipText(//from w w w . j a v a 2s . c om "<html>Filtern der gefundenen ReTime Angriffe nach der bekannten Truppenstärke im Dorf<br/>" + "Es ist ratsam, vor der Filterung zu prüfen, ob die in DS Workbench importierten<br/>" + "Truppeninformationen aktuell sind. Nach der Filterung sind die Einträge markiert, welche die eingestellten<br/>" + "Filterbedingungen <b>NICHT</b> erfüllen, um sie direkt löschen zu können.</html>"); filterRetimes.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { showFilterDialog(); } }); editPane.getContentPane().add(filterRetimes); JXTaskPane miscPane = new JXTaskPane(); miscPane.setTitle("Sonstiges"); JXButton calculate = new JXButton( new ImageIcon(DSWorkbenchTagFrame.class.getResource("/res/ui/att_validate.png"))); calculate.setToolTipText("ReTime Angriffe fr den eingestellten Angriff berechnen"); calculate.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { startCalculation(); } }); miscPane.getContentPane().add(calculate); centerPanel.setupTaskPane(editPane, miscPane); }
From source file:net.panthema.BispanningGame.GamePanel.java
public GamePanel() throws IOException { makeActions();//from w w w . j av a2s .co m setBackground(Color.WHITE); ImageAlice = ImageIO.read( getClass().getClassLoader().getResourceAsStream("net/panthema/BispanningGame/images/Alice.png")); ImageBob = ImageIO.read( getClass().getClassLoader().getResourceAsStream("net/panthema/BispanningGame/images/Bob.png")); logTextArea = new JTextArea(); makeNewRandomGraph(8); mLayout = MyGraphLayoutFactory(mGraph); mVV = new VisualizationViewer<Integer, MyEdge>(mLayout); mVV.setSize(new Dimension(1000, 800)); mVV.setBackground(Color.WHITE); // Bob's play does not repeat. mPlayBob.setRepeats(false); // set up mouse handling PluggableGraphMouse gm = new PluggableGraphMouse(); gm.add(new MyEditingGraphMousePlugin<Integer, MyEdge>(MouseEvent.CTRL_MASK, new MyVertexFactory(), new MyEdgeFactory())); gm.add(new TranslatingGraphMousePlugin(MouseEvent.BUTTON3_MASK)); gm.add(new MyGraphMousePlugin(MouseEvent.BUTTON1_MASK | MouseEvent.BUTTON3_MASK)); gm.add(new PickingGraphMousePlugin<Integer, MyEdge>()); gm.add(new ScalingGraphMousePlugin(new LayoutScalingControl(), 0, 1.1f, 0.9f)); mVV.setGraphMouse(gm); // set vertex and label drawing mVV.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.black)); mVV.getRenderContext().setVertexLabelTransformer(new Transformer<Integer, String>() { public String transform(Integer v) { return "v" + v; } }); mVV.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Integer>()); mVV.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR); mVV.getRenderer().setEdgeRenderer(new MyEdgeRenderer()); mVV.getRenderContext().setVertexDrawPaintTransformer(new MyVertexDrawPaintTransformer<Integer>()); mVV.getRenderContext().setVertexFillPaintTransformer(new MyVertexFillPaintTransformer()); mVV.getRenderContext().setEdgeStrokeTransformer(new MyEdgeStrokeTransformer()); MyQuadCurve<Integer, MyEdge> quadcurve = new MyQuadCurve<Integer, MyEdge>(); mVV.getRenderContext().setEdgeShapeTransformer(quadcurve); mVV.getRenderContext().setParallelEdgeIndexFunction(quadcurve); mVV.getRenderContext().setEdgeDrawPaintTransformer(new MyEdgeDrawPaintTransformer()); mVV.getRenderContext().setEdgeFillPaintTransformer(new MyEdgeFillPaintTransformer()); mVV.getRenderContext().setEdgeArrowStrokeTransformer(new MyEdgeInnerStrokeTransformer()); mVV.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.black)); mVV.getRenderContext().setEdgeLabelTransformer(new Transformer<MyEdge, String>() { public String transform(MyEdge e) { return e.toString(); } }); mVV.getRenderContext().setLabelOffset(6); // create pick support to select closest nodes and edges mPickSupport = new ShapePickSupport<Integer, MyEdge>(mVV, mPickDistance); // add pre renderer to draw Alice and Bob mVV.addPreRenderPaintable(new MyGraphPreRenderer()); // add post renderer to show error messages in background mVV.addPostRenderPaintable(new MyGraphPostRenderer()); setLayout(new BorderLayout()); add(mVV, BorderLayout.CENTER); JPanel panelSouth = new JPanel(); add(panelSouth, BorderLayout.SOUTH); panelSouth.setLayout(new GridLayout(0, 2, 0, 0)); JPanel panelButtons = new JPanel(); panelSouth.add(panelButtons); panelButtons.setLayout(new GridLayout(2, 2, 0, 0)); panelSouth.setPreferredSize(new Dimension(800, 60)); final JButton btnNewRandomGraph = new JButton("New Random Graph"); btnNewRandomGraph.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JPopupMenu popup = new JPopupMenu(); for (int i = 0; i < actionRandomGraph.length; ++i) { if (actionRandomGraph[i] != null) popup.add(actionRandomGraph[i]); } popup.addSeparator(); popup.add(getActionNewGraphType()); popup.show(btnNewRandomGraph, e.getX(), e.getY()); } }); panelButtons.add(btnNewRandomGraph); final JButton btnNewNamedGraph = new JButton("New Named Graph"); btnNewNamedGraph.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JPopupMenu popup = new JPopupMenu(); for (int i = 0; i < actionNamedGraph.size(); ++i) { if (actionNamedGraph.get(i) != null) popup.add(actionNamedGraph.get(i)); } popup.show(btnNewNamedGraph, e.getX(), e.getY()); } }); panelButtons.add(btnNewNamedGraph); final JButton btnRelayout = new JButton("Relayout"); btnRelayout.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { relayoutGraph(); } }); panelButtons.add(btnRelayout); final JButton btnOptions = new JButton("Options"); btnOptions.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JPopupMenu popup = new JPopupMenu(); addPopupActions(popup); popup.addSeparator(); popup.show(btnOptions, e.getX(), e.getY()); } }); panelButtons.add(btnOptions); JScrollPane scrollPane = new JScrollPane(logTextArea); panelSouth.add(scrollPane); logTextArea.setEditable(false); setSize(new Dimension(1000, 800)); relayoutGraph(); }