public void showItem() { if (!this.editorPanel.getViewer().isLanguageFunctionAvailable()) { return; } this.highlight = this.editorPanel .getEditor() .addHighlight(this.position, this.position + this.word.length(), null, true); final FindSynonymsActionHandler _this = this; QTextEditor editor = this.editorPanel.getEditor(); Rectangle r = null; try { r = editor.modelToView(this.position); } catch (Exception e) { // BadLocationException! Environment.logError("Location: " + this.position + " is not valid", e); UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms."); return; } int y = r.y; // Show a panel of all the items. final QPopup p = this.popup; p.setOpaque(false); Synonyms syns = null; try { syns = this.projectViewer.getSynonymProvider().getSynonyms(this.word); } catch (Exception e) { UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms."); Environment.logError("Unable to lookup synonyms for: " + word, e); return; } if ((syns.words.size() == 0) && (this.word.toLowerCase().endsWith("ed"))) { // Trim off the ed and try again. try { syns = this.projectViewer.getSynonyms(this.word.substring(0, this.word.length() - 2)); } catch (Exception e) { UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms."); Environment.logError("Unable to lookup synonyms for: " + word, e); return; } } if ((syns.words.size() == 0) && (this.word.toLowerCase().endsWith("s"))) { // Trim off the ed and try again. try { syns = this.projectViewer.getSynonyms(this.word.substring(0, this.word.length() - 1)); } catch (Exception e) { UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms."); Environment.logError("Unable to lookup synonyms for: " + word, e); return; } } StringBuilder sb = new StringBuilder(); if (syns.words.size() > 0) { sb.append("6px"); for (int i = 0; i < syns.words.size(); i++) { if (sb.length() > 0) { sb.append(", "); } sb.append("p, 3px, [p,90px], 5px"); } /* if (syns.words.size () > 0) { sb.append (",5px"); } */ } else { sb.append("6px, p, 6px"); } FormLayout summOnly = new FormLayout("3px, fill:380px:grow, 3px", sb.toString()); PanelBuilder pb = new PanelBuilder(summOnly); CellConstraints cc = new CellConstraints(); int ind = 2; Map<String, String> names = new HashMap(); names.put(Synonyms.ADJECTIVE + "", "Adjectives"); names.put(Synonyms.NOUN + "", "Nouns"); names.put(Synonyms.VERB + "", "Verbs"); names.put(Synonyms.ADVERB + "", "Adverbs"); names.put(Synonyms.OTHER + "", "Other"); if (syns.words.size() == 0) { JLabel l = new JLabel("No synonyms found."); l.setFont(l.getFont().deriveFont(Font.ITALIC)); pb.add(l, cc.xy(2, 2)); } // Determine what type of word we are looking for. for (Synonyms.Part i : syns.words) { JLabel l = new JLabel(names.get(i.type + "")); l.setFont(l.getFont().deriveFont(Font.ITALIC)); l.setFont(l.getFont().deriveFont((float) UIUtils.getEditorFontSize(10))); l.setBorder( new CompoundBorder( new MatteBorder(0, 0, 1, 0, Environment.getBorderColor()), new EmptyBorder(0, 0, 3, 0))); pb.add(l, cc.xy(2, ind)); ind += 2; HTMLEditorKit kit = new HTMLEditorKit(); HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument(); JTextPane t = new JTextPane(doc); t.setEditorKit(kit); t.setEditable(false); t.setOpaque(false); StringBuilder buf = new StringBuilder( "<style>a { text-decoration: none; } a:hover { text-decoration: underline; }</style><span style='color: #000000; font-size: " + ((int) UIUtils.getEditorFontSize(10) /*t.getFont ().getSize () + 2*/) + "pt; font-family: " + t.getFont().getFontName() + ";'>"); for (int x = 0; x < i.words.size(); x++) { String w = (String) i.words.get(x); buf.append("<a class='x' href='http://" + w + "'>" + w + "</a>"); if (x < (i.words.size() - 1)) { buf.append(", "); } } buf.append("</span>"); t.setText(buf.toString()); t.addHyperlinkListener( new HyperlinkAdapter() { public void hyperlinkUpdate(HyperlinkEvent ev) { if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { QTextEditor ed = _this.editorPanel.getEditor(); ed.replaceText( _this.position, _this.position + _this.word.length(), ev.getURL().getHost()); ed.removeHighlight(_this.highlight); _this.popup.setVisible(false); _this.projectViewer.fireProjectEvent( ProjectEvent.SYNONYM, ProjectEvent.REPLACE, ev.getURL().getHost()); } } }); // Annoying that we have to do this but it prevents the text from being too small. t.setSize(new Dimension(380, Short.MAX_VALUE)); JScrollPane sp = new JScrollPane(t); t.setCaretPosition(0); sp.setOpaque(false); sp.getVerticalScrollBar().setValue(0); /* sp.setPreferredSize (t.getPreferredSize ()); sp.setMaximumSize (new Dimension (380, 75)); */ sp.getViewport().setOpaque(false); sp.setOpaque(false); sp.setBorder(null); sp.getViewport().setBackground(Color.WHITE); sp.setAlignmentX(Component.LEFT_ALIGNMENT); pb.add(sp, cc.xy(2, ind)); ind += 2; } JPanel pan = pb.getPanel(); pan.setOpaque(true); pan.setBackground(Color.WHITE); this.popup.setContent(pan); // r.y -= this.editorPanel.getScrollPane ().getVerticalScrollBar ().getValue (); Point po = SwingUtilities.convertPoint(editor, r.x, r.y, this.editorPanel); r.x = po.x; r.y = po.y; // Subtract the insets of the editorPanel. Insets ins = this.editorPanel.getInsets(); r.x -= ins.left; r.y -= ins.top; this.editorPanel.showPopupAt(this.popup, r, "above", true); }
void initComponents() { JPanel mainPanel = new JPanel(new BorderLayout()); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); Color bgColor = Color.getHSBColor(0.58f, 0.17f, 0.95f); buttonPanel.setBackground(bgColor); Border empty = BorderFactory.createEmptyBorder(5, 5, 5, 5); buttonPanel.setBorder(empty); textField = new JTextField(75); buttonPanel.add(textField); buttonPanel.add(Box.createHorizontalStrut(10)); searchPHI = new JButton("Search PHI"); searchPHI.addActionListener(this); buttonPanel.add(searchPHI); buttonPanel.add(Box.createHorizontalStrut(10)); searchTrial = new JButton("Search Trial IDs"); searchTrial.addActionListener(this); buttonPanel.add(searchTrial); buttonPanel.add(Box.createHorizontalStrut(20)); buttonPanel.add(Box.createHorizontalGlue()); saveAs = new JCheckBox("Save As..."); saveAs.setBackground(bgColor); buttonPanel.add(saveAs); mainPanel.add(buttonPanel, BorderLayout.NORTH); JScrollPane scrollPane = new JScrollPane(); textPane = new ColorPane(); // textPane.setEditable(false); scrollPane.setViewportView(textPane); mainPanel.add(scrollPane, BorderLayout.CENTER); JPanel footerPanel = new JPanel(); footerPanel.setLayout(new BoxLayout(footerPanel, BoxLayout.X_AXIS)); footerPanel.setBackground(bgColor); message = new JLabel("Ready..."); footerPanel.add(message); mainPanel.add(footerPanel, BorderLayout.SOUTH); setTitle(windowTitle); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); getContentPane().add(mainPanel, BorderLayout.CENTER); pack(); centerFrame(); }
/** * References checked: 8.10.2003 (2.0b2) * * @param editorType editor type, one of this constants * <UL> * <LI>EDITOR_TYPE_DEFAULT * <LI>EDITOR_TYPE_STYLED * <LI>EDITOR_TYPE_SINGLE_LINE * </UL> * * @param controler if not <code>null</code> for <code>EDITOR_TYPE_STYLED</code> editors a toolbar * is created * @see PresentationDetail#PresentationDetail */ TextEditorPanel( int editorType, GraphPanelControler controler, boolean showToolbar, PresentationDetail detail) { this.editorType = editorType; this.controler = controler; this.showToolbar = showToolbar; this.detail = detail; setLayout(new BorderLayout()); // --- build this text editor panel --- switch (editorType) { case EDITOR_TYPE_DEFAULT: textComponent = new JTextArea(); add(new JScrollPane(textComponent)); break; case EDITOR_TYPE_STYLED: textComponent = new JTextPane(); textComponent.setTransferHandler(new TextTransferHandler()); // ### requires Java 1.4 // --- add toolbar --- if (showToolbar) { JPanel bar = new JPanel(); Hashtable actions = DeepaMehtaClientUtils.createActionTable(textComponent); bar.setBackground(COLOR_PROPERTY_PANEL); toolbarButtons = new JButton[3]; addButton(bar, new StyledEditorKit.BoldAction(), actions, controler.boldIcon()); addButton(bar, new StyledEditorKit.ItalicAction(), actions, controler.italicIcon()); addButton(bar, new StyledEditorKit.UnderlineAction(), actions, controler.underlineIcon()); // ### addButton(bar, "H1", CMD_SET_HEADLINE1); // ### addButton(bar, "H2", CMD_SET_HEADLINE2); add(bar, BorderLayout.SOUTH); } add(new JScrollPane(textComponent)); break; case EDITOR_TYPE_SINGLE_LINE: textComponent = new JTextField(); ((JTextField) textComponent).addActionListener(this); add(textComponent); break; default: throw new DeepaMehtaException("unexpected text editor type: " + editorType); } // --- enable automatic drag and drop support --- try { textComponent.setDragEnabled(true); } catch (NoSuchMethodError e) { // requires JDK 1.4 ### } }
public void addForDisplay(CTalkativeTextPane pane, LabelPair<String, String> lp) { GridBagLayout gridbag = (GridBagLayout) getLayout(); labelPair = lp; label = new JLabel(labelPair.getSingular(), JLabel.LEFT); pane.getDocument().addDocumentListener(this); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.1; c.weighty = 0.1; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 20, 0, 00); gridbag.setConstraints(pane, c); add(pane); c = new GridBagConstraints(); c.gridx = 1; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.1; c.weighty = 0.1; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 20); gridbag.setConstraints(label, c); add(label); JPanel filler = new JPanel(); filler.setBackground(white); c = new GridBagConstraints(); c.gridx = 2; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.8; c.weighty = 0.8; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.LINE_END; gridbag.setConstraints(filler, c); add(filler); filler = null; c = null; }
protected void buildErrorPanel() { errorPanel = new JPanel(); GroupLayout layout = new GroupLayout(errorPanel); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); errorPanel.setLayout(layout); // errorPanel.setBorder(BorderFactory.createMatteBorder(2, 0, 0, 0, Color.BLACK)); errorMessage = new JTextPane(); errorMessage.setEditable(false); errorMessage.setContentType("text/html"); errorMessage.setText( "<html><body>Could not connect to the Processing server.<br>" + "Contributions cannot be installed or updated without an Internet connection.<br>" + "Please verify your network connection again, then try connecting again.</body></html>"); errorMessage.setFont(Toolkit.getSansFont(14, Font.PLAIN)); errorMessage.setMaximumSize(new Dimension(550, 50)); errorMessage.setOpaque(false); StyledDocument doc = errorMessage.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, doc.getLength(), center, false); closeButton = new JButton("X"); closeButton.setContentAreaFilled(false); closeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { contribDialog.makeAndShowTab(false, false); } }); tryAgainButton = new JButton("Try Again"); tryAgainButton.setFont(Toolkit.getSansFont(14, Font.PLAIN)); tryAgainButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { contribDialog.makeAndShowTab(false, true); contribDialog.downloadAndUpdateContributionListing(editor.getBase()); } }); layout.setHorizontalGroup( layout .createSequentialGroup() .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(errorMessage) .addComponent( tryAgainButton, StatusPanel.BUTTON_WIDTH, StatusPanel.BUTTON_WIDTH, StatusPanel.BUTTON_WIDTH)) .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(closeButton)); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout.createParallelGroup().addComponent(errorMessage).addComponent(closeButton)) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(tryAgainButton)); errorPanel.setBackground(Color.PINK); errorPanel.validate(); }
/** * Returns a JPanel that represents the mancala board using strategy pattern to insert style. * * @param strat concrete strategy * @return JPanel containing both users' pits as controllers */ public JPanel boardContextDoWork(Strategy strat) { this.s = strat; Color boardColor = s.getBoardColor(); Color fontColor = s.getFontColor(); Font font = s.getFont(); JPanel panCenter = new JPanel(); JPanel panLeft = new JPanel(); JPanel panRight = new JPanel(); panCenter.setLayout(new GridLayout(2, 6, 10, 10)); // B6 to B1 Controllers for (int i = 12; i > 6; i--) { final Pits temp = new Pits(i); final int pit = i; final JLabel tempLabel = new JLabel(temp); tempLabel.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { if (Model.player == 1) { JFrame frame = new JFrame(); JOptionPane.showMessageDialog(frame, "Player A's turn!"); } else if (model.data[pit] == 0) { JFrame frame = new JFrame(); JOptionPane.showMessageDialog(frame, "Pit is Empty try another one."); } else { if (temp.pitShape.contains(e.getPoint())) { model.move(pit); // mutator undoBtn.setText("Undo : " + model.getUndoCounter()); model.display(); } } } }); JPanel tempPanel = new JPanel(new BorderLayout()); JTextPane textPane = new JTextPane(); textPane.setEditable(false); textPane.setBackground(boardColor); textPane.setForeground(fontColor); textPane.setFont(font); textPane.setText("B" + (i - 6)); StyledDocument doc = textPane.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, doc.getLength(), center, false); tempPanel.add(textPane, BorderLayout.NORTH); tempPanel.add(tempLabel, BorderLayout.SOUTH); panCenter.add(tempPanel, BorderLayout.SOUTH); tempPanel.setBackground(boardColor); } // A1 to A6 Controllers for (int i = 0; i < 6; i++) { final Pits newPits = new Pits(i); JLabel label = new JLabel(newPits); final int pit = i; label.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { if (Model.player == 2) { JFrame frame = new JFrame(); JOptionPane.showMessageDialog(frame, "Player B's turn!"); } else if (model.data[pit] == 0) { JFrame frame = new JFrame(); JOptionPane.showMessageDialog(frame, "Pit is Empty try another one."); } else { if (newPits.pitShape.contains(e.getPoint())) { model.move(pit); // mutator undoBtn.setText("Undo : " + model.getUndoCounter()); model.display(); } } } }); JPanel tempPanel = new JPanel(new BorderLayout()); tempPanel.add(label, BorderLayout.NORTH); JTextPane textPane = new JTextPane(); textPane.setBackground(boardColor); textPane.setForeground(fontColor); textPane.setFont(font); textPane.setEditable(false); textPane.setText("A" + (i + 1)); StyledDocument doc = textPane.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, doc.getLength(), center, false); tempPanel.add(textPane, BorderLayout.SOUTH); tempPanel.setBackground(boardColor); panCenter.add(tempPanel, BorderLayout.SOUTH); } // left text pane JTextPane paneLeft = new JTextPane(); paneLeft.setBackground(boardColor); paneLeft.setForeground(fontColor); paneLeft.setFont(font); paneLeft.setEditable(false); paneLeft.setText("M\nA\nN\nC\nA\nL\nA\n \nB"); // right text pane JTextPane paneRight = new JTextPane(); paneRight.setBackground(boardColor); paneRight.setForeground(fontColor); paneRight.setFont(font); paneRight.setEditable(false); paneRight.setText("M\nA\nN\nC\nA\nL\nA\n \nA"); // Add text panes to left and right panels panLeft.setLayout(new BorderLayout()); panRight.setLayout(new BorderLayout()); panLeft.add(paneLeft, BorderLayout.WEST); panRight.add(paneRight, BorderLayout.EAST); panLeft.add(new JLabel(new Pits(13)), BorderLayout.EAST); panRight.add(new JLabel(new Pits(6)), BorderLayout.WEST); // add the 2 mancala panels and pit panel to larger displayPanel JPanel displayPanel = new JPanel(); displayPanel.add(panLeft, BorderLayout.WEST); displayPanel.add(panCenter, BorderLayout.CENTER); displayPanel.add(panRight, BorderLayout.EAST); // set color panCenter.setBackground(boardColor); panLeft.setBackground(boardColor); panRight.setBackground(boardColor); displayPanel.setBackground(boardColor); // return display panel which contains the containers and elements created return displayPanel; }
/** * The consturctor Constructor instantiates all the panels, convertible value instance, and the * frame. And adds the panels to the frame. And sets a proper size for the frame. */ public HappyHackingConverter() { CFrame frame = new CFrame(); frame.setBackground(white); ConvertibleValue temperatures = new ConvertibleValue(); ConvertibleValue distances = new ConvertibleValue(); ConvertibleValue weights = new ConvertibleValue(); GridBagLayout leftSideLayout = new GridBagLayout(); JPanel leftSide = new JPanel(leftSideLayout); leftSide.setBackground(white); GridBagLayout rightSideLayout = new GridBagLayout(); JPanel rightSide = new JPanel(rightSideLayout); rightSide.setBackground(white); GridBagConstraints metricTemperatureConstraints = new GridBagConstraints(); metricTemperatureConstraints.gridx = 0; metricTemperatureConstraints.gridy = 0; metricTemperatureConstraints.weighty = 0.1; metricTemperatureConstraints.weightx = 1; metricTemperatureConstraints.fill = GridBagConstraints.BOTH; metricTemperatureConstraints.anchor = GridBagConstraints.FIRST_LINE_START; JPanel metricTemperaturePanel = new TemperaturePanel(frame, temperatures, TemperatureScales.CENTIGRADE); leftSideLayout.setConstraints(metricTemperaturePanel, metricTemperatureConstraints); leftSide.add(metricTemperaturePanel); GridBagConstraints metricDistancesPanelConstraints = new GridBagConstraints(); metricDistancesPanelConstraints.gridx = 0; metricDistancesPanelConstraints.gridy = 1; metricDistancesPanelConstraints.weighty = 0.3; metricDistancesPanelConstraints.weightx = 1; metricDistancesPanelConstraints.fill = GridBagConstraints.BOTH; metricDistancesPanelConstraints.anchor = GridBagConstraints.FIRST_LINE_START; JPanel metricDistancesPanel = new MetricDistancesPanel(frame, distances); leftSideLayout.setConstraints(metricDistancesPanel, metricDistancesPanelConstraints); leftSide.add(metricDistancesPanel); GridBagConstraints fahrenheitConstraints = new GridBagConstraints(); fahrenheitConstraints.gridx = 0; fahrenheitConstraints.gridy = 0; fahrenheitConstraints.weighty = 0.1; fahrenheitConstraints.weightx = 1; fahrenheitConstraints.fill = GridBagConstraints.BOTH; fahrenheitConstraints.anchor = GridBagConstraints.FIRST_LINE_START; JPanel fahrenheitTemperaturePanel = new TemperaturePanel(frame, temperatures, TemperatureScales.FAHRENHEIT); rightSideLayout.setConstraints(fahrenheitTemperaturePanel, fahrenheitConstraints); rightSide.add(fahrenheitTemperaturePanel); GridBagConstraints imperialDistancesPanelConstraints = new GridBagConstraints(); imperialDistancesPanelConstraints.gridx = 0; imperialDistancesPanelConstraints.gridy = 1; imperialDistancesPanelConstraints.weighty = 0.3; imperialDistancesPanelConstraints.weightx = 1; imperialDistancesPanelConstraints.fill = GridBagConstraints.BOTH; imperialDistancesPanelConstraints.anchor = GridBagConstraints.FIRST_LINE_START; JPanel imperialDistancesPanel = new ImperialDistancesPanel(frame, distances); rightSideLayout.setConstraints(imperialDistancesPanel, imperialDistancesPanelConstraints); rightSide.add(imperialDistancesPanel); GridBagConstraints metricWeightsConstraints = new GridBagConstraints(); metricWeightsConstraints.gridx = 0; metricWeightsConstraints.gridy = 2; metricWeightsConstraints.weighty = 0.6; metricWeightsConstraints.weightx = 1; metricWeightsConstraints.fill = GridBagConstraints.BOTH; metricWeightsConstraints.anchor = GridBagConstraints.FIRST_LINE_START; MetricWeightsPanel metricWeightsPanel = new MetricWeightsPanel(frame, weights); leftSideLayout.setConstraints(metricWeightsPanel, metricWeightsConstraints); leftSide.add(metricWeightsPanel); GridBagConstraints imperialWeightsConstraints = new GridBagConstraints(); imperialWeightsConstraints.gridx = 0; imperialWeightsConstraints.gridy = 2; imperialWeightsConstraints.weighty = 0.6; imperialWeightsConstraints.weightx = 1; imperialWeightsConstraints.fill = GridBagConstraints.BOTH; imperialWeightsConstraints.anchor = GridBagConstraints.FIRST_LINE_START; ImperialWeightsPanel imperialWeightsPanel = new ImperialWeightsPanel(frame, weights); rightSideLayout.setConstraints(imperialWeightsPanel, imperialWeightsConstraints); rightSide.add(imperialWeightsPanel); CSplit split = new CSplit(JSplitPane.HORIZONTAL_SPLIT, true, leftSide, rightSide); Container contentPane = frame.getContentPane(); contentPane.add(split); frame.validate(); frame.pack(); frame.setSize(600, 997); split.setResizeWeight(0.5); split.setDividerLocation(0.5); } // end of HappyHackingConverter constructor