Example usage for javax.swing JLabel addMouseListener

List of usage examples for javax.swing JLabel addMouseListener

Introduction

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

Prototype

public synchronized void addMouseListener(MouseListener l) 

Source Link

Document

Adds the specified mouse listener to receive mouse events from this component.

Usage

From source file:com.projity.pm.graphic.frames.GraphicManager.java

public void setRibbon(JRibbonFrame frame, MenuManager menuManger) {

    final JPanel filtersPanel = new JPanel(new GridLayout(3, 1));
    filterToolBarManager = FilterToolBarManager.create(getMenuManager());
    filterToolBarManager.addButtonsInRibbonBand(filtersPanel);

    CustomRibbonBandGenerator customBandsGenerator = new CustomRibbonBandGenerator() {

        @Override/*from w  w  w.j a  v a 2 s .  c o m*/
        public JComponent createRibbonComponent(String ribbonBandName) {
            if ("FiltersRibbonBand".equals(ribbonBandName)) {
                return filtersPanel;
            } else
                return null;
        }
    };

    Collection<RibbonTask> ribbonTasks = menuManger.getRibbon(MenuManager.STANDARD_RIBBON,
            customBandsGenerator);
    JRibbon ribbon = frame.getRibbon();

    for (RibbonTask ribbonTask : ribbonTasks) {
        ribbon.addTask(ribbonTask);
    }

    RibbonApplicationMenu applicationMenu = new RibbonApplicationMenu();

    ribbon.setApplicationMenu(applicationMenu);

    Collection<AbstractCommandButton> taskBars = menuManger.getTaskBar(MenuManager.STANDARD_RIBBON);
    for (AbstractCommandButton button : taskBars)
        ribbon.addTaskbarComponent(button);

    ribbon.configureHelp(IconManager.getRibbonIcon("ribbon.help", 26, 26), new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            showHelpDialog();

        }
    });

    JLabel openprojLogo = ribbon.getOpenprojLogo();
    openprojLogo.setIcon(IconManager.getIcon("logo.OpenProj"));
    openprojLogo.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent me) {
            BrowserControl.displayURL("http://www.projity.com/");
        }
    });

    JPanel projectViews = ribbon.getProjectViews();
    projectViews.setBorder(new EmptyBorder(0, 0, 0, 0));
    getMenuManager().initComponent(MenuManager.RIBBON_VIEW_BAR, projectViews);

    JPanel fileSelector = ribbon.getFileSelector();
    fileSelector.setLayout(new BorderLayout());
    fileSelector.setBackground(ProjectLibreRibbonUI.RIBBON_MENU_COLOR);
    JComponent filesComponent = ((DefaultFrameManager) getFrameManager()).getProjectComboPanel();
    filesComponent.setBackground(ProjectLibreRibbonUI.RIBBON_MENU_COLOR);
    fileSelector.add(filesComponent, BorderLayout.EAST);
    projectViews.setBorder(new EmptyBorder(0, 0, 0, 0));

}

From source file:edu.ku.brc.specify.Specify.java

/**
 * Shows the About dialog./*  w w w  .  java  2 s  .  c  o m*/
 */
public void doAbout() {
    AppContextMgr acm = AppContextMgr.getInstance();
    boolean showDetailedAbout = acm.hasContext() && acm.getClassObject(Division.class) != null
            && acm.getClassObject(Discipline.class) != null && acm.getClassObject(Collection.class) != null;

    int baseNumRows = 14;
    String serverName = AppPreferences.getLocalPrefs().get("login.servers_selected", null);
    if (serverName != null) {
        baseNumRows++;
    }

    CellConstraints cc = new CellConstraints();
    PanelBuilder infoPB = new PanelBuilder(new FormLayout("p,6px,f:p:g",
            "p,4px,p,4px," + UIHelper.createDuplicateJGoodiesDef("p", "2px", baseNumRows)));

    JLabel iconLabel = new JLabel(IconManager.getIcon("SpecifyLargeIcon"), SwingConstants.CENTER); //$NON-NLS-1$
    PanelBuilder iconPB = new PanelBuilder(new FormLayout("p", "20px,t:p,f:p:g"));
    iconPB.add(iconLabel, cc.xy(1, 2));

    if (showDetailedAbout) {
        final ArrayList<String> values = new ArrayList<String>();

        DBTableIdMgr tableMgr = DBTableIdMgr.getInstance();
        boolean hasReged = !RegisterSpecify.isAnonymous() && RegisterSpecify.hasInstitutionRegistered();

        int y = 1;
        infoPB.addSeparator(getResourceString("Specify.SYS_INFO"), cc.xyw(1, y, 3));
        y += 2;

        JLabel lbl = UIHelper.createLabel(databaseName);
        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.DB"), cc.xy(1, y));
        addLabel(values, infoPB, lbl, cc.xy(3, y));
        y += 2;
        lbl.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    openLocalPrefs();
                }
            }
        });

        int instId = Institution.getClassTableId();
        addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(instId)), cc.xy(1, y));
        addLabel(values, infoPB, lbl = UIHelper.createLabel(acm.getClassObject(Institution.class).getName()),
                cc.xy(3, y));
        y += 2;

        addLabel(values, infoPB, UIHelper.createFormLabel(getGUIDTitle(instId)), cc.xy(1, y));

        String noGUID = "<No GUID>";
        String guidStr = acm.getClassObject(Institution.class).getGuid();
        addLabel(values, infoPB, lbl = UIHelper.createLabel(guidStr != null ? guidStr : noGUID), cc.xy(3, y));
        y += 2;

        lbl.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    openRemotePrefs();
                }
            }
        });
        addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(Division.getClassTableId())),
                cc.xy(1, y));
        addLabel(values, infoPB, lbl = UIHelper.createLabel(acm.getClassObject(Division.class).getName()),
                cc.xy(3, y));
        y += 2;
        lbl.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    openGlobalPrefs();
                }
            }
        });

        addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(Discipline.getClassTableId())),
                cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(acm.getClassObject(Discipline.class).getName()),
                cc.xy(3, y));
        y += 2;

        addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(Collection.getClassTableId())),
                cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(acm.getClassObject(Collection.class).getCollectionName()),
                cc.xy(3, y));
        y += 2;
        addLabel(values, infoPB, UIHelper.createFormLabel(getGUIDTitle(Collection.getClassTableId())),
                cc.xy(1, y));

        guidStr = acm.getClassObject(Collection.class).getGuid();
        addLabel(values, infoPB, UIHelper.createLabel(guidStr != null ? guidStr : noGUID), cc.xy(3, y));
        y += 2;
        //addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.BLD"), cc.xy(1, y));
        //addLabel(values, infoPB, UIHelper.createLabel(appBuildVersion),cc.xy(3, y)); y += 2;

        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.BLD"), cc.xy(1, y));
        UIRegistry.loadAndPushResourceBundle("bld");
        addLabel(values, infoPB, UIHelper.createLabel(getResourceString("build")), cc.xy(3, y));
        y += 2;

        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.BLD_TM"), cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(getResourceString("buildtime")), cc.xy(3, y));
        y += 2;
        UIRegistry.popResourceBundle();

        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.REG"), cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createI18NLabel(hasReged ? "Specify.HASREG" : "Specify.NOTREG"),
                cc.xy(3, y));
        y += 2;

        String isaNumber = RegisterSpecify.getISANumber();
        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.ISANUM"), cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(StringUtils.isNotEmpty(isaNumber) ? isaNumber : ""),
                cc.xy(3, y));
        y += 2;

        if (serverName != null) {
            addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.SERVER"), cc.xy(1, y));
            addLabel(values, infoPB, UIHelper.createLabel(StringUtils.isNotEmpty(serverName) ? serverName : ""),
                    cc.xy(3, y));
            y += 2;
        }

        if (StringUtils.contains(DBConnection.getInstance().getConnectionStr(), "mysql")) {
            Vector<Object[]> list = BasicSQLUtils.query("select version() as ve");
            if (list != null && list.size() > 0) {
                addLabel(values, infoPB, UIHelper.createFormLabel("MySQL Version"), cc.xy(1, y));
                addLabel(values, infoPB, UIHelper.createLabel(list.get(0)[0].toString()), cc.xy(3, y));
                y += 2;
            }
        }

        addLabel(values, infoPB, UIHelper.createFormLabel("Java Version"), cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(System.getProperty("java.version")), cc.xy(3, y));
        y += 2;

        JButton copyCBBtn = createIconBtn("ClipboardCopy", IconManager.IconSize.Std24, "Specify.CPY_ABT_TO_TT",
                null);
        //copyCBBtn.setBackground(Color.WHITE);
        //copyCBBtn.setOpaque(true);
        //copyCBBtn.setBorder(BorderFactory.createEtchedBorder());

        copyCBBtn.setEnabled(true);

        PanelBuilder cbPB = new PanelBuilder(new FormLayout("f:p:g,p", "p"));
        cbPB.add(copyCBBtn, cc.xy(2, 1));
        copyCBBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // Copy to Clipboard
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < values.size(); i++) {
                    sb.append(String.format("%s = %s\n", values.get(i), values.get(i + 1)));
                    i++;
                }
                UIHelper.setTextToClipboard(sb.toString());
                UIRegistry.displayInfoMsgDlgLocalized("Specify.CPY_ABT_TO_MSG");
            }
        });
        infoPB.add(cbPB.getPanel(), cc.xy(3, y));
        y += 2;
    }

    String txt = getAboutText(appName, appVersion);
    JLabel txtLbl = createLabel(txt);
    txtLbl.setFont(UIRegistry.getDefaultFont());

    final JEditorPane txtPane = new JEditorPane("text/html", txt);
    txtPane.setEditable(false);
    txtPane.setBackground(new JPanel().getBackground());

    PanelBuilder pb = new PanelBuilder(new FormLayout("p,20px,f:min(400px;p):g,10px,8px,10px,p:g", "f:p:g"));

    pb.add(iconPB.getPanel(), cc.xy(1, 1));
    pb.add(txtPane, cc.xy(3, 1));
    Color bg = getBackground();

    if (showDetailedAbout) {
        pb.add(new VerticalSeparator(bg.darker(), bg.brighter()), cc.xy(5, 1));
        pb.add(infoPB.getPanel(), cc.xy(7, 1));
    }

    pb.setDefaultDialogBorder();

    String title = getResourceString("Specify.ABOUT");//$NON-NLS-1$
    CustomDialog aboutDlg = new CustomDialog(topFrame, title + " " + appName, true, CustomDialog.OK_BTN, //$NON-NLS-1$
            pb.getPanel());
    String okLabel = getResourceString("Specify.CLOSE");//$NON-NLS-1$
    aboutDlg.setOkLabel(okLabel);

    aboutDlg.createUI();
    aboutDlg.pack();

    // for some strange reason I can't get the dialog to size itself correctly
    Dimension size = aboutDlg.getSize();
    size.height += 120;
    aboutDlg.setSize(size);

    txtPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    AttachmentUtils.openURI(event.getURL().toURI());

                } catch (Exception e) {
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                }
            }
        }
    });

    UIHelper.centerAndShow(aboutDlg);
}

From source file:Tcpbw100.java

