List of usage examples for javax.swing JToggleButton JToggleButton
public JToggleButton(Action a)
From source file:geovista.network.gui.NodeLinkView.java
protected void addControls(final JPanel jp) { // Satellite/* w w w . j a va 2 s . c o m*/ // JComboBox modeBox = graphMouse.getModeComboBox(); // modeBox.addItemListener(((DefaultModalGraphMouse)satellite.getGraphMouse()).getModeListener()); // Control Panel jp.setBackground(Color.WHITE); jp.setLayout(new BorderLayout()); jp.add(vv, BorderLayout.CENTER); JPanel control_panel = new JPanel(new GridLayout(5, 1)); jp.add(control_panel, BorderLayout.EAST); // File_Layout Panel Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); jcb.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String valueString = value.toString(); valueString = valueString.substring(valueString.lastIndexOf('.') + 1); return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus); } }); jcb.addActionListener(new LayoutChooser(jcb, vv)); jcb.setSelectedItem(FRLayout.class); final Box file_layout_panel = Box.createVerticalBox(); file_layout_panel.setBorder(BorderFactory.createTitledBorder("File_Layout")); final JComboBox graph_chooser = new JComboBox(g_names); graph_chooser.addActionListener(new GraphChooser(jcb)); JPanel layoutPanel = new JPanel(); jcb.setAlignmentX(Component.CENTER_ALIGNMENT); layoutPanel.add(jcb); graph_chooser.setAlignmentX(Component.CENTER_ALIGNMENT); layoutPanel.add(graph_chooser); file_layout_panel.add(layoutPanel); // Basic Operation Panel final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Layout<Integer, Number> layout = vv.getGraphLayout(); layout.initialize(); Relaxer relaxer = vv.getModel().getRelaxer(); if (relaxer != null) { relaxer.stop(); relaxer.prerelax(); relaxer.relax(); } } }); // Tranform and picking part final DefaultModalGraphMouse<Integer, Number> graphMouse = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(((DefaultModalGraphMouse<Integer, Number>) vv.getGraphMouse()).getModeListener()); JButton collapse = new JButton("Collapse"); JButton expand = new JButton("Expand"); final Box basic_panel = Box.createVerticalBox(); basic_panel.setBorder(BorderFactory.createTitledBorder("Basic_Operation")); JPanel zoomPanel = new JPanel(); // plus.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(plus); // minus.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(minus); // modeBox.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(modeBox); // reset.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(reset); // collapse.setAlignmentY(Component.CENTER_ALIGNMENT); zoomPanel.add(collapse); // expand.setAlignmentY(Component.CENTER_ALIGNMENT); zoomPanel.add(expand); basic_panel.add(zoomPanel); // Vertex Part String[] vertexScoreType = { "VertexScore", "Degree", "BarycenterScorer", "BetweennessCentrality", "ClosenessCentrality", "DistanceCentralityScorer", "EigenvectorCentrality" }; final JComboBox vertexScoreList = new JComboBox(vertexScoreType); vertexScoreList.setSelectedIndex(0); vertexScoreList.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { // Renderer.VertexLabel.Position position = // (Renderer.VertexLabel.Position)e.getItem(); // vv.getRenderer().getVertexLabelRenderer().setPosition(position); if (vertexScoreList.getSelectedIndex() == 0) { // vertexScores = new VertexScoreTransformer<Integer, // Double>(voltage_scores); // vv.getRenderContext().setVertexShapeTransformer(new // ConstantTransformer(null)); // vssa.setScaling(false); vv.getRenderContext().setVertexLabelTransformer(nonvertexLabel); vv.repaint(); } if (vertexScoreList.getSelectedIndex() == 1) { // vertexScores = new VertexScoreTransformer<Integer, // Double>(degreeScorer); /* * vssa = new * VertexShapeSizeAspect<Integer,Number>((Graph<Integer * ,Number>)g, transformerDegree); * vv.getRenderContext().setVertexShapeTransformer(vssa); * vssa.setScaling(true); */ vv.getRenderContext().setVertexLabelTransformer(vertexLabelDegree); vv.repaint(); } if (vertexScoreList.getSelectedIndex() == 2) { vssa = new VertexShapeSizeAspect<Integer, Number>((Graph<Integer, Number>) g, transformerBarycenter); vv.getRenderContext().setVertexShapeTransformer(vssa); vssa.setScaling(true); vv.getRenderContext().setVertexLabelTransformer(vertexLabelBarycenter); vv.repaint(); } if (vertexScoreList.getSelectedIndex() == 3) { // betweennessCentrality= new BetweennessCentrality(g); // voltages = new VertexScoreTransformer<Integer, // Double>(betweennessCentrality); vssa = new VertexShapeSizeAspect<Integer, Number>((Graph<Integer, Number>) g, transformerBetweenness); vv.getRenderContext().setVertexShapeTransformer(vssa); vssa.setScaling(true); vv.getRenderContext().setVertexLabelTransformer(vertexLabelBetweenness); vv.repaint(); } if (vertexScoreList.getSelectedIndex() == 4) { vssa = new VertexShapeSizeAspect<Integer, Number>((Graph<Integer, Number>) g, transformerCloseness); vv.getRenderContext().setVertexShapeTransformer(vssa); vssa.setScaling(true); vv.getRenderContext().setVertexLabelTransformer(vertexLabelCloseness); vv.repaint(); } if (vertexScoreList.getSelectedIndex() == 5) { vssa = new VertexShapeSizeAspect<Integer, Number>((Graph<Integer, Number>) g, transformerDistanceCentrality); vv.getRenderContext().setVertexShapeTransformer(vssa); vssa.setScaling(true); vv.getRenderContext().setVertexLabelTransformer(vertexLabelDistanceCentrality); vv.repaint(); } if (vertexScoreList.getSelectedIndex() == 6) { vssa = new VertexShapeSizeAspect<Integer, Number>((Graph<Integer, Number>) g, transformerEigenvector); vv.getRenderContext().setVertexShapeTransformer(vssa); vssa.setScaling(true); vv.getRenderContext().setVertexLabelTransformer(vertexLabelEigenvector); vv.repaint(); } } }); // cb.setSelectedItem(Renderer.VertexLabel.Position.SE); /* * v_shape = new JCheckBox("shape by degree"); * v_shape.addActionListener(this); v_size = new * JCheckBox("size by vertexScores"); v_size.addActionListener(this); * v_size.setSelected(true); v_aspect = new * JCheckBox("stretch by degree ratio"); * v_aspect.addActionListener(this); */ v_small = new JCheckBox("filter when degree < " + VertexDisplayPredicate.MIN_DEGREE); v_small.addActionListener(this); e_labels = new JCheckBox("show edge labels"); e_labels.addActionListener(this); // Vertex Panel final Box vertex_panel = Box.createVerticalBox(); vertex_panel.setBorder(BorderFactory.createTitledBorder("Vertices")); // vertex_panel.add(v_stroke); vertex_panel.add(vertexScoreList); // vertex_panel.add(v_degree_labels); /* * vertex_panel.add(v_shape); vertex_panel.add(v_size); * vertex_panel.add(v_aspect); */ vertex_panel.add(v_small); // Edge Part final Box edge_panel = Box.createVerticalBox(); edge_panel.setBorder(BorderFactory.createTitledBorder("Edges")); edge_panel.add(e_labels); final JToggleButton groupVertices = new JToggleButton("Group Clusters"); // Create slider to adjust the number of edges to remove when clustering final JSlider edgeBetweennessSlider = new JSlider(JSlider.HORIZONTAL); edgeBetweennessSlider.setBackground(Color.WHITE); edgeBetweennessSlider.setPreferredSize(new Dimension(210, 50)); edgeBetweennessSlider.setPaintTicks(true); edgeBetweennessSlider.setMaximum(g.getEdgeCount()); edgeBetweennessSlider.setMinimum(0); edgeBetweennessSlider.setValue(0); edgeBetweennessSlider.setMajorTickSpacing(10); edgeBetweennessSlider.setPaintLabels(true); edgeBetweennessSlider.setPaintTicks(true); // Cluster Part final Box cluster_panel = Box.createVerticalBox(); cluster_panel.setBorder(BorderFactory.createTitledBorder("Cluster")); cluster_panel.add(edgeBetweennessSlider); final String COMMANDSTRING = "Edges removed for clusters: "; final String eastSize = COMMANDSTRING + edgeBetweennessSlider.getValue(); final TitledBorder sliderBorder = BorderFactory.createTitledBorder(eastSize); cluster_panel.setBorder(sliderBorder); cluster_panel.add(Box.createVerticalGlue()); groupVertices.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { clusterAndRecolor(layout, edgeBetweennessSlider.getValue(), similarColors, e.getStateChange() == ItemEvent.SELECTED); vv.repaint(); } }); clusterAndRecolor(layout, 0, similarColors, groupVertices.isSelected()); edgeBetweennessSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (!source.getValueIsAdjusting()) { int numEdgesToRemove = source.getValue(); clusterAndRecolor(layout, numEdgesToRemove, similarColors, groupVertices.isSelected()); sliderBorder.setTitle(COMMANDSTRING + edgeBetweennessSlider.getValue()); cluster_panel.repaint(); vv.validate(); vv.repaint(); } } }); cluster_panel.add(groupVertices); control_panel.add(file_layout_panel); control_panel.add(vertex_panel); control_panel.add(edge_panel); control_panel.add(cluster_panel); control_panel.add(basic_panel); }
From source file:lejos.pc.charting.LogChartFrame.java
/** All the setup of components, etc. What's scary is Swing is a "lightweight" GUI framework... * @throws Exception//from w ww .j a v a 2 s.c o m */ private void jbInit() throws Exception { this.setJMenuBar(menuBar); this.setSize(new Dimension(819, 613)); this.setMinimumSize(new Dimension(819, 613)); this.setTitle("NXT Charting Logger"); this.setEnabled(true); // enforce minimum window size this.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { JFrame theFrame = (JFrame) e.getSource(); Dimension d1 = theFrame.getMinimumSize(); Dimension d2 = theFrame.getSize(); boolean enforce = false; if (theFrame.getWidth() < d1.getWidth()) { d2.setSize(d1.getWidth(), d2.getHeight()); enforce = true; } if (theFrame.getHeight() < d1.getHeight()) { d2.setSize(d2.getWidth(), d1.getHeight()); enforce = true; } if (enforce) theFrame.setSize(d2); } }); this.getContentPane().setLayout(gridBagLayout1); MenuActionListener menuItemActionListener = new MenuActionListener(); MenuEventListener menuListener = new MenuEventListener(); menu = new JMenu("Edit"); menu.setMnemonic(KeyEvent.VK_E); menuBar.add(menu); menuItem = new JMenuItem("Copy Chart Image", KeyEvent.VK_I); menuItem.addActionListener(menuItemActionListener); menu.add(menuItem); menuItem = new JMenuItem("Copy Data Log", KeyEvent.VK_D); menuItem.addActionListener(menuItemActionListener); menu.add(menuItem); menu = new JMenu("View"); menu.setMnemonic(KeyEvent.VK_V); menu.setActionCommand("VIEW_MENU"); menu.addMenuListener(menuListener); menuBar.add(menu); menuItem = new JMenuItem("Expand Chart", KeyEvent.VK_F); menuItem.addActionListener(menuItemActionListener); menu.add(menuItem); menuItem = new JMenuItem("Chart in New Window", KeyEvent.VK_N); menuItem.addActionListener(menuItemActionListener); menu.add(menuItem); menu = new JMenu("Help"); menu.setMnemonic(KeyEvent.VK_H); menuBar.add(menu); menuItem = new JMenuItem("Chart controls", KeyEvent.VK_C); menuItem.addActionListener(menuItemActionListener); menu.add(menuItem); menuItem = new JMenuItem("Generate sample data", KeyEvent.VK_G); menuItem.addActionListener(menuItemActionListener); menu.add(menuItem); menuItem = new JMenuItem("About", KeyEvent.VK_A); menuItem.addActionListener(menuItemActionListener); jTabbedPane1.setPreferredSize(new Dimension(621, 199)); jTabbedPane1.setMinimumSize(new Dimension(621, 199)); menu.add(menuItem); jButtonConnect.setText("Connect"); jButtonConnect.setBounds(new Rectangle(25, 65, 115, 25)); jButtonConnect.setToolTipText("Connect/disconnect toggle"); jButtonConnect.setMnemonic('C'); jButtonConnect.setSelected(true); jButtonConnect.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jButtonConnect_actionPerformed(e); } }); UIPanel.setSize(new Dimension(820, 200)); UIPanel.setLayout(null); UIPanel.setPreferredSize(new Dimension(300, 200)); UIPanel.setMinimumSize(new Dimension(300, 200)); UIPanel.setBounds(new Rectangle(0, 350, 820, 200)); UIPanel.setMaximumSize(new Dimension(300, 32767)); connectionPanel.setBounds(new Rectangle(10, 10, 175, 100)); connectionPanel.setBorder(BorderFactory.createTitledBorder("Connection")); connectionPanel.setLayout(null); connectionPanel.setFont(new Font("Tahoma", 0, 11)); jLabel1logfilename.setText("Log File:"); jLabel1logfilename.setBounds(new Rectangle(10, 125, 165, 20)); jLabel1logfilename.setHorizontalTextPosition(SwingConstants.RIGHT); jLabel1logfilename.setHorizontalAlignment(SwingConstants.LEFT); jLabel1logfilename.setToolTipText("Specify the name of your log file here"); jTextFieldNXTName.setBounds(new Rectangle(5, 40, 165, 20)); jTextFieldNXTName.setToolTipText( "The name or Address of the NXT. Leave empty and the first one found will be used."); jTextFieldNXTName.requestFocus(); jTextAreaStatus.setLineWrap(true); jTextAreaStatus.setFont(new Font("Tahoma", 0, 11)); jTextAreaStatus.setWrapStyleWord(true); jTextAreaStatus.setBackground(SystemColor.window); dataLogTextArea.setLineWrap(false); dataLogTextArea.setFont(new Font("Tahoma", 0, 11)); dataLogTextArea.setBackground(SystemColor.window); FQPathTextArea.setBounds(new Rectangle(5, 170, 185, 40)); FQPathTextArea.setLineWrap(true); FQPathTextArea.setText(getCanonicalName(new File(".", ""))); FQPathTextArea.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); FQPathTextArea.setRows(2); FQPathTextArea.setFont(new Font("Tahoma", 0, 9)); FQPathTextArea.setOpaque(false); FQPathTextArea.setEditable(false); selectFolderButton.setText("Folder..."); selectFolderButton.setBounds(new Rectangle(120, 125, 70, 20)); selectFolderButton.setMargin(new Insets(1, 1, 1, 1)); selectFolderButton.setFocusable(false); selectFolderButton.setMnemonic('F'); selectFolderButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { selectFolderButton_actionPerformed(e); } }); // domain display limits GUI chartOptionsPanel.setLayout(null); chartDomLimitsPanel.setBounds(new Rectangle(5, 35, 180, 135)); chartDomLimitsPanel.setLayout(gridLayout1); chartDomLimitsPanel.setBorder(BorderFactory.createTitledBorder("Domain Display Limiting")); domainDisplayLimitSlider.setEnabled(false); domainDisplayLimitSlider.setMaximum(MAXDOMAIN_DATAPOINT_LIMIT); domainDisplayLimitSlider.setMinimum(MINDOMAIN_LIMIT); domainDisplayLimitSlider.setValue(MAXDOMAIN_DATAPOINT_LIMIT); domainDisplayLimitSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { domainDisplayLimitSlider_stateChanged(e); } }); useTimeRadioButton.setText("By Time"); useTimeRadioButton.setEnabled(false); useTimeRadioButton.setMnemonic('I'); useTimeRadioButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { domainDisplayLimitRadioButton_actionPerformed(e); } }); useDataPointsRadioButton.setText("By Data Points"); ButtonGroup bg1 = new ButtonGroup(); bg1.add(useTimeRadioButton); bg1.add(useDataPointsRadioButton); useDataPointsRadioButton.setSelected(true); useDataPointsRadioButton.setEnabled(false); useDataPointsRadioButton.setMnemonic('P'); useDataPointsRadioButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { domainDisplayLimitRadioButton_actionPerformed(e); } }); datasetLimitEnableCheckBox.setText("Enable"); datasetLimitEnableCheckBox.setRolloverEnabled(true); datasetLimitEnableCheckBox.setMnemonic('A'); datasetLimitEnableCheckBox.setToolTipText("Enable Domain Clipping"); datasetLimitEnableCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { datasetLimitEnableCheckBox_actionPerformed(e); } }); domainLimitLabel.setText(String.format("%1$,d datapoints", MAXDOMAIN_DATAPOINT_LIMIT).toString()); domainLimitLabel.setEnabled(false); gridLayout1.setRows(5); gridLayout1.setColumns(1); jLabel1.setText("Chart Title:"); jLabel1.setBounds(new Rectangle(200, 10, 85, 20)); jLabel1.setPreferredSize(new Dimension(115, 14)); jLabel2.setText("Range Axis 1 Label:"); jLabel2.setBounds(new Rectangle(200, 35, 115, 20)); jLabel2.setSize(new Dimension(115, 20)); jLabel3.setText("Range Axis 2 Label:"); jLabel3.setBounds(new Rectangle(200, 60, 115, 20)); jLabel3.setSize(new Dimension(115, 20)); jLabel4.setText("Range Axis 3 Label:"); jLabel4.setBounds(new Rectangle(200, 85, 115, 20)); jLabel4.setSize(new Dimension(115, 20)); jLabel6.setText("Range Axis 4 Label:"); jLabel6.setBounds(new Rectangle(200, 110, 115, 20)); jLabel6.setSize(new Dimension(115, 20)); titleLabelChangeNotifier notifier = new titleLabelChangeNotifier(); chartTitleTextField.setBounds(new Rectangle(315, 10, 290, 20)); chartTitleTextField.getDocument().addDocumentListener(notifier); axis1LabelTextField.setBounds(new Rectangle(315, 35, 290, 20)); axis1LabelTextField.getDocument().addDocumentListener(notifier); axis2LabelTextField.setBounds(new Rectangle(315, 60, 290, 20)); axis2LabelTextField.getDocument().addDocumentListener(notifier); axis3LabelTextField.setBounds(new Rectangle(315, 85, 290, 20)); axis3LabelTextField.getDocument().addDocumentListener(notifier); axis4LabelTextField.setBounds(new Rectangle(315, 110, 290, 20)); showCommentsCheckBox.setText("Show Comment Markers"); showCommentsCheckBox.setBounds(new Rectangle(200, 140, 185, 25)); showCommentsCheckBox.setToolTipText("Show/Hide any comment markers on the chart"); showCommentsCheckBox.setRolloverEnabled(true); showCommentsCheckBox.setSelected(true); showCommentsCheckBox.setMnemonic('M'); showCommentsCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { customChartPanel.setCommentsVisible(e.getStateChange() == ItemEvent.SELECTED); } }); scrollDomainCheckBox.setText("Scroll Domain"); scrollDomainCheckBox.setBounds(new Rectangle(10, 5, 175, 20)); scrollDomainCheckBox.setSize(new Dimension(175, 25)); scrollDomainCheckBox.setSelected(true); scrollDomainCheckBox.setMnemonic('O'); scrollDomainCheckBox.setToolTipText("Checked to scroll domain as new data is received"); scrollDomainCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scrollDomainCheckBox_actionPerformed(e); } }); axis4LabelTextField.getDocument().addDocumentListener(notifier); logFileTextField.setBounds(new Rectangle(10, 145, 180, 20)); logFileTextField.setText("NXTData.txt"); logFileTextField.setPreferredSize(new Dimension(180, 20)); logFileTextField.setToolTipText("File name. Leave empty to not log to file."); statusScrollPane.setOpaque(false); dataLogScrollPane.setOpaque(false); customChartPanel.setMinimumSize(new Dimension(400, 300)); customChartPanel.setPreferredSize(new Dimension(812, 400)); jLabel5.setText("NXT Name/Address:"); jLabel5.setBounds(new Rectangle(5, 20, 160, 20)); jLabel5.setToolTipText(jTextFieldNXTName.getToolTipText()); jLabel5.setHorizontalTextPosition(SwingConstants.RIGHT); jLabel5.setHorizontalAlignment(SwingConstants.LEFT); connectionPanel.add(jTextFieldNXTName, null); connectionPanel.add(jButtonConnect, null); connectionPanel.add(jLabel5, null); dataLogScrollPane.setViewportView(dataLogTextArea); jTabbedPane1.addTab("Data Log", dataLogScrollPane); statusScrollPane.setViewportView(jTextAreaStatus); jTabbedPane1.addTab("Status", statusScrollPane); jTabbedPane1.addTab("Chart", chartOptionsPanel); chartDomLimitsPanel.add(datasetLimitEnableCheckBox, null); chartDomLimitsPanel.add(useDataPointsRadioButton, null); chartDomLimitsPanel.add(useTimeRadioButton, null); chartDomLimitsPanel.add(domainDisplayLimitSlider, null); chartDomLimitsPanel.add(domainLimitLabel, null); chartOptionsPanel.add(scrollDomainCheckBox, null); chartOptionsPanel.add(showCommentsCheckBox, null); chartOptionsPanel.add(axis4LabelTextField, null); chartOptionsPanel.add(axis3LabelTextField, null); chartOptionsPanel.add(axis2LabelTextField, null); chartOptionsPanel.add(axis1LabelTextField, null); chartOptionsPanel.add(chartTitleTextField, null); chartOptionsPanel.add(jLabel6, null); chartOptionsPanel.add(jLabel4, null); chartOptionsPanel.add(jLabel3, null); chartOptionsPanel.add(jLabel2, null); chartOptionsPanel.add(jLabel1, null); chartOptionsPanel.add(chartDomLimitsPanel, null); tglbtnpauseplay = new JToggleButton(""); tglbtnpauseplay.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (lpm == null) return; boolean doPause = false; if (e.getStateChange() == ItemEvent.SELECTED) { doPause = true; } lpm.setReaderPaused(doPause); } }); // tglbtnpauseplay.addChangeListener(new ChangeListener() { // public void stateChanged(ChangeEvent e) { // System.out.println(e.toString()); // //lpm.setReaderPaused(doPause) // } // }); tglbtnpauseplay .setSelectedIcon(new ImageIcon(LogChartFrame.class.getResource("/lejos/pc/charting/play.png"))); tglbtnpauseplay.setIcon(new ImageIcon(LogChartFrame.class.getResource("/lejos/pc/charting/pause.png"))); tglbtnpauseplay.setBounds(571, 135, 30, 30); chartOptionsPanel.add(tglbtnpauseplay); jTabbedPane1.setToolTipTextAt(0, "The tab-delimited log of the data sent from the NXT"); jTabbedPane1.setToolTipTextAt(1, "Status output"); jTabbedPane1.setToolTipTextAt(2, "Chart options"); jTabbedPane1.setMnemonicAt(0, KeyEvent.VK_D); jTabbedPane1.setMnemonicAt(1, KeyEvent.VK_S); jTabbedPane1.setMnemonicAt(2, KeyEvent.VK_T); this.getContentPane().add(customChartPanel, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); this.getContentPane().add(UIPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), -107, 0)); this.getContentPane().add(jTabbedPane1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); UIPanel.add(connectionPanel, null); UIPanel.add(selectFolderButton, null); UIPanel.add(logFileTextField, null); UIPanel.add(jLabel1logfilename, null); UIPanel.add(FQPathTextArea, null); ActionListener taskPerformer = new ActionListener() { public void actionPerformed(ActionEvent evt) { String theData = null; for (;;) { theData = LogChartFrame.this.logDataQueue.poll(); if (theData == null) break; try { dataLogTextArea.getDocument().insertString(dataLogTextArea.getDocument().getLength(), theData, null); } catch (BadLocationException e) { System.out.print( "BadLocationException in datalog textarea updater thread:" + e.toString() + "\n"); } } } }; this.updateLogTextAreaTimer = new Timer(1000, taskPerformer); this.updateLogTextAreaTimer.start(); }
From source file:net.sf.jabref.gui.JabRefFrame.java
private void createToolBar() { tlb.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH); tlb.setBorder(null);// w w w . ja v a 2 s . c om tlb.setRollover(true); tlb.setFloatable(false); if (Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE)) { tlb.addAction(newBiblatexDatabaseAction); } else { tlb.addAction(newBibtexDatabaseAction); } tlb.addAction(getOpenDatabaseAction()); tlb.addAction(save); tlb.addAction(saveAll); tlb.addSeparator(); tlb.addAction(cut); tlb.addAction(copy); tlb.addAction(paste); tlb.addAction(undo); tlb.addAction(redo); tlb.addSeparator(); tlb.addAction(getBackAction()); tlb.addAction(getForwardAction()); tlb.addSeparator(); tlb.addAction(newEntryAction); tlb.addAction(editEntry); tlb.addAction(editStrings); tlb.addAction(deleteEntry); tlb.addSeparator(); tlb.addAction(makeKeyAction); tlb.addAction(cleanupEntries); tlb.addAction(mergeEntries); tlb.addAction(openConsole); tlb.addSeparator(); tlb.addAction(mark); tlb.addAction(unmark); if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SPECIALFIELDSENABLED)) { if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RANKING)) { JButton button = net.sf.jabref.specialfields.SpecialFieldDropDown .generateSpecialFieldButtonWithDropDown(Rank.getInstance(), this); tlb.add(button); specialFieldButtons.add(button); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RELEVANCE)) { tlb.addAction(toggleRelevance); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_QUALITY)) { tlb.addAction(toggleQualityAssured); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRIORITY)) { JButton button = net.sf.jabref.specialfields.SpecialFieldDropDown .generateSpecialFieldButtonWithDropDown(Priority.getInstance(), this); tlb.add(button); specialFieldButtons.add(button); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRINTED)) { tlb.addAction(togglePrinted); } if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_READ)) { JButton button = net.sf.jabref.specialfields.SpecialFieldDropDown .generateSpecialFieldButtonWithDropDown(ReadStatus.getInstance(), this); tlb.add(button); specialFieldButtons.add(button); } } tlb.addSeparator(); fetcherToggle = new JToggleButton(generalFetcher.getAction()); tlb.addJToogleButton(fetcherToggle); previewToggle = new JToggleButton(togglePreview); tlb.addJToogleButton(previewToggle); groupToggle = new JToggleButton(toggleGroups); tlb.addJToogleButton(groupToggle); tlb.addSeparator(); tlb.add(pushExternalButton.getComponent()); tlb.addSeparator(); tlb.add(donationAction); tlb.add(forkMeOnGitHubAction); }
From source file:com.maxl.java.amikodesk.AMiKoDesk.java
private static void createAndShowLightGUI() { // Create and setup window final JFrame jframe = new JFrame(Constants.APP_NAME); int min_width = CML_OPT_WIDTH; int min_height = CML_OPT_HEIGHT; jframe.setPreferredSize(new Dimension(min_width, min_height)); jframe.setMinimumSize(new Dimension(min_width, min_height)); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int x = (screen.width - min_width) / 2; int y = (screen.height - min_height) / 2; jframe.setBounds(x, y, min_width, min_height); // Action listeners jframe.addWindowListener(new WindowListener() { // Use WindowAdapter! @Override/*from ww w . j av a 2s. c om*/ public void windowOpened(WindowEvent e) { } @Override public void windowClosed(WindowEvent e) { m_web_panel.dispose(); Runtime.getRuntime().exit(0); } @Override public void windowClosing(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } }); // Container final Container container = jframe.getContentPane(); container.setBackground(Color.WHITE); container.setLayout(new BorderLayout()); // ==== Light panel ==== JPanel light_panel = new JPanel(); light_panel.setBackground(Color.WHITE); light_panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(2, 2, 2, 2); // ---- Section titles ---- m_section_titles = null; if (Utilities.appLanguage().equals("de")) { m_section_titles = new IndexPanel(SectionTitle_DE); } else if (Utilities.appLanguage().equals("fr")) { m_section_titles = new IndexPanel(SectionTitle_FR); } gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 8; gbc.weightx = gbc.weighty = 0.0; // --> container.add(m_section_titles, gbc); if (m_section_titles != null) light_panel.add(m_section_titles, gbc); // ---- Fachinformation ---- m_web_panel = new WebPanel2(); gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 1; gbc.gridy = 0; gbc.gridwidth = 3; gbc.gridheight = 20; gbc.weightx = 2.0; gbc.weighty = 1.0; gbc.anchor = GridBagConstraints.EAST; // --> container.add(m_web_panel, gbc); light_panel.add(m_web_panel, gbc); // ---- Add panel to main container ---- container.add(light_panel, BorderLayout.CENTER); // Display window jframe.pack(); // jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // jframe.setAlwaysOnTop(true); jframe.setVisible(true); // If command line options are provided start app with a particular // title or eancode if (commandLineOptionsProvided()) { final JToggleButton but_dummy = new JToggleButton("dummy_button"); if (!CML_OPT_TITLE.isEmpty()) startAppWithTitle(but_dummy); else if (!CML_OPT_EANCODE.isEmpty()) startAppWithEancode(but_dummy); else if (!CML_OPT_REGNR.isEmpty()) startAppWithRegnr(but_dummy); else if (CML_OPT_SERVER == true) { // Start thread that reads data from TCP server Thread server_thread = new Thread() { public void run() { while (true) { String tcpServerInput = ""; // Wait until new data is available from input stream // Note: the TCP client defines the update rate! // System.out.print("Waiting for input..."); while ((tcpServerInput = mTcpServer.getInput()).isEmpty()) ; /* * Important note: we use invokeLater to post a "job" to Swing, which will then be run on the * event dispatch thread at Swing's next convenience. Failing to do so will freeze the main thread. */ // Detect type of search (t=title, e=eancode, r=regnr) char typeOfSearch = tcpServerInput.charAt(0); if (typeOfSearch == 't') { // Extract title from received string CML_OPT_TITLE = tcpServerInput.substring(2); // System.out.println(" title -> " + // CML_OPT_TITLE); // Post a "job" to Swing, which will be run on // the event dispatch thread // at its next convenience. SwingUtilities.invokeLater(new Runnable() { public void run() { startAppWithTitle(but_dummy); } }); } else if (typeOfSearch == 'e') { // Extract ean code from received string CML_OPT_EANCODE = tcpServerInput.substring(2); // System.out.println(" eancode -> " + // CML_OPT_EANCODE); // Post a "job" to Swing, which will be run on // the event dispatch thread // at its next convenience. SwingUtilities.invokeLater(new Runnable() { public void run() { startAppWithEancode(but_dummy); } }); } else if (typeOfSearch == 'r') { // Extract registration number from received // string CML_OPT_REGNR = tcpServerInput.substring(2); // System.out.println(" regnr -> " + // CML_OPT_REGNR); // Post a "job" to Swing, which will be run on // the event dispatch thread // at its next convenience. SwingUtilities.invokeLater(new Runnable() { public void run() { startAppWithRegnr(but_dummy); } }); } } } }; server_thread.start(); } } }
From source file:com.maxl.java.amikodesk.AMiKoDesk.java
private static void createAndShowFullGUI() { // Create and setup window final JFrame jframe = new JFrame(Constants.APP_NAME); jframe.setName(Constants.APP_NAME + ".main"); int min_width = CML_OPT_WIDTH; int min_height = CML_OPT_HEIGHT; jframe.setPreferredSize(new Dimension(min_width, min_height)); jframe.setMinimumSize(new Dimension(min_width, min_height)); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int x = (screen.width - min_width) / 2; int y = (screen.height - min_height) / 2; jframe.setBounds(x, y, min_width, min_height); // Set application icon if (Utilities.appCustomization().equals("ywesee")) { ImageIcon img = new ImageIcon(Constants.AMIKO_ICON); jframe.setIconImage(img.getImage()); } else if (Utilities.appCustomization().equals("desitin")) { ImageIcon img = new ImageIcon(Constants.DESITIN_ICON); jframe.setIconImage(img.getImage()); } else if (Utilities.appCustomization().equals("meddrugs")) { ImageIcon img = new ImageIcon(Constants.MEDDRUGS_ICON); jframe.setIconImage(img.getImage()); } else if (Utilities.appCustomization().equals("zurrose")) { ImageIcon img = new ImageIcon(Constants.AMIKO_ICON); jframe.setIconImage(img.getImage()); }/*ww w. j ava 2 s. co m*/ // ------ Setup menubar ------ JMenuBar menu_bar = new JMenuBar(); // menu_bar.add(Box.createHorizontalGlue()); // --> aligns menu items to the right! // -- Menu "Datei" -- JMenu datei_menu = new JMenu("Datei"); if (Utilities.appLanguage().equals("fr")) datei_menu.setText("Fichier"); menu_bar.add(datei_menu); JMenuItem print_item = new JMenuItem("Drucken..."); JMenuItem settings_item = new JMenuItem(m_rb.getString("settings") + "..."); JMenuItem quit_item = new JMenuItem("Beenden"); if (Utilities.appLanguage().equals("fr")) { print_item.setText("Imprimer"); quit_item.setText("Terminer"); } datei_menu.add(print_item); datei_menu.addSeparator(); datei_menu.add(settings_item); datei_menu.addSeparator(); datei_menu.add(quit_item); // -- Menu "Aktualisieren" -- JMenu update_menu = new JMenu("Aktualisieren"); if (Utilities.appLanguage().equals("fr")) update_menu.setText("Mise jour"); menu_bar.add(update_menu); final JMenuItem updatedb_item = new JMenuItem("Aktualisieren via Internet..."); updatedb_item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); JMenuItem choosedb_item = new JMenuItem("Aktualisieren via Datei..."); update_menu.add(updatedb_item); update_menu.add(choosedb_item); if (Utilities.appLanguage().equals("fr")) { updatedb_item.setText("Tlcharger la banque de donnes..."); updatedb_item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK)); choosedb_item.setText("Ajourner la banque de donnes..."); } // -- Menu "Hilfe" -- JMenu hilfe_menu = new JMenu("Hilfe"); if (Utilities.appLanguage().equals("fr")) hilfe_menu.setText("Aide"); menu_bar.add(hilfe_menu); JMenuItem about_item = new JMenuItem("ber " + Constants.APP_NAME + "..."); JMenuItem ywesee_item = new JMenuItem(Constants.APP_NAME + " im Internet"); if (Utilities.appCustomization().equals("meddrugs")) ywesee_item.setText("med-drugs im Internet"); JMenuItem report_item = new JMenuItem("Error Report..."); JMenuItem contact_item = new JMenuItem("Kontakt..."); if (Utilities.appLanguage().equals("fr")) { // Extrawunsch med-drugs if (Utilities.appCustomization().equals("meddrugs")) about_item.setText(Constants.APP_NAME); else about_item.setText("A propos de " + Constants.APP_NAME + "..."); contact_item.setText("Contact..."); if (Utilities.appCustomization().equals("meddrugs")) ywesee_item.setText("med-drugs sur Internet"); else ywesee_item.setText(Constants.APP_NAME + " sur Internet"); report_item.setText("Rapport d'erreur..."); } hilfe_menu.add(about_item); hilfe_menu.add(ywesee_item); hilfe_menu.addSeparator(); hilfe_menu.add(report_item); hilfe_menu.addSeparator(); hilfe_menu.add(contact_item); // Menu "Abonnieren" (only for ywesee) JMenu subscribe_menu = new JMenu("Abonnieren"); if (Utilities.appLanguage().equals("fr")) subscribe_menu.setText("Abonnement"); if (Utilities.appCustomization().equals("ywesee")) { menu_bar.add(subscribe_menu); } jframe.setJMenuBar(menu_bar); // ------ Setup toolbar ------ JToolBar toolBar = new JToolBar("Database"); toolBar.setPreferredSize(new Dimension(jframe.getWidth(), 64)); final JToggleButton selectAipsButton = new JToggleButton( new ImageIcon(Constants.IMG_FOLDER + "aips32x32_bright.png")); final JToggleButton selectFavoritesButton = new JToggleButton( new ImageIcon(Constants.IMG_FOLDER + "favorites32x32_bright.png")); final JToggleButton selectInteractionsButton = new JToggleButton( new ImageIcon(Constants.IMG_FOLDER + "interactions32x32_bright.png")); final JToggleButton selectShoppingCartButton = new JToggleButton( new ImageIcon(Constants.IMG_FOLDER + "shoppingcart32x32_bright.png")); final JToggleButton selectComparisonCartButton = new JToggleButton( new ImageIcon(Constants.IMG_FOLDER + "comparisoncart32x32_bright.png")); final JToggleButton list_of_buttons[] = { selectAipsButton, selectFavoritesButton, selectInteractionsButton, selectShoppingCartButton, selectComparisonCartButton }; if (Utilities.appLanguage().equals("de")) { setupButton(selectAipsButton, "Kompendium", "aips32x32_gray.png", "aips32x32_dark.png"); setupButton(selectFavoritesButton, "Favoriten", "favorites32x32_gray.png", "favorites32x32_dark.png"); setupButton(selectInteractionsButton, "Interaktionen", "interactions32x32_gray.png", "interactions32x32_dark.png"); setupButton(selectShoppingCartButton, "Warenkorb", "shoppingcart32x32_gray.png", "shoppingcart32x32_dark.png"); setupButton(selectComparisonCartButton, "Preisvergleich", "comparisoncart32x32_gray.png", "comparisoncart32x32_dark.png"); } else if (Utilities.appLanguage().equals("fr")) { setupButton(selectAipsButton, "Compendium", "aips32x32_gray.png", "aips32x32_dark.png"); setupButton(selectFavoritesButton, "Favorites", "favorites32x32_gray.png", "favorites32x32_dark.png"); setupButton(selectInteractionsButton, "Interactions", "interactions32x32_gray.png", "interactions32x32_dark.png"); setupButton(selectShoppingCartButton, "Panier", "shoppingcart32x32_gray.png", "shoppingcart32x32_dark.png"); setupButton(selectComparisonCartButton, "Preisvergleich", "comparisoncart32x32_gray.png", "comparisoncart32x32_dark.png"); } // Add to toolbar and set up toolBar.setBackground(m_toolbar_bg); toolBar.add(selectAipsButton); toolBar.addSeparator(); toolBar.add(selectFavoritesButton); toolBar.addSeparator(); toolBar.add(selectInteractionsButton); if (!Utilities.appCustomization().equals("zurrose")) { toolBar.addSeparator(); toolBar.add(selectShoppingCartButton); } if (Utilities.appCustomization().equals("zurrorse")) { toolBar.addSeparator(); toolBar.add(selectComparisonCartButton); } toolBar.setRollover(true); toolBar.setFloatable(false); // Progress indicator (not working...) toolBar.addSeparator(new Dimension(32, 32)); toolBar.add(m_progress_indicator); // ------ Setup settingspage ------ final SettingsPage settingsPage = new SettingsPage(jframe, m_rb); // Attach observer to it settingsPage.addObserver(new Observer() { public void update(Observable o, Object arg) { System.out.println(arg); if (m_shopping_cart != null) { // Refresh some stuff m_shopping_basket.clear(); int index = m_shopping_cart.getCartIndex(); if (index > 0) m_web_panel.saveShoppingCartWithIndex(index); m_web_panel.updateShoppingHtml(); } } }); jframe.addWindowListener(new WindowListener() { // Use WindowAdapter! @Override public void windowOpened(WindowEvent e) { } @Override public void windowClosed(WindowEvent e) { m_web_panel.dispose(); Runtime.getRuntime().exit(0); } @Override public void windowClosing(WindowEvent e) { // Save shopping cart int index = m_shopping_cart.getCartIndex(); if (index > 0 && m_web_panel != null) m_web_panel.saveShoppingCartWithIndex(index); } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } }); print_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { m_web_panel.print(); } }); settings_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { settingsPage.display(); } }); quit_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { try { // Save shopping cart int index = m_shopping_cart.getCartIndex(); if (index > 0 && m_web_panel != null) m_web_panel.saveShoppingCartWithIndex(index); // Save settings WindowSaver.saveSettings(); m_web_panel.dispose(); Runtime.getRuntime().exit(0); } catch (Exception e) { System.out.println(e); } } }); subscribe_menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent event) { if (Utilities.appCustomization().equals("ywesee")) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URI( "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3UM84Z6WLFKZE")); } catch (IOException e) { // TODO: } catch (URISyntaxException r) { // TODO: } } } } @Override public void menuDeselected(MenuEvent event) { // do nothing } @Override public void menuCanceled(MenuEvent event) { // do nothing } }); contact_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (Utilities.appCustomization().equals("ywesee")) { if (Desktop.isDesktopSupported()) { try { URI mail_to_uri = URI .create("mailto:zdavatz@ywesee.com?subject=AmiKo%20Desktop%20Feedback"); Desktop.getDesktop().mail(mail_to_uri); } catch (IOException e) { // TODO: } } else { AmiKoDialogs cd = new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization()); cd.ContactDialog(); } } else if (Utilities.appCustomization().equals("desitin")) { if (Desktop.isDesktopSupported()) { try { URI mail_to_uri = URI .create("mailto:info@desitin.ch?subject=AmiKo%20Desktop%20Desitin%20Feedback"); Desktop.getDesktop().mail(mail_to_uri); } catch (IOException e) { // TODO: } } else { AmiKoDialogs cd = new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization()); cd.ContactDialog(); } } else if (Utilities.appCustomization().equals("meddrugs")) { if (Desktop.isDesktopSupported()) { try { URI mail_to_uri = URI.create( "mailto:med-drugs@just-medical.com?subject=med-drugs%20desktop%20Feedback"); Desktop.getDesktop().mail(mail_to_uri); } catch (IOException e) { // TODO: } } else { AmiKoDialogs cd = new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization()); cd.ContactDialog(); } } else if (Utilities.appCustomization().equals("zurrose")) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URI("www.zurrose.ch/amiko")); } catch (IOException e) { // TODO: } catch (URISyntaxException r) { // TODO: } } } } }); report_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { // Check first m_application_folder otherwise resort to // pre-installed report String report_file = m_application_data_folder + "\\" + Constants.DEFAULT_AMIKO_REPORT_BASE + Utilities.appLanguage() + ".html"; if (!(new File(report_file)).exists()) report_file = System.getProperty("user.dir") + "/dbs/" + Constants.DEFAULT_AMIKO_REPORT_BASE + Utilities.appLanguage() + ".html"; // Open report file in browser if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new File(report_file).toURI()); } catch (IOException e) { // TODO: } } } }); ywesee_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (Utilities.appCustomization().equals("ywesee")) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URI("http://www.ywesee.com/AmiKo/Desktop")); } catch (IOException e) { // TODO: } catch (URISyntaxException r) { // TODO: } } } else if (Utilities.appCustomization().equals("desitin")) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse( new URI("http://www.desitin.ch/produkte/arzneimittel-kompendium-apps/")); } catch (IOException e) { // TODO: } catch (URISyntaxException r) { // TODO: } } } else if (Utilities.appCustomization().equals("meddrugs")) { if (Desktop.isDesktopSupported()) { try { if (Utilities.appLanguage().equals("de")) Desktop.getDesktop().browse(new URI("http://www.med-drugs.ch")); else if (Utilities.appLanguage().equals("fr")) Desktop.getDesktop() .browse(new URI("http://www.med-drugs.ch/index.cfm?&newlang=fr")); } catch (IOException e) { // TODO: } catch (URISyntaxException r) { // TODO: } } } else if (Utilities.appCustomization().equals("zurrose")) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(new URI("www.zurrose.ch/amiko")); } catch (IOException e) { // TODO: } catch (URISyntaxException r) { // TODO: } } } } }); about_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { AmiKoDialogs ad = new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization()); ad.AboutDialog(); } }); // Container final Container container = jframe.getContentPane(); container.setBackground(Color.WHITE); container.setLayout(new BorderLayout()); // ==== Toolbar ===== container.add(toolBar, BorderLayout.NORTH); // ==== Left panel ==== JPanel left_panel = new JPanel(); left_panel.setBackground(Color.WHITE); left_panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(2, 2, 2, 2); // ---- Search field ---- final SearchField searchField = new SearchField("Suche Prparat"); if (Utilities.appLanguage().equals("fr")) searchField.setText("Recherche Specialit"); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = gbc.gridheight = 1; gbc.weightx = gbc.weighty = 0.0; // --> container.add(searchField, gbc); left_panel.add(searchField, gbc); // ---- Buttons ---- // Names String l_title = "Prparat"; String l_author = "Inhaberin"; String l_atccode = "Wirkstoff / ATC Code"; String l_regnr = "Zulassungsnummer"; String l_ingredient = "Wirkstoff"; String l_therapy = "Therapie"; String l_search = "Suche"; if (Utilities.appLanguage().equals("fr")) { l_title = "Spcialit"; l_author = "Titulaire"; l_atccode = "Principe Active / Code ATC"; l_regnr = "Nombre Enregistration"; l_ingredient = "Principe Active"; l_therapy = "Thrapie"; l_search = "Recherche"; } ButtonGroup bg = new ButtonGroup(); JToggleButton but_title = new JToggleButton(l_title); setupToggleButton(but_title); bg.add(but_title); gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth = gbc.gridheight = 1; gbc.weightx = gbc.weighty = 0.0; // --> container.add(but_title, gbc); left_panel.add(but_title, gbc); JToggleButton but_auth = new JToggleButton(l_author); setupToggleButton(but_auth); bg.add(but_auth); gbc.gridx = 0; gbc.gridy += 1; gbc.gridwidth = gbc.gridheight = 1; gbc.weightx = gbc.weighty = 0.0; // --> container.add(but_auth, gbc); left_panel.add(but_auth, gbc); JToggleButton but_atccode = new JToggleButton(l_atccode); setupToggleButton(but_atccode); bg.add(but_atccode); gbc.gridx = 0; gbc.gridy += 1; gbc.gridwidth = gbc.gridheight = 1; gbc.weightx = gbc.weighty = 0.0; // --> container.add(but_atccode, gbc); left_panel.add(but_atccode, gbc); JToggleButton but_regnr = new JToggleButton(l_regnr); setupToggleButton(but_regnr); bg.add(but_regnr); gbc.gridx = 0; gbc.gridy += 1; gbc.gridwidth = gbc.gridheight = 1; gbc.weightx = gbc.weighty = 0.0; // --> container.add(but_regnr, gbc); left_panel.add(but_regnr, gbc); JToggleButton but_therapy = new JToggleButton(l_therapy); setupToggleButton(but_therapy); bg.add(but_therapy); gbc.gridx = 0; gbc.gridy += 1; gbc.gridwidth = gbc.gridheight = 1; gbc.weightx = gbc.weighty = 0.0; // --> container.add(but_therapy, gbc); left_panel.add(but_therapy, gbc); // ---- Card layout ---- final CardLayout cardl = new CardLayout(); cardl.setHgap(-4); // HACK to make things look better!! final JPanel p_results = new JPanel(cardl); m_list_titles = new ListPanel(); m_list_auths = new ListPanel(); m_list_regnrs = new ListPanel(); m_list_atccodes = new ListPanel(); m_list_ingredients = new ListPanel(); m_list_therapies = new ListPanel(); // Contraints gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 0; gbc.gridy += 1; gbc.gridwidth = 1; gbc.gridheight = 10; gbc.weightx = 1.0; gbc.weighty = 1.0; // p_results.add(m_list_titles, l_title); p_results.add(m_list_auths, l_author); p_results.add(m_list_regnrs, l_regnr); p_results.add(m_list_atccodes, l_atccode); p_results.add(m_list_ingredients, l_ingredient); p_results.add(m_list_therapies, l_therapy); // --> container.add(p_results, gbc); left_panel.add(p_results, gbc); left_panel.setBorder(null); // First card to show cardl.show(p_results, l_title); // ==== Right panel ==== JPanel right_panel = new JPanel(); right_panel.setBackground(Color.WHITE); right_panel.setLayout(new GridBagLayout()); // ---- Section titles ---- m_section_titles = null; if (Utilities.appLanguage().equals("de")) { m_section_titles = new IndexPanel(SectionTitle_DE); } else if (Utilities.appLanguage().equals("fr")) { m_section_titles = new IndexPanel(SectionTitle_FR); } m_section_titles.setMinimumSize(new Dimension(150, 150)); m_section_titles.setMaximumSize(new Dimension(320, 1000)); // ---- Fachinformation ---- m_web_panel = new WebPanel2(); m_web_panel.setMinimumSize(new Dimension(320, 150)); // Add JSplitPane on the RIGHT final int Divider_location = 150; final int Divider_size = 10; final JSplitPane split_pane_right = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, m_section_titles, m_web_panel); split_pane_right.setOneTouchExpandable(true); split_pane_right.setDividerLocation(Divider_location); split_pane_right.setDividerSize(Divider_size); // Add JSplitPane on the LEFT JSplitPane split_pane_left = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left_panel, split_pane_right /* right_panel */); split_pane_left.setOneTouchExpandable(true); split_pane_left.setDividerLocation(320); // Sets the pane divider location split_pane_left.setDividerSize(Divider_size); container.add(split_pane_left, BorderLayout.CENTER); // Add status bar on the bottom JPanel statusPanel = new JPanel(); statusPanel.setPreferredSize(new Dimension(jframe.getWidth(), 16)); statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); container.add(statusPanel, BorderLayout.SOUTH); final JLabel m_status_label = new JLabel(""); m_status_label.setHorizontalAlignment(SwingConstants.LEFT); statusPanel.add(m_status_label); // Add mouse listener searchField.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { searchField.setText(""); } }); final String final_title = l_title; final String final_author = l_author; final String final_atccode = l_atccode; final String final_regnr = l_regnr; final String final_therapy = l_therapy; final String final_search = l_search; // Internal class that implements switching between buttons final class Toggle { public void toggleButton(JToggleButton jbn) { for (int i = 0; i < list_of_buttons.length; ++i) { if (jbn == list_of_buttons[i]) list_of_buttons[i].setSelected(true); else list_of_buttons[i].setSelected(false); } } } ; // ------ Add toolbar action listeners ------ selectAipsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { new Toggle().toggleButton(selectAipsButton); // Set state 'aips' if (!m_curr_uistate.getUseMode().equals("aips")) { m_curr_uistate.setUseMode("aips"); // Show middle pane split_pane_right.setDividerSize(Divider_size); split_pane_right.setDividerLocation(Divider_location); m_section_titles.setVisible(true); // SwingUtilities.invokeLater(new Runnable() { @Override public void run() { m_start_time = System.currentTimeMillis(); m_query_str = searchField.getText(); int num_hits = retrieveAipsSearchResults(false); m_status_label.setText(med_search.size() + " Suchresultate in " + (System.currentTimeMillis() - m_start_time) / 1000.0f + " Sek."); // if (med_index < 0 && prev_med_index >= 0) med_index = prev_med_index; m_web_panel.updateText(); if (num_hits == 0) { m_web_panel.emptyPage(); } } }); } } }); selectFavoritesButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { new Toggle().toggleButton(selectFavoritesButton); // Set state 'favorites' if (!m_curr_uistate.getUseMode().equals("favorites")) { m_curr_uistate.setUseMode("favorites"); // Show middle pane split_pane_right.setDividerSize(Divider_size); split_pane_right.setDividerLocation(Divider_location); m_section_titles.setVisible(true); // SwingUtilities.invokeLater(new Runnable() { @Override public void run() { m_start_time = System.currentTimeMillis(); // m_query_str = searchField.getText(); // Clear the search container med_search.clear(); for (String regnr : favorite_meds_set) { List<Medication> meds = m_sqldb.searchRegNr(regnr); if (!meds.isEmpty()) { // Add med database ID med_search.add(meds.get(0)); } } // Sort list of meds Collections.sort(med_search, new Comparator<Medication>() { @Override public int compare(final Medication m1, final Medication m2) { return m1.getTitle().compareTo(m2.getTitle()); } }); sTitle(); cardl.show(p_results, final_title); m_status_label.setText(med_search.size() + " Suchresultate in " + (System.currentTimeMillis() - m_start_time) / 1000.0f + " Sek."); } }); } } }); selectInteractionsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { new Toggle().toggleButton(selectInteractionsButton); // Set state 'interactions' if (!m_curr_uistate.getUseMode().equals("interactions")) { m_curr_uistate.setUseMode("interactions"); // Show middle pane split_pane_right.setDividerSize(Divider_size); split_pane_right.setDividerLocation(Divider_location); m_section_titles.setVisible(true); // SwingUtilities.invokeLater(new Runnable() { @Override public void run() { m_query_str = searchField.getText(); retrieveAipsSearchResults(false); // Switch to interaction mode m_web_panel.updateInteractionsCart(); m_web_panel.repaint(); m_web_panel.validate(); } }); } } }); selectShoppingCartButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { String email_adr = m_prefs.get("emailadresse", ""); if (email_adr != null && email_adr.length() > 2) // Two chars is the minimum lenght for an email address m_preferences_ok = true; if (m_preferences_ok) { m_preferences_ok = false; // Check always new Toggle().toggleButton(selectShoppingCartButton); // Set state 'shopping' if (!m_curr_uistate.getUseMode().equals("shopping")) { m_curr_uistate.setUseMode("shopping"); // Show middle pane split_pane_right.setDividerSize(Divider_size); split_pane_right.setDividerLocation(Divider_location); m_section_titles.setVisible(true); // Set right panel title m_web_panel.setTitle(m_rb.getString("shoppingCart")); // Switch to shopping cart int index = 1; if (m_shopping_cart != null) { index = m_shopping_cart.getCartIndex(); m_web_panel.loadShoppingCartWithIndex(index); // m_shopping_cart.printShoppingBasket(); } // m_web_panel.updateShoppingHtml(); m_web_panel.updateListOfPackages(); if (m_first_pass == true) { m_first_pass = false; if (Utilities.appCustomization().equals("ywesee")) med_search = m_sqldb.searchAuth("ibsa"); else if (Utilities.appCustomization().equals("desitin")) med_search = m_sqldb.searchAuth("desitin"); sAuth(); cardl.show(p_results, final_author); } } } else { selectShoppingCartButton.setSelected(false); settingsPage.display(); } } }); selectComparisonCartButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { new Toggle().toggleButton(selectComparisonCartButton); // Set state 'comparison' if (!m_curr_uistate.getUseMode().equals("comparison")) { m_curr_uistate.setUseMode("comparison"); // Hide middle pane m_section_titles.setVisible(false); split_pane_right.setDividerLocation(0); split_pane_right.setDividerSize(0); // SwingUtilities.invokeLater(new Runnable() { @Override public void run() { m_start_time = System.currentTimeMillis(); // Set right panel title m_web_panel.setTitle(getTitle("priceComp")); if (med_index >= 0) { if (med_id != null && med_index < med_id.size()) { Medication m = m_sqldb.getMediWithId(med_id.get(med_index)); String atc_code = m.getAtcCode(); if (atc_code != null) { String atc = atc_code.split(";")[0]; m_web_panel.fillComparisonBasket(atc); m_web_panel.updateComparisonCartHtml(); // Update pane on the left retrieveAipsSearchResults(false); } } } m_status_label.setText(rose_search.size() + " Suchresultate in " + (System.currentTimeMillis() - m_start_time) / 1000.0f + " Sek."); } }); } } }); // ------ Add keylistener to text field (type as you go feature) ------ searchField.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { // keyReleased(KeyEvent e) // invokeLater potentially in the wrong place... more testing // required SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (m_curr_uistate.isLoadCart()) m_curr_uistate.restoreUseMode(); m_start_time = System.currentTimeMillis(); m_query_str = searchField.getText(); // Queries for SQLite DB if (!m_query_str.isEmpty()) { if (m_query_type == 0) { if (m_curr_uistate.isComparisonMode()) { rose_search = m_rosedb.searchTitle(m_query_str); } else { med_search = m_sqldb.searchTitle(m_query_str); if (m_curr_uistate.databaseUsed().equals("favorites")) retrieveFavorites(); } sTitle(); cardl.show(p_results, final_title); } else if (m_query_type == 1) { if (m_curr_uistate.isComparisonMode()) { rose_search = m_rosedb.searchSupplier(m_query_str); } else { med_search = m_sqldb.searchAuth(m_query_str); if (m_curr_uistate.databaseUsed().equals("favorites")) retrieveFavorites(); } sAuth(); cardl.show(p_results, final_author); } else if (m_query_type == 2) { if (m_curr_uistate.isComparisonMode()) { rose_search = m_rosedb.searchATC(m_query_str); } else { med_search = m_sqldb.searchATC(m_query_str); if (m_curr_uistate.databaseUsed().equals("favorites")) retrieveFavorites(); } sATC(); cardl.show(p_results, final_atccode); } else if (m_query_type == 3) { if (m_curr_uistate.isComparisonMode()) { rose_search = m_rosedb.searchEan(m_query_str); } else { med_search = m_sqldb.searchRegNr(m_query_str); if (m_curr_uistate.databaseUsed().equals("favorites")) retrieveFavorites(); } sRegNr(); cardl.show(p_results, final_regnr); } else if (m_query_type == 4) { if (m_curr_uistate.isComparisonMode()) { rose_search = m_rosedb.searchTherapy(m_query_str); } else { med_search = m_sqldb.searchApplication(m_query_str); if (m_curr_uistate.databaseUsed().equals("favorites")) retrieveFavorites(); } sTherapy(); cardl.show(p_results, final_therapy); } else { // do nothing } int num_hits = 0; if (m_curr_uistate.isComparisonMode()) num_hits = rose_search.size(); else num_hits = med_search.size(); m_status_label.setText(num_hits + " Suchresultate in " + (System.currentTimeMillis() - m_start_time) / 1000.0f + " Sek."); } } }); } }); // Add actionlisteners but_title.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (m_curr_uistate.isLoadCart()) m_curr_uistate.restoreUseMode(); searchField.setText(final_search + " " + final_title); m_curr_uistate.setQueryType(m_query_type = 0); sTitle(); cardl.show(p_results, final_title); } }); but_auth.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (m_curr_uistate.isLoadCart()) m_curr_uistate.restoreUseMode(); searchField.setText(final_search + " " + final_author); m_curr_uistate.setQueryType(m_query_type = 1); sAuth(); cardl.show(p_results, final_author); } }); but_atccode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (m_curr_uistate.isLoadCart()) m_curr_uistate.restoreUseMode(); searchField.setText(final_search + " " + final_atccode); m_curr_uistate.setQueryType(m_query_type = 2); sATC(); cardl.show(p_results, final_atccode); } }); but_regnr.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (m_curr_uistate.isLoadCart()) m_curr_uistate.restoreUseMode(); searchField.setText(final_search + " " + final_regnr); m_curr_uistate.setQueryType(m_query_type = 3); sRegNr(); cardl.show(p_results, final_regnr); } }); but_therapy.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (m_curr_uistate.isLoadCart()) m_curr_uistate.restoreUseMode(); searchField.setText(final_search + " " + final_therapy); m_curr_uistate.setQueryType(m_query_type = 4); sTherapy(); cardl.show(p_results, final_therapy); } }); // Display window jframe.pack(); // jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // jframe.setAlwaysOnTop(true); jframe.setVisible(true); // Check if user has selected an alternative database /* * NOTE: 21/11/2013: This solution is put on ice. Favored is a solution * where the database selected by the user is saved in a default folder * (see variable "m_application_data_folder") */ /* * try { WindowSaver.loadSettings(jframe); String database_path = * WindowSaver.getDbPath(); if (database_path!=null) * m_sqldb.loadDBFromPath(database_path); } catch(IOException e) { * e.printStackTrace(); } */ // Load AIPS database selectAipsButton.setSelected(true); selectFavoritesButton.setSelected(false); m_curr_uistate.setUseMode("aips"); med_search = m_sqldb.searchTitle(""); sTitle(); // Used instead of sTitle (which is slow) cardl.show(p_results, final_title); // Add menu item listeners updatedb_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (m_mutex_update == false) { m_mutex_update = true; String db_file = m_maindb_update.doIt(jframe, Utilities.appLanguage(), Utilities.appCustomization(), m_application_data_folder, m_full_db_update); // ... and update time if (m_full_db_update == true) { DateTime dT = new DateTime(); m_prefs.put("updateTime", dT.now().toString()); } // if (!db_file.isEmpty()) { // Save db path (can't hurt) WindowSaver.setDbPath(db_file); } } } }); choosedb_item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { String db_file = m_maindb_update.chooseFromFile(jframe, Utilities.appLanguage(), Utilities.appCustomization(), m_application_data_folder); // ... and update time DateTime dT = new DateTime(); m_prefs.put("updateTime", dT.now().toString()); // if (!db_file.isEmpty()) { // Save db path (can't hurt) WindowSaver.setDbPath(db_file); } } }); /** * Observers */ // Attach observer to 'm_update' m_maindb_update.addObserver(new Observer() { @Override public void update(Observable o, Object arg) { System.out.println(arg); // Reset flag m_full_db_update = true; m_mutex_update = false; // Refresh some stuff after update loadAuthors(); m_emailer.loadMap(); settingsPage.load_gln_codes(); if (m_shopping_cart != null) { m_shopping_cart.load_conditions(); m_shopping_cart.load_glns(); } // Empty shopping basket if (m_curr_uistate.isShoppingMode()) { m_shopping_basket.clear(); int index = m_shopping_cart.getCartIndex(); if (index > 0) m_web_panel.saveShoppingCartWithIndex(index); m_web_panel.updateShoppingHtml(); } if (m_curr_uistate.isComparisonMode()) m_web_panel.setTitle(getTitle("priceComp")); } }); // Attach observer to 'm_emailer' m_emailer.addObserver(new Observer() { @Override public void update(Observable o, Object arg) { System.out.println(arg); // Empty shopping basket m_shopping_basket.clear(); int index = m_shopping_cart.getCartIndex(); if (index > 0) m_web_panel.saveShoppingCartWithIndex(index); m_web_panel.updateShoppingHtml(); } }); // Attach observer to "m_comparison_cart" m_comparison_cart.addObserver(new Observer() { @Override public void update(Observable o, Object arg) { System.out.println(arg); m_web_panel.setTitle(getTitle("priceComp")); m_comparison_cart.clearUploadList(); m_web_panel.updateComparisonCartHtml(); new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization()).UploadDialog((String) arg); } }); // If command line options are provided start app with a particular title or eancode if (commandLineOptionsProvided()) { if (!CML_OPT_TITLE.isEmpty()) startAppWithTitle(but_title); else if (!CML_OPT_EANCODE.isEmpty()) startAppWithEancode(but_regnr); else if (!CML_OPT_REGNR.isEmpty()) startAppWithRegnr(but_regnr); } // Start timer Timer global_timer = new Timer(); // Time checks all 2 minutes (120'000 milliseconds) global_timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { checkIfUpdateRequired(updatedb_item); } }, 2 * 60 * 1000, 2 * 60 * 1000); }
From source file:src.gui.ItSIMPLE.java
/** * This method initializes toolBar/*from w w w . j ava2 s. com*/ * * @return javax.swing.JToolBar */ private JToolBar getToolBar() { if (toolBar == null) { toolBar = new JToolBar(); toolBar.setRollover(true); toolBar.add(newProjectAction).setToolTipText("New UML Project"); toolBar.add(openProjectAction).setToolTipText("Open Project"); toolBar.add(saveAction).setToolTipText("Save Project"); toolBar.add(saveAllAction).setToolTipText("Save All"); toolBar.addSeparator(); perspectiveGroup = new ButtonGroup(); //toolBar.add(modelingAction).setToolTipText("Modeling domains"); modelingPerspectiveButton = new JToggleButton(modelingAction); modelingPerspectiveButton.setToolTipText("Modeling domains and problems"); perspectiveGroup.add(modelingPerspectiveButton); toolBar.add(modelingPerspectiveButton); //set modeling perpective selected by dafault perspectiveGroup.setSelected(modelingPerspectiveButton.getModel(), true); //toolBar.add(analysisAction).setToolTipText("Model analysis with different techniques and formalism"); analysisPerspectiveButton = new JToggleButton(analysisAction); analysisPerspectiveButton.setToolTipText("Model analysis using different techniques and formalism"); perspectiveGroup.add(analysisPerspectiveButton); toolBar.add(analysisPerspectiveButton); //toolBar.add(planningAction).setToolTipText("Planning process and experiments with planners and solvers"); planningPerspectiveButton = new JToggleButton(planningAction); planningPerspectiveButton.setToolTipText("Planning process and experiments using planners and solvers"); perspectiveGroup.add(planningPerspectiveButton); toolBar.add(planningPerspectiveButton); toolBar.addSeparator(); //toolBar.add(pddlTranslationPerspectiveAction).setToolTipText("UML to PDDL translation perspective"); pddlTranslationPerspectiveButton = new JToggleButton(pddlTranslationPerspectiveAction); pddlTranslationPerspectiveButton.setToolTipText("UML to PDDL translation"); perspectiveGroup.add(pddlTranslationPerspectiveButton); toolBar.add(pddlTranslationPerspectiveButton); //toolBar.addSeparator(); //toolBar.add(umlPerspectiveAction).setToolTipText("Set UML perspective"); //toolBar.add(pddlPerspectiveAction).setToolTipText("Set PDDL perspective"); } return toolBar; }
From source file:op.controlling.PnlControlling.java
private JPanel createContentPanel4Drugs() { JPanel pnlContent = new JPanel(new VerticalLayout()); /***//w w w . j a v a2 s. co m * ____ ____ _ _ _ _ _ * | _ \ _ __ _ _ __ _ / ___|___ _ __ | |_ _ __ ___ | | | | (_)___| |_ * | | | | '__| | | |/ _` | | | / _ \| '_ \| __| '__/ _ \| | | | | / __| __| * | |_| | | | |_| | (_| | | |__| (_) | | | | |_| | | (_) | | | |___| \__ \ |_ * |____/|_| \__,_|\__, | \____\___/|_| |_|\__|_| \___/|_| |_____|_|___/\__| * |___/ */ JPanel pnlDrugControl = new JPanel(new BorderLayout()); final JButton btnDrugControl = GUITools.createHyperlinkButton("opde.controlling.drugs.controllist", null, null); final JComboBox cmbStation = new JComboBox(StationTools.getAll4Combobox(false)); btnDrugControl.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { return MedStockTools.getListForMedControl((Station) cmbStation.getSelectedItem(), progressClosure); } @Override protected void done() { try { SYSFilesTools.print(get().toString(), true); } catch (ExecutionException ee) { OPDE.fatal(ee); } catch (InterruptedException ie) { // nop } OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); pnlDrugControl.add(btnDrugControl, BorderLayout.WEST); pnlDrugControl.add(cmbStation, BorderLayout.EAST); pnlContent.add(pnlDrugControl); /*** * __ __ _ _ _ ____ _ _ _ _ _ _ * \ \ / /__(_) __ _| |__ | |_ / ___|___ _ __ | |_ _ __ ___ | | | \ | | __ _ _ __ ___ ___ | |_(_) ___ ___ * \ \ /\ / / _ \ |/ _` | '_ \| __| | / _ \| '_ \| __| '__/ _ \| | | \| |/ _` | '__/ __/ _ \| __| |/ __/ __| * \ V V / __/ | (_| | | | | |_| |__| (_) | | | | |_| | | (_) | | | |\ | (_| | | | (_| (_) | |_| | (__\__ \ * \_/\_/ \___|_|\__, |_| |_|\__|\____\___/|_| |_|\__|_| \___/|_| |_| \_|\__,_|_| \___\___/ \__|_|\___|___/ * |___/ */ JPanel pnlWeightControllNarcotics = new JPanel(new BorderLayout()); final JButton btnWeightControl = GUITools .createHyperlinkButton("opde.controlling.prescription.narcotics.weightcontrol", null, null); // final JComboBox cmbStation = new JComboBox(StationTools.getAll4Combobox(false)); btnWeightControl.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { return MedStockTools.getNarcoticsWeightList(new LocalDate().minusMonths(1), new LocalDate()); } @Override protected void done() { try { SYSFilesTools.print(get().toString(), true); } catch (ExecutionException ee) { OPDE.fatal(ee); } catch (InterruptedException ie) { // nop } OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); final JToggleButton btnNotify = new JToggleButton(SYSConst.icon22mailOFF); btnNotify.setSelectedIcon(SYSConst.icon22mailON); btnNotify.setSelected(NotificationTools.find(OPDE.getLogin().getUser(), NotificationTools.NKEY_DRUG_WEIGHT_CONTROL) != null); btnNotify.setToolTipText(SYSTools.xx("opde.notification.enable.for.this.topic")); btnNotify.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Users user = em.merge(OPDE.getLogin().getUser()); em.lock(user, LockModeType.OPTIMISTIC_FORCE_INCREMENT); if (e.getStateChange() == ItemEvent.SELECTED) { Notification myNotification = em .merge(new Notification(NotificationTools.NKEY_DRUG_WEIGHT_CONTROL, user)); user.getNotifications().add(myNotification); } else { Notification myNotification = em.merge(NotificationTools.find(OPDE.getLogin().getUser(), NotificationTools.NKEY_DRUG_WEIGHT_CONTROL)); user.getNotifications().remove(myNotification); em.remove(myNotification); } em.getTransaction().commit(); OPDE.getLogin().setUser(user); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception ex) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(ex); } finally { em.close(); } } }); pnlWeightControllNarcotics.add(btnWeightControl, BorderLayout.WEST); pnlWeightControllNarcotics.add(btnNotify, BorderLayout.EAST); pnlContent.add(pnlWeightControllNarcotics); return pnlContent; }
From source file:org.apereo.learninganalytics.snapp.ClusteringDemo.java
private void setUpView(Graph<Integer, Number> grp, Map<Integer, String> name) { /*/*from w ww . ja va 2s. c o m*/ Factory<Number> vertexFactory = new Factory<Number>() { int n = 0; public Number create() { return n++; } }; Factory<Number> edgeFactory = new Factory<Number>() { int n = 0; public Number create() { return n++; } }; PajekNetReader<Graph<Number, Number>, Number,Number> pnr = new PajekNetReader<Graph<Number, Number>, Number,Number>(vertexFactory, edgeFactory); final Graph<Number,Number> graph = new SparseMultigraph<Number, Number>(); pnr.load(br, graph); */ //Create a simple layout frame //specify the Fruchterman-Rheingold layout algorithm this.usernames = name; final AggregateLayout<Integer, Number> layout = new AggregateLayout<Integer, Number>( new FRLayout<Integer, Number>(grp)); layout.setSize(new Dimension(500, 500)); vv = new VisualizationViewer<Integer, Number>(layout); vv.setBackground(Color.white); //Tell the renderer to use our own customized color rendering vv.getRenderContext() .setVertexFillPaintTransformer(MapTransformer.<Integer, Paint>getInstance(vertexPaints)); vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<Integer, Paint>() { public Paint transform(Integer v) { if (vv.getPickedVertexState().isPicked(v)) { return Color.cyan; } else { return Color.BLACK; } } }); vv.getRenderContext().setEdgeDrawPaintTransformer(MapTransformer.<Number, Paint>getInstance(edgePaints)); vv.getRenderContext().setEdgeStrokeTransformer(new Transformer<Number, Stroke>() { protected final Stroke THIN = new BasicStroke(1); protected final Stroke THICK = new BasicStroke(2); public Stroke transform(Number e) { Paint c = edgePaints.get(e); if (c == Color.LIGHT_GRAY) return THIN; else return THICK; } }); vv.getRenderContext().setVertexLabelTransformer( // this chains together Transformers so that the html tags // are prepended to the toString method output new ChainedTransformer<Integer, String>( new Transformer[] { new ToStringLabeller<String>(), new Transformer<String, String>() { public String transform(String input) { return usernames.get(Integer.parseInt(input)); } } })); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.S); /* //add restart button JButton scramble = new JButton("Restart"); scramble.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Layout layout = vv.getGraphLayout(); layout.initialize(); Relaxer relaxer = vv.getModel().getRelaxer(); if(relaxer != null) { relaxer.stop(); relaxer.prerelax(); relaxer.relax(); } } }); */ DefaultModalGraphMouse gm = new DefaultModalGraphMouse(); vv.setGraphMouse(gm); final JToggleButton groupVertices = new JToggleButton("Group Clusters"); //Create slider to adjust the number of edges to remove when clustering final JSlider edgeBetweennessSlider = new JSlider(JSlider.HORIZONTAL); edgeBetweennessSlider.setBackground(Color.WHITE); edgeBetweennessSlider.setPreferredSize(new Dimension(210, 50)); edgeBetweennessSlider.setPaintTicks(true); edgeBetweennessSlider.setMaximum(grp.getEdgeCount()); edgeBetweennessSlider.setMinimum(0); edgeBetweennessSlider.setValue(0); edgeBetweennessSlider.setMajorTickSpacing(10); edgeBetweennessSlider.setPaintLabels(true); edgeBetweennessSlider.setPaintTicks(true); // edgeBetweennessSlider.setBorder(BorderFactory.createLineBorder(Color.black)); //TO DO: edgeBetweennessSlider.add(new JLabel("Node Size (PageRank With Priors):")); //I also want the slider value to appear final JPanel eastControls = new JPanel(); eastControls.setOpaque(true); eastControls.setLayout(new BoxLayout(eastControls, BoxLayout.Y_AXIS)); eastControls.add(Box.createVerticalGlue()); eastControls.add(edgeBetweennessSlider); final String COMMANDSTRING = "Edges removed for clusters: "; final String eastSize = COMMANDSTRING + edgeBetweennessSlider.getValue(); final TitledBorder sliderBorder = BorderFactory.createTitledBorder(eastSize); eastControls.setBorder(sliderBorder); //eastControls.add(eastSize); eastControls.add(Box.createVerticalGlue()); groupVertices.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { clusterAndRecolor(layout, edgeBetweennessSlider.getValue(), similarColors, e.getStateChange() == ItemEvent.SELECTED); vv.repaint(); } }); clusterAndRecolor(layout, 0, similarColors, groupVertices.isSelected()); edgeBetweennessSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (!source.getValueIsAdjusting()) { int numEdgesToRemove = source.getValue(); clusterAndRecolor(layout, numEdgesToRemove, similarColors, groupVertices.isSelected()); sliderBorder.setTitle(COMMANDSTRING + edgeBetweennessSlider.getValue()); eastControls.repaint(); vv.validate(); vv.repaint(); } } }); // Add a restart button so the graph can be redrawn to fit the size of the frame JFrame jf = new JFrame("SNAPP: Find Clusters"); //jf.getContentPane().add(); //Container content = getContentPane(); //content.add(new GraphZoomScrollPane(vv)); jf.getContentPane().add(new GraphZoomScrollPane(vv)); JPanel south = new JPanel(); JPanel grid = new JPanel(new GridLayout(2, 1)); //grid.add(scramble); grid.add(groupVertices); south.add(grid); south.add(eastControls); JPanel p = new JPanel(); p.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); p.add(gm.getModeComboBox()); south.add(p); //content.add(south, BorderLayout.SOUTH); jf.getContentPane().add(south, BorderLayout.SOUTH); //jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.pack(); jf.setVisible(true); }
From source file:org.datavyu.controllers.component.MixerController.java
private void initView() { // Set default scale values minStart = 0;//from ww w .j a v a 2 s.c o m listenerList = new EventListenerList(); // Set up the root panel tracksPanel = new JPanel(); tracksPanel.setLayout(new MigLayout("ins 0", "[left|left|left|left]rel push[right|right]", "")); tracksPanel.setBackground(Color.WHITE); if (Platform.isMac()) { osxGestureListener.register(tracksPanel); } // Menu buttons lockToggle = new JToggleButton("Lock all"); lockToggle.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { lockToggleHandler(e); } }); lockToggle.setName("lockToggleButton"); bookmarkButton = new JButton("Add Bookmark"); bookmarkButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { addBookmarkHandler(); } }); bookmarkButton.setEnabled(false); bookmarkButton.setName("bookmarkButton"); JButton snapRegion = new JButton("Snap Region"); snapRegion.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { snapRegionHandler(e); } }); snapRegion.setName("snapRegionButton"); JButton clearRegion = new JButton("Clear Region"); clearRegion.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { clearRegionHandler(e); } }); clearRegion.setName("clearRegionButton"); zoomSlide = new JSlider(JSlider.HORIZONTAL, 1, 1000, 1); zoomSlide.addChangeListener(new ChangeListener() { public void stateChanged(final ChangeEvent e) { if (!isUpdatingZoomSlide && zoomSlide.getValueIsAdjusting()) { try { isUpdatingZoomSlide = true; zoomSetting = (double) (zoomSlide.getValue() - zoomSlide.getMinimum()) / (zoomSlide.getMaximum() - zoomSlide.getMinimum() + 1); viewportModel.setViewportZoom(zoomSetting, needleController.getNeedleModel().getCurrentTime()); } finally { isUpdatingZoomSlide = false; } } } }); zoomSlide.setName("zoomSlider"); zoomSlide.setBackground(tracksPanel.getBackground()); JButton zoomRegionButton = new JButton("", zoomIcon); zoomRegionButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { zoomToRegion(e); } }); zoomRegionButton.setName("zoomRegionButton"); tracksPanel.add(lockToggle); tracksPanel.add(bookmarkButton); tracksPanel.add(snapRegion); tracksPanel.add(clearRegion); tracksPanel.add(zoomRegionButton); tracksPanel.add(zoomSlide, "wrap"); timescaleController = new TimescaleController(mixerModel); timescaleController.addTimescaleEventListener(this); needleController = new NeedleController(this, mixerModel); regionController = new RegionController(mixerModel); tracksEditorController = new TracksEditorController(this, mixerModel); needleController.setTimescaleTransitionHeight( timescaleController.getTimescaleModel().getZoomWindowToTrackTransitionHeight()); needleController .setZoomIndicatorHeight(timescaleController.getTimescaleModel().getZoomWindowIndicatorHeight()); // Set up the layered pane layeredPane = new JLayeredPane(); layeredPane.setLayout(new MigLayout("fillx, ins 0")); final int layeredPaneHeight = 272; final int timescaleViewHeight = timescaleController.getTimescaleModel().getHeight(); final int needleHeadHeight = (int) Math.ceil(NeedleConstants.NEEDLE_HEAD_HEIGHT); final int tracksScrollPaneY = needleHeadHeight + 1; final int timescaleViewY = layeredPaneHeight - MixerConstants.HSCROLL_HEIGHT - timescaleViewHeight; final int tracksScrollPaneHeight = timescaleViewY - tracksScrollPaneY; final int tracksScrollBarY = timescaleViewY + timescaleViewHeight; final int needleAndRegionMarkerHeight = (timescaleViewY + timescaleViewHeight - timescaleController.getTimescaleModel().getZoomWindowIndicatorHeight() - timescaleController.getTimescaleModel().getZoomWindowToTrackTransitionHeight() + 1); // Set up filler component responsible for horizontal resizing of the // layout. { // Null args; let layout manager handle sizes. Box.Filler filler = new Filler(null, null, null); filler.setName("Filler"); filler.addComponentListener(new SizeHandler()); Map<String, String> constraints = Maps.newHashMap(); constraints.put("wmin", Integer.toString(MixerConstants.MIXER_MIN_WIDTH)); // TODO Could probably use this same component to handle vertical // resizing... String template = "id filler, h 0!, grow 100 0, wmin ${wmin}, cell 0 0 "; StrSubstitutor sub = new StrSubstitutor(constraints); layeredPane.setLayer(filler, MixerConstants.FILLER_ZORDER); layeredPane.add(filler, sub.replace(template), MixerConstants.FILLER_ZORDER); } // Set up the timescale layout { JComponent timescaleView = timescaleController.getView(); Map<String, String> constraints = Maps.newHashMap(); constraints.put("x", Integer.toString(TimescaleConstants.XPOS_ABS)); constraints.put("y", Integer.toString(timescaleViewY)); // Calculate padding from the right int rightPad = (int) (RegionConstants.RMARKER_WIDTH + MixerConstants.VSCROLL_WIDTH + MixerConstants.R_EDGE_PAD); constraints.put("x2", "(filler.w-" + rightPad + ")"); constraints.put("y2", "(tscale.y+${height})"); constraints.put("height", Integer.toString(timescaleViewHeight)); String template = "id tscale, pos ${x} ${y} ${x2} ${y2}"; StrSubstitutor sub = new StrSubstitutor(constraints); // Must call setLayer first. layeredPane.setLayer(timescaleView, MixerConstants.TIMESCALE_ZORDER); layeredPane.add(timescaleView, sub.replace(template), MixerConstants.TIMESCALE_ZORDER); } // Set up the scroll pane's layout. { tracksScrollPane = new JScrollPane(tracksEditorController.getView()); tracksScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); tracksScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); tracksScrollPane.setBorder(BorderFactory.createEmptyBorder()); tracksScrollPane.setName("jScrollPane"); Map<String, String> constraints = Maps.newHashMap(); constraints.put("x", "0"); constraints.put("y", Integer.toString(tracksScrollPaneY)); constraints.put("x2", "(filler.w-" + MixerConstants.R_EDGE_PAD + ")"); constraints.put("height", Integer.toString(tracksScrollPaneHeight)); String template = "pos ${x} ${y} ${x2} n, h ${height}!"; StrSubstitutor sub = new StrSubstitutor(constraints); layeredPane.setLayer(tracksScrollPane, MixerConstants.TRACKS_ZORDER); layeredPane.add(tracksScrollPane, sub.replace(template), MixerConstants.TRACKS_ZORDER); } // Create the region markers and set up the layout. { JComponent regionView = regionController.getView(); Map<String, String> constraints = Maps.newHashMap(); int x = (int) (TrackConstants.HEADER_WIDTH - RegionConstants.RMARKER_WIDTH); constraints.put("x", Integer.toString(x)); constraints.put("y", "0"); // Padding from the right int rightPad = MixerConstants.R_EDGE_PAD + MixerConstants.VSCROLL_WIDTH - 2; constraints.put("x2", "(filler.w-" + rightPad + ")"); constraints.put("height", Integer.toString(needleAndRegionMarkerHeight)); String template = "pos ${x} ${y} ${x2} n, h ${height}::"; StrSubstitutor sub = new StrSubstitutor(constraints); layeredPane.setLayer(regionView, MixerConstants.REGION_ZORDER); layeredPane.add(regionView, sub.replace(template), MixerConstants.REGION_ZORDER); } // Set up the timing needle's layout { JComponent needleView = needleController.getView(); Map<String, String> constraints = Maps.newHashMap(); int x = (int) (TrackConstants.HEADER_WIDTH - NeedleConstants.NEEDLE_HEAD_WIDTH + NeedleConstants.NEEDLE_WIDTH); constraints.put("x", Integer.toString(x)); constraints.put("y", "0"); // Padding from the right int rightPad = MixerConstants.R_EDGE_PAD + MixerConstants.VSCROLL_WIDTH - 1; constraints.put("x2", "(filler.w-" + rightPad + ")"); constraints.put("height", Integer.toString(needleAndRegionMarkerHeight + timescaleController.getTimescaleModel().getZoomWindowToTrackTransitionHeight() + timescaleController.getTimescaleModel().getZoomWindowIndicatorHeight() - 1)); String template = "pos ${x} ${y} ${x2} n, h ${height}::"; StrSubstitutor sub = new StrSubstitutor(constraints); layeredPane.setLayer(needleView, MixerConstants.NEEDLE_ZORDER); layeredPane.add(needleView, sub.replace(template), MixerConstants.NEEDLE_ZORDER); } // Set up the snap marker's layout { JComponent markerView = tracksEditorController.getMarkerView(); Map<String, String> constraints = Maps.newHashMap(); constraints.put("x", Integer.toString(TimescaleConstants.XPOS_ABS)); constraints.put("y", Integer.toString(needleHeadHeight + 1)); // Padding from the right int rightPad = MixerConstants.R_EDGE_PAD + MixerConstants.VSCROLL_WIDTH - 1; constraints.put("x2", "(filler.w-" + rightPad + ")"); constraints.put("height", Integer.toString(needleAndRegionMarkerHeight - needleHeadHeight - 1)); String template = "pos ${x} ${y} ${x2} n, h ${height}::"; StrSubstitutor sub = new StrSubstitutor(constraints); layeredPane.setLayer(markerView, MixerConstants.MARKER_ZORDER); layeredPane.add(markerView, sub.replace(template), MixerConstants.MARKER_ZORDER); } // Set up the tracks horizontal scroll bar { tracksScrollBar = new JScrollBar(Adjustable.HORIZONTAL); tracksScrollBar.setValues(0, TRACKS_SCROLL_BAR_RANGE, 0, TRACKS_SCROLL_BAR_RANGE); tracksScrollBar.setUnitIncrement(TRACKS_SCROLL_BAR_RANGE / 20); tracksScrollBar.setBlockIncrement(TRACKS_SCROLL_BAR_RANGE / 2); tracksScrollBar.addAdjustmentListener(this); tracksScrollBar.setValueIsAdjusting(false); tracksScrollBar.setVisible(false); tracksScrollBar.setName("horizontalScrollBar"); Map<String, String> constraints = Maps.newHashMap(); constraints.put("x", Integer.toString(TimescaleConstants.XPOS_ABS)); constraints.put("y", Integer.toString(tracksScrollBarY)); int rightPad = (int) (RegionConstants.RMARKER_WIDTH + MixerConstants.VSCROLL_WIDTH + MixerConstants.R_EDGE_PAD); constraints.put("x2", "(filler.w-" + rightPad + ")"); constraints.put("height", Integer.toString(MixerConstants.HSCROLL_HEIGHT)); String template = "pos ${x} ${y} ${x2} n, h ${height}::"; StrSubstitutor sub = new StrSubstitutor(constraints); layeredPane.setLayer(tracksScrollBar, MixerConstants.TRACKS_SB_ZORDER); layeredPane.add(tracksScrollBar, sub.replace(template), MixerConstants.TRACKS_SB_ZORDER); } { Map<String, String> constraints = Maps.newHashMap(); constraints.put("span", "6"); constraints.put("width", Integer.toString(MixerConstants.MIXER_MIN_WIDTH)); constraints.put("height", Integer.toString(layeredPaneHeight)); String template = "growx, span ${span}, w ${width}::, h ${height}::, wrap"; StrSubstitutor sub = new StrSubstitutor(constraints); tracksPanel.add(layeredPane, sub.replace(template)); } tracksPanel.validate(); }
From source file:org.geopublishing.atlasStyler.swing.AtlasStylerGUI.java
public JToggleButton getJTButtonShowXML() { final JToggleButton jButtonShowXML = new JToggleButton(ASUtil.R("AtlasStylerGUI.toolbarButton.show_xml")); jButtonShowXML.setSelected(false);//w w w .j a v a2 s . co m jButtonShowXML.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { boolean anAus = !xmlCodeFrame.isVisible(); xmlCodeFrame.setVisible(anAus); // jButtonShowXML.setSelected(anAus); xmlCodeFrame.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { jButtonShowXML.setSelected(false); } }); } }); return jButtonShowXML; }