code
stringlengths
73
34.1k
label
stringclasses
1 value
public void zDrawTextFieldIndicators() { if (!isEnabled()) { // (Possibility: DisabledComponent) // Note: The time should always be validated (as if the component lost focus), before // the component is disabled. timeTextField.setBackground(new Color(240, 240, 240...
java
@Override public void zEventCustomPopupWasClosed(CustomPopup popup) { popup = null; if (timeMenuPanel != null) { timeMenuPanel.clearParent(); } timeMenuPanel = null; lastPopupCloseTime = Instant.now(); }
java
private void zInstallSpinnerButtonListener(Component spinnerButton) { spinnerButton.addMouseListener(new MouseAdapter() { /** * mouseReleased, This will be called when the spinner button is pressed down. This is * only called once before release no matter how long the mouse...
java
private void zInternalSetLastValidTimeAndNotifyListeners(LocalTime newTime) { LocalTime oldTime = lastValidTime; lastValidTime = newTime; if (!PickerUtilities.isSameLocalTime(oldTime, newTime)) { for (TimeChangeListener timeChangeListener : timeChangeListeners) { Time...
java
private void zEventTextFieldChanged() { // Skip this function if it should not be run. if (skipTextFieldChangedFunctionWhileTrue) { return; } // Gather some variables that we will need. String timeText = timeTextField.getText(); boolean textIsEmpty = timeText....
java
public LocalDateTime getDateTimePermissive() { LocalDate dateValue = datePicker.getDate(); LocalTime timeValue = timePicker.getTime(); timeValue = (timeValue == null) ? LocalTime.MIDNIGHT : timeValue; if (dateValue == null) { return null; } return LocalDateTim...
java
public LocalDateTime getDateTimeStrict() { LocalDate dateValue = datePicker.getDate(); LocalTime timeValue = timePicker.getTime(); if (dateValue == null || timeValue == null) { return null; } return LocalDateTime.of(dateValue, timeValue); }
java
public boolean isDateTimeAllowed(LocalDateTime value) { LocalDate datePortion = (value == null) ? null : value.toLocalDate(); LocalTime timePortion = (value == null) ? null : value.toLocalTime(); boolean isDateAllowed = datePicker.isDateAllowed(datePortion); boolean isTimeAllowed = timeP...
java
public void setDateTimePermissive(LocalDateTime optionalDateTime) { if (optionalDateTime == null) { datePicker.setDate(null); timePicker.setTime(null); return; } datePicker.setDate(optionalDateTime.toLocalDate()); timePicker.setTime(optionalDateTime.to...
java
@Override public void setEnabled(boolean enabled) { super.setEnabled(enabled); datePicker.setEnabled(enabled); timePicker.setEnabled(enabled); }
java
public void setGapSize(int gapSize, ConstantSize.Unit units) { ConstantSize gapSizeObject = new ConstantSize(gapSize, units); ColumnSpec columnSpec = ColumnSpec.createGap(gapSizeObject); FormLayout layout = (FormLayout) getLayout(); layout.setColumnSpec(2, columnSpec); }
java
public static Size bounded(Size basis, Size lowerBound, Size upperBound) { return new BoundedSize(basis, lowerBound, upperBound); }
java
public static void setDefaultUnit(Unit unit) { if ((unit == ConstantSize.DLUX) || (unit == ConstantSize.DLUY)) { throw new IllegalArgumentException( "The unit must not be DLUX or DLUY. " + "To use DLU as default unit, invoke this method with null."); }...
java
protected static String getSystemProperty(String key) { try { return System.getProperty(key); } catch (SecurityException e) { Logger.getLogger(SystemUtils.class.getName()).warning( "Can't access the System property " + key + "."); return ""; ...
java
@Override final public void mouseReleased(MouseEvent e) { // Check to see if this mouse release completes a liberal single click. if (isComponentPressedDown) { // A liberal single click has occurred. mouseLiberalClick(e); // Check to see if we had two liberal sing...
java
public void setSettings(DatePickerSettings settings) { settings = (settings == null) ? new DatePickerSettings() : settings; settings.zSetParentDatePicker(this); this.settings = settings; // Apply needed settings from the settings instance to this date picker. // Note: CalendarPa...
java
@Override public int getBaseline(int width, int height) { if (dateTextField.isVisible()) { return dateTextField.getBaseline(width, height); } return super.getBaseline(width, height); }
java
public String getDateStringOrSuppliedString(String emptyDateString) { LocalDate date = getDate(); return (date == null) ? emptyDateString : date.toString(); }
java
public boolean isTextValid(String text) { // If the text is null or the settings are null, return false. if (text == null || settings == null) { return false; } // If the text is empty, return the value of allowEmptyDates. text = text.trim(); if (text.isEmpty(...
java
public void openPopup() { if (isPopupOpen()) { closePopup(); return; } if (settings == null) { return; } // If the component is disabled, do nothing. if (!isEnabled()) { return; } // If this function was cal...
java
public final void setDate(LocalDate optionalDate) { // Set the text field to the supplied date, using the standard format for null, AD, or BC. String standardDateString = zGetStandardTextFieldDateString(optionalDate); String textFieldString = dateTextField.getText(); // We will only chan...
java
@Override public void setEnabled(boolean enabled) { if (enabled == false) { closePopup(); } setTextFieldToValidStateIfNeeded(); super.setEnabled(enabled); toggleCalendarButton.setEnabled(enabled); dateTextField.setEnabled(enabled); zDrawTextFieldIn...
java
private void zAddTextChangeListener() { dateTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { zEventTextFieldChanged(); } @Override public void removeUpdate(Docum...
java
static void zSetPopupLocation(CustomPopup popup, int defaultX, int defaultY, JComponent picker, JComponent verticalFlipReference, int verticalFlipDistance, int bottomOverlapAllowed) { // Gather some variables that we will need. Window topWindowOrNull = SwingUtilities.getWindowAncestor(picker...
java
private void zInternalSetLastValidDateAndNotifyListeners(LocalDate newDate) { LocalDate oldDate = lastValidDate; lastValidDate = newDate; if (!PickerUtilities.isSameLocalDate(oldDate, newDate)) { for (DateChangeListener dateChangeListener : dateChangeListeners) { Date...
java
private void zEventTextFieldChanged() { if (settings == null) { return; } // Skip this function if it should not be run. if (skipTextFieldChangedFunctionWhileTrue) { return; } // Gather some variables that we will need. String dateText = da...
java
public void zDrawTextFieldIndicators() { if (settings == null) { return; } if (!isEnabled()) { // (Possibility: DisabledComponent) // Note: The date should always be validated (as if the component lost focus), before // the component is disabled. ...
java
@Override public void zEventCustomPopupWasClosed(CustomPopup popup) { this.popup = null; calendarPanel = null; lastPopupCloseTime = Instant.now(); }
java
public static double getJavaRunningVersionAsDouble() { String version = System.getProperty("java.version"); int pos = version.indexOf('.'); pos = version.indexOf('.', pos + 1); return Double.parseDouble(version.substring(0, pos)); }
java
public static String getJavaTargetVersionFromPom() { try { Properties properties = new Properties(); ClassLoader classLoader = ClassLoader.getSystemClassLoader(); properties.load(classLoader.getResourceAsStream("project.properties")); return "" + properties.getPro...
java
public static <T> T getMostCommonElementInList(List<T> sourceList) { if (sourceList == null || sourceList.isEmpty()) { return null; } Map<T, Integer> hashMap = new HashMap<T, Integer>(); for (T element : sourceList) { Integer countOrNull = hashMap.get(element); ...
java
static public Insets getScreenInsets(Window windowOrNull) { Insets insets; if (windowOrNull == null) { insets = Toolkit.getDefaultToolkit().getScreenInsets(GraphicsEnvironment .getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration());...
java
public static DateTimeFormatter generateDefaultFormatterCE(Locale pickerLocale) { DateTimeFormatter formatCE = new DateTimeFormatterBuilder().parseLenient(). parseCaseInsensitive().appendLocalized(FormatStyle.LONG, null). toFormatter(pickerLocale); // Get the local language as a ...
java
public static DateTimeFormatter generateDefaultFormatterBCE(Locale pickerLocale) { // This is verified to work for the following locale languages: // en, de, fr, pt, ru, it, nl, es, pl, da, ro, sv, zh. String displayFormatterBCPattern = DateTimeFormatterBuilder.getLocalizedDateTimePattern( ...
java
static public LocalDate getParsedDateOrNull(String text, DateTimeFormatter displayFormatterADStrict, DateTimeFormatter displayFormatterBCStrict, ArrayList<DateTimeFormatter> parsingFormattersStrict, Locale formatLocale) { if (text == null || text.trim().isEmpty()) { return n...
java
static String capitalizeFirstLetterOfString(String text, Locale locale) { if (text == null || text.length() < 1) { return text; } String textCapitalized = text.substring(0, 1).toUpperCase(locale) + text.substring(1); return textCapitalized; }
java
static public boolean isDateVetoed(DateVetoPolicy policy, LocalDate date) { if (policy == null || date == null) { return false; } return (!policy.isDateAllowed(date)); }
java
static public boolean isMouseWithinComponent(Component component) { Point mousePos = MouseInfo.getPointerInfo().getLocation(); Rectangle bounds = component.getBounds(); bounds.setLocation(component.getLocationOnScreen()); return bounds.contains(mousePos); }
java
static public String safeSubstring(String text, int beginIndex, int endIndexExclusive) { if (text == null) { return null; } int textLength = text.length(); if (beginIndex < 0) { beginIndex = 0; } if (endIndexExclusive < 0) { endIndexExc...
java
public static int getCompiledJavaVersionFromJavaClassFile( InputStream classByteStream, boolean majorVersionRequested) throws Exception { DataInputStream dataInputStream = new DataInputStream(classByteStream); // Skip the "magic number". dataInputStream.readInt(); int min...
java
public static void setDefaultTableEditorsClicks(JTable table, int clickCountToStart) { TableCellEditor editor; editor = table.getDefaultEditor(Object.class); if (editor instanceof DefaultCellEditor) { ((DefaultCellEditor) editor).setClickCountToStart(clickCountToStart); } ...
java
public void generatePotentialMenuTimes(ArrayList<LocalTime> desiredTimes) { potentialMenuTimes = new ArrayList<LocalTime>(); if (desiredTimes == null || desiredTimes.isEmpty()) { return; } TreeSet<LocalTime> timeSet = new TreeSet<LocalTime>(); for (LocalTime desiredTi...
java
public boolean isTimeAllowed(LocalTime time) { if (time == null) { return allowEmptyTimes; } return (!(InternalUtilities.isTimeVetoed(vetoPolicy, time))); }
java
public void setFormatForDisplayTime(String patternString) { DateTimeFormatter formatter = PickerUtilities.createFormatterFromPatternString(patternString, locale); setFormatForDisplayTime(formatter); }
java
public void setFormatForMenuTimes(String patternString) { DateTimeFormatter formatter = PickerUtilities.createFormatterFromPatternString(patternString, locale); setFormatForMenuTimes(formatter); }
java
private void zApplyAllowEmptyTimes() { // Find out if we need to initialize a null time. if ((!allowEmptyTimes) && (parent.getTime() == null)) { // We need to initialize the current time, so find out if the default time is vetoed. LocalTime defaultTime = LocalTime.of(7, 0); ...
java
void zApplyDisplaySpinnerButtons() { if (parent == null) { return; } parent.getComponentDecreaseSpinnerButton().setEnabled(displaySpinnerButtons); parent.getComponentDecreaseSpinnerButton().setVisible(displaySpinnerButtons); parent.getComponentIncreaseSpinnerButton()....
java
void zApplyDisplayToggleTimeMenuButton() { if (parent == null) { return; } parent.getComponentToggleTimeMenuButton().setEnabled(displayToggleTimeMenuButton); parent.getComponentToggleTimeMenuButton().setVisible(displayToggleTimeMenuButton); }
java
private void zApplyInitialTime() { if (allowEmptyTimes == true && initialTime == null) { parent.setTime(null); } if (initialTime != null) { parent.setTime(initialTime); } }
java
void zApplyMinimumSpinnerButtonWidthInPixels() { if (parent == null) { return; } Dimension decreaseButtonPreferredSize = parent.getComponentDecreaseSpinnerButton().getPreferredSize(); Dimension increaseButtonPreferredSize = parent.getComponentIncreaseSpinnerButton().getPrefer...
java
void zApplyMinimumToggleTimeMenuButtonWidthInPixels() { if (parent == null) { return; } Dimension menuButtonPreferredSize = parent.getComponentToggleTimeMenuButton().getPreferredSize(); int width = menuButtonPreferredSize.width; int height = menuButtonPreferredSize.he...
java
static ConstantSize valueOf(String encodedValueAndUnit, boolean horizontal) { String[] split = ConstantSize.splitValueAndUnit(encodedValueAndUnit); String encodedValue = split[0]; String encodedUnit = split[1]; Unit unit = Unit.valueOf(encodedUnit, horizontal); double value = Dou...
java
public int getPixelSize(Component component) { if (unit == PIXEL) { return intValue(); } else if (unit == POINT) { return Sizes.pointAsPixel(intValue(), component); } else if (unit == INCH) { return Sizes.inchAsPixel(value, component); } else if (unit ...
java
@Override public String encode() { return value == intValue() ? Integer.toString(intValue()) + unit.encode() : Double.toString(value) + unit.encode(); }
java
private static String[] splitValueAndUnit(String encodedValueAndUnit) { String[] result = new String[2]; int len = encodedValueAndUnit.length(); int firstLetterIndex = len; while (firstLetterIndex > 0 && Character.isLetter(encodedValueAndUnit.charAt(firstLetterIndex - 1))...
java
public static ColumnSpec decode(String encodedColumnSpec, LayoutMap layoutMap) { checkNotBlank(encodedColumnSpec, "The encoded column specification must not be null, empty or whitespace."); checkNotNull(layoutMap, "The LayoutMap must not be null."); String trimmed = encodedColumn...
java
static ColumnSpec decodeExpanded(String expandedTrimmedLowerCaseSpec) { ColumnSpec spec = CACHE.get(expandedTrimmedLowerCaseSpec); if (spec == null) { spec = new ColumnSpec(expandedTrimmedLowerCaseSpec); CACHE.put(expandedTrimmedLowerCaseSpec, spec); } return spec...
java
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { // Save the supplied value to the time picker. setCellEditorValue(value); // If needed, adjust the minimum row height for the table. zAdjustTableR...
java
@Override public Image getIcon(int iconType) { Pair<String, Image> pair = iconInformation.get(iconType); String imagePath = pair.first; Image imageOrNull = pair.second; if ((imageOrNull == null) && (imagePath != null)) { imageOrNull = loadImage(imagePath); } ...
java
protected double computeAverageCharWidth( FontMetrics metrics, String testString) { int width = metrics.stringWidth(testString); double average = (double) width / testString.length(); //System.out.println("Average width of '" + testString + "'=" + average); return...
java
protected int getScreenResolution(Component c) { if (c == null) { return getDefaultScreenResolution(); } Toolkit toolkit = c.getToolkit(); return toolkit != null ? toolkit.getScreenResolution() : getDefaultScreenResolution(); }
java
@Override public String encode() { StringBuffer buffer = new StringBuffer("["); if (lowerBound != null) { buffer.append(lowerBound.encode()); buffer.append(','); } buffer.append(basis.encode()); if (upperBound != null) { buffer.append(',');...
java
public static boolean isLocalTimeInRange(LocalTime value, LocalTime optionalMinimum, LocalTime optionalMaximum, boolean inclusiveOfEndpoints) { // If either bounding time does does not already exist, then set it to the maximum range. LocalTime minimum = (optionalMinimum == null) ? LocalTime....
java
static public boolean isSameLocalDate(LocalDate first, LocalDate second) { // If both values are null, return true. if (first == null && second == null) { return true; } // At least one value contains a date. If the other value is null, then return false. if (first ==...
java
public static boolean isSameYearMonth(YearMonth first, YearMonth second) { // If both values are null, return true. if (first == null && second == null) { return true; } // At least one value contains a YearMonth. If the other value is null, then return false. if (fir...
java
public static String localTimeToString(LocalTime time, String emptyTimeString) { return (time == null) ? emptyTimeString : time.toString(); }
java
private static Integer decodeInt(String token) { try { return Integer.decode(token); } catch (NumberFormatException e) { return null; } }
java
void ensureValidGridBounds(int colCount, int rowCount) { if (gridX <= 0) { throw new IndexOutOfBoundsException( "The column index " + gridX + " must be positive."); } if (gridX > colCount) { throw new IndexOutOfBoundsException( "The...
java
private static void ensureValidOrientations(Alignment horizontalAlignment, Alignment verticalAlignment) { if (!horizontalAlignment.isHorizontal()) { throw new IllegalArgumentException("The horizontal alignment must be one of: left, center, right, fill, default."); } if (!verticalAlig...
java
void setBounds(Component c, FormLayout layout, Rectangle cellBounds, FormLayout.Measure minWidthMeasure, FormLayout.Measure minHeightMeasure, FormLayout.Measure prefWidthMeasure, FormLayout.Measure prefHeightMeasure) { ColumnSpec colSpec = gridWidth ==...
java
private static int componentSize(Component component, FormSpec formSpec, int cellSize, FormLayout.Measure minMeasure, FormLayout.Measure prefMeasure) { if (formSpec == null) { return prefMeasure.sizeOf(component); } else if (formSpec.getSize() ...
java
private static int origin(Alignment alignment, int cellOrigin, int cellSize, int componentSize) { if (alignment == RIGHT || alignment == BOTTOM) { return cellOrigin + cellSize - componentSize; } else if (alignment == CENTER) { return cellOrigin...
java
private static String formatInt(int number) { String str = Integer.toString(number); return number < 10 ? " " + str : str; }
java
protected final void firePropertyChange(String propertyName, Object oldValue, Object newValue) { PropertyChangeSupport aChangeSupport = this.changeSupport; if (aChangeSupport == null) { return; } aChangeSupport.firePropertyChange(propertyName, oldValue...
java
protected final void firePropertyChange(String propertyName, double oldValue, double newValue) { firePropertyChange(propertyName, Double.valueOf(oldValue), Double.valueOf(newValue)); }
java
protected final void fireVetoableChange(String propertyName, Object oldValue, Object newValue) throws PropertyVetoException { VetoableChangeSupport aVetoSupport = this.vetoSupport; if (aVetoSupport == null) { return; } aVetoSupport.fireVeto...
java
protected final void fireVetoableChange(String propertyName, long oldValue, long newValue) throws PropertyVetoException { fireVetoableChange(propertyName, Long.valueOf(oldValue), Long.valueOf(newValue)); }
java
public static void main(String[] args) { // Use the standard swing code to start this demo inside a swing thread. SwingUtilities.invokeLater(new Runnable() { @Override public void run() { // Create an instance of the demo. BasicDemo basicDemo = new...
java
private void parseAndInitValues(String encodedDescription) { checkNotBlank(encodedDescription, "The encoded form specification must not be null, empty or whitespace."); String[] token = TOKEN_SEPARATOR_PATTERN.split(encodedDescription); checkArgument(token.length > 0, "The form s...
java
private Size parseSize(String token) { if (token.startsWith("[") && token.endsWith("]")) { return parseBoundedSize(token); } if (token.startsWith("max(") && token.endsWith(")")) { return parseOldBoundedSize(token, false); } if (token.startsWith("min(") && ...
java
private Size parseAtomicSize(String token) { String trimmedToken = token.trim(); if (trimmedToken.startsWith("'") && trimmedToken.endsWith("'")) { int length = trimmedToken.length(); if (length < 2) { throw new IllegalArgumentException("Missing closing \"'\" for p...
java
private static double parseResizeWeight(String token) { if (token.equals("g") || token.equals("grow")) { return DEFAULT_GROW; } if (token.equals("n") || token.equals("nogrow") || token.equals("none")) { return NO_GROW; } // Must have format: grow(<double>)...
java
@Override public void hide() { if (displayWindow != null) { displayWindow.setVisible(false); displayWindow.removeWindowFocusListener(this); displayWindow = null; } if (topWindow != null) { topWindow.removeComponentListener(this); to...
java
@Override public void windowLostFocus(WindowEvent e) { // This section is part of the bug fix for blank popup windows in linux. if (!enableHideWhenFocusIsLost) { e.getWindow().requestFocus(); return; } // This fixes a linux-specific behavior where the focus ca...
java
public java.util.Date getDateWithDefaultZone() { LocalDate pickerDate = parentDatePicker.getDate(); if (pickerDate == null) { return null; } Instant instant = pickerDate.atStartOfDay(ZoneId.systemDefault()).toInstant(); // for backport: java.util.Date javaUtilDate = D...
java
public java.util.Date getDateWithZone(ZoneId timezone) { LocalDate pickerDate = parentDatePicker.getDate(); if (pickerDate == null || timezone == null) { return null; } Instant instant = pickerDate.atStartOfDay(timezone).toInstant(); // for backport: java.util.Date ja...
java
public void setDateWithDefaultZone(java.util.Date javaUtilDate) { if (javaUtilDate == null) { parentDatePicker.setDate(null); return; } Instant instant = Instant.ofEpochMilli(javaUtilDate.getTime()); ZonedDateTime zonedDateTime = instant.atZone(ZoneId.systemDefaul...
java
private java.util.Date getJavaUtilDateFromInstant(Instant instant) { java.util.Date javaUtilDate; try { javaUtilDate = new java.util.Date(instant.toEpochMilli()); } catch (ArithmeticException ex) { throw new IllegalArgumentException(ex); } return javaUtilD...
java
@Override public boolean isDateAllowed(LocalDate date) { if ((firstAllowedDate != null) && (date.isBefore(firstAllowedDate))) { return false; } if ((lastAllowedDate != null) && (date.isAfter(lastAllowedDate))) { return false; } return true; }
java
public void setDateRangeLimits(LocalDate firstAllowedDate, LocalDate lastAllowedDate) { if (firstAllowedDate == null && lastAllowedDate == null) { throw new RuntimeException("DateVetoPolicyMinimumMaximumDate.setDateRangeLimits()," + "The variable firstAllowedDate can be null, or ...
java
public static void createAndShowTableDemoFrame() { // Create and set up the frame and the table demo panel. JFrame frame = new JFrame("LGoodDatePicker Table Editors Demo " + InternalUtilities.getProjectVersionString()); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); ...
java
public void setDefaultDialogFont(Font newFont) { Font oldFont = defaultDialogFont; // Don't use the getter defaultDialogFont = newFont; clearCache(); firePropertyChange(PROPERTY_DEFAULT_DIALOG_FONT, oldFont, newFont); }
java
private static Font lookupDefaultDialogFont() { Font buttonFont = UIManager.getFont("Button.font"); return buttonFont != null ? buttonFont : new JButton().getFont(); }
java
IntTree<V> changeKeysAbove(final long key, final int delta) { if(size==0 || delta==0) return this; if(this.key>=key) // adding delta to this.key changes the keys of _all_ children of this, // so we now need to un-change the children of this smaller than key, // all of which are to the left. note that w...
java
public static void copyRecursively(Path source, Path destination) throws IOException { if (Files.isDirectory(source)) { Files.createDirectories(destination); final Set<Path> sources = listFiles(source); for (Path srcFile : sources) { Path ...
java
public static void setScriptPermission(InstanceConfiguration config, String scriptName) { if (SystemUtils.IS_OS_WINDOWS) { // we do not have file permissions on windows return; } if (VersionUtil.isEqualOrGreater_7_0_0(config.getClusterConfiguration().getVersio...
java
public void lock() { log.info("Elasticsearch has started and the maven process has been blocked. Press CTRL+C to stop the process."); synchronized (lock) { try { lock.wait(); } catch (InterruptedException exception) ...
java
private File resolveArtifact(ClusterConfiguration config) throws ArtifactException, IOException { String flavour = config.getFlavour(); String version = config.getVersion(); String artifactId = getArtifactId(flavour, version); String classifier = getArtifactClassifier(ver...
java
private File downloadArtifact( ElasticsearchArtifact artifactReference, ClusterConfiguration config) throws IOException { String filename = Joiner.on("-").skipNulls() .join( artifactReference.getArtifactId(), ...
java
public static boolean isProcessRunning(String baseDir) { File pidFile = new File(baseDir, "pid"); boolean exists = pidFile.isFile(); return exists; }
java