public void testResults(String tmpstr) {
    StringTokenizer tokens;/*w w  w  . ja  v  a2s  .  c  o  m*/
    int i = 0;
    String sysvar, strval;
    int sysval, Zero = 0, bwdelay, minwin;
    double sysval2, j;
    String osName, osArch, osVer, javaVer, javaVendor, client;

    tokens = new StringTokenizer(tmpstr);
    sysvar = null;
    strval = null;
    while (tokens.hasMoreTokens()) {
        if (++i % 2 == 1) {
            sysvar = tokens.nextToken();
        } else {
            strval = tokens.nextToken();
            diagnosis.append(sysvar + " " + strval + "\n");
            //we load all the key value pairs to the report, too
            //may come in handy in the future
            //TODO: strip the trailing ':' from sysvar
            report.put("web100_" + sysvar.replaceAll(":$", ""), strval);
            emailText += sysvar + " " + strval + "\n%0A";
            if (strval.indexOf(".") == -1) {
                sysval = Integer.parseInt(strval);
                save_int_values(sysvar, sysval);
            } else {
                sysval2 = Double.valueOf(strval).doubleValue();
                save_dbl_values(sysvar, sysval2);
            }
        }
    }

    // Grab some client details from the applet environment
    osName = System.getProperty("os.name");
    pub_osName = osName;

    osArch = System.getProperty("os.arch");
    pub_osArch = osArch;

    osVer = System.getProperty("os.version");
    pub_osVer = osVer;

    javaVer = System.getProperty("java.version");
    pub_javaVer = javaVer;

    javaVendor = System.getProperty("java.vendor");

    if (osArch.startsWith("x86") == true) {
        client = messages.getString("pc");
    } else {
        client = messages.getString("workstation");
    }

    // Calculate some variables and determine path conditions
    // Note: calculations now done in server and the results are shipped
    //    back to the client for printing.

    if (CountRTT > 0) {
        // Now write some messages to the screen
        if (c2sData < 3) {
            if (c2sData < 0) {
                results.append(messages.getString("unableToDetectBottleneck") + "\n");
                emailText += "Server unable to determine bottleneck link type.\n%0A";
                pub_AccessTech = "Connection type unknown";

            } else {
                results.append(messages.getString("your") + " " + client + " "
                        + messages.getString("connectedTo") + " ");
                emailText += messages.getString("your") + " " + client + " " + messages.getString("connectedTo")
                        + " ";
                if (c2sData == 1) {
                    results.append(messages.getString("dialup") + "\n");
                    emailText += messages.getString("dialup") + "\n%0A";
                    mylink = .064;
                    pub_AccessTech = "Dial-up Modem";
                } else {
                    results.append(messages.getString("cabledsl") + "\n");
                    emailText += messages.getString("cabledsl") + "\n%0A";
                    mylink = 3;
                    pub_AccessTech = "Cable/DSL modem";
                }
            }
        } else {
            results.append(messages.getString("theSlowestLink") + " ");
            emailText += messages.getString("theSlowestLink") + " ";
            if (c2sData == 3) {
                results.append(messages.getString("10mbps") + "\n");
                emailText += messages.getString("10mbps") + "\n%0A";
                mylink = 10;
                pub_AccessTech = "10 Mbps Ethernet";
            } else if (c2sData == 4) {
                results.append(messages.getString("45mbps") + "\n");
                emailText += messages.getString("45mbps") + "\n%0A";
                mylink = 45;
                pub_AccessTech = "45 Mbps T3/DS3 subnet";
            } else if (c2sData == 5) {
                results.append("100 Mbps ");
                emailText += "100 Mbps ";
                mylink = 100;
                pub_AccessTech = "100 Mbps Ethernet";

                if (half_duplex == 0) {
                    results.append(messages.getString("fullDuplex") + "\n");
                    emailText += messages.getString("fullDuplex") + "\n%0A";
                } else {
                    results.append(messages.getString("halfDuplex") + "\n");
                    emailText += messages.getString("halfDuplex") + "\n%0A";
                }
            } else if (c2sData == 6) {
                results.append(messages.getString("622mbps") + "\n");
                emailText += messages.getString("622mbps") + "\n%0A";
                mylink = 622;
                pub_AccessTech = "622 Mbps OC-12";
            } else if (c2sData == 7) {
                results.append(messages.getString("1gbps") + "\n");
                emailText += messages.getString("1gbps") + "\n%0A";
                mylink = 1000;
                pub_AccessTech = "1.0 Gbps Gigabit Ethernet";
            } else if (c2sData == 8) {
                results.append(messages.getString("2.4gbps") + "\n");
                emailText += messages.getString("2.4gbps") + "\n%0A";
                mylink = 2400;
                pub_AccessTech = "2.4 Gbps OC-48";
            } else if (c2sData == 9) {
                results.append(messages.getString("10gbps") + "\n");
                emailText += messages.getString("10gbps") + "\n%0A";
                mylink = 10000;
                pub_AccessTech = "10 Gigabit Ethernet/OC-192";

            }
        }

        if (mismatch == 1) {
            results.append(messages.getString("oldDuplexMismatch") + "\n");
            emailText += messages.getString("oldDuplexMismatch") + "\n%0A";
        } else if (mismatch == 2) {
            results.append(messages.getString("duplexFullHalf") + "\n");
            emailText += messages.getString("duplexFullHalf") + "\n%0A";
        } else if (mismatch == 4) {
            results.append(messages.getString("possibleDuplexFullHalf") + "\n");
            emailText += messages.getString("possibleDuplexFullHalf") + "\n%0A";
        } else if (mismatch == 3) {
            results.append(messages.getString("duplexHalfFull") + "\n");
            emailText += messages.getString("duplexHalfFull") + "\n%0A";
        } else if (mismatch == 5) {
            results.append(messages.getString("possibleDuplexHalfFull") + "\n");
            emailText += messages.getString("possibleDuplexHalfFull") + "\n%0A";
        } else if (mismatch == 7) {
            results.append(messages.getString("possibleDuplexHalfFullWarning") + "\n");
            emailText += messages.getString("possibleDuplexHalfFullWarning") + "\n%0A";
        }

        if (mismatch == 0) {
            if (bad_cable == 1) {
                results.append(messages.getString("excessiveErrors ") + "\n");
                emailText += messages.getString("excessiveErrors") + "\n%0A";
            }
            if (congestion == 1) {
                results.append(messages.getString("otherTraffic") + "\n");
                emailText += messages.getString("otherTraffic") + "\n%0A";
            }
            if (((2 * rwin) / rttsec) < mylink) {
                j = (float) ((mylink * avgrtt) * 1000) / 8 / 1024;
                if (j > (float) MaxRwinRcvd) {
                    results.append(messages.getString("receiveBufferShouldBe") + " " + prtdbl(j)
                            + messages.getString("toMaximizeThroughput") + " \n");
                    emailText += messages.getString("receiveBufferShouldBe") + " " + prtdbl(j)
                            + messages.getString("toMaximizeThroughput") + "\n%0A";
                }
            }
        }

        if ((tests & TEST_C2S) == TEST_C2S) {
            if (sc2sspd < (c2sspd * (1.0 - VIEW_DIFF))) {
                // TODO:  distinguish the host buffering from the middleboxes buffering
                JLabel info = new JLabel(messages.getString("information"));
                info.addMouseListener(new MouseAdapter() {

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

                });
                info.setForeground(Color.BLUE);
                info.setCursor(new Cursor(Cursor.HAND_CURSOR));
                info.setAlignmentY((float) 0.8);
                results.insertComponent(info);
                results.append(messages.getString("c2sPacketQueuingDetected") + "\n");
            }
        }

        if ((tests & TEST_S2C) == TEST_S2C) {
            if (s2cspd < (ss2cspd * (1.0 - VIEW_DIFF))) {
                // TODO:  distinguish the host buffering from the middleboxes buffering
                JLabel info = new JLabel(messages.getString("information"));
                info.addMouseListener(new MouseAdapter() {

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

                });
                info.setForeground(Color.BLUE);
                info.setCursor(new Cursor(Cursor.HAND_CURSOR));
                info.setAlignmentY((float) 0.8);
                results.insertComponent(info);
                results.append(messages.getString("s2cPacketQueuingDetected") + "\n");
            }
        }

        statistics.append("\n\t------  " + messages.getString("clientInfo") + "------\n");
        statistics.append(messages.getString("osData") + " " + messages.getString("name") + " = " + osName
                + ", " + messages.getString("architecture") + " = " + osArch);
        statistics.append(", " + messages.getString("version") + " = " + osVer + "\n");
        statistics.append(messages.getString("javaData") + ": " + messages.getString("vendor") + " = "
                + javaVendor + ", " + messages.getString("version") + " = " + javaVer + "\n");

        report.put("os_name", osName);
        report.put("os_architecture", osArch);
        report.put("os_version", osVer);
        statistics.append("Java data: Vendor = " + javaVendor + ", Version = " + javaVer + "\n");
        report.put("java_vendor", javaVendor);
        report.put("java_version", javaVer);

        // statistics.append(" java.class.version=" + System.getProperty("java.class.version") + "\n");

        statistics.append("\n\t------  " + messages.getString("web100Details") + "  ------\n");
        if (c2sData == -2)
            statistics.append(messages.getString("insufficient") + "\n");
        else if (c2sData == -1)
            statistics.append(messages.getString("ipcFail") + "\n");
        else if (c2sData == 0)
            statistics.append(messages.getString("rttFail") + "\n");
        else if (c2sData == 1)
            statistics.append(messages.getString("foundDialup") + "\n");
        else if (c2sData == 2)
            statistics.append(messages.getString("foundDsl") + "\n");
        else if (c2sData == 3)
            statistics.append(messages.getString("found10mbps") + "\n");
        else if (c2sData == 4)
            statistics.append(messages.getString("found45mbps") + "\n");
        else if (c2sData == 5)
            statistics.append(messages.getString("found100mbps") + "\n");
        else if (c2sData == 6)
            statistics.append(messages.getString("found622mbps") + "\n");
        else if (c2sData == 7)
            statistics.append(messages.getString("found1gbps") + "\n");
        else if (c2sData == 8)
            statistics.append(messages.getString("found2.4gbps") + "\n");
        else if (c2sData == 9)
            statistics.append(messages.getString("found10gbps") + "\n");

        if (half_duplex == 0)
            statistics.append(messages.getString("linkFullDpx") + "\n");
        else
            statistics.append(messages.getString("linkHalfDpx") + "\n");

        if (congestion == 0)
            statistics.append(messages.getString("congestNo") + "\n");
        else
            statistics.append(messages.getString("congestYes") + "\n");

        if (bad_cable == 0)
            statistics.append(messages.getString("cablesOk") + "\n");
        else
            statistics.append(messages.getString("cablesNok") + "\n");

        if (mismatch == 0)
            statistics.append(messages.getString("duplexOk") + "\n");
        else if (mismatch == 1) {
            statistics.append(messages.getString("duplexNok") + " ");
            emailText += messages.getString("duplexNok") + " ";
        } else if (mismatch == 2) {
            statistics.append(messages.getString("duplexFullHalf") + "\n");
            emailText += messages.getString("duplexFullHalf") + "\n%0A ";
        } else if (mismatch == 3) {
            statistics.append(messages.getString("duplexHalfFull") + "\n");
            emailText += messages.getString("duplexHalfFull") + "\n%0A ";
        }

        statistics.append("\n" + messages.getString("web100rtt") + " =  " + prtdbl(avgrtt) + " " + "ms" + "; ");
        emailText += "\n%0A" + messages.getString("web100rtt") + " = " + prtdbl(avgrtt) + " " + "ms" + "; ";

        statistics.append(messages.getString("packetsize") + " = " + CurrentMSS + " "
                + messages.getString("bytes") + "; " + messages.getString("and") + " \n");
        emailText += messages.getString("packetsize") + " = " + CurrentMSS + " " + messages.getString("bytes")
                + "; " + messages.getString("and") + " \n%0A";

        report.put("rtt", prtdbl(avgrtt));
        rttLbl.setText(prtdbl(avgrtt));
        rttLbl.setText(String.format(padding + "%.0f msec", avgrtt));
        report.put("mss", Integer.toString(CurrentMSS));
        report.put("retransmissions", Integer.toString(PktsRetrans));
        report.put("sack_blocks", Integer.toString(SACKsRcvd));
        report.put("duplicate_acks", Integer.toString(DupAcksIn));
        report.put("timeouts", Integer.toString(Timeouts));
        report.put("wait_seconds", Double.toString(waitsec));
        report.put("out_of_order", Double.toString(order));
        report.put("loss", Double.toString(loss));
        report.put("jitter", get_jitter());
        lossLbl.setText(String.format(padding + "%.0f %%", loss * 100));
        jitterLbl.setText(padding + get_jitter() + " msec");

        if (PktsRetrans > 0) {
            statistics.append(PktsRetrans + " " + messages.getString("pktsRetrans"));
            statistics.append(", " + DupAcksIn + " " + messages.getString("dupAcksIn"));
            statistics.append(", " + messages.getString("and") + " " + SACKsRcvd + " "
                    + messages.getString("sackReceived") + "\n");
            emailText += PktsRetrans + " " + messages.getString("pktsRetrans");
            emailText += ", " + DupAcksIn + " " + messages.getString("dupAcksIn");
            emailText += ", " + messages.getString("and") + " " + SACKsRcvd + " "
                    + messages.getString("sackReceived") + "\n%0A";
            if (Timeouts > 0) {
                statistics.append(messages.getString("connStalled") + " " + Timeouts + " "
                        + messages.getString("timesPktLoss") + "\n");
            }

            statistics.append(messages.getString("connIdle") + " " + prtdbl(waitsec) + " "
                    + messages.getString("seconds") + " (" + prtdbl((waitsec / timesec) * 100)
                    + messages.getString("pctOfTime") + ")\n");
            emailText += messages.getString("connStalled") + " " + Timeouts + " "
                    + messages.getString("timesPktLoss") + "\n%0A";
            emailText += messages.getString("connIdle") + " " + prtdbl(waitsec) + " "
                    + messages.getString("seconds") + " (" + prtdbl((waitsec / timesec) * 100)
                    + messages.getString("pctOfTime") + ")\n%0A";
        } else if (DupAcksIn > 0) {
            statistics.append(messages.getString("noPktLoss1") + " - ");
            statistics.append(messages.getString("ooOrder") + " " + prtdbl(order * 100)
                    + messages.getString("pctOfTime") + "\n");
            emailText += messages.getString("noPktLoss1") + " - ";
            emailText += messages.getString("ooOrder") + " " + prtdbl(order * 100)
                    + messages.getString("pctOfTime") + "\n%0A";
        } else {
            statistics.append(messages.getString("noPktLoss2") + ".\n");
            emailText += messages.getString("noPktLoss2") + ".\n%0A";
        }

        if ((tests & TEST_C2S) == TEST_C2S) {
            if (c2sspd > sc2sspd) {
                if (sc2sspd < (c2sspd * (1.0 - VIEW_DIFF))) {
                    statistics.append(messages.getString("c2s") + " " + messages.getString("qSeen") + ": "
                            + prtdbl(100 * (c2sspd - sc2sspd) / c2sspd) + "%\n");
                } else {
                    statistics.append(messages.getString("c2s") + " " + messages.getString("qSeen") + ": "
                            + prtdbl(100 * (c2sspd - sc2sspd) / c2sspd) + "%\n");
                }
            }
        }

        if ((tests & TEST_S2C) == TEST_S2C) {
            if (ss2cspd > s2cspd) {
                if (s2cspd < (ss2cspd * (1.0 - VIEW_DIFF))) {
                    statistics.append(messages.getString("s2c") + " " + messages.getString("qSeen") + ": "
                            + prtdbl(100 * (ss2cspd - s2cspd) / ss2cspd) + "%\n");
                } else {
                    statistics.append(messages.getString("s2c") + " " + messages.getString("qSeen") + ": "
                            + prtdbl(100 * (ss2cspd - s2cspd) / ss2cspd) + "%\n");
                }
            }
        }

        if (rwintime > .015) {
            statistics.append(messages.getString("thisConnIs") + " " + messages.getString("limitRx") + " "
                    + prtdbl(rwintime * 100) + messages.getString("pctOfTime") + ".\n");
            emailText += messages.getString("thisConnIs") + " " + messages.getString("limitRx") + " "
                    + prtdbl(rwintime * 100) + messages.getString("pctOfTime") + ".\n%0A";
            pub_pctRcvrLimited = rwintime * 100;

            // I think there is a bug here, it sometimes tells you to increase the buffer
            // size, but the new size is smaller than the current.

            if (((2 * rwin) / rttsec) < mylink) {
                statistics.append("  " + messages.getString("incrRxBuf") + " (" + prtdbl(MaxRwinRcvd / 1024)
                        + " KB) " + messages.getString("willImprove") + "\n");
            }
        }
        if (sendtime > .015) {
            statistics.append(messages.getString("thisConnIs") + " " + messages.getString("limitTx") + " "
                    + prtdbl(sendtime * 100) + messages.getString("pctOfTime") + ".\n");
            emailText += messages.getString("thisConnIs") + " " + messages.getString("limitTx") + " "
                    + prtdbl(sendtime * 100) + messages.getString("pctOfTime") + ".\n%0A";
            if ((2 * (swin / rttsec)) < mylink) {
                statistics.append("  " + messages.getString("incrTxBuf") + " (" + prtdbl(Sndbuf / 2048)
                        + " KB) " + messages.getString("willImprove") + "\n");
            }
        }
        if (cwndtime > .005) {
            statistics.append(messages.getString("thisConnIs") + " " + messages.getString("limitNet") + " "
                    + prtdbl(cwndtime * 100) + messages.getString("pctOfTime") + ".\n");
            emailText += messages.getString("thisConnIs") + " " + messages.getString("limitNet") + " "
                    + prtdbl(cwndtime * 100) + messages.getString("pctOfTime") + ".\n%0A";
            // if (cwndtime > .15)
            //   statistics.append("  Contact your local network administrator to report a network problem\n");
            // if (order > .15)
            //   statistics.append("  Contact your local network admin and report excessive packet reordering\n");
        }
        if ((spd < 4) && (loss > .01)) {
            statistics.append(messages.getString("excLoss") + "\n");
        }

        statistics.append("\n" + messages.getString("web100tcpOpts") + " \n");
        statistics.append("RFC 2018 Selective Acknowledgment: ");
        if (SACKEnabled == Zero)
            statistics.append(messages.getString("off") + "\n");
        else
            statistics.append(messages.getString("on") + "\n");

        statistics.append("RFC 896 Nagle Algorithm: ");
        if (NagleEnabled == Zero)
            statistics.append(messages.getString("off") + "\n");
        else
            statistics.append(messages.getString("on") + "\n");

        statistics.append("RFC 3168 Explicit Congestion Notification: ");
        if (ECNEnabled == Zero)
            statistics.append(messages.getString("off") + "\n");
        else
            statistics.append(messages.getString("on") + "\n");

        statistics.append("RFC 1323 Time Stamping: ");
        if (TimestampsEnabled == 0)
            statistics.append(messages.getString("off") + "\n");
        else
            statistics.append(messages.getString("on") + "\n");

        statistics.append("RFC 1323 Window Scaling: ");
        if (MaxRwinRcvd < 65535)
            WinScaleRcvd = 0;
        if ((WinScaleRcvd == 0) || (WinScaleRcvd > 20)) {
            statistics.append(messages.getString("off") + "\n");
            report.put("window_scaling", "0");
        } else {
            statistics.append(messages.getString("on") + "; " + messages.getString("scalingFactors") + " -  "
                    + messages.getString("server") + "=" + WinScaleRcvd + ", " + messages.getString("client")
                    + "=" + WinScaleSent + "\n");
            report.put("window_scaling", "1");
        }
        statistics.append("\n");

        if ((tests & TEST_SFW) == TEST_SFW) {
            switch (c2sResult) {
            case SFW_NOFIREWALL:
                statistics.append(messages.getString("server") + " '" + host + "' "
                        + messages.getString("firewallNo") + "\n");
                emailText += messages.getString("server") + " '" + host + "' "
                        + messages.getString("firewallNo") + "\n%0A";
                break;
            case SFW_POSSIBLE:
                statistics.append(messages.getString("server") + " '" + host + "' "
                        + messages.getString("firewallYes") + "\n");
                emailText += messages.getString("server") + " '" + host + "' "
                        + messages.getString("firewallYes") + "\n%0A";
                break;
            case SFW_UNKNOWN:
            case SFW_NOTTESTED:
                break;
            }
            switch (s2cResult) {
            case SFW_NOFIREWALL:
                statistics
                        .append(messages.getString("client2") + " " + messages.getString("firewallNo") + "\n");
                emailText += messages.getString("client2") + " " + messages.getString("firewallNo") + "\n%0A";
                break;
            case SFW_POSSIBLE:
                statistics
                        .append(messages.getString("client2") + " " + messages.getString("firewallYes") + "\n");
                emailText += messages.getString("client2") + " " + messages.getString("firewallYes") + "\n%0A";
                break;
            case SFW_UNKNOWN:
            case SFW_NOTTESTED:
                break;
            }
        }

        //         diagnosis.append("\nEstimate = " + prtdbl(estimate) + " based on packet size = "
        //            + (CurrentMSS*8/1024) + "kbits, RTT = " + prtdbl(avgrtt) + "msec, " + "and loss = " + loss + "\n");
        diagnosis.append("\n");

        diagnosis.append(messages.getString("theoreticalLimit") + " " + prtdbl(estimate) + " " + "Mbps\n");
        emailText += messages.getString("theoreticalLimit") + " " + prtdbl(estimate) + " Mbps\n%0A";

        diagnosis.append(messages.getString("ndtServerHas") + " " + prtdbl(Sndbuf / 2048) + " "
                + messages.getString("kbyteBufferLimits") + " " + prtdbl(swin / rttsec) + " Mbps\n");
        emailText += messages.getString("ndtServerHas") + " " + prtdbl(Sndbuf / 2048) + " "
                + messages.getString("kbyteBufferLimits") + " " + prtdbl(swin / rttsec) + " Mbps\n%0A";

        diagnosis.append(messages.getString("yourPcHas") + " " + prtdbl(MaxRwinRcvd / 1024) + " "
                + messages.getString("kbyteBufferLimits") + " " + prtdbl(rwin / rttsec) + " Mbps\n");
        emailText += messages.getString("yourPcHas") + " " + prtdbl(MaxRwinRcvd / 1024) + " "
                + messages.getString("kbyteBufferLimits") + " " + prtdbl(rwin / rttsec) + " Mbps\n%0A";

        diagnosis.append(messages.getString("flowControlLimits") + " " + prtdbl(cwin / rttsec) + " Mbps\n");
        emailText += messages.getString("flowControlLimits") + " " + prtdbl(cwin / rttsec) + " Mbps\n%0A";

        diagnosis.append("\n" + messages.getString("clientDataReports") + " '" + prttxt(c2sData) + "', "
                + messages.getString("clientAcksReport") + " '" + prttxt(c2sAck) + "'\n"
                + messages.getString("serverDataReports") + " '" + prttxt(s2cData) + "', "
                + messages.getString("serverAcksReport") + " '" + prttxt(s2cAck) + "'\n");
        pub_diagnosis = diagnosis.getText();

    }
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

@SuppressWarnings("unchecked")
private List<ParameterInfo> createAndDisplayAParameterPanel(
        final List<ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?>> batchParameters, final String title,
        final SubmodelInfo parent, final boolean submodelSelectionWithoutNotify,
        final IModelHandler currentModelHandler) {
    final List<ParameterMetaData> metadata = new LinkedList<ParameterMetaData>(),
            unknownFields = new ArrayList<ParameterMetaData>();
    for (final ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?> record : batchParameters) {
        final String parameterName = record.getName(), fieldName = StringUtils.uncapitalize(parameterName);
        Class<?> modelComponentType = parent == null ? currentModelHandler.getModelClass()
                : parent.getActualType();
        while (true) {
            try {
                final Field field = modelComponentType.getDeclaredField(fieldName);
                final ParameterMetaData datum = new ParameterMetaData();
                for (final Annotation element : field.getAnnotations()) {
                    if (element.annotationType().getName() != Layout.class.getName()) // Proxies
                        continue;
                    final Class<? extends Annotation> type = element.annotationType();
                    datum.verboseDescription = (String) type.getMethod("VerboseDescription").invoke(element);
                    datum.banner = (String) type.getMethod("Title").invoke(element);
                    datum.fieldName = (String) " " + type.getMethod("FieldName").invoke(element);
                    datum.imageFileName = (String) type.getMethod("Image").invoke(element);
                    datum.layoutOrder = (Double) type.getMethod("Order").invoke(element);
                }//from   ww w . j  a  va2 s . c o m
                datum.parameter = record;
                if (datum.fieldName.trim().isEmpty())
                    datum.fieldName = parameterName.replaceAll("([A-Z])", " $1");
                metadata.add(datum);
                break;
            } catch (final SecurityException e) {
            } catch (final NoSuchFieldException e) {
            } catch (final IllegalArgumentException e) {
            } catch (final IllegalAccessException e) {
            } catch (final InvocationTargetException e) {
            } catch (final NoSuchMethodException e) {
            }
            modelComponentType = modelComponentType.getSuperclass();
            if (modelComponentType == null) {
                ParameterMetaData.createAndRegisterUnknown(fieldName, record, unknownFields);
                break;
            }
        }
    }
    Collections.sort(metadata);
    for (int i = unknownFields.size() - 1; i >= 0; --i)
        metadata.add(0, unknownFields.get(i));

    // initialize single run form
    final DefaultFormBuilder formBuilder = FormsUtils.build("p ~ p:g", "");
    appendMinimumWidthHintToPresentation(formBuilder, 550);

    if (parent == null) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                numberOfTurnsField.grabFocus();
            }
        });

        appendBannerToPresentation(formBuilder, "General Parameters");
        appendTextToPresentation(formBuilder, "Global parameters affecting the entire simulation");

        formBuilder.append(NUMBER_OF_TURNS_LABEL_TEXT, numberOfTurnsField);
        formBuilder.append(NUMBER_OF_TIMESTEPS_TO_IGNORE_LABEL_TEXT, numberTimestepsIgnored);

        appendCheckBoxFieldToPresentation(formBuilder, UPDATE_CHARTS_LABEL_TEXT, onLineChartsCheckBox);
        appendCheckBoxFieldToPresentation(formBuilder, DISPLAY_ADVANCED_CHARTS_LABEL_TEXT,
                advancedChartsCheckBox);
    }

    appendBannerToPresentation(formBuilder, title);

    final DefaultMutableTreeNode parentNode = (parent == null) ? parameterValueComponentTree
            : findParameterInfoNode(parent, false);

    final List<ParameterInfo> info = new ArrayList<ParameterInfo>();

    // Search for a @ConfigurationComponent annotation
    {
        String headerText = "", imagePath = "";
        final Class<?> parentType = parent == null ? currentModelHandler.getModelClass()
                : parent.getActualType();
        for (final Annotation element : parentType.getAnnotations()) { // Proxies
            if (element.annotationType().getName() != ConfigurationComponent.class.getName())
                continue;
            boolean doBreak = false;
            try {
                try {
                    headerText = (String) element.annotationType().getMethod("Description").invoke(element);
                    if (headerText.startsWith("#")) {
                        headerText = (String) parent.getActualType().getMethod(headerText.substring(1))
                                .invoke(parent.getInstance());
                    }
                    doBreak = true;
                } catch (IllegalArgumentException e) {
                } catch (SecurityException e) {
                } catch (IllegalAccessException e) {
                } catch (InvocationTargetException e) {
                } catch (NoSuchMethodException e) {
                }
            } catch (final Exception e) {
            }
            try {
                imagePath = (String) element.annotationType().getMethod("ImagePath").invoke(element);
                doBreak = true;
            } catch (IllegalArgumentException e) {
            } catch (SecurityException e) {
            } catch (IllegalAccessException e) {
            } catch (InvocationTargetException e) {
            } catch (NoSuchMethodException e) {
            }
            if (doBreak)
                break;
        }
        if (!headerText.isEmpty())
            appendHeaderTextToPresentation(formBuilder, headerText);
        if (!imagePath.isEmpty())
            appendImageToPresentation(formBuilder, imagePath);
    }

    if (metadata.isEmpty()) {
        // No fields to display.
        appendTextToPresentation(formBuilder, "No configuration is required for this module.");
    } else {
        for (final ParameterMetaData record : metadata) {
            final ai.aitia.meme.paramsweep.batch.param.ParameterInfo<?> batchParameterInfo = record.parameter;

            if (!record.banner.isEmpty())
                appendBannerToPresentation(formBuilder, record.banner);
            if (!record.imageFileName.isEmpty())
                appendImageToPresentation(formBuilder, record.imageFileName);
            appendTextToPresentation(formBuilder, record.verboseDescription);

            final ParameterInfo parameterInfo = InfoConverter.parameterInfo2ParameterInfo(batchParameterInfo);
            if (parent != null && parameterInfo instanceof ISubmodelGUIInfo) {
                //               sgi.setParentValue(parent.getActualType());
            }

            final JComponent field;
            final DefaultMutableTreeNode oldNode = findParameterInfoNode(parameterInfo, true);
            Pair<ParameterInfo, JComponent> userData = null;
            JComponent oldField = null;
            if (oldNode != null) {
                userData = (Pair<ParameterInfo, JComponent>) oldNode.getUserObject();
                oldField = userData.getSecond();
            }

            if (parameterInfo.isBoolean()) {
                field = new JCheckBox();
                boolean value = oldField != null ? ((JCheckBox) oldField).isSelected()
                        : ((Boolean) batchParameterInfo.getDefaultValue()).booleanValue();
                ((JCheckBox) field).setSelected(value);
            } else if (parameterInfo.isEnum() || parameterInfo instanceof MasonChooserParameterInfo) {
                Object[] elements = null;
                if (parameterInfo.isEnum()) {
                    final Class<Enum<?>> type = (Class<Enum<?>>) parameterInfo.getJavaType();
                    elements = type.getEnumConstants();
                } else {
                    final MasonChooserParameterInfo chooserInfo = (MasonChooserParameterInfo) parameterInfo;
                    elements = chooserInfo.getValidStrings();
                }
                final JComboBox list = new JComboBox(elements);

                if (parameterInfo.isEnum()) {
                    final Object value = oldField != null ? ((JComboBox) oldField).getSelectedItem()
                            : parameterInfo.getValue();
                    list.setSelectedItem(value);
                } else {
                    final int value = oldField != null ? ((JComboBox) oldField).getSelectedIndex()
                            : (Integer) parameterInfo.getValue();
                    list.setSelectedIndex(value);
                }

                field = list;
            } else if (parameterInfo instanceof SubmodelInfo) {
                final SubmodelInfo submodelInfo = (SubmodelInfo) parameterInfo;
                final Object[] elements = new Object[] { "Loading class information..." };
                final JComboBox list = new JComboBox(elements);
                //            field = list;

                final Object value = oldField != null
                        ? ((JComboBox) ((JPanel) oldField).getComponent(0)).getSelectedItem()
                        : new ClassElement(submodelInfo.getActualType(), null);

                new ClassCollector(this, list, submodelInfo, value, submodelSelectionWithoutNotify).execute();

                final JButton rightButton = new JButton();
                rightButton.setOpaque(false);
                rightButton.setRolloverEnabled(true);
                rightButton.setIcon(SHOW_SUBMODEL_ICON);
                rightButton.setRolloverIcon(SHOW_SUBMODEL_ICON_RO);
                rightButton.setDisabledIcon(SHOW_SUBMODEL_ICON_DIS);
                rightButton.setBorder(null);
                rightButton.setToolTipText("Display submodel parameters");
                rightButton.setActionCommand(ACTIONCOMMAND_SHOW_SUBMODEL);
                rightButton.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        if (parameterInfo instanceof SubmodelInfo) {
                            SubmodelInfo submodelInfo = (SubmodelInfo) parameterInfo;
                            int level = 0;

                            showHideSubparameters(list, submodelInfo);

                            List<String> components = new ArrayList<String>();
                            components.add(submodelInfo.getName());
                            while (submodelInfo.getParent() != null) {
                                submodelInfo = submodelInfo.getParent();
                                components.add(submodelInfo.getName());
                                level++;
                            }
                            Collections.reverse(components);
                            final String[] breadcrumbText = components.toArray(new String[components.size()]);
                            for (int i = 0; i < breadcrumbText.length; ++i)
                                breadcrumbText[i] = breadcrumbText[i].replaceAll("([A-Z])", " $1");
                            breadcrumb.setPath(
                                    currentModelHandler.getModelClassSimpleName().replaceAll("([A-Z])", " $1"),
                                    breadcrumbText);
                            Style.apply(breadcrumb, dashboard.getCssStyle());

                            // reset all buttons that are nested deeper than this to default color
                            for (int i = submodelButtons.size() - 1; i >= level; i--) {
                                JButton button = submodelButtons.get(i);
                                button.setIcon(SHOW_SUBMODEL_ICON);
                                submodelButtons.remove(i);
                            }

                            rightButton.setIcon(SHOW_SUBMODEL_ICON_RO);
                            submodelButtons.add(rightButton);
                        }
                    }
                });

                field = new JPanel(new BorderLayout());
                field.add(list, BorderLayout.CENTER);
                field.add(rightButton, BorderLayout.EAST);
            } else if (File.class.isAssignableFrom(parameterInfo.getJavaType())) {
                field = new JPanel(new BorderLayout());

                String oldName = "";
                String oldPath = "";
                if (oldField != null) {
                    final JTextField oldTextField = (JTextField) oldField.getComponent(0);
                    oldName = oldTextField.getText();
                    oldPath = oldTextField.getToolTipText();
                } else if (parameterInfo.getValue() != null) {
                    final File file = (File) parameterInfo.getValue();
                    oldName = file.getName();
                    oldPath = file.getAbsolutePath();
                }

                final JTextField textField = new JTextField(oldName);
                textField.setToolTipText(oldPath);
                textField.setInputVerifier(new InputVerifier() {

                    @Override
                    public boolean verify(final JComponent input) {
                        final JTextField inputField = (JTextField) input;
                        if (inputField.getText() == null || inputField.getText().isEmpty()) {
                            final File file = new File("");
                            inputField.setToolTipText(file.getAbsolutePath());
                            hideError();
                            return true;
                        }

                        final File oldFile = new File(inputField.getToolTipText());
                        if (oldFile.exists() && oldFile.getName().equals(inputField.getText().trim())) {
                            hideError();
                            return true;
                        }

                        inputField.setToolTipText("");
                        final File file = new File(inputField.getText().trim());
                        if (file.exists()) {
                            inputField.setToolTipText(file.getAbsolutePath());
                            inputField.setText(file.getName());
                            hideError();
                            return true;
                        } else {
                            final PopupFactory popupFactory = PopupFactory.getSharedInstance();
                            final Point locationOnScreen = inputField.getLocationOnScreen();
                            final JLabel message = new JLabel("Please specify an existing file!");
                            message.setBorder(new LineBorder(Color.RED, 2, true));
                            if (errorPopup != null)
                                errorPopup.hide();
                            errorPopup = popupFactory.getPopup(inputField, message, locationOnScreen.x - 10,
                                    locationOnScreen.y - 30);
                            errorPopup.show();
                            return false;
                        }
                    }
                });

                final JButton browseButton = new JButton(BROWSE_BUTTON_TEXT);
                browseButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        final JFileChooser fileDialog = new JFileChooser(
                                !"".equals(textField.getToolTipText()) ? textField.getToolTipText()
                                        : currentDirectory);
                        if (!"".equals(textField.getToolTipText()))
                            fileDialog.setSelectedFile(new File(textField.getToolTipText()));
                        int dialogResult = fileDialog.showOpenDialog(dashboard);
                        if (dialogResult == JFileChooser.APPROVE_OPTION) {
                            final File selectedFile = fileDialog.getSelectedFile();
                            if (selectedFile != null) {
                                currentDirectory = selectedFile.getAbsoluteFile().getParent();
                                textField.setText(selectedFile.getName());
                                textField.setToolTipText(selectedFile.getAbsolutePath());
                            }
                        }
                    }
                });

                field.add(textField, BorderLayout.CENTER);
                field.add(browseButton, BorderLayout.EAST);
            } else if (parameterInfo instanceof MasonIntervalParameterInfo) {
                final MasonIntervalParameterInfo intervalInfo = (MasonIntervalParameterInfo) parameterInfo;

                field = new JPanel(new BorderLayout());

                String oldValueStr = String.valueOf(parameterInfo.getValue());
                if (oldField != null) {
                    final JTextField oldTextField = (JTextField) oldField.getComponent(0);
                    oldValueStr = oldTextField.getText();
                }

                final JTextField textField = new JTextField(oldValueStr);

                PercentJSlider tempSlider = null;
                if (intervalInfo.isDoubleInterval())
                    tempSlider = new PercentJSlider(intervalInfo.getIntervalMin().doubleValue(),
                            intervalInfo.getIntervalMax().doubleValue(), Double.parseDouble(oldValueStr));
                else
                    tempSlider = new PercentJSlider(intervalInfo.getIntervalMin().longValue(),
                            intervalInfo.getIntervalMax().longValue(), Long.parseLong(oldValueStr));

                final PercentJSlider slider = tempSlider;
                slider.setMajorTickSpacing(100);
                slider.setMinorTickSpacing(10);
                slider.setPaintTicks(true);
                slider.setPaintLabels(true);
                slider.addChangeListener(new ChangeListener() {
                    public void stateChanged(final ChangeEvent _) {
                        if (slider.hasFocus()) {
                            final String value = intervalInfo.isDoubleInterval()
                                    ? String.valueOf(slider.getDoubleValue())
                                    : String.valueOf(slider.getLongValue());
                            textField.setText(value);
                            slider.setToolTipText(value);
                        }
                    }
                });

                textField.setInputVerifier(new InputVerifier() {
                    public boolean verify(JComponent input) {
                        final JTextField inputField = (JTextField) input;

                        try {
                            hideError();
                            final String valueStr = inputField.getText().trim();
                            if (intervalInfo.isDoubleInterval()) {
                                final double value = Double.parseDouble(valueStr);
                                if (intervalInfo.isValidValue(valueStr)) {
                                    slider.setValue(value);
                                    return true;
                                } else
                                    showError(
                                            "Please specify a value between " + intervalInfo.getIntervalMin()
                                                    + " and " + intervalInfo.getIntervalMax() + ".",
                                            inputField);
                                return false;
                            } else {
                                final long value = Long.parseLong(valueStr);
                                if (intervalInfo.isValidValue(valueStr)) {
                                    slider.setValue(value);
                                    return true;
                                } else {
                                    showError("Please specify an integer value between "
                                            + intervalInfo.getIntervalMin() + " and "
                                            + intervalInfo.getIntervalMax() + ".", inputField);
                                    return false;
                                }
                            }
                        } catch (final NumberFormatException _) {
                            final String message = "The specified value is not a"
                                    + (intervalInfo.isDoubleInterval() ? "" : "n integer") + " number.";
                            showError(message, inputField);
                            return false;
                        }

                    }
                });

                textField.getDocument().addDocumentListener(new DocumentListener() {
                    //               private Popup errorPopup;

                    public void removeUpdate(final DocumentEvent _) {
                        textFieldChanged();
                    }

                    public void insertUpdate(final DocumentEvent _) {
                        textFieldChanged();
                    }

                    public void changedUpdate(final DocumentEvent _) {
                        textFieldChanged();
                    }

                    private void textFieldChanged() {
                        if (!textField.hasFocus()) {
                            hideError();
                            return;
                        }

                        try {
                            hideError();
                            final String valueStr = textField.getText().trim();
                            if (intervalInfo.isDoubleInterval()) {
                                final double value = Double.parseDouble(valueStr);
                                if (intervalInfo.isValidValue(valueStr))
                                    slider.setValue(value);
                                else
                                    showError("Please specify a value between " + intervalInfo.getIntervalMin()
                                            + " and " + intervalInfo.getIntervalMax() + ".", textField);
                            } else {
                                final long value = Long.parseLong(valueStr);
                                if (intervalInfo.isValidValue(valueStr))
                                    slider.setValue(value);
                                else
                                    showError("Please specify an integer value between "
                                            + intervalInfo.getIntervalMin() + " and "
                                            + intervalInfo.getIntervalMax() + ".", textField);
                            }
                        } catch (final NumberFormatException _) {
                            final String message = "The specified value is not a"
                                    + (intervalInfo.isDoubleInterval() ? "" : "n integer") + " number.";
                            showError(message, textField);
                        }
                    }
                });

                field.add(textField, BorderLayout.CENTER);
                field.add(slider, BorderLayout.SOUTH);
            } else {
                final Object value = oldField != null ? ((JTextField) oldField).getText()
                        : parameterInfo.getValue();
                field = new JTextField(value.toString());
                ((JTextField) field).addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        wizard.clickDefaultButton();
                    }
                });
            }

            final JLabel parameterLabel = new JLabel(record.fieldName);

            final String description = parameterInfo.getDescription();
            if (description != null && !description.isEmpty()) {
                parameterLabel.addMouseListener(new MouseAdapter() {

                    @Override
                    public void mouseEntered(final MouseEvent e) {
                        final DescriptionPopupFactory popupFactory = DescriptionPopupFactory.getInstance();

                        final Popup parameterDescriptionPopup = popupFactory.getPopup(parameterLabel,
                                description, dashboard.getCssStyle());

                        parameterDescriptionPopup.show();
                    }

                });
            }

            if (oldNode != null)
                userData.setSecond(field);
            else {
                final Pair<ParameterInfo, JComponent> pair = new Pair<ParameterInfo, JComponent>(parameterInfo,
                        field);
                final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(pair);
                parentNode.add(newNode);
            }

            if (field instanceof JCheckBox) {
                parameterLabel
                        .setText("<html><div style=\"margin-bottom: 4pt; margin-top: 6pt; margin-left: 4pt\">"
                                + parameterLabel.getText() + "</div></html>");
                formBuilder.append(parameterLabel, field);

                //            appendCheckBoxFieldToPresentation(
                //               formBuilder, parameterLabel.getText(), (JCheckBox) field);
            } else {
                formBuilder.append(parameterLabel, field);
                final CellConstraints constraints = formBuilder.getLayout().getConstraints(parameterLabel);
                constraints.vAlign = CellConstraints.TOP;
                constraints.insets = new Insets(5, 0, 0, 0);
                formBuilder.getLayout().setConstraints(parameterLabel, constraints);
            }

            // prepare the parameterInfo for the param sweeps
            parameterInfo.setRuns(0);
            parameterInfo.setDefinitionType(ParameterInfo.CONST_DEF);
            parameterInfo.setValue(batchParameterInfo.getDefaultValue());
            info.add(parameterInfo);
        }
    }
    appendVerticalSpaceToPresentation(formBuilder);

    final JPanel panel = formBuilder.getPanel();
    singleRunParametersPanel.add(panel);

    if (singleRunParametersPanel.getComponentCount() > 1) {
        panel.setBorder(
                BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 1, 0, 0, Color.GRAY),
                        BorderFactory.createEmptyBorder(0, 5, 0, 5)));
    } else {
        panel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    }

    Style.apply(panel, dashboard.getCssStyle());

    return info;
}

