Example usage for javax.swing JLabel setBorder

List of usage examples for javax.swing JLabel setBorder

Introduction

In this page you can find the example usage for javax.swing JLabel setBorder.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The component's border.")
public void setBorder(Border border) 

Source Link

Document

Sets the border of this component.

Usage

From source file:edu.harvard.i2b2.query.ui.QueryTopPanel.java

public void addPanel() {
    int rightmostPosition = dataModel.lastLabelPosition();
    JLabel label = new JLabel();
    label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    label.setText("and");
    label.setToolTipText("Click to change the relationship");
    label.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    label.addMouseListener(new java.awt.event.MouseAdapter() {
        @Override//from   w  w  w .java2s. c om
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            jAndOrLabelMouseClicked(evt);
        }
    });

    // jPanel1.add(label);
    // label.setBounds(rightmostPosition, 90, 30, 18);

    QueryConceptTreePanel panel = new QueryConceptTreePanel("Group " + (dataModel.getCurrentPanelCount() + 1),
            this);
    jPanel1.add(panel);
    panel.setBounds(rightmostPosition + 5, 0, 180, getParent().getHeight() - 100);
    jPanel1.setPreferredSize(new Dimension(rightmostPosition + 5 + 181 + 60, getHeight() - 100));
    jScrollPane4.setViewportView(jPanel1);

    dataModel.addPanel(panel, label, rightmostPosition + 5 + 180);

    jScrollPane4.getHorizontalScrollBar().setValue(jScrollPane4.getHorizontalScrollBar().getMaximum());
    jScrollPane4.getHorizontalScrollBar().setUnitIncrement(40);
    resizePanels(getParent().getWidth(), getParent().getHeight());
}

From source file:edu.ku.brc.specify.datamodel.busrules.CollectionObjectBusRules.java

/**
 * Show objects that were not added to the batch
 *//* ww w. jav a  2 s.  c om*/
@SuppressWarnings("rawtypes")
protected void showBatchErrorObjects(final Vector<String> badObjects, final String TitleKey,
        final String MsgKey) {
    JPanel pane = new JPanel(new BorderLayout());
    JLabel lbl = createLabel(getResourceString(MsgKey));
    lbl.setBorder(new EmptyBorder(3, 1, 2, 0));
    pane.add(lbl, BorderLayout.NORTH);
    JPanel lstPane = new JPanel(new BorderLayout());
    JList lst = UIHelper.createList(badObjects);
    lst.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
    lstPane.setBorder(new EmptyBorder(1, 1, 10, 1));
    lstPane.add(lst, BorderLayout.CENTER);
    JScrollPane sp = new JScrollPane(lstPane);
    //pane.add(lstPane, BorderLayout.CENTER);
    pane.add(sp, BorderLayout.CENTER);
    //pane.setPreferredSize(new Dimension((int )lbl.getPreferredSize().getWidth() + 5, (int )lst.getPreferredScrollableViewportSize().getHeight() + 5));
    //pane.setPreferredSize(new Dimension((int )lbl.getPreferredSize().getWidth() + 5, (int )lst.getPreferredScrollableViewportSize().getHeight() + 5));
    CustomDialog dlg = new CustomDialog((Frame) UIRegistry.getTopWindow(),
            UIRegistry.getResourceString(TitleKey), true, CustomDialog.OKHELP, pane);
    UIHelper.centerAndShow(dlg);
    dlg.dispose();
}

From source file:edu.harvard.i2b2.query.ui.QueryTopPanel.java

private void jMorePanelsButtonActionPerformed(java.awt.event.ActionEvent evt) {
    if (dataModel.hasEmptyPanels()) {
        JOptionPane.showMessageDialog(this, "Please use an existing empty panel before adding a new one.");
        return;/*from  w  w w . ja  v  a2  s .  c  om*/
    }
    int rightmostPosition = dataModel.lastLabelPosition();
    JLabel label = new JLabel();
    label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    label.setText("and");
    label.setToolTipText("Click to change the relationship");
    label.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    label.addMouseListener(new java.awt.event.MouseAdapter() {
        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            jAndOrLabelMouseClicked(evt);
        }
    });

    QueryConceptTreePanel panel = new QueryConceptTreePanel("Group " + (dataModel.getCurrentPanelCount() + 1),
            this);
    jPanel1.add(panel);
    panel.setBounds(rightmostPosition + 5, 0, 180, getParent().getHeight() - 100);
    jPanel1.setPreferredSize(new Dimension(rightmostPosition + 5 + 181 + 60, getHeight() - 100));
    jScrollPane4.setViewportView(jPanel1);

    dataModel.addPanel(panel, label, rightmostPosition + 5 + 180);

    /*
     * System.out.println(jScrollPane4.getViewport().getExtentSize().width+":"
     * + jScrollPane4.getViewport().getExtentSize().height);
     * System.out.println
     * (jScrollPane4.getHorizontalScrollBar().getVisibleRect().width+":"
     * +jScrollPane4.getHorizontalScrollBar().getVisibleRect().height);
     * System
     * .out.println(jScrollPane4.getHorizontalScrollBar().getVisibleAmount
     * ());
     * System.out.println(jScrollPane4.getHorizontalScrollBar().getValue());
     */
    jScrollPane4.getHorizontalScrollBar().setValue(jScrollPane4.getHorizontalScrollBar().getMaximum());
    jScrollPane4.getHorizontalScrollBar().setUnitIncrement(40);
    // this.jScrollPane4.removeAll();
    // this.jScrollPane4.setViewportView(jPanel1);
    // revalidate();
    // jScrollPane3.setBounds(420, 0, 170, 300);
    // jScrollPane4.setBounds(20, 35, 335, 220);
    resizePanels(getParent().getWidth(), getParent().getHeight());
}

