List of usage examples for java.awt.event MouseListener MouseListener
MouseListener
From source file:self.philbrown.javaQuery.$.java
/** * Invokes the given Function for click events on each view in the current selection. * The function will receive two arguments: * <ol>//from w ww .ja v a2s . c o m * <li>a javaQuery containing the clicked view * <li>{@code eventData} * </ol> * @param eventData the second argument to pass to the {@code function} * @param function the function to invoke * @return */ public $ click(final Object eventData, final Function function) { for (final Component view : this.views) { view.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { function.invoke($.with(view), eventData); } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); } return this; }
From source file:self.philbrown.javaQuery.$.java
/** * Invokes the given Function every time each view in the current selection is long-clicked. * The only parameter passed to the given function a javaQuery instance with the long-clicked view. * @param function the function to call when this view is long-clicked * @return this//from ww w . j a v a 2 s. c om */ public $ dblclick(final Function function) { for (final Component view : this.views) { view.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) function.invoke($.with(view)); } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); } return this; }
From source file:self.philbrown.javaQuery.$.java
/** * Invokes the given Function for long-click events on the views in the current selection. * The function will receive two arguments: * <ol>/* ww w. ja v a2 s . c om*/ * <li>a javaQuery containing the long-clicked view * <li>{@code eventData} * </ol> * @param eventData the second argument to pass to the {@code function} * @param function the function to invoke * @return */ public $ dblclick(final Object eventData, final Function function) { for (final Component view : this.views) { view.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) function.invoke($.with(view), eventData); } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); } return this; }
From source file:lcmc.gui.resources.ServiceInfo.java
/** * Creates host score combo boxes with labels, one per host. *//*from ww w . j a v a2s .co m*/ protected void addHostLocations(final JPanel optionsPanel, final int leftWidth, final int rightWidth) { int rows = 0; final JPanel panel = getParamPanel(Tools.getString("ClusterBrowser.HostLocations")); panel.setLayout(new SpringLayout()); for (final Host host : getBrowser().getClusterHosts()) { final HostInfo hi = host.getBrowser().getHostInfo(); final Map<String, String> abbreviations = new HashMap<String, String>(); abbreviations.put("i", CRMXML.INFINITY_STRING); abbreviations.put("+", CRMXML.PLUS_INFINITY_STRING); abbreviations.put("I", CRMXML.INFINITY_STRING); abbreviations.put("a", "ALWAYS"); abbreviations.put("n", "NEVER"); final Widget wi = new Widget(null, new String[] { null, "0", "2", "ALWAYS", "NEVER", CRMXML.INFINITY_STRING, CRMXML.MINUS_INFINITY_STRING, CRMXML.INFINITY_STRING }, null, /* units */ null, /* type */ "^((-?\\d*|(-|\\+)?" + CRMXML.INFINITY_STRING + "))|ALWAYS|NEVER|@NOTHING_SELECTED@$", rightWidth, abbreviations, new AccessMode(ConfigData.AccessType.ADMIN, false)); wi.setEditable(true); final Widget prevWi = scoreComboBoxHash.get(hi); scoreComboBoxHash.put(hi, wi); /* set selected host scores in the combo box from * savedHostLocations */ if (prevWi == null) { final HostLocation hl = savedHostLocations.get(hi); String hsSaved = null; if (hl != null) { hsSaved = hl.getScore(); } wi.setValue(hsSaved); } else { wi.setValue(prevWi.getValue()); } } /* host score combo boxes */ for (Host host : getBrowser().getClusterHosts()) { final HostInfo hi = host.getBrowser().getHostInfo(); final Widget wi = scoreComboBoxHash.get(hi); String op = null; final HostLocation hl = savedHostLocations.get(hi); if (hl != null) { op = hl.getOperation(); } final String text = getHostLocationLabel(hi.getName(), op); final JLabel label = new JLabel(text); final String onText = getHostLocationLabel(hi.getName(), "eq"); final String notOnText = getHostLocationLabel(hi.getName(), "ne"); label.addMouseListener(new MouseListener() { @Override public final void mouseClicked(final MouseEvent e) { /* do nothing */ } @Override public final void mouseEntered(final MouseEvent e) { /* do nothing */ } @Override public final void mouseExited(final MouseEvent e) { /* do nothing */ } @Override public final void mousePressed(final MouseEvent e) { final String currentText = label.getText(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (currentText.equals(onText)) { label.setText(notOnText); } else if (currentText.equals(notOnText)) { label.setText(onText); } else { /* wierd things */ label.setText(onText); } final String[] params = getParametersFromXML(); setApplyButtons(CACHED_FIELD, params); } }); } @Override public final void mouseReleased(final MouseEvent e) { /* do nothing */ } }); wi.setLabel(label, ""); addField(panel, label, wi, leftWidth, rightWidth, 0); rows++; } rows += addPingField(panel, leftWidth, rightWidth); SpringUtilities.makeCompactGrid(panel, rows, 2, /* rows, cols */ 1, 1, /* initX, initY */ 1, 1); /* xPad, yPad */ optionsPanel.add(panel); }
From source file:Installer.java
public static JLabel linkify(final String text, String URL, String toolTip) { URI temp = null;/* w w w. j a v a 2 s . c o m*/ try { temp = new URI(URL); } catch (Exception e) { e.printStackTrace(); } final URI uri = temp; final JLabel link = new JLabel(); link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); if (!toolTip.equals("")) link.setToolTipText(toolTip); link.setCursor(new Cursor(Cursor.HAND_CURSOR)); link.addMouseListener(new MouseListener() { public void mouseExited(MouseEvent arg0) { link.setText("<HTML><FONT color=\"#000099\">" + text + "</FONT></HTML>"); } public void mouseEntered(MouseEvent arg0) { link.setText("<HTML><FONT color=\"#000099\"><U>" + text + "</U></FONT></HTML>"); } public void mouseClicked(MouseEvent arg0) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(uri); } catch (Exception e) { e.printStackTrace(); } } else { JOptionPane pane = new JOptionPane("Could not open link."); JDialog dialog = pane.createDialog(new JFrame(), ""); dialog.setVisible(true); } } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }); return link; }
From source file:org.sikuli.ide.SikuliIDE.java
private void initMsgPane(boolean atBottom) { msgPane = new JTabbedPane(); _console = new EditorConsolePane(); msgPane.addTab(_I("paneMessage"), null, _console, "DoubleClick to hide/unhide"); if (Settings.isWindows() || Settings.isLinux()) { msgPane.setBorder(BorderFactory.createEmptyBorder(5, 8, 5, 8)); }// ww w. j ava2 s. co m msgPane.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent me) { if (me.getClickCount() < 2) { return; } if (msgPaneCollapsed) { _mainSplitPane.setDividerLocation(_mainSplitPane.getLastDividerLocation()); msgPaneCollapsed = false; } else { int pos = _mainSplitPane.getWidth() - 35; if (prefs.getPrefMoreMessage() == PreferencesUser.HORIZONTAL) { pos = _mainSplitPane.getHeight() - 35; } _mainSplitPane.setDividerLocation(pos); msgPaneCollapsed = true; } } //<editor-fold defaultstate="collapsed" desc="mouse events not used"> @Override public void mousePressed(MouseEvent me) { } @Override public void mouseReleased(MouseEvent me) { } @Override public void mouseEntered(MouseEvent me) { } @Override public void mouseExited(MouseEvent me) { } //</editor-fold> }); }
From source file:base.BasePlayer.Main.java
void setButtons() { try {/* w w w .j a v a2s .c o m*/ // filemenu.setFont(font); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.NORTHWEST; c.insets = new Insets(1, 4, 4, 2); //c.insets = new Insets(5, 5, 2, 5); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; /* opensamples.setMargin(new Insets(0, 0, 0,0)); opensamples.setPreferredSize(buttonDimension); addtracks.setMargin(new Insets(0, 0, 0, 0)); addtracks.setPreferredSize(buttonDimension); addcontrols.setMargin(new Insets(0, 0, 0, 0)); addcontrols.setPreferredSize(buttonDimension); */ menubar.setOpaque(true); panel.add(menubar, c); c.gridx = 1; setbut = new JButton("", settingsIcon); setbut.setToolTipText("Settings"); setbut.setOpaque(false); setbut.setContentAreaFilled(false); setbut.setBackground(Main.panel.getBackground()); setbut.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { Settings.frame.setLocation( frame.getLocationOnScreen().x + frame.getWidth() / 2 - Settings.frame.getWidth() / 2, frame.getLocationOnScreen().y + frame.getHeight() / 6); Settings.frame.setState(JFrame.NORMAL); Settings.frame.setVisible(true); } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { setbut.setOpaque(true); Main.setbut.setBackground(Color.white); Main.setbut.revalidate(); } @Override public void mouseExited(MouseEvent e) { setbut.setOpaque(false); Main.setbut.revalidate(); } }); setbut.setBorder(null); c.insets = new Insets(0, 2, 0, 0); menubar.add(setbut, c); // c.gridx = 1; // c.gridx = 2; // c.gridx = 3; // zoomout.setMargin(new Insets(0, 0, 0, 0)); // panel.add(zoomout, c); /* JMenuItem empty2 = new JMenuItem(""); empty2.setEnabled(false); menubar.add(empty2); c.gridx = 4;*/ // chromosomeDropdown.setPreferredSize(buttonDimension); // panel.add(chromosomeDropdown, c); // c.gridx = 5; // back.setMargin(new Insets(0, 0, 0, 0)); // forward.setMargin(new Insets(0, 0, 0, 0)); // back.setPreferredSize(new Dimension(back.getFontMetrics(back.getFont()).stringWidth("<")+10,(int)fieldDimension.getHeight())); // forward.setPreferredSize(new Dimension(forward.getFontMetrics(forward.getFont()).stringWidth("<")+10,(int)fieldDimension.getHeight())); //back.setMinimumSize(new Dimension(back.getFontMetrics(back.getFont()).stringWidth("<")+10,(int)fieldDimension.getHeight())); // forward.setMinimumSize(new Dimension(forward.getFontMetrics(forward.getFont()).stringWidth("<")+10,(int)fieldDimension.getHeight())); // panel.add(back, c); // c.gridx = 7; // panel.add(forward, c); chromosomeDropdown.setMaximumRowCount(25); chromosomeDropdown.setEnabled(true); chromosomeDropdown.addActionListener(ChromoDropActionListener); chromosomeDropdown.addMouseListener(this); c.gridwidth = 10; c.gridx = 0; c.gridy = 1; bedScroll = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); bedScroll.getViewport().setPreferredSize(bedDimensions); drawScroll = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); drawScroll.getViewport().setPreferredSize(drawDimensions); chromScroll = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); chromScroll.getViewport().setPreferredSize(chromDimensions); drawScroll.getVerticalScrollBar().setAutoscrolls(false); // chromScroll.getViewport().setPreferredSize(new Dimension(drawWidth,chromHeight-20)); // drawScroll.setBorder(BorderFactory.createEmptyBorder()); //chromScroll.setBorder(BorderFactory.createLoweredBevelBorder()); // drawScroll.setBorder(BorderFactory.createLoweredBevelBorder()); // bedScroll.setBorder(BorderFactory.createLoweredBevelBorder()); // chromScroll.setBorder(BorderFactory.createEmptyBorder()); // bedScroll.setBorder(BorderFactory.createEmptyBorder()); controlScroll = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); controlScroll.getViewport().setPreferredSize(bedDimensions); controlScroll.getViewport().add(controlDraw); controlDraw.setVisible(false); controlScroll.setVisible(false); chromScroll.setBorder(BorderFactory.createEmptyBorder()); drawScroll.setBorder(BorderFactory.createEmptyBorder()); bedScroll.setBorder(BorderFactory.createLoweredBevelBorder()); controlScroll.setBorder(BorderFactory.createLoweredBevelBorder()); addSplit(chromosomeDropdown.getItemAt(0)); chromScroll.getViewport().add(chromDraw); drawScroll.getViewport().add(drawCanvas); drawScroll.addMouseListener(this); bedCanvas = new BedCanvas(drawWidth, 200); bedScroll.getViewport().add(bedCanvas); frame.setExtendedState(frame.getExtendedState() | JFrame.MAXIMIZED_BOTH); c.weightx = 1.0; c.weighty = 1.0; c.fill = GridBagConstraints.BOTH; trackPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, bedScroll, controlScroll); trackPane.setUI(new BasicSplitPaneUI() { public BasicSplitPaneDivider createDefaultDivider() { return new BasicSplitPaneDivider(this) { private static final long serialVersionUID = 1L; public void setBorder(Border b) { } @Override public void paint(Graphics g) { g.setColor(Color.lightGray); g.fillRect(0, 0, getSize().width, getSize().height); super.paint(g); } }; } }); trackPane.setBorder(null); trackPane.setDividerSize(0); trackPane.setPreferredSize(drawDimensions); trackPane.setResizeWeight(0.0); trackPane.setContinuousLayout(true); trackPane.setVisible(false); varpane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, trackPane, drawScroll); varpane.setUI(new BasicSplitPaneUI() { public BasicSplitPaneDivider createDefaultDivider() { return new BasicSplitPaneDivider(this) { private static final long serialVersionUID = 1L; public void setBorder(Border b) { } @Override public void paint(Graphics g) { g.setColor(Color.lightGray); g.fillRect(0, 0, getSize().width, getSize().height); super.paint(g); } }; } }); varpane.setBorder(null); varpane.setDividerSize(0); varpane.setPreferredSize(drawDimensions); varpane.setResizeWeight(0.0); varpane.setContinuousLayout(true); bedScroll.setVisible(false); controlScroll.setVisible(false); chrompan = new JPanel() { private static final long serialVersionUID = 1L; protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Draw.sidecolor); g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.setColor(Color.gray); g.fillRect(0, 0, 3, this.getHeight()); g.setColor(Color.lightGray); g.fillRect(2, 0, 2, this.getHeight()); } }; chrompan.setLayout(new GridBagLayout()); GridBagConstraints gb = new GridBagConstraints(); gb.anchor = GridBagConstraints.NORTHWEST; gb.insets = new Insets(2, 10, 2, 2); gb.gridx = 0; gb.gridy = 0; gb.gridwidth = 1; gb.fill = GridBagConstraints.HORIZONTAL; refDropdown.setBackground(Color.white); refDropdown.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.lightGray)); refDropdown.setBorder(BorderFactory.createCompoundBorder(refDropdown.getBorder(), BorderFactory.createEmptyBorder(0, 0, 0, 0))); geneDropdown.setBackground(Color.white); geneDropdown.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.lightGray)); geneDropdown.setBorder(BorderFactory.createCompoundBorder(geneDropdown.getBorder(), BorderFactory.createEmptyBorder(0, 0, 0, 0))); geneDropdown.addActionListener(annoDropActionListener); JLabel refLabel = new JLabel("Reference genome:"); JLabel geneLabel = new JLabel("Gene annotation:"); chromLabel.setName("header"); chrompan.add(chromLabel, gb); gb.gridy++; chrompan.add(new JSeparator(), gb); gb.gridy++; gb.insets = new Insets(0, 10, 0, 2); chrompan.add(refLabel, gb); gb.gridy++; chrompan.add(refDropdown, gb); gb.gridy++; chrompan.add(geneLabel, gb); gb.gridy++; chrompan.add(geneDropdown, gb); gb.gridy++; gb.insets = new Insets(20, 10, 0, 2); JLabel memory = new JLabel("Memory usage:"); memory.setName("header"); chrompan.add(memory, gb); gb.insets = new Insets(0, 10, 0, 2); gb.gridy++; chrompan.add(memLabel, gb); gb.weightx = 1; gb.weighty = 1; gb.gridwidth = GridBagConstraints.REMAINDER; chrompan.add(new JLabel(), gb); chrompan.setMinimumSize(new Dimension(1, 1)); chrompan.addComponentListener(this); upPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, chrompan, chromScroll); drawScroll.addComponentListener(this); //upPanel.setBorder(BorderFactory.createLoweredBevelBorder()); upPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.white)); upPanel.setDividerLocation(Main.sidebarWidth - 2); chrompan.setBackground(Draw.sidecolor); BasicSplitPaneUI chromPaneUI = (BasicSplitPaneUI) upPanel.getUI(); chromPaneDivider = chromPaneUI.getDivider(); chromPaneDivider.addMouseListener(this); upPanel.setDividerSize(3); upPanel.setUI(new BasicSplitPaneUI() { public BasicSplitPaneDivider createDefaultDivider() { return new BasicSplitPaneDivider(this) { private static final long serialVersionUID = 1L; public void setBorder(Border b) { } @Override public void paint(Graphics g) { g.setColor(Color.lightGray); g.fillRect(0, 0, getSize().width, getSize().height); super.paint(g); } }; } }); splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, upPanel, varpane); splitPane.setUI(new BasicSplitPaneUI() { public BasicSplitPaneDivider createDefaultDivider() { return new BasicSplitPaneDivider(this) { private static final long serialVersionUID = 1L; public void setBorder(Border b) { } @Override public void paint(Graphics g) { g.setColor(Color.lightGray); g.fillRect(0, 0, getSize().width, getSize().height); super.paint(g); } }; } }); BasicSplitPaneUI basicSplitPaneUI = (BasicSplitPaneUI) splitPane.getUI(); splitPaneDivider = basicSplitPaneUI.getDivider(); // splitPaneDivider.addMouseListener(this); basicSplitPaneUI = (BasicSplitPaneUI) trackPane.getUI(); trackPaneDivider = basicSplitPaneUI.getDivider(); // trackPaneDivider.addMouseListener(this); BasicSplitPaneUI splitPaneUI = (BasicSplitPaneUI) varpane.getUI(); varPaneDivider = splitPaneUI.getDivider(); // varPaneDivider.addMouseListener(this); splitPane.setDividerSize(3); splitPane.setPreferredSize(drawDimensions); splitPane.setContinuousLayout(true); panel.add(splitPane, c); add(panel, c); openvcfs.addActionListener(this); openbams.addActionListener(this); addtracks.addActionListener(this); addcontrols.addActionListener(this); openProject.addActionListener(this); saveProject.addActionListener(this); saveProjectAs.addActionListener(this); dosomething.addActionListener(this); clear.addActionListener(this); // drawScroll.getVerticalScrollBar().addMouseMotionListener(this); drawScroll.getVerticalScrollBar().addMouseListener(this); drawScroll.getVerticalScrollBar().addMouseMotionListener(this); drawScroll.getVerticalScrollBar().addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { Draw.setGlasspane(true); if (e.getWheelRotation() < 0) { if (drawCanvas.drawVariables.visiblestart > 0) { drawCanvas.drawVariables.visiblestart--; } Draw.setScrollbar((int) (drawCanvas.drawVariables.visiblestart * drawCanvas.drawVariables.sampleHeight)); } else { if (drawCanvas.drawVariables.visiblestart + drawCanvas.drawVariables.visiblesamples < Main.samples) { drawCanvas.drawVariables.visiblestart++; } Draw.setScrollbar((int) (drawCanvas.drawVariables.visiblestart * drawCanvas.drawVariables.sampleHeight)); } } } ); drawScroll.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent event) { //System.out.println(drawCanvas.drawVariables.visiblestart +" " +(short)(Main.drawScroll.getVerticalScrollBar().getValue()/drawCanvas.drawVariables.sampleHeight)); if (drawCanvas.drawVariables.visiblestart != (short) (Main.drawScroll.getVerticalScrollBar() .getValue() / drawCanvas.drawVariables.sampleHeight)) { if (!drawCanvas.sidebar) { drawCanvas.drawVariables.visiblestart = (short) (Main.drawScroll.getVerticalScrollBar() .getValue() / drawCanvas.drawVariables.sampleHeight); } if (drawCanvas.splits.size() > 1) { for (int i = 0; i < drawCanvas.splits.size(); i++) { drawCanvas.splits.get(i).updateReads = true; } } else { Draw.updateReads = true; Draw.updatevars = true; } Draw.updatevars = true; Main.drawCanvas.repaint(); } } }); zoomout.addActionListener(this); FileRead.head = new VarNode(0, (byte) 0, "N", (short) 0, (short) 0, false, (float) 0, (float) 0, null, null, new Sample("", (short) 1, null), null, null); drawCanvas.current = FileRead.head; frame.addComponentListener(this); frame.addMouseListener(this); frame.setGlassPane(glassPane); glassPane.setOpaque(false); glassPane.setVisible(false); positionField.setText("chr1:1-" + MethodLibrary.formatNumber(drawCanvas.splits.get(0).chromEnd)); positionField.setToolTipText("Current chromosomal region"); widthLabel.setText(MethodLibrary.formatNumber(drawCanvas.splits.get(0).chromEnd) + "bp"); widthLabel.setToolTipText("Current region width in base pairs"); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.yccheok.jstock.gui.MainFrame.java
private void createSystemTrayIcon() { if (SystemTray.isSupported()) { SystemTray tray = SystemTray.getSystemTray(); final Image image; if (Utils.isWindows7() || Utils.isWindows8()) { image = new javax.swing.ImageIcon(getClass().getResource("/images/128x128/chart.png")).getImage(); } else {/*from w ww . j ava2 s .co m*/ image = new javax.swing.ImageIcon(getClass().getResource("/images/16x16/chart.png")).getImage(); } MouseListener mouseListener = new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { MainFrame.this.setVisible(true); MainFrame.this.setState(Frame.NORMAL); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }; ActionListener exitListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MainFrame.this.setVisible(false); MainFrame.this.dispose(); } }; PopupMenu popup = new PopupMenu(); MenuItem defaultItem = new MenuItem( java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui").getString("MainFrame_Exit")); defaultItem.addActionListener(exitListener); popup.add(defaultItem); trayIcon = new TrayIcon(image, GUIBundle.getString("MainFrame_Application_Title"), popup); ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { } }; trayIcon.setImageAutoSize(true); trayIcon.addActionListener(actionListener); trayIcon.addMouseListener(mouseListener); try { tray.add(trayIcon); } catch (AWTException e) { trayIcon = null; JOptionPane.showMessageDialog(MainFrame.this, java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/messages") .getString("warning_message_trayicon_could_not_be_added"), java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/messages").getString( "warning_title_trayicon_could_not_be_added"), JOptionPane.WARNING_MESSAGE); } } else { // System Tray is not supported trayIcon = null; JOptionPane.showMessageDialog(MainFrame.this, java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/messages") .getString("warning_message_system_tray_is_not_supported"), java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/messages") .getString("warning_title_system_tray_is_not_supported"), JOptionPane.WARNING_MESSAGE); } }
From source file:org.yccheok.jstock.gui.JStock.java
private void createSystemTrayIcon() { if (SystemTray.isSupported()) { SystemTray tray = SystemTray.getSystemTray(); final Image image = new javax.swing.ImageIcon(getClass().getResource("/images/128x128/chart.png")) .getImage();//from w ww . j a va2 s . c o m MouseListener mouseListener = new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { JStock.this.setVisible(true); JStock.this.setState(Frame.NORMAL); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }; ActionListener exitListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JStock.this.setVisible(false); JStock.this.dispose(); } }; PopupMenu popup = new PopupMenu(); MenuItem defaultItem = new MenuItem( java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/gui").getString("MainFrame_Exit")); defaultItem.addActionListener(exitListener); popup.add(defaultItem); trayIcon = new TrayIcon(image, GUIBundle.getString("MainFrame_Application_Title"), popup); ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { } }; trayIcon.setImageAutoSize(true); trayIcon.addActionListener(actionListener); trayIcon.addMouseListener(mouseListener); try { tray.add(trayIcon); } catch (AWTException e) { trayIcon = null; JOptionPane.showMessageDialog(JStock.this, java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/messages") .getString("warning_message_trayicon_could_not_be_added"), java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/messages").getString( "warning_title_trayicon_could_not_be_added"), JOptionPane.WARNING_MESSAGE); } } else { // System Tray is not supported trayIcon = null; JOptionPane.showMessageDialog(JStock.this, java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/messages") .getString("warning_message_system_tray_is_not_supported"), java.util.ResourceBundle.getBundle("org/yccheok/jstock/data/messages") .getString("warning_title_system_tray_is_not_supported"), JOptionPane.WARNING_MESSAGE); } }
From source file:Form.Principal.java
public void PanelClientes() { int i = 0;/* w w w . j a v a 2 s .c om*/ int Altura = 0; Color gris = new Color(44, 44, 44); Color rojo = new Color(221, 76, 76); Color azul = new Color(0, 153, 255); try { //Consultamos todos los clientes ResultSet Comandos = Funcion.Select(st, "SELECT * FROM cliente;"); //Ciclo para crear un panel para cada uno while (Comandos.next()) { //Creamos un panel con alineacion a la izquierda JPanel Panel = new JPanel(); Panel.setLayout(null); jPanel8.add(Panel); //Tamao del panel Panel.setSize(700, 195); // La posicion y del panel ira incrementando para que no se encimen Altura = 30 + (i * 205); Panel.setLocation(50, Altura); Panel.setBackground(Color.white); Panel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); //Creamos label para mostrar los datos del cliente, el codigo html es para que al llegar al final del panel //se pase a la siguiente linea y para el margen izquierdo JLabel RFC = new JLabel(); RFC.setText("RFC: " + Comandos.getString("RFC")); JLabel Nombre = new JLabel(); Nombre.setText("Nombre: " + Comandos.getString("NombreCliente")); JTextArea Direccion = new JTextArea(); Direccion.setLineWrap(true); Direccion.setBorder(null); Direccion.setText("Direccin: " + Comandos.getString("Direccion")); JLabel Correo = new JLabel(); Correo.setText("Correo: " + Comandos.getString("correo")); JButton VerMas = new JButton(); VerMas.setText("Ver ms"); VerMas.setName(Comandos.getString("idCliente")); VerMas.setBackground(azul); JButton Eliminar = new JButton(); Eliminar.setText("Eliminar"); Eliminar.setName(Comandos.getString("idCliente")); Eliminar.setBackground(rojo); MouseListener mlVerMas = new MouseListener() { @Override public void mouseReleased(MouseEvent e) { //System.out.println("Released!"); } @Override public void mousePressed(MouseEvent e) { //System.out.println("Pressed!"); } @Override public void mouseExited(MouseEvent e) { //System.out.println("Exited!"); } @Override public void mouseEntered(MouseEvent e) { //System.out.println("Entered!"); e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } @Override public void mouseClicked(MouseEvent e) { JButton source = (JButton) e.getSource(); id = Integer.parseInt(source.getName()); jTabbedPane2.setSelectedIndex(4); jButton16.setVisible(true); jButton17.setVisible(true); jButtonEditar.setVisible(true); jPanel9.setVisible(true); jPanel10.setVisible(true); jPanel14.setVisible(false); LlenarPanel(); } }; VerMas.addMouseListener(mlVerMas); MouseListener mlEliminar = new MouseListener() { @Override public void mouseReleased(MouseEvent e) { //System.out.println("Released!"); } @Override public void mousePressed(MouseEvent e) { //System.out.println("Pressed!"); } @Override public void mouseExited(MouseEvent e) { //System.out.println("Exited!"); } @Override public void mouseEntered(MouseEvent e) { //System.out.println("Entered!"); e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } @Override public void mouseClicked(MouseEvent e) { JButton source = (JButton) e.getSource(); Funcion.Update(st, "DELETE FROM cliente WHERE idCliente = " + source.getName() + ";"); Autocompletar.removeAllItems(); Autocompletar = new TextAutoCompleter(jTextField2); ResultSet Comandos = Funcion.Select(st, "SELECT * FROM cliente;"); try { while (Comandos.next()) { Autocompletar.addItem(Comandos.getString("RFC")); } } catch (SQLException ex) { //Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex); } jPanel8.removeAll(); PanelClientes(); jPanel8.repaint(); } }; Eliminar.addMouseListener(mlEliminar); //Fuente del texto RFC.setFont(new Font("Verdana", Font.PLAIN, 14)); RFC.setForeground(gris); Nombre.setFont(new Font("Verdana", Font.PLAIN, 14)); Nombre.setForeground(gris); Direccion.setFont(new Font("Verdana", Font.PLAIN, 14)); Direccion.setForeground(gris); Correo.setFont(new Font("Verdana", Font.PLAIN, 14)); Correo.setForeground(gris); VerMas.setFont(new Font("Verdana", Font.PLAIN, 14)); VerMas.setForeground(Color.white); Eliminar.setFont(new Font("Verdana", Font.PLAIN, 14)); Eliminar.setForeground(Color.white); /*VERMAS.setFont(new Font("Verdana", Font.PLAIN, 13)); VERMAS.setForeground(azul);*/ //Aadimos los label al panel correspondiente del cliente Panel.add(RFC); Panel.add(Nombre); Panel.add(Direccion); Panel.add(Correo); Panel.add(VerMas); Panel.add(Eliminar); RFC.setLocation(30, 10); RFC.setSize(610, 30); Nombre.setLocation(30, 40); Nombre.setSize(610, 30); Direccion.setLocation(30, 75); Direccion.setSize(610, 40); Correo.setLocation(30, 115); Correo.setSize(610, 30); VerMas.setLocation(210, 150); VerMas.setSize(120, 35); Eliminar.setLocation(390, 150); Eliminar.setSize(120, 35); //Panel.add(VERMAS); i++; } } catch (SQLException ex) { Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex); } //Dependiendo de cuantos clientes se agregaron, se ajusta el tamao del panel principal para que el scroll llegue hasta ahi jPanel8.setPreferredSize(new Dimension(jPanel8.getWidth(), Altura + 205)); }