From source file:com.mirth.connect.client.ui.Frame.java

/**
 * Builds the content panel with a title bar and settings.
 *//*from www.  j a v a2  s .  c om*/
private void buildContentPanel(JXTitledPanel container, JScrollPane component, boolean opaque) {
    container.getContentContainer().setLayout(new BorderLayout());
    container.setBorder(null);
    container.setTitleFont(new Font("Tahoma", Font.BOLD, 18));
    container.setTitleForeground(UIConstants.HEADER_TITLE_TEXT_COLOR);
    JLabel mirthConnectImage = new JLabel();
    mirthConnectImage.setIcon(UIConstants.MIRTHCONNECT_LOGO_GRAY);
    mirthConnectImage.setText(" ");
    mirthConnectImage.setToolTipText(UIConstants.MIRTHCONNECT_TOOLTIP);
    mirthConnectImage.setCursor(new Cursor(Cursor.HAND_CURSOR));

    mirthConnectImage.addMouseListener(new java.awt.event.MouseAdapter() {

        public void mouseClicked(java.awt.event.MouseEvent evt) {
            BareBonesBrowserLaunch.openURL(UIConstants.MIRTHCONNECT_URL);
        }
    });

    ((JPanel) container.getComponent(0)).add(mirthConnectImage);

    component.setBorder(new LineBorder(Color.GRAY, 1));
    component.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    component.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

    container.getContentContainer().add(component);
}

