Example usage for javax.swing JTextArea setPreferredSize

List of usage examples for javax.swing JTextArea setPreferredSize

Introduction

In this page you can find the example usage for javax.swing JTextArea setPreferredSize.

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:ConfigFiles.java

public ConfigFiles(Dimension screensize) {
    //         initializeFileBrowser();
    paths = new JPanel();
    paths.setBackground(Color.WHITE);
    //paths.setBorder(BorderFactory.createTitledBorder("Paths"));
    paths.setLayout(null);/*from ww w  . j av a2s .  com*/
    paths.setPreferredSize(new Dimension(930, 1144));
    paths.setSize(new Dimension(930, 1144));
    paths.setMinimumSize(new Dimension(930, 1144));
    paths.setMaximumSize(new Dimension(930, 1144));
    //paths.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
    setLayout(null);
    ttcpath = new JTextField();
    addPanel("TestCase Source Path",
            "Master directory with the test cases that can" + " be run by the framework", ttcpath,
            RunnerRepository.TESTSUITEPATH, 10, true, null);
    tMasterXML = new JTextField();
    tUsers = new JTextField();

    addPanel("Projects Path", "Location of projects XML files", tUsers, RunnerRepository.REMOTEUSERSDIRECTORY,
            83, true, null);

    tSuites = new JTextField();
    addPanel("Predefined Suites Path", "Location of predefined suites", tSuites,
            RunnerRepository.PREDEFINEDSUITES, 156, true, null);

    testconfigpath = new JTextField();
    addPanel("Test Configuration Path", "Test Configuration path", testconfigpath,
            RunnerRepository.TESTCONFIGPATH, 303, true, null);

    tepid = new JTextField();
    addPanel("EP name File", "Location of the file that contains" + " the Ep name list", tepid,
            RunnerRepository.REMOTEEPIDDIR, 595, true, null);
    tlog = new JTextField();
    addPanel("Logs Path", "Location of the directory that stores the most recent log files."
            + " The files are re-used each Run.", tlog, RunnerRepository.LOGSPATH, 667, true, null);
    tsecondarylog = new JTextField();

    JPanel p = addPanel("Secondary Logs Path",
            "Location of the directory that archives copies of the most recent log files, with"
                    + " original file names appended with <.epoch time>",
            tsecondarylog, RunnerRepository.SECONDARYLOGSPATH, 930, true, null);
    logsenabled.setSelected(Boolean.parseBoolean(RunnerRepository.PATHENABLED));
    logsenabled.setBackground(Color.WHITE);
    p.add(logsenabled);

    JPanel p7 = new JPanel();
    p7.setBackground(Color.WHITE);
    TitledBorder border7 = BorderFactory.createTitledBorder("Log Files");
    border7.setTitleFont(new Font("Arial", Font.PLAIN, 14));
    border7.setBorder(BorderFactory.createLineBorder(new Color(150, 150, 150), 1));
    p7.setBorder(border7);
    p7.setLayout(new BoxLayout(p7, BoxLayout.Y_AXIS));
    p7.setBounds(80, 740, 800, 190);
    paths.add(p7);
    JTextArea log2 = new JTextArea("All the log files that will be monitored");
    log2.setWrapStyleWord(true);
    log2.setLineWrap(true);
    log2.setEditable(false);
    log2.setCursor(null);
    log2.setOpaque(false);
    log2.setFocusable(false);
    log2.setBorder(null);
    log2.setFont(new Font("Arial", Font.PLAIN, 12));
    log2.setBackground(getBackground());
    log2.setMaximumSize(new Dimension(170, 25));
    log2.setPreferredSize(new Dimension(170, 25));
    JPanel p71 = new JPanel();
    p71.setBackground(Color.WHITE);
    p71.setLayout(new GridLayout());
    p71.setMaximumSize(new Dimension(700, 13));
    p71.setPreferredSize(new Dimension(700, 13));
    p71.add(log2);
    JPanel p72 = new JPanel();
    p72.setBackground(Color.WHITE);
    p72.setLayout(new BoxLayout(p72, BoxLayout.Y_AXIS));
    trunning = new JTextField();
    p72.add(addField(trunning, "Running: ", 0));
    tdebug = new JTextField();
    p72.add(addField(tdebug, "Debug: ", 1));
    tsummary = new JTextField();
    p72.add(addField(tsummary, "Summary: ", 2));
    tinfo = new JTextField();
    p72.add(addField(tinfo, "Info: ", 3));
    tcli = new JTextField();
    p72.add(addField(tcli, "Cli: ", 4));
    p7.add(p71);
    p7.add(p72);
    libpath = new JTextField();

    addPanel("Library path", "Secondary user library path", libpath, RunnerRepository.REMOTELIBRARY, 229, true,
            null);

    JPanel p8 = new JPanel();
    p8.setBackground(Color.WHITE);
    TitledBorder border8 = BorderFactory.createTitledBorder("File");
    border8.setTitleFont(new Font("Arial", Font.PLAIN, 14));
    border8.setBorder(BorderFactory.createLineBorder(new Color(150, 150, 150), 1));
    p8.setBorder(border8);
    p8.setLayout(null);
    p8.setBounds(80, 1076, 800, 50);
    if (PermissionValidator.canChangeFWM()) {
        paths.add(p8);
    }
    JButton save = new JButton("Save");
    save.setToolTipText("Save and automatically load config");
    save.setBounds(490, 20, 70, 20);
    save.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            saveXML(false, "fwmconfig");
            loadConfig("fwmconfig.xml");
        }
    });
    p8.add(save);
    //         if(!PermissionValidator.canChangeFWM()){
    //             save.setEnabled(false);
    //         }
    JButton saveas = new JButton("Save as");
    saveas.setBounds(570, 20, 90, 20);
    saveas.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            String filename = CustomDialog.showInputDialog(JOptionPane.QUESTION_MESSAGE,
                    JOptionPane.OK_CANCEL_OPTION, ConfigFiles.this, "File Name", "Please enter file name");
            if (!filename.equals("NULL")) {
                saveXML(false, filename);
            }
        }
    });
    p8.add(saveas);

    final JButton loadXML = new JButton("Load Config");
    loadXML.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                String[] configs = RunnerRepository
                        .getRemoteFolderContent(RunnerRepository.USERHOME + "/twister/config/");
                JComboBox combo = new JComboBox(configs);
                int resp = (Integer) CustomDialog.showDialog(combo, JOptionPane.INFORMATION_MESSAGE,
                        JOptionPane.OK_CANCEL_OPTION, ConfigFiles.this, "Config", null);
                final String config;
                if (resp == JOptionPane.OK_OPTION)
                    config = combo.getSelectedItem().toString();
                else
                    config = null;
                if (config != null) {
                    new Thread() {
                        public void run() {
                            setEnabledTabs(false);
                            JFrame progress = new JFrame();
                            progress.setAlwaysOnTop(true);
                            progress.setLocation((int) loadXML.getLocationOnScreen().getX(),
                                    (int) loadXML.getLocationOnScreen().getY());
                            progress.setUndecorated(true);
                            JProgressBar bar = new JProgressBar();
                            bar.setIndeterminate(true);
                            progress.add(bar);
                            progress.pack();
                            progress.setVisible(true);
                            loadConfig(config);
                            progress.dispose();
                            setEnabledTabs(true);
                        }
                    }.start();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    loadXML.setBounds(670, 20, 120, 20);
    p8.add(loadXML);
    //         if(!PermissionValidator.canChangeFWM()){
    //             loadXML.setEnabled(false);
    //         }

    tdbfile = new JTextField();
    addPanel("Database XML path", "File location for database configuration", tdbfile,
            RunnerRepository.REMOTEDATABASECONFIGPATH + RunnerRepository.REMOTEDATABASECONFIGFILE, 375, true,
            null);
    temailfile = new JTextField();
    //         emailpanel = (JPanel)
    addPanel("Email XML path", "File location for email configuration", temailfile,
            RunnerRepository.REMOTEEMAILCONFIGPATH + RunnerRepository.REMOTEEMAILCONFIGFILE, 448, true, null)
                    .getParent();
    //paths.remove(emailpanel);

    //         emailpanel.setBounds(360,440,350,100);
    //         RunnerRepository.window.mainpanel.p4.getEmails().add(emailpanel);

    tglobalsfile = new JTextField();
    addPanel("Globals XML file", "File location for globals parameters", tglobalsfile,
            RunnerRepository.GLOBALSREMOTEFILE, 521, true, null);

    tceport = new JTextField();
    addPanel("Central Engine Port", "Central Engine port", tceport, RunnerRepository.getCentralEnginePort(),
            1003, false, null);
    //         traPort = new JTextField();
    //         addPanel("Resource Allocator Port","Resource Allocator Port",
    //                 traPort,RunnerRepository.getResourceAllocatorPort(),808,false,null);                
    //         thttpPort = new JTextField();
    //         addPanel("HTTP Server Port","HTTP Server Port",thttpPort,
    //                 RunnerRepository.getHTTPServerPort(),740,false,null);

    //paths.add(loadXML);

    if (!PermissionValidator.canChangeFWM()) {
        ttcpath.setEnabled(false);
        tMasterXML.setEnabled(false);
        tUsers.setEnabled(false);
        tepid.setEnabled(false);
        tSuites.setEnabled(false);
        tlog.setEnabled(false);
        trunning.setEnabled(false);
        tdebug.setEnabled(false);
        tsummary.setEnabled(false);
        tinfo.setEnabled(false);
        tcli.setEnabled(false);
        tdbfile.setEnabled(false);
        temailfile.setEnabled(false);
        tceport.setEnabled(false);
        libpath.setEnabled(false);
        tsecondarylog.setEnabled(false);
        testconfigpath.setEnabled(false);
        tglobalsfile.setEnabled(false);
        logsenabled.setEnabled(false);
    }

}