From source file:edu.ku.brc.specify.tasks.subpane.security.SecurityAdminPane.java

/**
 * //from   w  w  w.j  a  v a2 s  .  com
 */
private void createNavigationTree() {
    TreeSelectionListener tsl = new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent tse) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

            if (node == null || !(node.getUserObject() instanceof DataModelObjBaseWrapper)) {
                // Nothing is selected or object type isn't relevant
                clearPanels();
                return;
            }

            // ask if user he wants to discard changes if that's the case
            if (!aboutToShutdown()) {
                clearPanels();
                return;
            }

            DataModelObjBaseWrapper dataWrp = (DataModelObjBaseWrapper) (node.getUserObject());

            // get parent if it is a user
            /*DataModelObjBaseWrapper userObjWrp    = null;
            DataModelObjBaseWrapper groupObjWrp   = null;
            DataModelObjBaseWrapper collectionWrp = null;
            Object                  dataObj     = dataWrp.getDataObj();
            if (dataObj instanceof SpecifyUser)
            {
            // XXX Also might need to check to see if anyone is logged into the Group
            // when editing a Group
            SpecifyUser currentUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class);
            SpecifyUser spUser      = (SpecifyUser)dataObj;
                    
            if (!spUser.getIsLoggedIn() || currentUser.getId().equals(spUser.getId()))
            {
                DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
                userObjWrp    = (DataModelObjBaseWrapper) node.getUserObject();
                groupObjWrp   = (DataModelObjBaseWrapper) parent.getUserObject();
                collectionWrp = (DataModelObjBaseWrapper) ((DefaultMutableTreeNode)parent.getParent()).getUserObject();
                        
            } else
            {
                UIRegistry.showLocalizedError("SecuirytAdminPane.USR_IS_ON", spUser.getName());
                        
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run()
                    {
                        tree.clearSelection();
                    }
                });
                return;
            }
            }
                    
            nodesDiscipline = navTreeMgr.getParentOfClass(node, Discipline.class);
            nodesDivision   = nodesDiscipline != null ? nodesDiscipline.getDivision() : null;
            showInfoPanel(dataWrp, userObjWrp, groupObjWrp, collectionWrp, node.toString());
            updateUIEnabled(dataWrp);*/

            // get parent if it is a user
            DataModelObjBaseWrapper secondObjWrp = null;
            DataModelObjBaseWrapper collectionWrp = null;
            Object dataObj = dataWrp.getDataObj();
            if (dataObj instanceof SpecifyUser) {
                // XXX Also might need to check to see if anyone is logged into the Group
                // when editing a Group
                SpecifyUser currentUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class);
                SpecifyUser spUser = (SpecifyUser) dataObj;

                if (!spUser.getIsLoggedIn() || currentUser.getId().equals(spUser.getId())) {
                    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
                    secondObjWrp = (DataModelObjBaseWrapper) parent.getUserObject();
                    collectionWrp = (DataModelObjBaseWrapper) ((DefaultMutableTreeNode) parent.getParent())
                            .getUserObject();
                } else {
                    UIRegistry.showLocalizedError("SecuirytAdminPane.USR_IS_ON", spUser.getName());

                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            tree.clearSelection();
                        }
                    });
                    return;
                }
            }

            nodesDiscipline = navTreeMgr.getParentOfClass(node, Discipline.class);
            nodesDivision = nodesDiscipline != null ? nodesDiscipline.getDivision() : null;
            showInfoPanel(dataWrp, secondObjWrp, collectionWrp, node.toString());
            updateUIEnabled(dataWrp);
        }
    };

    DefaultTreeModel model = createNavigationTreeModel();
    tree = new JTree(model);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setRootVisible(false);
    tree.setCellRenderer(new MyTreeCellRenderer());
    tree.addTreeSelectionListener(tsl);

    // Expand the tree
    for (int i = 0; i < tree.getRowCount(); i++) {
        tree.expandRow(i);
    }

    for (int i = tree.getRowCount() - 1; i >= 1; i--) {
        if (tree.getPathForRow(i).getPathCount() > 3) {
            tree.collapseRow(i);
        }
    }

    navTreeMgr = new NavigationTreeMgr(tree, spUsers);

    // create object that will control the creation of popups
    // constructor will take care of hooking up right listeners to the tree.
    navTreeContextMgr = new NavigationTreeContextMenuMgr(navTreeMgr);

    IconManager.IconSize iconSize = IconManager.IconSize.Std20;
    ImageIcon sysIcon = IconManager.getIcon("SystemSetup", iconSize);
    JLabel label = createLabel("XXXX");

    label.setIcon(sysIcon);
    label.setBorder(BorderFactory.createEmptyBorder(1, 0, 0, 0));

    tree.setRowHeight(label.getPreferredSize().height);

    // Why doesn't this work?
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            tree.expandRow(1);
        }
    });

    //expandAll(tree, true);
}