From source file:lcmc.gui.resources.ServiceInfo.java

/**
 * Creates host score combo boxes with labels, one per host.
 *//* w w  w.  ja  va  2  s .  co  m*/
protected void addHostLocations(final JPanel optionsPanel, final int leftWidth, final int rightWidth) {
    int rows = 0;

    final JPanel panel = getParamPanel(Tools.getString("ClusterBrowser.HostLocations"));
    panel.setLayout(new SpringLayout());

    for (final Host host : getBrowser().getClusterHosts()) {
        final HostInfo hi = host.getBrowser().getHostInfo();
        final Map<String, String> abbreviations = new HashMap<String, String>();
        abbreviations.put("i", CRMXML.INFINITY_STRING);
        abbreviations.put("+", CRMXML.PLUS_INFINITY_STRING);
        abbreviations.put("I", CRMXML.INFINITY_STRING);
        abbreviations.put("a", "ALWAYS");
        abbreviations.put("n", "NEVER");
        final Widget wi = new Widget(null,
                new String[] { null, "0", "2", "ALWAYS", "NEVER", CRMXML.INFINITY_STRING,
                        CRMXML.MINUS_INFINITY_STRING, CRMXML.INFINITY_STRING },
                null, /* units */
                null, /* type */
                "^((-?\\d*|(-|\\+)?" + CRMXML.INFINITY_STRING + "))|ALWAYS|NEVER|@NOTHING_SELECTED@$",
                rightWidth, abbreviations, new AccessMode(ConfigData.AccessType.ADMIN, false));
        wi.setEditable(true);
        final Widget prevWi = scoreComboBoxHash.get(hi);
        scoreComboBoxHash.put(hi, wi);

        /* set selected host scores in the combo box from
         * savedHostLocations */
        if (prevWi == null) {
            final HostLocation hl = savedHostLocations.get(hi);
            String hsSaved = null;
            if (hl != null) {
                hsSaved = hl.getScore();
            }
            wi.setValue(hsSaved);
        } else {
            wi.setValue(prevWi.getValue());
        }
    }

    /* host score combo boxes */
    for (Host host : getBrowser().getClusterHosts()) {
        final HostInfo hi = host.getBrowser().getHostInfo();
        final Widget wi = scoreComboBoxHash.get(hi);
        String op = null;
        final HostLocation hl = savedHostLocations.get(hi);
        if (hl != null) {
            op = hl.getOperation();
        }
        final String text = getHostLocationLabel(hi.getName(), op);
        final JLabel label = new JLabel(text);
        final String onText = getHostLocationLabel(hi.getName(), "eq");
        final String notOnText = getHostLocationLabel(hi.getName(), "ne");
        label.addMouseListener(new MouseListener() {
            @Override
            public final void mouseClicked(final MouseEvent e) {
                /* do nothing */
            }

            @Override
            public final void mouseEntered(final MouseEvent e) {
                /* do nothing */
            }

            @Override
            public final void mouseExited(final MouseEvent e) {
                /* do nothing */
            }

            @Override
            public final void mousePressed(final MouseEvent e) {
                final String currentText = label.getText();
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        if (currentText.equals(onText)) {
                            label.setText(notOnText);
                        } else if (currentText.equals(notOnText)) {
                            label.setText(onText);
                        } else {
                            /* wierd things */
                            label.setText(onText);
                        }
                        final String[] params = getParametersFromXML();
                        setApplyButtons(CACHED_FIELD, params);
                    }
                });
            }

            @Override
            public final void mouseReleased(final MouseEvent e) {
                /* do nothing */
            }
        });
        wi.setLabel(label, "");
        addField(panel, label, wi, leftWidth, rightWidth, 0);
        rows++;
    }
    rows += addPingField(panel, leftWidth, rightWidth);

    SpringUtilities.makeCompactGrid(panel, rows, 2, /* rows, cols */
            1, 1, /* initX, initY */
            1, 1); /* xPad, yPad */
    optionsPanel.add(panel);
}