From source file:it.imtech.metadata.MetaUtility.java

/**
 * Metodo adibito alla creazione dinamica ricorsiva dell'interfaccia dei
 * metadati//from   w ww . j av  a 2 s.c  om
 *
 * @param submetadatas Map contente i metadati e i sottolivelli di metadati
 * @param vocabularies Map contenente i dati contenuti nel file xml
 * vocabulary.xml
 * @param parent Jpanel nel quale devono venir inseriti i metadati
 * @param level Livello corrente
 */
public void create_metadata_view(Map<Object, Metadata> submetadatas, JPanel parent, int level,
        final String panelname) throws Exception {
    ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader);
    int lenght = submetadatas.size();
    int labelwidth = 220;
    int i = 0;
    JButton addcontribute = null;

    for (Map.Entry<Object, Metadata> kv : submetadatas.entrySet()) {
        ArrayList<Component> tabobjects = new ArrayList<Component>();

        if (kv.getValue().MID == 17 || kv.getValue().MID == 23 || kv.getValue().MID == 18
                || kv.getValue().MID == 137) {
            continue;
        }

        //Crea un jpanel nuovo e fa appen su parent
        JPanel innerPanel = new JPanel(new MigLayout("fillx, insets 1 1 1 1"));
        innerPanel.setName("pannello" + level + i);

        i++;
        String datatype = kv.getValue().datatype.toString();

        if (kv.getValue().MID == 45) {
            JPanel choice = new JPanel(new MigLayout());

            JComboBox combo = addClassificationChoice(choice, kv.getValue().sequence, panelname);

            JLabel labelc = new JLabel();
            labelc.setText(Utility.getBundleString("selectclassif", bundle));
            labelc.setPreferredSize(new Dimension(100, 20));

            choice.add(labelc);

            findLastClassification(panelname);
            if (last_classification != 0 && classificationRemoveButton == null) {
                logger.info("Removing last clasification");
                classificationRemoveButton = new JButton("-");

                classificationRemoveButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent event) {
                        BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                        removeClassificationToMetadata(panelname);
                        BookImporter.getInstance().refreshMetadataTab(false, panelname);
                        findLastClassification(panelname); //update last_classification
                        BookImporter.getInstance().setCursor(null);
                    }
                });
                if (Integer.parseInt(kv.getValue().sequence) == last_classification) {
                    choice.add(classificationRemoveButton, "wrap, width :50:");
                }
            }

            if (classificationAddButton == null) {
                logger.info("Adding a new classification");
                choice.add(combo, "width 100:600:600");

                classificationAddButton = new JButton("+");

                classificationAddButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent event) {
                        BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                        addClassificationToMetadata(panelname);
                        BookImporter.getInstance().refreshMetadataTab(false, panelname);
                        BookImporter.getInstance().setCursor(null);
                    }
                });

                choice.add(classificationAddButton, "width :50:");
            } else {
                //choice.add(combo, "wrap,width 100:700:700");
                choice.add(combo, "width 100:700:700");
                if (Integer.parseInt(kv.getValue().sequence) == last_classification) {
                    choice.add(classificationRemoveButton, "wrap, width :50");
                }
            }
            parent.add(choice, "wrap,width 100:700:700");
            classificationMID = kv.getValue().MID;

            innerPanel.setName(panelname + "---ImPannelloClassif---" + kv.getValue().sequence);
            try {

                addClassification(innerPanel, classificationMID, kv.getValue().sequence, panelname);
            } catch (Exception ex) {
                logger.error("Errore nell'aggiunta delle classificazioni");
            }
            parent.add(innerPanel, "wrap, growx");
            BookImporter.policy.addIndexedComponent(combo);

            continue;
        }

        if (datatype.equals("Node")) {
            JLabel label = new JLabel();
            label.setText(kv.getValue().description);
            label.setPreferredSize(new Dimension(100, 20));

            int size = 16 - (level * 2);
            Font myFont = new Font("MS Sans Serif", Font.PLAIN, size);
            label.setFont(myFont);

            if (Integer.toString(kv.getValue().MID).equals("11")) {
                JPanel temppanel = new JPanel(new MigLayout());

                //update last_contribute
                findLastContribute(panelname);

                if (last_contribute != 0 && removeContribute == null) {
                    logger.info("Removing last contribute");
                    removeContribute = new JButton("-");

                    removeContribute.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent event) {
                            BookImporter.getInstance()
                                    .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                            removeContributorToMetadata(panelname);
                            BookImporter.getInstance().refreshMetadataTab(false, panelname);
                            BookImporter.getInstance().setCursor(null);
                        }
                    });

                    if (!kv.getValue().sequence.equals("")) {
                        if (Integer.parseInt(kv.getValue().sequence) == last_contribute) {
                            innerPanel.add(removeContribute, "width :50:");
                        }
                    }
                }

                if (addcontribute == null) {
                    logger.info("Adding a new contribute");
                    addcontribute = new JButton("+");

                    addcontribute.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent event) {
                            BookImporter.getInstance()
                                    .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                            addContributorToMetadata(panelname);
                            BookImporter.getInstance().refreshMetadataTab(false, panelname);
                            BookImporter.getInstance().setCursor(null);
                        }
                    });

                    temppanel.add(label, " width :200:");
                    temppanel.add(addcontribute, "width :50:");
                    innerPanel.add(temppanel, "wrap, growx");
                } else {
                    temppanel.add(label, " width :200:");
                    findLastContribute(panelname);
                    if (!kv.getValue().sequence.equals("")) {
                        if (Integer.parseInt(kv.getValue().sequence) == last_contribute) {
                            temppanel.add(removeContribute, "width :50:");
                        }
                    }
                    innerPanel.add(temppanel, "wrap, growx");
                }
            } else if (Integer.toString(kv.getValue().MID).equals("115")) {
                logger.info("Devo gestire una provenience!");
            }
        } else {
            String title = "";

            if (kv.getValue().mandatory.equals("Y") || kv.getValue().MID == 14 || kv.getValue().MID == 15) {
                title = kv.getValue().description + " *";
            } else {
                title = kv.getValue().description;
            }

            innerPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title,
                    TitledBorder.LEFT, TitledBorder.TOP));

            if (datatype.equals("Vocabulary")) {
                TreeMap<String, String> entryCombo = new TreeMap<String, String>();
                int index = 0;
                String selected = null;

                if (!Integer.toString(kv.getValue().MID).equals("8"))
                    entryCombo.put(Utility.getBundleString("comboselect", bundle),
                            Utility.getBundleString("comboselect", bundle));

                for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) {
                    String tempmid = Integer.toString(kv.getValue().MID);

                    if (Integer.toString(kv.getValue().MID_parent).equals("11")
                            || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                        String[] testmid = tempmid.split("---");
                        tempmid = testmid[0];
                    }

                    if (vc.getKey().equals(tempmid)) {
                        TreeMap<String, VocEntry> iEntry = vc.getValue();

                        for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) {
                            entryCombo.put(ivc.getValue().description, ivc.getValue().ID);
                            if (kv.getValue().value != null) {
                                if (kv.getValue().value.equals(ivc.getValue().ID)) {
                                    selected = ivc.getValue().ID;
                                }
                            }
                            index++;
                        }
                    }
                }

                final ComboMapImpl model = new ComboMapImpl();
                model.setVocabularyCombo(true);
                model.putAll(entryCombo);

                final JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                if (Integer.toString(kv.getValue().MID_parent).equals("11")
                        || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                    voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence);
                } else {
                    voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                }

                if (Integer.toString(kv.getValue().MID).equals("8") && selected == null)
                    selected = "44";

                selected = (selected == null) ? Utility.getBundleString("comboselect", bundle) : selected;

                for (int k = 0; k < voc.getItemCount(); k++) {
                    Map.Entry<String, String> el = (Map.Entry<String, String>) voc.getItemAt(k);
                    if (el.getValue().equals(selected))
                        voc.setSelectedIndex(k);
                }

                voc.setPreferredSize(new Dimension(150, 30));
                innerPanel.add(voc, "wrap, width :400:");
                tabobjects.add(voc);
            } else if (datatype.equals("CharacterString") || datatype.equals("GPS")) {
                final JTextArea textField = new javax.swing.JTextArea();

                if (Integer.toString(kv.getValue().MID_parent).equals("11")
                        || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                    textField.setName(
                            "MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence);
                } else {
                    textField.setName("MID_" + Integer.toString(kv.getValue().MID));
                }

                textField.setPreferredSize(new Dimension(230, 0));
                textField.setText(kv.getValue().value);
                textField.setLineWrap(true);
                textField.setWrapStyleWord(true);

                innerPanel.add(textField, "wrap, width :300:");

                textField.addKeyListener(new KeyAdapter() {
                    @Override
                    public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode() == KeyEvent.VK_TAB) {
                            if (e.getModifiers() > 0) {
                                textField.transferFocusBackward();
                            } else {
                                textField.transferFocus();
                            }
                            e.consume();
                        }
                    }
                });

                tabobjects.add(textField);
            } else if (datatype.equals("LangString")) {
                JScrollPane inner_scroll = new javax.swing.JScrollPane();
                inner_scroll.setHorizontalScrollBarPolicy(
                        javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
                inner_scroll.setVerticalScrollBarPolicy(
                        javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
                inner_scroll.setPreferredSize(new Dimension(240, 80));
                inner_scroll.setName("langStringScroll");
                final JTextArea jTextArea1 = new javax.swing.JTextArea();
                jTextArea1.setName("MID_" + Integer.toString(kv.getValue().MID));
                jTextArea1.setText(kv.getValue().value);

                jTextArea1.setSize(new Dimension(350, 70));
                jTextArea1.setLineWrap(true);
                jTextArea1.setWrapStyleWord(true);

                inner_scroll.setViewportView(jTextArea1);
                innerPanel.add(inner_scroll, "width :300:");

                //Add combo language box
                JComboBox voc = getComboLangBox(kv.getValue().language);
                voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "_lang");

                voc.setPreferredSize(new Dimension(200, 20));
                innerPanel.add(voc, "wrap, width :300:");

                jTextArea1.addKeyListener(new KeyAdapter() {
                    @Override
                    public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode() == KeyEvent.VK_TAB) {
                            if (e.getModifiers() > 0) {
                                jTextArea1.transferFocusBackward();
                            } else {
                                jTextArea1.transferFocus();
                            }
                            e.consume();
                        }
                    }
                });
                tabobjects.add(jTextArea1);
                tabobjects.add(voc);
            } else if (datatype.equals("Language")) {
                final JComboBox voc = getComboLangBox(kv.getValue().value);
                voc.setName("MID_" + Integer.toString(kv.getValue().MID));

                voc.setPreferredSize(new Dimension(150, 20));
                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :500:");

                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);

            } else if (datatype.equals("Boolean")) {
                int selected = 0;
                TreeMap bin = new TreeMap<String, String>();
                bin.put("yes", Utility.getBundleString("voc1", bundle));
                bin.put("no", Utility.getBundleString("voc2", bundle));

                if (kv.getValue().value == null) {
                    switch (kv.getValue().MID) {
                    case 35:
                        selected = 0;
                        break;
                    case 36:
                        selected = 1;
                        break;
                    }
                } else if (kv.getValue().value.equals("yes")) {
                    selected = 1;
                } else {
                    selected = 0;
                }

                final ComboMapImpl model = new ComboMapImpl();
                model.putAll(bin);

                final JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                voc.setSelectedIndex(selected);

                voc.setPreferredSize(new Dimension(150, 20));
                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :300:");
                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);
            } else if (datatype.equals("License")) {
                String selectedIndex = null;
                int vindex = 0;
                int defaultIndex = 0;

                TreeMap<String, String> entryCombo = new TreeMap<String, String>();

                for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) {
                    if (vc.getKey().equals(Integer.toString(kv.getValue().MID))) {
                        TreeMap<String, VocEntry> iEntry = vc.getValue();

                        for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) {
                            entryCombo.put(ivc.getValue().description, ivc.getValue().ID);

                            if (ivc.getValue().ID.equals("1"))
                                defaultIndex = vindex;

                            if (kv.getValue().value != null) {
                                if (ivc.getValue().ID.equals(kv.getValue().value)) {
                                    selectedIndex = Integer.toString(vindex);
                                }
                            }
                            vindex++;
                        }
                    }
                }

                if (selectedIndex == null)
                    selectedIndex = Integer.toString(defaultIndex);

                ComboMapImpl model = new ComboMapImpl();
                model.putAll(entryCombo);
                model.setVocabularyCombo(true);

                JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                voc.setSelectedIndex(Integer.parseInt(selectedIndex));
                voc.setPreferredSize(new Dimension(150, 20));

                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :500:");
                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);
            } else if (datatype.equals("DateTime")) {
                //final JXDatePicker datePicker = new JXDatePicker();
                JDateChooser datePicker = new JDateChooser();
                datePicker.setName("MID_" + Integer.toString(kv.getValue().MID));

                JPanel test = new JPanel(new MigLayout());
                JLabel lbefore = new JLabel(Utility.getBundleString("beforechristlabel", bundle));
                JCheckBox beforechrist = new JCheckBox();
                beforechrist.setName("MID_" + Integer.toString(kv.getValue().MID) + "_check");

                if (kv.getValue().value != null) {
                    try {
                        if (kv.getValue().value.charAt(0) == '-') {
                            beforechrist.setSelected(true);
                        }

                        Date date1 = new Date();
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        if (kv.getValue().value.charAt(0) == '-') {
                            date1 = sdf.parse(adjustDate(kv.getValue().value));
                        } else {
                            date1 = sdf.parse(kv.getValue().value);
                        }
                        datePicker.setDate(date1);
                    } catch (Exception e) {
                        //Console.WriteLine("ERROR import date:" + ex.Message);
                    }
                }

                test.add(datePicker, "width :200:");
                test.add(lbefore, "gapleft 30");
                test.add(beforechrist, "wrap");

                innerPanel.add(test, "wrap");
            }
        }

        //Recursive call
        create_metadata_view(kv.getValue().submetadatas, innerPanel, level + 1, panelname);

        if (kv.getValue().editable.equals("Y")
                || (datatype.equals("Node") && kv.getValue().hidden.equals("0"))) {
            parent.add(innerPanel, "wrap, growx");

            for (Component tabobject : tabobjects) {
                BookImporter.policy.addIndexedComponent(tabobject);
            }
        }
    }
}

