Java Code Examples for javax.swing.JComboBox#setToolTipText()
The following examples show how to use
javax.swing.JComboBox#setToolTipText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextBoxPanel.java From energy2d with GNU Lesser General Public License v3.0 | 6 votes |
private static JComboBox<String> createFontNameComboBox() { JComboBox<String> c = new JComboBox<String>(FONT_FAMILY_NAMES); c.setRenderer(new ComboBoxRenderer.FontLabel()); c.setToolTipText("Font type"); FontMetrics fm = c.getFontMetrics(c.getFont()); int max = 0, n = 0; for (int i = 0; i < FONT_FAMILY_NAMES.length; i++) { n = fm.stringWidth(FONT_FAMILY_NAMES[i]); if (max < n) max = n; } int w = max + 50; int h = fm.getHeight() + 8; c.setPreferredSize(new Dimension(w, h)); c.setEditable(false); c.setRequestFocusEnabled(false); return c; }
Example 2
Source File: DBConnectionUtil.java From jeddict with Apache License 2.0 | 6 votes |
/** * Load combobox with DB connection * * @param file * @param dbConComboBox */ public static void loadConnection(ModelerFile file, JComboBox dbConComboBox) { EntityMappings entityMappings = (EntityMappings) file.getDefinitionElement(); Cache cache = entityMappings.getCache(); DatabaseConnectionCache dbCache = cache.getDatabaseConnectionCache(); DatabaseExplorerUIs.connect(dbConComboBox, ConnectionManager.getDefault()); dbConComboBox.setToolTipText("Available Database Connection"); for (int i = 0; i < dbConComboBox.getItemCount(); i++) { Object item = dbConComboBox.getItemAt(i); if (dbCache != null && item instanceof DatabaseConnection && ((DatabaseConnection) item).getDatabaseURL().equals(dbCache.getUrl())) { dbConComboBox.setSelectedIndex(i); break; } } }
Example 3
Source File: ControlsDialog.java From WorldGrower with GNU General Public License v3.0 | 6 votes |
private void addPerformancePanel(KeyBindings keyBindings) { JPanel performancePanel = JPanelFactory.createJPanel("Performance"); performancePanel.setOpaque(false); performancePanel.setBounds(15, 310, 368, 100); performancePanel.setLayout(null); JLabel lblAnimationSpeed = JLabelFactory.createJLabel("Animation Speed:"); lblAnimationSpeed.setToolTipText(ANIMATION_SPEED_TOOL_TIP); lblAnimationSpeed.setOpaque(false); lblAnimationSpeed.setBounds(12, 25, 137, 25); performancePanel.add(lblAnimationSpeed); JComboBox<AnimationSpeed> cmbAnimationSpeed = JComboBoxFactory.createJComboBox(AnimationSpeed.values(), imageInfoReader); cmbAnimationSpeed.setForeground(Color.BLACK); cmbAnimationSpeed.setToolTipText(ANIMATION_SPEED_TOOL_TIP); cmbAnimationSpeed.setSelectedItem(keyBindings.getAnimationSpeed()); cmbAnimationSpeed.setOpaque(false); cmbAnimationSpeed.setBounds(228, 25, 127, 25); performancePanel.add(cmbAnimationSpeed); cmbAnimationSpeed.addActionListener(e -> keyBindings.setAnimationSpeed((AnimationSpeed)cmbAnimationSpeed.getSelectedItem())); addComponent(performancePanel); }
Example 4
Source File: SpacecraftFrame.java From FoxTelem with GNU General Public License v3.0 | 6 votes |
private JComboBox<String> addComboBoxRow(JPanel parent, String name, String tip, String[] values) { JPanel row = new JPanel(); row.setLayout(new GridLayout(1,2,5,5)); //row.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel lbl = new JLabel(name); JComboBox<String> checkBox = new JComboBox<String>(values); checkBox.setEnabled(true); checkBox.addItemListener(this); checkBox.setToolTipText(tip); lbl.setToolTipText(tip); row.add(lbl); row.add(checkBox); parent.add(row); parent.add(new Box.Filler(new Dimension(10,5), new Dimension(10,5), new Dimension(10,5))); return checkBox; }
Example 5
Source File: CustomCodeView.java From netbeans with Apache License 2.0 | 5 votes |
EditableLine(Position pos, EditableBlock eBlock, int selIndex, List<EditableLine> lines) { position = pos; linesInBlock = lines; codeEntries = eBlock.getEntries(); targetCombo = new JComboBox(codeEntries); setSelectedIndex(selIndex); targetCombo.getAccessibleContext().setAccessibleName(codeEntries[selIndex].getName()); targetCombo.setToolTipText(codeEntries[selIndex].getToolTipText()); targetCombo.addActionListener(new EditSwitchL()); }
Example 6
Source File: TextBoxPanel.java From energy2d with GNU Lesser General Public License v3.0 | 5 votes |
private static JComboBox<Integer> createFontSizeComboBox() { JComboBox<Integer> c = new JComboBox<Integer>(FONT_SIZE); c.setToolTipText("Font size"); FontMetrics fm = c.getFontMetrics(c.getFont()); int w = fm.stringWidth(FONT_SIZE[FONT_SIZE.length - 1].toString()) + 40; int h = fm.getHeight() + 8; c.setPreferredSize(new Dimension(w, h)); c.setEditable(false); c.setRequestFocusEnabled(false); return c; }
Example 7
Source File: JPlagCreator.java From jplag with GNU General Public License v3.0 | 5 votes |
public static JComboBox<String> createJComboBox(String[] items, int width, int height, String toolTip) { JComboBox<String> comboBox = new JComboBox<String>(items); comboBox.setPreferredSize(new java.awt.Dimension(width, height)); comboBox.setBackground(java.awt.Color.white); comboBox.setFont(JPlagCreator.SYSTEM_FONT); if (toolTip != null) comboBox.setToolTipText(toolTip); return comboBox; }
Example 8
Source File: DisplayPreferences.java From gcs with Mozilla Public License 2.0 | 5 votes |
private <E> JComboBox<E> createCombo(E[] values, E choice, String tooltip) { JComboBox<E> combo = new JComboBox<>(values); combo.setOpaque(false); combo.setToolTipText(Text.wrapPlainTextForToolTip(tooltip)); combo.setSelectedItem(choice); combo.addActionListener(this); combo.setMaximumRowCount(combo.getItemCount()); UIUtilities.setToPreferredSizeOnly(combo); add(combo); return combo; }
Example 9
Source File: BaseSpellEditor.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Utility function to create a combobox, populate it, and set a few properties. * * @param parent Container for the widget. * @param items Items of the combobox. * @param selection The item initialliy selected. * @param tooltip The tooltip of the combobox. */ protected <E> JComboBox<E> createComboBox(Container parent, E[] items, Object selection, String tooltip) { JComboBox<E> combo = new JComboBox<>(items); combo.setToolTipText(Text.wrapPlainTextForToolTip(tooltip)); combo.setSelectedItem(selection); combo.addActionListener(this); combo.setMaximumRowCount(items.length); UIUtilities.setToPreferredSizeOnly(combo); combo.setEnabled(mIsEditable); parent.add(combo); return combo; }
Example 10
Source File: ActivitySequenceEditor.java From jclic with GNU General Public License v2.0 | 5 votes |
public boolean createNewSequenceElement(int index, boolean prompt, Component dlgParent) { String act = null, tag = null; Messages msg = getOptions().getMessages(); if (prompt) { ListModel lm = getProjectEditor().getActivityBagEditor().getListModel(); if (lm.getSize() == 0) { msg.showAlert(dlgParent, "edit_seq_newElement_error_emptyList"); return false; } JComboBox actCombo = new JComboBox<Object>( new ListComboModel(getProjectEditor().getActivityBagEditor().getListModel())); actCombo.setToolTipText(msg.get("edit_seq_activity_tooltip")); JTextField tagField = new JTextField(); tagField.setToolTipText(msg.get("edit_seq_tag_tooltip")); JComponent[] prompt_objects = new JComponent[] { actCombo, tagField }; String[] prompt_keys = new String[] { "edit_seq_activity", "edit_seq_tag" }; String[] prompt_msg = new String[] { "edit_seq_newElement_msg" }; if (!msg.showInputDlg(dlgParent, prompt_msg, prompt_keys, prompt_objects, "edit_seq_newElement")) return false; act = StrUtils.nullableString(actCombo.getSelectedItem()); tag = StrUtils.nullableString(tagField.getText()); } if (act == null) { msg.showAlert(dlgParent, "edit_seq_newElement_error_noAct"); return false; } return createNewSequenceElement(act, tag, index); }
Example 11
Source File: SkillEditor.java From gcs with Mozilla Public License 2.0 | 5 votes |
private JComboBox<Object> createComboBox(Container parent, Object[] items, Object selection, String tooltip) { JComboBox<Object> combo = new JComboBox<>(items); combo.setToolTipText(Text.wrapPlainTextForToolTip(tooltip)); combo.setSelectedItem(selection); combo.addActionListener(this); combo.setMaximumRowCount(items.length); UIUtilities.setToPreferredSizeOnly(combo); combo.setEnabled(mIsEditable); parent.add(combo); return combo; }
Example 12
Source File: BroadcastFrame.java From JRakNet with MIT License | 4 votes |
/** * Creates a broadcast test frame. */ protected BroadcastFrame() { // Frame and content settings this.setResizable(false); this.setSize(FRAME_WIDTH, FRAME_HEIGHT); this.setTitle("JRakNet Broadcast Test"); this.getContentPane().setLayout(null); // Discovered MCPE Servers JTextPane txtpnDiscoveredMcpeServers = new JTextPane(); txtpnDiscoveredMcpeServers.setEditable(false); txtpnDiscoveredMcpeServers.setBackground(UIManager.getColor("Button.background")); txtpnDiscoveredMcpeServers.setText("Discovered servers"); txtpnDiscoveredMcpeServers.setBounds(10, 10, 350, 20); this.getContentPane().add(txtpnDiscoveredMcpeServers); // How the client will discover servers on the local network JComboBox<String> comboBoxDiscoveryType = new JComboBox<String>(); comboBoxDiscoveryType.setToolTipText( "Changing this will update how the client will discover servers, by default it will look for any possible connection on the network"); comboBoxDiscoveryType.setModel(new DefaultComboBoxModel<String>(DISCOVERY_MODE_OPTIONS)); comboBoxDiscoveryType.setBounds(370, 10, 115, 20); comboBoxDiscoveryType.addActionListener(new RakNetBroadcastDiscoveryTypeListener()); this.getContentPane().add(comboBoxDiscoveryType); // Used to update the discovery port JTextField textFieldDiscoveryPort = new JTextField(); textFieldDiscoveryPort.setBounds(370, 45, 115, 20); textFieldDiscoveryPort.setText(Integer.toString(Discovery.getPorts()[0])); this.getContentPane().add(textFieldDiscoveryPort); textFieldDiscoveryPort.setColumns(10); JButton btnUpdatePort = new JButton("Update Port"); btnUpdatePort.setBounds(370, 76, 114, 23); btnUpdatePort.addActionListener(new RakNetBroadcastUpdatePortListener(textFieldDiscoveryPort)); this.getContentPane().add(btnUpdatePort); // The text containing the discovered MCPE servers txtPnDiscoveredMcpeServerList = new JTextPane(); txtPnDiscoveredMcpeServerList.setToolTipText("This is the list of the discovered servers on the local network"); txtPnDiscoveredMcpeServerList.setEditable(false); txtPnDiscoveredMcpeServerList.setBackground(UIManager.getColor("Button.background")); txtPnDiscoveredMcpeServerList.setBounds(10, 30, 350, 165); this.getContentPane().add(txtPnDiscoveredMcpeServerList); }
Example 13
Source File: AttributeEditor.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
private void createNewColumn() { // name JTextField nameField = new JTextField(); nameField.setToolTipText("The name of the attribute."); cellEditors.add(NAME_ROW, new DefaultCellEditor(nameField)); // type JComboBox<String> typeBox = new JComboBox<>(Attributes.KNOWN_ATTRIBUTE_TYPES); typeBox.setEditable(true); typeBox.setToolTipText( "The type of the attribute ('attribute' for regular learning attributes or a special attribute name)."); cellEditors.add(TYPE_ROW, new DefaultCellEditor(typeBox)); // value type List<String> usedTypes = new LinkedList<>(); for (int i = 0; i < Ontology.VALUE_TYPE_NAMES.length; i++) { if (i != Ontology.ATTRIBUTE_VALUE && i != Ontology.FILE_PATH && !Ontology.ATTRIBUTE_VALUE_TYPE.isA(i, Ontology.DATE_TIME)) { usedTypes.add(Ontology.ATTRIBUTE_VALUE_TYPE.mapIndex(i)); } } String[] valueTypes = new String[usedTypes.size()]; int vCounter = 0; for (String type : usedTypes) { valueTypes[vCounter++] = type; } JComboBox<String> valueTypeBox = new JComboBox<>(valueTypes); valueTypeBox.setToolTipText("The value type of the attribute."); cellEditors.add(VALUE_TYPE_ROW, new DefaultCellEditor(valueTypeBox)); // block type JComboBox<String> blockTypeBox = new JComboBox<>(Ontology.ATTRIBUTE_BLOCK_TYPE.getNames()); blockTypeBox.setToolTipText("The block type of this attribute."); cellEditors.add(BLOCK_TYPE_ROW, new DefaultCellEditor(blockTypeBox)); // separator JTextField separator = new JTextField(); separator.setToolTipText("Separates meta data from data."); separator.setEditable(false); cellEditors.add(SEPARATOR_ROW, new DefaultCellEditor(separator)); for (int i = 0; i < cellRenderers.getSize(); i++) { cellRenderers.add(i, new EditorCellRenderer(cellEditors.get(i, cellEditors.getSize(i) - 1))); } dataColumnVector.add(new Vector<String>()); this.dataChanged = true; this.metaDataChanged = true; }
Example 14
Source File: MainForm.java From zxpoly with GNU General Public License v3.0 | 4 votes |
private Optional<SourceSoundPort> showSelectSoundLineDialog( final List<SourceSoundPort> variants) { assertUiThread(); final JPanel panel = new JPanel(new FlowLayout(FlowLayout.TRAILING)); final String previouslySelectedDevice = AppOptions.getInstance().getLastSelectedAudioDevice(); final JComboBox<SourceSoundPort> comboBox = new JComboBox<>(variants.toArray(new SourceSoundPort[0])); comboBox.setPrototypeDisplayValue( new SourceSoundPort(null, "some very long device name to be shown", null)); comboBox.addActionListener(x -> { comboBox.setToolTipText(comboBox.getSelectedItem().toString()); }); comboBox.setToolTipText(comboBox.getSelectedItem().toString()); int index = -1; for (int i = 0; i < comboBox.getItemCount(); i++) { if (comboBox.getItemAt(i).toString().equals(previouslySelectedDevice)) { index = i; break; } } comboBox.setSelectedIndex(Math.max(0, index)); panel.add(new JLabel("Sound device:")); panel.add(comboBox); if (JOptionPane.showConfirmDialog( this, panel, "Select sound device", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE ) == JOptionPane.OK_OPTION) { final SourceSoundPort selected = (SourceSoundPort) comboBox.getSelectedItem(); AppOptions.getInstance().setLastSelectedAudioDevice(selected.toString()); return Optional.ofNullable(selected); } else { return Optional.empty(); } }
Example 15
Source File: VisualSettings.java From stendhal with GNU General Public License v2.0 | 4 votes |
/** * Create the transparency mode selector row. * * @return component holding the selector and the related label */ private JComponent createTransparencySelector() { JComponent row = SBoxLayout.createContainer(SBoxLayout.HORIZONTAL, SBoxLayout.COMMON_PADDING); JLabel label = new JLabel("Transparency mode:"); row.add(label); final JComboBox<String> selector = new JComboBox<>(); final String[][] data = { {"Automatic (default)", "auto", "The appropriate mode is decided automatically based on the system speed."}, {"Full translucency", "translucent", "Use semitransparent images where available. This is slow on some systems."}, {"Simple transparency", "bitmask", "Use simple transparency where parts of the image are either fully transparent or fully opaque.<p>Use this setting on old computers, if the game is unresponsive otherwise."} }; // Convenience mapping for getting the data rows from either short or // long names final Map<String, String[]> desc2data = new HashMap<String, String[]>(); Map<String, String[]> key2data = new HashMap<String, String[]>(); for (String[] s : data) { // fill the selector... selector.addItem(s[0]); // ...and prepare the convenience mappings in the same step desc2data.put(s[0], s); key2data.put(s[1], s); } // Find out the current option final WtWindowManager wm = WtWindowManager.getInstance(); String currentKey = wm.getProperty(TRANSPARENCY_PROPERTY, "auto"); String[] currentData = key2data.get(currentKey); if (currentData == null) { // invalid value; force the default currentData = key2data.get("auto"); } selector.setSelectedItem(currentData[0]); selector.setRenderer(new TooltippedRenderer(data)); selector.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object selected = selector.getSelectedItem(); String[] selectedData = desc2data.get(selected); wm.setProperty(TRANSPARENCY_PROPERTY, selectedData[1]); ClientSingletonRepository.getUserInterface().addEventLine(new EventLine("", "The new transparency mode will be used the next time you start the game client.", NotificationType.CLIENT)); } }); row.add(selector); StringBuilder toolTip = new StringBuilder("<html>The transparency mode used for the graphics. The available options are:<dl>"); for (String[] optionData : data) { toolTip.append("<dt><b>"); toolTip.append(optionData[0]); toolTip.append("</b></dt>"); toolTip.append("<dd>"); toolTip.append(optionData[2]); toolTip.append("</dd>"); } toolTip.append("</dl></html>"); row.setToolTipText(toolTip.toString()); selector.setToolTipText(toolTip.toString()); return row; }
Example 16
Source File: PageFlowToolbarUtilities.java From netbeans with Apache License 2.0 | 4 votes |
/** * Creates a JComboBox for the user to select the scope type. * @param view * @param pfc * @return */ public JComboBox createScopeComboBox() { JComboBox comboBox = new JComboBox(); comboBox.addItem(getScopeLabel(Scope.SCOPE_FACESCONFIG)); comboBox.addItem(getScopeLabel(Scope.SCOPE_PROJECT)); comboBox.addItem(getScopeLabel(Scope.SCOPE_ALL_FACESCONFIG)); //Set the appropriate size of the combo box so it doesn't take up the whole page. Dimension prefSize = comboBox.getPreferredSize(); comboBox.setMinimumSize(prefSize); comboBox.setMaximumSize(prefSize); comboBox.setSelectedItem(getScopeLabel(currentScope)); comboBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { PageFlowView view = getPageFlowView(); if (event.getStateChange() == ItemEvent.SELECTED) { String newScope = (String) event.getItem(); /* Save Locations before switching scope */ view.saveLocations(); LogRecord record = new LogRecord(Level.FINE, "PageFLowEditor Scope Changed To:" + newScope); record.setSourceClassName("PageFlowUtilities.ItemListener"); record.setSourceMethodName("itemStateChanged"); record.setParameters(new Object[]{newScope, new Date()}); LOGGER.log(record); setCurrentScope(getScope(newScope)); //As we are setting the current scope, we should update the controller and update the scene. But what happens with setup? /* We don't want the background process to continue adding pins to the pages */ // view.clearBackgroundPinAddingProcess(); /* You don't want to override the data you just stored */ view.getPageFlowController().setupGraphNoSaveData(); } view.requestMultiViewActive(); } }); comboBox.setToolTipText(TT_SCOPE); scopeBox = comboBox; return comboBox; }
Example 17
Source File: HierarchyTopComponent.java From netbeans with Apache License 2.0 | 4 votes |
@NbBundle.Messages({ "TXT_NonActiveContent=<No View Available - Refresh Manually>", "TXT_InspectHierarchyHistory=<empty>", "TOOLTIP_RefreshContent=Refresh for entity under cursor", "TOOLTIP_OpenJDoc=Open Javadoc Window", "TOOLTIP_ViewHierarchyType=Hierachy View Type", "TOOLTIP_InspectHierarchyHistory=Inspect Hierarchy History" }) public HierarchyTopComponent() { history = HistorySupport.getInstnace(this.getClass()); jdocFinder = SelectJavadocTask.create(this); jdocTask = RP.create(jdocFinder); explorerManager = new ExplorerManager(); rootChildren = new RootChildren(); filters = new HierarchyFilters(); explorerManager.setRootContext(Nodes.rootNode(rootChildren, filters)); selectedNodes = new InstanceContent(); lookup = new AbstractLookup(selectedNodes); explorerManager.addPropertyChangeListener(this); initComponents(); setName(Bundle.CTL_HierarchyTopComponent()); setToolTipText(Bundle.HINT_HierarchyTopComponent()); viewTypeCombo = new JComboBox(new DefaultComboBoxModel(ViewType.values())); viewTypeCombo.setMinimumSize(new Dimension(MIN_TYPE_WIDTH,COMBO_HEIGHT)); viewTypeCombo.addActionListener(this); viewTypeCombo.setToolTipText(Bundle.TOOLTIP_ViewHierarchyType()); historyCombo = new JComboBox(HistorySupport.createModel(history, Bundle.TXT_InspectHierarchyHistory())); historyCombo.setMinimumSize(new Dimension(MIN_HISTORY_WIDTH,COMBO_HEIGHT)); historyCombo.setRenderer(HistorySupport.createRenderer(history)); historyCombo.addActionListener(this); historyCombo.setEnabled(false); historyCombo.getModel().addListDataListener(this); historyCombo.setToolTipText(Bundle.TOOLTIP_InspectHierarchyHistory()); refreshButton = new JButton(ImageUtilities.loadImageIcon(REFRESH_ICON, true)); refreshButton.addActionListener(this); refreshButton.setToolTipText(Bundle.TOOLTIP_RefreshContent()); jdocButton = new JButton(ImageUtilities.loadImageIcon(JDOC_ICON, true)); jdocButton.addActionListener(this); jdocButton.setToolTipText(Bundle.TOOLTIP_OpenJDoc()); final Box upperToolBar = new MainToolBar( constrainedComponent(viewTypeCombo, GridBagConstraints.HORIZONTAL, 1.0, new Insets(0,0,0,0)), constrainedComponent(historyCombo, GridBagConstraints.HORIZONTAL, 1.5, new Insets(0,3,0,0)), constrainedComponent(refreshButton, GridBagConstraints.NONE, 0.0, new Insets(0,3,0,0)), constrainedComponent(jdocButton, GridBagConstraints.NONE, 0.0, new Insets(0,3,0,3))); add(decorateAsUpperPanel(upperToolBar), BorderLayout.NORTH); contentView = new JPanel(); contentView.setLayout(new CardLayout()); JPanel nonActiveContent = Utils.updateBackground(new JPanel()); nonActiveContent.setLayout(new BorderLayout()); nonActiveInfo = new JLabel(Bundle.TXT_NonActiveContent()); nonActiveInfo.setEnabled(false); nonActiveInfo.setHorizontalAlignment(SwingConstants.CENTER); nonActiveContent.add(nonActiveInfo, BorderLayout.CENTER); btw = createBeanTreeView(); contentView.add(nonActiveContent, NON_ACTIVE_CONTENT); contentView.add(btw, ACTIVE_CONTENT); add(contentView,BorderLayout.CENTER); lowerToolBar = new TapPanel(); lowerToolBar.setOrientation(TapPanel.DOWN); final JComponent lowerButtons = filters.getComponent(); lowerButtons.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 0)); lowerToolBar.add(lowerButtons); final boolean expanded = NbPreferences.forModule(HierarchyTopComponent.class). getBoolean(PROP_LOWER_TOOLBAR_EXPANDED, true); //NOI18N lowerToolBar.setExpanded(expanded); lowerToolBar.addPropertyChangeListener(this); add(Utils.updateBackground(lowerToolBar), BorderLayout.SOUTH); }
Example 18
Source File: CustomCodeView.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void actionPerformed(ActionEvent e) { if (ignoreComboAction) return; // not invoked by user, ignore GuardedBlock gBlock = codeData.getGuardedBlock(category, blockIndex); GuardBlockInfo gInfo = getGuardInfos(category)[blockIndex]; int[] blockBounds = getGuardBlockBounds(category, blockIndex); int startOffset = blockBounds[0]; int endOffset = blockBounds[1]; int gHead = gBlock.getHeaderLength(); int gFoot = gBlock.getFooterLength(); JTextComponent editor = getEditor(category); StyledDocument doc = (StyledDocument) editor.getDocument(); changed = true; JComboBox combo = (JComboBox) e.getSource(); try { docListener.setActive(false); if (combo.getSelectedIndex() == 1) { // changing from default to custom NbDocument.unmarkGuarded(doc, startOffset, endOffset - startOffset); // keep last '\n' so we don't destroy next editable block's position doc.remove(startOffset, endOffset - startOffset - 1); // insert the custom code into the document String customCode = gBlock.getCustomCode(); int customLength = customCode.length(); if (gInfo.customizedCode != null) { // already was edited before customCode = customCode.substring(0, gHead) + gInfo.customizedCode + customCode.substring(customLength - gFoot); customLength = customCode.length(); } if (customCode.endsWith("\n")) // NOI18N customCode = customCode.substring(0, customLength-1); doc.insertString(startOffset, customCode, null); gInfo.customized = true; // make guarded "header" and "footer", select the text in between NbDocument.markGuarded(doc, startOffset, gHead); NbDocument.markGuarded(doc, startOffset + customLength - gFoot, gFoot); editor.setSelectionStart(startOffset + gHead); editor.setSelectionEnd(startOffset + customLength - gFoot); editor.requestFocus(); combo.setToolTipText(gBlock.getCustomEntry().getToolTipText()); } else { // changing from custom to default // remember the customized code gInfo.customizedCode = doc.getText(startOffset + gHead, endOffset - gFoot - gHead - startOffset); NbDocument.unmarkGuarded(doc, endOffset - gFoot, gFoot); NbDocument.unmarkGuarded(doc, startOffset, gHead); // keep last '\n' so we don't destroy next editable block's position doc.remove(startOffset, endOffset - startOffset - 1); String defaultCode = gBlock.getDefaultCode(); if (defaultCode.endsWith("\n")) // NOI18N defaultCode = defaultCode.substring(0, defaultCode.length()-1); doc.insertString(startOffset, defaultCode, null); gInfo.customized = false; // make the whole text guarded, cancel selection NbDocument.markGuarded(doc, startOffset, defaultCode.length()+1); // including '\n' if (editor.getSelectionStart() >= startOffset && editor.getSelectionEnd() <= endOffset) editor.setCaretPosition(startOffset); combo.setToolTipText(NbBundle.getMessage(CustomCodeData.class, "CTL_GuardCombo_Default_Hint")); // NOI18N } // we must create a new Position - current was moved away by inserting new string on it gInfo.position = NbDocument.createPosition(doc, startOffset, Position.Bias.Forward); docListener.setActive(true); } catch (BadLocationException ex) { // should not happen ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); } }
Example 19
Source File: DocInfoUI.java From CQL with GNU Affero General Public License v3.0 | 4 votes |
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public List<Option> getOptions() { LinkedList<Option> opts = new LinkedList<>(); // Add a title: if (context == InfoContext.OVERVIEW) { opts.add(new Option.Title("Document information")); } else if (context == InfoContext.SKETCH) { opts.add(new Option.Title("Sketch information")); } else { opts.add(new Option.Title("View information")); } // Add the name field opts.add(new Option(new JLabel("Title"), name = JUtils.textField(docInfo.getName(), 15))); // Add the author field opts.add(new Option(new JLabel("Author(s)"), author = JUtils.textField(docInfo.getAuthorString(), 15))); // Add the description field opts.add(new Option(new JLabel("Description"), description = JUtils.textArea(docInfo.getDesc()))); // add the time info Date created = docInfo.getCreationDate(), modified = docInfo.getModificationDate(); String sCreated = (created == null) ? "N/A" : EasikConstants.DATETIME_LONG.format(created); String sModified = (modified == null) ? "N/A" : EasikConstants.DATETIME_LONG.format(modified); opts.add(new Option(new JLabel("Created"), new JLabel(sCreated))); opts.add(new Option(new JLabel("Last modified"), new JLabel(sModified))); // For a sketch, add the options for the default cascade mode for new // edges of this sketch if (context == InfoContext.SKETCH) { Sketch sketch = ((SketchFrame) _theFrame).getMModel(); edgeCascading = new JComboBox(new String[] { "Restrict deletions", "Cascade deletions" }); edgeCascading.setSelectedIndex((sketch.getDefaultCascading() == Cascade.CASCADE) ? 1 : 0); edgeCascadingPartial = new JComboBox( new String[] { "Set null", "Restrict deletions", "Cascade deletions" }); edgeCascadingPartial.setSelectedIndex((sketch.getDefaultPartialCascading() == Cascade.CASCADE) ? 2 : (sketch.getDefaultPartialCascading() == Cascade.RESTRICT) ? 1 : 0); JLabel cascadeLabel = new JLabel("Edge Cascading"); String cascadeTT = JUtils.tooltip( "This option affects how new edges of this sketch are handled when exporting to a db.\n\n\"Cascade deletions\" cause deletions in one table to trigger deletions of any rows in other tables that point to the row(s) being deleted.\n\n\"Restrict deletions\" causes attempted deletions of referenced rows to fail.\n\nThis option will be used by default for any new normal or injective edges of this sketch."); cascadeLabel.setToolTipText(cascadeTT); edgeCascading.setToolTipText(cascadeTT); opts.add(new Option(cascadeLabel, edgeCascading)); JLabel cascadePartialLabel = new JLabel("Partial Edge Cascading"); String cascadePartialTT = JUtils.tooltip( "This option affects how EASIK creates partial edges when exporting to a db.\n\n\"Cascade deletions\" cause deletions in one table to trigger deletions of any rows in other tables that point to the row(s) being deleted.\n\n\"Restrict deletions\" cause attempted deletions of referenced rows to fail.\n\n\"Set null\" causes references to be set to NULL when the targeted row is deleted.\n\nThis option will be used by default for new partial edges of this sketch."); cascadePartialLabel.setToolTipText(cascadePartialTT); edgeCascadingPartial.setToolTipText(cascadePartialTT); opts.add(new Option(cascadePartialLabel, edgeCascadingPartial)); } return opts; }
Example 20
Source File: PreferencePanel.java From gcs with Mozilla Public License 2.0 | 2 votes |
/** * Sets up a {@link JComboBox} suitable for use within the preference panel. * * @param combo The {@link JComboBox} to prepare. * @param tooltip The tooltip to use. */ protected void setupCombo(JComboBox<?> combo, String tooltip) { combo.setOpaque(false); combo.setToolTipText(Text.wrapPlainTextForToolTip(tooltip)); add(combo); }