From source file:net.sourceforge.squirrel_sql.client.preferences.UpdatePreferencesPanel.java

private JPanel createUpdateSitePanel() {
    JPanel pnl = new JPanel(new GridBagLayout());
    pnl.setBorder(BorderFactory.createTitledBorder(i18n.UPDATE_SITE_BORDER_LABEL));

    ItemListener urlUpdateItemListener = new UrlItemListener();
    DocumentListener urlDocumentListener = new UrlDocumentListener();
    final GridBagConstraints gbc = new GridBagConstraints();

    setSeparatorConstraints(gbc, 0);//from  w w w.  j  a v a 2s.co  m
    gbc.gridwidth = 1;
    gbc.weightx = 0;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.EAST;
    siteTypeLabel = new JLabel(i18n.SITE_TYPE_LABEL, JLabel.RIGHT);
    pnl.add(siteTypeLabel, gbc);

    // Site type

    setSeparatorConstraints(gbc, 0);
    gbc.gridx = 1;
    gbc.gridwidth = 1;
    gbc.fill = GridBagConstraints.NONE;
    pnl.add(getSiteTypePanel(), gbc);

    setSeparatorConstraints(gbc, 1);
    pnl.add(getSep(), gbc);

    // Update server name

    setLabelConstraints(gbc, 2);
    _serverLabel = new JLabel(i18n.SERVER, SwingConstants.RIGHT);
    pnl.add(_serverLabel, gbc);

    setFieldConstraints(gbc, 2);
    _updateServerName.getDocument().addDocumentListener(urlDocumentListener);
    pnl.add(_updateServerName, gbc);

    // Update server port

    setLabelConstraints(gbc, 3);
    _portLabel = new JLabel(i18n.PORT, SwingConstants.RIGHT);
    pnl.add(_portLabel, gbc);

    setFieldConstraints(gbc, 3);
    _updateServerPort.getDocument().addDocumentListener(urlDocumentListener);
    pnl.add(_updateServerPort, gbc);

    // Path to release.xml

    setLabelConstraints(gbc, 4);
    _pathLabel = new JLabel(i18n.PATH, SwingConstants.RIGHT);
    pnl.add(_pathLabel, gbc);

    setFieldConstraints(gbc, 4);
    _updateServerPath.getDocument().addDocumentListener(urlDocumentListener);
    pnl.add(_updateServerPath, gbc);

    // Channnel combo-box

    setLabelConstraints(gbc, 5);
    _channelLabel = new JLabel(i18n.CHANNEL, SwingConstants.RIGHT);
    pnl.add(_channelLabel, gbc);

    setFieldConstraints(gbc, 5);
    gbc.fill = GridBagConstraints.NONE;
    _updateServerChannel.addItemListener(urlUpdateItemListener);
    pnl.add(_updateServerChannel, gbc);

    // URL text field

    setLabelConstraints(gbc, 6);
    _urlLabel = new JLabel(i18n.URL, SwingConstants.RIGHT);
    pnl.add(_urlLabel, gbc);

    setFieldConstraints(gbc, 6);
    updateUrl();
    pnl.add(_updateUrl, gbc);

    setFieldConstraints(gbc, 7);
    JLabel lblProxy = new JLabel(s_stringMgr.getString("UpdatePreferencesPanel.proxyHintHtml"));
    lblProxy.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    lblProxy.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            _prefrenceTabActvivationListener.activateTabForClass(ProxyPreferenceTabComponent.class);
        }
    });
    pnl.add(lblProxy, gbc);

    // Test Connection Button Panel (Both the button and the status label

    setFieldConstraints(gbc, 8);

    Box buttonBox = Box.createHorizontalBox();
    buttonBox.add(_testConnectionButton);
    buttonBox.add(Box.createHorizontalStrut(20));
    buttonBox.add(_testConnectionStatusLabel);
    _testConnectionButton.addActionListener(new TestConnectionButtonListener());
    pnl.add(buttonBox, gbc);

    // Separator

    setSeparatorConstraints(gbc, 9);
    pnl.add(getSep(), gbc);

    // Local update directory

    setLabelConstraints(gbc, 10);
    _localPathLabel = new JLabel(i18n.LOCAL_PATH, SwingConstants.RIGHT);
    pnl.add(_localPathLabel, gbc);

    setFieldConstraints(gbc, 10);
    pnl.add(_localPath, gbc);
    return pnl;
}

