public void move() { Graphics g = canvas.getGraphics(); g.setColor(canvas.getBackground()); g.fillOval(x, y, XSIZE, YSIZE); x += dx; y += dy; Dimension d = canvas.getSize(); if (x < 0) { x = 0; dx = -dx; } if (x + XSIZE >= d.width) { x = d.width - XSIZE; dx = -dx; } if (y < 0) { y = 0; dy = -dy; } if (y + YSIZE >= d.height) { y = d.height - YSIZE; dy = -dy; } g.setColor(color); g.fillOval(x, y, XSIZE, YSIZE); g.dispose(); }
public Element toXML() { Element result = new Element("timer"); XMLUtil.createElement("title", getTitle(), result); XMLUtil.createElement("started", started == null ? "" : started.toString(), result); XMLUtil.createElement("total", period.toString(), result); XMLUtil.createElement("speed", update_speed, result); XMLUtil.createElement("x", getX(), result); XMLUtil.createElement("y", getY(), result); XMLUtil.createElement("width", getWidth(), result); XMLUtil.createElement("height", getHeight(), result); XMLUtil.createElement( "foreground", String.format("%08x", total.getForeground().getRGB()), result); XMLUtil.createElement( "background", String.format("%08x", panel.getBackground().getRGB()), result); XMLUtil.createElement("visible", isVisible(), result); Element times = new Element("times"); for (TimeSpan ts : this.times) { times.addContent(ts.toXML()); } result.addContent(times); return result; }
public void addGui(final DownloadDialog gui) { buildDownloadAreaInputFields(); final JPanel dlg = new JPanel(new GridBagLayout()); tfOsmUrl.getDocument().addDocumentListener(new OsmUrlRefresher()); // select content on receiving focus. this seems to be the default in the // windows look+feel but not for others. needs invokeLater to avoid strange // side effects that will cancel out the newly made selection otherwise. tfOsmUrl.addFocusListener(new SelectAllOnFocusHandler(tfOsmUrl)); tfOsmUrl.setLineWrap(true); tfOsmUrl.setBorder(latlon[0].getBorder()); dlg.add(new JLabel(tr("min lat")), GBC.std().insets(10, 20, 5, 0)); dlg.add(latlon[0], GBC.std().insets(0, 20, 0, 0)); dlg.add(new JLabel(tr("min lon")), GBC.std().insets(10, 20, 5, 0)); dlg.add(latlon[1], GBC.eol().insets(0, 20, 0, 0)); dlg.add(new JLabel(tr("max lat")), GBC.std().insets(10, 0, 5, 0)); dlg.add(latlon[2], GBC.std()); dlg.add(new JLabel(tr("max lon")), GBC.std().insets(10, 0, 5, 0)); dlg.add(latlon[3], GBC.eol()); dlg.add( new JLabel( tr("URL from www.openstreetmap.org (you can paste an URL here to download the area)")), GBC.eol().insets(10, 20, 5, 0)); dlg.add(tfOsmUrl, GBC.eop().insets(10, 0, 5, 0).fill()); tfOsmUrl.addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { checkPopup(e); } @Override public void mouseClicked(MouseEvent e) { checkPopup(e); } @Override public void mouseReleased(MouseEvent e) { checkPopup(e); } private void checkPopup(MouseEvent e) { if (e.isPopupTrigger()) { OsmUrlPopup popup = new OsmUrlPopup(); popup.show(tfOsmUrl, e.getX(), e.getY()); } } }); dlg.add(showUrl, GBC.eop().insets(10, 0, 5, 5)); showUrl.setEditable(false); showUrl.setBackground(dlg.getBackground()); showUrl.addFocusListener(new SelectAllOnFocusHandler(showUrl)); gui.addDownloadAreaSelector(dlg, tr("Bounding Box")); this.parent = gui; }
/** Mouse listener used to open JColorChooser dialog when colorPreview Panel is clicked */ public void mouseClicked(MouseEvent e) { // if(colorPreview_.getBackground().equals(Color.black)) colorPreview_.setBackground(Color.red); // else if(colorPreview_.getBackground().equals(Color.red)) // colorPreview_.setBackground(Color.blue); // else if(colorPreview_.getBackground().equals(Color.blue)) // colorPreview_.setBackground(Color.black); Color color = JColorChooser.showDialog( this, Messages.getString("EditOneVehicleControlPanel.color"), colorPreview_.getBackground()); if (color == null) colorPreview_.setBackground(Color.black); else colorPreview_.setBackground(color); }
private void initComponents() { btLogin.setFocusable(false); // Fókusz letiltása btSettings.setFocusable(false); // Fókusz letiltása btLogin.setBackground(Color.lightGray); // A "bejelentkezés" gomb háttérszÃnének beállÃtása btSettings.setBackground( pnLogin.getBackground()); // A "BeállÃtások" gomb háttérszÃnének beállÃtása tfUsername.setPreferredSize(new Dimension(120, 25)); // SzövegmezÅ‘ átméretezése pfPassword.setPreferredSize(new Dimension(120, 25)); // JelszómezÅ‘ átméretezése tfUsername.addKeyListener(btEnabler); // A figyelÅ‘ hozzáadása a felhasználónév mezÅ‘hÅ‘z pfPassword.addKeyListener(btEnabler); // A figyelÅ‘ hozzáadása a jelszó mezÅ‘hÅ‘z }
private void initComponents() { setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); messagePane.setBackground(contentPane.getBackground()); messagePane.setEditorKit(new HTMLEditorKit()); messagePane.setForeground(contentPane.getForeground()); setSize(450, 360); // center the window int x = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() - getWidth()) / 2; int y = (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() - getHeight()) / 2; setLocation(x, y); okButton.addActionListener(this); }
@Override public void stateMachineMetaGame(long timeout) throws TransitionDefinitionException, MoveDefinitionException, GoalDefinitionException { if (theCanvas == null) System.err.println("KioskGamer did not receive a canvas."); theCanvas.setStateMachine(getStateMachine()); theGUI = new GameGUI(theCanvas); theGUI.setRole(getRole()); theGUI.setBackground(theGUIPanel.getBackground()); theGUI.updateGameState(getStateMachine().getInitialState()); theGUI.addObserver(this); theGUIPanel.removeAll(); theGUIPanel.add("Center", theGUI); theGUIPanel.repaint(); theGUIPanel.setVisible(false); theGUIPanel.setVisible(true); theGUIPanel.validate(); theGUIPanel.repaint(); }
public ANOVAMatrixViewer(ANOVAMatrix matrix) { super(new BorderLayout()); JPanel infoPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); // info string JTextPane infoText = new JTextPane(); infoText.setEditable(false); infoText.setBackground(infoPanel.getBackground()); infoText.setFont(infoText.getFont().deriveFont(Font.BOLD)); infoText.setText( "A dark background indicates that the probability for non-difference between the groups is less than " + Tools.formatNumber(matrix.getSignificanceLevel())); infoPanel.add(infoText); infoPanel.setBorder(BorderFactory.createEtchedBorder()); add(infoPanel, BorderLayout.NORTH); // table ANOVAMatrixViewerTable table = new ANOVAMatrixViewerTable(matrix); table.setBorder(BorderFactory.createEtchedBorder()); add(new ExtendedJScrollPane(table), BorderLayout.CENTER); }
@Override public void actionPerformed(ActionEvent e) { Color color = display.getBackground(); int red = color.getRed(); int green = color.getGreen(); int blue = color.getBlue(); System.out.println("before"); System.out.println("red=" + red + ", green=" + green + ", blue=" + blue); Object source = e.getSource(); if (source.equals(redButton)) { red = red == 0 ? 255 : 0; } if (source.equals(greenButton)) { green = green == 0 ? 255 : 0; } if (source.equals(blueButton)) { blue = blue == 0 ? 255 : 0; } System.out.println("after"); System.out.println("red=" + red + ", green=" + green + ", blue=" + blue); Color setColor = new Color(red, green, blue); display.setBackground(setColor); }
private void initGui() { srsComboBoxLabel = new JLabel(); sridLabel = new JLabel(); DecimalFormat tileFormat = new DecimalFormat("##########"); tileFormat.setMaximumIntegerDigits(10); tileFormat.setMinimumIntegerDigits(1); sridText = new JFormattedTextField(tileFormat); srsNameLabel = new JLabel(); gmlSrsNameText = new JTextField(); descriptionLabel = new JLabel(); descriptionText = new JTextField(); newButton = new JButton(); applyButton = new JButton(); deleteButton = new JButton(); checkButton = new JButton(); checkButton.setEnabled(false); copyButton = new JButton(); fileLabel = new JLabel(); fileText = new JTextField(); browseFileButton = new JButton(); addFileButton = new JButton(); replaceWithFileButton = new JButton(); saveFileButton = new JButton(); dbSrsTypeLabel = new JLabel(); dbSrsTypeText = new JTextPane(); dbSrsNameLabel = new JLabel(); dbSrsNameText = new JTextPane(); srsComboBoxFactory = SrsComboBoxFactory.getInstance(config); srsComboBox = srsComboBoxFactory.createSrsComboBox(false); PopupMenuDecorator.getInstance() .decorate( sridText, gmlSrsNameText, descriptionText, fileText, dbSrsTypeText, dbSrsNameText); sridText.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (sridText.getValue() != null) { if (((Number) sridText.getValue()).intValue() < 0) sridText.setValue(0); else if (((Number) sridText.getValue()).intValue() > Integer.MAX_VALUE) sridText.setValue(Integer.MAX_VALUE); } } }); setLayout(new GridBagLayout()); contentsPanel = new JPanel(); contentsPanel.setBorder(BorderFactory.createTitledBorder("")); contentsPanel.setLayout(new GridBagLayout()); add(contentsPanel, GuiUtil.setConstraints(0, 0, 1.0, 0.0, GridBagConstraints.BOTH, 5, 0, 5, 0)); { JPanel srsPanel = new JPanel(); srsPanel.setLayout(new GridBagLayout()); gmlSrsNameText.setPreferredSize(gmlSrsNameText.getPreferredSize()); descriptionText.setPreferredSize(gmlSrsNameText.getPreferredSize()); srsComboBox.setPreferredSize(gmlSrsNameText.getPreferredSize()); srsPanel.add( sridLabel, GuiUtil.setConstraints( 0, 0, 0, 0, GridBagConstraints.BOTH, 0, BORDER_THICKNESS, 0, BORDER_THICKNESS)); srsPanel.add( sridText, GuiUtil.setConstraints( 1, 0, 1, 0, GridBagConstraints.HORIZONTAL, 0, BORDER_THICKNESS, 0, BORDER_THICKNESS)); srsPanel.add( checkButton, GuiUtil.setConstraints( 2, 0, 0, 0, GridBagConstraints.HORIZONTAL, 0, BORDER_THICKNESS, 0, BORDER_THICKNESS)); srsPanel.add( srsNameLabel, GuiUtil.setConstraints( 0, 1, 0, 0, GridBagConstraints.BOTH, BORDER_THICKNESS, BORDER_THICKNESS, 0, BORDER_THICKNESS)); srsPanel.add( gmlSrsNameText, GuiUtil.setConstraints( 1, 1, 2, 1, 1, 0, GridBagConstraints.HORIZONTAL, BORDER_THICKNESS, BORDER_THICKNESS, 0, BORDER_THICKNESS)); srsPanel.add( descriptionLabel, GuiUtil.setConstraints( 0, 2, 0, 0, GridBagConstraints.BOTH, BORDER_THICKNESS, BORDER_THICKNESS, 0, BORDER_THICKNESS)); srsPanel.add( descriptionText, GuiUtil.setConstraints( 1, 2, 2, 1, 1, 0, GridBagConstraints.HORIZONTAL, BORDER_THICKNESS, BORDER_THICKNESS, 0, BORDER_THICKNESS)); dbSrsTypeText.setEditable(false); dbSrsTypeText.setBorder(sridText.getBorder()); dbSrsTypeText.setBackground(srsPanel.getBackground()); dbSrsTypeText.setMargin(sridText.getMargin()); dbSrsNameText.setEditable(false); dbSrsNameText.setBorder(sridText.getBorder()); dbSrsNameText.setBackground(srsPanel.getBackground()); dbSrsNameText.setMargin(sridText.getMargin()); srsPanel.add( dbSrsNameLabel, GuiUtil.setConstraints( 0, 3, 0, 0, GridBagConstraints.HORIZONTAL, BORDER_THICKNESS, BORDER_THICKNESS, 0, BORDER_THICKNESS)); srsPanel.add( dbSrsNameText, GuiUtil.setConstraints( 1, 3, 2, 1, 1, 0, GridBagConstraints.BOTH, BORDER_THICKNESS, BORDER_THICKNESS, 0, BORDER_THICKNESS)); srsPanel.add( dbSrsTypeLabel, GuiUtil.setConstraints( 0, 4, 0, 0, GridBagConstraints.HORIZONTAL, BORDER_THICKNESS, BORDER_THICKNESS, BORDER_THICKNESS, BORDER_THICKNESS)); srsPanel.add( dbSrsTypeText, GuiUtil.setConstraints( 1, 4, 2, 1, 1, 0, GridBagConstraints.BOTH, BORDER_THICKNESS, BORDER_THICKNESS, BORDER_THICKNESS, BORDER_THICKNESS)); Box buttonsPanel = Box.createHorizontalBox(); buttonsPanel.add(applyButton); buttonsPanel.add(Box.createRigidArea(new Dimension(2 * BORDER_THICKNESS, 0))); buttonsPanel.add(newButton); buttonsPanel.add(Box.createRigidArea(new Dimension(2 * BORDER_THICKNESS, 0))); buttonsPanel.add(copyButton); buttonsPanel.add(Box.createRigidArea(new Dimension(2 * BORDER_THICKNESS, 0))); buttonsPanel.add(deleteButton); buttonsPanel.add(Box.createRigidArea(new Dimension(2 * BORDER_THICKNESS, 0))); GridBagConstraints c = GuiUtil.setConstraints( 0, 5, 3, 1, 1, 0, GridBagConstraints.NONE, BORDER_THICKNESS * 2, BORDER_THICKNESS, BORDER_THICKNESS, BORDER_THICKNESS); c.anchor = GridBagConstraints.CENTER; srsPanel.add(buttonsPanel, c); JPanel currentlySupportedContent = new JPanel(); currentlySupportedContent.setBorder(BorderFactory.createEmptyBorder()); currentlySupportedContent.setLayout(new GridBagLayout()); currentlySupportedContent.add( srsComboBoxLabel, GuiUtil.setConstraints(0, 0, 0.0, 1.0, GridBagConstraints.BOTH, 0, 5, 0, 5)); currentlySupportedContent.add( srsComboBox, GuiUtil.setConstraints(1, 0, 1.0, 1.0, GridBagConstraints.BOTH, 0, 5, 0, 5)); contentsPanel.add( currentlySupportedContent, GuiUtil.setConstraints(0, 0, 1.0, 0.0, GridBagConstraints.BOTH, 0, 0, 5, 0)); contentsPanel.add( srsPanel, GuiUtil.setConstraints(0, 1, 1.0, 0.0, GridBagConstraints.BOTH, 20, 0, 5, 0)); } impExpPanel = new JPanel(); impExpPanel.setBorder(BorderFactory.createTitledBorder("")); impExpPanel.setLayout(new GridBagLayout()); add(impExpPanel, GuiUtil.setConstraints(0, 1, 1.0, 0.0, GridBagConstraints.BOTH, 5, 0, 5, 0)); { JPanel browse = new JPanel(); JPanel button = new JPanel(); impExpPanel.add( browse, GuiUtil.setConstraints(0, 0, 1.0, 1.0, GridBagConstraints.BOTH, 0, 0, 0, 0)); impExpPanel.add( button, GuiUtil.setConstraints(0, 1, 0.0, 1.0, GridBagConstraints.BOTH, 5, 0, 5, 0)); fileText.setPreferredSize(fileText.getPreferredSize()); browse.setLayout(new GridBagLayout()); { browse.add( fileLabel, GuiUtil.setConstraints(0, 0, 1.0, 0.0, GridBagConstraints.HORIZONTAL, 5, 5, 0, 5)); browse.add( fileText, GuiUtil.setConstraints(0, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL, 0, 5, 5, 5)); browse.add( browseFileButton, GuiUtil.setConstraints(1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 5, 5, 5)); } button.setLayout(new GridBagLayout()); { button.add( addFileButton, GuiUtil.setConstraints(0, 0, 0, 0, GridBagConstraints.NONE, 5, 5, 5, 5)); button.add( replaceWithFileButton, GuiUtil.setConstraints(1, 0, 0, 0, GridBagConstraints.NONE, 5, 5, 5, 5)); button.add( saveFileButton, GuiUtil.setConstraints(2, 0, 0, 0, GridBagConstraints.NONE, 5, 20, 5, 5)); } } // influence focus policy checkButton.setFocusCycleRoot(false); srsComboBoxListener = new ActionListener() { public void actionPerformed(ActionEvent e) { displaySelectedValues(); } }; DropTarget dropTarget = new DropTarget(fileText, this); fileText.setDropTarget(dropTarget); impExpPanel.setDropTarget(dropTarget); srsComboBox.addActionListener(srsComboBoxListener); newButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (requestChange()) { DatabaseSrs refSys = DatabaseSrs.createDefaultSrs(); refSys.setDescription(getNewRefSysDescription()); refSys.setSupported(!dbPool.isConnected()); config.getProject().getDatabase().addReferenceSystem(refSys); updateSrsComboBoxes(false); srsComboBox.setSelectedItem(refSys); displaySelectedValues(); } } }); copyButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (requestChange()) { DatabaseSrs orig = srsComboBox.getSelectedItem(); DatabaseSrs copy = new DatabaseSrs(orig); copy.setDescription(getCopyOfDescription(orig)); config.getProject().getDatabase().addReferenceSystem(copy); updateSrsComboBoxes(false); srsComboBox.setSelectedItem(copy); displaySelectedValues(); } } }); applyButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { setSettings(); LOG.info("Settings successfully applied."); } }); deleteButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { DatabaseSrs refSys = srsComboBox.getSelectedItem(); int index = srsComboBox.getSelectedIndex(); String text = Language.I18N.getString("pref.db.srs.dialog.delete.msg"); Object[] args = new Object[] {refSys.getDescription()}; String formattedMsg = MessageFormat.format(text, args); if (JOptionPane.showConfirmDialog( getTopLevelAncestor(), formattedMsg, Language.I18N.getString("pref.db.srs.dialog.delete.title"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { config.getProject().getDatabase().getReferenceSystems().remove(refSys); updateSrsComboBoxes(false); srsComboBox.setSelectedIndex(index < srsComboBox.getItemCount() ? index : index - 1); displaySelectedValues(); } } }); checkButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { int srid = 0; try { srid = Integer.parseInt(sridText.getText().trim()); } catch (NumberFormatException nfe) { // } try { DatabaseSrs tmp = DatabaseSrs.createDefaultSrs(); tmp.setSrid(srid); dbPool.getActiveDatabaseAdapter().getUtil().getSrsInfo(tmp); if (tmp.isSupported()) { LOG.all(LogLevel.INFO, "SRID " + srid + " is supported."); LOG.all(LogLevel.INFO, "Database name: " + tmp.getDatabaseSrsName()); LOG.all(LogLevel.INFO, "SRS type: " + tmp.getType()); } else LOG.all(LogLevel.WARN, "SRID " + srid + " is NOT supported."); } catch (SQLException sqlEx) { LOG.error("Error while checking user-defined SRSs: " + sqlEx.getMessage().trim()); } } }); browseFileButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { browseReferenceSystemFile(Language.I18N.getString("pref.db.srs.label.file")); } }); addFileButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { importReferenceSystems(false); } }); replaceWithFileButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { importReferenceSystems(true); } }); saveFileButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { exportReferenceSystems(); } }); }
@Override public JComponent create(Object param) throws BadParameterException { if (param instanceof Canvas) { final Canvas canvas = (Canvas) param; final JScrollPane jsp = new JScrollPane(); final JPanel bar = new JPanel(new FlowLayout(FlowLayout.RIGHT)); JButton lastToken = new JButton(new ImageIcon(getClass().getResource(ICONS_PATH + "token.png"))); JPanel main = new JPanel(new BorderLayout()); jsp.setViewportView(Output.getInstance().getView((Canvas) param)); lastToken.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jsp.setViewportView(TokenOutput.getInstance().getView(canvas)); } }); lastToken.setBorder(new EmptyBorder(0, 0, 0, 0)); lastToken.setRolloverEnabled(true); lastToken.setBackground(bar.getBackground()); lastToken.setToolTipText("Tokens"); JButton errorReovery = new JButton( new ImageIcon(getClass().getResource(ICONS_PATH + "errorRecoveryStatus.png"))); errorReovery.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jsp.setViewportView(SyntaxErrorOutput.getInstance().getView(canvas)); } }); errorReovery.setBorder(new EmptyBorder(0, 0, 0, 0)); errorReovery.setRolloverEnabled(true); errorReovery.setBackground(bar.getBackground()); errorReovery.setToolTipText("Error Recovery"); JButton clear = new JButton(new ImageIcon(getClass().getResource(ICONS_PATH + "eraser.png"))); clear.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Output.getInstance().clear(); TokenOutput.getInstance().clear(); SyntaxErrorOutput.getInstance().clear(); } }); clear.setBorder(new EmptyBorder(0, 0, 0, 0)); clear.setRolloverEnabled(true); clear.setBackground(bar.getBackground()); clear.setToolTipText("Clear All"); JButton output = new JButton(new ImageIcon(getClass().getResource(ICONS_PATH + "output.png"))); output.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jsp.setViewportView(Output.getInstance().getView(canvas)); } }); output.setBorder(new EmptyBorder(0, 0, 0, 0)); output.setRolloverEnabled(true); output.setBackground(bar.getBackground()); output.setToolTipText("Output"); JButton saveReport = new JButton(new ImageIcon(getClass().getResource(ICONS_PATH + "html_report.png"))); saveReport.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Output.getInstance().saveReport(bar); } }); saveReport.setBorder(new EmptyBorder(0, 0, 0, 0)); saveReport.setRolloverEnabled(true); saveReport.setBackground(bar.getBackground()); saveReport.setToolTipText("Save an html report."); bar.add(output); bar.add(errorReovery); bar.add(lastToken); bar.add(clear); bar.add(saveReport); main.add(bar, BorderLayout.NORTH); main.add(jsp, BorderLayout.CENTER); return main; } else { throw new BadParameterException("Was Expecting a canvas as parameter."); } }
/** * Initializes and draws the dialog. * * @param parent the parent frame for this dialog. * @param sKey the property string associated with this message - used to set FormatProperties * when user ticks box. */ public UIHintDialog(JFrame parent, int nType) { super(parent, true); setTitle("Hint"); this.nType = nType; if (nType == PASTE_HINT) { this.sMessage = LanguageProperties.getString(LanguageProperties.DIALOGS_BUNDLE, "UIHintDialog.pasteHint1") + "\n\n" + LanguageProperties.getString( LanguageProperties.DIALOGS_BUNDLE, "UIHintDialog.pasteHint2") + "\n\n" + LanguageProperties.getString( LanguageProperties.DIALOGS_BUNDLE, "UIHintDialog.pasteHint3"); } oContentPane = getContentPane(); oContentPane.setLayout(new BorderLayout()); oDetailsPanel = new JPanel(new BorderLayout()); JPanel imagePanel = new JPanel(); imagePanel.setBorder(new EmptyBorder(10, 10, 10, 0)); oImage = UIImages.getNodeImage(ICoreConstants.POSITION); oImageLabel = new JLabel(oImage); oImageLabel.setVerticalAlignment(SwingConstants.TOP); imagePanel.add(oImageLabel); oDetailsPanel.add(imagePanel, BorderLayout.WEST); oTextArea = new JTextArea(sMessage); oTextArea.setEditable(false); oTextArea.setFont(new Font("Dialog", Font.PLAIN, 12)); // $NON-NLS-1$ oTextArea.setBackground(oDetailsPanel.getBackground()); oTextArea.setColumns(35); oTextArea.setLineWrap(true); oTextArea.setWrapStyleWord(true); oTextArea.setSize(oTextArea.getPreferredSize()); JPanel textPanel = new JPanel(); textPanel.setBorder(new EmptyBorder(10, 10, 20, 10)); textPanel.setBorder(new EmptyBorder(10, 10, 20, 10)); textPanel.add(oTextArea); JPanel oCheckBoxPanel = new JPanel(); cbShowPasteHint = new JCheckBox(); cbShowPasteHint.setText( LanguageProperties.getString(LanguageProperties.DIALOGS_BUNDLE, "UIHintDialog.hideHint")); cbShowPasteHint.setSelected(false); cbShowPasteHint.setHorizontalAlignment(SwingConstants.LEFT); oCheckBoxPanel.add(cbShowPasteHint); oDetailsPanel.add(textPanel, BorderLayout.CENTER); oDetailsPanel.add(oCheckBoxPanel, BorderLayout.SOUTH); oButtonPanel = new UIButtonPanel(); pbClose = new UIButton( LanguageProperties.getString( LanguageProperties.DIALOGS_BUNDLE, "UIHintDialog.closeButton")); // $NON-NLS-1$ pbClose.setMnemonic( LanguageProperties.getString( LanguageProperties.DIALOGS_BUNDLE, "UIHintDialog.closeButtonMnemonic") .charAt(0)); pbClose.addActionListener(this); oButtonPanel.addButton(pbClose); oContentPane.add(oDetailsPanel, BorderLayout.CENTER); oContentPane.add(oButtonPanel, BorderLayout.SOUTH); pack(); setResizable(false); }
/** * This method populates the ProjectSelector with all the subpanels and buttons * * @param main The object to notify when the ok button is pressed. */ public void populate(Object main) { this.main = main; // gather all projects String[] projects = getAllProjectNames(); if (projects == null) { Main.fatalError( "Cannot find the project folder. Please ensure that the framework is installed properly."); } Arrays.sort(projects); // sort the projects in ascending order this.addComponentListener( new ComponentListener() { int oldX = appConfig.projectSelectorWindowPosX, oldY = appConfig.projectSelectorWindowPosY; public void componentResized(ComponentEvent e) { if (ProjectSelector.this.getExtendedState() == JFrame.MAXIMIZED_BOTH) { appConfig.projectSelectorIsMaximized = true; appConfig.projectSelectorWindowPosX = oldX; appConfig.projectSelectorWindowPosY = oldY; } else { appConfig.projectSelectorIsMaximized = false; appConfig.projectSelectorWindowWidth = ProjectSelector.this.getWidth(); appConfig.projectSelectorWindowHeight = ProjectSelector.this.getHeight(); } customParameters.setSize( 100, customParameters .getHeight()); // needed to ensure that the text field shrinks as well } public void componentMoved(ComponentEvent e) { oldX = appConfig.projectSelectorWindowPosX; oldY = appConfig.projectSelectorWindowPosY; appConfig.projectSelectorWindowPosX = ProjectSelector.this.getX(); appConfig.projectSelectorWindowPosY = ProjectSelector.this.getY(); } public void componentShown(ComponentEvent e) {} public void componentHidden(ComponentEvent e) {} }); // safe the overal config file when the project selector closes this.addWindowListener( new WindowListener() { public void windowOpened(WindowEvent e) {} public void windowClosing(WindowEvent e) { appConfig.projectSelectorSelectedTab = 1 + right.getSelectedIndex(); appConfig.writeConfig(); } public void windowClosed(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowActivated(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} }); this.setLayout(new BorderLayout()); this.setResizable(true); if (appConfig.projectSelectorIsMaximized) { setExtendedState(JFrame.MAXIMIZED_BOTH); } this.setSize( new Dimension(appConfig.projectSelectorWindowWidth, appConfig.projectSelectorWindowHeight)); this.setLocation(appConfig.projectSelectorWindowPosX, appConfig.projectSelectorWindowPosY); JPanel left = new JPanel(); left.setLayout(new BorderLayout()); // List of all projects selection.setListData(projects); selection.setSelectedValue(appConfig.lastChosenProject, true); if (!selection.isSelectionEmpty()) { selectedProjectName = (String) selection.getSelectedValue(); } else { selectedProjectName = ""; } selection.addListSelectionListener(this); selection.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 0)); selection.setBackground(listPanel.getBackground()); listScroller = new JScrollPane(selection); listPanel.setLayout(new BorderLayout()); listScroller.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); listPanel.add(listScroller, BorderLayout.CENTER); listPanel.setBorder(BorderFactory.createTitledBorder("Available Projects")); left.add(listPanel, BorderLayout.CENTER); // OK / Cancel buttons buttonPanel.add(ok); buttonPanel.add(cancel); ok.addActionListener(this); cancel.addActionListener(this); buttonPanel.setPreferredSize(new Dimension(projectListWidth, 40)); left.add(buttonPanel, BorderLayout.SOUTH); this.add(left, BorderLayout.WEST); // right.setBorder(BorderFactory.createTitledBorder("Project Description & Configuration")); // The tab containing the description of the selected project JPanel description = new JPanel(); description.setLayout(new BorderLayout()); scrollableDescriptionPane = new JScrollPane(descriptionText); description.add(scrollableDescriptionPane); descriptionText.setEditable(false); descriptionText.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); int i = selection.getSelectedIndex(); if (i == -1) { // there was no defaultProject descriptionText.setText("Please select a project."); } else { generateGUIDescription(selectedProjectName); } right.addTab("Description", description); // The tab containing the config-file entries configuration.setLayout(new BoxLayout(configuration, BoxLayout.Y_AXIS)); scrollableConfigurationPane = new JScrollPane(frameworkConfigurationPanel); // increment the scroll speed (for some reason the speed for the scrollableConfigurationPane is // very low) scrollableConfigurationPane.getVerticalScrollBar().setUnitIncrement(15); frameworkConfigurationPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); configuration.add(scrollableConfigurationPane); JPanel bp = new JPanel(); bp.add(saveConfig); saveConfig.addActionListener(this); saveConfig.setMnemonic(java.awt.event.KeyEvent.VK_S); configuration.add(bp); expand = createFrameworkIconButton("expand", "expand.gif", "Show advanced settings"); collapse = createFrameworkIconButton("collapse", "collapse.gif", "Hide advanced settings"); customConfigurationPanel.setLayout(new BorderLayout()); JPanel mainCustomConfigurationPanel = new JPanel(); mainCustomConfigurationPanel.setLayout( new BoxLayout(mainCustomConfigurationPanel, BoxLayout.Y_AXIS)); mainCustomConfigurationPanel.add(customConfigurationPanel); // and the save button JPanel bp2 = new JPanel(); bp2.add(saveConfig2); saveConfig2.addActionListener(this); saveConfig2.setMnemonic(java.awt.event.KeyEvent.VK_S); mainCustomConfigurationPanel.add(bp2); right.addTab("Framework Config", configuration); right.addTab("Project Config", mainCustomConfigurationPanel); right.setMnemonicAt(0, java.awt.event.KeyEvent.VK_D); right.setMnemonicAt(1, java.awt.event.KeyEvent.VK_F); right.setMnemonicAt(2, java.awt.event.KeyEvent.VK_P); right.setSelectedIndex(appConfig.projectSelectorSelectedTab - 1); if (i == -1) { JTextField msg = new JTextField("Please select a project."); msg.setEditable(false); frameworkConfigurationPanel.add(msg); } else { generateGUIGonfiguration(selectedProjectName); } this.add(right, BorderLayout.CENTER); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.getRootPane().setDefaultButton(ok); this.setVisible(true); // this.setUndecorated(true); // GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this); }
public void stopBall() { Graphics g = canvas.getGraphics(); g.setColor(canvas.getBackground()); g.fillOval(x, y, XSIZE, YSIZE); stop = true; }
/** * An implemented <code>ActionListener</code> which performs all needed actions when a <code> * JButton</code> is clicked. * * @param e an <code>ActionEvent</code> */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if ("createRandom".equals(command)) { // $NON-NLS-1$ Renderer.getInstance().setShowVehicles(true); Runnable job = new Runnable() { public void run() { int i, j, k, l = 0; VanetSimStart.setProgressBar(true); int maxX = Map.getInstance().getMapWidth(); int maxY = Map.getInstance().getMapHeight(); int minSpeedValue = (int) Math.round(((Number) minSpeed_.getValue()).intValue() * 100000.0 / 3600); int maxSpeedValue = (int) Math.round(((Number) maxSpeed_.getValue()).intValue() * 100000.0 / 3600); int minCommDistValue = ((Number) minCommDist_.getValue()).intValue() * 100; int maxCommDistValue = ((Number) maxCommDist_.getValue()).intValue() * 100; int minWaitValue = ((Number) minWait_.getValue()).intValue(); int maxWaitValue = ((Number) maxWait_.getValue()).intValue(); int minBrakingValue = ((Number) minBraking_.getValue()).intValue(); int maxBrakingValue = ((Number) maxBraking_.getValue()).intValue(); int minAccelerationValue = ((Number) minAcceleration_.getValue()).intValue(); int maxAccelerationValue = ((Number) maxAcceleration_.getValue()).intValue(); int minTimeDistance = ((Number) minTimeDistance_.getValue()).intValue(); int maxTimeDistance = ((Number) maxTimeDistance_.getValue()).intValue(); int minPoliteness = ((Number) minPoliteness_.getValue()).intValue(); int maxPoliteness = ((Number) maxPoliteness_.getValue()).intValue(); int vehiclesDeviatingMaxSpeed = ((Number) vehiclesDeviatingMaxSpeed_.getValue()).intValue(); int deviationFromSpeedLimit = ((Number) deviationFromSpeedLimit_.getValue()).intValue(); // int deviationFromSpeedLimit = // (int)Math.round(((Number)deviationFromSpeedLimit_.getValue()).intValue() * // 100000.0/3600); int speedDeviation = 0; int wiFiValue = ((Number) wiFi_.getValue()).intValue(); int emergencyValue = ((Number) emergencyVehicle_.getValue()).intValue(); int speedRestriction = (int) Math.round( ((Number) speedStreetRestriction_.getValue()).intValue() * 100000.0 / 3600); int vehiclesFaking = ((Number) fakingVehicle_.getValue()).intValue(); if (wiFiValue < 0) { wiFiValue = 0; wiFi_.setValue(0); } else if (wiFiValue > 100) { wiFiValue = 100; wiFi_.setValue(100); } if (emergencyValue < 0) { emergencyValue = 0; emergencyVehicle_.setValue(0); } else if (emergencyValue > 100) { emergencyValue = 100; emergencyVehicle_.setValue(100); } if (vehiclesFaking < 0) { vehiclesFaking = 0; fakingVehicle_.setValue(0); } else if (vehiclesFaking > 100) { vehiclesFaking = 100; fakingVehicle_.setValue(100); } int amountValue = ((Number) amount_.getValue()).intValue(); boolean wiFiEnabled; boolean emergencyEnabled; boolean fakingEnabled; ArrayDeque<WayPoint> destinations = null; Vehicle tmpVehicle; Random random = new Random(); int tmpRandom = -1; // create the random vehicles. It may fail lots of times if the map is almost empty. // Then, possible less // vehicles are created than specified because it's only tried 4 x amountValue! for (i = 0; i < amountValue; ) { j = 0; k = 0; ++l; destinations = new ArrayDeque<WayPoint>(2); while (j < 2 && k < 20) { // if snapping fails more than 20 times break try { ++k; WayPoint tmpWayPoint = new WayPoint( random.nextInt(maxX), random.nextInt(maxY), getRandomRange(minWaitValue, maxWaitValue, random)); if (tmpWayPoint.getStreet().getSpeed() <= speedRestriction) { destinations.add(tmpWayPoint); ++j; } } catch (Exception e) { } } if (k < 20) { try { tmpRandom = getRandomRange(1, 100, random); if (tmpRandom <= vehiclesDeviatingMaxSpeed) speedDeviation = getRandomRange(-deviationFromSpeedLimit, deviationFromSpeedLimit, random); else speedDeviation = 0; if (getRandomRange(0, 99, random) < wiFiValue) wiFiEnabled = true; else wiFiEnabled = false; if (getRandomRange(0, 99, random) < emergencyValue) emergencyEnabled = true; else emergencyEnabled = false; if (getRandomRange(0, 99, random) < vehiclesFaking) fakingEnabled = true; else fakingEnabled = false; tmpVehicle = new Vehicle( destinations, ((Number) vehicleLength_.getValue()).intValue(), getRandomRange(minSpeedValue, maxSpeedValue, random), getRandomRange(minCommDistValue, maxCommDistValue, random), wiFiEnabled, emergencyEnabled, getRandomRange(minBrakingValue, maxBrakingValue, random), getRandomRange(minAccelerationValue, maxAccelerationValue, random), getRandomRange(minTimeDistance, maxTimeDistance, random), getRandomRange(minPoliteness, maxPoliteness, random), (int) Math.round(speedDeviation * 100000.0 / 3600), colorPreview_.getBackground(), fakingEnabled, fakeMessagesTypes_.getSelectedItem().toString()); Map.getInstance().addVehicle(tmpVehicle); ++i; } catch (Exception e) { } } if (l > amountValue * 4) break; } int errorLevel = 2; if (i < amountValue) errorLevel = 6; ErrorLog.log( Messages.getString("EditVehicleControlPanel.createdRandomVehicles") + i + " (" + amountValue + Messages.getString("EditVehicleControlPanel.requested"), errorLevel, getClass().getName(), "actionPerformed", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ VanetSimStart.setProgressBar(false); Renderer.getInstance().ReRender(false, false); // jobIsReady_ = true; } }; new Thread(job).start(); } // update GUI when vehicle type is selected else if ("comboBoxChanged".equals(command)) { if (((Component) e.getSource()).getName().equals("chooseVehicleType")) { VehicleType tmpVehicleType = (VehicleType) chooseVehicleType_.getSelectedItem(); if (tmpVehicleType != null) { maxSpeed_.setValue((int) Math.round(tmpVehicleType.getMaxSpeed() / (100000.0 / 3600))); vehicleLength_.setValue(tmpVehicleType.getVehicleLength()); maxCommDist_.setValue((int) Math.round(tmpVehicleType.getMaxCommDist() / 100)); maxWait_.setValue((int) tmpVehicleType.getMaxWaittime()); maxBraking_.setValue((int) tmpVehicleType.getMaxBrakingRate()); maxAcceleration_.setValue((int) tmpVehicleType.getMaxAccelerationRate()); maxTimeDistance_.setValue((int) tmpVehicleType.getMaxTimeDistance()); maxPoliteness_.setValue((int) tmpVehicleType.getMaxPoliteness()); minSpeed_.setValue((int) Math.round(tmpVehicleType.getMinSpeed() / (100000.0 / 3600))); minCommDist_.setValue((int) Math.round(tmpVehicleType.getMinCommDist() / 100)); minWait_.setValue((int) tmpVehicleType.getMinWaittime()); minBraking_.setValue((int) tmpVehicleType.getMinBrakingRate()); minAcceleration_.setValue((int) tmpVehicleType.getMinAccelerationRate()); minTimeDistance_.setValue((int) tmpVehicleType.getMinTimeDistance()); minPoliteness_.setValue((int) tmpVehicleType.getMinPoliteness()); vehiclesDeviatingMaxSpeed_.setValue((int) tmpVehicleType.getVehiclesDeviatingMaxSpeed_()); deviationFromSpeedLimit_.setValue( (int) Math.round(tmpVehicleType.getDeviationFromSpeedLimit_() / (100000.0 / 3600))); colorPreview_.setBackground(new Color(tmpVehicleType.getColor())); } } else if (((Component) e.getSource()).getName().equals("fakeMessagesTypes")) { } } // delete all Vehicles else if ("clearVehicles".equals(command)) { if (JOptionPane.showConfirmDialog( null, Messages.getString("EditVehicleControlPanel.msgBoxClearAll"), "", JOptionPane.YES_NO_OPTION) == 0) { Map.getInstance().clearVehicles(); Renderer.getInstance().ReRender(true, false); } } else if ("speed".equals(command) || "communication distance".equals(command) || "wait time".equals(command) || "braking rate".equals(command) || "acceleration".equals(command) || "time distance".equals(command) || "politeness".equals(command) || "vehicles deviating speed".equals(command) || "speed deviation".equals(command) || "length".equals(command) || "wifi amount".equals(command) || "emergency amount".equals(command) || "faking amount".equals(command) || "amount".equals(command)) { ResearchSeriesDialog.getInstance().hideResearchWindow(false, "vehicles", command); ResearchSeriesDialog.getInstance().setVisible(true); } else if ("applyToScenarioCreator".equals(command)) { ResearchSeriesDialog.getInstance().hideResearchWindow(false, "allVehicleProperties", "all"); int minSpeedValue = (int) Math.round(((Number) minSpeed_.getValue()).intValue() * 100000.0 / 3600); int maxSpeedValue = (int) Math.round(((Number) maxSpeed_.getValue()).intValue() * 100000.0 / 3600); int minCommDistValue = ((Number) minCommDist_.getValue()).intValue() * 100; int maxCommDistValue = ((Number) maxCommDist_.getValue()).intValue() * 100; int minWaitValue = ((Number) minWait_.getValue()).intValue(); int maxWaitValue = ((Number) maxWait_.getValue()).intValue(); int minBrakingValue = ((Number) minBraking_.getValue()).intValue(); int maxBrakingValue = ((Number) maxBraking_.getValue()).intValue(); int minAccelerationValue = ((Number) minAcceleration_.getValue()).intValue(); int maxAccelerationValue = ((Number) maxAcceleration_.getValue()).intValue(); int minTimeDistance = ((Number) minTimeDistance_.getValue()).intValue(); int maxTimeDistance = ((Number) maxTimeDistance_.getValue()).intValue(); int minPoliteness = ((Number) minPoliteness_.getValue()).intValue(); int maxPoliteness = ((Number) maxPoliteness_.getValue()).intValue(); int vehiclesDeviatingMaxSpeed = ((Number) vehiclesDeviatingMaxSpeed_.getValue()).intValue(); int deviationFromSpeedLimit = ((Number) deviationFromSpeedLimit_.getValue()).intValue(); // int deviationFromSpeedLimit = // (int)Math.round(((Number)deviationFromSpeedLimit_.getValue()).intValue() * 100000.0/3600); // int speedDeviation = 0; int wiFiValue = ((Number) wiFi_.getValue()).intValue(); int emergencyValue = ((Number) emergencyVehicle_.getValue()).intValue(); int speedRestriction = (int) Math.round( ((Number) speedStreetRestriction_.getValue()).intValue() * 100000.0 / 3600); int vehiclesFaking = ((Number) fakingVehicle_.getValue()).intValue(); if (wiFiValue < 0) { wiFiValue = 0; wiFi_.setValue(0); } else if (wiFiValue > 100) { wiFiValue = 100; wiFi_.setValue(100); } if (emergencyValue < 0) { emergencyValue = 0; emergencyVehicle_.setValue(0); } else if (emergencyValue > 100) { emergencyValue = 100; emergencyVehicle_.setValue(100); } if (vehiclesFaking < 0) { vehiclesFaking = 0; fakingVehicle_.setValue(0); } else if (vehiclesFaking > 100) { vehiclesFaking = 100; fakingVehicle_.setValue(100); } int amountValue = ((Number) amount_.getValue()).intValue(); ResearchSeriesDialog.getInstance() .getActiveVehicleSet_() .setData( ((Number) vehicleLength_.getValue()).intValue(), minSpeedValue, maxSpeedValue, minCommDistValue, maxCommDistValue, minWaitValue, maxWaitValue, minBrakingValue, maxBrakingValue, minAccelerationValue, maxAccelerationValue, minTimeDistance, maxTimeDistance, minPoliteness, maxPoliteness, wiFiValue, emergencyValue, vehiclesFaking, fakeMessagesTypes_.getSelectedItem().toString(), amountValue, speedRestriction, vehiclesDeviatingMaxSpeed, deviationFromSpeedLimit, colorPreview_.getBackground()); ResearchSeriesDialog.getInstance().setVisible(true); } else if ("openTypeDialog".equals(command)) { // $NON-NLS-1$ new VehicleTypeDialog(); } }
public MultipleChoice(boolean singleSelection, String question, String[] options) { super(new BorderLayout(5, 5)); if (options == null) { options = new String[4]; options[0] = "A."; options[1] = "B."; options[2] = "C."; options[3] = "D."; } int n = options.length; scripts = new String[n]; Arrays.fill(scripts, ""); if (singleSelection) { invisibleButton = new JToggleButton(); buttonGroup = new ButtonGroup(); buttonGroup.add(invisibleButton); choices = new JRadioButton[n]; for (int i = 0; i < n; i++) { choices[i] = new JRadioButton(options[i]); choices[i].addItemListener(itemListener); buttonGroup.add(choices[i]); } } else { choices = new JCheckBox[n]; for (int i = 0; i < n; i++) { choices[i] = new JCheckBox(options[i]); choices[i].addItemListener(itemListener); } } questionBody = new BasicPageTextBox() { public void createPopupMenu() {} public JPopupMenu getPopupMenu() { return null; } }; questionBody.setText(question); questionBody.setEditable(false); questionBody.addMouseListener(popupListener); add(questionBody, BorderLayout.NORTH); choicePanel = new JPanel(); layChoices(); add(choicePanel, BorderLayout.CENTER); buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); questionBody.setBackground(buttonPanel.getBackground()); add(buttonPanel, BorderLayout.SOUTH); String s = Modeler.getInternationalText("CheckAnswer"); checkAnswerButton = new JButton(s != null ? s : "Check Answer"); checkAnswerButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { boolean selected = false; for (int i = 0; i < choices.length; i++) { if (choices[i].isSelected()) { selected = true; break; } } if (!selected) { String s = Modeler.getInternationalText("YouHaveNotChosenAnswer"); JOptionPane.showMessageDialog( MultipleChoice.this, s != null ? s : "You haven't chosen your answer.", "Error", JOptionPane.ERROR_MESSAGE); return; } if (answer == null) { String s = Modeler.getInternationalText("QuestionDesignerDidNotProvideAnswer"); JOptionPane.showMessageDialog( MultipleChoice.this, s != null ? s : "The question designer didn't provide an answer.", "Answer unknown", JOptionPane.ERROR_MESSAGE); } else { if (getSingleSelection()) { int[] selectedIndices = getUserSelectedIndices(); if (selectedIndices != null && selectedIndices.length == 1) { int si = selectedIndices[0]; notifyAnswerChecked(new MultipleChoiceEvent(MultipleChoice.this, si)); boolean b = si == answer[0]; if (b) { if (hasNoScripts()) { String s = Modeler.getInternationalText("Correct"); JOptionPane.showMessageDialog( MultipleChoice.this, s != null ? s : "Correct!", "Answer", JOptionPane.INFORMATION_MESSAGE); } } else { if (hasNoScripts()) { String s = Modeler.getInternationalText("TryAgain"); JOptionPane.showMessageDialog( MultipleChoice.this, s != null ? s : "Try again!", "Answer", JOptionPane.INFORMATION_MESSAGE); } for (int i = 0; i < choices.length; i++) { if (choices[i].isSelected()) { addCheckAnswerHistory((char) ('a' + i) + ""); break; } } } } } else { // multiple selection boolean b = true; boolean p; for (int i = 0; i < choices.length; i++) { p = false; for (int j = 0; j < answer.length; j++) { if (answer[j] == i) { p = true; break; } } if ((p && !choices[i].isSelected()) || (!p && choices[i].isSelected())) { b = false; break; } } notifyAnswerChecked(new MultipleChoiceEvent(MultipleChoice.this, b)); if (b) { if (hasNoScripts()) { String s = Modeler.getInternationalText("Correct"); JOptionPane.showMessageDialog( MultipleChoice.this, s != null ? s : "Correct!", "Answer", JOptionPane.INFORMATION_MESSAGE); } } else { if (hasNoScripts()) { String s = Modeler.getInternationalText("TryAgain"); JOptionPane.showMessageDialog( MultipleChoice.this, s != null ? s : "Try again!", "Answer", JOptionPane.INFORMATION_MESSAGE); } String s = ""; char c = 'a'; for (int i = 0; i < choices.length; i++) { if (choices[i].isSelected()) { s += (char) (c + i) + " "; } } if (!s.equals("")) addCheckAnswerHistory(s.trim()); } } } } }); buttonPanel.add(checkAnswerButton); s = Modeler.getInternationalText("ClearAnswer"); clearAnswerButton = new JButton(s != null ? s : "Clear Answer"); clearAnswerButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { clearAnswer(); } }); }
protected void actionBackground() { Color color = JColorChooser.showDialog(this, "Background", panel.getBackground()); if (color != null) { panel.setBackground(color); } }
private void initGUI() { try { { GridBagLayout thisLayout = new GridBagLayout(); thisLayout.rowWeights = new double[] {0.0, 0.1}; thisLayout.rowHeights = new int[] {267, 7}; thisLayout.columnWeights = new double[] {0.0, 0.1, 0.1}; thisLayout.columnWidths = new int[] {154, 7, 7}; getContentPane().setLayout(thisLayout); { pnButtons = new JPanel(); FlowLayout pnButtonsLayout = new FlowLayout(); pnButtonsLayout.setAlignment(FlowLayout.LEFT); pnButtons.setLayout(pnButtonsLayout); getContentPane() .add( pnButtons, new GridBagConstraints( 0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { btOK = new JButton( Messages.getMessage(getLocale(), "$MD11617"), IconRegistry.getIcon("accept.png")); pnButtons.add(btOK); btOK.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { createArc(); drawingPane.getDrawObjectsAsGeoPoints().clear(); digitizerModule.getMapModule().update(); } }); } { btCancel = new JButton( Messages.getMessage(getLocale(), "$MD11618"), IconRegistry.getIcon("cancel.png")); pnButtons.add(btCancel); btCancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); } } { pnHelp = new JPanel(); FlowLayout pnHelpLayout = new FlowLayout(); pnHelpLayout.setAlignment(FlowLayout.RIGHT); pnHelp.setLayout(pnHelpLayout); getContentPane() .add( pnHelp, new GridBagConstraints( 2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { btHelp = new JButton( Messages.getMessage(getLocale(), "$MD11619"), IconRegistry.getIcon("help.png")); pnHelp.add(btHelp); } } { pnDescription = new JPanel(); BorderLayout pnDescriptionLayout = new BorderLayout(); pnDescription.setLayout(pnDescriptionLayout); getContentPane() .add( pnDescription, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnDescription.setBorder( BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11620"))); { tpDescription = new JTextPane(); pnDescription.add(tpDescription, BorderLayout.CENTER); tpDescription.setBackground(pnDescription.getBackground()); tpDescription.setEditable(false); tpDescription.setContentType("text/html"); tpDescription.setText(Messages.getMessage(getLocale(), "$MD11621")); } } { pnControl = new JPanel(); GridBagLayout pnControlLayout = new GridBagLayout(); getContentPane() .add( pnControl, new GridBagConstraints( 1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnControl.setBorder( BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11622"))); pnControlLayout.rowWeights = new double[] {0.0, 0.0, 0.1}; pnControlLayout.rowHeights = new int[] {63, 109, 20}; pnControlLayout.columnWeights = new double[] {0.1}; pnControlLayout.columnWidths = new int[] {7}; pnControl.setLayout(pnControlLayout); { pnArc = new JPanel(); GridBagLayout pnArcLayout = new GridBagLayout(); pnControl.add( pnArc, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnArc.setBorder( BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11623"))); pnArcLayout.rowWeights = new double[] {0.1}; pnArcLayout.rowHeights = new int[] {7}; pnArcLayout.columnWeights = new double[] {0.1}; pnArcLayout.columnWidths = new int[] {7}; pnArc.setLayout(pnArcLayout); { spArc = new JSpinner(new SpinnerNumberModel(0, -181, 181, 0.5)); pnArc.add( spArc, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 9), 0, 0)); spArc.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { applyArc(); } }); } } { pnRadius = new JPanel(); GridBagLayout pnRadiusLayout = new GridBagLayout(); pnControl.add( pnRadius, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); pnRadius.setBorder( BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11624"))); pnRadiusLayout.rowWeights = new double[] {0.0, 0.1}; pnRadiusLayout.rowHeights = new int[] {43, 20}; pnRadiusLayout.columnWeights = new double[] {0.1}; pnRadiusLayout.columnWidths = new int[] {7}; pnRadius.setLayout(pnRadiusLayout); { spArcRadius = new JSpinner(new SpinnerNumberModel(1d, 0.0001, 999999999, 0.5)); pnRadius.add( spArcRadius, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 9), 0, 0)); spArcRadius.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { applyRadius(); } }); } { pnUOM = new JPanel(); FlowLayout pnUOMLayout = new FlowLayout(); pnUOMLayout.setAlignment(FlowLayout.LEFT); pnUOMLayout.setHgap(9); pnUOMLayout.setVgap(10); pnUOM.setLayout(pnUOMLayout); pnRadius.add( pnUOM, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); { lbUOM = new JLabel(Messages.getMessage(getLocale(), "$MD11625")); pnUOM.add(lbUOM); lbUOM.setPreferredSize(new Dimension(102, 16)); } { String tmp = Messages.getMessage(getLocale(), "$MD11626"); cbUOM = new JComboBox(new DefaultComboBoxModel(tmp.split(","))); pnUOM.add(cbUOM); cbUOM.setPreferredSize(new Dimension(136, 22)); } } } { pnRotation = new JPanel(); GridBagLayout pnRotationLayout = new GridBagLayout(); pnControl.add( pnRotation, new GridBagConstraints( 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 0, 0, 0, 0), 0, 0)); pnRotation.setBorder( BorderFactory.createTitledBorder(Messages.getMessage(getLocale(), "$MD11627"))); pnRotationLayout.rowWeights = new double[] {0.1}; pnRotationLayout.rowHeights = new int[] {7}; pnRotationLayout.columnWeights = new double[] {0.1}; pnRotationLayout.columnWidths = new int[] {7}; pnRotation.setLayout(pnRotationLayout); { spNoOfVertices = new JSpinner(new SpinnerNumberModel(10, 5, 1000, 1)); pnRotation.add( spNoOfVertices, new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 9, 0, 9), 0, 0)); } } } } this.setSize(457, 339); } catch (Exception e) { e.printStackTrace(); } }
private void initializeComponents() { this.setTitle("Configuration"); this.setResizable(false); setLayout(new BorderLayout(20, 20)); JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.X_AXIS)); mainPanel.setBorder(new LineBorder(mainPanel.getBackground(), 10)); add(mainPanel, BorderLayout.CENTER); GridBagConstraints labelConstraints = new GridBagConstraints(); labelConstraints.gridx = 0; labelConstraints.anchor = GridBagConstraints.WEST; labelConstraints.insets = new Insets(5, 5, 5, 5); GridBagConstraints inputConstraints = new GridBagConstraints(); inputConstraints.gridx = 1; inputConstraints.anchor = GridBagConstraints.EAST; inputConstraints.weightx = 1; inputConstraints.insets = new Insets(5, 5, 5, 5); JPanel evolutionOptionsPanel = new JPanel(); evolutionOptionsPanel.setBorder(new TitledBorder("Evolution")); evolutionOptionsPanel.setLayout(new BoxLayout(evolutionOptionsPanel, BoxLayout.Y_AXIS)); mainPanel.add(evolutionOptionsPanel); // world size JPanel worldSizePanel = new JPanel(new GridBagLayout()); evolutionOptionsPanel.add(worldSizePanel); JLabel worldSizeLabel = new JLabel("World Size"); worldSizeLabel.setToolTipText("Size of the world in pixels. Width x Height."); worldSizePanel.add(worldSizeLabel, labelConstraints); JPanel worldSizeInputPanel = new JPanel(); worldSizeInputPanel.setLayout(new GridBagLayout()); final AutoSelectOnFocusSpinner worldSizeWidthSpinner = new AutoSelectOnFocusSpinner( new SpinnerNumberModel(config.getDimension().width, 1, Integer.MAX_VALUE, 1)); final AutoSelectOnFocusSpinner worldSizeHeightSpinner = new AutoSelectOnFocusSpinner( new SpinnerNumberModel(config.getDimension().height, 1, Integer.MAX_VALUE, 1)); worldSizeInputPanel.add(worldSizeWidthSpinner); JLabel separatorLabel = new JLabel("x"); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(0, 5, 0, 5); worldSizeInputPanel.add(separatorLabel, c); worldSizeInputPanel.add(worldSizeHeightSpinner); worldSizePanel.add(worldSizeInputPanel, inputConstraints); // starting energy JPanel startingEnergyPanel = new JPanel(new GridBagLayout()); evolutionOptionsPanel.add(startingEnergyPanel); JLabel startingEnergyLabel = new JLabel("Starting Energy"); startingEnergyLabel.setToolTipText( "<html>The amount of energy all newly painted pixels start out with.<br />Note that changing this will not affect already painted pixels.</html>"); startingEnergyPanel.add(startingEnergyLabel, labelConstraints); final AutoSelectOnFocusSpinner startingEnergySpinner = new AutoSelectOnFocusSpinner( new SpinnerNumberModel(config.startingEnergy, 1, Integer.MAX_VALUE, 1)); startingEnergyPanel.add(startingEnergySpinner, inputConstraints); // mutation rate JPanel mutationRatePanel = new JPanel(new GridBagLayout()); evolutionOptionsPanel.add(mutationRatePanel); JLabel mutationRateLabel = new JLabel("Mutation Rate"); mutationRateLabel.setToolTipText( "<html>Chance for a mutation to occur during copy or mixing operations.<br />A value of 0.01 means a 1% chance, a value of 0 disables mutation.</html>"); mutationRatePanel.add(mutationRateLabel, labelConstraints); final JSpinner mutationRateSpinner = new JSpinner(new SpinnerNumberModel(config.mutationRate, 0.0, 1.0, 0.01)); mutationRateSpinner.setEditor( new JSpinner.NumberEditor(mutationRateSpinner, "#.##############")); mutationRateSpinner.setPreferredSize( new Dimension(180, mutationRateSpinner.getPreferredSize().height)); final JFormattedTextField mutationRateSpinnerText = ((JSpinner.NumberEditor) mutationRateSpinner.getEditor()).getTextField(); mutationRateSpinnerText.addFocusListener( new FocusListener() { public void focusGained(FocusEvent e) { SwingUtilities.invokeLater( new Runnable() { public void run() { mutationRateSpinnerText.selectAll(); } }); } public void focusLost(FocusEvent e) {} }); mutationRatePanel.add(mutationRateSpinner, inputConstraints); JPanel guiOptionsPanel = new JPanel(); guiOptionsPanel.setBorder(new TitledBorder("GUI")); guiOptionsPanel.setLayout(new BoxLayout(guiOptionsPanel, BoxLayout.Y_AXIS)); mainPanel.add(guiOptionsPanel); // background color JPanel backgroundColorPanel = new JPanel(new GridBagLayout()); guiOptionsPanel.add(backgroundColorPanel, labelConstraints); JLabel backgroundColorLabel = new JLabel("Background Color"); backgroundColorLabel.setToolTipText( "<html>Pick the background color.<br />If you have a lot of dark pixels, you might want to set this to a light color.</html>"); backgroundColorPanel.add(backgroundColorLabel, labelConstraints); backgroundColor = new PixelColor(config.backgroundColor); JPanel backgroundColorAlignmentPanel = new JPanel(); backgroundColorAlignmentPanel.setLayout(new GridBagLayout()); backgroundColorAlignmentPanel.setPreferredSize(mutationRateSpinner.getPreferredSize()); final ColorChooserLabel backgroundColorChooserLabel = new ColorChooserLabel(backgroundColor); backgroundColorAlignmentPanel.add(backgroundColorChooserLabel); backgroundColorPanel.add(backgroundColorAlignmentPanel, inputConstraints); // FPS JPanel fpsPanel = new JPanel(new GridBagLayout()); guiOptionsPanel.add(fpsPanel); JLabel fpsLabel = new JLabel("FPS"); fpsLabel.setToolTipText( "<html>The repaint interval in frames per second (FPS).<br />Set this to a lower value to save a few CPU cycles.</html>"); fpsPanel.add(fpsLabel, labelConstraints); final AutoSelectOnFocusSpinner fpsSpinner = new AutoSelectOnFocusSpinner(new SpinnerNumberModel(config.fps, 1, Integer.MAX_VALUE, 1)); fpsPanel.add(fpsSpinner, inputConstraints); // paint history size JPanel paintHistorySizePanel = new JPanel(new GridBagLayout()); guiOptionsPanel.add(paintHistorySizePanel); JLabel paintHistorySizeLabel = new JLabel("Paint-History Size"); paintHistorySizeLabel.setToolTipText( "<html>Sets the number of entries in the paint history.<br />In case you have not found it yet: the paint history is the little menu that appears when you right-click on the image.</html>"); paintHistorySizePanel.add(paintHistorySizeLabel, labelConstraints); final AutoSelectOnFocusSpinner paintHistorySizeSpinner = new AutoSelectOnFocusSpinner( new SpinnerNumberModel(config.paintHistorySize, 1, Integer.MAX_VALUE, 1)); paintHistorySizePanel.add(paintHistorySizeSpinner, inputConstraints); JPanel videoOptionsPanel = new JPanel(); videoOptionsPanel.setBorder(new TitledBorder("Video Recording")); videoOptionsPanel.setLayout(new BoxLayout(videoOptionsPanel, BoxLayout.Y_AXIS)); mainPanel.add(videoOptionsPanel); // FPS video JPanel fpsVideoPanel = new JPanel(new GridBagLayout()); videoOptionsPanel.add(fpsVideoPanel); JLabel fpsVideoLabel = new JLabel("FPS of videos"); fpsVideoLabel.setToolTipText("The number of frames per second (FPS) in recorded videos."); fpsVideoPanel.add(fpsVideoLabel, labelConstraints); final AutoSelectOnFocusSpinner fpsVideoSpinner = new AutoSelectOnFocusSpinner( new SpinnerNumberModel(config.fpsVideo, 1, Integer.MAX_VALUE, 1)); fpsVideoPanel.add(fpsVideoSpinner, inputConstraints); // video encoder command JPanel videoEncoderPanel = new JPanel(new GridBagLayout()); videoOptionsPanel.add(videoEncoderPanel); JLabel videoEncoderLabel = new JLabel("Video Encoder"); videoEncoderLabel.setToolTipText( "<html>The command to invoke your video encoder.<br />Use the tokens INPUT_FILE and OUTPUT_FILE to denote input and output files of your encoder.</html>"); videoEncoderPanel.add(videoEncoderLabel, labelConstraints); final JTextArea videoEncoderTextArea = new JTextArea(Configuration.ENCODER_COMMAND); videoEncoderTextArea.setLineWrap(true); videoEncoderTextArea.setWrapStyleWord(true); JScrollPane videoEncoderScrollPane = new JScrollPane( videoEncoderTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); videoEncoderScrollPane.setViewportBorder(null); videoEncoderScrollPane.setPreferredSize( new Dimension(worldSizeInputPanel.getPreferredSize().width, 100)); videoEncoderPanel.add(videoEncoderScrollPane, inputConstraints); JPanel controlPanel = new JPanel(); add(controlPanel, BorderLayout.SOUTH); JButton okButton = new JButton("OK"); okButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new Thread() { @Override public void run() { config.world.addChangeListener( new IChangeListener() { public void changed() { int i, j; double d; String s; // evolution i = (Integer) worldSizeWidthSpinner.getValue(); j = (Integer) worldSizeHeightSpinner.getValue(); if (config.getDimension().width != i || config.getDimension().height != i) { config.setDimension(new Dimension(i, j)); } i = (Integer) startingEnergySpinner.getValue(); if (config.startingEnergy != i) { config.startingEnergy = i; } d = (Double) mutationRateSpinner.getValue(); if (config.mutationRate != d) { config.mutationRate = d; } // gui i = backgroundColor.getInteger(); if (config.backgroundColor != i) { config.backgroundColor = i; } i = (Integer) fpsSpinner.getValue(); if (config.fps != i) { config.fps = i; } i = (Integer) paintHistorySizeSpinner.getValue(); if (config.paintHistorySize != i) { config.paintHistorySize = i; } // video recording i = (Integer) fpsVideoSpinner.getValue(); if (config.fpsVideo != i) { config.fpsVideo = i; } s = videoEncoderTextArea.getText(); if (false == Configuration.ENCODER_COMMAND.equals(s)) { Configuration.ENCODER_COMMAND = s; } dispose(); } }); } }.start(); } }); controlPanel.add(okButton); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); controlPanel.add(cancelButton); pack(); }
public TrayIconPopup(TrayExtension trayExtension) { super(); this.extension = trayExtension; // resizecomps = new ArrayList<AbstractButton>(); setVisible(false); setLayout(new MigLayout("ins 0", "[grow,fill]", "[grow,fill]")); addMouseListener(this); this.setUndecorated(true); // initEntryPanel(); // initQuickConfigPanel(); // initBottomPanel(); // initExitPanel(); JPanel content = new JPanel(new MigLayout("ins 5, wrap 1", "[fill]", "[]5[]")); add(content); JButton header; content.add( header = new JButton("<html><b>" + JDUtilities.getJDTitle(0) + "</b></html>"), "align center"); header.setBorderPainted(false); header.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JDGui.getInstance().setWindowToTray(false); dispose(); } }); AbstractButton ab; // System.out.println(this.getColConstraints(list.length)); MenuItemData last = null; for (final MenuItemData menudata : MenuManagerTrayIcon.getInstance().getMenuData().getItems()) { AbstractButton bt = null; AppAction action; try { if (!menudata.isVisible()) { continue; } if (menudata instanceof SeparatorData) { if (last != null && last instanceof SeparatorData) { // no separator dupes continue; } content.add(new JSeparator(SwingConstants.HORIZONTAL), "growx,spanx"); last = menudata; continue; } if (menudata._getValidateException() != null) { continue; } if (menudata.getType() == org.jdownloader.controlling.contextmenu.MenuItemData.Type.CONTAINER) { bt = new JToggleButton() { protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); g2.setColor(Color.BLACK); g2.fillPolygon( new int[] {getWidth() - 5, getWidth() - 5 - 6, getWidth() - 5 - 6}, new int[] {getHeight() / 2, getHeight() / 2 - 4, getHeight() / 2 + 4}, 3); } }; bt.setText(menudata.getName()); bt.setOpaque(false); bt.setContentAreaFilled(false); bt.setBorderPainted(false); bt.addActionListener( new ActionListener() { private ExtPopupMenu root = null; public void actionPerformed(ActionEvent e) { hideThreadrunning = false; if (root != null && root.isShowing()) { return; } root = new ExtPopupMenu(); new MenuBuilder( MenuManagerMainToolbar.getInstance(), root, (MenuContainer) menudata) { protected void addAction( final JComponent root, final MenuItemData inst, int index, int size) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException, ExtensionNotLoadedException { final JComponent ret = inst.addTo(root); if (ret instanceof AbstractButton) { ((AbstractButton) ret) .addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { ((AbstractButton) ret).getAction().actionPerformed(evt); TrayIconPopup.this.dispose(); } }); } } }.run(); Object src = e.getSource(); if (e.getSource() instanceof Component) { Component button = (Component) e.getSource(); Dimension prefSize = root.getPreferredSize(); int[] insets = LAFOptions.getInstance().getPopupBorderInsets(); root.show(button, button.getWidth(), -insets[0]); } } }); bt.setIcon(MenuItemData.getIcon(menudata.getIconKey(), ICON_SIZE)); bt.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); bt.setFocusPainted(false); bt.setHorizontalAlignment(JButton.LEFT); bt.setIconTextGap(5); bt.addMouseListener(new HoverEffect(bt)); final AbstractButton finalBt = bt; bt.addMouseListener( new MouseListener() { private Timer timer; @Override public void mouseReleased(MouseEvent e) { if (timer != null) { timer.stop(); timer = null; } } @Override public void mousePressed(MouseEvent e) { if (timer != null) { timer.stop(); timer = null; } } @Override public void mouseExited(MouseEvent e) { if (timer != null) { timer.stop(); timer = null; } } @Override public void mouseEntered(MouseEvent e) { timer = new Timer( 500, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { finalBt.doClick(); } }); timer.setRepeats(false); timer.start(); } @Override public void mouseClicked(MouseEvent e) { if (timer != null) { timer.stop(); timer = null; } } }); content.add(bt); continue; } else if (menudata instanceof MenuLink) { final JComponent item = menudata.createItem(); if (StringUtils.isNotEmpty(menudata.getIconKey())) { if (item instanceof AbstractButton) { ((AbstractButton) item) .setIcon(MenuItemData.getIcon(menudata.getIconKey(), ICON_SIZE)); } } content.add(item, ""); } else if (menudata.getActionData() != null) { action = menudata.createAction(); if (!action.isVisible()) { continue; } if (StringUtils.isNotEmpty(menudata.getShortcut()) && KeyStroke.getKeyStroke(menudata.getShortcut()) != null) { action.setAccelerator(KeyStroke.getKeyStroke(menudata.getShortcut())); } else if (MenuItemData.isEmptyValue(menudata.getShortcut())) { action.setAccelerator(null); } content.add(getMenuEntry(action)); last = menudata; } } catch (Exception e) { e.printStackTrace(); } } // content.add(new JSeparator(), "growx, spanx"); // content.add(entryPanel); // content.add(new JSeparator(), "growx, spanx"); // content.add(quickConfigPanel); // content.add(new JSeparator(), "growx, spanx"); // content.add(bottomPanel, "pushx,growx"); // content.add(new JSeparator(), "growx, spanx"); // content.add(exitPanel); // content.setBorder(BorderFactory.createLineBorder(content.getBackground().darker())); // Dimension size = new Dimension(getPreferredSize().width, // resizecomps.get(0).getPreferredSize().height); // for (AbstractButton c : resizecomps) { // c.setPreferredSize(size); // c.setMinimumSize(size); // c.setMaximumSize(size); // } setAlwaysOnTop(true); pack(); hideThread = new Thread() { /* * this thread handles closing of popup because enter/exit/move events are too slow and can miss the exitevent */ public void run() { while (true && hideThreadrunning) { try { sleep(500); } catch (InterruptedException e) { } if (enteredPopup && hideThreadrunning) { PointerInfo mouse = MouseInfo.getPointerInfo(); Point current = TrayIconPopup.this.getLocation(); if (mouse.getLocation().x < current.x || mouse.getLocation().x > current.x + TrayIconPopup.this.getSize().width) { dispose(); break; } else if (mouse.getLocation().y < current.y || mouse.getLocation().y > current.y + TrayIconPopup.this.getSize().height) { dispose(); break; } } } } }; hideThreadrunning = true; hideThread.start(); }