From source file:org.kepler.gui.ComponentLibraryPreferencesTab.java

/**
 * Initialize the top panel that contains controls for the table.
 *///w w w. j a  va 2  s .  c  o  m
private void initDoc() {

    String header = StaticResources.getDisplayString("preferences.description1",
            "The Component Library is built using KAR files found"
                    + " in the following local directories.  Adding or removing local directories will rebuild"
                    + " the component library.")
            + "\n\n"
            + StaticResources.getDisplayString("preferences.description2",
                    "By selecting the search box next to remote"
                            + " repositories, components from the remote repositories will be included"
                            + " when searching components.")
            + "\n\n"
            + StaticResources.getDisplayString("preferences.description3",
                    "By selecting the save box next to a local repository, KAR files will be saved"
                            + " to that directory by default.")
            + "\n\n"
            + StaticResources.getDisplayString("preferences.description4",
                    "By selecting the save box next to a remote repository, you will be asked "
                            + " if you want to upload the KAR to that repository when it is saved.");

    JTextArea headerTextArea = new JTextArea(header);
    headerTextArea.setEditable(false);
    headerTextArea.setLineWrap(true);
    headerTextArea.setWrapStyleWord(true);
    headerTextArea.setPreferredSize(new Dimension(300, 400));
    headerTextArea.setBackground(TabManager.BGCOLOR);
    JPanel headerPanel = new JPanel(new BorderLayout());
    headerPanel.setBackground(TabManager.BGCOLOR);
    headerPanel.add(headerTextArea, BorderLayout.CENTER);
    JScrollPane headerPane = new JScrollPane(headerPanel);
    headerPane.setPreferredSize(new Dimension(300, 150));

    add(headerPane);
}