From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java

@Override
public void refreshView(final ViewState state) {
    this.removeAll();

    tableMenu = new JPopupMenu("TableMenu");
    this.add(tableMenu);
    override = new JMenuItem(OVERRIDE);
    override.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition());
            String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state);
            Metadata staticMet = state.getSelected().getModel().getStaticMetadata();
            if (staticMet == null) {
                staticMet = new Metadata();
            }/* w  w w  . j a v a2 s  .  co m*/
            if (e.getActionCommand().equals(OVERRIDE)) {
                if (!staticMet.containsKey(key)) {
                    staticMet.addMetadata(key, (String) DefaultPropView.this.table.getValueAt(row, 2));
                    String envReplace = (String) DefaultPropView.this.table.getValueAt(row, 3);
                    if (Boolean.valueOf(envReplace)) {
                        staticMet.addMetadata(key + "/envReplace", envReplace);
                    }
                    state.getSelected().getModel().setStaticMetadata(staticMet);
                    DefaultPropView.this.notifyListeners();
                }
            }
        }
    });
    delete = new JMenuItem(DELETE);
    delete.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition());
            String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state);
            Metadata staticMet = state.getSelected().getModel().getStaticMetadata();
            if (staticMet == null) {
                staticMet = new Metadata();
            }
            staticMet.removeMetadata(key);
            staticMet.removeMetadata(key + "/envReplace");
            state.getSelected().getModel().setStaticMetadata(staticMet);
            DefaultPropView.this.notifyListeners();
        }

    });
    tableMenu.add(override);
    tableMenu.add(delete);

    if (state.getSelected() != null) {
        JPanel masterPanel = new JPanel();
        masterPanel.setLayout(new BoxLayout(masterPanel, BoxLayout.Y_AXIS));
        masterPanel.add(this.getModelIdPanel(state.getSelected(), state));
        masterPanel.add(this.getModelNamePanel(state.getSelected(), state));
        if (!state.getSelected().getModel().isParentType()) {
            masterPanel.add(this.getInstanceClassPanel(state.getSelected(), state));
        }
        masterPanel.add(this.getExecutionTypePanel(state.getSelected(), state));
        masterPanel.add(this.getPriorityPanel(state));
        masterPanel.add(this.getExecusedIds(state.getSelected()));
        if (state.getSelected().getModel().getExecutionType().equals("condition")) {
            masterPanel.add(this.getTimeout(state.getSelected(), state));
            masterPanel.add(this.getOptional(state.getSelected(), state));
        }
        JScrollPane scrollPane = new JScrollPane(table = this.createTable(state),
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.getHorizontalScrollBar().setUnitIncrement(10);
        scrollPane.getVerticalScrollBar().setUnitIncrement(10);
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.setBorder(new EtchedBorder());
        final JLabel metLabel = new JLabel("Static Metadata");
        metLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        final JLabel extendsLabel = new JLabel("<extends>");
        extendsLabel.setFont(new Font("Serif", Font.PLAIN, 10));
        extendsLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        extendsLabel.addMouseListener(new MouseListener() {

            private JScrollPane availableScroller;
            private JScrollPane mineScroller;
            private JList mineList;
            private JList availableList;
            private DefaultListModel mineModel;
            private DefaultListModel availableModel;

            public void mouseClicked(MouseEvent e) {
                final JPopupMenu popup = new JPopupMenu();
                popup.setLayout(new BorderLayout());

                JPanel main = new JPanel();
                main.setLayout(new BoxLayout(main, BoxLayout.X_AXIS));

                JPanel mine = new JPanel();
                mine.setBorder(new EtchedBorder());
                mine.setLayout(new BorderLayout());
                JLabel mineLabel = new JLabel("Mine");
                mineScroller = new JScrollPane(mineList = createJList(mineModel = new DefaultListModel(),
                        state.getSelected().getModel().getExtendsConfig()));
                mineScroller.setPreferredSize(new Dimension(250, 80));
                mine.add(mineLabel, BorderLayout.NORTH);
                mine.add(mineScroller, BorderLayout.CENTER);

                JPanel available = new JPanel();
                available.setBorder(new EtchedBorder());
                available.setLayout(new BorderLayout());
                JLabel availableLabel = new JLabel("Available");
                Vector<String> availableGroups = new Vector<String>(state.getGlobalConfigGroups().keySet());
                availableGroups.removeAll(state.getSelected().getModel().getExtendsConfig());
                availableScroller = new JScrollPane(availableList = this
                        .createJList(availableModel = new DefaultListModel(), availableGroups));
                availableScroller.setPreferredSize(new Dimension(250, 80));
                available.add(availableLabel, BorderLayout.NORTH);
                available.add(availableScroller, BorderLayout.CENTER);

                JPanel buttons = new JPanel();
                buttons.setLayout(new BoxLayout(buttons, BoxLayout.Y_AXIS));
                JButton addButton = new JButton("<---");
                addButton.addMouseListener(new MouseListener() {

                    public void mouseClicked(MouseEvent e) {
                        String selected = availableList.getSelectedValue().toString();
                        Vector<String> extendsConfig = new Vector<String>(
                                state.getSelected().getModel().getExtendsConfig());
                        extendsConfig.add(selected);
                        state.getSelected().getModel().setExtendsConfig(extendsConfig);
                        availableModel.remove(availableList.getSelectedIndex());
                        mineModel.addElement(selected);
                        popup.revalidate();
                        DefaultPropView.this.notifyListeners();
                    }

                    public void mouseEntered(MouseEvent e) {
                    }

                    public void mouseExited(MouseEvent e) {
                    }

                    public void mousePressed(MouseEvent e) {
                    }

                    public void mouseReleased(MouseEvent e) {
                    }

                });
                JButton removeButton = new JButton("--->");
                removeButton.addMouseListener(new MouseListener() {

                    public void mouseClicked(MouseEvent e) {
                        String selected = mineList.getSelectedValue().toString();
                        Vector<String> extendsConfig = new Vector<String>(
                                state.getSelected().getModel().getExtendsConfig());
                        extendsConfig.remove(selected);
                        state.getSelected().getModel().setExtendsConfig(extendsConfig);
                        mineModel.remove(mineList.getSelectedIndex());
                        availableModel.addElement(selected);
                        popup.revalidate();
                        DefaultPropView.this.notifyListeners();
                    }

                    public void mouseEntered(MouseEvent e) {
                    }

                    public void mouseExited(MouseEvent e) {
                    }

                    public void mousePressed(MouseEvent e) {
                    }

                    public void mouseReleased(MouseEvent e) {
                    }

                });
                buttons.add(addButton);
                buttons.add(removeButton);

                main.add(mine);
                main.add(buttons);
                main.add(available);
                popup.add(main, BorderLayout.CENTER);
                popup.show(extendsLabel, e.getX(), e.getY());
            }

            public void mouseEntered(MouseEvent e) {
                extendsLabel.setForeground(Color.blue);
            }

            public void mouseExited(MouseEvent e) {
                extendsLabel.setForeground(Color.black);
            }

            public void mousePressed(MouseEvent e) {
            }

            public void mouseReleased(MouseEvent e) {
            }

            private JList createJList(DefaultListModel model, final List<String> list) {
                for (String value : list) {
                    model.addElement(value);
                }
                JList jList = new JList(model);
                jList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
                jList.setLayoutOrientation(JList.VERTICAL);
                return jList;
            }
        });
        JLabel metGroupLabel = new JLabel("(Sub-Group: "
                + (state.getCurrentMetGroup() != null ? state.getCurrentMetGroup() : "<base>") + ")");
        metGroupLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        JPanel labelPanel = new JPanel();
        labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));
        JPanel top = new JPanel();
        top.setLayout(new BoxLayout(top, BoxLayout.Y_AXIS));
        top.add(extendsLabel);
        top.add(metLabel);
        labelPanel.add(top);
        labelPanel.add(metGroupLabel);
        panel.add(labelPanel, BorderLayout.NORTH);
        panel.add(scrollPane, BorderLayout.CENTER);
        masterPanel.add(panel);
        this.add(masterPanel);
    } else {
        this.add(new JPanel());
    }
    this.revalidate();
}