From source file:edu.harvard.i2b2.query.ui.TopPanel.java

public void addPanel() {
    int rightmostPosition = dataModel.lastLabelPosition();
    JLabel label = new JLabel();
    label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    label.setText("and");
    label.setToolTipText("Click to change the relationship");
    label.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    label.addMouseListener(new java.awt.event.MouseAdapter() {
        @Override//from   ww  w. ja  v a  2  s . c  o m
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            jAndOrLabelMouseClicked(evt);
        }
    });

    // jPanel1.add(label);
    // label.setBounds(rightmostPosition, 90, 30, 18);

    ConceptTreePanel panel = new ConceptTreePanel("Group " + (dataModel.getCurrentPanelCount() + 1), this);
    jPanel1.add(panel);
    panel.setBounds(rightmostPosition + 5, 0, 180, getParent().getHeight() - 100);
    jPanel1.setPreferredSize(new Dimension(rightmostPosition + 5 + 181 + 60, getHeight() - 100));
    jScrollPane4.setViewportView(jPanel1);

    dataModel.addPanel(panel, label, rightmostPosition + 5 + 180);

    jScrollPane4.getHorizontalScrollBar().setValue(jScrollPane4.getHorizontalScrollBar().getMaximum());
    jScrollPane4.getHorizontalScrollBar().setUnitIncrement(40);
    resizePanels(getParent().getWidth(), getParent().getHeight());
}

From source file:edu.harvard.i2b2.query.ui.TopPanel.java

private void jMorePanelsButtonActionPerformed(java.awt.event.ActionEvent evt) {
    if (dataModel.hasEmptyPanels()) {
        JOptionPane.showMessageDialog(this, "Please use an existing empty panel before adding a new one.");
        return;// w  w  w. j a  va 2 s. c om
    }
    int rightmostPosition = dataModel.lastLabelPosition();
    JLabel label = new JLabel();
    label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    label.setText("and");
    label.setToolTipText("Click to change the relationship");
    label.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    label.addMouseListener(new java.awt.event.MouseAdapter() {
        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            jAndOrLabelMouseClicked(evt);
        }
    });

    ConceptTreePanel panel = new ConceptTreePanel("Group " + (dataModel.getCurrentPanelCount() + 1), this);
    jPanel1.add(panel);
    panel.setBounds(rightmostPosition + 5, 0, 180, getParent().getHeight() - 100);
    jPanel1.setPreferredSize(new Dimension(rightmostPosition + 5 + 181 + 60, getHeight() - 100));
    jScrollPane4.setViewportView(jPanel1);

    dataModel.addPanel(panel, label, rightmostPosition + 5 + 180);

    /*
     * System.out.println(jScrollPane4.getViewport().getExtentSize().width+":"
     * + jScrollPane4.getViewport().getExtentSize().height);
     * System.out.println
     * (jScrollPane4.getHorizontalScrollBar().getVisibleRect().width+":"
     * +jScrollPane4.getHorizontalScrollBar().getVisibleRect().height);
     * System
     * .out.println(jScrollPane4.getHorizontalScrollBar().getVisibleAmount
     * ());
     * System.out.println(jScrollPane4.getHorizontalScrollBar().getValue());
     */
    jScrollPane4.getHorizontalScrollBar().setValue(jScrollPane4.getHorizontalScrollBar().getMaximum());
    jScrollPane4.getHorizontalScrollBar().setUnitIncrement(40);
    // this.jScrollPane4.removeAll();
    // this.jScrollPane4.setViewportView(jPanel1);
    // revalidate();
    // jScrollPane3.setBounds(420, 0, 170, 300);
    // jScrollPane4.setBounds(20, 35, 335, 220);
    resizePanels(getParent().getWidth(), getParent().getHeight());
}

From source file:jchrest.gui.Shell.java