From source file:tvbrowser.TVBrowser.java

/**
 * Entry point of the application//w ww . jav  a2  s  .c  o  m
 * @param args The arguments given in the command line.
 */
public static void main(String[] args) {
    // Read the command line parameters
    parseCommandline(args);

    try {
        Toolkit.getDefaultToolkit().setDynamicLayout(
                (Boolean) Toolkit.getDefaultToolkit().getDesktopProperty("awt.dynamicLayoutSupported"));
    } catch (Exception e) {
        e.printStackTrace();
    }

    mLocalizer = util.ui.Localizer.getLocalizerFor(TVBrowser.class);

    // Check whether the TV-Browser was started in the right directory
    if (!new File("imgs").exists()) {
        String msg = "Please start TV-Browser in the TV-Browser directory!";
        if (mLocalizer != null) {
            msg = mLocalizer.msg("error.2", "Please start TV-Browser in the TV-Browser directory!");
        }
        JOptionPane.showMessageDialog(null, msg);
        System.exit(1);
    }

    if (mIsTransportable) {
        System.getProperties().remove("propertiesfile");
    }

    // setup logging

    // Get the default Logger
    Logger mainLogger = Logger.getLogger("");

    // Use a even simpler Formatter for console logging
    mainLogger.getHandlers()[0].setFormatter(createFormatter());

    if (mIsTransportable) {
        File settingsDir = new File("settings");
        try {
            File test = File.createTempFile("write", "test", settingsDir);
            test.delete();
        } catch (IOException e) {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (Exception e1) {
                //ignore
            }

            JTextArea area = new JTextArea(mLocalizer.msg("error.noWriteRightsText",
                    "You are using the transportable version of TV-Browser but you have no writing rights in the settings directory:\n\n{0}'\n\nTV-Browser will be closed.",
                    settingsDir.getAbsolutePath()));
            area.setFont(new JLabel().getFont());
            area.setFont(area.getFont().deriveFont((float) 14).deriveFont(Font.BOLD));
            area.setLineWrap(true);
            area.setWrapStyleWord(true);
            area.setPreferredSize(new Dimension(500, 100));
            area.setEditable(false);
            area.setBorder(null);
            area.setOpaque(false);

            JOptionPane.showMessageDialog(null, area,
                    mLocalizer.msg("error.noWriteRightsTitle", "No write rights in settings directory"),
                    JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
    }

    // Load the settings
    Settings.loadSettings();
    Locale.setDefault(new Locale(Settings.propLanguage.getString(), Settings.propCountry.getString()));

    if (Settings.propFirstStartDate.getDate() == null) {
        Settings.propFirstStartDate.setDate(Date.getCurrentDate());
    }

    if (!createLockFile()) {
        updateLookAndFeel();
        showTVBrowserIsAlreadyRunningMessageBox();
    }

    String logDirectory = Settings.propLogdirectory.getString();
    if (logDirectory != null) {
        try {
            File logDir = new File(logDirectory);
            logDir.mkdirs();
            mainLogger.addHandler(
                    new FileLoggingHandler(logDir.getAbsolutePath() + "/tvbrowser.log", createFormatter()));
        } catch (IOException exc) {
            String msg = mLocalizer.msg("error.4", "Can't create log file.");
            ErrorHandler.handle(msg, exc);
        }
    } else {
        // if no logging is configured, show WARNING or worse for normal usage, show everything for unstable versions
        if (TVBrowser.isStable()) {
            mainLogger.setLevel(Level.WARNING);
        }
    }

    // log warning for OpenJDK users
    if (!isJavaImplementationSupported()) {
        mainLogger.warning(SUN_JAVA_WARNING);
    }

    //Update plugin on version change
    if (Settings.propTVBrowserVersion.getVersion() != null
            && VERSION.compareTo(Settings.propTVBrowserVersion.getVersion()) > 0) {
        updateLookAndFeel();
        updatePluginsOnVersionChange();
    }

    // Capture unhandled exceptions
    //System.setErr(new PrintStream(new MonitoringErrorStream()));

    String timezone = Settings.propTimezone.getString();
    if (timezone != null) {
        TimeZone.setDefault(TimeZone.getTimeZone(timezone));
    }
    mLog.info("Using timezone " + TimeZone.getDefault().getDisplayName());

    // refresh the localizers because we know the language now
    Localizer.emptyLocalizerCache();
    mLocalizer = Localizer.getLocalizerFor(TVBrowser.class);
    ProgramInfo.resetLocalizer();
    ReminderPlugin.resetLocalizer();
    Date.resetLocalizer();
    ProgramFieldType.resetLocalizer();

    // Set the proxy settings
    updateProxySettings();

    // Set the String to use for indicating the user agent in http requests
    System.setProperty("http.agent", MAINWINDOW_TITLE);

    Version tmpVer = Settings.propTVBrowserVersion.getVersion();
    final Version currentVersion = tmpVer != null
            ? new Version(tmpVer.getMajor(), tmpVer.getMinor(),
                    Settings.propTVBrowserVersionIsStable.getBoolean())
            : tmpVer;

    /*TODO Create an update service for installed TV data services that doesn't
     *     work with TV-Browser 3.0 and updates for them are known.
     */
    if (!isTransportable() && Launch.isOsWindowsNtBranch() && currentVersion != null
            && currentVersion.compareTo(new Version(3, 0, true)) < 0) {
        String tvDataDir = Settings.propTVDataDirectory.getString().replace("/", File.separator);

        if (!tvDataDir.startsWith(System.getenv("appdata"))) {
            StringBuilder oldDefaultTvDataDir = new StringBuilder(System.getProperty("user.home"))
                    .append(File.separator).append("TV-Browser").append(File.separator).append("tvdata");

            if (oldDefaultTvDataDir.toString().equals(tvDataDir)) {
                Settings.propTVDataDirectory.setString(Settings.propTVDataDirectory.getDefault());
            }
        }
    }

    Settings.propTVBrowserVersion.setVersion(VERSION);
    Settings.propTVBrowserVersionIsStable.setBoolean(VERSION.isStable());

    final Splash splash;

    if (mShowSplashScreen && Settings.propSplashShow.getBoolean()) {
        splash = new SplashScreen(Settings.propSplashImage.getString(), Settings.propSplashTextPosX.getInt(),
                Settings.propSplashTextPosY.getInt(), Settings.propSplashForegroundColor.getColor());
    } else {
        splash = new DummySplash();
    }
    splash.showSplash();

    /* Initialize the MarkedProgramsList */
    MarkedProgramsList.getInstance();

    /*Maybe there are tvdataservices to install (.jar.inst files)*/
    PluginLoader.getInstance().installPendingPlugins();

    PluginLoader.getInstance().loadAllPlugins();

    mLog.info("Loading TV listings service...");
    splash.setMessage(mLocalizer.msg("splash.dataService", "Loading TV listings service..."));
    TvDataServiceProxyManager.getInstance().init();
    ChannelList.createForTvBrowserStart();

    ChannelList.initSubscribedChannels();

    if (!lookAndFeelInitialized) {
        mLog.info("Loading Look&Feel...");
        splash.setMessage(mLocalizer.msg("splash.laf", "Loading look and feel..."));

        updateLookAndFeel();
    }

    mLog.info("Loading plugins...");
    splash.setMessage(mLocalizer.msg("splash.plugins", "Loading plugins..."));
    try {
        PluginProxyManager.getInstance().init();
    } catch (TvBrowserException exc) {
        ErrorHandler.handle(exc);
    }

    splash.setMessage(mLocalizer.msg("splash.tvData", "Checking TV database..."));

    mLog.info("Checking TV listings inventory...");
    TvDataBase.getInstance().checkTvDataInventory();

    mLog.info("Starting up...");
    splash.setMessage(mLocalizer.msg("splash.ui", "Starting up..."));

    Toolkit.getDefaultToolkit().getSystemEventQueue().push(new TextComponentPopupEventQueue());

    // Init the UI
    final boolean fStartMinimized = Settings.propMinimizeAfterStartup.getBoolean() || mMinimized;
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            initUi(splash, fStartMinimized);

            new Thread("Start finished callbacks") {
                public void run() {
                    setPriority(Thread.MIN_PRIORITY);

                    mLog.info("Deleting expired TV listings...");
                    TvDataBase.getInstance().deleteExpiredFiles(1, false);

                    // first reset "starting" flag of mainframe
                    mainFrame.handleTvBrowserStartFinished();

                    // initialize program info for fast reaction to program table click
                    ProgramInfo.getInstance().handleTvBrowserStartFinished();

                    // load reminders and favorites
                    ReminderPlugin.getInstance().handleTvBrowserStartFinished();
                    FavoritesPlugin.getInstance().handleTvBrowserStartFinished();

                    // now handle all plugins and services
                    GlobalPluginProgramFormatingManager.getInstance();
                    PluginProxyManager.getInstance().fireTvBrowserStartFinished();
                    TvDataServiceProxyManager.getInstance().fireTvBrowserStartFinished();

                    // finally submit plugin caused updates to database
                    TvDataBase.getInstance().handleTvBrowserStartFinished();

                    startPeriodicSaveSettings();

                }
            }.start();
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    ChannelList.completeChannelLoading();
                    initializeAutomaticDownload();
                    if (Launch.isOsWindowsNtBranch()) {
                        try {
                            RegistryKey desktopSettings = new RegistryKey(RootKey.HKEY_CURRENT_USER,
                                    "Control Panel\\Desktop");
                            RegistryValue autoEnd = desktopSettings.getValue("AutoEndTasks");

                            if (autoEnd.getData().equals("1")) {
                                RegistryValue killWait = desktopSettings.getValue("WaitToKillAppTimeout");

                                int i = Integer.parseInt(killWait.getData().toString());

                                if (i < 5000) {
                                    JOptionPane pane = new JOptionPane();

                                    String cancel = mLocalizer.msg("registryCancel", "Close TV-Browser");
                                    String dontDoIt = mLocalizer.msg("registryJumpOver", "Not this time");

                                    pane.setOptions(new String[] { Localizer.getLocalization(Localizer.I18N_OK),
                                            dontDoIt, cancel });
                                    pane.setOptionType(JOptionPane.YES_NO_CANCEL_OPTION);
                                    pane.setMessageType(JOptionPane.WARNING_MESSAGE);
                                    pane.setMessage(mLocalizer.msg("registryWarning",
                                            "The fast shutdown of Windows is activated.\nThe timeout to wait for before Windows is closing an application is too short,\nto give TV-Browser enough time to save all settings.\n\nThe setting hasn't the default value. It was changed by a tool or by you.\nTV-Browser will now try to change the timeout.\n\nIf you don't want to change this timeout select 'Not this time' or 'Close TV-Browser'."));

                                    pane.setInitialValue(mLocalizer.msg("registryCancel", "Close TV-Browser"));

                                    JDialog d = pane.createDialog(UiUtilities.getLastModalChildOf(mainFrame),
                                            UIManager.getString("OptionPane.messageDialogTitle"));
                                    d.setModal(true);
                                    UiUtilities.centerAndShow(d);

                                    if (pane.getValue() == null || pane.getValue().equals(cancel)) {
                                        mainFrame.quit();
                                    } else if (!pane.getValue().equals(dontDoIt)) {
                                        try {
                                            killWait.setData("5000");
                                            desktopSettings.setValue(killWait);
                                            JOptionPane.showMessageDialog(
                                                    UiUtilities.getLastModalChildOf(mainFrame),
                                                    mLocalizer.msg("registryChanged",
                                                            "The timeout was changed successfully.\nPlease reboot Windows!"));
                                        } catch (Exception registySetting) {
                                            JOptionPane.showMessageDialog(
                                                    UiUtilities.getLastModalChildOf(mainFrame),
                                                    mLocalizer.msg("registryNotChanged",
                                                            "<html>The Registry value couldn't be changed. Maybe you haven't the right to do it.<br>If it is so contact you Administrator and let him do it for you.<br><br><b><Attention:/b> The following description is for experts. If you change or delete the wrong value in the Registry you could destroy your Windows installation.<br><br>To get no warning on TV-Browser start the Registry value <b>WaitToKillAppTimeout</b> in the Registry path<br><b>HKEY_CURRENT_USER\\Control Panel\\Desktop</b> have to be at least <b>5000</b> or the value for <b>AutoEndTasks</b> in the same path have to be <b>0</b>.</html>"),
                                                    Localizer.getLocalization(Localizer.I18N_ERROR),
                                                    JOptionPane.ERROR_MESSAGE);
                                        }
                                    }
                                }
                            }
                        } catch (Throwable registry) {
                        }
                    }

                    if (currentVersion != null && currentVersion.compareTo(new Version(2, 71, false)) < 0) {
                        if (Settings.propProgramPanelMarkedMinPriorityColor.getColor()
                                .equals(Settings.propProgramPanelMarkedMinPriorityColor.getDefaultColor())) {
                            Settings.propProgramPanelMarkedMinPriorityColor.setColor(new Color(255, 0, 0, 30));
                        }
                        if (Settings.propProgramPanelMarkedMediumPriorityColor.getColor()
                                .equals(Settings.propProgramPanelMarkedMediumPriorityColor.getDefaultColor())) {
                            Settings.propProgramPanelMarkedMediumPriorityColor
                                    .setColor(new Color(140, 255, 0, 60));
                        }
                        if (Settings.propProgramPanelMarkedHigherMediumPriorityColor.getColor().equals(
                                Settings.propProgramPanelMarkedHigherMediumPriorityColor.getDefaultColor())) {
                            Settings.propProgramPanelMarkedHigherMediumPriorityColor
                                    .setColor(new Color(255, 255, 0, 60));
                        }
                        if (Settings.propProgramPanelMarkedMaxPriorityColor.getColor()
                                .equals(Settings.propProgramPanelMarkedMaxPriorityColor.getDefaultColor())) {
                            Settings.propProgramPanelMarkedMaxPriorityColor
                                    .setColor(new Color(255, 180, 0, 110));
                        }
                    }

                    // check if user should select picture settings
                    if (currentVersion != null && currentVersion.compareTo(new Version(2, 22)) < 0) {
                        TvBrowserPictureSettingsUpdateDialog.createAndShow(mainFrame);
                    } else if (currentVersion != null
                            && currentVersion.compareTo(new Version(2, 51, true)) < 0) {
                        Settings.propAcceptedLicenseArrForServiceIds.setStringArray(new String[0]);
                    }

                    if (currentVersion != null && currentVersion.compareTo(new Version(2, 60, true)) < 0) {
                        int startOfDay = Settings.propProgramTableStartOfDay.getInt();
                        int endOfDay = Settings.propProgramTableEndOfDay.getInt();

                        if (endOfDay - startOfDay < -1) {
                            Settings.propProgramTableEndOfDay.setInt(startOfDay);

                            JOptionPane.showMessageDialog(UiUtilities.getLastModalChildOf(mainFrame),
                                    mLocalizer.msg("timeInfoText",
                                            "The time range of the program table was corrected because the defined day was shorter than 24 hours.\n\nIf the program table should show less than 24h use a time filter for that. That time filter can be selected\nto be the default filter by selecting it in the filter settings and pressing on the button 'Default'."),
                                    mLocalizer.msg("timeInfoTitle", "Times corrected"),
                                    JOptionPane.INFORMATION_MESSAGE);
                            Settings.handleChangedSettings();
                        }
                    }
                    MainFrame.getInstance().getProgramTableScrollPane().requestFocusInWindow();
                }
            });
        }
    });

    // register the shutdown hook
    Runtime.getRuntime().addShutdownHook(new Thread("Shutdown hook") {
        public void run() {
            deleteLockFile();
            MainFrame.getInstance().quit(false);
        }
    });
}