public void showFrame(Editor editor, ContributionType contributionType) { this.editor = editor; // Calculating index to switch to the required tab int index = getIndex(contributionType); if (dialog == null) { makeFrame(editor); // done before as downloadAndUpdateContributionListing() // requires the current selected tab tabbedPane.setSelectedIndex(index); downloadAndUpdateContributionListing(editor.getBase()); if (index != 4) { Component selected = tabbedPane.getTabComponentAt(tabbedPane.getSelectedIndex()); selected.setBackground(new Color(0xe0fffd)); selected.setForeground(Color.BLACK); } else { updateTabPanel.setBackground(new Color(0xe0fffd)); updateTabLabel.setForeground(Color.BLACK); } } tabbedPane.setSelectedIndex(index); dialog.setVisible(true); }
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(); }
private void makeAndSetTabComponents() { final String[] tabTitles = {"Libraries", "Modes", "Tools", "Examples", "Updates"}; tabLabels = new JLabel[4]; for (int i = 0; i < 4; i++) { final int temp = i; tabLabels[i] = new JLabel(tabTitles[i]) { @Override protected void paintComponent(Graphics g) { g.setClip( Toolkit.createRoundRect( 0, 0, getWidth(), getHeight(), temp == 0 ? 6 : 0, temp == 3 ? 6 : 0, 0, 0)); super.paintComponent(g); } }; tabLabels[i].setForeground(Color.WHITE); tabLabels[i].setBackground(new Color(0x2d4251)); tabLabels[i].setOpaque(true); tabLabels[i].setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); tabLabels[i].setPreferredSize(new Dimension(TAB_WIDTH, TAB_HEIGHT)); tabLabels[i].setHorizontalAlignment(SwingConstants.CENTER); tabLabels[i].setFont(Toolkit.getSansFont(14, Font.BOLD)); tabbedPane.setTabComponentAt(i, tabLabels[i]); } updateTabPanel = new JPanel() { @Override protected void paintComponent(Graphics g) { g.setClip(Toolkit.createRoundRect(0, 0, getWidth(), getHeight(), 6, 6, 0, 0)); super.paintComponent(g); } }; ; updateTabLabel = new JLabel("Updates"); updateTabLabel.setFont(Toolkit.getSansFont(14, Font.BOLD)); numberLabel.setVerticalTextPosition(SwingConstants.CENTER); numberLabel.setHorizontalTextPosition(SwingConstants.CENTER); numberLabel.setFont(Toolkit.getSansFont(14, Font.BOLD)); numberLabel.setForeground(Color.WHITE); updateTabPanel.setOpaque(true); updateTabPanel.setBackground(new Color(0x2d4251)); updateTabLabel.setForeground(Color.WHITE); updateTabPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); updateTabPanel.setPreferredSize(new Dimension(TAB_WIDTH, TAB_HEIGHT)); tabbedPane.setTabComponentAt(4, updateTabPanel); GroupLayout tabLayout = new GroupLayout(updateTabPanel); tabLayout.setAutoCreateGaps(true); updateTabPanel.setLayout(tabLayout); tabLayout.setHorizontalGroup( tabLayout .createSequentialGroup() .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(updateTabLabel) .addComponent(numberLabel) .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)); tabLayout.setVerticalGroup( tabLayout .createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(numberLabel) .addComponent(updateTabLabel)); numberLabel.setVisible(false); }