List of usage examples for javax.swing JCheckBox setSelected
public void setSelected(boolean b)
From source file:org.languagetool.gui.ConfigurationDialog.java
private void createOfficeElements(GridBagConstraints cons, JPanel portPanel) { int numParaCheck = config.getNumParasToCheck(); JRadioButton[] radioButtons = new JRadioButton[3]; ButtonGroup numParaGroup = new ButtonGroup(); radioButtons[0] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckOnlyParagraph"))); radioButtons[0].setActionCommand("ParagraphCheck"); radioButtons[1] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckFullText"))); radioButtons[1].setActionCommand("FullTextCheck"); radioButtons[2] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckNumParagraphs"))); radioButtons[2].setActionCommand("NParagraphCheck"); radioButtons[2].setSelected(true);// w ww . j a v a2 s .c o m JTextField numParaField = new JTextField(Integer.toString(5), 2); numParaField.setEnabled(radioButtons[2].isSelected()); numParaField.setMinimumSize(new Dimension(30, 25)); for (int i = 0; i < 3; i++) { numParaGroup.add(radioButtons[i]); } if (numParaCheck == 0) { radioButtons[0].setSelected(true); numParaField.setEnabled(false); } else if (numParaCheck < 0) { radioButtons[1].setSelected(true); numParaField.setEnabled(false); } else { radioButtons[2].setSelected(true); numParaField.setText(Integer.toString(numParaCheck)); numParaField.setEnabled(true); } radioButtons[0].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { numParaField.setEnabled(false); config.setNumParasToCheck(0); } }); radioButtons[1].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { numParaField.setEnabled(false); config.setNumParasToCheck(-1); } }); radioButtons[2].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int numParaCheck = Integer.parseInt(numParaField.getText()); if (numParaCheck < 1) numParaCheck = 1; else if (numParaCheck > 99) numParaCheck = 99; config.setNumParasToCheck(numParaCheck); numParaField.setForeground(Color.BLACK); numParaField.setText(Integer.toString(numParaCheck)); numParaField.setEnabled(true); } }); numParaField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { changedUpdate(e); } @Override public void removeUpdate(DocumentEvent e) { changedUpdate(e); } @Override public void changedUpdate(DocumentEvent e) { try { int numParaCheck = Integer.parseInt(numParaField.getText()); if (numParaCheck > 0 && numParaCheck < 99) { numParaField.setForeground(Color.BLACK); config.setNumParasToCheck(numParaCheck); } else { numParaField.setForeground(Color.RED); } } catch (NumberFormatException ex) { numParaField.setForeground(Color.RED); } } }); JLabel textChangedLabel = new JLabel(Tools.getLabel(messages.getString("guiTextChangeLabel"))); cons.gridy++; portPanel.add(textChangedLabel, cons); cons.gridy++; cons.insets = new Insets(0, 30, 0, 0); for (int i = 0; i < 3; i++) { portPanel.add(radioButtons[i], cons); if (i < 2) cons.gridy++; } cons.gridx = 1; portPanel.add(numParaField, cons); JCheckBox noMultiResetbox = new JCheckBox(Tools.getLabel(messages.getString("guiNoMultiReset"))); noMultiResetbox.setSelected(config.isNoMultiReset()); noMultiResetbox.setEnabled(config.isResetCheck()); noMultiResetbox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { config.setNoMultiReset(noMultiResetbox.isSelected()); } }); JCheckBox resetCheckbox = new JCheckBox(Tools.getLabel(messages.getString("guiDoResetCheck"))); resetCheckbox.setSelected(config.isResetCheck()); resetCheckbox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { config.setDoResetCheck(resetCheckbox.isSelected()); noMultiResetbox.setEnabled(resetCheckbox.isSelected()); } }); cons.insets = new Insets(0, 4, 0, 0); cons.gridx = 0; // JLabel dummyLabel = new JLabel(" "); // cons.gridy++; // portPanel.add(dummyLabel, cons); cons.gridy++; portPanel.add(resetCheckbox, cons); cons.insets = new Insets(0, 30, 0, 0); cons.gridx = 0; cons.gridy++; portPanel.add(noMultiResetbox, cons); JCheckBox fullTextCheckAtFirstBox = new JCheckBox( Tools.getLabel(messages.getString("guiCheckFullTextAtFirst"))); fullTextCheckAtFirstBox.setSelected(config.doFullCheckAtFirst()); fullTextCheckAtFirstBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { config.setFullCheckAtFirst(fullTextCheckAtFirstBox.isSelected()); } }); cons.insets = new Insets(0, 4, 0, 0); cons.gridx = 0; // cons.gridy++; // JLabel dummyLabel2 = new JLabel(" "); // portPanel.add(dummyLabel2, cons); cons.gridy++; portPanel.add(fullTextCheckAtFirstBox, cons); JCheckBox isMultiThreadBox = new JCheckBox(Tools.getLabel(messages.getString("guiIsMultiThread"))); isMultiThreadBox.setSelected(config.isMultiThread()); isMultiThreadBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { config.setMultiThreadLO(isMultiThreadBox.isSelected()); } }); cons.gridy++; JLabel dummyLabel3 = new JLabel(" "); portPanel.add(dummyLabel3, cons); cons.gridy++; portPanel.add(isMultiThreadBox, cons); }
From source file:org.languagetool.gui.ConfigurationDialog.java
private JPanel getSpecialRuleValuePanel() { JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints cons = new GridBagConstraints(); cons.gridx = 0;/*from ww w .ja va 2 s.c om*/ cons.gridy = 0; cons.weightx = 0.0f; cons.anchor = GridBagConstraints.WEST; List<JCheckBox> ruleCheckboxes = new ArrayList<JCheckBox>(); List<JLabel> ruleLabels = new ArrayList<JLabel>(); List<JTextField> ruleValueFields = new ArrayList<JTextField>(); for (int i = 0; i < configurableRules.size(); i++) { Rule rule = configurableRules.get(i); JCheckBox ruleCheckbox = new JCheckBox(rule.getDescription()); ruleCheckboxes.add(ruleCheckbox); ruleCheckbox.setSelected(getEnabledState(rule)); cons.insets = new Insets(3, 0, 0, 0); panel.add(ruleCheckbox, cons); cons.insets = new Insets(0, 24, 0, 0); cons.gridy++; JLabel ruleLabel = new JLabel(rule.getConfigureText()); ruleLabels.add(ruleLabel); ruleLabel.setEnabled(ruleCheckbox.isSelected()); panel.add(ruleLabel, cons); cons.gridx++; int value = config.getConfigurableValue(rule.getId()); if (config.getConfigurableValue(rule.getId()) < 0) { value = rule.getDefaultValue(); } JTextField ruleValueField = new JTextField(Integer.toString(value), 2); ruleValueFields.add(ruleValueField); ruleValueField.setEnabled(ruleCheckbox.isSelected()); ruleValueField.setMinimumSize(new Dimension(35, 25)); // without this the box is just a few pixels small, but why? panel.add(ruleValueField, cons); ruleCheckbox.addActionListener(new ActionListener() { @Override public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) { ruleValueField.setEnabled(ruleCheckbox.isSelected()); ruleLabel.setEnabled(ruleCheckbox.isSelected()); if (ruleCheckbox.isSelected()) { config.getEnabledRuleIds().add(rule.getId()); config.getDisabledRuleIds().remove(rule.getId()); } else { config.getEnabledRuleIds().remove(rule.getId()); config.getDisabledRuleIds().add(rule.getId()); } } }); ruleValueField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { changedUpdate(e); } @Override public void removeUpdate(DocumentEvent e) { changedUpdate(e); } @Override public void changedUpdate(DocumentEvent e) { try { int num = Integer.parseInt(ruleValueField.getText()); if (num < rule.getMinConfigurableValue()) { num = rule.getMinConfigurableValue(); ruleValueField.setForeground(Color.RED); } else if (num > rule.getMaxConfigurableValue()) { num = rule.getMaxConfigurableValue(); ruleValueField.setForeground(Color.RED); } else { ruleValueField.setForeground(null); } config.setConfigurableValue(rule.getId(), num); } catch (Exception ex) { ruleValueField.setForeground(Color.RED); } } }); cons.gridx = 0; cons.gridy++; } return panel; }
From source file:org.languagetool.gui.Main.java
private void createGUI() { loadRecentFiles();/*from ww w .j ava 2 s . com*/ frame = new JFrame("LanguageTool " + JLanguageTool.VERSION); setLookAndFeel(); openAction = new OpenAction(); saveAction = new SaveAction(); saveAsAction = new SaveAsAction(); checkAction = new CheckAction(); autoCheckAction = new AutoCheckAction(true); showResultAction = new ShowResultAction(true); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new CloseListener()); URL iconUrl = JLanguageTool.getDataBroker().getFromResourceDirAsUrl(TRAY_ICON); frame.setIconImage(new ImageIcon(iconUrl).getImage()); textArea = new JTextArea(); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.addKeyListener(new ControlReturnTextCheckingListener()); textLineNumber = new TextLineNumber(textArea, 2); numberedTextAreaPane = new JScrollPane(textArea); numberedTextAreaPane.setRowHeaderView(textLineNumber); resultArea = new JTextPane(); undoRedo = new UndoRedoSupport(this.textArea, messages); frame.setJMenuBar(createMenuBar()); GridBagConstraints buttonCons = new GridBagConstraints(); JPanel insidePanel = new JPanel(); insidePanel.setOpaque(false); insidePanel.setLayout(new GridBagLayout()); buttonCons.gridx = 0; buttonCons.gridy = 0; buttonCons.anchor = GridBagConstraints.LINE_START; insidePanel.add(new JLabel(messages.getString("textLanguage") + " "), buttonCons); //create a ComboBox with flags, do not include hidden languages languageBox = LanguageComboBox.create(messages, EXTERNAL_LANGUAGE_SUFFIX, true, false); buttonCons.gridx = 1; buttonCons.gridy = 0; buttonCons.anchor = GridBagConstraints.LINE_START; insidePanel.add(languageBox, buttonCons); JCheckBox autoDetectBox = new JCheckBox(messages.getString("atd")); buttonCons.gridx = 2; buttonCons.gridy = 0; buttonCons.gridwidth = GridBagConstraints.REMAINDER; buttonCons.anchor = GridBagConstraints.LINE_START; insidePanel.add(autoDetectBox, buttonCons); buttonCons.gridx = 0; buttonCons.gridy = 1; buttonCons.gridwidth = GridBagConstraints.REMAINDER; buttonCons.fill = GridBagConstraints.HORIZONTAL; buttonCons.anchor = GridBagConstraints.LINE_END; buttonCons.weightx = 1.0; insidePanel.add(statusLabel, buttonCons); Container contentPane = frame.getContentPane(); GridBagLayout gridLayout = new GridBagLayout(); contentPane.setLayout(gridLayout); GridBagConstraints cons = new GridBagConstraints(); cons.gridx = 0; cons.gridy = 1; cons.fill = GridBagConstraints.HORIZONTAL; cons.anchor = GridBagConstraints.FIRST_LINE_START; JToolBar toolbar = new JToolBar("Toolbar", JToolBar.HORIZONTAL); toolbar.setFloatable(false); contentPane.add(toolbar, cons); JButton openButton = new JButton(openAction); openButton.setHideActionText(true); openButton.setFocusable(false); toolbar.add(openButton); JButton saveButton = new JButton(saveAction); saveButton.setHideActionText(true); saveButton.setFocusable(false); toolbar.add(saveButton); JButton saveAsButton = new JButton(saveAsAction); saveAsButton.setHideActionText(true); saveAsButton.setFocusable(false); toolbar.add(saveAsButton); JButton spellButton = new JButton(this.checkAction); spellButton.setHideActionText(true); spellButton.setFocusable(false); toolbar.add(spellButton); JToggleButton autoSpellButton = new JToggleButton(autoCheckAction); autoSpellButton.setHideActionText(true); autoSpellButton.setFocusable(false); toolbar.add(autoSpellButton); JButton clearTextButton = new JButton(new ClearTextAction()); clearTextButton.setHideActionText(true); clearTextButton.setFocusable(false); toolbar.add(clearTextButton); cons.insets = new Insets(5, 5, 5, 5); cons.fill = GridBagConstraints.BOTH; cons.weightx = 10.0f; cons.weighty = 10.0f; cons.gridx = 0; cons.gridy = 2; cons.weighty = 5.0f; splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, numberedTextAreaPane, new JScrollPane(resultArea)); mainPanel.setLayout(new GridLayout(0, 1)); contentPane.add(mainPanel, cons); mainPanel.add(splitPane); cons.fill = GridBagConstraints.HORIZONTAL; cons.gridx = 0; cons.gridy = 3; cons.weightx = 1.0f; cons.weighty = 0.0f; cons.insets = new Insets(4, 12, 4, 12); contentPane.add(insidePanel, cons); ltSupport = new LanguageToolSupport(this.frame, this.textArea, this.undoRedo); ResultAreaHelper.install(messages, ltSupport, resultArea); languageBox.selectLanguage(ltSupport.getLanguage()); languageBox.setEnabled(!ltSupport.getConfig().getAutoDetect()); autoDetectBox.setSelected(ltSupport.getConfig().getAutoDetect()); taggerShowsDisambigLog = ltSupport.getConfig().getTaggerShowsDisambigLog(); languageBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { // we cannot re-use the existing LT object anymore frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault())); Language lang = languageBox.getSelectedLanguage(); ComponentOrientation componentOrientation = ComponentOrientation .getOrientation(lang.getLocale()); textArea.applyComponentOrientation(componentOrientation); resultArea.applyComponentOrientation(componentOrientation); ltSupport.setLanguage(lang); } } }); autoDetectBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { boolean selected = e.getStateChange() == ItemEvent.SELECTED; languageBox.setEnabled(!selected); ltSupport.getConfig().setAutoDetect(selected); if (selected) { Language detected = ltSupport.autoDetectLanguage(textArea.getText()); languageBox.selectLanguage(detected); } } }); ltSupport.addLanguageToolListener(new LanguageToolListener() { @Override public void languageToolEventOccurred(LanguageToolEvent event) { if (event.getType() == LanguageToolEvent.Type.CHECKING_STARTED) { String msg = org.languagetool.tools.Tools.i18n(messages, "checkStart"); statusLabel.setText(msg); if (event.getCaller() == getFrame()) { setWaitCursor(); checkAction.setEnabled(false); } } else if (event.getType() == LanguageToolEvent.Type.CHECKING_FINISHED) { if (event.getCaller() == getFrame()) { checkAction.setEnabled(true); unsetWaitCursor(); } String msg = org.languagetool.tools.Tools.i18n(messages, "checkDone", event.getSource().getMatches().size(), event.getElapsedTime()); statusLabel.setText(msg); } else if (event.getType() == LanguageToolEvent.Type.LANGUAGE_CHANGED) { languageBox.selectLanguage(ltSupport.getLanguage()); } else if (event.getType() == LanguageToolEvent.Type.RULE_ENABLED) { //this will trigger a check and the result will be updated by //the CHECKING_FINISHED event } else if (event.getType() == LanguageToolEvent.Type.RULE_DISABLED) { String msg = org.languagetool.tools.Tools.i18n(messages, "checkDoneNoTime", event.getSource().getMatches().size()); statusLabel.setText(msg); } } }); frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault())); Language lang = ltSupport.getLanguage(); ComponentOrientation componentOrientation = ComponentOrientation.getOrientation(lang.getLocale()); textArea.applyComponentOrientation(componentOrientation); resultArea.applyComponentOrientation(componentOrientation); ResourceBundle textLanguageMessageBundle = JLanguageTool.getMessageBundle(ltSupport.getLanguage()); textArea.setText(textLanguageMessageBundle.getString("guiDemoText")); Configuration config = ltSupport.getConfig(); if (config.getFontName() != null || config.getFontStyle() != Configuration.FONT_STYLE_INVALID || config.getFontSize() != Configuration.FONT_SIZE_INVALID) { String fontName = config.getFontName(); if (fontName == null) { fontName = textArea.getFont().getFamily(); } int fontSize = config.getFontSize(); if (fontSize == Configuration.FONT_SIZE_INVALID) { fontSize = textArea.getFont().getSize(); } Font font = new Font(fontName, config.getFontStyle(), fontSize); textArea.setFont(font); } frame.pack(); frame.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); frame.setLocationByPlatform(true); splitPane.setDividerLocation(200); MainWindowStateBean state = localStorage.loadProperty("gui.state", MainWindowStateBean.class); if (state != null) { if (state.getBounds() != null) { frame.setBounds(state.getBounds()); ResizeComponentListener.setBoundsProperty(frame, state.getBounds()); } if (state.getDividerLocation() != null) { splitPane.setDividerLocation(state.getDividerLocation()); } if (state.getState() != null) { frame.setExtendedState(state.getState()); } } ResizeComponentListener.attachToWindow(frame); maybeStartServer(); }
From source file:org.languagetool.gui.Main.java
private void tagTextAndDisplayResults() { JLanguageTool langTool = ltSupport.getLanguageTool(); // tag text/*www . ja v a 2s.co m*/ List<String> sentences = langTool.sentenceTokenize(textArea.getText()); StringBuilder sb = new StringBuilder(); if (taggerShowsDisambigLog) { sb.append("<table>"); sb.append("<tr>"); sb.append("<td><b>"); sb.append(messages.getString("token")); sb.append("</b></td>"); sb.append("<td><b>"); sb.append(messages.getString("disambiguatorLog")); sb.append("</b></td>"); sb.append("</tr>"); boolean odd = true; try { for (String sent : sentences) { AnalyzedSentence analyzed = langTool.getAnalyzedSentence(sent); odd = appendTagsWithDisambigLog(sb, analyzed, odd); } } catch (Exception e) { sb.append(getStackTraceAsHtml(e)); } sb.append("</table>"); } else { try { for (String sent : sentences) { AnalyzedSentence analyzed = langTool.getAnalyzedSentence(sent); String analyzedString = StringTools.escapeHTML(analyzed.toString(",")) .replace("<S>", "<S><br>").replace("[", "<font color='" + TAG_COLOR + "'>[") .replace("]", "]</font><br>"); sb.append(analyzedString).append('\n'); } } catch (Exception e) { sb.append(getStackTraceAsHtml(e)); } } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (taggerDialog == null) { taggerDialog = new JDialog(frame); taggerDialog.setTitle(messages.getString("taggerWindowTitle")); taggerDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); taggerDialog.setResizable(true); taggerDialog.setSize(640, 480); taggerDialog.setLocationRelativeTo(frame); KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); ActionListener actionListener = actionEvent -> taggerDialog.setVisible(false); taggerDialog.getRootPane().registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); JPanel panel = new JPanel(new GridBagLayout()); taggerDialog.add(panel); taggerArea = new JTextPane(); taggerArea.setContentType("text/html"); taggerArea.setEditable(false); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridwidth = 2; c.gridy = 0; c.weightx = 1.0; c.weighty = 1.0; c.insets = new Insets(8, 8, 4, 8); c.fill = GridBagConstraints.BOTH; panel.add(new JScrollPane(taggerArea), c); c.gridwidth = 1; c.gridx = 0; c.gridy = 1; c.weightx = 0.0; c.weighty = 0.0; c.insets = new Insets(4, 8, 8, 8); c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.EAST; JCheckBox showDisAmbig = new JCheckBox(messages.getString("ShowDisambiguatorLog")); showDisAmbig.setSelected(taggerShowsDisambigLog); showDisAmbig.addItemListener((ItemEvent e) -> { taggerShowsDisambigLog = e.getStateChange() == ItemEvent.SELECTED; ltSupport.getConfig().setTaggerShowsDisambigLog(taggerShowsDisambigLog); }); panel.add(showDisAmbig, c); c.gridx = 1; JButton closeButton = new JButton(messages.getString("guiCloseButton")); closeButton.addActionListener(actionListener); panel.add(closeButton, c); } // orientation each time should be set as language may is changed taggerDialog.applyComponentOrientation( ComponentOrientation.getOrientation(languageBox.getSelectedLanguage().getLocale())); taggerDialog.setVisible(true); taggerArea.setText(HTML_FONT_START + sb + HTML_FONT_END); } }); }
From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java
/** * Setup General (Control Center) Tab//from w ww .java2s . c o m * * @return JPanel for Control Center */ private JPanel setupGeneral() { JPanel generalPanel = new JPanel(); generalPanel.setLayout(new BorderLayout()); /* -- Stats Panel -- */ JPanel statsPanel = new JPanel(); generalPanel.add(statsPanel, BorderLayout.NORTH); statsPanel.setLayout(new GridLayout(0, 2, 10, 10)); JPanel eastPanel = new JPanel(); statsPanel.add(eastPanel, BorderLayout.EAST); eastPanel.setLayout(new BorderLayout()); JPanel westPanel = new JPanel(); statsPanel.add(westPanel, BorderLayout.WEST); westPanel.setLayout(new BorderLayout()); // Grid Information Panel JPanel gridInfoPanel = new JPanel(); eastPanel.add(gridInfoPanel, BorderLayout.NORTH); gridInfoPanel.setBorder(BorderFactory.createTitledBorder("Grid Information")); gridInfoPanel.setLayout(new GridLayout(0, 2, 10, 10)); JLabel nodeIdLabel = new JLabel("Node ID :"); gridInfoPanel.add(nodeIdLabel); JLabel nodeId = new JLabel("#nodeid#"); gridInfoPanel.add(nodeId); addUIElement("general.stats.nodeid", nodeId); // Add to components map JLabel nodeIpLabel = new JLabel("Node IP :"); gridInfoPanel.add(nodeIpLabel); JLabel nodeIp = new JLabel("#nodeip#"); gridInfoPanel.add(nodeIp); addUIElement("general.stats.nodeip", nodeIp); // Add to components map JLabel clusterIdLabel = new JLabel("Cluster ID :"); gridInfoPanel.add(clusterIdLabel); JLabel clusterId = new JLabel("#clusterid#"); gridInfoPanel.add(clusterId); addUIElement("general.stats.clusterid", clusterId); // Add to components map JLabel clusterServiceLabel = new JLabel("Cluster Service :"); gridInfoPanel.add(clusterServiceLabel); JLabel clusterService = new JLabel("#clusterservice#"); gridInfoPanel.add(clusterService); addUIElement("general.stats.clusterservice", clusterService); // Add to components map // Node Status Panel JPanel nodeStatusPanel = new JPanel(); eastPanel.add(nodeStatusPanel, BorderLayout.SOUTH); nodeStatusPanel.setBorder(BorderFactory.createTitledBorder("GridNode Status")); nodeStatusPanel.setLayout(new GridLayout(0, 2, 10, 10)); JLabel statusLabel = new JLabel("Status :"); nodeStatusPanel.add(statusLabel); JLabel status = new JLabel("#status#"); nodeStatusPanel.add(status); addUIElement("general.stats.status", status); // Add to components map JLabel uptimeLabel = new JLabel("Node Up Time :"); nodeStatusPanel.add(uptimeLabel); JLabel uptime = new JLabel("#uptime#"); nodeStatusPanel.add(uptime); addUIElement("general.stats.uptime", uptime); // Add to components map JLabel execTimeLabel = new JLabel("Execution Time :"); nodeStatusPanel.add(execTimeLabel); JLabel execTime = new JLabel("#exectime#"); nodeStatusPanel.add(execTime); addUIElement("general.stats.exectime", execTime); // Add to components map // Execution Statistics Panel JPanel execStatsPanel = new JPanel(); westPanel.add(execStatsPanel, BorderLayout.NORTH); execStatsPanel.setLayout(new GridLayout(0, 2, 10, 10)); execStatsPanel.setBorder(BorderFactory.createTitledBorder("Execution Statistics")); JLabel totalJobsLabel = new JLabel("Total Jobs :"); execStatsPanel.add(totalJobsLabel); JLabel totalJobs = new JLabel("0"); execStatsPanel.add(totalJobs); addUIElement("general.stats.totaljobs", totalJobs); // Add to components map JLabel totalTasksLabel = new JLabel("Total Tasks :"); execStatsPanel.add(totalTasksLabel); JLabel totalTasks = new JLabel("0"); execStatsPanel.add(totalTasks); addUIElement("general.stats.totaltasks", totalTasks); // Add to components map JLabel totalBansLabel = new JLabel("Banments :"); execStatsPanel.add(totalBansLabel); JLabel totalBans = new JLabel("0"); execStatsPanel.add(totalBans); addUIElement("general.stats.totalbans", totalBans); // Add to components map // Execution Active Job Panel JPanel activeJobPanel = new JPanel(); westPanel.add(activeJobPanel, BorderLayout.SOUTH); activeJobPanel.setLayout(new GridLayout(0, 2, 10, 10)); activeJobPanel.setBorder(BorderFactory.createTitledBorder("Active Job")); JLabel jobNameLabel = new JLabel("GridJob Name :"); activeJobPanel.add(jobNameLabel); JLabel jobName = new JLabel("#jobname#"); activeJobPanel.add(jobName); addUIElement("general.stats.jobname", jobName); // Add to components map JLabel durationLabel = new JLabel("Duration :"); activeJobPanel.add(durationLabel); JLabel duration = new JLabel("#duration#"); activeJobPanel.add(duration); addUIElement("general.stats.duration", duration); // Add to components map JLabel tasksLabel = new JLabel("Tasks Executed :"); activeJobPanel.add(tasksLabel); JLabel tasks = new JLabel("#xyz#"); activeJobPanel.add(tasks); addUIElement("general.stats.tasks", tasks); // Add to components map JLabel failuresLabel = new JLabel("Failures :"); activeJobPanel.add(failuresLabel); JLabel failures = new JLabel("#failures#"); activeJobPanel.add(failures); addUIElement("general.stats.failures", failures); // Add to components map /* -- Log Panel -- */ JPanel logPanel = new JPanel(); generalPanel.add(logPanel, BorderLayout.CENTER); logPanel.setLayout(new BorderLayout()); logPanel.setBorder(BorderFactory.createTitledBorder("Log Output")); JTextPane logTextPane = new JTextPane(); logTextPane.setEditable(false); logTextPane.setBackground(Color.BLACK); logTextPane.setForeground(Color.WHITE); logPanel.add(new JScrollPane(logTextPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER); addUIElement("general.log", logTextPane); // Add to component map JPanel logOptionsPanel = new JPanel(); logPanel.add(logOptionsPanel, BorderLayout.SOUTH); logOptionsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); final JCheckBox logScrollCheckbox = new JCheckBox("Auto-Scroll Log"); logScrollCheckbox.setSelected(true); logScrollCheckbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JTextPaneAppender.setAutoScroll(logScrollCheckbox.isSelected()); } }); logOptionsPanel.add(logScrollCheckbox); // Enable Logging JTextPaneAppender.setTextPane(logTextPane); /* -- Buttons Panel -- */ JPanel buttonsPanel = new JPanel(); generalPanel.add(buttonsPanel, BorderLayout.SOUTH); buttonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); // Shutdown Button JButton shutdownButton = new JButton("Shutdown"); buttonsPanel.add(shutdownButton); shutdownButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doShutdownNode(); } }); // Start Up time Thread Thread t = new Thread(new Runnable() { public void run() { long start = System.currentTimeMillis(); while (true) { try { Thread.sleep(1000); } catch (InterruptedException e) { log.warn("Interrupted Exception in Up Time Thread", e); } final String uptime = TimeUtils.timeDifference(start); SwingUtilities.invokeLater(new Runnable() { public void run() { JLabel upTime = getUIElement("general.stats.uptime"); upTime.setText(uptime); } }); } } }); t.setDaemon(true); t.start(); // Auto-Discovery Thread Thread autoDiscovery = new Thread(new Runnable() { public void run() { while (true) { try { // Attempt every 30 seconds Thread.sleep(30000); } catch (InterruptedException e) { log.warn("Interrupted Exception in Up Time Thread", e); } if (autodiscover && (!Grid.isNode())) { // 30 Second Intervals doDiscover(true); } } } }); autoDiscovery.setDaemon(true); autoDiscovery.start(); return generalPanel; }
From source file:org.openconcerto.erp.core.finance.accounting.ui.ClotureMensuellePayePanel.java
public ClotureMensuellePayePanel() { super();/*from w ww.ja va 2 s. c o m*/ this.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.HORIZONTAL; c.insets = new Insets(2, 2, 1, 2); c.weightx = 0; c.weighty = 0; c.gridheight = 1; c.gridwidth = 1; c.gridx = 0; c.gridy = 0; JLabel labelMois = new JLabel("Cloture du mois de "); this.add(labelMois, c); final ElementComboBox selMois = new ElementComboBox(true, 25); selMois.init(((ComptaPropsConfiguration) Configuration.getInstance()).getDirectory() .getElement(MoisSQLElement.class)); selMois.setButtonsVisible(false); c.gridx++; this.add(selMois, c); JLabel labelAnnee = new JLabel("Anne"); c.gridx++; this.add(labelAnnee, c); final JTextField textAnnee = new JTextField(5); c.gridx++; this.add(textAnnee, c); DateFormat format = new SimpleDateFormat("yyyy"); textAnnee.setText(format.format(new Date())); c.gridy++; c.gridx = 0; final JCheckBox boxValid = new JCheckBox("Valider toutes les payes du mois"); final JCheckBox boxCompta = new JCheckBox("Gnrer les critures comptables associes"); c.gridwidth = GridBagConstraints.REMAINDER; this.add(boxValid, c); boxValid.setSelected(true); c.gridy++; this.add(boxCompta, c); JButton buttonClot = new JButton("Clturer"); JButton buttonFermer = new JButton("Fermer"); JPanel panelButton = new JPanel(); panelButton.add(buttonClot); panelButton.add(buttonFermer); c.anchor = GridBagConstraints.SOUTHEAST; c.fill = GridBagConstraints.NONE; c.weighty = 1; c.gridy++; this.add(panelButton, c); buttonFermer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ((JFrame) SwingUtilities.getRoot(ClotureMensuellePayePanel.this)).dispose(); } }); buttonClot.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { // Valider les fiches non valids des salaris actifs if (boxValid.isSelected()) { SQLSelect selFiche = new SQLSelect(); SQLTable tableFiche = ClotureMensuellePayePanel.this.base.getTable("FICHE_PAYE"); SQLTable tableSalarie = ClotureMensuellePayePanel.this.base.getTable("SALARIE"); SQLTable tableInfosSal = ClotureMensuellePayePanel.this.base.getTable("INFOS_SALARIE_PAYE"); selFiche.addSelect(tableFiche.getField("ID")); selFiche.setWhere(new Where(tableFiche.getField("VALIDE"), "=", Boolean.FALSE)); selFiche.andWhere(new Where(tableFiche.getField("ID_MOIS"), "=", selMois.getSelectedId())); selFiche.andWhere( new Where(tableFiche.getField("ANNEE"), "=", new Integer(textAnnee.getText()))); selFiche.andWhere( new Where(tableSalarie.getField("ID"), "=", tableFiche.getField("ID_SALARIE"))); selFiche.andWhere(new Where(tableInfosSal.getField("ID"), "=", tableSalarie.getField("ID_INFOS_SALARIE_PAYE"))); // FIXME ne pas valider les fiches d'un employ renvoy // Where w2 = new Where(tableInfosSal.getField("DATE_SORTIE"), "IS", // "NULL"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, selMois.getSelectedId() - 2); cal.set(Calendar.YEAR, Integer.parseInt(textAnnee.getText())); cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE)); Where w = new Where(tableInfosSal.getField("DATE_SORTIE"), "<=", cal.getTime()); w = w.or(new Where(tableInfosSal.getField("DATE_SORTIE"), "=", (Object) null)); selFiche.andWhere(w); String req = selFiche.asString(); System.err.println(req); List l = (List) ClotureMensuellePayePanel.this.base.getDataSource().execute(req, new ArrayListHandler()); for (int i = 0; i < l.size(); i++) { Object[] tmp = (Object[]) l.get(i); SQLRow rowFicheTmp = tableFiche.getRow(Integer.parseInt(tmp[0].toString())); System.err.println(rowFicheTmp); FichePayeSQLElement.validationFiche(rowFicheTmp.getID()); } } // cloture du mois et generation compta SQLSelect selFiche = new SQLSelect(ClotureMensuellePayePanel.this.base); SQLTable tableFiche = ClotureMensuellePayePanel.this.base.getTable("FICHE_PAYE"); SQLTable tableMois = ClotureMensuellePayePanel.this.base.getTable("MOIS"); selFiche.addSelect(tableFiche.getField("ID")); selFiche.setWhere(new Where(tableFiche.getField("VALIDE"), "=", Boolean.TRUE)); selFiche.andWhere(new Where(tableFiche.getField("ID_MOIS"), "=", selMois.getSelectedId())); selFiche.andWhere( new Where(tableFiche.getField("ANNEE"), "=", new Integer(textAnnee.getText()))); String req = selFiche.asString(); List l = (List) ClotureMensuellePayePanel.this.base.getDataSource().execute(req, new ArrayListHandler()); if (l != null && l.size() > 0) { int[] idS = new int[l.size()]; SQLRow rowMois = tableMois.getRow(selMois.getSelectedId()); for (int i = 0; i < l.size(); i++) { Object[] tmp = (Object[]) l.get(i); idS[i] = Integer.parseInt(tmp[0].toString()); SQLRow rowFiche = tableFiche.getRow(idS[i]); FichePayeSQLElement.clotureMensuelle(selMois.getSelectedId(), Integer.parseInt(textAnnee.getText()), rowFiche.getInt("ID_SALARIE")); } if (boxCompta.isSelected()) { new GenerationMvtFichePaye(idS, rowMois.getString("NOM"), textAnnee.getText()); } } System.err.println( "ClotureMensuellePayePanel.ClotureMensuellePayePanel().new ActionListener() {...}.actionPerformed()"); JOptionPane.showMessageDialog(null, "Clture termine"); } catch (Exception ex) { ExceptionHandler.handle("Unable to complete operation", ex); } } }); }
From source file:org.openmicroscopy.shoola.agents.dataBrowser.view.SearchPanel.java
/** * Builds and lays out the component displaying the various options. * /* w w w . j av a 2 s . c om*/ * @return See above. */ private JPanel buildFields() { List<SearchObject> nodes = model.getNodes(); SearchObject n; int m = nodes.size(); JCheckBox box; JPanel p = new JPanel(); p.setBackground(UIUtilities.BACKGROUND_COLOR); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1.0; c.gridy = 1; List<Integer> ctxNodes = null; SearchContext ctx = model.getSearchContext(); if (ctx != null) ctxNodes = ctx.getContext(); if (ctxNodes == null) { for (int i = 0; i < m; i++) { n = nodes.get(i); box = new JCheckBox(n.getDescription()); box.setBackground(UIUtilities.BACKGROUND_COLOR); if (i % 2 == 0) { c.gridy++; } p.add(box, c); scopes.put(n.getIndex(), box); } } else { for (int i = 0; i < m; i++) { n = nodes.get(i); box = new JCheckBox(n.getDescription()); box.setBackground(UIUtilities.BACKGROUND_COLOR); box.setSelected(ctxNodes.contains(n.getIndex())); if (i % 2 == 0) c.gridy++; p.add(box, c); scopes.put(n.getIndex(), box); } } c.gridy++; UIUtilities.setBoldTitledBorder("Restrict by Field", p); return p; }
From source file:org.openmicroscopy.shoola.agents.dataBrowser.view.SearchPanel.java
/** * Builds and lays out the component displaying the various types. * //from www .j a va 2 s .c o m * @return See above. */ private JPanel buildType() { JPanel p = new JPanel(); p.setBackground(UIUtilities.BACKGROUND_COLOR); p.setLayout(new GridBagLayout()); // p.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.HORIZONTAL; c.insets = new Insets(3, 3, 3, 3); List<SearchObject> nodes = model.getTypes(); List<Integer> ctxNodes = null; SearchContext ctx = model.getSearchContext(); if (ctx != null) ctxNodes = ctx.getType(); SearchObject n; int m = nodes.size(); JCheckBox box; c.weightx = 1.0; if (ctxNodes == null) { for (int i = 0; i < m; i++) { n = nodes.get(i); box = new JCheckBox(n.getDescription()); box.setBackground(UIUtilities.BACKGROUND_COLOR); box.setSelected(true); p.add(box, c); if (i % 2 == 0) c.gridy++; types.put(n.getIndex(), box); } } else { for (int i = 0; i < m; i++) { n = nodes.get(i); box = new JCheckBox(n.getDescription()); box.setBackground(UIUtilities.BACKGROUND_COLOR); box.setSelected(ctxNodes.contains(n.getIndex())); p.add(box, c); if (i % 2 == 0) c.gridy++; types.put(n.getIndex(), box); } } UIUtilities.setBoldTitledBorder(TYPE_TITLE, p); return p; }
From source file:org.openmicroscopy.shoola.agents.measurement.util.ui.ResultsCellRenderer.java
/** * @see TableCellRenderer#getTableCellRendererComponent(JTable, Object, * boolean, boolean, int, int) *//*from w w w. j a va2s . c om*/ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component thisComponent = new JLabel(); JLabel label = new JLabel(); label.setOpaque(true); if (value instanceof Number) { MeasurementTableModel tm = (MeasurementTableModel) table.getModel(); KeyDescription key = tm.getColumnNames().get(column); String k = key.getKey(); MeasurementUnits units = tm.getUnitsType(); Number n = (Number) value; String s; if (units.isInMicrons()) { UnitsObject object; StringBuffer buffer = new StringBuffer(); object = UIUtilities.transformSize(n.doubleValue()); s = twoDecimalPlaces(object.getValue()); if (StringUtils.isNotBlank(s)) { buffer.append(s); if (!(AnnotationKeys.ANGLE.getKey().equals(k) || AnnotationDescription.ZSECTION_STRING.equals(k) || AnnotationDescription.ROIID_STRING.equals(k) || AnnotationDescription.TIME_STRING.equals(k))) { buffer.append(object.getUnits()); } if (AnnotationKeys.AREA.getKey().equals(k)) { buffer = new StringBuffer(); object = UIUtilities.transformSquareSize(n.doubleValue()); s = twoDecimalPlaces(object.getValue()); buffer.append(s); buffer.append(object.getUnits()); } label.setText(buffer.toString()); } } else { s = UIUtilities.twoDecimalPlaces(n.doubleValue()); if (StringUtils.isNotBlank(s)) { label.setText(s); } } thisComponent = label; } else if (value instanceof FigureType || value instanceof String) { thisComponent = makeShapeIcon(label, "" + value); } else if (value instanceof Color) { label.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); label.setBackground((Color) value); thisComponent = label; } else if (value instanceof Boolean) { JCheckBox checkBox = new JCheckBox(); checkBox.setSelected((Boolean) value); thisComponent = checkBox; } else if (value instanceof ArrayList) { thisComponent = createList(value); //return list; } if (!(value instanceof Color)) { RendererUtils.setRowColor(thisComponent, table.getSelectedRow(), row); if (label != null) label.setBackground(thisComponent.getBackground()); } return thisComponent; }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java
/** * Builds the panel hosting the information * // ww w .j a v a 2s . c o m * @param details The information to display. * @param image The image of reference. * @return See above. */ private JPanel buildContentPanel(Map details, ImageData image) { JPanel content = new JPanel(); content.setBackground(UIUtilities.BACKGROUND_COLOR); content.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); content.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(0, 2, 2, 0); c.gridy = 0; c.gridx = 0; JLabel l = new JLabel(); Font font = l.getFont(); int size = font.getSize() - 2; JLabel label = UIUtilities.setTextFont(EditorUtil.ARCHIVED, Font.BOLD, size); JCheckBox box = new JCheckBox(); box.setEnabled(false); box.setBackground(UIUtilities.BACKGROUND); box.setSelected(model.isArchived()); content.add(label, c); c.gridx = c.gridx + 2; content.add(box, c); c.gridy++; c.gridx = 0; label = UIUtilities.setTextFont(EditorUtil.ACQUISITION_DATE, Font.BOLD, size); JLabel value = UIUtilities.createComponent(null); String v = model.formatDate(image); value.setText(v); content.add(label, c); c.gridx = c.gridx + 2; content.add(value, c); c.gridy++; c.gridx = 0; try { //just to be on the save side label = UIUtilities.setTextFont(EditorUtil.IMPORTED_DATE, Font.BOLD, size); value = UIUtilities.createComponent(null); v = UIUtilities.formatShortDateTime(image.getInserted()); value.setText(v); content.add(label, c); c.gridx = c.gridx + 2; content.add(value, c); c.gridy++; } catch (Exception e) { } label = UIUtilities.setTextFont(EditorUtil.XY_DIMENSION, Font.BOLD, size); value = UIUtilities.createComponent(null); v = (String) details.get(EditorUtil.SIZE_X); v += " x "; v += (String) details.get(EditorUtil.SIZE_Y); value.setText(v); c.gridx = 0; content.add(label, c); c.gridx = c.gridx + 2; content.add(value, c); c.gridy++; label = UIUtilities.setTextFont(EditorUtil.PIXEL_TYPE, Font.BOLD, size); value = UIUtilities.createComponent(null); value.setText((String) details.get(EditorUtil.PIXEL_TYPE)); c.gridx = 0; content.add(label, c); c.gridx = c.gridx + 2; content.add(value, c); value = UIUtilities.createComponent(null); String s = formatPixelsSize(details, value); if (s != null) { c.gridy++; label = UIUtilities.setTextFont(s, Font.BOLD, size); c.gridx = 0; content.add(label, c); c.gridx = c.gridx + 2; content.add(value, c); } //parse modulo T. Map<Integer, ModuloInfo> modulo = model.getModulo(); ModuloInfo moduloT = modulo.get(ModuloInfo.T); c.gridy++; label = UIUtilities.setTextFont(EditorUtil.Z_T_FIELDS, Font.BOLD, size); value = UIUtilities.createComponent(null); v = (String) details.get(EditorUtil.SECTIONS); v += " x "; if (moduloT != null) { String time = (String) details.get(EditorUtil.TIMEPOINTS); int t = Integer.parseInt(time); v += "" + (t / moduloT.getSize()); } else { v += (String) details.get(EditorUtil.TIMEPOINTS); } value.setText(v); c.gridx = 0; content.add(label, c); c.gridx = c.gridx + 2; content.add(value, c); c.gridy++; if (moduloT != null) { label = UIUtilities.setTextFont(EditorUtil.SMALL_T_VARIABLE, Font.BOLD, size); value = UIUtilities.createComponent(null); value.setText("" + moduloT.getSize()); c.gridx = 0; content.add(label, c); c.gridx = c.gridx + 2; content.add(value, c); c.gridy++; } if (!model.isNumerousChannel() && model.getRefObjectID() > 0) { label = UIUtilities.setTextFont(EditorUtil.CHANNELS, Font.BOLD, size); c.gridx = 0; c.anchor = GridBagConstraints.NORTHEAST; content.add(label, c); c.anchor = GridBagConstraints.CENTER; c.gridx++; content.add(editChannel, c); c.gridx++; content.add(channelsPane, c); } JPanel p = UIUtilities.buildComponentPanel(content); p.setBackground(UIUtilities.BACKGROUND_COLOR); return p; }