From source file:org.broad.igv.hic.MainWindow.java

private void initComponents() {
    JPanel mainPanel = new JPanel();
    JPanel toolbarPanel = new JPanel();

    //======== this ========

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    mainPanel.setLayout(new BorderLayout());

    toolbarPanel.setBorder(null);//from  w  ww .j  ava  2 s .  c o  m
    toolbarPanel.setLayout(new GridLayout());

    JPanel chrSelectionPanel = new JPanel();
    chrSelectionPanel.setBorder(LineBorder.createGrayLineBorder());
    chrSelectionPanel.setMinimumSize(new Dimension(130, 57));
    chrSelectionPanel.setPreferredSize(new Dimension(130, 57));
    chrSelectionPanel.setLayout(new BorderLayout());

    JPanel panel10 = new JPanel();
    panel10.setBackground(new Color(204, 204, 204));
    panel10.setLayout(new BorderLayout());

    JLabel label3 = new JLabel();
    label3.setText("Chromosomes");
    label3.setHorizontalAlignment(SwingConstants.CENTER);
    panel10.add(label3, BorderLayout.CENTER);

    chrSelectionPanel.add(panel10, BorderLayout.PAGE_START);

    JPanel panel9 = new JPanel();
    panel9.setBackground(new Color(238, 238, 238));
    panel9.setLayout(new BoxLayout(panel9, BoxLayout.X_AXIS));

    //---- chrBox1 ----
    chrBox1 = new JComboBox();
    chrBox1.setModel(new DefaultComboBoxModel(new String[] { "All" }));
    chrBox1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            chrBox1ActionPerformed(e);
        }
    });
    panel9.add(chrBox1);

    //---- chrBox2 ----
    chrBox2 = new JComboBox();
    chrBox2.setModel(new DefaultComboBoxModel(new String[] { "All" }));
    chrBox2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            chrBox2ActionPerformed(e);
        }
    });
    panel9.add(chrBox2);

    //---- refreshButton ----
    JideButton refreshButton = new JideButton();
    refreshButton
            .setIcon(new ImageIcon(getClass().getResource("/toolbarButtonGraphics/general/Refresh24.gif")));
    refreshButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            refreshButtonActionPerformed(e);
        }
    });
    panel9.add(refreshButton);

    chrSelectionPanel.add(panel9, BorderLayout.CENTER);

    toolbarPanel.add(chrSelectionPanel);

    //======== displayOptionPanel ========
    JPanel displayOptionPanel = new JPanel();
    JPanel panel1 = new JPanel();
    displayOptionComboBox = new JComboBox();

    displayOptionPanel.setBackground(new Color(238, 238, 238));
    displayOptionPanel.setBorder(LineBorder.createGrayLineBorder());
    displayOptionPanel.setLayout(new BorderLayout());

    //======== panel14 ========

    JPanel panel14 = new JPanel();
    panel14.setBackground(new Color(204, 204, 204));
    panel14.setLayout(new BorderLayout());

    //---- label4 ----
    JLabel label4 = new JLabel();
    label4.setText("Show");
    label4.setHorizontalAlignment(SwingConstants.CENTER);
    panel14.add(label4, BorderLayout.CENTER);

    displayOptionPanel.add(panel14, BorderLayout.PAGE_START);

    //======== panel1 ========

    panel1.setBorder(new EmptyBorder(0, 10, 0, 10));
    panel1.setLayout(new GridLayout(1, 0, 20, 0));

    //---- comboBox1 ----
    displayOptionComboBox
            .setModel(new DefaultComboBoxModel(new String[] { DisplayOption.OBSERVED.toString() }));
    displayOptionComboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            displayOptionComboBoxActionPerformed(e);
        }
    });
    panel1.add(displayOptionComboBox);

    displayOptionPanel.add(panel1, BorderLayout.CENTER);

    toolbarPanel.add(displayOptionPanel);

    //======== colorRangePanel ========

    JPanel colorRangePanel = new JPanel();
    JLabel colorRangeLabel = new JLabel();
    colorRangeSlider = new RangeSlider();
    colorRangePanel.setBorder(LineBorder.createGrayLineBorder());
    colorRangePanel.setMinimumSize(new Dimension(96, 70));
    colorRangePanel.setPreferredSize(new Dimension(202, 70));
    colorRangePanel.setMaximumSize(new Dimension(32769, 70));
    colorRangePanel.setLayout(new BorderLayout());

    //======== panel11 ========

    JPanel colorLabelPanel = new JPanel();
    colorLabelPanel.setBackground(new Color(204, 204, 204));
    colorLabelPanel.setLayout(new BorderLayout());

    //---- colorRangeLabel ----
    colorRangeLabel.setText("Color Range");
    colorRangeLabel.setHorizontalAlignment(SwingConstants.CENTER);
    colorRangeLabel.setToolTipText("Range of color scale in counts per mega-base squared.");
    colorRangeLabel.setHorizontalTextPosition(SwingConstants.CENTER);
    colorRangeLabel.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                ColorRangeDialog rangeDialog = new ColorRangeDialog(MainWindow.this, colorRangeSlider);
                rangeDialog.setVisible(true);
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            ColorRangeDialog rangeDialog = new ColorRangeDialog(MainWindow.this, colorRangeSlider);
            rangeDialog.setVisible(true);
        }
    });
    colorLabelPanel.add(colorRangeLabel, BorderLayout.CENTER);

    colorRangePanel.add(colorLabelPanel, BorderLayout.PAGE_START);

    //---- colorRangeSlider ----
    colorRangeSlider.setPaintTicks(true);
    colorRangeSlider.setPaintLabels(true);
    colorRangeSlider.setLowerValue(0);
    colorRangeSlider.setMajorTickSpacing(500);
    colorRangeSlider.setMaximumSize(new Dimension(32767, 52));
    colorRangeSlider.setPreferredSize(new Dimension(200, 52));
    colorRangeSlider.setMinimumSize(new Dimension(36, 52));
    colorRangeSlider.setMaximum(2000);
    colorRangeSlider.setUpperValue(500);
    colorRangeSlider.setMinorTickSpacing(100);
    colorRangeSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            colorRangeSliderStateChanged(e);
        }
    });
    colorRangePanel.add(colorRangeSlider, BorderLayout.PAGE_END);

    //        JPanel colorRangeTextPanel = new JPanel();
    //        colorRangeTextPanel.setLayout(new FlowLayout());
    //        JTextField minField = new JTextField();
    //        minField.setPreferredSize(new Dimension(50, 15));
    //        colorRangeTextPanel.add(minField);
    //        colorRangeTextPanel.add(new JLabel(" - "));
    //        JTextField maxField = new JTextField();
    //        maxField.setPreferredSize(new Dimension(50, 15));
    //        colorRangeTextPanel.add(maxField);
    //        colorRangeTextPanel.setPreferredSize(new Dimension(200, 52));
    //        colorRangePanel.add(colorRangeTextPanel, BorderLayout.PAGE_END);

    toolbarPanel.add(colorRangePanel);

    //======== resolutionPanel ========

    JLabel resolutionLabel = new JLabel();
    JPanel resolutionPanel = new JPanel();

    resolutionPanel.setBorder(LineBorder.createGrayLineBorder());
    resolutionPanel.setLayout(new BorderLayout());

    //======== panel12 ========

    JPanel panel12 = new JPanel();
    panel12.setBackground(new Color(204, 204, 204));
    panel12.setLayout(new BorderLayout());

    //---- resolutionLabel ----
    resolutionLabel.setText("Resolution");
    resolutionLabel.setHorizontalAlignment(SwingConstants.CENTER);
    resolutionLabel.setBackground(new Color(204, 204, 204));
    panel12.add(resolutionLabel, BorderLayout.CENTER);

    resolutionPanel.add(panel12, BorderLayout.PAGE_START);

    //======== panel2 ========

    JPanel panel2 = new JPanel();
    panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS));

    //---- resolutionSlider ----
    resolutionSlider = new JSlider();
    resolutionSlider.setMaximum(8);
    resolutionSlider.setMajorTickSpacing(1);
    resolutionSlider.setPaintTicks(true);
    resolutionSlider.setSnapToTicks(true);
    resolutionSlider.setPaintLabels(true);
    resolutionSlider.setMinorTickSpacing(1);

    Dictionary<Integer, JLabel> resolutionLabels = new Hashtable<Integer, JLabel>();
    Font f = FontManager.getFont(8);
    for (int i = 0; i < HiCGlobals.zoomLabels.length; i++) {
        if ((i + 1) % 2 == 0) {
            final JLabel tickLabel = new JLabel(HiCGlobals.zoomLabels[i]);
            tickLabel.setFont(f);
            resolutionLabels.put(i, tickLabel);
        }
    }
    resolutionSlider.setLabelTable(resolutionLabels);
    // Setting the zoom should always be done by calling resolutionSlider.setValue() so work isn't done twice.
    resolutionSlider.addChangeListener(new ChangeListener() {
        // Change zoom level while staying centered on current location.
        // Centering is relative to the bounds of the data, which might not be the bounds of the window

        public void stateChanged(ChangeEvent e) {
            if (!resolutionSlider.getValueIsAdjusting()) {
                int idx = resolutionSlider.getValue();
                idx = Math.max(0, Math.min(idx, MAX_ZOOM));

                if (hic.zd != null && idx == hic.zd.getZoom()) {
                    // Nothing to do
                    return;
                }

                if (hic.xContext != null) {
                    int centerLocationX = (int) hic.xContext
                            .getChromosomePosition(getHeatmapPanel().getWidth() / 2);
                    int centerLocationY = (int) hic.yContext
                            .getChromosomePosition(getHeatmapPanel().getHeight() / 2);
                    hic.setZoom(idx, centerLocationX, centerLocationY, false);
                }
                //zoomInButton.setEnabled(newZoom < MAX_ZOOM);
                //zoomOutButton.setEnabled(newZoom > 0);
            }
        }
    });
    panel2.add(resolutionSlider);

    resolutionPanel.add(panel2, BorderLayout.CENTER);

    toolbarPanel.add(resolutionPanel);

    mainPanel.add(toolbarPanel, BorderLayout.NORTH);

    //======== hiCPanel ========

    final JPanel hiCPanel = new JPanel();
    hiCPanel.setLayout(new HiCLayout());

    //---- rulerPanel2 ----
    rulerPanel2 = new HiCRulerPanel(hic);
    rulerPanel2.setMaximumSize(new Dimension(4000, 50));
    rulerPanel2.setMinimumSize(new Dimension(1, 50));
    rulerPanel2.setPreferredSize(new Dimension(1, 50));
    rulerPanel2.setBorder(null);

    JPanel panel2_5 = new JPanel();
    panel2_5.setLayout(new BorderLayout());
    panel2_5.add(rulerPanel2, BorderLayout.SOUTH);

    trackPanel = new TrackPanel(hic);
    trackPanel.setMaximumSize(new Dimension(4000, 50));
    trackPanel.setPreferredSize(new Dimension(1, 50));
    trackPanel.setMinimumSize(new Dimension(1, 50));
    trackPanel.setBorder(null);

    //        trackPanelScrollpane = new JScrollPane();
    //        trackPanelScrollpane.getViewport().add(trackPanel);
    //        trackPanelScrollpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    //        trackPanelScrollpane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    //        trackPanelScrollpane.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 102)));
    //        trackPanelScrollpane.setBackground(new java.awt.Color(237, 237, 237));
    //        trackPanelScrollpane.setVisible(false);
    //        panel2_5.add(trackPanelScrollpane, BorderLayout.NORTH);
    //
    trackPanel.setVisible(false);
    panel2_5.add(trackPanel, BorderLayout.NORTH);

    hiCPanel.add(panel2_5, BorderLayout.NORTH);

    //---- rulerPanel1 ----
    rulerPanel1 = new HiCRulerPanel(hic);
    rulerPanel1.setMaximumSize(new Dimension(50, 4000));
    rulerPanel1.setPreferredSize(new Dimension(50, 500));
    rulerPanel1.setBorder(null);
    rulerPanel1.setMinimumSize(new Dimension(50, 1));
    hiCPanel.add(rulerPanel1, BorderLayout.WEST);

    //---- heatmapPanel ----
    heatmapPanel = new HeatmapPanel(this, hic);
    heatmapPanel.setBorder(LineBorder.createBlackLineBorder());
    heatmapPanel.setMaximumSize(new Dimension(500, 500));
    heatmapPanel.setMinimumSize(new Dimension(500, 500));
    heatmapPanel.setPreferredSize(new Dimension(500, 500));
    heatmapPanel.setBackground(new Color(238, 238, 238));
    hiCPanel.add(heatmapPanel, BorderLayout.CENTER);

    //======== panel8 ========

    JPanel rightSidePanel = new JPanel();
    rightSidePanel.setMaximumSize(new Dimension(120, 100));
    rightSidePanel.setBorder(new EmptyBorder(0, 10, 0, 0));
    rightSidePanel.setLayout(null);

    //---- thumbnailPanel ----
    thumbnailPanel = new ThumbnailPanel(this, hic);
    thumbnailPanel.setMaximumSize(new Dimension(100, 100));
    thumbnailPanel.setMinimumSize(new Dimension(100, 100));
    thumbnailPanel.setPreferredSize(new Dimension(100, 100));
    thumbnailPanel.setBorder(LineBorder.createBlackLineBorder());
    thumbnailPanel.setPreferredSize(new Dimension(100, 100));
    thumbnailPanel.setBounds(new Rectangle(new Point(20, 0), thumbnailPanel.getPreferredSize()));
    rightSidePanel.add(thumbnailPanel);

    //======== xPlotPanel ========

    xPlotPanel = new JPanel();
    xPlotPanel.setPreferredSize(new Dimension(250, 100));
    xPlotPanel.setLayout(null);

    rightSidePanel.add(xPlotPanel);
    xPlotPanel.setBounds(10, 100, xPlotPanel.getPreferredSize().width, 228);

    //======== yPlotPanel ========

    yPlotPanel = new JPanel();
    yPlotPanel.setPreferredSize(new Dimension(250, 100));
    yPlotPanel.setLayout(null);

    rightSidePanel.add(yPlotPanel);
    yPlotPanel.setBounds(10, 328, yPlotPanel.getPreferredSize().width, 228);

    // compute preferred size
    Dimension preferredSize = new Dimension();
    for (int i = 0; i < rightSidePanel.getComponentCount(); i++) {
        Rectangle bounds = rightSidePanel.getComponent(i).getBounds();
        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
    }
    Insets insets = rightSidePanel.getInsets();
    preferredSize.width += insets.right;
    preferredSize.height += insets.bottom;
    rightSidePanel.setMinimumSize(preferredSize);
    rightSidePanel.setPreferredSize(preferredSize);

    hiCPanel.add(rightSidePanel, BorderLayout.EAST);

    mainPanel.add(hiCPanel, BorderLayout.CENTER);

    contentPane.add(mainPanel, BorderLayout.CENTER);

    JMenuBar menuBar = createMenuBar(hiCPanel);
    contentPane.add(menuBar, BorderLayout.NORTH);

    // setup the glass pane to display a wait cursor when visible, and to grab all mouse events
    rootPane.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    rootPane.getGlassPane().addMouseListener(new MouseAdapter() {
    });

}