public Shell(Chrest model) {
    super("jCHREST");
    this._model = model;

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    createMenuBar(0);//  w w w  . j  a  v  a 2  s  .  c  o  m

    JLabel startupInfo = new JLabel(
            "<html>Load data by clicking on the 'Data' toolbar option.  Two types of data<br>"
                    + "can be loaded:" + "<ul>"
                    + " <li>Pre-experiment data: trains CHREST before undertaking an experiment.</li>"
                    + " <li>Experiment data: loads an experiment for CHREST to undertake.</li>" + "</ul>"
                    + "Note that only one set of experiment data can be used with CHREST at any<br>"
                    + "time whereas multiple pre-experiment data files can be used.<br>" + "<br>"
                    + "To reset CHREST and undertake a different experiment, select 'Model' then<br>"
                    + "'Clear' from the toolbar.  Clearing CHREST will remove any pre-experiment<br>"
                    + "data learned too." + "</html>");

    startupInfo.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
    setContentPane(startupInfo);

    setSize(800, 600);
    setLocationRelativeTo(null);
    setTheme("Nimbus");

    //_model.setNotLoadedIntoExperiment();
    //_model.setNotEngagedInExperiment();

    _model.addObserver(this);
}

From source file:com.diversityarrays.kdxplore.KDXploreFrame.java

private void initialiseKdxApps() throws IOException {

    String[] classNames = KdxploreConfig.getInstance().getMainPluginClassNames();
    if (classNames != null && classNames.length > 0) {
        List<String> classNamesToLoad = new ArrayList<>();
        Collections.addAll(classNamesToLoad, classNames);
        if (!classNamesToLoad.contains(OFFLINE_DATA_APP_SERVICE_CLASS_NAME)) {
            classNamesToLoad.add(0, OFFLINE_DATA_APP_SERVICE_CLASS_NAME);
            classNames = classNamesToLoad.toArray(new String[classNamesToLoad.size()]);
        }//from  w  ww.jav  a2 s. c  om
    }

    Map<KdxApp, Component> componentByApp = collectKdxApps(classNames);

    appByComponent.clear();
    for (KdxApp app : componentByApp.keySet()) {
        Component comp = componentByApp.get(app);
        if (comp != null) {
            appByComponent.put(comp, app);
        }
    }

    allKdxApps.clear();
    allKdxApps.addAll(componentByApp.keySet());

    // Initialise the apps in initialisation order.
    allKdxApps.sort(Comparator.comparing(KdxApp::getInitialisationOrder));

    // And while we're initialising them we collect
    // those that can perform a databaseBackup (i.e. have a BackupProvider).
    backupProviders.clear();
    List<KdxApp> wantedAppsWithUi = new ArrayList<>();

    for (KdxApp app : allKdxApps) {
        BackupProvider bp = app.getBackupProvider();
        if (bp != null) {
            backupProviders.add(bp);
        }

        /**
         * See {@link com.diversityarrays.kdxplore.prefs.KdxplorePreferences#SHOW_ALL_APPS}
         */
        if (appIsWanted(app)) {
            try {
                app.initialiseAppBeforeUpdateCheck(appInitContext);
            } catch (Exception e) {
                String msg = Msg.MSG_KDXAPP_INIT_PROBLEM(app.getAppName());
                Shared.Log.w(TAG, msg, e);
                messagesPanel.println(msg);
                messagesPanel.println(e.getMessage());
            }
        }

        if (appIsWanted(app) && null != componentByApp.get(app)) {
            wantedAppsWithUi.add(app);
        }
    }

    // - - - - - - - - - - - - - - - - - - - - -
    // Display the apps in display order.
    wantedAppsWithUi.sort(Comparator.comparing(KdxApp::getDisplayOrder));
    backupProviders.sort(Comparator.comparing(BackupProvider::getDisplayOrder));

    switch (wantedAppsWithUi.size()) {
    case 0:
        JLabel label = new JLabel(Msg.MSG_NO_KDXPLORE_APPS_AVAILABLE());
        label.setHorizontalAlignment(JLabel.CENTER);
        cardPanel.add(label, CARD_KDXAPPS);
        break;
    case 1:
        KdxApp kdxApp = wantedAppsWithUi.get(0);
        Component uiComponent = componentByApp.get(kdxApp);

        Component appComponent = makeComponentForTab(kdxApp, uiComponent);
        cardPanel.add(appComponent, CARD_KDXAPPS);

        getRootPane().setDefaultButton(kdxApp.getDefaultButton());

        String msg = Msg.MSG_SHOWING_KDXAPP(kdxApp.getAppName());
        messagesPanel.println(msg);
        System.err.println(msg + " uiClass=" //$NON-NLS-1$
                + uiComponent.getClass().getName());
        break;
    default:
        kdxAppTabs = new JTabbedPane(JTabbedPane.LEFT);
        cardPanel.add(kdxAppTabs, CARD_KDXAPPS);
        Bag<String> tabsSeen = new HashBag<>();
        for (KdxApp app : wantedAppsWithUi) {
            Component ui = componentByApp.get(app);

            String tabName = app.getAppName();
            DevelopmentState devState = app.getDevelopmentState();
            switch (devState) {
            case ALPHA:
                tabName = tabName + " (\u03b1)"; // TODO move to UnicodeChars
                break;
            case BETA:
                tabName = tabName + " (\u03b2)"; // TODO move to UnicodeChars
                break;
            case PRODUCTION:
                break;
            default:
                tabName = tabName + " " + devState.name();
                break;
            }
            tabsSeen.add(tabName);
            int count = tabsSeen.getCount(tabName);
            if (count > 1) {
                tabName = tabName + "_" + count; //$NON-NLS-1$
            }

            Component tabComponent = makeComponentForTab(app, ui);
            kdxAppTabs.addTab(tabName, tabComponent);
            if (macapp == null) {
                int index = kdxAppTabs.indexOfTab(tabName);
                if (index >= 0) {
                    JLabel tabLabel = new JLabel(tabName);
                    tabLabel.setBorder(new EmptyBorder(2, 2, 2, 2));
                    tabLabel.setUI(new VerticalLabelUI(VerticalLabelUI.UPWARDS));
                    kdxAppTabs.setTabComponentAt(index, tabLabel);
                }
            }
            messagesPanel.println(Msg.MSG_SHOWING_KDXAPP(tabName));
        }

        kdxAppTabs.addChangeListener(kdxAppTabsChangeListener);
        kdxAppTabs.setSelectedIndex(0);
        break;
    }
}

