code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
public static JScrollPane createVerticalScrollPane(
final JComponent component)
{
JScrollPane scrollPane = new JScrollPane(component)
{
/**
* Serial UID
*/
private static final long serialVersionUID = -177913025197077320L;
... | java |
public boolean addSorted(E element) {
boolean added = false;
added = super.add(element);
Comparable<E> cmp = (Comparable<E>) element;
for (int i = size() - 1; i > 0 && cmp.compareTo(get(i - 1)) < 0; i--)
Collections.swap(this, i, i - 1);
return added;
} | java |
public boolean addSorted(E element, boolean allowDuplicates) {
boolean added = false;
if(!allowDuplicates){
if(this.contains(element)){
System.err.println("item is a duplicate");
return added;
}}
added = super.add(element);
Comparable<E> cmp = (Comparable<E>) element;
for (int i = size() - 1; i ... | java |
private void prepareMenu(Container menu, Component component, int x, int y)
{
int n = menu.getComponentCount();
for (int i=0; i<n; i++)
{
Component menuComponent = popupMenu.getComponent(i);
if (menuComponent instanceof JMenu)
{
JMe... | java |
private void removeColumn(int index)
{
TableColumn column = tableColumns.get(index);
column.removePropertyChangeListener(widthListener);
tableColumns.remove(index);
JComponent component = customComponents.remove(index);
remove(component);
if (componentRemover !... | java |
private void addColumn(int index)
{
TableColumnModel columnModel = getColumnModel();
TableColumn column = columnModel.getColumn(index);
while (tableColumns.size() - 1 < index)
{
tableColumns.add(null);
}
tableColumns.set(index, column);
co... | java |
private void updateCustomComponentBounds()
{
if (customComponents == null)
{
return;
}
if (table == null)
{
return;
}
for (int i = 0; i < customComponents.size(); i++)
{
JComponent component = customCompo... | java |
private void initialiseLifecycleObserver(Application application) {
LifeCycleController.registerLifeCycleObserver(application, new LifecycleListener() {
@Override
public void onForegrounded(Context context) {
for (LifecycleListener listener : lifecycleListeners) {
... | java |
@Override
public Session getSession() {
return state.get() > GlobalState.INITIALISING ? new Session(dataMgr.getSessionDAO().session()) : new Session();
} | java |
private Observable<SessionData> loadSession(final Boolean initialised) {
if (initialised) {
final SessionData session = dataMgr.getSessionDAO().session();
if (session != null) {
if (session.getExpiresOn() > System.currentTimeMillis()) {
state.compare... | java |
public final AbstractMeter[] getMeters() {
final AbstractMeter[] returnVal = new AbstractMeter[meters.length];
System.arraycopy(meters, 0, returnVal, 0, returnVal.length);
return returnVal;
} | java |
public final AbstractOutput[] getListener() {
final AbstractOutput[] returnVal = new AbstractOutput[listeners.length];
System.arraycopy(listeners, 0, returnVal, 0, returnVal.length);
return returnVal;
} | java |
public <T> void adapt(@NonNull final Observable<T> subscriber, @Nullable final Callback<T> callback) {
subscriber.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<T>() {
@Override
public voi... | java |
private void setSelectionStateOfAll(State state)
{
Objects.requireNonNull(state, "The state may not be null");
List<Object> allNodes = JTrees.getAllNodes(getModel());
for (Object node : allNodes)
{
setSelectionState(node, state);
}
} | java |
private void setSelectionState(Object node, State state, boolean propagate)
{
Objects.requireNonNull(state, "The state may not be null");
Objects.requireNonNull(node, "The node may not be null");
State oldState = selectionStates.put(node, state);
if (!state.equals(oldState))
... | java |
private void handleMousePress(MouseEvent e)
{
int row = getRowForLocation(e.getX(), e.getY());
TreePath path = getPathForLocation(e.getX(), e.getY());
if (path == null)
{
return;
}
TreeCellRenderer cellRenderer = getCellRenderer();
TreeNod... | java |
private void toggleSelection(TreePath path)
{
Object node = path.getLastPathComponent();
State state = getSelectionState(node);
if (state == null)
{
return;
}
if (state == State.SELECTED)
{
setSelectionState(node, State.UNSELE... | java |
private void updateSelection(Object node)
{
State newState = getSelectionState(node);
List<Object> descendants =
JTrees.getAllDescendants(getModel(), node);
for (Object descendant : descendants)
{
setSelectionState(descendant, newState, false);
... | java |
private State computeState(List<Object> nodes)
{
Set<State> set = new LinkedHashSet<State>();
for (Object node : nodes)
{
set.add(getSelectionState(node));
}
// Should never happen
while (set.contains(null))
{
logger.warning("... | java |
public void removeFromAccordion(JComponent component)
{
CollapsiblePanel collapsiblePanel = collapsiblePanels.get(component);
if (collapsiblePanel != null)
{
contentPanel.remove(collapsiblePanel);
collapsiblePanels.remove(component);
revalidate();
... | java |
public void connectSocket() {
synchronized (lock) {
if (isForegrounded) {
if (socketConnection == null) {
SocketFactory factory = new SocketFactory(socketURI, new SocketEventDispatcher(listener, new Parser()).setLogger(log), log);
socketConnec... | java |
public void disconnectSocket() {
synchronized (lock) {
if (socketConnection != null) {
socketConnection.setManageReconnection(false);
socketConnection.disconnect();
}
lock.notifyAll();
}
} | java |
public LifecycleListener createLifecycleListener() {
return new LifecycleListener() {
@Override
public void onForegrounded(Context context) {
synchronized (lock) {
if (!isForegrounded) {
isForegrounded = true;
... | java |
public boolean initProgressView(final Map<BenchmarkMethod, Integer> mapping)
throws SocketViewException {
if (mapping != null) {
final Set<BenchmarkMethod> methodSet = mapping.keySet();
final Map<String, Integer> finalMap = new HashMap<String, Integer>();
for (BenchmarkMethod benchmarkMethod : methodSet)... | java |
public boolean updateCurrentElement(final AbstractMeter meter,
final String name) throws SocketViewException {
if (meter != null && !regMeterHash) {
registerFirstMeterHash(meter);
}
if (name != null && meter.hashCode() == (getRegMeter())) {
viewStub.updateCurrentRun(name);
}
return true;
} | java |
public boolean updateErrorInElement(final String name,
final Exception exception) throws SocketViewException {
if (name != null && exception != null) {
if (exception instanceof AbstractPerfidixMethodException) {
final AbstractPerfidixMethodException exc = (AbstractPerfidixMethodException) exception;
vie... | java |
static String getLevelTag(final int logLevel) {
switch (logLevel) {
case LogLevelConst.FATAL:
return LogConstants.TAG_FATAL;
case LogLevelConst.ERROR:
return LogConstants.TAG_ERROR;
case LogLevelConst.WARNING:
return LogCons... | java |
public String getMessageId() {
return (data != null && data.payload != null) ? data.payload.messageId : null;
} | java |
public String getConversationId() {
return (data != null && data.payload != null) ? data.payload.conversationId : null;
} | java |
public String getProfileId() {
return (data != null && data.payload != null) ? data.payload.profileId : null;
} | java |
public String getTimestamp() {
return (data != null && data.payload != null) ? data.payload.timestamp : null;
} | java |
static String combine(final String... args) {
final StringBuilder builder = new StringBuilder();
for (final String arg : args) {
builder.append(arg);
}
return builder.toString();
} | java |
static String implode(final String glue, final String[] what) {
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < what.length; i++) {
builder.append(what[i]);
if (i + 1 != what.length) {
builder.append(glue);
}
}
r... | java |
static String repeat(final String toBeRepeated, final int numTimes) {
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < numTimes; i++) {
builder.append(toBeRepeated);
}
return builder.toString();
} | java |
private static int numNewLines(final String toExamine) {
final char[] arr = toExamine.toCharArray();
int result = 0;
for (char ch : arr) {
if (AbstractTabularComponent.NEWLINE.equals(new String(new char[]{ch}))) {
result++;
}
}
return resul... | java |
public static String[][] createMatrix(final String[] data) {
int maxNewLines = 0;
for (final String col : data) {
maxNewLines = Math.max(maxNewLines, Util.numNewLines(col));
}
final String[][] matrix = new String[maxNewLines + 1][data.length];
for (int col = 0; col < ... | java |
private void handleCommand(byte b) throws IOException {
if (b == SE) {
telnetCommand += (char) b;
handleNegotiation();
reset();
} else if (isWill || isDo) {
if (isWill && b == TERMINAL_TYPE) {
socketChannel
.write(ByteBu... | java |
private void handleNegotiation() throws IOException {
if (telnetCommand.contains(new String(new byte[] { TERMINAL_TYPE }))) {
// IAC SB TERMINAL_TYPE IS XXX IAC SE
boolean isSuccess = false;
clientTerminalType = telnetCommand.substring(4, telnetCommand.length() - 2);
... | java |
public String normalizeNumber(final String number) {
try {
final BigDecimal normalizedNumber = parseNumber(new NumberBuffer(
number));
if (normalizedNumber == null) {
return number;
}
return normalizedNumber.toBigIntegerExact().... | java |
private BigDecimal parseNumber(final NumberBuffer buffer) {
BigDecimal sum = BigDecimal.ZERO;
BigDecimal result = parseLargePair(buffer);
if (result == null) {
return null;
}
while (result != null) {
sum = sum.add(result);
result = parseLarge... | java |
public boolean isNumeralPunctuation(final String input) {
for (int i = 0; i < input.length(); i++) {
if (!isNumeralPunctuation(input.charAt(i))) {
return false;
}
}
return true;
} | java |
public void adaptHeightToChildren() {
DividableGridAdapter adapter = (DividableGridAdapter) getAdapter();
if (adapter != null) {
int height = getPaddingTop() + getPaddingBottom();
for (int i = 0; i < adapter.getCount(); i += adapter.getColumnCount()) {
AbstractI... | java |
private List<AbstractItem> getRawItems() {
if (rawItems == null) {
rawItems = new ArrayList<>();
for (int i = 0; i < items.size(); i++) {
AbstractItem item = items.get(i);
if (item instanceof Divider && columnCount > 1) {
for (int j =... | java |
private View inflateItemView(@Nullable final ViewGroup parent) {
LayoutInflater layoutInflater = LayoutInflater.from(context);
View view = layoutInflater
.inflate(style == Style.GRID ? R.layout.grid_item : R.layout.list_item, parent,
false);
ItemViewHolder... | java |
@SuppressWarnings("PrimitiveArrayArgumentToVariableArgMethod")
private void visualizeItem(@NonNull final Item item, @NonNull final ItemViewHolder viewHolder) {
viewHolder.iconImageView.setVisibility(iconCount > 0 ? View.VISIBLE : View.GONE);
viewHolder.iconImageView.setEnabled(item.isEnabled());
... | java |
private View inflateDividerView(@Nullable final ViewGroup parent,
@NonNull final Divider divider, final int position) {
LayoutInflater layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(R.layout.divider, parent, false);
DividerVi... | java |
private void visualizeDivider(@NonNull final Divider divider,
@NonNull final DividerViewHolder viewHolder) {
if (!TextUtils.isEmpty(divider.getTitle())) {
viewHolder.titleTextView.setText(divider.getTitle());
viewHolder.titleTextView.setVisibility(View.V... | java |
public final void setStyle(@NonNull final Style style) {
Condition.INSTANCE.ensureNotNull(style, "The style may not be null");
this.style = style;
this.rawItems = null;
notifyDataSetChanged();
} | java |
public final void setWidth(final int width) {
if (style == Style.LIST_COLUMNS && (getDeviceType(context) == DeviceType.TABLET ||
getOrientation(context) == Orientation.LANDSCAPE)) {
columnCount = 2;
} else if (style == Style.GRID) {
int padding = context.getResour... | java |
public final void add(@NonNull final AbstractItem item) {
Condition.INSTANCE.ensureNotNull(item, "The item may not be null");
items.add(item);
if (item instanceof Item && ((Item) item).getIcon() != null) {
iconCount++;
} else if (item instanceof Divider) {
divide... | java |
public final void set(final int index, @NonNull final AbstractItem item) {
Condition.INSTANCE.ensureNotNull(item, "The item may not be null");
AbstractItem replacedItem = items.set(index, item);
if (replacedItem instanceof Item && ((Item) replacedItem).getIcon() != null) {
iconCount... | java |
public final void remove(final int index) {
AbstractItem removedItem = items.remove(index);
if (removedItem instanceof Item && ((Item) removedItem).getIcon() != null) {
iconCount--;
} else if (removedItem instanceof Divider) {
dividerCount--;
}
rawItems ... | java |
public final void clear() {
items.clear();
iconCount = 0;
dividerCount = 0;
if (rawItems != null) {
rawItems.clear();
}
notifyOnDataSetChanged();
} | java |
public final boolean isItemEnabled(final int index) {
AbstractItem item = items.get(index);
return item instanceof Item && ((Item) item).isEnabled();
} | java |
public final void setItemEnabled(final int index, final boolean enabled) {
AbstractItem item = items.get(index);
if (item instanceof Item) {
((Item) item).setEnabled(enabled);
rawItems = null;
notifyOnDataSetChanged();
}
} | java |
public final void setTitle(@NonNull final Context context, @StringRes final int resourceId) {
setTitle(context.getText(resourceId));
} | java |
private boolean isScrollUpEvent(final float x, final float y,
@NonNull final ViewGroup viewGroup) {
int location[] = new int[2];
viewGroup.getLocationOnScreen(location);
if (x >= location[0] && x <= location[0] + viewGroup.getWidth() && y >= location[1] &&
... | java |
private boolean handleDrag() {
if (!isAnimationRunning()) {
if (dragHelper.hasThresholdBeenReached()) {
int margin = Math.round(isMaximized() ? dragHelper.getDragDistance() :
initialMargin + dragHelper.getDragDistance());
margin = Math.max(Math... | java |
private void handleRelease() {
float speed = Math.max(dragHelper.getDragSpeed(), animationSpeed);
if (getTopMargin() > initialMargin ||
(dragHelper.getDragSpeed() > animationSpeed && dragHelper.getDragDistance() > 0) ||
(getDeviceType(getContext()) == DeviceType.TABLET &... | java |
private void setTopMargin(final int margin) {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) getLayoutParams();
layoutParams.topMargin = margin;
setLayoutParams(layoutParams);
} | java |
private void animateShowView(final int diff, final float animationSpeed,
@NonNull final Interpolator interpolator) {
animateView(diff, animationSpeed, createAnimationListener(true, false), interpolator);
} | java |
private void animateHideView(final int diff, final float animationSpeed,
@NonNull final Interpolator interpolator, final boolean cancel) {
animateView(diff, animationSpeed, createAnimationListener(false, cancel), interpolator);
} | java |
private void animateView(final int diff, final float animationSpeed,
@NonNull final AnimationListener animationListener,
@NonNull final Interpolator interpolator) {
if (!isDragging() && !isAnimationRunning()) {
long duration = calculateAnimat... | java |
private AnimationListener createAnimationListener(final boolean show, final boolean cancel) {
return new AnimationListener() {
@Override
public void onAnimationStart(final Animation animation) {
}
@Override
public void onAnimationEnd(final Animation... | java |
public final void setIcon(@NonNull final Context context, @DrawableRes final int resourceId) {
setIcon(ContextCompat.getDrawable(context, resourceId));
} | java |
public final void setTitle(@NonNull final Context context, @StringRes final int resourceId) {
Condition.INSTANCE.ensureNotNull(context, "The context may not be null");
setTitle(context.getText(resourceId));
} | java |
private void initialize() {
width = getContext().getResources().getDimensionPixelSize(R.dimen.default_width);
maximize = false;
adapter = new DividableGridAdapter(getContext(), Style.LIST, width);
super.setOnShowListener(createOnShowListener());
} | java |
private WindowManager.LayoutParams createLayoutParams() {
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
return layoutParams;
} | java |
private FrameLayout.LayoutParams createRootViewLayoutParams() {
FrameLayout.LayoutParams layoutParams =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT);
layoutParams.gravity = Gravity.BOTTOM | Gravity.CENT... | java |
private void inflateRootView() {
ViewGroup contentView = findViewById(android.R.id.content);
contentView.removeAllViews();
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
rootView =
(DraggableView) layoutInflater.inflate(R.layout.bottom_sheet, contentVi... | java |
private void inflateTitleView() {
titleContainer = rootView.findViewById(R.id.title_container);
titleContainer.removeAllViews();
if (customTitleView != null) {
titleContainer.addView(customTitleView);
} else if (customTitleViewId != -1) {
LayoutInflater layoutInf... | java |
private void inflateContentView() {
contentContainer = rootView.findViewById(R.id.content_container);
contentContainer.removeAllViews();
if (customView != null) {
contentContainer.setVisibility(View.VISIBLE);
contentContainer.addView(customView);
} else if (custo... | java |
private void showGridView() {
gridView = contentContainer.findViewById(R.id.bottom_sheet_grid_view);
if (gridView != null) {
contentContainer.setVisibility(View.VISIBLE);
if (getStyle() == Style.GRID) {
int horizontalPadding = getContext().getResources()
... | java |
private void adaptRootView() {
if (rootView != null) {
if (getStyle() == Style.LIST) {
int paddingTop = getContext().getResources()
.getDimensionPixelSize(R.dimen.bottom_sheet_list_padding_top);
rootView.setPadding(0, paddingTop, 0, 0);
... | java |
private void adaptIcon() {
if (titleTextView != null) {
titleTextView.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
}
adaptTitleContainerVisibility();
} | java |
private void adaptTitleContainerVisibility() {
if (titleContainer != null) {
if (customTitleView == null && customTitleViewId == -1) {
titleContainer.setVisibility(
!TextUtils.isEmpty(title) || icon != null ? View.VISIBLE : View.GONE);
} else {
... | java |
private void adaptWidth() {
adapter.setWidth(width);
if (rootView != null) {
rootView.setWidth(width);
rootView.requestLayout();
}
} | java |
@TargetApi(VERSION_CODES.FROYO)
private OnShowListener createOnShowListener() {
return new OnShowListener() {
@Override
public void onShow(final DialogInterface dialog) {
if (onShowListener != null) {
onShowListener.onShow(dialog);
... | java |
private View.OnTouchListener createCancelOnTouchListener() {
return new View.OnTouchListener() {
@Override
public boolean onTouch(final View v, final MotionEvent event) {
if (cancelable && canceledOnTouchOutside) {
cancel();
v.perf... | java |
private OnItemClickListener createItemClickListener() {
return new OnItemClickListener() {
@Override
public void onItemClick(final AdapterView<?> parent, final View view,
final int position, final long id) {
if (itemClickListener != nu... | java |
private OnItemLongClickListener createItemLongClickListener() {
return new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(final AdapterView<?> parent, final View view,
final int position, final long id) {
... | java |
private OnItemClickListener createIntentClickListener(@NonNull final Activity activity,
@NonNull final Intent intent,
@NonNull final List<ResolveInfo> resolveInfos) {
return new OnItemClickListene... | java |
public final GridView getGridView() {
return (gridView != null && gridView.getVisibility() == View.VISIBLE) ? gridView : null;
} | java |
public final void setIcon(@DrawableRes final int resourceId) {
this.icon = ContextCompat.getDrawable(getContext(), resourceId);
this.iconBitmap = null;
this.iconId = resourceId;
this.iconAttributeId = -1;
adaptIcon();
} | java |
public final void setIconAttribute(@AttrRes final int attributeId) {
TypedArray typedArray =
getContext().getTheme().obtainStyledAttributes(new int[]{attributeId});
this.icon = typedArray.getDrawable(0);
this.iconBitmap = null;
this.iconId = -1;
this.iconAttribute... | java |
public final void setBackgroundColor(@ColorInt final int color) {
this.background = new ColorDrawable(color);
this.backgroundBitmap = null;
this.backgroundId = -1;
this.backgroundColor = color;
adaptBackground();
} | java |
public final void setDragSensitivity(final float dragSensitivity) {
Condition.INSTANCE
.ensureAtLeast(dragSensitivity, 0, "The drag sensitivity must be at least 0");
Condition.INSTANCE
.ensureAtMaximum(dragSensitivity, 1, "The drag sensitivity must be at maximum 1");
... | java |
public final void setDimAmount(final float dimAmount) {
Condition.INSTANCE.ensureAtLeast(dimAmount, 0, "The dim amount must be at least 0");
Condition.INSTANCE.ensureAtMaximum(dimAmount, 1, "The dim amount must be at maximum 1");
this.dimAmount = dimAmount;
getWindow().getAttributes().di... | java |
public final int indexOf(final int id) {
Condition.INSTANCE.ensureAtLeast(id, 0, "The id must be at least 0");
for (int i = 0; i < getItemCount(); i++) {
AbstractItem item = adapter.getItem(i);
if (item.getId() == id) {
return i;
}
}
... | java |
public final void setIntent(@NonNull final Activity activity, @NonNull final Intent intent) {
Condition.INSTANCE.ensureNotNull(activity, "The activity may not be null");
Condition.INSTANCE.ensureNotNull(intent, "The intent may not be null");
removeAllItems();
PackageManager packageManage... | java |
@TargetApi(VERSION_CODES.FROYO)
public final void maximize() {
if (!isMaximized()) {
if (!isShowing()) {
maximize = true;
show();
} else {
rootView.maximize(new AccelerateDecelerateInterpolator());
}
}
} | java |
public final void setStyle(@NonNull final Style style) {
Condition.INSTANCE.ensureNotNull(style, "The style may not be null");
adapter.setStyle(style);
adaptRootView();
adaptTitleView();
adaptContentView();
adaptGridViewHeight();
} | java |
private void initializeBottomSheet() {
BottomSheet.Builder builder = createBottomSheetBuilder();
addItems(builder);
bottomSheet = builder.create();
} | java |
private void initializeCustomBottomSheet() {
BottomSheet.Builder builder = createBottomSheetBuilder();
builder.setView(R.layout.custom_view);
customBottomSheet = builder.create();
} | java |
private void initializeIntentBottomSheet() {
BottomSheet.Builder builder = createBottomSheetBuilder();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
intent.setType("text/plain");
builder... | java |
private void initializeShowBottomSheetPreference() {
Preference showBottomSheetPreference =
findPreference(getString(R.string.show_bottom_sheet_preference_key));
showBottomSheetPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
pu... | java |
private void initializeShowCustomBottomSheetPreference() {
Preference showCustomBottomSheetPreference =
findPreference(getString(R.string.show_custom_bottom_sheet_preference_key));
showCustomBottomSheetPreference
.setOnPreferenceClickListener(new OnPreferenceClickListener... | java |
private void initializeShowIntentBottmSheetPreference() {
Preference showIntentBottomSheetPreference =
findPreference(getString(R.string.show_intent_bottom_sheet_preference_key));
showIntentBottomSheetPreference
.setOnPreferenceClickListener(new OnPreferenceClickListener(... | java |
private BottomSheet.Builder createBottomSheetBuilder() {
BottomSheet.Builder builder = new BottomSheet.Builder(getActivity());
builder.setStyle(getStyle());
if (shouldTitleBeShown()) {
builder.setTitle(getBottomSheetTitle());
}
if (shouldIconBeShown()) {
... | java |
private void addItems(@NonNull final BottomSheet.Builder builder) {
int dividerCount = getDividerCount();
boolean showDividerTitle = shouldDividerTitleBeShown();
int itemCount = getItemCount();
boolean showIcon = shouldItemIconsBeShown();
boolean disableItems = shouldItemsBeDisab... | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.