From source file:org.datacleaner.panels.WelcomePanel.java

private JComponent createContentPanel() {
    JComponent result = null;/*from   w  w  w.j a  v  a  2  s  . c om*/

    final String welcomePanelClassName = SystemProperties.getString(SystemProperties.UI_DESKTOP_WELCOME_PANEL,
            null);
    if (!Strings.isNullOrEmpty(welcomePanelClassName)) {
        final Injector injector = _dcModule.createInjectorBuilder().with(WelcomePanel.class, this)
                .createInjector();
        try {
            @SuppressWarnings("unchecked")
            final Class<? extends JComponent> componentClass = (Class<? extends JComponent>) Class
                    .forName(welcomePanelClassName);

            result = injector.getInstance(componentClass);
        } catch (Exception e) {
            logger.error("Failed to instantiate welcome panel class: {}", welcomePanelClassName, e);
        }
    }

    if (result == null) {
        result = new DCPanel();
        if (Version.isCommunityEdition()) {
            final JXEditorPane editorPane = new JXEditorPane("text/html",
                    "You're now using the <b>Community Edition</b> of DataCleaner.<br/><br/>"
                            + "We hope that you enjoy this free product. We encourage you to also check out the "
                            + "commercial DataCleaner editions which feature added functionality, "
                            + "helpful getting started wizards and commercial support. "
                            + "You can find more information about them online.");
            editorPane.setEditable(false);
            editorPane.setOpaque(false);
            editorPane.setFont(WidgetUtils.FONT_HEADER2);
            editorPane.setPreferredSize(new Dimension(DCSplashPanel.WIDTH_CONTENT, 120));

            final JButton tryProfessionalButton = WidgetFactory.createDefaultButton("Try professional edition",
                    IconUtils.APPLICATION_ICON);
            tryProfessionalButton
                    .addActionListener(new OpenBrowserAction("http://datacleaner.org/get_datacleaner"));

            final JButton readMoreButton = WidgetFactory.createDefaultButton("Compare the editions",
                    IconUtils.WEBSITE);
            readMoreButton.addActionListener(new OpenBrowserAction("http://datacleaner.org/editions"));

            final JButton discussionForumButton = WidgetFactory
                    .createDefaultButton("Visit the discussion forum", "images/menu/forum.png");
            discussionForumButton.setToolTipText(
                    "Visit the online discussion forum for questions and answers in the community");
            final OpenBrowserAction forumActionListener = new OpenBrowserAction("http://datacleaner.org/forum");
            discussionForumButton.addActionListener(forumActionListener);

            final JButton twitterButton = WidgetFactory.createDefaultButton(null, "images/menu/twitter.png");
            twitterButton.setToolTipText("Spread the message about #DataCleaner on Twitter");
            twitterButton.addActionListener(new OpenBrowserAction("https://twitter.com/intent/tweet?text="
                    + UrlEscapers.urlFormParameterEscaper().escape("I'm using @DataCleaner (v. "
                            + Version.getVersion() + ") for some really fancy #dataquality stuff!")));

            final JButton linkedInButton = WidgetFactory.createDefaultButton(null, "images/menu/linkedin.png");
            linkedInButton.setToolTipText("Join our LinkedIn group of users and professionals");
            linkedInButton
                    .addActionListener(new OpenBrowserAction("http://www.linkedin.com/groups?gid=3352784"));

            final JLabel loveFeedbackAnimation = new JLabel(
                    ImageManager.get().getImageIcon("images/window/we_love_community_and_feedback.gif"),
                    JLabel.LEFT);
            loveFeedbackAnimation.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            loveFeedbackAnimation.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    forumActionListener.actionPerformed(null);
                }
            });

            final DCPanel innerPanel = new DCPanel();
            innerPanel.setLayout(new VerticalLayout());
            innerPanel.setBorder(
                    new CompoundBorder(WidgetUtils.BORDER_LIST_ITEM_LEFT_ONLY, new EmptyBorder(0, 20, 0, 0)));
            innerPanel.add(editorPane);
            innerPanel.add(DCPanel.flow(tryProfessionalButton, readMoreButton));
            innerPanel.add(Box.createVerticalStrut(80));
            innerPanel.add(loveFeedbackAnimation);
            innerPanel.add(Box.createVerticalStrut(20));
            innerPanel.add(DCPanel.flow(discussionForumButton, twitterButton, linkedInButton));
            innerPanel.add(Box.createVerticalStrut(5));

            result.setLayout(new VerticalLayout());
            result.add(Box.createVerticalStrut(100));
            result.add(innerPanel);
        }
    }

    return wrapContent(result);
}