From source file:com.dragoniade.deviantart.ui.PreferencesDialog.java

public PreferencesDialog(final DownloaderGUI owner, Properties config) {
    super(owner, "Preferences", true);

    HttpClientParams params = new HttpClientParams();
    params.setVersion(HttpVersion.HTTP_1_1);
    params.setSoTimeout(30000);//from www  .  ja v a  2  s . c  om
    client = new HttpClient(params);
    setProxy(ProxyCfg.parseConfig(config));

    sample = new Deviation();
    sample.setId(15972367L);
    sample.setTitle("Fella Promo");
    sample.setArtist("devart");
    sample.setImageDownloadUrl(DOWNLOAD_URL);
    sample.setImageFilename(Deviation.extractFilename(DOWNLOAD_URL));
    sample.setCollection(new Collection(1L, "MyCollect"));
    setLayout(new BorderLayout());
    panes = new JTabbedPane(JTabbedPane.TOP);

    JPanel genPanel = new JPanel();
    BoxLayout genLayout = new BoxLayout(genPanel, BoxLayout.Y_AXIS);
    genPanel.setLayout(genLayout);
    panes.add("General", genPanel);

    JLabel userLabel = new JLabel("Username");

    userLabel.setToolTipText("The username the account you want to download the favorites from.");

    userField = new JTextField(config.getProperty(Constants.USERNAME));

    userLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    userLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    userField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    userField.setMaximumSize(new Dimension(Integer.MAX_VALUE, userField.getFont().getSize() * 2));

    genPanel.add(userLabel);
    genPanel.add(userField);

    JPanel radioPanel = new JPanel();
    BoxLayout radioLayout = new BoxLayout(radioPanel, BoxLayout.X_AXIS);
    radioPanel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    radioPanel.setBorder(new EmptyBorder(0, 5, 0, 5));

    radioPanel.setLayout(radioLayout);

    JLabel searchLabel = new JLabel("Search for");
    searchLabel
            .setToolTipText("Select what you want to download from that user: it favorites or it galleries.");
    searchLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searchLabel.setBorder(new EmptyBorder(0, 5, 0, 5));

    selectedSearch = SEARCH.lookup(config.getProperty(Constants.SEARCH, SEARCH.getDefault().getId()));
    buttonGroup = new ButtonGroup();

    for (final SEARCH search : SEARCH.values()) {
        JRadioButton radio = new JRadioButton(search.getLabel());
        radio.setAlignmentX(JLabel.LEFT_ALIGNMENT);
        radio.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                selectedSearch = search;
            }
        });

        buttonGroup.add(radio);
        radioPanel.add(radio);
        if (search.equals(selectedSearch)) {
            radio.setSelected(true);
        }
    }

    genPanel.add(radioPanel);

    final JTextField sampleField = new JTextField("");
    sampleField.setEditable(false);

    JLabel locationLabel = new JLabel("Download location");
    locationLabel.setToolTipText("The folder pattern where you want the file to be downloaded in.");

    JLabel legendsLabel = new JLabel(
            "<html><body>Field names: %user%, %artist%, %title%, %id%, %filename%, %collection%, %ext%<br></br>Example:</body></html>");
    legendsLabel.setToolTipText("An example of where a file will be downloaded to.");

    locationString = new StringBuilder();
    locationField = new JTextField(config.getProperty(Constants.LOCATION));
    locationField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

        }

        public void keyReleased(KeyEvent e) {
            File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample,
                    sample.getImageFilename());
            locationString.setLength(0);
            locationString.append(dest.getAbsolutePath());
            sampleField.setText(locationString.toString());
            if (useSameForMatureBox.isSelected()) {
                locationMatureString.setLength(0);
                locationMatureString.append(sampleField.getText());
                locationMatureField.setText(locationField.getText());
            }
        }

        public void keyTyped(KeyEvent e) {
        }

    });
    locationField.addMouseListener(new MouseListener() {
        public void mouseReleased(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseEntered(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseClicked(MouseEvent e) {
        }
    });
    JLabel locationMatureLabel = new JLabel("Mature download location");
    locationMatureLabel.setToolTipText(
            "The folder pattern where you want the file marked as 'Mature' to be downloaded in.");

    locationMatureString = new StringBuilder();
    locationMatureField = new JTextField(config.getProperty(Constants.MATURE));
    locationMatureField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

        }

        public void keyReleased(KeyEvent e) {
            File dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample,
                    sample.getImageFilename());
            locationMatureString.setLength(0);
            locationMatureString.append(dest.getAbsolutePath());
            sampleField.setText(locationMatureString.toString());
        }

        public void keyTyped(KeyEvent e) {
        }

    });

    locationMatureField.addMouseListener(new MouseListener() {
        public void mouseReleased(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseEntered(MouseEvent e) {
            sampleField.setText(locationMatureString.toString());
        }

        public void mouseClicked(MouseEvent e) {
        }
    });

    useSameForMatureBox = new JCheckBox("Use same location for mature deviation?");
    useSameForMatureBox.setSelected(locationLabel.getText().equals(locationMatureField.getText()));
    useSameForMatureBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (useSameForMatureBox.isSelected()) {
                locationMatureField.setEditable(false);
                locationMatureField.setText(locationField.getText());
                locationMatureString.setLength(0);
                locationMatureString.append(locationString);
            } else {
                locationMatureField.setEditable(true);
            }

        }
    });

    File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample,
            sample.getImageFilename());
    sampleField.setText(dest.getAbsolutePath());
    locationString.append(sampleField.getText());

    dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample,
            sample.getImageFilename());
    locationMatureString.append(dest.getAbsolutePath());

    locationLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    locationField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationField.setMaximumSize(new Dimension(Integer.MAX_VALUE, locationField.getFont().getSize() * 2));
    locationMatureLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationMatureLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    locationMatureField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationMatureField
            .setMaximumSize(new Dimension(Integer.MAX_VALUE, locationMatureField.getFont().getSize() * 2));
    useSameForMatureBox.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    legendsLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    legendsLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    legendsLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, legendsLabel.getFont().getSize() * 2));
    sampleField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    sampleField.setMaximumSize(new Dimension(Integer.MAX_VALUE, sampleField.getFont().getSize() * 2));

    genPanel.add(locationLabel);
    genPanel.add(locationField);

    genPanel.add(locationMatureLabel);
    genPanel.add(locationMatureField);
    genPanel.add(useSameForMatureBox);

    genPanel.add(legendsLabel);
    genPanel.add(sampleField);
    genPanel.add(Box.createVerticalBox());

    final KeyListener prxChangeListener = new KeyListener() {

        public void keyTyped(KeyEvent e) {
            proxyChangeState = true;
        }

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
        }
    };

    JPanel prxPanel = new JPanel();
    BoxLayout prxLayout = new BoxLayout(prxPanel, BoxLayout.Y_AXIS);
    prxPanel.setLayout(prxLayout);
    panes.add("Proxy", prxPanel);

    JLabel prxHostLabel = new JLabel("Proxy Host");
    prxHostLabel.setToolTipText("The hostname of the proxy server");
    prxHostField = new JTextField(config.getProperty(Constants.PROXY_HOST));
    prxHostLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxHostLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxHostField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxHostField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxHostField.getFont().getSize() * 2));

    JLabel prxPortLabel = new JLabel("Proxy Port");
    prxPortLabel.setToolTipText("The port of the proxy server (Default 80).");

    prxPortSpinner = new JSpinner();
    prxPortSpinner.setModel(new SpinnerNumberModel(
            Integer.parseInt(config.getProperty(Constants.PROXY_PORT, "80")), 1, 65535, 1));

    prxPortLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPortLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxPortSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPortSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPortSpinner.getFont().getSize() * 2));

    JLabel prxUserLabel = new JLabel("Proxy username");
    prxUserLabel.setToolTipText("The username used for authentication, if applicable.");
    prxUserField = new JTextField(config.getProperty(Constants.PROXY_USERNAME));
    prxUserLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxUserLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxUserField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxUserField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxUserField.getFont().getSize() * 2));

    JLabel prxPassLabel = new JLabel("Proxy username");
    prxPassLabel.setToolTipText("The username used for authentication, if applicable.");
    prxPassField = new JPasswordField(config.getProperty(Constants.PROXY_PASSWORD));
    prxPassLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPassLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxPassField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPassField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPassField.getFont().getSize() * 2));

    prxUseBox = new JCheckBox("Use a proxy?");
    prxUseBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            prxChangeListener.keyTyped(null);

            if (prxUseBox.isSelected()) {
                prxHostField.setEditable(true);
                prxPortSpinner.setEnabled(true);
                prxUserField.setEditable(true);
                prxPassField.setEditable(true);

            } else {
                prxHostField.setEditable(false);
                prxPortSpinner.setEnabled(false);
                prxUserField.setEditable(false);
                prxPassField.setEditable(false);
            }
        }
    });

    prxUseBox.setSelected(!Boolean.parseBoolean(config.getProperty(Constants.PROXY_USE)));
    prxUseBox.doClick();
    proxyChangeState = false;

    prxHostField.addKeyListener(prxChangeListener);
    prxUserField.addKeyListener(prxChangeListener);
    prxPassField.addKeyListener(prxChangeListener);
    prxPortSpinner.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            proxyChangeState = true;
        }
    });
    prxPanel.add(prxUseBox);

    prxPanel.add(prxHostLabel);
    prxPanel.add(prxHostField);

    prxPanel.add(prxPortLabel);
    prxPanel.add(prxPortSpinner);

    prxPanel.add(prxUserLabel);
    prxPanel.add(prxUserField);

    prxPanel.add(prxPassLabel);
    prxPanel.add(prxPassField);
    prxPanel.add(Box.createVerticalBox());

    final JPanel advPanel = new JPanel();
    BoxLayout advLayout = new BoxLayout(advPanel, BoxLayout.Y_AXIS);
    advPanel.setLayout(advLayout);
    panes.add("Advanced", advPanel);
    panes.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            JTabbedPane pane = (JTabbedPane) e.getSource();

            if (proxyChangeState && pane.getSelectedComponent() == advPanel) {
                Properties properties = new Properties();
                properties.setProperty(Constants.PROXY_USERNAME, prxUserField.getText().trim());
                properties.setProperty(Constants.PROXY_PASSWORD, new String(prxPassField.getPassword()).trim());
                properties.setProperty(Constants.PROXY_HOST, prxHostField.getText().trim());
                properties.setProperty(Constants.PROXY_PORT, prxPortSpinner.getValue().toString());
                properties.setProperty(Constants.PROXY_USE, Boolean.toString(prxUseBox.isSelected()));
                ProxyCfg prx = ProxyCfg.parseConfig(properties);
                setProxy(prx);
                revalidateSearcher(null);
            }
        }
    });
    JLabel domainLabel = new JLabel("Deviant Art domain name");
    domainLabel.setToolTipText("The deviantART main domain, should it ever change.");

    domainField = new JTextField(config.getProperty(Constants.DOMAIN));
    domainLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    domainLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    domainField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    domainField.setMaximumSize(new Dimension(Integer.MAX_VALUE, domainField.getFont().getSize() * 2));

    advPanel.add(domainLabel);
    advPanel.add(domainField);

    JLabel throttleLabel = new JLabel("Throttle search delay");
    throttleLabel.setToolTipText(
            "Slow down search query by inserting a pause between them. This help prevent abuse when doing a massive download.");

    throttleSpinner = new JSpinner();
    throttleSpinner.setModel(
            new SpinnerNumberModel(Integer.parseInt(config.getProperty(Constants.THROTTLE, "0")), 5, 60, 1));

    throttleLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    throttleLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    throttleSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    throttleSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, throttleSpinner.getFont().getSize() * 2));

    advPanel.add(throttleLabel);
    advPanel.add(throttleSpinner);

    JLabel searcherLabel = new JLabel("Searcher");
    searcherLabel.setToolTipText("Select a searcher that will look for your favorites.");

    searcherBox = new JComboBox();
    searcherBox.setRenderer(new TogglingRenderer());

    final AtomicInteger index = new AtomicInteger(0);
    searcherBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox combo = (JComboBox) e.getSource();
            Object selectedItem = combo.getSelectedItem();
            if (selectedItem instanceof SearchItem) {
                SearchItem item = (SearchItem) selectedItem;
                if (item.isValid) {
                    index.set(combo.getSelectedIndex());
                } else {
                    combo.setSelectedIndex(index.get());
                }
            }
        }
    });

    try {
        for (Class<Search> clazz : SearcherClassCache.getInstance().getClasses()) {

            Search searcher = clazz.newInstance();
            String name = searcher.getName();

            SearchItem item = new SearchItem(name, clazz.getName(), true);
            searcherBox.addItem(item);
        }
        String selectedClazz = config.getProperty(Constants.SEARCHER,
                com.dragoniade.deviantart.deviation.SearchRss.class.getName());
        revalidateSearcher(selectedClazz);
    } catch (Exception e1) {
        throw new RuntimeException(e1);
    }

    searcherLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searcherLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    searcherBox.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searcherBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, searcherBox.getFont().getSize() * 2));

    advPanel.add(searcherLabel);
    advPanel.add(searcherBox);

    advPanel.add(Box.createVerticalBox());

    add(panes, BorderLayout.CENTER);

    JButton saveBut = new JButton("Save");

    userField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            if (field.getText().trim().length() == 0) {
                JOptionPane.showMessageDialog(input, "The user musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    locationField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String content = field.getText().trim();
            if (content.length() == 0) {
                JOptionPane.showMessageDialog(input, "The location musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (!content.contains("%filename%") && !content.contains("%id%")) {
                JOptionPane.showMessageDialog(input,
                        "The location must contains at least a %filename% or an %id% field.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    locationMatureField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String content = field.getText().trim();
            if (content.length() == 0) {
                JOptionPane.showMessageDialog(input, "The Mature location musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (!content.contains("%filename%") && !content.contains("%id%")) {
                JOptionPane.showMessageDialog(input,
                        "The Mature location must contains at least a %username% or an %id% field.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    domainField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String domain = field.getText().trim();
            if (domain.length() == 0) {
                JOptionPane.showMessageDialog(input, "You must specify the deviantART main domain.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (domain.toLowerCase().startsWith("http://")) {
                JOptionPane.showMessageDialog(input,
                        "You must specify the deviantART main domain, not the full URL (aka www.deviantart.com).",
                        "Warning", JOptionPane.WARNING_MESSAGE);
                return false;
            }

            return true;
        }
    });
    locationField.setVerifyInputWhenFocusTarget(true);

    final JDialog parent = this;
    saveBut.addActionListener(new ActionListener() {

        String errorMsg = "The location is invalid or cannot be written to.";

        public void actionPerformed(ActionEvent e) {

            String username = userField.getText().trim();
            String location = locationField.getText().trim();
            String locationMature = locationMatureField.getText().trim();
            String domain = domainField.getText().trim();
            String throttle = throttleSpinner.getValue().toString();
            String searcher = searcherBox.getSelectedItem().toString();

            String prxUse = Boolean.toString(prxUseBox.isSelected());
            String prxHost = prxHostField.getText().trim();
            String prxPort = prxPortSpinner.getValue().toString();
            String prxUsername = prxUserField.getText().trim();
            String prxPassword = new String(prxPassField.getPassword()).trim();

            if (!testPath(location, username)) {
                JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE);
            }
            if (!testPath(locationMature, username)) {
                JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE);
            }

            Properties p = new Properties();
            p.setProperty(Constants.USERNAME, username);
            p.setProperty(Constants.LOCATION, location);
            p.setProperty(Constants.MATURE, locationMature);
            p.setProperty(Constants.DOMAIN, domain);
            p.setProperty(Constants.THROTTLE, throttle);
            p.setProperty(Constants.SEARCHER, searcher);
            p.setProperty(Constants.SEARCH, selectedSearch.getId());

            p.setProperty(Constants.PROXY_USE, prxUse);
            p.setProperty(Constants.PROXY_HOST, prxHost);
            p.setProperty(Constants.PROXY_PORT, prxPort);
            p.setProperty(Constants.PROXY_USERNAME, prxUsername);
            p.setProperty(Constants.PROXY_PASSWORD, prxPassword);

            owner.savePreferences(p);
            parent.dispose();
        }
    });

    JButton cancelBut = new JButton("Cancel");
    cancelBut.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            parent.dispose();
        }
    });

    JPanel buttonPanel = new JPanel();
    BoxLayout butLayout = new BoxLayout(buttonPanel, BoxLayout.X_AXIS);
    buttonPanel.setLayout(butLayout);

    buttonPanel.add(saveBut);
    buttonPanel.add(cancelBut);
    add(buttonPanel, BorderLayout.SOUTH);

    pack();
    setResizable(false);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2);
    setVisible(true);
}

