List of usage examples for javax.swing JLabel getFont
@Transient
public Font getFont()
From source file:com.atlassian.theplugin.idea.bamboo.tree.BuildTreeNode.java
private void recalculateColumnWidths(final BuildListModel buildModel) { JLabel l = new JLabel(); reasonWidth = 0.0;/*from ww w. j av a 2 s . co m*/ serverWidth = 0.0; dateWidth = 0.0; planInProgressWidth = 0.0; for (BambooBuildAdapter b : buildModel.getBuilds()) { // PL-1202 - argument to TextLayout must be a non-empty string String reason = getBuildReasonString(b); TextLayout layoutStatus = new TextLayout(reason.length() > 0 ? reason : ".", l.getFont(), new FontRenderContext(null, true, true)); reasonWidth = Math.max(layoutStatus.getBounds().getWidth(), reasonWidth); String server = getBuildServerString(b); TextLayout layoutName = new TextLayout(server.length() > 0 ? server : ".", l.getFont(), new FontRenderContext(null, true, true)); serverWidth = Math.max(layoutName.getBounds().getWidth(), serverWidth); String date = getRelativeBuildTimeString(b); TextLayout layoutDate = new TextLayout(date.length() > 0 ? date : ".", l.getFont(), new FontRenderContext(null, true, true)); dateWidth = Math.max(layoutDate.getBounds().getWidth(), dateWidth); TextLayout planStatus = new TextLayout( build.getPlanStateString().length() > 0 ? build.getPlanStateString() : " ", l.getFont(), new FontRenderContext(null, true, true)); planInProgressWidth = Math.max(planStatus.getBounds().getWidth(), planInProgressWidth); } }
From source file:dk.dma.epd.common.prototype.gui.notification.ChatServicePanel.java
/** * Updates the chat message panel in the Swing event thread *//*from ww w .j av a 2s .com*/ public void updateChatMessagePanel() { // Ensure that we operate in the Swing event thread if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { updateChatMessagePanel(); } }); return; } // Set the title header titleHeader.setText(chatData != null ? NameUtils.getName(chatData.getId(), NameFormat.MEDIUM) : " "); titleHeader.setVisible(chatData != null); // Only enable send-function when there is chat data, and hence a target sendBtn.setEnabled(chatData != null); messageText.setEditable(chatData != null); // Remove all components from the messages panel messagesPanel.removeAll(); Insets insets = new Insets(0, 2, 2, 2); Insets insets2 = new Insets(6, 2, 0, 2); if (chatData != null && chatData.getMessageCount() > 0) { // First, add a filler component int y = 0; messagesPanel.add(new JLabel(""), new GridBagConstraints(0, y++, 1, 1, 0.0, 1.0, NORTH, VERTICAL, insets, 0, 0)); // Add the messages long lastMessageTime = 0; for (EPDChatMessage message : chatData.getMessages()) { // Check if we need to add a time label if (message.getSendDate().getTime() - lastMessageTime > PRINT_DATE_INTERVAL) { JLabel dateLabel = new JLabel( String.format(message.isOwnMessage() ? "Sent to %s" : "Received %s", Formatter.formatShortDateTimeNoTz(new Date(message.getSendDate().getTime())))); dateLabel.setFont(dateLabel.getFont().deriveFont(9.0f).deriveFont(Font.PLAIN)); dateLabel.setHorizontalAlignment(SwingConstants.CENTER); dateLabel.setForeground(Color.LIGHT_GRAY); messagesPanel.add(dateLabel, new GridBagConstraints(0, y++, 1, 1, 1.0, 0.0, NORTH, HORIZONTAL, insets2, 0, 0)); } // Add a chat message field JPanel msg = new JPanel(); msg.setBorder(new ChatMessageBorder(message)); JLabel msgLabel = new ChatMessageLabel(message.getMsg(), message.isOwnMessage()); msg.add(msgLabel); messagesPanel.add(msg, new GridBagConstraints(0, y++, 1, 1, 1.0, 0.0, NORTH, HORIZONTAL, insets, 0, 0)); lastMessageTime = message.getSendDate().getTime(); } // Scroll to the bottom validate(); scrollPane.getVerticalScrollBar().setValue(scrollPane.getVerticalScrollBar().getMaximum()); messagesPanel.repaint(); } else if (chatData == null && noDataComponent != null) { // The noDataComponent may e.g. be a message messagesPanel.add(noDataComponent, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, NORTH, BOTH, insets, 0, 0)); } }
From source file:edu.ku.brc.af.tasks.subpane.StatsPane.java
/** * Creates a StatsPane.//from ww w . j a v a 2s . c o m * @param name name of pane * @param task the owning task * @param resourceName the name of the resource that contains the configuration * @param useSeparatorTitles indicates the group panels should use separator titles instead of boxes * @param bgColor the background color * @param upperDisplayComp a display component for the upper half of the screen */ public StatsPane(final String name, final Taskable task, final String resourceName, final boolean useSeparatorTitles, final Color bgColor, final JComponent upperDisplayComp) { super(name, task); this.resourceName = resourceName; this.useSeparatorTitles = useSeparatorTitles; this.upperDisplayComp = upperDisplayComp; if (bgColor != null) { this.bgColor = bgColor; } else { this.bgColor = Color.WHITE; } setBackground(this.bgColor); setOpaque(true); setLayout(new BorderLayout()); if (upperDisplayComp == null) { JLabel lbl = UIHelper.createI18NLabel("COLL_STATS", SwingConstants.CENTER); int pntSize = lbl.getFont().getSize(); lbl.setFont(lbl.getFont().deriveFont((float) pntSize + 2).deriveFont(Font.BOLD)); add(lbl, BorderLayout.NORTH); } init(); registerPrintContextMenu(); }
From source file:JXTransformer.java
private JPanel createDemoPanel() { JPanel buttonPanel = new JPanel(new GridLayout(3, 2)); TitledBorder titledBorder = BorderFactory.createTitledBorder("Try three sliders below !"); Font titleFont = titledBorder.getTitleFont(); titledBorder.setTitleFont(titleFont.deriveFont(titleFont.getSize2D() + 10)); titledBorder.setTitleJustification(TitledBorder.CENTER); buttonPanel.setBorder(titledBorder); JButton b = new JButton("JButton"); b.setPreferredSize(new Dimension(100, 50)); buttonPanel.add(createTransformer(b)); Vector<String> v = new Vector<String>(); v.add("One"); v.add("Two"); v.add("Three"); JList list = new JList(v); buttonPanel.add(createTransformer(list)); buttonPanel.add(createTransformer(new JCheckBox("JCheckBox"))); JSlider slider = new JSlider(0, 100); slider.setLabelTable(slider.createStandardLabels(25, 0)); slider.setPaintLabels(true);/*from w w w . j av a 2 s.c om*/ slider.setPaintTicks(true); slider.setMajorTickSpacing(10); buttonPanel.add(createTransformer(slider)); buttonPanel.add(createTransformer(new JRadioButton("JRadioButton"))); final JLabel label = new JLabel("JLabel"); label.addMouseListener(new MouseAdapter() { public void mouseEntered(MouseEvent e) { Font font = label.getFont(); label.setFont(font.deriveFont(font.getSize2D() + 10)); } public void mouseExited(MouseEvent e) { Font font = label.getFont(); label.setFont(font.deriveFont(font.getSize2D() - 10)); } }); buttonPanel.add(createTransformer(label)); return buttonPanel; }
From source file:com.floreantpos.ui.views.payment.GroupSettleTicketDialog.java
private JPanel createTotalViewerPanel() { JLabel lblSubtotal = new javax.swing.JLabel(); lblSubtotal.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblSubtotal.setText(com.floreantpos.POSConstants.SUBTOTAL + ":" + " " + CurrencyUtil.getCurrencySymbol()); //$NON-NLS-1$ //$NON-NLS-2$ tfSubtotal = new javax.swing.JTextField(10); tfSubtotal.setHorizontalAlignment(SwingConstants.TRAILING); tfSubtotal.setEditable(false);/*from ww w. j a va 2 s . co m*/ JLabel lblDiscount = new javax.swing.JLabel(); lblDiscount.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblDiscount.setText(Messages.getString("TicketView.9") + " " + CurrencyUtil.getCurrencySymbol()); //$NON-NLS-1$ //$NON-NLS-2$ tfDiscount = new javax.swing.JTextField(10); tfDiscount.setHorizontalAlignment(SwingConstants.TRAILING); tfDiscount.setEditable(false); JLabel lblDeliveryCharge = new javax.swing.JLabel(); lblDeliveryCharge.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblDeliveryCharge.setText("Delivery Charge:" + " " + CurrencyUtil.getCurrencySymbol()); //$NON-NLS-1$ //$NON-NLS-2$ tfDeliveryCharge = new JTextField(10); tfDeliveryCharge.setHorizontalAlignment(SwingConstants.TRAILING); tfDeliveryCharge.setEditable(false); JLabel lblTax = new javax.swing.JLabel(); lblTax.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblTax.setText(com.floreantpos.POSConstants.TAX + ":" + " " + CurrencyUtil.getCurrencySymbol()); //$NON-NLS-1$ //$NON-NLS-2$ tfTax = new javax.swing.JTextField(); tfTax.setEditable(false); tfTax.setHorizontalAlignment(SwingConstants.TRAILING); JLabel lblGratuity = new javax.swing.JLabel(); lblGratuity.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblGratuity .setText(Messages.getString("SettleTicketDialog.5") + ":" + " " + CurrencyUtil.getCurrencySymbol()); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ tfGratuity = new javax.swing.JTextField(); tfGratuity.setEditable(false); tfGratuity.setHorizontalAlignment(SwingConstants.TRAILING); JLabel lblTotal = new javax.swing.JLabel(); lblTotal.setFont(lblTotal.getFont().deriveFont(Font.BOLD, 18)); lblTotal.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblTotal.setText(com.floreantpos.POSConstants.TOTAL + ":" + " " + CurrencyUtil.getCurrencySymbol()); //$NON-NLS-1$ //$NON-NLS-2$ tfTotal = new javax.swing.JTextField(10); tfTotal.setFont(tfTotal.getFont().deriveFont(Font.BOLD, 18)); tfTotal.setHorizontalAlignment(SwingConstants.TRAILING); tfTotal.setEditable(false); JPanel ticketAmountPanel = new com.floreantpos.swing.TransparentPanel( new MigLayout("hidemode 3,ins 2 2 3 2,alignx trailing,fill", "[grow][]", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ticketAmountPanel.add(lblSubtotal, "growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(tfSubtotal, "growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(lblDiscount, "newline,growx,aligny center"); //$NON-NLS-1$ //$NON-NLS-2$ ticketAmountPanel.add(tfDiscount, "growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(lblTax, "newline,growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(tfTax, "growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(lblDeliveryCharge, "newline,growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(tfDeliveryCharge, "growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(lblGratuity, "newline,growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(tfGratuity, "growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(lblTotal, "newline,growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(tfTotal, "growx,aligny center"); //$NON-NLS-1$ return ticketAmountPanel; }
From source file:com.sshtools.appframework.ui.SshToolsApplication.java
/** * Show an 'About' dialog//from w ww. ja va 2 s . com */ public void showAbout(Component parent) { JPanel p = new JPanel(new GridBagLayout()); p.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); GridBagConstraints gBC = new GridBagConstraints(); gBC.anchor = GridBagConstraints.CENTER; gBC.fill = GridBagConstraints.HORIZONTAL; gBC.insets = new Insets(1, 1, 1, 1); JLabel a = new JLabel(getApplicationName()); a.setFont(a.getFont().deriveFont(24f)); UIUtil.jGridBagAdd(p, a, gBC, GridBagConstraints.REMAINDER); JLabel v = new JLabel("Version " + getApplicationVersion()); v.setFont(v.getFont().deriveFont(10f)); UIUtil.jGridBagAdd(p, v, gBC, GridBagConstraints.REMAINDER); MultilineLabel x = new MultilineLabel(getAboutLicenseDetails()); x.setBorder(BorderFactory.createEmptyBorder(8, 0, 8, 0)); x.setFont(x.getFont().deriveFont(12f)); UIUtil.jGridBagAdd(p, x, gBC, GridBagConstraints.REMAINDER); MultilineLabel c = new MultilineLabel(getExpiryInfo()); c.setFont(c.getFont().deriveFont(10f)); UIUtil.jGridBagAdd(p, c, gBC, GridBagConstraints.REMAINDER); final JLabel h = new JLabel(getAboutURL()); h.setForeground(Color.blue); h.setFont(new Font(h.getFont().getName(), Font.BOLD, 10)); h.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); h.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { try { BrowserLauncher.openURL(getAboutURL()); } catch (IOException ioe) { ioe.printStackTrace(); } } }); UIUtil.jGridBagAdd(p, h, gBC, GridBagConstraints.REMAINDER); JOptionPane.showMessageDialog(parent, p, "About", JOptionPane.PLAIN_MESSAGE, getApplicationLargeIcon()); }
From source file:components.DialogDemo.java
/** Creates the panel shown by the second tab. */ private JPanel createFeatureDialogBox() { final int numButtons = 5; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton showItButton = null;/*from w w w .j av a2 s . c o m*/ final String pickOneCommand = "pickone"; final String textEnteredCommand = "textfield"; final String nonAutoCommand = "nonautooption"; final String customOptionCommand = "customoption"; final String nonModalCommand = "nonmodal"; radioButtons[0] = new JRadioButton("Pick one of several choices"); radioButtons[0].setActionCommand(pickOneCommand); radioButtons[1] = new JRadioButton("Enter some text"); radioButtons[1].setActionCommand(textEnteredCommand); radioButtons[2] = new JRadioButton("Non-auto-closing dialog"); radioButtons[2].setActionCommand(nonAutoCommand); radioButtons[3] = new JRadioButton("Input-validating dialog " + "(with custom message area)"); radioButtons[3].setActionCommand(customOptionCommand); radioButtons[4] = new JRadioButton("Non-modal dialog"); radioButtons[4].setActionCommand(nonModalCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } radioButtons[0].setSelected(true); showItButton = new JButton("Show it!"); showItButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); //pick one of many if (command == pickOneCommand) { Object[] possibilities = { "ham", "spam", "yam" }; String s = (String) JOptionPane.showInputDialog(frame, "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog", JOptionPane.PLAIN_MESSAGE, icon, possibilities, "ham"); //If a string was returned, say so. if ((s != null) && (s.length() > 0)) { setLabel("Green eggs and... " + s + "!"); return; } //If you're here, the return value was null/empty. setLabel("Come on, finish the sentence!"); //text input } else if (command == textEnteredCommand) { String s = (String) JOptionPane.showInputDialog(frame, "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog", JOptionPane.PLAIN_MESSAGE, icon, null, "ham"); //If a string was returned, say so. if ((s != null) && (s.length() > 0)) { setLabel("Green eggs and... " + s + "!"); return; } //If you're here, the return value was null/empty. setLabel("Come on, finish the sentence!"); //non-auto-closing dialog } else if (command == nonAutoCommand) { final JOptionPane optionPane = new JOptionPane( "The only way to close this dialog is by\n" + "pressing one of the following buttons.\n" + "Do you understand?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); //You can't use pane.createDialog() because that //method sets up the JDialog with a property change //listener that automatically closes the window //when a button is clicked. final JDialog dialog = new JDialog(frame, "Click a button", true); dialog.setContentPane(optionPane); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { setLabel("Thwarted user attempt to close window."); } }); optionPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (dialog.isVisible() && (e.getSource() == optionPane) && (JOptionPane.VALUE_PROPERTY.equals(prop))) { //If you were going to check something //before closing the window, you'd do //it here. dialog.setVisible(false); } } }); dialog.pack(); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); int value = ((Integer) optionPane.getValue()).intValue(); if (value == JOptionPane.YES_OPTION) { setLabel("Good."); } else if (value == JOptionPane.NO_OPTION) { setLabel("Try using the window decorations " + "to close the non-auto-closing dialog. " + "You can't!"); } else { setLabel("Window unavoidably closed (ESC?)."); } //non-auto-closing dialog with custom message area //NOTE: if you don't intend to check the input, //then just use showInputDialog instead. } else if (command == customOptionCommand) { customDialog.setLocationRelativeTo(frame); customDialog.setVisible(true); String s = customDialog.getValidatedText(); if (s != null) { //The text is valid. setLabel("Congratulations! " + "You entered \"" + s + "\"."); } //non-modal dialog } else if (command == nonModalCommand) { //Create the dialog. final JDialog dialog = new JDialog(frame, "A Non-Modal Dialog"); //Add contents to it. It must have a close button, //since some L&Fs (notably Java/Metal) don't provide one //in the window decorations for dialogs. JLabel label = new JLabel("<html><p align=center>" + "This is a non-modal dialog.<br>" + "You can have one or more of these up<br>" + "and still use the main window."); label.setHorizontalAlignment(JLabel.CENTER); Font font = label.getFont(); label.setFont(label.getFont().deriveFont(font.PLAIN, 14.0f)); JButton closeButton = new JButton("Close"); closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); dialog.dispose(); } }); JPanel closePanel = new JPanel(); closePanel.setLayout(new BoxLayout(closePanel, BoxLayout.LINE_AXIS)); closePanel.add(Box.createHorizontalGlue()); closePanel.add(closeButton); closePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 5)); JPanel contentPane = new JPanel(new BorderLayout()); contentPane.add(label, BorderLayout.CENTER); contentPane.add(closePanel, BorderLayout.PAGE_END); contentPane.setOpaque(true); dialog.setContentPane(contentPane); //Show it. dialog.setSize(new Dimension(300, 150)); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); } } }); return createPane(moreDialogDesc + ":", radioButtons, showItButton); }
From source file:com.floreantpos.ui.views.payment.SettleTicketDialog.java
private JPanel createTotalViewerPanel() { JLabel lblSubtotal = new javax.swing.JLabel(); lblSubtotal.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblSubtotal.setText(com.floreantpos.POSConstants.SUBTOTAL + ":" + " " + CurrencyUtil.getCurrencySymbol()); //$NON-NLS-1$ //$NON-NLS-2$ tfSubtotal = new javax.swing.JTextField(10); tfSubtotal.setHorizontalAlignment(SwingConstants.TRAILING); tfSubtotal.setEditable(false);/* w w w. ja va 2 s.co m*/ JLabel lblDiscount = new javax.swing.JLabel(); lblDiscount.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblDiscount.setText(Messages.getString("TicketView.9") + " " + CurrencyUtil.getCurrencySymbol()); //$NON-NLS-1$ //$NON-NLS-2$ tfDiscount = new javax.swing.JTextField(10); // tfDiscount.setFont(tfDiscount.getFont().deriveFont(Font.PLAIN, 16)); tfDiscount.setHorizontalAlignment(SwingConstants.TRAILING); tfDiscount.setEditable(false); tfDiscount.setText(ticket.getDiscountAmount().toString()); JLabel lblDeliveryCharge = new javax.swing.JLabel(); lblDeliveryCharge.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblDeliveryCharge.setText("Delivery Charge:" + " " + CurrencyUtil.getCurrencySymbol()); //$NON-NLS-1$ //$NON-NLS-2$ tfDeliveryCharge = new javax.swing.JTextField(10); tfDeliveryCharge.setHorizontalAlignment(SwingConstants.TRAILING); tfDeliveryCharge.setEditable(false); JLabel lblTax = new javax.swing.JLabel(); lblTax.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblTax.setText(com.floreantpos.POSConstants.TAX + ":" + " " + CurrencyUtil.getCurrencySymbol()); //$NON-NLS-1$ //$NON-NLS-2$ tfTax = new javax.swing.JTextField(10); // tfTax.setFont(tfTax.getFont().deriveFont(Font.PLAIN, 16)); tfTax.setEditable(false); tfTax.setHorizontalAlignment(SwingConstants.TRAILING); JLabel lblGratuity = new javax.swing.JLabel(); lblGratuity.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblGratuity .setText(Messages.getString("SettleTicketDialog.5") + ":" + " " + CurrencyUtil.getCurrencySymbol()); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ tfGratuity = new javax.swing.JTextField(10); tfGratuity.setEditable(false); tfGratuity.setHorizontalAlignment(SwingConstants.TRAILING); JLabel lblTotal = new javax.swing.JLabel(); lblTotal.setFont(lblTotal.getFont().deriveFont(Font.BOLD, PosUIManager.getFontSize(18))); lblTotal.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); lblTotal.setText(com.floreantpos.POSConstants.TOTAL + ":" + " " + CurrencyUtil.getCurrencySymbol()); //$NON-NLS-1$ //$NON-NLS-2$ tfTotal = new javax.swing.JTextField(10); tfTotal.setFont(tfTotal.getFont().deriveFont(Font.BOLD, PosUIManager.getFontSize(18))); tfTotal.setHorizontalAlignment(SwingConstants.TRAILING); tfTotal.setEditable(false); JPanel ticketAmountPanel = new com.floreantpos.swing.TransparentPanel( new MigLayout("hidemode 3,ins 2 2 3 2,alignx trailing,fill", "[grow]2[]", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ticketAmountPanel.add(lblSubtotal, "growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(tfSubtotal, "growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(lblDiscount, "newline,growx,aligny center"); //$NON-NLS-1$ //$NON-NLS-2$ ticketAmountPanel.add(tfDiscount, "growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(lblTax, "newline,growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(tfTax, "growx,aligny center"); //$NON-NLS-1$ if (ticket.getOrderType().isDelivery() && !ticket.isCustomerWillPickup()) { ticketAmountPanel.add(lblDeliveryCharge, "newline,growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(tfDeliveryCharge, "growx,aligny center"); //$NON-NLS-1$ } ticketAmountPanel.add(lblGratuity, "newline,growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(tfGratuity, "growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(lblTotal, "newline,growx,aligny center"); //$NON-NLS-1$ ticketAmountPanel.add(tfTotal, "growx,aligny center"); //$NON-NLS-1$ return ticketAmountPanel; }
From source file:net.sf.taverna.t2.activities.wsdlsir.views.WSDLActivityConfigurationView.java
private void initComponents() { this.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL); int gridy = 0; // title panel JPanel titlePanel = new JPanel(new BorderLayout()); titlePanel.setBackground(Color.WHITE); JLabel titleLabel = new JLabel("Security configuration"); titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 13.5f)); titleLabel.setBorder(new EmptyBorder(10, 10, 0, 10)); DialogTextArea titleMessage = new DialogTextArea("Select a security profile for the service"); titleMessage.setMargin(new Insets(5, 20, 10, 10)); titleMessage.setFont(titleMessage.getFont().deriveFont(11f)); titleMessage.setEditable(false);/*from ww w . ja v a2 s . c o m*/ titleMessage.setFocusable(false); titlePanel.setBorder(new EmptyBorder(10, 10, 0, 10)); titlePanel.add(titleLabel, BorderLayout.NORTH); titlePanel.add(titleMessage, BorderLayout.CENTER); addDivider(titlePanel, SwingConstants.BOTTOM, true); // Main panel JPanel mainPanel = new JPanel(); mainPanel.setLayout(new GridBagLayout()); mainPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); //Create the radio buttons noSecurityRadioButton = new JRadioButton("None"); noSecurityRadioButton.addItemListener(this); wsSecurityAuthNRadioButton = new JRadioButton("WS-Security username and password authentication"); wsSecurityAuthNRadioButton.addItemListener(this); httpSecurityAuthNRadioButton = new JRadioButton("HTTP username and password authentication"); httpSecurityAuthNRadioButton.addItemListener(this); SAMLSecurityAuthNRadioButton = new JRadioButton("SAML WEB SSO profile authentication"); SAMLSecurityAuthNRadioButton.addItemListener(this); //Group the radio buttons buttonGroup = new ButtonGroup(); buttonGroup.add(noSecurityRadioButton); buttonGroup.add(wsSecurityAuthNRadioButton); buttonGroup.add(httpSecurityAuthNRadioButton); buttonGroup.add(SAMLSecurityAuthNRadioButton); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.gridx = 0; gbc.gridy = gridy++; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 10, 0, 0); mainPanel.add(noSecurityRadioButton, gbc); noSecurityLabel = new JLabel("Service requires no security"); noSecurityLabel.setFont(noSecurityLabel.getFont().deriveFont(11f)); // addDivider(noSecurityLabel, SwingConstants.BOTTOM, false); gbc.gridx = 0; gbc.gridy = gridy++; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(0, 40, 10, 10); mainPanel.add(noSecurityLabel, gbc); gbc.gridx = 0; gbc.gridy = gridy++; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 10, 0, 0); mainPanel.add(httpSecurityAuthNRadioButton, gbc); ActionListener usernamePasswordListener = new ActionListener() { public void actionPerformed(ActionEvent e) { // Get Credential Manager UI to get the username and password for the service CredentialManagerUI credManagerUI = CredentialManagerUI.getInstance(); if (credManagerUI != null) credManagerUI.newPasswordForService(oldBean.getWsdl()); } }; httpSecurityAuthNLabel = new JLabel( "Service requires HTTP username and password in order to authenticate the user"); httpSecurityAuthNLabel.setFont(httpSecurityAuthNLabel.getFont().deriveFont(11f)); gbc.gridx = 0; gbc.gridy = gridy++; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(0, 40, 10, 10); mainPanel.add(httpSecurityAuthNLabel, gbc); // Set username and password button; setHttpUsernamePasswordButton = new JButton("Set username and password"); gbc.gridx = 0; gbc.gridy = gridy++; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.EAST; gbc.insets = new Insets(0, 40, 10, 10); gbc.weightx = 1.0; gbc.weighty = 1.0; // add any vertical space to this component mainPanel.add(setHttpUsernamePasswordButton, gbc); setHttpUsernamePasswordButton.addActionListener(usernamePasswordListener); /////SAML gbc.gridx = 0; gbc.gridy = gridy++; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 10, 0, 0); mainPanel.add(SAMLSecurityAuthNRadioButton, gbc); ActionListener getCookieListener = new ActionListener() { /** * This listener will use the CallPreparator to obtain the cookies (included shibsession_XXX cookie) and * save it in the Credential Manager (as the password for user "nomatter") */ public void actionPerformed(ActionEvent e) { try { WSDLParser parser = new WSDLParser(newBean.getWsdl()); List<String> endpoints = parser.getOperationEndpointLocations(newBean.getOperation()); for (String endpoint : endpoints) //Actually i am only expecting one endpoint { if (debug) System.out .println("Obtaining a SAML cookies to save in credential manager:" + endpoint); Cookie[] cookies = CallPreparator.createCookieForCallToEndpoint(endpoint); // Uncomment for just the shibsession cookie // Cookie[] cookiessession = new Cookie[1]; // for (Cookie cook : cookies) // if (cook.getName().contains("shibsession")) // cookiessession[0]=cook; // cookies=cookiessession; CredentialManager credman = CredentialManager.getInstance(); credman.saveUsernameAndPasswordForService( new UsernamePassword("nomatter", serializetoString(cookies)), new URI(endpoint)); } } catch (WSDLException ex) { System.err.println( "Problem getting or saving SAML cookie: " + newBean.getWsdl() + ". " + ex.getMessage()); ex.printStackTrace(); } catch (ParserConfigurationException ex) { System.err.println( "Problem getting or saving SAML cookie: " + newBean.getWsdl() + ". " + ex.getMessage()); ex.printStackTrace(); } catch (Exception ex) { System.err.println( "Problem getting or saving SAML cookie: " + newBean.getWsdl() + ". " + ex.getMessage()); ex.printStackTrace(); } } }; SAMLSecurityAuthNLabel = new JLabel("<html>" + "Service requires SAML Web SSO profile to be perfomed in order to authenticate the user. " + "A cookie will be saved in your Credential Manger. " + "In the case that it stops working, please delete the entry in your Credential Manager or re-authenticate" + "</html>"); SAMLSecurityAuthNLabel.setFont(SAMLSecurityAuthNLabel.getFont().deriveFont(11f)); gbc.gridx = 0; gbc.gridy = gridy++; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(3, 40, 10, 10); mainPanel.add(SAMLSecurityAuthNLabel, gbc); // Set username and password button; setSAMLGETCookieButton = new JButton("Authenticate and save Authentication data in Credential Manger"); gbc.gridx = 0; gbc.gridy = gridy++; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.EAST; gbc.insets = new Insets(0, 40, 10, 10); gbc.weightx = 1.0; gbc.weighty = 1.0; // add any vertical space to this component mainPanel.add(setSAMLGETCookieButton, gbc); setSAMLGETCookieButton.addActionListener(getCookieListener); //END SAML gbc.gridx = 0; gbc.gridy = gridy++; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 10, 0, 0); mainPanel.add(wsSecurityAuthNRadioButton, gbc); wsSecurityAuthNLabel = new JLabel( "Service requires WS-Security username and password in order to authenticate the user"); wsSecurityAuthNLabel.setFont(wsSecurityAuthNLabel.getFont().deriveFont(11f)); gbc.gridx = 0; gbc.gridy = gridy++; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(0, 40, 0, 0); mainPanel.add(wsSecurityAuthNLabel, gbc); // Password type list passwordTypeComboBox = new JComboBox(passwordTypes); passwordTypeComboBox.setRenderer(new ComboBoxTooltipRenderer()); gbc.gridx = 0; gbc.gridy = gridy++; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(10, 40, 0, 0); mainPanel.add(passwordTypeComboBox, gbc); // 'Add timestamp' checkbox addTimestampCheckBox = new JCheckBox("Add a timestamp to SOAP message"); gbc.gridx = 0; gbc.gridy = gridy++; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 40, 10, 10); mainPanel.add(addTimestampCheckBox, gbc); // Set username and password button; setWsdlUsernamePasswordButton = new JButton("Set username and password"); gbc.gridx = 0; gbc.gridy = gridy++; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.EAST; gbc.insets = new Insets(0, 40, 10, 10); gbc.weightx = 1.0; gbc.weighty = 1.0; // add any vertical space to this component mainPanel.add(setWsdlUsernamePasswordButton, gbc); setWsdlUsernamePasswordButton.addActionListener(usernamePasswordListener); addDivider(mainPanel, SwingConstants.BOTTOM, true); // OK/Cancel button panel JPanel okCancelPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); JButton okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okPressed(); } }); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancelPressed(); } }); okCancelPanel.add(cancelButton); okCancelPanel.add(okButton); // Enable/disable controls based on what is the current security profiles String securityProfile = oldBean.getSecurityProfile(); if (securityProfile == null) { noSecurityRadioButton.setSelected(true); } else { if (securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_PLAINTEXTPASSWORD) || securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_DIGESTPASSWORD) || securityProfile.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTEXTPASSWORD) || securityProfile.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD)) { wsSecurityAuthNRadioButton.setSelected(true); } if (securityProfile.equals(SecurityProfiles.HTTP_BASIC_AUTHN) || securityProfile.equals(SecurityProfiles.HTTP_DIGEST_AUTHN)) { httpSecurityAuthNRadioButton.setSelected(true); } if (securityProfile.equals(SecurityProfiles.SAMLWEBSSOAUTH)) { SAMLSecurityAuthNRadioButton.setSelected(true); } if (securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_PLAINTEXTPASSWORD) || securityProfile .equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTEXTPASSWORD)) { passwordTypeComboBox.setSelectedItem(PLAINTEXT_PASSWORD); } else if (securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_DIGESTPASSWORD) || securityProfile.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD)) { passwordTypeComboBox.setSelectedItem(DIGEST_PASSWORD); } if (securityProfile.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD) || securityProfile .equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTEXTPASSWORD)) { addTimestampCheckBox.setSelected(true); } else { addTimestampCheckBox.setSelected(false); } } // Put everything together JPanel layoutPanel = new JPanel(new BorderLayout()); layoutPanel.add(titlePanel, BorderLayout.NORTH); layoutPanel.add(mainPanel, BorderLayout.CENTER); layoutPanel.add(okCancelPanel, BorderLayout.SOUTH); layoutPanel.setPreferredSize(new Dimension(550, 490)); this.getContentPane().add(layoutPanel); this.pack(); }