List of usage examples for java.lang Character toLowerCase
public static int toLowerCase(int codePoint)
From source file:org.apache.openjpa.jdbc.meta.ReverseMappingTool.java
/** * Return a default Java identifier-formatted name for the given * column/table name.//ww w. j a v a 2s . c o m */ public String getFieldName(String name, ClassMapping dec) { name = replaceInvalidCharacters(name); if (allUpperCase(name)) name = name.toLowerCase(); else name = Character.toLowerCase(name.charAt(0)) + name.substring(1); StringBuilder buf = new StringBuilder(); String[] subs = Strings.split(name, "_", 0); for (int i = 0; i < subs.length; i++) { if (i > 0) subs[i] = StringUtils.capitalise(subs[i]); buf.append(subs[i]); } return getUniqueName(buf.toString(), dec); }
From source file:org.apache.openjpa.jdbc.meta.ReverseMappingTool.java
/** * Return a default java identifier-formatted field relation name * for the given class name./*from w w w . j av a2 s. co m*/ */ private String getRelationName(Class fieldType, boolean coll, ForeignKey fk, boolean inverse, ClassMapping dec) { if (_useFK && fk.getName() != null) { String name = getFieldName(fk.getName(), dec); if (inverse && coll) name = name + "Inverses"; else if (inverse) name = name + "Inverse"; return getUniqueName(name, dec); } // get just the class name, w/o package String name = fieldType.getName(); name = name.substring(name.lastIndexOf('.') + 1); // make the first character lowercase and pluralize if a collection name = Character.toLowerCase(name.charAt(0)) + name.substring(1); if (coll && !name.endsWith("s")) name += "s"; return getUniqueName(name, dec); }
From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
@Override public void onPress(final int primaryCode) { setVibration();//from w w w .j a v a2s . c o m final InputConnection ic = getCurrentInputConnection(); if (popupKeypress && (primaryCode == 32 || primaryCode == 126 || primaryCode == -5 || primaryCode == -1 || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_1 || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_2 || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_3 || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_4 || primaryCode == EmojiKeyboardView.KEYCODE_EMOJI_5)) { kv.setPreviewEnabled(false); } if (oppositeCase) { timer = new CountDownTimer(300, 1) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { if (!swipe) { if (primaryCode == 46) { ic.commitText(",", 1); printedCommaa = true; if (autoSpacing) { ic.commitText(" ", 1); } } else if (primaryCode == 32) { Intent intent = new Intent(getApplicationContext(), Home.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } else if (primaryCode == -5) { if (voiceInput) { if (mVoiceRecognitionTrigger.isInstalled()) { mVoiceRecognitionTrigger.startVoiceRecognition(); } } } else { char code = (char) primaryCode; if (Character.isLetter(code) && caps) { code = Character.toLowerCase(code); } else if (Character.isLetter(code) && !caps) { code = Character.toUpperCase(code); } ic.commitText(String.valueOf(code), 1); } printedDifferent = true; } } }.start(); } if (spaceDot) { if (primaryCode == 32) { doubleSpace++; if (doubleSpace == 2) { ic.deleteSurroundingText(1, 0); ic.commitText(".", 1); if (autoSpacing) { ic.commitText(" ", 1); } printedDot = true; doubleSpace = 0; } else { printedDot = false; } } else { printedDot = false; doubleSpace = 0; } } }
From source file:com.android.tools.lint.checks.StringFormatDetector.java
/** * Check the given String.format call (with the given arguments) to see if the string format is * being used correctly/*from w w w.j av a 2 s .c o m*/ * @param context the context to report errors to * @param calledMethod the method being called * @param call the AST node for the {@link String#format} * @param specifiesLocale whether the first parameter is a locale string, shifting the */ private void checkStringFormatCall(JavaContext context, PsiMethod calledMethod, PsiMethodCallExpression call, boolean specifiesLocale) { int argIndex = specifiesLocale ? 1 : 0; PsiExpression[] args = call.getArgumentList().getExpressions(); if (args.length <= argIndex) { return; } PsiExpression argument = args[argIndex]; ResourceUrl resource = ResourceEvaluator.getResource(context.getEvaluator(), argument); if (resource == null || resource.framework || resource.type != ResourceType.STRING) { return; } String name = resource.name; if (mIgnoreStrings != null && mIgnoreStrings.contains(name)) { return; } boolean passingVarArgsArray = false; int callCount = args.length - 1 - argIndex; if (callCount == 1) { // If instead of a varargs call like // getString(R.string.foo, arg1, arg2, arg3) // the code is calling the varargs method with a packed Object array, as in // getString(R.string.foo, new Object[] { arg1, arg2, arg3 }) // we'll need to handle that such that we don't think this is a single // argument PsiExpression lastArg = args[args.length - 1]; PsiParameterList parameterList = calledMethod.getParameterList(); int parameterCount = parameterList.getParametersCount(); if (parameterCount > 0 && parameterList.getParameters()[parameterCount - 1].isVarArgs()) { boolean knownArity = false; boolean argWasReference = false; if (lastArg instanceof PsiReference) { PsiElement resolved = ((PsiReference) lastArg).resolve(); if (resolved instanceof PsiVariable) { PsiExpression initializer = ((PsiVariable) resolved).getInitializer(); if (initializer instanceof PsiNewExpression) { argWasReference = true; // Now handled by check below lastArg = initializer; } else if (initializer instanceof PsiArrayInitializerExpression) { argWasReference = true; // Now handled by check below lastArg = initializer; } } } if (lastArg instanceof PsiNewExpression) { PsiNewExpression newExpression = (PsiNewExpression) lastArg; PsiArrayInitializerExpression initializer = newExpression.getArrayInitializer(); if (initializer != null) { callCount = initializer.getInitializers().length; knownArity = true; } else { PsiExpression[] arrayDimensions = newExpression.getArrayDimensions(); if (arrayDimensions.length == 1) { PsiExpression first = arrayDimensions[0]; if (first instanceof PsiLiteral) { Object o = ((PsiLiteral) first).getValue(); if (o instanceof Integer) { callCount = (Integer) o; knownArity = true; } } } } if (!knownArity) { if (!argWasReference) { return; } } else { passingVarArgsArray = true; } } else if (lastArg instanceof PsiArrayInitializerExpression) { PsiArrayInitializerExpression initializer = (PsiArrayInitializerExpression) lastArg; callCount = initializer.getInitializers().length; passingVarArgsArray = true; } } } if (callCount > 0 && mNotFormatStrings.containsKey(name)) { checkNotFormattedHandle(context, call, name, mNotFormatStrings.get(name)); return; } List<Pair<Handle, String>> list = mFormatStrings != null ? mFormatStrings.get(name) : null; if (list == null) { LintClient client = context.getClient(); if (client.supportsProjectResources() && !context.getScope().contains(Scope.RESOURCE_FILE)) { AbstractResourceRepository resources = client.getResourceRepository(context.getMainProject(), true, false); List<ResourceItem> items; if (resources != null) { items = resources.getResourceItem(ResourceType.STRING, name); } else { // Must be a non-Android module items = null; } if (items != null) { for (final ResourceItem item : items) { ResourceValue v = item.getResourceValue(false); if (v != null) { String value = v.getRawXmlValue(); if (value != null) { // Make sure it's really a formatting string, // not for example "Battery remaining: 90%" boolean isFormattingString = value.indexOf('%') != -1; for (int j = 0, m = value.length(); j < m && isFormattingString; j++) { char c = value.charAt(j); if (c == '\\') { j++; } else if (c == '%') { Matcher matcher = FORMAT.matcher(value); if (!matcher.find(j)) { isFormattingString = false; } else { String conversion = matcher.group(6); int conversionClass = getConversionClass(conversion.charAt(0)); if (conversionClass == CONVERSION_CLASS_UNKNOWN || matcher.group(5) != null) { // Some date format etc - don't process return; } } j++; // Don't process second % in a %% } // If the user marked the string with } Handle handle = client.createResourceItemHandle(item); if (isFormattingString) { if (list == null) { list = Lists.newArrayList(); if (mFormatStrings == null) { mFormatStrings = Maps.newHashMap(); } mFormatStrings.put(name, list); } list.add(Pair.of(handle, value)); } else if (callCount > 0) { checkNotFormattedHandle(context, call, name, handle); } } } } } } else { return; } } if (list != null) { Set<String> reported = null; for (Pair<Handle, String> pair : list) { String s = pair.getSecond(); if (reported != null && reported.contains(s)) { continue; } int count = getFormatArgumentCount(s, null); Handle handle = pair.getFirst(); if (count != callCount) { Location location = context.getLocation(call); Location secondary = handle.resolve(); secondary.setMessage(String.format("This definition requires %1$d arguments", count)); location.setSecondary(secondary); String message = String .format("Wrong argument count, format string `%1$s` requires `%2$d` but format " + "call supplies `%3$d`", name, count, callCount); context.report(ARG_TYPES, call, location, message); if (reported == null) { reported = Sets.newHashSet(); } reported.add(s); } else { if (passingVarArgsArray) { // Can't currently check these: make sure we don't incorrectly // flag parameters on the Object[] instead of the wrapped parameters return; } for (int i = 1; i <= count; i++) { int argumentIndex = i + argIndex; PsiType type = args[argumentIndex].getType(); if (type != null) { boolean valid = true; String formatType = getFormatArgumentType(s, i); if (formatType == null) { continue; } char last = formatType.charAt(formatType.length() - 1); if (formatType.length() >= 2 && Character.toLowerCase(formatType.charAt(formatType.length() - 2)) == 't') { // Date time conversion. // TODO continue; } switch (last) { // Booleans. It's okay to pass objects to these; // it will print "true" if non-null, but it's // unusual and probably not intended. case 'b': case 'B': valid = isBooleanType(type); break; // Numeric: integer and floats in various formats case 'x': case 'X': case 'd': case 'o': case 'e': case 'E': case 'f': case 'g': case 'G': case 'a': case 'A': valid = isNumericType(type, true); break; case 'c': case 'C': // Unicode character valid = isCharacterType(type); break; case 'h': case 'H': // Hex print of hash code of objects case 's': case 'S': // String. Can pass anything, but warn about // numbers since you may have meant more // specific formatting. Use special issue // explanation for this? valid = !isBooleanType(type) && !isNumericType(type, false); break; } if (!valid) { Location location = context.getLocation(args[argumentIndex]); Location secondary = handle.resolve(); secondary.setMessage("Conflicting argument declaration here"); location.setSecondary(secondary); String suggestion = null; if (isBooleanType(type)) { suggestion = "`b`"; } else if (isCharacterType(type)) { suggestion = "'c'"; } else if (PsiType.INT.equals(type) || PsiType.LONG.equals(type) || PsiType.BYTE.equals(type) || PsiType.SHORT.equals(type)) { suggestion = "`d`, 'o' or `x`"; } else if (PsiType.FLOAT.equals(type) || PsiType.DOUBLE.equals(type)) { suggestion = "`e`, 'f', 'g' or `a`"; } else if (type instanceof PsiClassType) { String fqn = type.getCanonicalText(); if (TYPE_INTEGER_WRAPPER.equals(fqn) || TYPE_LONG_WRAPPER.equals(fqn) || TYPE_BYTE_WRAPPER.equals(fqn) || TYPE_SHORT_WRAPPER.equals(fqn)) { suggestion = "`d`, 'o' or `x`"; } else if (TYPE_FLOAT_WRAPPER.equals(fqn) || TYPE_DOUBLE_WRAPPER.equals(fqn)) { suggestion = "`d`, 'o' or `x`"; } else if (TYPE_OBJECT.equals(fqn)) { suggestion = "'s' or 'h'"; } } if (suggestion != null) { suggestion = " (Did you mean formatting character " + suggestion + "?)"; } else { suggestion = ""; } String canonicalText = type.getCanonicalText(); canonicalText = canonicalText.substring(canonicalText.lastIndexOf('.') + 1); String message = String.format( "Wrong argument type for formatting argument '#%1$d' " + "in `%2$s`: conversion is '`%3$s`', received `%4$s` " + "(argument #%5$d in method call)%6$s", i, name, formatType, canonicalText, argumentIndex + 1, suggestion); context.report(ARG_TYPES, call, location, message); if (reported == null) { reported = Sets.newHashSet(); } reported.add(s); } } } } } } }
From source file:org.eclipse.php.internal.core.ast.rewrite.ASTRewriteAnalyzer.java
public boolean visit(Program node) { if (!hasChildrenChanges(node)) { return doVisitUnchangedChildren(node); }// w w w . j av a 2 s . c om int pos = node.getStart() + 2; if (content.length > node.getStart() + 3) { if (Character.toLowerCase(content[node.getStart() + 2]) == 'p' && Character.toLowerCase(content[node.getStart() + 3]) == 'h' && Character.toLowerCase(content[node.getStart() + 4]) == 'p') { pos += 4; } } rewriteNodeList(node, Program.STATEMENTS_PROPERTY, pos, "", //$NON-NLS-1$ getLineDelimiter()); return false; }
From source file:com.evolveum.icf.dummy.connector.DummyConnector.java
private String varyLetterCase(String name) { StringBuilder sb = new StringBuilder(name.length()); for (char c : name.toCharArray()) { double a = Math.random(); if (a < 0.4) { c = Character.toLowerCase(c); } else if (a > 0.7) { c = Character.toUpperCase(c); }/*from w w w . j av a 2 s.c om*/ sb.append(c); } return sb.toString(); }
From source file:com.cohort.util.String2.java
/** * Replaces all occurences of <tt>oldS</tt> in sb with <tt>newS</tt>. * If <tt>oldS</tt> occurs inside <tt>newS</tt>, it won't be replaced * recursively (obviously)./*from w w w. j a v a 2s. co m*/ * * @param sb the StringBuilder * @param oldS the string to be searched for * @param newS the string to replace oldS * @param ignoreCase If true, when searching sb for oldS, this ignores the case of sb and oldS. * @return the number of replacements made. */ public static int replaceAll(StringBuilder sb, String oldS, String newS, boolean ignoreCase) { int sbL = sb.length(); int oldSL = oldS.length(); if (oldSL == 0) return 0; int newSL = newS.length(); StringBuilder testSB = sb; String testOldS = oldS; if (ignoreCase) { testSB = new StringBuilder(sbL); for (int i = 0; i < sbL; i++) testSB.append(Character.toLowerCase(sb.charAt(i))); testOldS = oldS.toLowerCase(); } int po = testSB.indexOf(testOldS); //System.out.println("testSB=" + testSB.toString() + " testOldS=" + testOldS + " po=" + po); //not String2.log if (po < 0) return 0; StringBuilder sb2 = new StringBuilder(sbL / 5 * 6); //a little bigger int base = 0; int n = 0; while (po >= 0) { n++; sb2.append(sb.substring(base, po)); sb2.append(newS); base = po + oldSL; po = testSB.indexOf(testOldS, base); //System.out.println("testSB=" + testSB.toString() + " testOldS=" + testOldS + " po=" + po + // " sb2=" + sb2.toString()); //not String2.log } sb2.append(sb.substring(base)); sb.setLength(0); sb.append(sb2); return n; }
From source file:com.juick.android.MainActivity.java
private boolean parseUri(Uri uri, boolean shouldFinish) { List<String> segs = uri.getPathSegments(); if (uri == null || uri.getHost() == null) return true; if (uri.getHost().contains("juick.com")) { if ((segs.size() == 1 && segs.get(0).matches("\\A[0-9]+\\z")) || (segs.size() == 2 && segs.get(1).matches("\\A[0-9]+\\z") && !segs.get(0).equals("places"))) { int mid = Integer.parseInt(segs.get(segs.size() - 1)); if (mid > 0) { if (shouldFinish) finish();//from w w w . j a v a 2 s .c o m Intent intent = new Intent(this, ThreadActivity.class); intent.setData(null); JuickMessageID jmid = new JuickMessageID(mid); intent.putExtra("mid", jmid); intent.putExtra("messagesSource", ChildrenMessageSource.forMID(this, jmid)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; } } else if (segs.size() == 1 && segs.get(0).matches("\\A[a-zA-Z0-9\\-]+\\z")) { //TODO show user } } if (uri.getHost().contains("bnw.im")) { String[] hostPart = uri.getHost().split("\\."); if (hostPart.length == 2 && segs.size() == 2 && segs.get(0).equals("p")) { // http://bnw.im/p/KLMNOP // open thread if (shouldFinish) finish(); Intent intent = new Intent(this, ThreadActivity.class); intent.setData(null); BnwMessageID mid = new BnwMessageID(segs.get(1)); intent.putExtra("mid", mid); intent.putExtra("messagesSource", ChildrenMessageSource.forMID(this, mid)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } } if (uri.getHost().contains("point.im")) { String s = uri.toString(); if (s.endsWith("/")) return false; s = s.substring(s.indexOf("point.im") + 9); if (s.contains("#")) { s = s.substring(0, s.indexOf("#")); } if (s.contains("/") || s.length() > 6) return false; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != Character.toLowerCase(s.charAt(i))) return false; } PointMessageID mid = new PointMessageID("", s, -1); Intent intent = new Intent(this, ThreadActivity.class); intent.setData(null); intent.putExtra("mid", mid); intent.putExtra("messagesSource", ChildrenMessageSource.forMID(this, mid)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } return false; }
From source file:org.dbgl.gui.MainWindow.java
private void createDosboxVersionsTab(TabFolder tabFolder) { final TabItem dosboxTabItem = new TabItem(tabFolder, SWT.NONE); dosboxTabItem.setText(settings.msg("dialog.main.dosboxversions")); final Composite composite = new Composite(tabFolder, SWT.NONE); composite.setLayout(new BorderLayout(0, 0)); dosboxTabItem.setControl(composite); final ToolBar toolBar = new ToolBar(composite, SWT.NONE); toolBar.setLayoutData(BorderLayout.NORTH); SelectionAdapter addDosboxAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { doAddDosboxVersion();/*from w ww. ja v a2s. c o m*/ } }; SelectionAdapter editDosboxAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { doEditDosboxVersion(); } }; SelectionAdapter removeDosboxAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { doRemoveDosboxVersion(); } }; SelectionAdapter runDosboxAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { doRunDosbox(); } }; SelectionAdapter toggleDosboxAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { doToggleDefaultVersion(); } }; SelectionAdapter openDosboxAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { int index = dbversion_table.getSelectionIndex(); if (index != -1) { PlatformUtils .openDirForViewing(dbversionsList.get(index).getCanonicalConfFile().getParentFile()); } } }; MouseAdapter mouseAdapter = new MouseAdapter() { public void mouseDoubleClick(final MouseEvent event) { doRunDosbox(); } }; KeyAdapter keyAdapter = new KeyAdapter() { public void keyPressed(final KeyEvent event) { if (event.keyCode == SWT.DEL || (event.stateMask == SWT.MOD1 && (Character.toLowerCase(event.keyCode) == 'r'))) { doRemoveDosboxVersion(); } else if (event.keyCode == SWT.INSERT || (event.stateMask == SWT.MOD1 && (Character.toLowerCase(event.keyCode) == 'n'))) { doAddDosboxVersion(); } else if (event.stateMask == SWT.MOD1 && (Character.toLowerCase(event.keyCode) == 'm')) { doToggleDefaultVersion(); } } }; TraverseListener travListener = new TraverseListener() { public void keyTraversed(final TraverseEvent event) { if ((event.stateMask == SWT.MOD1) && (event.detail == SWT.TRAVERSE_RETURN)) { doEditDosboxVersion(); } else if (event.detail == SWT.TRAVERSE_RETURN) { doRunDosbox(); } } }; final SelectionAdapter selectDosboxAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { int index = dbversion_table.getSelectionIndex(); if (index != -1) { updateViewDosboxSubmenu(dbversionsList.get(index)); } } }; GeneralPurposeGUI.createIconToolItem(toolBar, settings, settings.msg("dialog.main.addversion"), SWTImageManager.IMG_TB_NEW, addDosboxAdapter); GeneralPurposeGUI.createIconToolItem(toolBar, settings, settings.msg("dialog.main.editversion"), SWTImageManager.IMG_TB_EDIT, editDosboxAdapter); GeneralPurposeGUI.createIconToolItem(toolBar, settings, settings.msg("dialog.main.removeversion"), SWTImageManager.IMG_TB_DELETE, removeDosboxAdapter); GeneralPurposeGUI.createIconToolItem(toolBar, settings, settings.msg("dialog.main.runversion"), SWTImageManager.IMG_TB_RUN, runDosboxAdapter); dbversion_table = new Table(composite, SWT.FULL_SELECTION | SWT.BORDER); dbversion_table.setLinesVisible(true); dbversion_table.setHeaderVisible(true); addDBColumn(settings.msg("dialog.main.dosboxversions.column.title"), 0); addDBColumn(settings.msg("dialog.main.dosboxversions.column.version"), 1); addDBColumn(settings.msg("dialog.main.dosboxversions.column.path"), 2); addDBColumn(settings.msg("dialog.main.dosboxversions.column.default"), 3); addDBColumn(settings.msg("dialog.main.dosboxversions.column.id"), 4); addDBColumn(settings.msg("dialog.main.generic.column.created"), 5); addDBColumn(settings.msg("dialog.main.generic.column.lastmodify"), 6); addDBColumn(settings.msg("dialog.main.generic.column.lastrun"), 7); addDBColumn(settings.msg("dialog.main.generic.column.runs"), 8); final Menu menu = new Menu(dbversion_table); dbversion_table.setMenu(menu); GeneralPurposeGUI.createIconMenuItem(menu, SWT.NONE, settings, settings.msg("dialog.main.dosboxversion.run"), SWTImageManager.IMG_RUN, runDosboxAdapter); new MenuItem(menu, SWT.SEPARATOR); GeneralPurposeGUI.createIconMenuItem(menu, SWT.NONE, settings, settings.msg("dialog.main.dosboxversion.openfolder"), SWTImageManager.IMG_FOLDER, openDosboxAdapter); final MenuItem viewLinkMenuItem = GeneralPurposeGUI.createIconMenuItem(menu, SWT.CASCADE, settings, settings.msg("dialog.main.profile.view"), SWTImageManager.IMG_ZOOM, null); viewDosboxSubMenu = new Menu(viewLinkMenuItem); viewLinkMenuItem.setMenu(viewDosboxSubMenu); new MenuItem(menu, SWT.SEPARATOR); GeneralPurposeGUI.createIconMenuItem(menu, SWT.NONE, settings, settings.msg("dialog.main.dosboxversion.add"), SWTImageManager.IMG_NEW, addDosboxAdapter); GeneralPurposeGUI.createIconMenuItem(menu, SWT.NONE, settings, settings.msg("dialog.main.dosboxversion.edit"), SWTImageManager.IMG_EDIT, editDosboxAdapter); GeneralPurposeGUI.createIconMenuItem(menu, SWT.NONE, settings, settings.msg("dialog.main.dosboxversion.remove"), SWTImageManager.IMG_DELETE, removeDosboxAdapter); new MenuItem(menu, SWT.SEPARATOR); GeneralPurposeGUI.createIconMenuItem(menu, SWT.NONE, settings, settings.msg("dialog.main.dosboxversion.toggledefault"), SWTImageManager.IMG_HOME, toggleDosboxAdapter); dbversion_table.addKeyListener(keyAdapter); dbversion_table.addTraverseListener(travListener); dbversion_table.addMouseListener(mouseAdapter); dbversion_table.addSelectionListener(selectDosboxAdapter); }
From source file:org.dbgl.gui.MainWindow.java
private void createTemplatesTab(TabFolder tabFolder) { final TabItem templatesTabItem = new TabItem(tabFolder, SWT.NONE); templatesTabItem.setText(settings.msg("dialog.main.templates")); final Composite composite = new Composite(tabFolder, SWT.NONE); composite.setLayout(new BorderLayout(0, 0)); templatesTabItem.setControl(composite); final ToolBar toolBar = new ToolBar(composite, SWT.NONE); toolBar.setLayoutData(BorderLayout.NORTH); SelectionAdapter addTemplAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { doAddTemplate();/*from w w w . j a v a 2 s. c o m*/ } }; SelectionAdapter editTemplAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { doEditTemplate(); } }; SelectionAdapter duplicateTemplateAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { doDuplicateTemplate(); } }; SelectionAdapter removeTemplAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { doRemoveTemplate(); } }; SelectionAdapter runTemplAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { doRunTemplate(); } }; SelectionAdapter toggleTemplAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { doToggleDefaultTemplate(); } }; MouseAdapter mouseAdapter = new MouseAdapter() { public void mouseDoubleClick(final MouseEvent event) { doRunTemplate(); } }; KeyAdapter keyAdapter = new KeyAdapter() { public void keyPressed(final KeyEvent event) { if (event.keyCode == SWT.DEL || (event.stateMask == SWT.MOD1 && (Character.toLowerCase(event.keyCode) == 'r'))) { doRemoveTemplate(); } else if (event.keyCode == SWT.INSERT || (event.stateMask == SWT.MOD1 && (Character.toLowerCase(event.keyCode) == 'n'))) { doAddTemplate(); } else if (event.stateMask == SWT.MOD1 && (Character.toLowerCase(event.keyCode) == 'm')) { doToggleDefaultTemplate(); } } }; TraverseListener travListener = new TraverseListener() { public void keyTraversed(final TraverseEvent event) { if ((event.stateMask == SWT.MOD1) && (event.detail == SWT.TRAVERSE_RETURN)) { doEditTemplate(); } else if (event.detail == SWT.TRAVERSE_RETURN) { doRunTemplate(); } } }; final SelectionAdapter selectTemplateAdapter = new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { int index = template_table.getSelectionIndex(); if (index != -1) { updateViewTemplateSubmenu(templatesList.get(index)); } } }; GeneralPurposeGUI.createIconToolItem(toolBar, settings, settings.msg("dialog.main.addtemplate"), SWTImageManager.IMG_TB_NEW, addTemplAdapter); GeneralPurposeGUI.createIconToolItem(toolBar, settings, settings.msg("dialog.main.edittemplate"), SWTImageManager.IMG_TB_EDIT, editTemplAdapter); GeneralPurposeGUI.createIconToolItem(toolBar, settings, settings.msg("dialog.main.removetemplate"), SWTImageManager.IMG_TB_DELETE, removeTemplAdapter); GeneralPurposeGUI.createIconToolItem(toolBar, settings, settings.msg("dialog.main.runtemplate"), SWTImageManager.IMG_TB_RUN, runTemplAdapter); template_table = new Table(composite, SWT.FULL_SELECTION | SWT.BORDER); template_table.setLinesVisible(true); template_table.setHeaderVisible(true); addTemplateColumn(settings.msg("dialog.main.templates.column.title"), 0); addTemplateColumn(settings.msg("dialog.main.templates.column.default"), 1); addTemplateColumn(settings.msg("dialog.main.templates.column.id"), 2); addTemplateColumn(settings.msg("dialog.main.generic.column.created"), 3); addTemplateColumn(settings.msg("dialog.main.generic.column.lastmodify"), 4); addTemplateColumn(settings.msg("dialog.main.generic.column.lastrun"), 5); addTemplateColumn(settings.msg("dialog.main.generic.column.runs"), 6); final Menu menu = new Menu(template_table); template_table.setMenu(menu); GeneralPurposeGUI.createIconMenuItem(menu, SWT.NONE, settings, settings.msg("dialog.main.template.run"), SWTImageManager.IMG_RUN, runTemplAdapter); new MenuItem(menu, SWT.SEPARATOR); final MenuItem viewLinkMenuItem = GeneralPurposeGUI.createIconMenuItem(menu, SWT.CASCADE, settings, settings.msg("dialog.main.profile.view"), SWTImageManager.IMG_ZOOM, null); viewTemplateSubMenu = new Menu(viewLinkMenuItem); viewLinkMenuItem.setMenu(viewTemplateSubMenu); new MenuItem(menu, SWT.SEPARATOR); GeneralPurposeGUI.createIconMenuItem(menu, SWT.NONE, settings, settings.msg("dialog.main.template.add"), SWTImageManager.IMG_NEW, addTemplAdapter); GeneralPurposeGUI.createIconMenuItem(menu, SWT.NONE, settings, settings.msg("dialog.main.template.edit"), SWTImageManager.IMG_EDIT, editTemplAdapter); GeneralPurposeGUI.createIconMenuItem(menu, SWT.NONE, settings, settings.msg("dialog.main.template.duplicate"), SWTImageManager.IMG_DUPLICATE, duplicateTemplateAdapter); GeneralPurposeGUI.createIconMenuItem(menu, SWT.NONE, settings, settings.msg("dialog.main.template.remove"), SWTImageManager.IMG_DELETE, removeTemplAdapter); new MenuItem(menu, SWT.SEPARATOR); GeneralPurposeGUI.createIconMenuItem(menu, SWT.NONE, settings, settings.msg("dialog.main.template.toggledefault"), SWTImageManager.IMG_HOME, toggleTemplAdapter); template_table.addKeyListener(keyAdapter); template_table.addTraverseListener(travListener); template_table.addMouseListener(mouseAdapter); template_table.addSelectionListener(selectTemplateAdapter); }