From source file:edu.harvard.i2b2.query.ui.MainPanel.java

public void addPanel() {
    int rightmostPosition = dataModel.lastLabelPosition();
    JLabel label = new JLabel();
    label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    label.setText("and");
    label.setToolTipText("Click to change the relationship");
    label.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    label.addMouseListener(new java.awt.event.MouseAdapter() {
        @Override/*from ww  w.  ja  v  a  2  s.  c o m*/
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            jAndOrLabelMouseClicked(evt);
        }
    });

    // jPanel1.add(label);
    // label.setBounds(rightmostPosition, 90, 30, 18);

    GroupPanel panel = new GroupPanel("Group " + (dataModel.getCurrentPanelCount() + 1), this);
    jPanel1.add(panel);
    panel.setBounds(rightmostPosition + 5, 0, 180, getParent().getHeight() - 100);
    jPanel1.setPreferredSize(new Dimension(rightmostPosition + 5 + 181 + 60, getHeight() - 100));
    jScrollPane4.setViewportView(jPanel1);

    dataModel.addPanel(panel, label, rightmostPosition + 5 + 180);

    jScrollPane4.getHorizontalScrollBar().setValue(jScrollPane4.getHorizontalScrollBar().getMaximum());
    jScrollPane4.getHorizontalScrollBar().setUnitIncrement(40);
    resizePanels(getParent().getWidth(), getParent().getHeight());
}