List of usage examples for javax.swing JComboBox setSelectedItem
@BeanProperty(bound = false, preferred = true, description = "Sets the selected item in the JComboBox.") public void setSelectedItem(Object anObject)
From source file:com.nikonhacker.gui.EmulatorUI.java
private void openChipOptionsDialog(final int chip) { // ------------------------ Disassembly options JPanel disassemblyOptionsPanel = new JPanel(new MigLayout("", "[left,grow][left,grow]")); // Prepare sample code area final RSyntaxTextArea listingArea = new RSyntaxTextArea(20, 90); SourceCodeFrame.prepareAreaFormat(chip, listingArea); final List<JCheckBox> outputOptionsCheckBoxes = new ArrayList<JCheckBox>(); ActionListener areaRefresherListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { Set<OutputOption> sampleOptions = EnumSet.noneOf(OutputOption.class); dumpOptionCheckboxes(outputOptionsCheckBoxes, sampleOptions); int baseAddress = framework.getPlatform(chip).getCpuState().getResetAddress(); int lastAddress = baseAddress; Memory sampleMemory = new DebuggableMemory(false); sampleMemory.map(baseAddress, 0x100, true, true, true); StringWriter writer = new StringWriter(); Disassembler disassembler; if (chip == Constants.CHIP_FR) { sampleMemory.store16(lastAddress, 0x1781); // PUSH RP lastAddress += 2;/*from w ww .j a v a2 s . co m*/ sampleMemory.store16(lastAddress, 0x8FFE); // PUSH (FP,AC,R12,R11,R10,R9,R8) lastAddress += 2; sampleMemory.store16(lastAddress, 0x83EF); // ANDCCR #0xEF lastAddress += 2; sampleMemory.store16(lastAddress, 0x9F80); // LDI:32 #0x68000000,R0 lastAddress += 2; sampleMemory.store16(lastAddress, 0x6800); lastAddress += 2; sampleMemory.store16(lastAddress, 0x0000); lastAddress += 2; sampleMemory.store16(lastAddress, 0x2031); // LD @(FP,0x00C),R1 lastAddress += 2; sampleMemory.store16(lastAddress, 0xB581); // LSL #24,R1 lastAddress += 2; sampleMemory.store16(lastAddress, 0x1A40); // DMOVB R13,@0x40 lastAddress += 2; sampleMemory.store16(lastAddress, 0x9310); // ORCCR #0x10 lastAddress += 2; sampleMemory.store16(lastAddress, 0x8D7F); // POP (R8,R9,R10,R11,R12,AC,FP) lastAddress += 2; sampleMemory.store16(lastAddress, 0x0781); // POP RP lastAddress += 2; disassembler = new Dfr(); disassembler.setDebugPrintWriter(new PrintWriter(new StringWriter())); // Ignore disassembler.setOutputFileName(null); disassembler.processOptions(new String[] { "-m", "0x" + Format.asHex(baseAddress, 8) + "-0x" + Format.asHex(lastAddress, 8) + "=CODE" }); } else { sampleMemory.store32(lastAddress, 0x340B0001); // li $t3, 0x0001 lastAddress += 4; sampleMemory.store32(lastAddress, 0x17600006); // bnez $k1, 0xBFC00020 lastAddress += 4; sampleMemory.store32(lastAddress, 0x00000000); // nop lastAddress += 4; sampleMemory.store32(lastAddress, 0x54400006); // bnezl $t4, 0xBFC00028 lastAddress += 4; sampleMemory.store32(lastAddress, 0x3C0C0000); // ?lui $t4, 0x0000 lastAddress += 4; int baseAddress16 = lastAddress; int lastAddress16 = baseAddress16; sampleMemory.store32(lastAddress16, 0xF70064F6); // save $ra,$s0,$s1,$s2-$s7,$fp, 0x30 lastAddress16 += 4; sampleMemory.store16(lastAddress16, 0x6500); // nop lastAddress16 += 2; sampleMemory.store32(lastAddress16, 0xF7006476); // restore $ra,$s0,$s1,$s2-$s7,$fp, 0x30 lastAddress16 += 4; sampleMemory.store16(lastAddress16, 0xE8A0); // ret lastAddress16 += 2; disassembler = new Dtx(); disassembler.setDebugPrintWriter(new PrintWriter(new StringWriter())); // Ignore disassembler.setOutputFileName(null); disassembler.processOptions(new String[] { "-m", "0x" + Format.asHex(baseAddress, 8) + "-0x" + Format.asHex(lastAddress, 8) + "=CODE:32", "-m", "0x" + Format.asHex(baseAddress16, 8) + "-0x" + Format.asHex(lastAddress16, 8) + "=CODE:16" }); } disassembler.setOutputOptions(sampleOptions); disassembler.setMemory(sampleMemory); disassembler.initialize(); disassembler.setOutWriter(writer); disassembler.disassembleMemRanges(); disassembler.cleanup(); listingArea.setText(""); listingArea.append(writer.toString()); listingArea.setCaretPosition(0); } catch (Exception ex) { ex.printStackTrace(); } } }; int i = 1; for (OutputOption outputOption : OutputOption.allFormatOptions) { JCheckBox checkBox = makeOutputOptionCheckBox(chip, outputOption, prefs.getOutputOptions(chip), false); if (checkBox != null) { outputOptionsCheckBoxes.add(checkBox); disassemblyOptionsPanel.add(checkBox, (i % 2 == 0) ? "wrap" : ""); checkBox.addActionListener(areaRefresherListener); i++; } } if (i % 2 == 0) { disassemblyOptionsPanel.add(new JLabel(), "wrap"); } // Force a refresh areaRefresherListener.actionPerformed(new ActionEvent(outputOptionsCheckBoxes.get(0), 0, "")); // disassemblyOptionsPanel.add(new JLabel("Sample output:", SwingConstants.LEADING), "gapbottom 1, span, split 2, aligny center"); // disassemblyOptionsPanel.add(new JSeparator(), "span 2,wrap"); disassemblyOptionsPanel.add(new JSeparator(), "span 2, gapleft rel, growx, wrap"); disassemblyOptionsPanel.add(new JLabel("Sample output:"), "span 2,wrap"); disassemblyOptionsPanel.add(new JScrollPane(listingArea), "span 2,wrap"); disassemblyOptionsPanel.add(new JLabel("Tip: hover over the option checkboxes for help"), "span 2, center, wrap"); // ------------------------ Emulation options JPanel emulationOptionsPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT)); emulationOptionsPanel.add(new JLabel()); JLabel warningLabel = new JLabel( "NOTE: these options only take effect after reloading the firmware (or performing a 'Stop and reset')"); warningLabel.setBackground(Color.RED); warningLabel.setOpaque(true); warningLabel.setForeground(Color.WHITE); warningLabel.setHorizontalAlignment(SwingConstants.CENTER); emulationOptionsPanel.add(warningLabel); emulationOptionsPanel.add(new JLabel()); final JCheckBox writeProtectFirmwareCheckBox = new JCheckBox("Write-protect firmware"); writeProtectFirmwareCheckBox.setSelected(prefs.isFirmwareWriteProtected(chip)); emulationOptionsPanel.add(writeProtectFirmwareCheckBox); emulationOptionsPanel.add(new JLabel( "If checked, any attempt to write to the loaded firmware area will result in an Emulator error. This can help trap spurious writes")); final JCheckBox dmaSynchronousCheckBox = new JCheckBox("Make DMA synchronous"); dmaSynchronousCheckBox.setSelected(prefs.isDmaSynchronous(chip)); emulationOptionsPanel.add(dmaSynchronousCheckBox); emulationOptionsPanel.add(new JLabel( "If checked, DMA operations will be performed immediately, pausing the CPU. Otherwise they are performed in a separate thread.")); final JCheckBox autoEnableTimersCheckBox = new JCheckBox("Auto enable timers"); autoEnableTimersCheckBox.setSelected(prefs.isAutoEnableTimers(chip)); emulationOptionsPanel.add(autoEnableTimersCheckBox); emulationOptionsPanel .add(new JLabel("If checked, timers will be automatically enabled upon reset or firmware load.")); // Log memory messages final JCheckBox logMemoryMessagesCheckBox = new JCheckBox("Log memory messages"); logMemoryMessagesCheckBox.setSelected(prefs.isLogMemoryMessages(chip)); emulationOptionsPanel.add(logMemoryMessagesCheckBox); emulationOptionsPanel .add(new JLabel("If checked, messages related to memory will be logged to the console.")); // Log serial messages final JCheckBox logSerialMessagesCheckBox = new JCheckBox("Log serial messages"); logSerialMessagesCheckBox.setSelected(prefs.isLogSerialMessages(chip)); emulationOptionsPanel.add(logSerialMessagesCheckBox); emulationOptionsPanel.add( new JLabel("If checked, messages related to serial interfaces will be logged to the console.")); // Log register messages final JCheckBox logRegisterMessagesCheckBox = new JCheckBox("Log register messages"); logRegisterMessagesCheckBox.setSelected(prefs.isLogRegisterMessages(chip)); emulationOptionsPanel.add(logRegisterMessagesCheckBox); emulationOptionsPanel.add(new JLabel( "If checked, warnings related to unimplemented register addresses will be logged to the console.")); // Log pin messages final JCheckBox logPinMessagesCheckBox = new JCheckBox("Log pin messages"); logPinMessagesCheckBox.setSelected(prefs.isLogPinMessages(chip)); emulationOptionsPanel.add(logPinMessagesCheckBox); emulationOptionsPanel.add(new JLabel( "If checked, warnings related to unimplemented I/O pins will be logged to the console.")); emulationOptionsPanel.add(new JSeparator(JSeparator.HORIZONTAL)); // Alt mode upon Debug JPanel altDebugPanel = new JPanel(new FlowLayout()); Object[] altDebugMode = EnumSet.allOf(EmulationFramework.ExecutionMode.class).toArray(); final JComboBox altModeForDebugCombo = new JComboBox(new DefaultComboBoxModel(altDebugMode)); for (int j = 0; j < altDebugMode.length; j++) { if (altDebugMode[j].equals(prefs.getAltExecutionModeForSyncedCpuUponDebug(chip))) { altModeForDebugCombo.setSelectedIndex(j); } } altDebugPanel.add(new JLabel(Constants.CHIP_LABEL[1 - chip] + " mode when " + Constants.CHIP_LABEL[chip] + " runs in sync Debug: ")); altDebugPanel.add(altModeForDebugCombo); emulationOptionsPanel.add(altDebugPanel); emulationOptionsPanel .add(new JLabel("If 'sync mode' is selected, this is the mode the " + Constants.CHIP_LABEL[1 - chip] + " chip will run in when running the " + Constants.CHIP_LABEL[chip] + " in Debug mode")); // Alt mode upon Step JPanel altStepPanel = new JPanel(new FlowLayout()); Object[] altStepMode = EnumSet.allOf(EmulationFramework.ExecutionMode.class).toArray(); final JComboBox altModeForStepCombo = new JComboBox(new DefaultComboBoxModel(altStepMode)); for (int j = 0; j < altStepMode.length; j++) { if (altStepMode[j].equals(prefs.getAltExecutionModeForSyncedCpuUponStep(chip))) { altModeForStepCombo.setSelectedIndex(j); } } altStepPanel.add(new JLabel(Constants.CHIP_LABEL[1 - chip] + " mode when " + Constants.CHIP_LABEL[chip] + " runs in sync Step: ")); altStepPanel.add(altModeForStepCombo); emulationOptionsPanel.add(altStepPanel); emulationOptionsPanel .add(new JLabel("If 'sync mode' is selected, this is the mode the " + Constants.CHIP_LABEL[1 - chip] + " chip will run in when running the " + Constants.CHIP_LABEL[chip] + " in Step mode")); // ------------------------ Prepare tabbed pane JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " Disassembly Options", null, disassemblyOptionsPanel); tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " Emulation Options", null, emulationOptionsPanel); if (chip == Constants.CHIP_TX) { JPanel chipSpecificOptionsPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT)); chipSpecificOptionsPanel.add(new JLabel("Eeprom status upon startup:")); ActionListener eepromInitializationRadioActionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { prefs.setEepromInitMode(Prefs.EepromInitMode.valueOf(e.getActionCommand())); } }; JRadioButton blank = new JRadioButton("Blank"); blank.setActionCommand(Prefs.EepromInitMode.BLANK.name()); blank.addActionListener(eepromInitializationRadioActionListener); if (Prefs.EepromInitMode.BLANK.equals(prefs.getEepromInitMode())) blank.setSelected(true); JRadioButton persistent = new JRadioButton("Persistent across sessions"); persistent.setActionCommand(Prefs.EepromInitMode.PERSISTENT.name()); persistent.addActionListener(eepromInitializationRadioActionListener); if (Prefs.EepromInitMode.PERSISTENT.equals(prefs.getEepromInitMode())) persistent.setSelected(true); JRadioButton lastLoaded = new JRadioButton("Last Loaded"); lastLoaded.setActionCommand(Prefs.EepromInitMode.LAST_LOADED.name()); lastLoaded.addActionListener(eepromInitializationRadioActionListener); if (Prefs.EepromInitMode.LAST_LOADED.equals(prefs.getEepromInitMode())) lastLoaded.setSelected(true); ButtonGroup group = new ButtonGroup(); group.add(blank); group.add(persistent); group.add(lastLoaded); chipSpecificOptionsPanel.add(blank); chipSpecificOptionsPanel.add(persistent); chipSpecificOptionsPanel.add(lastLoaded); chipSpecificOptionsPanel.add(new JLabel("Front panel type:")); final JComboBox frontPanelNameCombo = new JComboBox(new String[] { "D5100_small", "D5100_large" }); if (prefs.getFrontPanelName() != null) { frontPanelNameCombo.setSelectedItem(prefs.getFrontPanelName()); } frontPanelNameCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { prefs.setFrontPanelName((String) frontPanelNameCombo.getSelectedItem()); } }); chipSpecificOptionsPanel.add(frontPanelNameCombo); emulationOptionsPanel.add(new JSeparator(JSeparator.HORIZONTAL)); tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " specific options", null, chipSpecificOptionsPanel); } // ------------------------ Show it if (JOptionPane.OK_OPTION == JOptionPane.showOptionDialog(this, tabbedPane, Constants.CHIP_LABEL[chip] + " options", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, JOptionPane.DEFAULT_OPTION)) { // save output options dumpOptionCheckboxes(outputOptionsCheckBoxes, prefs.getOutputOptions(chip)); // apply TxCPUState.initRegisterLabels(prefs.getOutputOptions(chip)); // save other prefs prefs.setFirmwareWriteProtected(chip, writeProtectFirmwareCheckBox.isSelected()); prefs.setDmaSynchronous(chip, dmaSynchronousCheckBox.isSelected()); prefs.setAutoEnableTimers(chip, autoEnableTimersCheckBox.isSelected()); prefs.setLogRegisterMessages(chip, logRegisterMessagesCheckBox.isSelected()); prefs.setLogSerialMessages(chip, logSerialMessagesCheckBox.isSelected()); prefs.setLogPinMessages(chip, logPinMessagesCheckBox.isSelected()); prefs.setLogMemoryMessages(chip, logMemoryMessagesCheckBox.isSelected()); prefs.setAltExecutionModeForSyncedCpuUponDebug(chip, (EmulationFramework.ExecutionMode) altModeForDebugCombo.getSelectedItem()); prefs.setAltExecutionModeForSyncedCpuUponStep(chip, (EmulationFramework.ExecutionMode) altModeForStepCombo.getSelectedItem()); } }
From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java
@SuppressWarnings("unchecked") private JComponent initializeJComponentForParameter(final String strValue, final ParameterInfo info) throws ModelInformationException { JComponent field = null;/*from w ww. ja va 2 s . c om*/ if (info.isBoolean()) { field = new JCheckBox(); boolean value = Boolean.parseBoolean(strValue); ((JCheckBox) field).setSelected(value); } else if (info.isEnum() || info instanceof MasonChooserParameterInfo) { Object[] elements = null; if (info.isEnum()) { final Class<Enum<?>> type = (Class<Enum<?>>) info.getJavaType(); elements = type.getEnumConstants(); } else { final MasonChooserParameterInfo chooserInfo = (MasonChooserParameterInfo) info; elements = chooserInfo.getValidStrings(); } final JComboBox list = new JComboBox(elements); if (info.isEnum()) { try { @SuppressWarnings("rawtypes") final Object value = Enum.valueOf((Class<? extends Enum>) info.getJavaType(), strValue); list.setSelectedItem(value); } catch (final IllegalArgumentException e) { throw new ModelInformationException(e.getMessage() + " for parameter: " + info.getName() + "."); } } else { try { final int value = Integer.parseInt(strValue); list.setSelectedIndex(value); } catch (final NumberFormatException e) { throw new ModelInformationException( "Invalid value for parameter " + info.getName() + " (not a number)."); } } field = list; } else if (info.isFile()) { field = new JPanel(); final JTextField textField = new JTextField(); if (!strValue.isEmpty()) { final File file = new File(strValue); textField.setText(file.getName()); textField.setToolTipText(file.getAbsolutePath()); } field.add(textField); } else if (info instanceof MasonIntervalParameterInfo) { field = new JPanel(); final JTextField textField = new JTextField(strValue); field.add(textField); } else { field = new JTextField(strValue); } return field; }
From source file:ucar.unidata.idv.flythrough.Flythrough.java
/** * _more_//from w w w . j a v a2s .c om * * @param pt _more_ * * @return _more_ */ private boolean showProperties(FlythroughPoint pt) { try { DateTime[] times = viewManager.getAnimationWidget().getTimes(); JComboBox timeBox = null; JLabel timeLabel = GuiUtils.rLabel("Time:"); Vector timesList = new Vector(); timesList.add(0, new TwoFacedObject("None", null)); if ((times != null) && (times.length > 0)) { timesList.addAll(Misc.toList(times)); } if ((pt.getDateTime() != null) && !timesList.contains(pt.getDateTime())) { timesList.add(pt.getDateTime()); } timeBox = new JComboBox(timesList); if (pt.getDateTime() != null) { timeBox.setSelectedItem(pt.getDateTime()); } LatLonWidget llw = new LatLonWidget("Latitude: ", "Longitude: ", "Altitude: ", null) { protected String formatLatLonString(String latOrLon) { return latOrLon; } }; EarthLocation el = pt.getEarthLocation(); llw.setLatLon(el.getLatitude().getValue(CommonUnit.degree), el.getLongitude().getValue(CommonUnit.degree)); llw.setAlt(getAlt(el)); JTextArea textArea = new JTextArea("", 5, 100); if (pt.getDescription() != null) { textArea.setText(pt.getDescription()); } JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setPreferredSize(new Dimension(400, 300)); JComponent contents = GuiUtils.formLayout(new Component[] { GuiUtils.rLabel("Location:"), llw, timeLabel, GuiUtils.left(timeBox), GuiUtils.rLabel("Description:"), scrollPane }); if (!GuiUtils.showOkCancelDialog(frame, "Point Properties", contents, null)) { return false; } pt.setDescription(textArea.getText()); pt.setEarthLocation(makePoint(llw.getLat(), llw.getLon(), llw.getAlt())); Object selectedDate = timeBox.getSelectedItem(); if (selectedDate instanceof TwoFacedObject) { pt.setDateTime(null); } else { pt.setDateTime((DateTime) selectedDate); } return true; } catch (Exception exc) { logException("Showing point properties", exc); return false; } }
From source file:com.game.ui.views.CharachterEditorPanel.java
@Override public void actionPerformed(ActionEvent ae) { if (ae.getActionCommand().equalsIgnoreCase("dropDown")) { JComboBox comboBox = (JComboBox) ae.getSource(); JPanel panel = (JPanel) comboBox.getParent().getComponent(4); String name = comboBox.getSelectedItem().toString(); for (GameCharacter enemy : GameBean.enemyDetails) { if (enemy.getName().equalsIgnoreCase(name)) { ((JTextField) panel.getComponent(2)).setText(enemy.getName()); ((JTextField) panel.getComponent(4)).setText(enemy.getImagePath()); ((JTextField) panel.getComponent(6)).setText(new Integer(enemy.getHealth()).toString()); ((JTextField) panel.getComponent(8)).setText(new Integer(enemy.getAttackPts()).toString()); ((JTextField) panel.getComponent(10)).setText(new Integer(enemy.getArmor()).toString()); ((JTextField) panel.getComponent(12)).setText(new Integer(enemy.getAttackRange()).toString()); ((JTextField) panel.getComponent(14)).setText(new Integer(enemy.getMovement()).toString()); return; }/* w w w.j av a2 s . c om*/ } } else { JButton btn = (JButton) ae.getSource(); JPanel panel = (JPanel) btn.getParent(); int indexOfBtn = btn.getAccessibleContext().getAccessibleIndexInParent(); String name = ((JTextField) panel.getComponent(2)).getText(); String image = ((JTextField) panel.getComponent(4)).getText(); String health = ((JTextField) panel.getComponent(6)).getText(); String attackPts = ((JTextField) panel.getComponent(8)).getText(); String armourPts = ((JTextField) panel.getComponent(10)).getText(); String attackRnge = ((JTextField) panel.getComponent(12)).getText(); String movement = ((JTextField) panel.getComponent(14)).getText(); System.out.println("Index : " + indexOfBtn); JLabel message = ((JLabel) this.getComponent(5)); message.setText(""); message.setVisible(false); if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(image) && StringUtils.isNotBlank(health) && StringUtils.isNotBlank(attackPts) && StringUtils.isNotBlank(armourPts) && StringUtils.isNotBlank(attackRnge) && StringUtils.isNotBlank(movement)) { message.setVisible(false); GameCharacter character = new GameCharacter(); character.setName(name); character.setAttackPts(Integer.parseInt(attackPts)); character.setAttackRange(Integer.parseInt(attackRnge)); character.setHealth(Integer.parseInt(health)); character.setImagePath(image); character.setMovement(Integer.parseInt(movement)); character.setArmor(Integer.parseInt(armourPts)); boolean characterAlrdyPresent = false; for (int i = 0; i < GameBean.enemyDetails.size(); i++) { GameCharacter charFromList = GameBean.enemyDetails.get(i); if (charFromList.getName().equalsIgnoreCase(name)) { GameBean.enemyDetails.remove(i); GameBean.enemyDetails.add(i, character); characterAlrdyPresent = true; } } if (!characterAlrdyPresent) { GameBean.enemyDetails.add(character); } try { GameUtils.writeCharactersToXML(GameBean.enemyDetails, Configuration.PATH_FOR_ENEMY_CHARACTERS); message.setText("Saved Successfully.."); message.setVisible(true); if (!characterAlrdyPresent) { comboBox.addItem(name); comboBox.setSelectedItem(name); } TileInformation tileInfo = GameBean.mapInfo.getPathMap().get(location); if (tileInfo == null) { tileInfo = new TileInformation(); } tileInfo.setEnemy(character); GameBean.mapInfo.getPathMap().put(location, tileInfo); chkBox.setSelected(true); this.revalidate(); return; } catch (Exception e) { System.out.println("CharachterEditorPanel : actionPerformed() : Some error occured " + e); e.printStackTrace(); } } else { message.setText("Pls enter all the fields or pls choose a character from the drop down"); message.setVisible(true); this.revalidate(); } } }
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); }/* www.ja v a2 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:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfDescriptionPanel.java
/** * Builds generic country JComboBox to be used into form. */// ww w . ja v a2s. co m private JComboBox buildCountryJComboBox() { JComboBox jCountry = new JComboBox(countriesListWithEmpty.toArray()); jCountry.setSelectedItem(TextFieldWithComboBoxEacCpf.DEFAULT_VALUE); //if this method is called empty_default_value is selected return jCountry; }
From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfDescriptionPanel.java
/** * Builds placeEntry form part.//from w w w. j a v a 2 s. c o m */ private PanelBuilder buildPlaceEntry(PanelBuilder builder, CellConstraints cc, PlaceEntry placeEntry, boolean flag, int index, boolean filled) { JLabel jLabelPlace = new JLabel(this.labels.getString("eaccpf.description.place")); builder.add(jLabelPlace, cc.xy(1, rowNb)); if (placeEntry != null) { //placeEntry part TextFieldWithLanguage textFieldWithLanguage = new TextFieldWithLanguage(placeEntry.getContent(), placeEntry.getLang()); JTextField placeEntryTextField = textFieldWithLanguage.getTextField(); placeEntryTextField.addKeyListener(new CheckPlaceContent(placeEntryTextField, index)); builder.add(placeEntryTextField, cc.xy(3, rowNb)); JLabel jLabelLanguage = new JLabel(this.labels.getString("eaccpf.description.selectlanguage")); builder.add(jLabelLanguage, cc.xy(5, rowNb)); JComboBox placeEntryLanguage = textFieldWithLanguage.getLanguageBox(); placeEntryLanguage.setEnabled(filled); builder.add(placeEntryLanguage, cc.xy(7, rowNb)); appendPlaceEntryPlace(placeEntryTextField, placeEntryLanguage); } else { //empty one JTextField jTextfieldPlace = new JTextField(); jTextfieldPlace.addKeyListener(new CheckPlaceContent(jTextfieldPlace, index)); builder.add(jTextfieldPlace, cc.xy(3, rowNb)); JLabel jLabelLanguage = new JLabel(this.labels.getString("eaccpf.description.selectlanguage")); builder.add(jLabelLanguage, cc.xy(5, rowNb)); JComboBox jComboboxLanguage = buildLanguageJComboBox(/*flag*/); if (!flag) { jComboboxLanguage.setSelectedItem("---"); } // Disable combo action. jComboboxLanguage.setEnabled(filled); builder.add(jComboboxLanguage, cc.xy(7, rowNb)); appendPlaceEntryPlace(jTextfieldPlace, jComboboxLanguage); } setNextRow(); //second line JLabel jControlledPlaceLabel = new JLabel(this.labels.getString("eaccpf.description.linkvocabularyplaces")); builder.add(jControlledPlaceLabel, cc.xy(1, rowNb)); JTextField jTextfieldControlledLabelPlace = new JTextField(); if (placeEntry != null) { String vocabLink = placeEntry.getVocabularySource(); jTextfieldControlledLabelPlace.setText(vocabLink); } jTextfieldControlledLabelPlace.setEnabled(filled); builder.add(jTextfieldControlledLabelPlace, cc.xy(3, rowNb)); appendPlaceEntryVocabularyPlace(jTextfieldControlledLabelPlace); setNextRow(); //third line JLabel jCountryLabel = new JLabel(this.labels.getString("eaccpf.description.country")); builder.add(jCountryLabel, cc.xy(1, rowNb)); JComboBox jComboboxCountry = buildCountryJComboBox(); if (placeEntry != null) { String isoCountry = placeEntry.getCountryCode(); if (isoCountry != null && !isoCountry.isEmpty()) { jComboboxCountry.setSelectedItem(parseIsoToCountry(isoCountry)); } } jComboboxCountry.setEnabled(filled); builder.add(jComboboxCountry, cc.xy(3, rowNb)); appendPlaceEntryCountry(jComboboxCountry); setNextRow(); // role of the place has been moved from above to this part because placeEntry is needed // and there is not index (iterator var) by schema (if this part is between "add DATES" and // "add further address details" is impossible to put an index different from '0' JLabel jRolePlaceLabel = new JLabel(this.labels.getString("eaccpf.description.roleplace")); builder.add(jRolePlaceLabel, cc.xy(1, rowNb)); TextFieldWithComboBoxEacCpf jComboBoxRolePlace = null; if (placeEntry != null) { jComboBoxRolePlace = new TextFieldWithComboBoxEacCpf("", placeEntry.getLocalType(), TextFieldWithComboBoxEacCpf.TYPE_PLACE_ROLE, this.entityType, this.labels); } else { jComboBoxRolePlace = new TextFieldWithComboBoxEacCpf("", "", TextFieldWithComboBoxEacCpf.TYPE_PLACE_ROLE, this.entityType, this.labels); } jComboBoxRolePlace.getComboBox().setEnabled(filled); builder.add(jComboBoxRolePlace.getComboBox(), cc.xy(3, rowNb)); appendPlaceEntryRole(jComboBoxRolePlace); setNextRow(); return builder; }
From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfDescriptionPanel.java
/** * Builds a JComboBox with all languages used in several parts of this form. * Languages are provided by CommonsPropertiesPanels class. */// w ww.j av a2s. c o m private JComboBox buildLanguageJComboBox() { JComboBox jComboboxLanguageGenealogy = new JComboBox(CommonsPropertiesPanels.languagesDisplay); if (StringUtils.isNotEmpty(this.firstLanguage)) { // Locale.ENGLISH.getISO3Language() jComboboxLanguageGenealogy.setSelectedItem(LanguageIsoList.getLanguageStr(this.firstLanguage)); } else { jComboboxLanguageGenealogy.setSelectedItem("---"); } return jComboboxLanguageGenealogy; }
From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfDescriptionPanel.java
/** * Build part of function form related to places. *//*ww w . j av a2 s .c om*/ private PanelBuilder buildPlaceFunction(PanelBuilder builder, CellConstraints cc, Function function, boolean flag) { //first line JLabel jLabelFunction = new JLabel(this.labels.getString("eaccpf.description.function")); builder.add(jLabelFunction, cc.xy(1, rowNb)); TextFieldWithLanguage textFieldWithLanguage = null; if (function != null && function.getTerm() != null) { textFieldWithLanguage = new TextFieldWithLanguage(function.getTerm().getContent(), function.getTerm().getLang()); JTextField textField = textFieldWithLanguage.getTextField(); builder.add(textField, cc.xy(3, rowNb)); addPlaceFunctionPlacesJTextfield(textField); } else { JTextField jTextfieldFunction = new JTextField(); builder.add(jTextfieldFunction, cc.xy(3, rowNb)); addPlaceFunctionPlacesJTextfield(jTextfieldFunction); } JLabel jLabelLanguage = new JLabel(this.labels.getString("eaccpf.description.selectlanguage")); builder.add(jLabelLanguage, cc.xy(5, rowNb)); if (textFieldWithLanguage != null) { JComboBox languageBox = textFieldWithLanguage.getLanguageBox(); builder.add(languageBox, cc.xy(7, rowNb)); addPlaceFunctionLanguageJComboBox(languageBox); } else { JComboBox jComboboxLanguage = buildLanguageJComboBox(/*flag*/); // if(!flag){ // jComboboxLanguage.setSelectedItem("---"); // } builder.add(jComboboxLanguage, cc.xy(7, rowNb)); addPlaceFunctionLanguageJComboBox(jComboboxLanguage); } setNextRow(); //second line JLabel jLabelVocabulary = new JLabel(this.labels.getString("eaccpf.description.linktovocabulary")); builder.add(jLabelVocabulary, cc.xy(1, rowNb)); JTextField jTextfieldVocabularyLink = new JTextField( (function != null && function.getTerm() != null && function.getTerm().getVocabularySource() != null) ? function.getTerm().getVocabularySource() : ""); builder.add(jTextfieldVocabularyLink, cc.xy(3, rowNb)); addPlaceFunctionVocabularyJTextField(jTextfieldVocabularyLink); setNextRow(); //third line JLabel jLabelDescription = new JLabel(this.labels.getString("eaccpf.description.descriptionfunction")); builder.add(jLabelDescription, cc.xy(1, rowNb)); String content = ""; if (function != null && function.getDescriptiveNote() != null && function.getDescriptiveNote().getP() != null) { List<P> paragraphs = function.getDescriptiveNote().getP(); for (P p : paragraphs) { if (p.getContent() != null && !p.getContent().isEmpty()) { content += p.getContent(); } } } TextAreaWithLanguage jTextFieldLinkDescriptionOcupation = new TextAreaWithLanguage(content, ""); builder.add(jTextFieldLinkDescriptionOcupation.getTextField(), cc.xyw(3, this.rowNb, 4)); addPlaceFunctionDescriptionTextfields(jTextFieldLinkDescriptionOcupation); setNextRow(); //fourth part, each place and country for functions if (function != null && function.getPlaceEntry() != null && !function.getPlaceEntry().isEmpty()) { List<PlaceEntry> placeEntries = function.getPlaceEntry(); for (int i = 0; placeEntries.size() > i; i++) { PlaceEntry placeEntry = placeEntries.get(i); JLabel jLabelPlace = new JLabel(this.labels.getString("eaccpf.description.place")); builder.add(jLabelPlace, cc.xy(1, rowNb)); JTextField jTextfieldPlace = new JTextField( placeEntry.getContent() != null ? placeEntry.getContent() : ""); builder.add(jTextfieldPlace, cc.xy(3, rowNb)); addPlaceFunctionPlaceJTextfields(i == 0, jTextfieldPlace); JLabel jCountryLabel = new JLabel(this.labels.getString("eaccpf.description.country")); builder.add(jCountryLabel, cc.xy(5, rowNb)); JComboBox jComboboxCountry = buildCountryJComboBox(); if (placeEntry.getCountryCode() != null) { jComboboxCountry.setSelectedItem(parseIsoToCountry(placeEntry.getCountryCode())); } builder.add(jComboboxCountry, cc.xy(7, rowNb)); addPlaceFunctionCountryJComboBoxes(i == 0, jComboboxCountry); setNextRow(); } } else { //empty one JLabel jLabelPlace = new JLabel(this.labels.getString("eaccpf.description.place")); builder.add(jLabelPlace, cc.xy(1, rowNb)); JTextField jTextfieldPlace = new JTextField(); builder.add(jTextfieldPlace, cc.xy(3, rowNb)); addPlaceFunctionPlaceJTextfields(true, jTextfieldPlace); JLabel jCountryLabel = new JLabel(this.labels.getString("eaccpf.description.country")); builder.add(jCountryLabel, cc.xy(5, rowNb)); JComboBox countryJComboBox = buildCountryJComboBox(); builder.add(countryJComboBox, cc.xy(7, rowNb)); addPlaceFunctionCountryJComboBoxes(true, countryJComboBox); setNextRow(); } return builder; }
From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfDescriptionPanel.java
/** * Build occupations part form. //w w w . ja v a 2 s. c o m */ private PanelBuilder buildOcupationPlace(PanelBuilder builder, CellConstraints cc, Occupation occupation, boolean flag) { //first line JLabel jLabelOcupation = new JLabel(this.labels.getString("eaccpf.description.ocupation")); builder.add(jLabelOcupation, cc.xy(1, rowNb)); TextFieldWithLanguage textFieldWithLanguage = null; if (occupation != null && occupation.getTerm() != null && occupation.getTerm().getContent() != null) { textFieldWithLanguage = new TextFieldWithLanguage(occupation.getTerm().getContent(), occupation.getTerm().getLang()); JTextField textField = textFieldWithLanguage.getTextField(); builder.add(textField, cc.xy(3, rowNb)); addOcupationPlaceOcupationJTextField(textField); } else { JTextField jTextfieldOcupation = new JTextField(); builder.add(jTextfieldOcupation, cc.xy(3, rowNb)); addOcupationPlaceOcupationJTextField(jTextfieldOcupation); } JLabel jLabelLanguage = new JLabel(this.labels.getString("eaccpf.description.selectlanguage")); builder.add(jLabelLanguage, cc.xy(5, rowNb)); if (textFieldWithLanguage != null) { JComboBox jComboBoxLanguage = textFieldWithLanguage.getLanguageBox(); builder.add(jComboBoxLanguage, cc.xy(7, rowNb)); addOcupationPlaceOcupationLanguageJComboBox(jComboBoxLanguage); } else { JComboBox jComboboxLanguage = buildLanguageJComboBox(/*flag*/); // if(!flag){ // jComboboxLanguage.setSelectedItem("---"); // } builder.add(jComboboxLanguage, cc.xy(7, rowNb)); addOcupationPlaceOcupationLanguageJComboBox(jComboboxLanguage); } setNextRow(); //second line JLabel jLabelLinkOcupation = new JLabel( this.labels.getString("eaccpf.description.linktocontrolledocupations")); builder.add(jLabelLinkOcupation, cc.xy(1, rowNb)); JTextField jLinkOcupationOcupation = new JTextField((occupation != null && occupation.getTerm() != null && occupation.getTerm().getVocabularySource() != null) ? occupation.getTerm().getVocabularySource() : ""); builder.add(jLinkOcupationOcupation, cc.xy(3, rowNb)); addOcupationPlaceLinkToControlledVocabulary(jLinkOcupationOcupation); setNextRow(); //third line JLabel jLabelLinkDescriptionOcupation = new JLabel( this.labels.getString("eaccpf.description.descriptionocupations")); builder.add(jLabelLinkDescriptionOcupation, cc.xy(1, rowNb)); String content = ""; if (occupation != null && occupation.getDescriptiveNote() != null && occupation.getDescriptiveNote().getP() != null) { for (P p : occupation.getDescriptiveNote().getP()) { if (p.getContent() != null) { content += p.getContent(); } } } // JTextField jTextFieldLinkDescriptionOcupation = new JTextField(content); TextAreaWithLanguage jTextFieldLinkDescriptionOcupation = new TextAreaWithLanguage(content, ""); builder.add(jTextFieldLinkDescriptionOcupation.getTextField(), cc.xyw(3, this.rowNb, 4)); addOcupationPlaceOcupationDescription(jTextFieldLinkDescriptionOcupation); setNextRow(); textFieldWithLanguage = null; //each place entry, four part lines if (occupation != null && occupation.getPlaceEntry() != null && !occupation.getPlaceEntry().isEmpty()) { List<PlaceEntry> placeEntries = occupation.getPlaceEntry(); for (int i = 0; i < placeEntries.size(); i++) { PlaceEntry placeEntry = placeEntries.get(i); JLabel jLabelOcupationPlace = new JLabel(this.labels.getString("eaccpf.description.place")); builder.add(jLabelOcupationPlace, cc.xy(1, rowNb)); JTextField placeTextField = new JTextField( (placeEntry.getContent() != null) ? placeEntry.getContent() : ""); builder.add(placeTextField, cc.xy(3, rowNb)); addOcupationPlacePlaceJTextField(i == 0, placeTextField); JLabel jLabelLanguageOcupationPlace = new JLabel( this.labels.getString("eaccpf.description.country")); builder.add(jLabelLanguageOcupationPlace, cc.xy(5, rowNb)); JComboBox placeCountryJComboBox = buildCountryJComboBox(); if (placeEntry.getCountryCode() != null) { placeCountryJComboBox.setSelectedItem(parseIsoToCountry(placeEntry.getCountryCode())); } builder.add(placeCountryJComboBox, cc.xy(7, rowNb)); addOcupationPlaceCountryPlaceJComboBoxes(i == 0, placeCountryJComboBox); setNextRow(); } } else { //empty part JLabel jLabelOcupationPlace = new JLabel(this.labels.getString("eaccpf.description.place")); builder.add(jLabelOcupationPlace, cc.xy(1, rowNb)); JTextField jTextfieldOcupationPlace = new JTextField(); builder.add(jTextfieldOcupationPlace, cc.xy(3, rowNb)); addOcupationPlacePlaceJTextField(true, jTextfieldOcupationPlace); JLabel jLabelLanguageOcupationPlace = new JLabel(this.labels.getString("eaccpf.description.country")); builder.add(jLabelLanguageOcupationPlace, cc.xy(5, rowNb)); JComboBox placeCountryJComboBox = buildCountryJComboBox(); builder.add(placeCountryJComboBox, cc.xy(7, rowNb)); addOcupationPlaceCountryPlaceJComboBoxes(true, placeCountryJComboBox); } return builder; }